archimedes: define matrix and keymap

This commit is contained in:
tmk 2023-10-20 02:08:59 +09:00
parent 909b37d641
commit 06f1bded16
5 changed files with 104 additions and 60 deletions

View file

@ -49,10 +49,10 @@ F_USB ?= $(F_CPU)
# Build Options # Build Options
# *Comment out* to disable the options. # *Comment out* to disable the options.
# #
#MOUSEKEY_ENABLE ?= yes # Mouse keys MOUSEKEY_ENABLE ?= yes # Mouse keys
#EXTRAKEY_ENABLE ?= yes # Audio control and System control EXTRAKEY_ENABLE ?= yes # Audio control and System control
CONSOLE_ENABLE ?= yes # Console for debug CONSOLE_ENABLE ?= yes # Console for debug
COMMAND_ENABLE ?= yes # Commands for debug and configuration COMMAND_ENABLE ?= yes # Commands for debug and configuration
#NKRO_ENABLE ?= yes # USB Nkey Rollover #NKRO_ENABLE ?= yes # USB Nkey Rollover
UNIMAP_ENABLE = yes UNIMAP_ENABLE = yes
KEYMAP_SECTION_ENABLE = yes KEYMAP_SECTION_ENABLE = yes

View file

@ -23,6 +23,7 @@ SOFTWARE.
#include <stdint.h> #include <stdint.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include "protocol/serial.h" #include "protocol/serial.h"
#include "matrix.h"
#include "wait.h" #include "wait.h"
#include "timer.h" #include "timer.h"
#include "debug.h" #include "debug.h"
@ -52,19 +53,46 @@ SOFTWARE.
#define ARC_LED_NUM_LOCK 1 #define ARC_LED_NUM_LOCK 1
#define ARC_LED_SCROLL_LOCK 2 #define ARC_LED_SCROLL_LOCK 2
/* key matrix 8x16
* |R/C| 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| A| B| C| D| E| F|
* |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
* | 0|ESC| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Prt|ScL|Brk|
* | 1| `~| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -_| =+| £| BS|Ins|
* | 2|Hom|PgU|NmL| P/| P*| P#|Tab| Q| W| E| R| T| Y| U| I| O|
* | 3| P| [{| ]}| \||Del|Cpy|PgD| P7| P8| P9| P-|LCt| A| S| D| F|
* | 4| G| H| J| K| L| ;:| '"|Rtn| P4| P5| P6| P+|LSh| | Z| X|
* | 5| C| V| B| N| M| ,<| .>| /?|RSh| Up| P1| P2| P3|Cap|LAl|Spc|
* | 6|Ral|RCt|Lef|Dow|Rig| P0| P.|PEn| | | | | | | | |
* | 7|SW1|SW2|SW3| | | | | | | | | | | | | |
*/
#define ROW(key) ((key & 0x70) >> 4)
#define COL(key) (key & 0x0F)
static matrix_row_t matrix[MATRIX_ROWS];
void matrix_clear(void)
{
for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
}
matrix_row_t matrix_get_row(uint8_t row)
{
return matrix[row];
}
void matrix_init(void) void matrix_init(void)
{ {
//debug_enable = true; //debug_enable = true;
//debug_matrix = true;
matrix_clear();
serial_init(); serial_init();
// wait for keyboard coming up // wait for keyboard coming up
// otherwise LED status update fails // otherwise LED status update fails
print("Archimedes starts.\n"); print("Archimedes starts.\n");
xprintf("EIMSK: %02X\n", EIMSK); //xprintf("EIMSK: %02X\n", EIMSK);
xprintf("EICRA: %02X\n", EICRA); //xprintf("EICRA: %02X\n", EICRA);
return; return;
} }
@ -72,6 +100,7 @@ void matrix_init(void)
// LED status // LED status
static uint8_t arc_led = 0; static uint8_t arc_led = 0;
static uint8_t arc_led_prev = 0; static uint8_t arc_led_prev = 0;
static enum { static enum {
INIT, INIT,
SCAN, SCAN,
@ -148,10 +177,10 @@ uint8_t matrix_scan(void)
case KDDA ... KDDA+15: case KDDA ... KDDA+15:
case KUDA ... KUDA+15: case KUDA ... KUDA+15:
// key row // key row
key = (d & 0xF) << 4; key = (d & 0x7) << 4;
wait_us(100); wait_us(100);
// ack for key data first byte // ack
send_cmd(BACK); send_cmd(BACK);
state = WAIT_KEY_COL; state = WAIT_KEY_COL;
break; break;
@ -173,13 +202,18 @@ uint8_t matrix_scan(void)
// key col // key col
key |= d & 0xF; key |= d & 0xF;
if ((d & KUDA) == KUDA) { key |= 0x80; } // key up flag if ((d & KUDA) == KUDA) { key |= 0x80; } // key up flag
//
// ack // ack
wait_us(100); wait_us(100);
send_cmd(SMAK); send_cmd(SMAK);
state = SCAN; state = SCAN;
// TODO: make/brak key // TODO: make/brak key
if (key & 0x80) {
matrix[ROW(key)] &= ~(1 << COL(key));
} else {
matrix[ROW(key)] |= (1 << COL(key));
}
xprintf("[k%02X] ", key); xprintf("[k%02X] ", key);
break; break;
default: default:
@ -193,21 +227,17 @@ uint8_t matrix_scan(void)
// DEBUG // DEBUG
// toggle ScrollLock LED // toggle ScrollLock LED
/*
static uint16_t time_last; static uint16_t time_last;
if (timer_elapsed(time_last) > 1000) { if (timer_elapsed(time_last) > 1000) {
arc_led = arc_led ^ 1<<ARC_LED_SCROLL_LOCK; arc_led = arc_led ^ 1<<ARC_LED_SCROLL_LOCK;
time_last = timer_read(); time_last = timer_read();
} }
*/
return 0; return 0;
} }
uint8_t matrix_get_row(uint8_t row)
{
// TODO
return 0;
}
#include "led.h" #include "led.h"
void led_set(uint8_t usb_led) void led_set(uint8_t usb_led)
{ {
@ -215,5 +245,5 @@ void led_set(uint8_t usb_led)
if (usb_led & (1<<USB_LED_NUM_LOCK)) arc_led |= (1<<ARC_LED_NUM_LOCK); if (usb_led & (1<<USB_LED_NUM_LOCK)) arc_led |= (1<<ARC_LED_NUM_LOCK);
if (usb_led & (1<<USB_LED_CAPS_LOCK)) arc_led |= (1<<ARC_LED_CAPS_LOCK); if (usb_led & (1<<USB_LED_CAPS_LOCK)) arc_led |= (1<<ARC_LED_CAPS_LOCK);
if (usb_led & (1<<USB_LED_SCROLL_LOCK)) arc_led |= (1<<ARC_LED_SCROLL_LOCK); if (usb_led & (1<<USB_LED_SCROLL_LOCK)) arc_led |= (1<<ARC_LED_SCROLL_LOCK);
xprintf("LED: %02X %02X\n", usb_led, arc_led); xprintf("LED:%02X:%02X ", usb_led, arc_led);
} }

