X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=protocol%2Fadb.c;h=9e8d76832dc82ab64ff53158b266c864d93d1d17;hb=48433a5e9988647a737234c11dd9db4080fd4a4e;hp=d60b8608b1ee9ce222b41f7d821fcdab1f044609;hpb=76033dcd892a115240c5a990e5643cd53acbca87;p=max%2Ftmk_keyboard.git diff --git a/protocol/adb.c b/protocol/adb.c index d60b8608..9e8d7683 100644 --- a/protocol/adb.c +++ b/protocol/adb.c @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "adb.h" @@ -66,6 +67,12 @@ void adb_host_init(void) #ifdef ADB_PSW_BIT psw_hi(); #endif + + // Enable keyboard left/right modifier distinction + // Addr:Keyboard(0010), Cmd:Listen(10), Register3(11) + // upper byte: reserved bits 0000, device address 0010 + // lower byte: device handler 00000011 + adb_host_listen(0x2B,0x02,0x03); } #ifdef ADB_PSW_BIT @@ -85,26 +92,39 @@ uint16_t adb_host_kbd_recv(void) return 0; // No data to send if (!read_bit()) // Startbit(1) return -2; + + // ad hoc fix: without block inerrupt read wrong bit occasionally and get keys stuck + cli(); data = read_byte(); data = (data<<8) | read_byte(); + sei(); + if (read_bit()) // Stopbit(0) return -3; return data; } -// send state of LEDs -void adb_host_kbd_led(uint8_t led) +void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) { attention(); - send_byte(0x2A); // Addr:Keyboard(0010), Cmd:Listen(10), Register2(10) + send_byte(cmd); place_bit0(); // Stopbit(0) _delay_us(200); // Tlt/Stop to Start place_bit1(); // Startbit(1) - send_byte(0); // send upper byte (not used) - send_byte(led&0x07); // send lower byte (bit2: ScrollLock, bit1: CapsLock, bit0: NumLock) + send_byte(data_h); + send_byte(data_l); place_bit0(); // Stopbit(0); } +// send state of LEDs +void adb_host_kbd_led(uint8_t led) +{ + // Addr:Keyboard(0010), Cmd:Listen(10), Register2(10) + // send upper byte (not used) + // send lower byte (bit2: ScrollLock, bit1: CapsLock, bit0: + adb_host_listen(0x2A,0,led&0x07); +} + static inline void data_lo() { @@ -244,6 +264,7 @@ ADB Keycode http://72.0.193.250/Documentation/macppc/adbkeycodes/ http://m0115.web.fc2.com/m0115.jpg [Inside Macintosh volume V, pages 191-192] + http://www.opensource.apple.com/source/IOHIDFamily/IOHIDFamily-421.18.3/IOHIDFamily/Cosmo_USB2ADB.c ADB Signaling http://kbdbabel.sourceforge.net/doc/kbd_signaling_pcxt_ps2_adb.pdf ADB Overview & History