From: tmk Date: Sun, 20 Sep 2015 01:33:25 +0000 (+0900) Subject: next_usb: Fix next_kbd_set_leds() X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=9b99f8f8649c25b5efa92c9fd49b7f4c0ce60a76;p=max%2Ftmk_keyboard.git next_usb: Fix next_kbd_set_leds() --- diff --git a/tmk_core/protocol/next_kbd.c b/tmk_core/protocol/next_kbd.c index a5a07a7a..fa3034b3 100644 --- a/tmk_core/protocol/next_kbd.c +++ b/tmk_core/protocol/next_kbd.c @@ -59,10 +59,16 @@ static inline void query(void); static inline void reset(void); static inline uint32_t response(void); -#define out_hi_delay(intervals) do { out_hi(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); -#define out_lo_delay(intervals) do { out_lo(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); -#define query_delay(intervals) do { query(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); -#define reset_delay(intervals) do { reset(); _delay_us(NEXT_KBD_TIMING * intervals); } while (0); +/* The keyboard sends signal with 50us pulse width on OUT line + * while it seems to miss the 50us pulse on In line. + * next_kbd_set_leds() often fails to sync LED status with 50us + * but it works well with 51us(+1us) on TMK converter(ATMeaga32u2) at least. + * TODO: test on Teensy and Pro Micro configuration + */ +#define out_hi_delay(intervals) do { out_hi(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0); +#define out_lo_delay(intervals) do { out_lo(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0); +#define query_delay(intervals) do { query(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0); +#define reset_delay(intervals) do { reset(); _delay_us((NEXT_KBD_TIMING+1) * intervals); } while (0); void next_kbd_init(void) { @@ -79,6 +85,7 @@ void next_kbd_init(void) void next_kbd_set_leds(bool left, bool right) { + cli(); out_lo_delay(9); out_hi_delay(3); @@ -98,6 +105,7 @@ void next_kbd_set_leds(bool left, bool right) out_lo_delay(7); out_hi(); + sei(); } #define NEXT_KBD_READ (NEXT_KBD_IN_PIN&(1<