archimedes: Add mouse support
This commit is contained in:
parent
06f1bded16
commit
f61b50395a
3 changed files with 90 additions and 12 deletions
|
|
@ -26,6 +26,7 @@ SOFTWARE.
|
|||
#include "matrix.h"
|
||||
#include "wait.h"
|
||||
#include "timer.h"
|
||||
#include "host.h"
|
||||
#include "debug.h"
|
||||
#include "print.h"
|
||||
|
||||
|
|
@ -47,6 +48,10 @@ SOFTWARE.
|
|||
#define SMAK 0x33
|
||||
#define KDDA 0xC0
|
||||
#define KUDA 0xD0
|
||||
// mouse data: 0b0xxx xxxx(0x00 - 0x7F)
|
||||
// mouse delta: -64 - 63
|
||||
#define MDAT_MIN 0x00
|
||||
#define MDAT_MAX 0x7F
|
||||
|
||||
// Archimedes LED
|
||||
#define ARC_LED_CAPS_LOCK 0
|
||||
|
|
@ -84,6 +89,8 @@ void matrix_init(void)
|
|||
{
|
||||
//debug_enable = true;
|
||||
//debug_matrix = true;
|
||||
//debug_keyboard = true;
|
||||
//debug_mouse = true;
|
||||
|
||||
matrix_clear();
|
||||
serial_init();
|
||||
|
|
@ -105,6 +112,7 @@ static enum {
|
|||
INIT,
|
||||
SCAN,
|
||||
WAIT_KEY_COL,
|
||||
WAIT_MDAT_Y,
|
||||
} state = INIT;
|
||||
|
||||
static int16_t check_reply(void)
|
||||
|
|
@ -121,14 +129,18 @@ static int16_t check_reply(void)
|
|||
static void send_cmd(uint8_t cmd)
|
||||
{
|
||||
xprintf("s%02X ", cmd);
|
||||
uint8_t sreg = SREG;
|
||||
cli();
|
||||
serial_send(cmd);
|
||||
sei();
|
||||
SREG = sreg;
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void)
|
||||
{
|
||||
static uint8_t key;
|
||||
static uint8_t mouse_btn = 0;
|
||||
static int8_t mouse_x = 0;
|
||||
static int8_t mouse_y = 0;
|
||||
|
||||
switch (state) {
|
||||
case INIT:
|
||||
|
|
@ -184,6 +196,14 @@ uint8_t matrix_scan(void)
|
|||
send_cmd(BACK);
|
||||
state = WAIT_KEY_COL;
|
||||
break;
|
||||
case MDAT_MIN ... MDAT_MAX:
|
||||
// sign bit for int8_t
|
||||
if (d & 0x40) d |= 0x80;
|
||||
mouse_x = d;
|
||||
// ack
|
||||
send_cmd(BACK);
|
||||
state = WAIT_MDAT_Y;
|
||||
break;
|
||||
default:
|
||||
state = INIT;
|
||||
break;
|
||||
|
|
@ -208,11 +228,38 @@ uint8_t matrix_scan(void)
|
|||
send_cmd(SMAK);
|
||||
state = SCAN;
|
||||
|
||||
// TODO: make/brak key
|
||||
if (key & 0x80) {
|
||||
// break
|
||||
switch (key & 0x7F) {
|
||||
case 0x70: // mouse SW1
|
||||
case 0x71: // mouse SW2
|
||||
case 0x72: // mouse SW3
|
||||
mouse_btn &= ~(1 << (key & 3));
|
||||
|
||||
report_mouse_t mouse_report = {};
|
||||
mouse_report.buttons = mouse_btn;
|
||||
host_mouse_send(&mouse_report);
|
||||
break;
|
||||
default:
|
||||
matrix[ROW(key)] &= ~(1 << COL(key));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// make
|
||||
switch (key & 0x7F) {
|
||||
case 0x70: // mouse SW1
|
||||
case 0x71: // mouse SW2
|
||||
case 0x72: // mouse SW3
|
||||
mouse_btn |= (1 << (key & 3));
|
||||
|
||||
report_mouse_t mouse_report = {};
|
||||
mouse_report.buttons = mouse_btn;
|
||||
host_mouse_send(&mouse_report);
|
||||
break;
|
||||
default:
|
||||
matrix[ROW(key)] |= (1 << COL(key));
|
||||
break;
|
||||
}
|
||||
}
|
||||
xprintf("[k%02X] ", key);
|
||||
break;
|
||||
|
|
@ -223,6 +270,37 @@ uint8_t matrix_scan(void)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case WAIT_MDAT_Y: {
|
||||
int16_t d;
|
||||
d = check_reply();
|
||||
switch (d) {
|
||||
case -1:
|
||||
// no reply
|
||||
break;
|
||||
case MDAT_MIN ... MDAT_MAX:
|
||||
// sign bit for int8_t
|
||||
if (d & 0x40) d |= 0x80;
|
||||
mouse_y = d;
|
||||
xprintf("[m%02d,%02d] ", mouse_x, mouse_y);
|
||||
|
||||
report_mouse_t mouse_report = {};
|
||||
mouse_report.buttons = mouse_btn;
|
||||
// TODO: move direction is not confirmed
|
||||
mouse_report.x = mouse_x;
|
||||
mouse_report.y = mouse_y;
|
||||
host_mouse_send(&mouse_report);
|
||||
|
||||
// ack
|
||||
wait_us(100);
|
||||
send_cmd(SMAK);
|
||||
state = SCAN;
|
||||
break;
|
||||
default:
|
||||
state = INIT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
|
|
@ -245,5 +323,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_CAPS_LOCK)) arc_led |= (1<<ARC_LED_CAPS_LOCK);
|
||||
if (usb_led & (1<<USB_LED_SCROLL_LOCK)) arc_led |= (1<<ARC_LED_SCROLL_LOCK);
|
||||
xprintf("LED:%02X:%02X ", usb_led, arc_led);
|
||||
xprintf("[LED:%02X:%02X] ", usb_led, arc_led);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = {
|
|||
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
|
||||
CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP, INS, TRNS, TRNS,TRNS,TRNS, TRNS,MS_U,TRNS,TRNS,
|
||||
TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,LEFT,RGHT, TRNS,TRNS, MS_L,TRNS,MS_R,TRNS,
|
||||
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,END, PGDN,DOWN, TRNS,TRNS, PGUP, TRNS,MS_D,TRNS,BTN3,
|
||||
TRNS,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, HOME,PGDN,END, BTN1,BTN2,TRNS
|
||||
),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
* |-----------------------------------------------------------| |-----------| |---------------|
|
||||
* |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| +|
|
||||
* |CapsL | A| S| D| F| G| H| J| K| L| ;| '| Enter | | 4| 5| 6| +|
|
||||
* |-----------------------------------------------------------| ,---. |---------------|
|
||||
* |Shift | Z| X| C| V| B| N| M| ,| .| /| RO|Shift | |Up | | 1| 2| 3| |
|
||||
* |Shift | Z| X| C| V| B| N| M| ,| .| /| Shift | |Up | | 1| 2| 3| |
|
||||
* |-----------------------------------------------------------| ,-----------. |-----------|Ent|
|
||||
* | Ctrl| | Alt | Space | Alt | | Ctrl| |Lef|Dow|Rig| | 0| .| |
|
||||
* `-----' `---------------------------------------' `-----' `-----------' `---------------'
|
||||
|
|
@ -67,7 +67,7 @@ const uint8_t PROGMEM unimap_trans[MATRIX_ROWS][MATRIX_COLS] = {
|
|||
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, /* 70-77 */
|
||||
UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO, UNIMAP_NO }, /* 78-7F */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue