1
0

Merge branch 'adb_iso_fix'

This commit is contained in:
tmk 2016-05-19 16:29:13 +09:00
commit f43a2df761
6 changed files with 226 additions and 65 deletions

View File

@ -56,7 +56,7 @@ SRC = keymap_common.c \
ifdef KEYMAP ifdef KEYMAP
SRC := keymap_$(KEYMAP).c $(SRC) SRC := keymap_$(KEYMAP).c $(SRC)
else else
SRC := keymap_ansi.c $(SRC) SRC := keymap_plain.c $(SRC)
endif endif
CONFIG_H = config.h CONFIG_H = config.h

View File

@ -33,6 +33,49 @@ extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint16_t fn_actions[]; extern const uint16_t fn_actions[];
/* Common layout: ANSI+ISO
* ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,---.
* |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|
* `---' `---------------' `---------------' `---------------' `-----------' `---'
* ,-----------------------------------------------------------. ,-----------. ,---------------.
* | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| |Ins|Hom|PgU| |NmL| =| /| *|
* |-----------------------------------------------------------| |-----------| |---------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| -|
* |-----------------------------------------------------------| `-----------' |---------------|
* |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| +|
* |-----------------------------------------------------------| ,---. |---------------|
* |Shif|\ | Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| |
* |-----------------------------------------------------------| ,-----------. |-----------|Ent|
* |Ctrl |Opt |Cmd | Space | |Opt |Ctrl | |Lef|Dow|Rig| | 0| .| |
* `-----------------------------------------------------------' `-----------' `---------------'
*/
#define KEYMAP( \
K35, K7A,K78,K63,K76, K60,K61,K62,K64, K65,K6D,K67,K6F, K69,K6B,K71, K7F, \
K32,K12,K13,K14,K15,K17,K16,K1A,K1C,K19,K1D,K1B,K18,K33, K72,K73,K74, K47,K51,K4B,K43, \
K30,K0C,K0D,K0E,K0F,K11,K10,K20,K22,K1F,K23,K21,K1E,K2A, K75,K77,K79, K59,K5B,K5C,K4E, \
K39,K00,K01,K02,K03,K05,K04,K26,K28,K25,K29,K27, K24, K56,K57,K58,K45, \
K38,K0A,K06,K07,K08,K09,K0B,K2D,K2E,K2B,K2F,K2C, K7B, K3E, K53,K54,K55, \
K36,K3A,K37, K31, K7C,K7D, K3B,K3D,K3C, K52, K41,K4C \
) { \
{ KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
{ KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_##K0F }, \
{ KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
{ KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
{ KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
{ KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
{ KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_PENT, KC_##K35, KC_##K36, KC_##K37 }, \
{ KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_NO }, \
{ KC_F17, KC_##K41, KC_NO, KC_##K43, KC_F18, KC_##K45, KC_NO, KC_##K47 }, \
{ KC_NO, KC_NO, KC_NO, KC_##K4B, KC_##K4C, KC_NO, KC_##K4E, KC_F18 }, \
{ KC_F19, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
{ KC_##K58, KC_##K59, KC_F20, KC_##K5B, KC_##K5C, KC_INT3, KC_INT1, KC_PCMM }, \
{ KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_LANG2, KC_##K67 }, \
{ KC_LANG1, KC_##K69, KC_F16, KC_##K6B, KC_NO, KC_##K6D, KC_APP, KC_##K6F }, \
{ KC_NO, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_##K77 }, \
{ KC_##K78, KC_##K79, KC_##K7A, KC_##K7B, KC_##K7C, KC_##K7D, KC_NO, KC_##K7F } \
}
/* M0115 Apple Extended Keyboard ANSI /* M0115 Apple Extended Keyboard ANSI
* ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,---. * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,---.
* |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr| * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|
@ -93,10 +136,10 @@ extern const uint16_t fn_actions[];
*/ */
#define KEYMAP_EXT_ISO( \ #define KEYMAP_EXT_ISO( \
K35, K7A,K78,K63,K76, K60,K61,K62,K64, K65,K6D,K67,K6F, K69,K6B,K71, K7F, \ K35, K7A,K78,K63,K76, K60,K61,K62,K64, K65,K6D,K67,K6F, K69,K6B,K71, K7F, \
K0A,K12,K13,K14,K15,K17,K16,K1A,K1C,K19,K1D,K1B,K18,K33, K72,K73,K74, K47,K51,K4B,K43, \ K32,K12,K13,K14,K15,K17,K16,K1A,K1C,K19,K1D,K1B,K18,K33, K72,K73,K74, K47,K51,K4B,K43, \
K30,K0C,K0D,K0E,K0F,K11,K10,K20,K22,K1F,K23,K21,K1E,K24, K75,K77,K79, K59,K5B,K5C,K4E, \ K30,K0C,K0D,K0E,K0F,K11,K10,K20,K22,K1F,K23,K21,K1E,K24, K75,K77,K79, K59,K5B,K5C,K4E, \
K39,K00,K01,K02,K03,K05,K04,K26,K28,K25,K29,K27,K2A, K56,K57,K58,K45, \ K39,K00,K01,K02,K03,K05,K04,K26,K28,K25,K29,K27,K2A, K56,K57,K58,K45, \
K38,K32,K06,K07,K08,K09,K0B,K2D,K2E,K2B,K2F,K2C, K7B, K3E, K53,K54,K55, \ K38,K0A,K06,K07,K08,K09,K0B,K2D,K2E,K2B,K2F,K2C, K7B, K3E, K53,K54,K55, \
K36,K3A,K37, K31, K7C,K7D, K3B,K3D,K3C, K52, K41,K4C \ K36,K3A,K37, K31, K7C,K7D, K3B,K3D,K3C, K52, K41,K4C \
) { \ ) { \
{ KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \ { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
@ -183,16 +226,16 @@ extern const uint16_t fn_actions[];
K35,K12,K13,K14,K15,K17,K16,K1A,K1C,K19,K1D,K1B,K18,K33, K47,K51,K4B,K43, \ K35,K12,K13,K14,K15,K17,K16,K1A,K1C,K19,K1D,K1B,K18,K33, K47,K51,K4B,K43, \
K30,K0C,K0D,K0E,K0F,K11,K10,K20,K22,K1F,K23,K21,K1E, K59,K5B,K5C,K45, \ K30,K0C,K0D,K0E,K0F,K11,K10,K20,K22,K1F,K23,K21,K1E, K59,K5B,K5C,K45, \
K39,K00,K01,K02,K03,K05,K04,K26,K28,K25,K29,K27,K2A,K24, K56,K57,K58,K4E, \ K39,K00,K01,K02,K03,K05,K04,K26,K28,K25,K29,K27,K2A,K24, K56,K57,K58,K4E, \
K38,K32,K06,K07,K08,K09,K0B,K2D,K2E,K2B,K2F,K2C,K7B,K3E, K53,K54,K55, \ K38,K0A,K06,K07,K08,K09,K0B,K2D,K2E,K2B,K2F,K2C,K7B,K3E, K53,K54,K55, \
K36,K3A,K37, K31, K3B,K3C,K3D, K52, K41,K4C \ K36,K3A,K37, K31, K3B,K3C,K3D, K52, K41,K4C \
) { \ ) { \
{ KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \ { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
{ KC_##K08, KC_##K09, KC_NO, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_##K0F }, \ { KC_##K08, KC_##K09, KC_##K0A KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_##K0F }, \
{ KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \ { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
{ KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \ { KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
{ KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \ { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
{ KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \ { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
{ KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_NO, KC_##K35, KC_##K36, KC_##K37 }, \ { KC_##K30, KC_##K31, KC_NO, KC_##K33, KC_NO, KC_##K35, KC_##K36, KC_##K37 }, \
{ KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_NO }, \ { KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_NO }, \
{ KC_NO, KC_##K41, KC_NO, KC_##K43, KC_NO, KC_##K45, KC_NO, KC_##K47 }, \ { KC_NO, KC_##K41, KC_NO, KC_##K43, KC_NO, KC_##K45, KC_NO, KC_##K47 }, \
{ KC_NO, KC_NO, KC_NO, KC_##K4B, KC_##K4C, KC_NO, KC_##K4E, KC_NO }, \ { KC_NO, KC_NO, KC_NO, KC_##K4B, KC_##K4C, KC_NO, KC_##K4E, KC_NO }, \

View File

@ -0,0 +1,42 @@
#include "keymap_common.h"
/*
* ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,---.
* |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|
* `---' `---------------' `---------------' `---------------' `-----------' `---'
* ,-----------------------------------------------------------. ,-----------. ,---------------.
* | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| |Ins|Hom|PgU| |NmL| =| /| *|
* |-----------------------------------------------------------| |-----------| |---------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| -|
* |-----------------------------------------------------------| `-----------' |---------------|
* |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| +|
* |-----------------------------------------------------------| ,---. |---------------|
* |Shif|\ | Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| |
* |-----------------------------------------------------------| ,-----------. |-----------|Ent|
* |Ctrl |Opt |Cmd | Space | |Opt |Ctrl | |Lef|Dow|Rig| | 0| .| |
* `-----------------------------------------------------------' `-----------' `---------------'
*/
const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = KEYMAP(
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,PAUS, NO,
FN0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,EQL, PSLS,PAST,
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,FN1, DEL, END, PGDN, P7, P8, P9, PMNS,
LCAP,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS,
LSFT,NUBS,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3,
LCTL,LALT,LGUI, SPC, RALT,RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
),
[1] = KEYMAP(
GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, NO,
FN0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, INS, HOME,PGUP, NLCK,BTN1,BTN2,BTN3,
TAB, Q, W, E, R, T, Y, U, PSCR,SLCK,PAUS,UP, INS, FN1, DEL, END, PGDN, WH_D,MS_U,WH_U,WH_D,
LCAP,VOLD,VOLU,MUTE,F, G, H, J, HOME,PGUP,LEFT,RGHT, ENT, MS_L,MS_D,MS_R,WH_U,
LSFT,NUBS,Z, X, C, V, B, N, M, END, PGDN,DOWN, RSFT, PGUP, WH_L,MS_D,WH_R,
LCTL,LGUI,LALT, SPC, RGUI,RCTL, HOME,PGDN,END, BTN1, BTN2,BTN3
),
};
const uint16_t PROGMEM fn_actions[] = {
[0] = ACTION_LAYER_TAP_KEY(1, KC_GRV),
[1] = ACTION_LAYER_TAP_KEY(1, KC_BSLS),
};

View File

@ -39,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif #endif
static bool is_iso_layout = false;
static bool is_modified = false; static bool is_modified = false;
static report_mouse_t mouse_report = {}; static report_mouse_t mouse_report = {};
@ -72,6 +73,21 @@ void matrix_init(void)
adb_host_init(); adb_host_init();
// wait for keyboard to boot up and receive command // wait for keyboard to boot up and receive command
_delay_ms(1000); _delay_ms(1000);
// Determine ISO keyboard by handle id
// http://lxr.free-electrons.com/source/drivers/macintosh/adbhid.c?v=4.4#L815
uint16_t handle_id = adb_host_talk(ADB_ADDR_KEYBOARD, 3);
switch (handle_id) {
case 0x04: case 0x05: case 0x07: case 0x09: case 0x0D:
case 0x11: case 0x14: case 0x19: case 0x1D: case 0xC1:
case 0xC4: case 0xC7:
is_iso_layout = true;
break;
default:
is_iso_layout = false;
break;
}
// Enable keyboard left/right modifier distinction // Enable keyboard left/right modifier distinction
// Addr:Keyboard(0010), Cmd:Listen(10), Register3(11) // Addr:Keyboard(0010), Cmd:Listen(10), Register3(11)
// upper byte: reserved bits 0000, device address 0010 // upper byte: reserved bits 0000, device address 0010
@ -92,6 +108,9 @@ void matrix_init(void)
_delay_ms(500); _delay_ms(500);
DDRD |= (1<<6); PORTD &= ~(1<<6); DDRD |= (1<<6); PORTD &= ~(1<<6);
uint16_t handle_id2 = adb_host_talk(ADB_ADDR_KEYBOARD, 3);
xprintf("handle_id: %02X -> %02X\n", handle_id&0xff, handle_id2&0xff);
return; return;
} }
@ -106,10 +125,10 @@ void adb_mouse_task(void)
{ {
uint16_t codes; uint16_t codes;
int16_t x, y; int16_t x, y;
static int8_t mouseacc; static int8_t mouseacc;
_delay_ms(12); // delay for preventing overload of poor ADB keyboard controller _delay_ms(12); // delay for preventing overload of poor ADB keyboard controller
codes = adb_host_mouse_recv(); codes = adb_host_mouse_recv();
// If nothing received reset mouse acceleration, and quit. // If nothing received reset mouse acceleration, and quit.
if (!codes) { if (!codes) {
mouseacc = 1; mouseacc = 1;
return; return;
@ -119,12 +138,12 @@ void adb_mouse_task(void)
mouse_report.buttons |= MOUSE_BTN1; mouse_report.buttons |= MOUSE_BTN1;
if (codes & (1 << 15)) if (codes & (1 << 15))
mouse_report.buttons &= ~MOUSE_BTN1; mouse_report.buttons &= ~MOUSE_BTN1;
// lower seven bits are movement, as signed int_7. // lower seven bits are movement, as signed int_7.
// low byte is X-axis, high byte is Y. // low byte is X-axis, high byte is Y.
y = (codes>>8 & 0x3F); y = (codes>>8 & 0x3F);
x = (codes>>0 & 0x3F); x = (codes>>0 & 0x3F);
// bit seven and fifteen is negative // bit seven and fifteen is negative
// usb does not use int_8, but int_7 (measuring distance) with sign-bit. // usb does not use int_8, but int_7 (measuring distance) with sign-bit.
if (codes & (1 << 6)) if (codes & (1 << 6))
x = (x-0x40); x = (x-0x40);
if (codes & (1 << 14)) if (codes & (1 << 14))
@ -132,7 +151,7 @@ void adb_mouse_task(void)
// Accelerate mouse. (They weren't meant to be used on screens larger than 320x200). // Accelerate mouse. (They weren't meant to be used on screens larger than 320x200).
x *= mouseacc; x *= mouseacc;
y *= mouseacc; y *= mouseacc;
// Cap our two bytes per axis to one byte. // Cap our two bytes per axis to one byte.
// Easier with a MIN-function, but since -MAX(-a,-b) = MIN(a,b)... // Easier with a MIN-function, but since -MAX(-a,-b) = MIN(a,b)...
// I.E. MIN(MAX(x,-127),127) = -MAX(-MAX(x, -127), -127) = MIN(-MIN(-x,127),127) // I.E. MIN(MAX(x,-127),127) = -MAX(-MAX(x, -127), -127) = MIN(-MIN(-x,127),127)
mouse_report.x = -MAX(-MAX(x, -127), -127); mouse_report.x = -MAX(-MAX(x, -127), -127);
@ -145,7 +164,7 @@ void adb_mouse_task(void)
print_decs(mouse_report.x); print(" "); print_decs(mouse_report.x); print(" ");
print_decs(mouse_report.y); print("]\n"); print_decs(mouse_report.y); print("]\n");
} }
// Send result by usb. // Send result by usb.
host_mouse_send(&mouse_report); host_mouse_send(&mouse_report);
// increase acceleration of mouse // increase acceleration of mouse
mouseacc += ( mouseacc < ADB_MOUSE_MAXACC ? 1 : 0 ); mouseacc += ( mouseacc < ADB_MOUSE_MAXACC ? 1 : 0 );
@ -192,6 +211,45 @@ uint8_t matrix_scan(void)
xprintf("adb_host_kbd_recv: ERROR(%d)\n", codes); xprintf("adb_host_kbd_recv: ERROR(%d)\n", codes);
return key1; return key1;
} else { } else {
/* Swap codes for ISO keyboard
*
* ANSI
* ,----------- ----------.
* | *a| 1| 2 =|Backspa|
* |----------- ----------|
* |Tab | Q| | ]| *c|
* |----------- ----------|
* |CapsLo| A| '|Return |
* |----------- ----------|
* |Shift | Shift |
* `----------- ----------'
*
* ISO
* ,----------- ----------.
* | *a| 1| 2 =|Backspa|
* |----------- ----------|
* |Tab | Q| | ]|Retur|
* |----------- -----` |
* |CapsLo| A| '| *c| |
* |----------- ----------|
* |Shif| *b| Shift |
* `----------- ----------'
*
* ADB scan code USB usage
* ------------- ---------
* Key ANSI ISO ANSI ISO
* ---------------------------------------------
* *a 0x32 0x0A 0x35 0x35
* *b ---- 0x32 ---- 0x64
* *c 0x2A 0x2A 0x31 0x31(or 0x32)
*/
if (is_iso_layout) {
if (key0 == 0x32) {
key0 = 0x0A;
} else if (key0 == 0x0A) {
key0 = 0x32;
}
}
register_key(key0); register_key(key0);
if (key1 != 0xFF) // key1 is 0xFF when no second key. if (key1 != 0xFF) // key1 is 0xFF when no second key.
extra_key = key1<<8 | 0xFF; // process in a separate call extra_key = key1<<8 | 0xFF; // process in a separate call

View File

@ -60,7 +60,6 @@ static inline void place_bit1(void);
static inline void send_byte(uint8_t data); static inline void send_byte(uint8_t data);
static inline uint16_t wait_data_lo(uint16_t us); static inline uint16_t wait_data_lo(uint16_t us);
static inline uint16_t wait_data_hi(uint16_t us); static inline uint16_t wait_data_hi(uint16_t us);
static inline uint16_t adb_host_dev_recv(uint8_t device);
void adb_host_init(void) void adb_host_init(void)
@ -87,49 +86,9 @@ bool adb_host_psw(void)
* <http://geekhack.org/index.php?topic=14290.msg1068919#msg1068919> * <http://geekhack.org/index.php?topic=14290.msg1068919#msg1068919>
* <http://geekhack.org/index.php?topic=14290.msg1070139#msg1070139> * <http://geekhack.org/index.php?topic=14290.msg1070139#msg1070139>
*/ */
// ADB Bit Cells
//
// bit cell time: 70-130us
// low part of bit0: 60-70% of bit cell
// low part of bit1: 30-40% of bit cell
//
// bit cell time 70us 130us
// --------------------------------------------
// low part of bit0 42-49 78-91
// high part of bit0 21-28 39-52
// low part of bit1 21-28 39-52
// high part of bit1 42-49 78-91
//
//
// bit0:
// 70us bit cell:
// ____________~~~~~~
// 42-49 21-28
//
// 130us bit cell:
// ____________~~~~~~
// 78-91 39-52
//
// bit1:
// 70us bit cell:
// ______~~~~~~~~~~~~
// 21-28 42-49
//
// 130us bit cell:
// ______~~~~~~~~~~~~
// 39-52 78-91
//
// [from Apple IIgs Hardware Reference Second Edition]
enum {
ADDR_KEYB = 0x20,
ADDR_MOUSE = 0x30
};
uint16_t adb_host_kbd_recv(void) uint16_t adb_host_kbd_recv(void)
{ {
return adb_host_dev_recv(ADDR_KEYB); return adb_host_talk(ADB_ADDR_KEYBOARD, ADB_REG_0);
} }
#ifdef ADB_MOUSE_ENABLE #ifdef ADB_MOUSE_ENABLE
@ -139,16 +98,16 @@ void adb_mouse_init(void) {
uint16_t adb_host_mouse_recv(void) uint16_t adb_host_mouse_recv(void)
{ {
return adb_host_dev_recv(ADDR_MOUSE); return adb_host_talk(ADB_ADDR_MOUSE, ADB_REG_0);
} }
#endif #endif
static inline uint16_t adb_host_dev_recv(uint8_t device) uint16_t adb_host_talk(uint8_t addr, uint8_t reg)
{ {
uint16_t data = 0; uint16_t data = 0;
cli(); cli();
attention(); attention();
send_byte(device|0x0C); // Addr:Keyboard(0010)/Mouse(0011), Cmd:Talk(11), Register0(00) send_byte((addr<<4) | (ADB_CMD_TALK<<2) | reg);
place_bit0(); // Stopbit(0) place_bit0(); // Stopbit(0)
if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored
sei(); sei();
@ -158,20 +117,20 @@ static inline uint16_t adb_host_dev_recv(uint8_t device)
sei(); sei();
return 0; // No data to send return 0; // No data to send
} }
uint8_t n = 17; // start bit + 16 data bits uint8_t n = 17; // start bit + 16 data bits
do { do {
uint8_t lo = (uint8_t) wait_data_hi(130); uint8_t lo = (uint8_t) wait_data_hi(130);
if (!lo) if (!lo)
goto error; goto error;
uint8_t hi = (uint8_t) wait_data_lo(lo); uint8_t hi = (uint8_t) wait_data_lo(lo);
if (!hi) if (!hi)
goto error; goto error;
hi = lo - hi; hi = lo - hi;
lo = 130 - lo; lo = 130 - lo;
data <<= 1; data <<= 1;
if (lo < hi) { if (lo < hi) {
data |= 1; data |= 1;
@ -205,7 +164,7 @@ void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l)
place_bit0(); // Stopbit(0) place_bit0(); // Stopbit(0)
_delay_us(200); // Tlt/Stop to Start _delay_us(200); // Tlt/Stop to Start
place_bit1(); // Startbit(1) place_bit1(); // Startbit(1)
send_byte(data_h); send_byte(data_h);
send_byte(data_l); send_byte(data_l);
place_bit0(); // Stopbit(0); place_bit0(); // Stopbit(0);
sei(); sei();
@ -375,7 +334,7 @@ Commands
A A A A 1 1 R R Talk(read from a device) A A A A 1 1 R R Talk(read from a device)
The command to read keycodes from keyboard is 0x2C which The command to read keycodes from keyboard is 0x2C which
consist of keyboard address 2 and Talk against register 0. consist of keyboard address 2 and Talk against register 0.
Address: Address:
2: keyboard 2: keyboard
@ -457,7 +416,7 @@ Keyboard Data(Register0)
Keyboard LEDs & state of keys(Register2) Keyboard LEDs & state of keys(Register2)
This register hold current state of three LEDs and nine keys. This register hold current state of three LEDs and nine keys.
The state of LEDs can be changed by sending Listen command. The state of LEDs can be changed by sending Listen command.
1514 . . . . . . 7 6 5 . 3 2 1 0 1514 . . . . . . 7 6 5 . 3 2 1 0
| | | | | | | | | | | | | | | +- LED1(NumLock) | | | | | | | | | | | | | | | +- LED1(NumLock)
| | | | | | | | | | | | | | +--- LED2(CapsLock) | | | | | | | | | | | | | | +--- LED2(CapsLock)
@ -474,5 +433,46 @@ Keyboard LEDs & state of keys(Register2)
| +----------------------------- Delete | +----------------------------- Delete
+------------------------------- Reserved +------------------------------- Reserved
ADB Bit Cells
bit cell time: 70-130us
low part of bit0: 60-70% of bit cell
low part of bit1: 30-40% of bit cell
bit cell time 70us 130us
--------------------------------------------
low part of bit0 42-49 78-91
high part of bit0 21-28 39-52
low part of bit1 21-28 39-52
high part of bit1 42-49 78-91
bit0:
70us bit cell:
____________~~~~~~
42-49 21-28
130us bit cell:
____________~~~~~~
78-91 39-52
bit1:
70us bit cell:
______~~~~~~~~~~~~
21-28 42-49
130us bit cell:
______~~~~~~~~~~~~
39-52 78-91
[from Apple IIgs Hardware Reference Second Edition]
Keyboard Handle ID
Apple Standard Keyboard M0116: 0x01
Apple Extended Keyboard M0115: 0x02
Apple Extended Keyboard II M3501: 0x02
Apple Adjustable Keybaord: 0x10
http://lxr.free-electrons.com/source/drivers/macintosh/adbhid.c?v=4.4#L802
END_OF_ADB END_OF_ADB
*/ */

View File

@ -52,11 +52,29 @@ POSSIBILITY OF SUCH DAMAGE.
#define ADB_CAPS 0x39 #define ADB_CAPS 0x39
/* ADB commands */
#define ADB_ADDR_KEYBOARD 2
#define ADB_ADDR_MOUSE 3
#define ADB_CMD_LISTEN 2
#define ADB_CMD_TALK 3
#define ADB_REG_0 0
#define ADB_REG_1 1
#define ADB_REG_2 2
#define ADB_REG_3 3
/* ADB keyboard handle id */
#define ADB_HANDLE_M0116 0x01
#define ADB_HANDLE_M0115 0x02
#define ADB_HANDLE_M3501 0x02
#define ADB_HANDLE_M1242 0x10
// ADB host // ADB host
void adb_host_init(void); void adb_host_init(void);
bool adb_host_psw(void); bool adb_host_psw(void);
uint16_t adb_host_kbd_recv(void); uint16_t adb_host_kbd_recv(void);
uint16_t adb_host_mouse_recv(void); uint16_t adb_host_mouse_recv(void);
uint16_t adb_host_talk(uint8_t addr, uint8_t reg);
void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l); void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l);
void adb_host_kbd_led(uint8_t led); void adb_host_kbd_led(uint8_t led);
void adb_mouse_task(void); void adb_mouse_task(void);