View file

@ -31,8 +31,8 @@ SOFTWARE.
#define DESCRIPTION converts Archimedes keyboard into USB #define DESCRIPTION converts Archimedes keyboard into USB
/* matrix size */ /* matrix size */
#define MATRIX_ROWS 16 #define MATRIX_ROWS 8
#define MATRIX_COLS 8 #define MATRIX_COLS 16
/* key combination for command */ /* key combination for command */
#define IS_COMMAND() ( \ #define IS_COMMAND() ( \

View file

@ -1,25 +1,32 @@
/* /*
Copyright 2016 Jun Wako <wakojun@gmail.com> Copyright 2023 Jun Wako <wakojun@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "unimap_trans.h" #include "unimap_trans.h"
#define AC_L1 ACTION_LAYER_MOMENTARY(1)
#ifdef KEYMAP_SECTION_ENABLE #ifdef KEYMAP_SECTION_ENABLE
const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] __attribute__ ((section (".keymap.keymaps"))) = { const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
#else #else
const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = { const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = {
#endif #endif
UNIMAP(
F13, F14, F15, F16, F17, F18, F19, F20, F21, F22, F23, F24,
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,PAUS, VOLD,VOLU,MUTE,
GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, JYEN,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSLS, DEL, END, PGDN, P7, P8, P9, PPLS,
CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, NUHS,ENT, P4, P5, P6, PCMM,
LSFT,NUBS,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RO, RSFT, UP, P1, P2, P3, PENT,
LCTL,LGUI,LALT,MHEN, SPC, HENK,KANA,RALT,RGUI,APP, L1, LEFT,DOWN,RGHT, P0, PDOT,PEQL
),
UNIMAP(
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
GRV, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, TRNS,TRNS,TRNS,
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, TRNS,TRNS,TRNS, TRNS,TRNS,TRNS,TRNS,
CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP, INS, TRNS, TRNS,TRNS,TRNS, TRNS,TRNS,TRNS,TRNS,
TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,LEFT,RGHT, TRNS,TRNS, TRNS,TRNS,TRNS,TRNS,
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,END, PGDN,DOWN, TRNS,TRNS, PGUP, TRNS,TRNS,TRNS,TRNS,
TRNS,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, HOME,PGDN,END, TRNS,TRNS,TRNS
),
}; };

View file

@ -21,47 +21,54 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "unimap.h" #include "unimap.h"
/* /* Acorn Archimedes A300
* Scan Code Set 2: * ,---. ,-----------------------------------------------. ,-----------. ,-----------.
* ,-----------------------------------------------. * |Esc| |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12| |Prt|ScL|Brk| |SW1|SW2|SW3|
* |F13|F14|F15|F16|F17|F18|F19|F20|F21|F22|F23|F24|
* ,---. |-----------------------------------------------| ,-----------. ,-----------.
* |Esc| |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12| |PrS|ScL|Pau| |VDn|VUp|Mut|
* `---' `-----------------------------------------------' `-----------' `-----------' * `---' `-----------------------------------------------' `-----------' `-----------'
* ,-----------------------------------------------------------. ,-----------. ,---------------. * ,-----------------------------------------------------------. ,-----------. ,---------------.
* | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|JPY|Bsp| |Ins|Hom|PgU| |NmL| /| *| -| * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| £|Bsp| |Ins|Hom|PgU| |NmL| /| *| #|
* |-----------------------------------------------------------| |-----------| |---------------| * |-----------------------------------------------------------| |-----------| |---------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|End|PgD| | 7| 8| 9| +| * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |Del|Cpy|PgD| | 7| 8| 9| -|
* |-----------------------------------------------------------| `-----------' |---------------| * |-----------------------------------------------------------| `-----------' |---------------|
* |CapsL | A| S| D| F| G| H| J| K| L| ;| '| ^a|Entr| | 4| 5| 6|KP,| * |CapsL | A| S| D| F| G| H| J| K| L| ;| '| ^a|Entr| | 4| 5| 6| +|
* |-----------------------------------------------------------| ,---. |---------------| * |-----------------------------------------------------------| ,---. |---------------|
* |Shft| <| Z| X| C| V| B| N| M| ,| .| /| RO|Shift | |Up | | 1| 2| 3|Ent| * |Shift | Z| X| C| V| B| N| M| ,| .| /| RO|Shift | |Up | | 1| 2| 3| |
* |-----------------------------------------------------------| ,-----------. |---------------| * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
* |Ctl|Gui|Alt|MHEN| Space |HENK|KANA|Alt|Gui|App|Ctl| |Lef|Dow|Rig| | #| 0| .|KP=| * | Ctrl| | Alt | Space | Alt | | Ctrl| |Lef|Dow|Rig| | 0| .| |
* `-----------------------------------------------------------' `-----------' `---------------' * `-----' `---------------------------------------' `-----' `-----------' `---------------'
* *
* ,-----------------------------------------------. * ,---. ,-----------------------------------------------. ,-----------. ,-----------.
* | 08| 10| 18| 20| 28| 30| 38| 40| 48| 50| 57| 5F| * | 00| | 01| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| | 0D| 0E| 0F| | 70| 72| 73|
* ,---. |-----------------------------------------------| ,-----------. ,-----------.
* | 76| | 05| 06| 04| 0C| 03| 0B| 83| 0A| 01| 09| 78| 07| |+7C| 7E|+77| |*21|*32|*23|
* `---' `-----------------------------------------------' `-----------' `-----------' * `---' `-----------------------------------------------' `-----------' `-----------'
* ,-----------------------------------------------------------. ,-----------. ,---------------. * ,-----------------------------------------------------------. ,-----------. ,---------------.
* | 0E| 16| 1E| 26| 25| 2E| 36| 3D| 3E| 46| 45| 4E| 55| 6A| 66| |*70|*6C|*7D| | 77|*4A| 7C| 7B| * | 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B| 1C| 1D| 1E| | 1F| 20| 21| | 22| 23| 24| 25|
* |-----------------------------------------------------------| |-----------| |---------------| * |-----------------------------------------------------------| |-----------| |---------------|
* | 0D | 15| 1D| 24| 2D| 2C| 35| 3C| 43| 44| 4D| 54| 5B| 5D | |*71|*69|*7A| | 6C| 75| 7D| 79| * | 26 | 27| 28| 29| 2A| 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33 | | 34| 35| 36| | 37| 38| 39| 3A|
* |-----------------------------------------------------------| `-----------' |---------------| * |-----------------------------------------------------------| `-----------' |---------------|
* | 58 | 1C| 1B| 23| 2B| 34| 33| 3B| 42| 4B| 4C| 52| ^a| 5A | | 6B| 73| 74| 6D| * | 3B | 3C| 3D| 3E| 3F| 40| 41| 42| 43| 44| 45| 46| 47 | | 48| 49| 4A| 4B|
* |-----------------------------------------------------------| ,---. |---------------| * |-----------------------------------------------------------| ,---. |---------------|
* | 12 | 61| 1A| 22| 21| 2A| 32| 31| 3A| 41| 49| 4A| 51| 59 | |*75| | 69| 72| 7A|*5A| * | 4C | 4E| 4F| 50| 51| 52| 53| 54| 55| 56| 57| 58 | | 59| | 5A| 5B| 5C| |
* |-----------------------------------------------------------| ,-----------. |---------------| * |-----------------------------------------------------------| ,-----------. |-----------| 67|
* | 14|*1F| 11| 67 | 29 | 64 | 13 |*11|*27|*2F|*14| |*6B|*72|*74| | 68| 70| 71| 63| * | 5D | | 5E | 5F | 60 | | 61 | | 62| 63| 64| | 65| 66| |
* `-----------------------------------------------------------' `-----------' `---------------' * `-----' `---------------------------------------' `-----' `-----------' `---------------'
* *: E0-prefixed codes. See cs2_e0code() for remapping to unimap array.
* +: Special codes sequence
* ^a: ISO hash key and US backslash use identical code 5D.
* 51, 63, 68, 6A, 6D: Hidden keys in IBM model M [6]
*/ */
const uint8_t PROGMEM unimap_trans[MATRIX_ROWS][MATRIX_COLS] = { const uint8_t PROGMEM unimap_trans[MATRIX_ROWS][MATRIX_COLS] = {
{ UNIMAP_ESC, UNIMAP_F1, UNIMAP_F2, UNIMAP_F3, UNIMAP_F4, UNIMAP_F5, UNIMAP_F6, UNIMAP_F7, /* 00-07 */
UNIMAP_F8, UNIMAP_F9, UNIMAP_F10, UNIMAP_F11, UNIMAP_F12, UNIMAP_PSCR, UNIMAP_SLCK, UNIMAP_PAUS }, /* 08-0F */
{ UNIMAP_GRV, UNIMAP_1, UNIMAP_2, UNIMAP_3, UNIMAP_4, UNIMAP_5, UNIMAP_6, UNIMAP_7, /* 10-17 */
UNIMAP_8, UNIMAP_9, UNIMAP_0, UNIMAP_MINS, UNIMAP_EQL, UNIMAP_JPY, UNIMAP_BSPC, UNIMAP_INS }, /* 18-1F */
{ UNIMAP_HOME, UNIMAP_PGUP, UNIMAP_NLCK, UNIMAP_PSLS, UNIMAP_PAST, UNIMAP_PEQL, UNIMAP_TAB, UNIMAP_Q, /* 20-27 */
UNIMAP_W, UNIMAP_E, UNIMAP_R, UNIMAP_T, UNIMAP_Y, UNIMAP_U, UNIMAP_I, UNIMAP_O }, /* 28-2F */
{ UNIMAP_P, UNIMAP_LBRC, UNIMAP_RBRC, UNIMAP_BSLS, UNIMAP_DEL, UNIMAP_END, UNIMAP_PGDN, UNIMAP_P7, /* 30-37 */
UNIMAP_P8, UNIMAP_P9, UNIMAP_PMNS, UNIMAP_LCTL, UNIMAP_A, UNIMAP_S, UNIMAP_D, UNIMAP_F }, /* 38-3F */
{ UNIMAP_G, UNIMAP_H, UNIMAP_J, UNIMAP_K, UNIMAP_L, UNIMAP_SCLN, UNIMAP_QUOT, UNIMAP_ENT, /* 40-47 */
UNIMAP_P4, UNIMAP_P5, UNIMAP_P6, UNIMAP_PPLS, UNIMAP_LSFT, UNIMAP_NUBS, UNIMAP_Z, UNIMAP_X }, /* 48-4F */
{ UNIMAP_C, UNIMAP_V, UNIMAP_B, UNIMAP_N, UNIMAP_M, UNIMAP_COMM, UNIMAP_DOT, UNIMAP_SLSH, /* 50-57 */
UNIMAP_RSFT, UNIMAP_UP, UNIMAP_P1, UNIMAP_P2, UNIMAP_P3, UNIMAP_CAPS, UNIMAP_LALT, UNIMAP_SPC }, /* 58-5F */
{ UNIMAP_RALT, UNIMAP_RCTL, UNIMAP_LEFT, UNIMAP_DOWN, UNIMAP_RIGHT,UNIMAP_P0, UNIMAP_PDOT, UNIMAP_PENT, /* 60-67 */
UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO }, /* 68-6F */
{ UNIMAP_VOLD, UNIMAP_VOLU, UNIMAP_MUTE, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, /* 70-77 */
UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO }, /* 78-7F */
}; };
#endif #endif