diff options
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/common.mk | 19 | ||||
| -rw-r--r-- | tmk_core/common/avr/suspend.c | 98 | ||||
| -rw-r--r-- | tmk_core/common/chibios/suspend.c | 85 | ||||
| -rw-r--r-- | tmk_core/common/suspend.h | 2 | ||||
| -rw-r--r-- | tmk_core/protocol/ibm4704.c | 185 | ||||
| -rw-r--r-- | tmk_core/protocol/ibm4704.h | 103 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa.mk | 27 | ||||
| -rw-r--r-- | tmk_core/protocol/news.c | 161 | ||||
| -rw-r--r-- | tmk_core/protocol/news.h | 48 | ||||
| -rw-r--r-- | tmk_core/protocol/next_kbd.c | 219 | ||||
| -rw-r--r-- | tmk_core/protocol/next_kbd.h | 60 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_hid/parser.h | 5 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_hid/usb_hid.h | 6 |
13 files changed, 8 insertions, 1010 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 7f7420059..e5eced56f 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk | |||
| @@ -55,8 +55,6 @@ ifeq ($(strip $(NKRO_ENABLE)), yes) | |||
| 55 | $(info NKRO is not currently supported on V-USB, and has been disabled.) | 55 | $(info NKRO is not currently supported on V-USB, and has been disabled.) |
| 56 | else ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) | 56 | else ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) |
| 57 | $(info NKRO is not currently supported with Bluetooth, and has been disabled.) | 57 | $(info NKRO is not currently supported with Bluetooth, and has been disabled.) |
| 58 | else ifneq ($(BLUETOOTH),) | ||
| 59 | $(info NKRO is not currently supported with Bluetooth, and has been disabled.) | ||
| 60 | else | 58 | else |
| 61 | TMK_COMMON_DEFS += -DNKRO_ENABLE | 59 | TMK_COMMON_DEFS += -DNKRO_ENABLE |
| 62 | SHARED_EP_ENABLE = yes | 60 | SHARED_EP_ENABLE = yes |
| @@ -77,23 +75,6 @@ ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes) | |||
| 77 | TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN | 75 | TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN |
| 78 | endif | 76 | endif |
| 79 | 77 | ||
| 80 | ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) | ||
| 81 | TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE | ||
| 82 | TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK | ||
| 83 | endif | ||
| 84 | |||
| 85 | ifeq ($(strip $(BLUETOOTH)), AdafruitBLE) | ||
| 86 | TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE | ||
| 87 | TMK_COMMON_DEFS += -DMODULE_ADAFRUIT_BLE | ||
| 88 | TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK | ||
| 89 | endif | ||
| 90 | |||
| 91 | ifeq ($(strip $(BLUETOOTH)), RN42) | ||
| 92 | TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE | ||
| 93 | TMK_COMMON_DEFS += -DMODULE_RN42 | ||
| 94 | TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK | ||
| 95 | endif | ||
| 96 | |||
| 97 | ifeq ($(strip $(SWAP_HANDS_ENABLE)), yes) | 78 | ifeq ($(strip $(SWAP_HANDS_ENABLE)), yes) |
| 98 | TMK_COMMON_DEFS += -DSWAP_HANDS_ENABLE | 79 | TMK_COMMON_DEFS += -DSWAP_HANDS_ENABLE |
| 99 | endif | 80 | endif |
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 690d7f38c..b614746e6 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
| @@ -16,25 +16,6 @@ | |||
| 16 | # include "vusb.h" | 16 | # include "vusb.h" |
| 17 | #endif | 17 | #endif |
| 18 | 18 | ||
| 19 | #ifdef BACKLIGHT_ENABLE | ||
| 20 | # include "backlight.h" | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #ifdef AUDIO_ENABLE | ||
| 24 | # include "audio.h" | ||
| 25 | #endif /* AUDIO_ENABLE */ | ||
| 26 | |||
| 27 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
| 28 | # include "rgblight.h" | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifdef LED_MATRIX_ENABLE | ||
| 32 | # include "led_matrix.h" | ||
| 33 | #endif | ||
| 34 | #ifdef RGB_MATRIX_ENABLE | ||
| 35 | # include "rgb_matrix.h" | ||
| 36 | #endif | ||
| 37 | |||
| 38 | /** \brief Suspend idle | 19 | /** \brief Suspend idle |
| 39 | * | 20 | * |
| 40 | * FIXME: needs doc | 21 | * FIXME: needs doc |
| @@ -50,17 +31,6 @@ void suspend_idle(uint8_t time) { | |||
| 50 | 31 | ||
| 51 | // TODO: This needs some cleanup | 32 | // TODO: This needs some cleanup |
| 52 | 33 | ||
| 53 | /** \brief Run keyboard level Power down | ||
| 54 | * | ||
| 55 | * FIXME: needs doc | ||
| 56 | */ | ||
| 57 | __attribute__((weak)) void suspend_power_down_user(void) {} | ||
| 58 | /** \brief Run keyboard level Power down | ||
| 59 | * | ||
| 60 | * FIXME: needs doc | ||
| 61 | */ | ||
| 62 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } | ||
| 63 | |||
| 64 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) | 34 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) |
| 65 | 35 | ||
| 66 | // clang-format off | 36 | // clang-format off |
| @@ -135,41 +105,9 @@ void suspend_power_down(void) { | |||
| 135 | if (!vusb_suspended) return; | 105 | if (!vusb_suspended) return; |
| 136 | #endif | 106 | #endif |
| 137 | 107 | ||
| 138 | suspend_power_down_kb(); | 108 | suspend_power_down_quantum(); |
| 139 | 109 | ||
| 140 | #ifndef NO_SUSPEND_POWER_DOWN | 110 | #ifndef NO_SUSPEND_POWER_DOWN |
| 141 | // Turn off backlight | ||
| 142 | # ifdef BACKLIGHT_ENABLE | ||
| 143 | backlight_set(0); | ||
| 144 | # endif | ||
| 145 | |||
| 146 | // Turn off LED indicators | ||
| 147 | uint8_t leds_off = 0; | ||
| 148 | # if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
| 149 | if (is_backlight_enabled()) { | ||
| 150 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | ||
| 151 | leds_off |= (1 << USB_LED_CAPS_LOCK); | ||
| 152 | } | ||
| 153 | # endif | ||
| 154 | led_set(leds_off); | ||
| 155 | |||
| 156 | // Turn off audio | ||
| 157 | # ifdef AUDIO_ENABLE | ||
| 158 | stop_all_notes(); | ||
| 159 | # endif | ||
| 160 | |||
| 161 | // Turn off underglow | ||
| 162 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
| 163 | rgblight_suspend(); | ||
| 164 | # endif | ||
| 165 | |||
| 166 | # if defined(LED_MATRIX_ENABLE) | ||
| 167 | led_matrix_set_suspend_state(true); | ||
| 168 | # endif | ||
| 169 | # if defined(RGB_MATRIX_ENABLE) | ||
| 170 | rgb_matrix_set_suspend_state(true); | ||
| 171 | # endif | ||
| 172 | |||
| 173 | // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt) | 111 | // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt) |
| 174 | # if defined(WDT_vect) | 112 | # if defined(WDT_vect) |
| 175 | power_down(WDTO_15MS); | 113 | power_down(WDTO_15MS); |
| @@ -189,18 +127,6 @@ bool suspend_wakeup_condition(void) { | |||
| 189 | return false; | 127 | return false; |
| 190 | } | 128 | } |
| 191 | 129 | ||
| 192 | /** \brief run user level code immediately after wakeup | ||
| 193 | * | ||
| 194 | * FIXME: needs doc | ||
| 195 | */ | ||
| 196 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} | ||
| 197 | |||
| 198 | /** \brief run keyboard level code immediately after wakeup | ||
| 199 | * | ||
| 200 | * FIXME: needs doc | ||
| 201 | */ | ||
| 202 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } | ||
| 203 | |||
| 204 | /** \brief run immediately after wakeup | 130 | /** \brief run immediately after wakeup |
| 205 | * | 131 | * |
| 206 | * FIXME: needs doc | 132 | * FIXME: needs doc |
| @@ -209,27 +135,7 @@ void suspend_wakeup_init(void) { | |||
| 209 | // clear keyboard state | 135 | // clear keyboard state |
| 210 | clear_keyboard(); | 136 | clear_keyboard(); |
| 211 | 137 | ||
| 212 | // Turn on backlight | 138 | suspend_wakeup_init_quantum(); |
| 213 | #ifdef BACKLIGHT_ENABLE | ||
| 214 | backlight_init(); | ||
| 215 | #endif | ||
| 216 | |||
| 217 | // Restore LED indicators | ||
| 218 | led_set(host_keyboard_leds()); | ||
| 219 | |||
| 220 | // Wake up underglow | ||
| 221 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
| 222 | rgblight_wakeup(); | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #if defined(LED_MATRIX_ENABLE) | ||
| 226 | led_matrix_set_suspend_state(false); | ||
| 227 | #endif | ||
| 228 | #if defined(RGB_MATRIX_ENABLE) | ||
| 229 | rgb_matrix_set_suspend_state(false); | ||
| 230 | #endif | ||
| 231 | |||
| 232 | suspend_wakeup_init_kb(); | ||
| 233 | } | 139 | } |
| 234 | 140 | ||
| 235 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) | 141 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) |
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 38517e06f..991fe6e08 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c | |||
| @@ -12,25 +12,6 @@ | |||
| 12 | #include "led.h" | 12 | #include "led.h" |
| 13 | #include "wait.h" | 13 | #include "wait.h" |
| 14 | 14 | ||
| 15 | #ifdef AUDIO_ENABLE | ||
| 16 | # include "audio.h" | ||
| 17 | #endif /* AUDIO_ENABLE */ | ||
| 18 | |||
| 19 | #ifdef BACKLIGHT_ENABLE | ||
| 20 | # include "backlight.h" | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
| 24 | # include "rgblight.h" | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifdef LED_MATRIX_ENABLE | ||
| 28 | # include "led_matrix.h" | ||
| 29 | #endif | ||
| 30 | #ifdef RGB_MATRIX_ENABLE | ||
| 31 | # include "rgb_matrix.h" | ||
| 32 | #endif | ||
| 33 | |||
| 34 | /** \brief suspend idle | 15 | /** \brief suspend idle |
| 35 | * | 16 | * |
| 36 | * FIXME: needs doc | 17 | * FIXME: needs doc |
| @@ -40,61 +21,12 @@ void suspend_idle(uint8_t time) { | |||
| 40 | wait_ms(time); | 21 | wait_ms(time); |
| 41 | } | 22 | } |
| 42 | 23 | ||
| 43 | /** \brief Run keyboard level Power down | ||
| 44 | * | ||
| 45 | * FIXME: needs doc | ||
| 46 | */ | ||
| 47 | __attribute__((weak)) void suspend_power_down_user(void) {} | ||
| 48 | /** \brief Run keyboard level Power down | ||
| 49 | * | ||
| 50 | * FIXME: needs doc | ||
| 51 | */ | ||
| 52 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } | ||
| 53 | |||
| 54 | /** \brief suspend power down | 24 | /** \brief suspend power down |
| 55 | * | 25 | * |
| 56 | * FIXME: needs doc | 26 | * FIXME: needs doc |
| 57 | */ | 27 | */ |
| 58 | void suspend_power_down(void) { | 28 | void suspend_power_down(void) { |
| 59 | #ifdef BACKLIGHT_ENABLE | 29 | suspend_power_down_quantum(); |
| 60 | backlight_set(0); | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #ifdef LED_MATRIX_ENABLE | ||
| 64 | led_matrix_task(); | ||
| 65 | #endif | ||
| 66 | #ifdef RGB_MATRIX_ENABLE | ||
| 67 | rgb_matrix_task(); | ||
| 68 | #endif | ||
| 69 | |||
| 70 | // Turn off LED indicators | ||
| 71 | uint8_t leds_off = 0; | ||
| 72 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
| 73 | if (is_backlight_enabled()) { | ||
| 74 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | ||
| 75 | leds_off |= (1 << USB_LED_CAPS_LOCK); | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | led_set(leds_off); | ||
| 79 | |||
| 80 | // TODO: figure out what to power down and how | ||
| 81 | // shouldn't power down TPM/FTM if we want a breathing LED | ||
| 82 | // also shouldn't power down USB | ||
| 83 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
| 84 | rgblight_suspend(); | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #if defined(LED_MATRIX_ENABLE) | ||
| 88 | led_matrix_set_suspend_state(true); | ||
| 89 | #endif | ||
| 90 | #if defined(RGB_MATRIX_ENABLE) | ||
| 91 | rgb_matrix_set_suspend_state(true); | ||
| 92 | #endif | ||
| 93 | #ifdef AUDIO_ENABLE | ||
| 94 | stop_all_notes(); | ||
| 95 | #endif /* AUDIO_ENABLE */ | ||
| 96 | |||
| 97 | suspend_power_down_kb(); | ||
| 98 | // on AVR, this enables the watchdog for 15ms (max), and goes to | 30 | // on AVR, this enables the watchdog for 15ms (max), and goes to |
| 99 | // SLEEP_MODE_PWR_DOWN | 31 | // SLEEP_MODE_PWR_DOWN |
| 100 | 32 | ||
| @@ -151,19 +83,6 @@ void suspend_wakeup_init(void) { | |||
| 151 | host_system_send(0); | 83 | host_system_send(0); |
| 152 | host_consumer_send(0); | 84 | host_consumer_send(0); |
| 153 | #endif /* EXTRAKEY_ENABLE */ | 85 | #endif /* EXTRAKEY_ENABLE */ |
| 154 | #ifdef BACKLIGHT_ENABLE | ||
| 155 | backlight_init(); | ||
| 156 | #endif /* BACKLIGHT_ENABLE */ | ||
| 157 | led_set(host_keyboard_leds()); | ||
| 158 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
| 159 | rgblight_wakeup(); | ||
| 160 | #endif | ||
| 161 | 86 | ||
| 162 | #if defined(LED_MATRIX_ENABLE) | 87 | suspend_wakeup_init_quantum(); |
| 163 | led_matrix_set_suspend_state(false); | ||
| 164 | #endif | ||
| 165 | #if defined(RGB_MATRIX_ENABLE) | ||
| 166 | rgb_matrix_set_suspend_state(false); | ||
| 167 | #endif | ||
| 168 | suspend_wakeup_init_kb(); | ||
| 169 | } | 88 | } |
diff --git a/tmk_core/common/suspend.h b/tmk_core/common/suspend.h index 95845e4b6..081735f90 100644 --- a/tmk_core/common/suspend.h +++ b/tmk_core/common/suspend.h | |||
| @@ -10,8 +10,10 @@ void suspend_wakeup_init(void); | |||
| 10 | 10 | ||
| 11 | void suspend_wakeup_init_user(void); | 11 | void suspend_wakeup_init_user(void); |
| 12 | void suspend_wakeup_init_kb(void); | 12 | void suspend_wakeup_init_kb(void); |
| 13 | void suspend_wakeup_init_quantum(void); | ||
| 13 | void suspend_power_down_user(void); | 14 | void suspend_power_down_user(void); |
| 14 | void suspend_power_down_kb(void); | 15 | void suspend_power_down_kb(void); |
| 16 | void suspend_power_down_quantum(void); | ||
| 15 | 17 | ||
| 16 | #ifndef USB_SUSPEND_WAKEUP_DELAY | 18 | #ifndef USB_SUSPEND_WAKEUP_DELAY |
| 17 | # define USB_SUSPEND_WAKEUP_DELAY 0 | 19 | # define USB_SUSPEND_WAKEUP_DELAY 0 |
diff --git a/tmk_core/protocol/ibm4704.c b/tmk_core/protocol/ibm4704.c deleted file mode 100644 index a19443976..000000000 --- a/tmk_core/protocol/ibm4704.c +++ /dev/null | |||
| @@ -1,185 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2010,2011,2012,2013 Jun WAKO <wakojun@gmail.com> | ||
| 3 | */ | ||
| 4 | #include <stdbool.h> | ||
| 5 | #include <util/delay.h> | ||
| 6 | #include "debug.h" | ||
| 7 | #include "ring_buffer.h" | ||
| 8 | #include "ibm4704.h" | ||
| 9 | |||
| 10 | #define WAIT(stat, us, err) \ | ||
| 11 | do { \ | ||
| 12 | if (!wait_##stat(us)) { \ | ||
| 13 | ibm4704_error = err; \ | ||
| 14 | goto ERROR; \ | ||
| 15 | } \ | ||
| 16 | } while (0) | ||
| 17 | |||
| 18 | uint8_t ibm4704_error = 0; | ||
| 19 | |||
| 20 | void ibm4704_init(void) { | ||
| 21 | inhibit(); // keep keyboard from sending | ||
| 22 | IBM4704_INT_INIT(); | ||
| 23 | IBM4704_INT_ON(); | ||
| 24 | idle(); // allow keyboard sending | ||
| 25 | } | ||
| 26 | |||
| 27 | /* | ||
| 28 | Host to Keyboard | ||
| 29 | ---------------- | ||
| 30 | Data bits are LSB first and Parity is odd. Clock has around 60us high and 30us low part. | ||
| 31 | |||
| 32 | ____ __ __ __ __ __ __ __ __ __ ________ | ||
| 33 | Clock \______/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ | ||
| 34 | ^ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ___ | ||
| 35 | Data ____|__/ X____X____X____X____X____X____X____X____X____X \___ | ||
| 36 | | Start 0 1 2 3 4 5 6 7 P Stop | ||
| 37 | Request by host | ||
| 38 | |||
| 39 | Start bit: can be long as 300-350us. | ||
| 40 | Request: Host pulls Clock line down to request to send a command. | ||
| 41 | Timing: After Request keyboard pull up Data and down Clock line to low for start bit. | ||
| 42 | After request host release Clock line once Data line becomes hi. | ||
| 43 | Host writes a bit while Clock is hi and Keyboard reads while low. | ||
| 44 | Stop bit: Host releases or pulls up Data line to hi after 9th clock and waits for keyboard pull down the line to lo. | ||
| 45 | */ | ||
| 46 | uint8_t ibm4704_send(uint8_t data) { | ||
| 47 | bool parity = true; // odd parity | ||
| 48 | ibm4704_error = 0; | ||
| 49 | |||
| 50 | IBM4704_INT_OFF(); | ||
| 51 | |||
| 52 | /* Request to send */ | ||
| 53 | idle(); | ||
| 54 | clock_lo(); | ||
| 55 | |||
| 56 | /* wait for Start bit(Clock:lo/Data:hi) */ | ||
| 57 | WAIT(data_hi, 300, 0x30); | ||
| 58 | |||
| 59 | /* Data bit */ | ||
| 60 | for (uint8_t i = 0; i < 8; i++) { | ||
| 61 | WAIT(clock_hi, 100, 0x40 + i); | ||
| 62 | if (data & (1 << i)) { | ||
| 63 | parity = !parity; | ||
| 64 | data_hi(); | ||
| 65 | } else { | ||
| 66 | data_lo(); | ||
| 67 | } | ||
| 68 | WAIT(clock_lo, 100, 0x48 + i); | ||
| 69 | } | ||
| 70 | |||
| 71 | /* Parity bit */ | ||
| 72 | WAIT(clock_hi, 100, 0x34); | ||
| 73 | if (parity) { | ||
| 74 | data_hi(); | ||
| 75 | } else { | ||
| 76 | data_lo(); | ||
| 77 | } | ||
| 78 | WAIT(clock_lo, 100, 0x35); | ||
| 79 | |||
| 80 | /* Stop bit */ | ||
| 81 | WAIT(clock_hi, 100, 0x34); | ||
| 82 | data_hi(); | ||
| 83 | |||
| 84 | /* End */ | ||
| 85 | WAIT(data_lo, 100, 0x36); | ||
| 86 | |||
| 87 | idle(); | ||
| 88 | IBM4704_INT_ON(); | ||
| 89 | return 0; | ||
| 90 | ERROR: | ||
| 91 | idle(); | ||
| 92 | if (ibm4704_error > 0x30) { | ||
| 93 | xprintf("S:%02X ", ibm4704_error); | ||
| 94 | } | ||
| 95 | IBM4704_INT_ON(); | ||
| 96 | return -1; | ||
| 97 | } | ||
| 98 | |||
| 99 | /* wait forever to receive data */ | ||
| 100 | uint8_t ibm4704_recv_response(void) { | ||
| 101 | while (!rbuf_has_data()) { | ||
| 102 | _delay_ms(1); | ||
| 103 | } | ||
| 104 | return rbuf_dequeue(); | ||
| 105 | } | ||
| 106 | |||
| 107 | uint8_t ibm4704_recv(void) { | ||
| 108 | if (rbuf_has_data()) { | ||
| 109 | return rbuf_dequeue(); | ||
| 110 | } else { | ||
| 111 | return -1; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | /* | ||
| 116 | Keyboard to Host | ||
| 117 | ---------------- | ||
| 118 | Data bits are LSB first and Parity is odd. Clock has around 60us high and 30us low part. | ||
| 119 | |||
| 120 | ____ __ __ __ __ __ __ __ __ __ _______ | ||
| 121 | Clock \_____/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ | ||
| 122 | ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ | ||
| 123 | Data ____/ X____X____X____X____X____X____X____X____X____X________ | ||
| 124 | Start 0 1 2 3 4 5 6 7 P Stop | ||
| 125 | |||
| 126 | Start bit: can be long as 300-350us. | ||
| 127 | Inhibit: Pull Data line down to inhibit keyboard to send. | ||
| 128 | Timing: Host reads bit while Clock is hi.(rising edge) | ||
| 129 | Stop bit: Keyboard pulls down Data line to lo after 9th clock. | ||
| 130 | */ | ||
| 131 | ISR(IBM4704_INT_VECT) { | ||
| 132 | static enum { BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, PARITY, STOP } state = BIT0; | ||
| 133 | // LSB first | ||
| 134 | static uint8_t data = 0; | ||
| 135 | // Odd parity | ||
| 136 | static uint8_t parity = false; | ||
| 137 | |||
| 138 | ibm4704_error = 0; | ||
| 139 | |||
| 140 | switch (state) { | ||
| 141 | case BIT0: | ||
| 142 | case BIT1: | ||
| 143 | case BIT2: | ||
| 144 | case BIT3: | ||
| 145 | case BIT4: | ||
| 146 | case BIT5: | ||
| 147 | case BIT6: | ||
| 148 | case BIT7: | ||
| 149 | data >>= 1; | ||
| 150 | if (data_in()) { | ||
| 151 | data |= 0x80; | ||
| 152 | parity = !parity; | ||
| 153 | } | ||
| 154 | break; | ||
| 155 | case PARITY: | ||
| 156 | if (data_in()) { | ||
| 157 | parity = !parity; | ||
| 158 | } | ||
| 159 | if (!parity) goto ERROR; | ||
| 160 | break; | ||
| 161 | case STOP: | ||
| 162 | // Data:Low | ||
| 163 | WAIT(data_lo, 100, state); | ||
| 164 | if (!rbuf_enqueue(data)) { | ||
| 165 | print("rbuf: full\n"); | ||
| 166 | } | ||
| 167 | ibm4704_error = IBM4704_ERR_NONE; | ||
| 168 | goto DONE; | ||
| 169 | break; | ||
| 170 | default: | ||
| 171 | goto ERROR; | ||
| 172 | } | ||
| 173 | state++; | ||
| 174 | goto RETURN; | ||
| 175 | ERROR: | ||
| 176 | ibm4704_error = state; | ||
| 177 | while (ibm4704_send(0xFE)) _delay_ms(1); // resend | ||
| 178 | xprintf("R:%02X%02X\n", state, data); | ||
| 179 | DONE: | ||
| 180 | state = BIT0; | ||
| 181 | data = 0; | ||
| 182 | parity = false; | ||
| 183 | RETURN: | ||
| 184 | return; | ||
| 185 | } | ||
diff --git a/tmk_core/protocol/ibm4704.h b/tmk_core/protocol/ibm4704.h deleted file mode 100644 index 4f88d148b..000000000 --- a/tmk_core/protocol/ibm4704.h +++ /dev/null | |||
| @@ -1,103 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Jun WAKO <wakojun@gmail.com> | ||
| 3 | */ | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #define IBM4704_ERR_NONE 0 | ||
| 8 | #define IBM4704_ERR_PARITY 0x70 | ||
| 9 | |||
| 10 | void ibm4704_init(void); | ||
| 11 | uint8_t ibm4704_send(uint8_t data); | ||
| 12 | uint8_t ibm4704_recv_response(void); | ||
| 13 | uint8_t ibm4704_recv(void); | ||
| 14 | |||
| 15 | /* Check pin configuration */ | ||
| 16 | #if !(defined(IBM4704_CLOCK_PORT) && defined(IBM4704_CLOCK_PIN) && defined(IBM4704_CLOCK_DDR) && defined(IBM4704_CLOCK_BIT)) | ||
| 17 | # error "ibm4704 clock pin configuration is required in config.h" | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #if !(defined(IBM4704_DATA_PORT) && defined(IBM4704_DATA_PIN) && defined(IBM4704_DATA_DDR) && defined(IBM4704_DATA_BIT)) | ||
| 21 | # error "ibm4704 data pin configuration is required in config.h" | ||
| 22 | #endif | ||
| 23 | |||
| 24 | /*-------------------------------------------------------------------- | ||
| 25 | * static functions | ||
| 26 | *------------------------------------------------------------------*/ | ||
| 27 | static inline void clock_lo(void) { | ||
| 28 | IBM4704_CLOCK_PORT &= ~(1 << IBM4704_CLOCK_BIT); | ||
| 29 | IBM4704_CLOCK_DDR |= (1 << IBM4704_CLOCK_BIT); | ||
| 30 | } | ||
| 31 | static inline void clock_hi(void) { | ||
| 32 | /* input with pull up */ | ||
| 33 | IBM4704_CLOCK_DDR &= ~(1 << IBM4704_CLOCK_BIT); | ||
| 34 | IBM4704_CLOCK_PORT |= (1 << IBM4704_CLOCK_BIT); | ||
| 35 | } | ||
| 36 | static inline bool clock_in(void) { | ||
| 37 | IBM4704_CLOCK_DDR &= ~(1 << IBM4704_CLOCK_BIT); | ||
| 38 | IBM4704_CLOCK_PORT |= (1 << IBM4704_CLOCK_BIT); | ||
| 39 | _delay_us(1); | ||
| 40 | return IBM4704_CLOCK_PIN & (1 << IBM4704_CLOCK_BIT); | ||
| 41 | } | ||
| 42 | static inline void data_lo(void) { | ||
| 43 | IBM4704_DATA_PORT &= ~(1 << IBM4704_DATA_BIT); | ||
| 44 | IBM4704_DATA_DDR |= (1 << IBM4704_DATA_BIT); | ||
| 45 | } | ||
| 46 | static inline void data_hi(void) { | ||
| 47 | /* input with pull up */ | ||
| 48 | IBM4704_DATA_DDR &= ~(1 << IBM4704_DATA_BIT); | ||
| 49 | IBM4704_DATA_PORT |= (1 << IBM4704_DATA_BIT); | ||
| 50 | } | ||
| 51 | static inline bool data_in(void) { | ||
| 52 | IBM4704_DATA_DDR &= ~(1 << IBM4704_DATA_BIT); | ||
| 53 | IBM4704_DATA_PORT |= (1 << IBM4704_DATA_BIT); | ||
| 54 | _delay_us(1); | ||
| 55 | return IBM4704_DATA_PIN & (1 << IBM4704_DATA_BIT); | ||
| 56 | } | ||
| 57 | |||
| 58 | static inline uint16_t wait_clock_lo(uint16_t us) { | ||
| 59 | while (clock_in() && us) { | ||
| 60 | asm(""); | ||
| 61 | _delay_us(1); | ||
| 62 | us--; | ||
| 63 | } | ||
| 64 | return us; | ||
| 65 | } | ||
| 66 | static inline uint16_t wait_clock_hi(uint16_t us) { | ||
| 67 | while (!clock_in() && us) { | ||
| 68 | asm(""); | ||
| 69 | _delay_us(1); | ||
| 70 | us--; | ||
| 71 | } | ||
| 72 | return us; | ||
| 73 | } | ||
| 74 | static inline uint16_t wait_data_lo(uint16_t us) { | ||
| 75 | while (data_in() && us) { | ||
| 76 | asm(""); | ||
| 77 | _delay_us(1); | ||
| 78 | us--; | ||
| 79 | } | ||
| 80 | return us; | ||
| 81 | } | ||
| 82 | static inline uint16_t wait_data_hi(uint16_t us) { | ||
| 83 | while (!data_in() && us) { | ||
| 84 | asm(""); | ||
| 85 | _delay_us(1); | ||
| 86 | us--; | ||
| 87 | } | ||
| 88 | return us; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* idle state that device can send */ | ||
| 92 | static inline void idle(void) { | ||
| 93 | clock_hi(); | ||
| 94 | data_hi(); | ||
| 95 | } | ||
| 96 | |||
| 97 | /* inhibit device to send | ||
| 98 | * keyboard checks Data line on start bit(Data:hi) and it stops sending if Data line is low. | ||
| 99 | */ | ||
| 100 | static inline void inhibit(void) { | ||
| 101 | clock_hi(); | ||
| 102 | data_lo(); | ||
| 103 | } | ||
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk index c8935dacb..00fec478a 100644 --- a/tmk_core/protocol/lufa.mk +++ b/tmk_core/protocol/lufa.mk | |||
| @@ -3,7 +3,6 @@ LUFA_DIR = protocol/lufa | |||
| 3 | # Path to the LUFA library | 3 | # Path to the LUFA library |
| 4 | LUFA_PATH = $(LIB_PATH)/lufa | 4 | LUFA_PATH = $(LIB_PATH)/lufa |
| 5 | 5 | ||
| 6 | |||
| 7 | # Create the LUFA source path variables by including the LUFA makefile | 6 | # Create the LUFA source path variables by including the LUFA makefile |
| 8 | ifneq (, $(wildcard $(LUFA_PATH)/LUFA/Build/lufa_sources.mk)) | 7 | ifneq (, $(wildcard $(LUFA_PATH)/LUFA/Build/lufa_sources.mk)) |
| 9 | # New build system from 20120730 | 8 | # New build system from 20120730 |
| @@ -22,23 +21,6 @@ ifeq ($(strip $(MIDI_ENABLE)), yes) | |||
| 22 | include $(TMK_PATH)/protocol/midi.mk | 21 | include $(TMK_PATH)/protocol/midi.mk |
| 23 | endif | 22 | endif |
| 24 | 23 | ||
| 25 | ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) | ||
| 26 | LUFA_SRC += outputselect.c \ | ||
| 27 | $(TMK_DIR)/protocol/serial_uart.c | ||
| 28 | endif | ||
| 29 | |||
| 30 | ifeq ($(strip $(BLUETOOTH)), AdafruitBLE) | ||
| 31 | LUFA_SRC += spi_master.c \ | ||
| 32 | analog.c \ | ||
| 33 | outputselect.c \ | ||
| 34 | $(LUFA_DIR)/adafruit_ble.cpp | ||
| 35 | endif | ||
| 36 | |||
| 37 | ifeq ($(strip $(BLUETOOTH)), RN42) | ||
| 38 | LUFA_SRC += outputselect.c \ | ||
| 39 | $(TMK_DIR)/protocol/serial_uart.c | ||
| 40 | endif | ||
| 41 | |||
| 42 | ifeq ($(strip $(VIRTSER_ENABLE)), yes) | 24 | ifeq ($(strip $(VIRTSER_ENABLE)), yes) |
| 43 | LUFA_SRC += $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/CDCClassDevice.c | 25 | LUFA_SRC += $(LUFA_ROOT_PATH)/Drivers/USB/Class/Device/CDCClassDevice.c |
| 44 | endif | 26 | endif |
| @@ -50,19 +32,10 @@ SRC += $(LUFA_DIR)/usb_util.c | |||
| 50 | VPATH += $(TMK_PATH)/$(LUFA_DIR) | 32 | VPATH += $(TMK_PATH)/$(LUFA_DIR) |
| 51 | VPATH += $(LUFA_PATH) | 33 | VPATH += $(LUFA_PATH) |
| 52 | 34 | ||
| 53 | # Option modules | ||
| 54 | #ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #ifdef EXTRAKEY_ENABLE | ||
| 58 | #endif | ||
| 59 | |||
| 60 | # LUFA library compile-time options and predefined tokens | 35 | # LUFA library compile-time options and predefined tokens |
| 61 | LUFA_OPTS = -DUSB_DEVICE_ONLY | 36 | LUFA_OPTS = -DUSB_DEVICE_ONLY |
| 62 | LUFA_OPTS += -DUSE_FLASH_DESCRIPTORS | 37 | LUFA_OPTS += -DUSE_FLASH_DESCRIPTORS |
| 63 | LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" | 38 | LUFA_OPTS += -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" |
| 64 | #LUFA_OPTS += -DINTERRUPT_CONTROL_ENDPOINT | ||
| 65 | LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 | ||
| 66 | LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 | 39 | LUFA_OPTS += -DFIXED_CONTROL_ENDPOINT_SIZE=8 |
| 67 | LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1 | 40 | LUFA_OPTS += -DFIXED_NUM_CONFIGURATIONS=1 |
| 68 | 41 | ||
diff --git a/tmk_core/protocol/news.c b/tmk_core/protocol/news.c deleted file mode 100644 index 4463e8dd4..000000000 --- a/tmk_core/protocol/news.c +++ /dev/null | |||
| @@ -1,161 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun WAKO <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This software is licensed with a Modified BSD License. | ||
| 5 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 6 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 7 | Additions and corrections to this file are welcome. | ||
| 8 | |||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without | ||
| 11 | modification, are permitted provided that the following conditions are met: | ||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright | ||
| 14 | notice, this list of conditions and the following disclaimer. | ||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright | ||
| 17 | notice, this list of conditions and the following disclaimer in | ||
| 18 | the documentation and/or other materials provided with the | ||
| 19 | distribution. | ||
| 20 | |||
| 21 | * Neither the name of the copyright holders nor the names of | ||
| 22 | contributors may be used to endorse or promote products derived | ||
| 23 | from this software without specific prior written permission. | ||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <stdbool.h> | ||
| 39 | #include <avr/io.h> | ||
| 40 | #include <avr/interrupt.h> | ||
| 41 | #include "news.h" | ||
| 42 | |||
| 43 | void news_init(void) { NEWS_KBD_RX_INIT(); } | ||
| 44 | |||
| 45 | // RX ring buffer | ||
| 46 | #define RBUF_SIZE 8 | ||
| 47 | static uint8_t rbuf[RBUF_SIZE]; | ||
| 48 | static uint8_t rbuf_head = 0; | ||
| 49 | static uint8_t rbuf_tail = 0; | ||
| 50 | |||
| 51 | uint8_t news_recv(void) { | ||
| 52 | uint8_t data = 0; | ||
| 53 | if (rbuf_head == rbuf_tail) { | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | data = rbuf[rbuf_tail]; | ||
| 58 | rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE; | ||
| 59 | return data; | ||
| 60 | } | ||
| 61 | |||
| 62 | // USART RX complete interrupt | ||
| 63 | ISR(NEWS_KBD_RX_VECT) { | ||
| 64 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; | ||
| 65 | if (next != rbuf_tail) { | ||
| 66 | rbuf[rbuf_head] = NEWS_KBD_RX_DATA; | ||
| 67 | rbuf_head = next; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | /* | ||
| 72 | SONY NEWS Keyboard Protocol | ||
| 73 | =========================== | ||
| 74 | |||
| 75 | Resources | ||
| 76 | --------- | ||
| 77 | Mouse protocol of NWA-5461(Japanese) | ||
| 78 | http://groups.google.com/group/fj.sys.news/browse_thread/thread/a01b3e3ac6ae5b2d | ||
| 79 | |||
| 80 | SONY NEWS Info(Japanese) | ||
| 81 | http://katsu.watanabe.name/doc/sonynews/ | ||
| 82 | |||
| 83 | |||
| 84 | Pinouts | ||
| 85 | ------- | ||
| 86 | EIA 232 male connector from NWP-5461 | ||
| 87 | ------------- | ||
| 88 | \ 1 2 3 4 5 / | ||
| 89 | \ 6 7 8 9 / | ||
| 90 | --------- | ||
| 91 | 1 VCC | ||
| 92 | 2 BZ(Speaker) | ||
| 93 | 3 Keyboard Data(from keyboard MCU TxD) | ||
| 94 | 4 NC | ||
| 95 | 5 GND | ||
| 96 | 6 Unknown Input(to keyboard MCU RxD via schmitt trigger) | ||
| 97 | 7 Mouse Data(from Mouse Ext connector) | ||
| 98 | 8 Unknown Input(to Keyboard MCU Input via diode and buffer) | ||
| 99 | 9 FG | ||
| 100 | NOTE: Two LED on keyboard are controlled by pin 6,8? | ||
| 101 | |||
| 102 | EIA 232 male connector from NWP-411A | ||
| 103 | ------------- | ||
| 104 | \ 1 2 3 4 5 / | ||
| 105 | \ 6 7 8 9 / | ||
| 106 | --------- | ||
| 107 | 1 VCC | ||
| 108 | 2 BZ(Speaker) | ||
| 109 | 3 Keyboard Data(from keyboard MCU TxD) | ||
| 110 | 4 NC | ||
| 111 | 5 GND | ||
| 112 | 6 NC | ||
| 113 | 7 Mouse Data(from Mouse Ext connector) | ||
| 114 | 8 NC | ||
| 115 | 9 FG | ||
| 116 | NOTE: These are just from my guess and not confirmed. | ||
| 117 | |||
| 118 | |||
| 119 | Signaling | ||
| 120 | --------- | ||
| 121 | ~~~~~~~~~~ ____XOO0X111X222X333X444X555X666X777~~~~ ~~~~~~~ | ||
| 122 | Idle Start LSB MSB Stop Idle | ||
| 123 | |||
| 124 | Idle: High | ||
| 125 | Start bit: Low | ||
| 126 | Stop bit: High | ||
| 127 | Bit order: LSB first | ||
| 128 | |||
| 129 | Baud rate: 9600 | ||
| 130 | Interface: TTL level(5V) UART | ||
| 131 | |||
| 132 | NOTE: This is observed on NWP-5461 with its DIP switch all OFF. | ||
| 133 | |||
| 134 | |||
| 135 | Format | ||
| 136 | ------ | ||
| 137 | MSB LSB | ||
| 138 | 7 6 5 4 3 2 1 0 bit | ||
| 139 | | | | | | | | | | ||
| 140 | | +-+-+-+-+-+-+-- scan code(00-7F) | ||
| 141 | +---------------- break flag: sets when released | ||
| 142 | |||
| 143 | |||
| 144 | Scan Codes | ||
| 145 | ---------- | ||
| 146 | SONY NEWS NWP-5461 | ||
| 147 | ,---. ,------------------------, ,------------------------. ,---------. | ||
| 148 | | 7A| | 01 | 02 | 03 | 04 | 05 | | 06 | 07 | 08 | 09 | 0A | | 68 | 69 | ,-----------. | ||
| 149 | `---' `------------------------' `------------------------' `---------' | 64| 65| 52| | ||
| 150 | ,-------------------------------------------------------------. ,---. ,---------------| | ||
| 151 | | 0B| 0C| 0D| 0E| 0F| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19 | | 6A| | 4B| 4C| 4D| 4E| | ||
| 152 | |-------------------------------------------------------------| |---| |---------------| | ||
| 153 | | 1A | 1B| 1C| 1D| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| | | 6B| | 4F| 50| 51| 56| | ||
| 154 | |---------------------------------------------------------' | |---| |---------------| | ||
| 155 | | 28 | 29| 2A| 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35 | | 6C| | 53| 54| 55| | | ||
| 156 | |-------------------------------------------------------------| |---| |-----------| 5A| | ||
| 157 | | 36 | 37| 38| 39| 3A| 3B| 3C| 3D| 3E| 3F| 40| 41| 42 | | 6D| | 57| 59| 58| | | ||
| 158 | |-------------------------------------------------------------| |---| |---------------| | ||
| 159 | | 43 | 44 | 45 | 46 | 47 | 48| 49| 4A | | 6E| | 66| 5B| 5C| 5D| | ||
| 160 | `-------------------------------------------------------------' `---' `---------------' | ||
| 161 | */ | ||
diff --git a/tmk_core/protocol/news.h b/tmk_core/protocol/news.h deleted file mode 100644 index 327a13856..000000000 --- a/tmk_core/protocol/news.h +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun WAKO <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This software is licensed with a Modified BSD License. | ||
| 5 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 6 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 7 | Additions and corrections to this file are welcome. | ||
| 8 | |||
| 9 | |||
| 10 | Redistribution and use in source and binary forms, with or without | ||
| 11 | modification, are permitted provided that the following conditions are met: | ||
| 12 | |||
| 13 | * Redistributions of source code must retain the above copyright | ||
| 14 | notice, this list of conditions and the following disclaimer. | ||
| 15 | |||
| 16 | * Redistributions in binary form must reproduce the above copyright | ||
| 17 | notice, this list of conditions and the following disclaimer in | ||
| 18 | the documentation and/or other materials provided with the | ||
| 19 | distribution. | ||
| 20 | |||
| 21 | * Neither the name of the copyright holders nor the names of | ||
| 22 | contributors may be used to endorse or promote products derived | ||
| 23 | from this software without specific prior written permission. | ||
| 24 | |||
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | */ | ||
| 37 | |||
| 38 | #pragma once | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Primitive PS/2 Library for AVR | ||
| 42 | */ | ||
| 43 | |||
| 44 | /* host role */ | ||
| 45 | void news_init(void); | ||
| 46 | uint8_t news_recv(void); | ||
| 47 | |||
| 48 | /* device role */ | ||
diff --git a/tmk_core/protocol/next_kbd.c b/tmk_core/protocol/next_kbd.c deleted file mode 100644 index 6f118e617..000000000 --- a/tmk_core/protocol/next_kbd.c +++ /dev/null | |||
| @@ -1,219 +0,0 @@ | |||
| 1 | /* | ||
| 2 | |||
| 3 | NeXT non-ADB Keyboard Protocol | ||
| 4 | |||
| 5 | Copyright 2013, Benjamin Gould (bgould@github.com) | ||
| 6 | |||
| 7 | Based on: | ||
| 8 | TMK firmware code Copyright 2011,2012 Jun WAKO <wakojun@gmail.com> | ||
| 9 | Arduino code by "Ladyada" Limor Fried (http://ladyada.net/, http://adafruit.com/), released under BSD license | ||
| 10 | |||
| 11 | Timing reference thanks to http://m0115.web.fc2.com/ (dead link), http://cfile7.uf.tistory.com/image/14448E464F410BF22380BB | ||
| 12 | Pinouts thanks to http://www.68k.org/~degs/nextkeyboard.html | ||
| 13 | Keycodes from http://ftp.netbsd.org/pub/NetBSD/NetBSD-release-6/src/sys/arch/next68k/dev/ | ||
| 14 | |||
| 15 | This software is licensed with a Modified BSD License. | ||
| 16 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 17 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 18 | Additions and corrections to this file are welcome. | ||
| 19 | |||
| 20 | Redistribution and use in source and binary forms, with or without | ||
| 21 | modification, are permitted provided that the following conditions are met: | ||
| 22 | |||
| 23 | * Redistributions of source code must retain the above copyright | ||
| 24 | notice, this list of conditions and the following disclaimer. | ||
| 25 | |||
| 26 | * Redistributions in binary form must reproduce the above copyright | ||
| 27 | notice, this list of conditions and the following disclaimer in | ||
| 28 | the documentation and/or other materials provided with the | ||
| 29 | distribution. | ||
| 30 | |||
| 31 | * Neither the name of the copyright holders nor the names of | ||
| 32 | contributors may be used to endorse or promote products derived | ||
| 33 | from this software without specific prior written permission. | ||
| 34 | |||
| 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 36 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 37 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 38 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 39 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 40 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 41 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 42 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 43 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 44 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 45 | POSSIBILITY OF SUCH DAMAGE. | ||
| 46 | |||
| 47 | */ | ||
| 48 | |||
| 49 | #include <stdint.h> | ||
| 50 | #include <stdbool.h> | ||
| 51 | #include <util/atomic.h> | ||
| 52 | #include <util/delay.h> | ||
| 53 | #include "next_kbd.h" | ||
| 54 | #include "debug.h" | ||
| 55 | |||
| 56 | static inline void out_lo(void); | ||
| 57 | static inline void out_hi(void); | ||
| 58 | static inline void query(void); | ||
| 59 | static inline void reset(void); | ||
| 60 | static inline uint32_t response(void); | ||
| 61 | |||
| 62 | /* The keyboard sends signal with 50us pulse width on OUT line | ||
| 63 | * while it seems to miss the 50us pulse on In line. | ||
| 64 | * next_kbd_set_leds() often fails to sync LED status with 50us | ||
| 65 | * but it works well with 51us(+1us) on TMK converter(ATMeaga32u2) at least. | ||
| 66 | * TODO: test on Teensy and Pro Micro configuration | ||
| 67 | */ | ||
| 68 | #define out_hi_delay(intervals) \ | ||
| 69 | do { \ | ||
| 70 | out_hi(); \ | ||
| 71 | _delay_us((NEXT_KBD_TIMING + 1) * intervals); \ | ||
| 72 | } while (0); | ||
| 73 | #define out_lo_delay(intervals) \ | ||
| 74 | do { \ | ||
| 75 | out_lo(); \ | ||
| 76 | _delay_us((NEXT_KBD_TIMING + 1) * intervals); \ | ||
| 77 | } while (0); | ||
| 78 | #define query_delay(intervals) \ | ||
| 79 | do { \ | ||
| 80 | query(); \ | ||
| 81 | _delay_us((NEXT_KBD_TIMING + 1) * intervals); \ | ||
| 82 | } while (0); | ||
| 83 | #define reset_delay(intervals) \ | ||
| 84 | do { \ | ||
| 85 | reset(); \ | ||
| 86 | _delay_us((NEXT_KBD_TIMING + 1) * intervals); \ | ||
| 87 | } while (0); | ||
| 88 | |||
| 89 | void next_kbd_init(void) { | ||
| 90 | out_hi(); | ||
| 91 | NEXT_KBD_IN_DDR &= ~(1 << NEXT_KBD_IN_BIT); // KBD_IN to input | ||
| 92 | NEXT_KBD_IN_PORT |= (1 << NEXT_KBD_IN_BIT); // KBD_IN pull up | ||
| 93 | |||
| 94 | query_delay(5); | ||
| 95 | reset_delay(8); | ||
| 96 | |||
| 97 | query_delay(5); | ||
| 98 | reset_delay(8); | ||
| 99 | } | ||
| 100 | |||
| 101 | void next_kbd_set_leds(bool left, bool right) { | ||
| 102 | cli(); | ||
| 103 | out_lo_delay(9); | ||
| 104 | |||
| 105 | out_hi_delay(3); | ||
| 106 | out_lo_delay(1); | ||
| 107 | |||
| 108 | if (left) { | ||
| 109 | out_hi_delay(1); | ||
| 110 | } else { | ||
| 111 | out_lo_delay(1); | ||
| 112 | } | ||
| 113 | |||
| 114 | if (right) { | ||
| 115 | out_hi_delay(1); | ||
| 116 | } else { | ||
| 117 | out_lo_delay(1); | ||
| 118 | } | ||
| 119 | |||
| 120 | out_lo_delay(7); | ||
| 121 | out_hi(); | ||
| 122 | sei(); | ||
| 123 | } | ||
| 124 | |||
| 125 | #define NEXT_KBD_READ (NEXT_KBD_IN_PIN & (1 << NEXT_KBD_IN_BIT)) | ||
| 126 | uint32_t next_kbd_recv(void) { | ||
| 127 | // First check to make sure that the keyboard is actually connected; | ||
| 128 | // if not, just return | ||
| 129 | // TODO: reflect the status of the keyboard in a return code | ||
| 130 | if (!NEXT_KBD_READ) { | ||
| 131 | sei(); | ||
| 132 | return 0; | ||
| 133 | } | ||
| 134 | |||
| 135 | query(); | ||
| 136 | uint32_t resp = response(); | ||
| 137 | |||
| 138 | return resp; | ||
| 139 | } | ||
| 140 | |||
| 141 | static inline uint32_t response(void) { | ||
| 142 | cli(); | ||
| 143 | |||
| 144 | // try a 5ms read; this should be called after the query method has | ||
| 145 | // been run so if a key is pressed we should get a response within | ||
| 146 | // 5ms; if not then send a reset and exit | ||
| 147 | uint8_t i = 0; | ||
| 148 | uint32_t data = 0; | ||
| 149 | uint16_t reset_timeout = 50000; | ||
| 150 | while (NEXT_KBD_READ && reset_timeout) { | ||
| 151 | asm(""); | ||
| 152 | _delay_us(1); | ||
| 153 | reset_timeout--; | ||
| 154 | } | ||
| 155 | if (!reset_timeout) { | ||
| 156 | reset(); | ||
| 157 | sei(); | ||
| 158 | return 0; | ||
| 159 | } | ||
| 160 | _delay_us(NEXT_KBD_TIMING / 2); | ||
| 161 | for (; i < 22; i++) { | ||
| 162 | if (NEXT_KBD_READ) { | ||
| 163 | data |= ((uint32_t)1 << i); | ||
| 164 | /* Note: | ||
| 165 | * My testing with the ATmega32u4 showed that there might | ||
| 166 | * something wrong with the timing here; by the end of the | ||
| 167 | * second data byte some of the modifiers can get bumped out | ||
| 168 | * to the next bit over if we just cycle through the data | ||
| 169 | * based on the expected interval. There is a bit (i = 10) | ||
| 170 | * in the middle of the data that is always on followed by | ||
| 171 | * one that is always off - so we'll use that to reset our | ||
| 172 | * timing in case we've gotten ahead of the keyboard; | ||
| 173 | */ | ||
| 174 | if (i == 10) { | ||
| 175 | i++; | ||
| 176 | while (NEXT_KBD_READ) | ||
| 177 | ; | ||
| 178 | _delay_us(NEXT_KBD_TIMING / 2); | ||
| 179 | } | ||
| 180 | } else { | ||
| 181 | /* redundant - but I don't want to remove if it might screw | ||
| 182 | * up the timing | ||
| 183 | */ | ||
| 184 | data |= ((uint32_t)0 << i); | ||
| 185 | } | ||
| 186 | _delay_us(NEXT_KBD_TIMING); | ||
| 187 | } | ||
| 188 | |||
| 189 | sei(); | ||
| 190 | |||
| 191 | return data; | ||
| 192 | } | ||
| 193 | |||
| 194 | static inline void out_lo(void) { | ||
| 195 | NEXT_KBD_OUT_PORT &= ~(1 << NEXT_KBD_OUT_BIT); | ||
| 196 | NEXT_KBD_OUT_DDR |= (1 << NEXT_KBD_OUT_BIT); | ||
| 197 | } | ||
| 198 | |||
| 199 | static inline void out_hi(void) { | ||
| 200 | /* input with pull up */ | ||
| 201 | NEXT_KBD_OUT_DDR &= ~(1 << NEXT_KBD_OUT_BIT); | ||
| 202 | NEXT_KBD_OUT_PORT |= (1 << NEXT_KBD_OUT_BIT); | ||
| 203 | } | ||
| 204 | |||
| 205 | static inline void query(void) { | ||
| 206 | out_lo_delay(5); | ||
| 207 | out_hi_delay(1); | ||
| 208 | out_lo_delay(3); | ||
| 209 | out_hi(); | ||
| 210 | } | ||
| 211 | |||
| 212 | static inline void reset(void) { | ||
| 213 | out_lo_delay(1); | ||
| 214 | out_hi_delay(4); | ||
| 215 | out_lo_delay(1); | ||
| 216 | out_hi_delay(6); | ||
| 217 | out_lo_delay(10); | ||
| 218 | out_hi(); | ||
| 219 | } | ||
diff --git a/tmk_core/protocol/next_kbd.h b/tmk_core/protocol/next_kbd.h deleted file mode 100644 index 1249ebf39..000000000 --- a/tmk_core/protocol/next_kbd.h +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | /* | ||
| 2 | NeXT non-ADB Keyboard Protocol | ||
| 3 | |||
| 4 | Copyright 2013, Benjamin Gould (bgould@github.com) | ||
| 5 | |||
| 6 | Based on: | ||
| 7 | TMK firmware code Copyright 2011,2012 Jun WAKO <wakojun@gmail.com> | ||
| 8 | Arduino code by "Ladyada" Limor Fried (http://ladyada.net/, http://adafruit.com/), released under BSD license | ||
| 9 | |||
| 10 | Timing reference thanks to http://m0115.web.fc2.com/ (dead link), http://cfile7.uf.tistory.com/image/14448E464F410BF22380BB | ||
| 11 | Pinouts thanks to http://www.68k.org/~degs/nextkeyboard.html | ||
| 12 | Keycodes from http://ftp.netbsd.org/pub/NetBSD/NetBSD-release-6/src/sys/arch/next68k/dev/ | ||
| 13 | |||
| 14 | This software is licensed with a Modified BSD License. | ||
| 15 | All of this is supposed to be Free Software, Open Source, DFSG-free, | ||
| 16 | GPL-compatible, and OK to use in both free and proprietary applications. | ||
| 17 | Additions and corrections to this file are welcome. | ||
| 18 | |||
| 19 | Redistribution and use in source and binary forms, with or without | ||
| 20 | modification, are permitted provided that the following conditions are met: | ||
| 21 | |||
| 22 | * Redistributions of source code must retain the above copyright | ||
| 23 | notice, this list of conditions and the following disclaimer. | ||
| 24 | |||
| 25 | * Redistributions in binary form must reproduce the above copyright | ||
| 26 | notice, this list of conditions and the following disclaimer in | ||
| 27 | the documentation and/or other materials provided with the | ||
| 28 | distribution. | ||
| 29 | |||
| 30 | * Neither the name of the copyright holders nor the names of | ||
| 31 | contributors may be used to endorse or promote products derived | ||
| 32 | from this software without specific prior written permission. | ||
| 33 | |||
| 34 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 35 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 36 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 37 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 38 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 39 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 40 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 41 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 42 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 43 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 44 | POSSIBILITY OF SUCH DAMAGE. | ||
| 45 | |||
| 46 | */ | ||
| 47 | |||
| 48 | #pragma once | ||
| 49 | |||
| 50 | #include <stdbool.h> | ||
| 51 | |||
| 52 | #define NEXT_KBD_KMBUS_IDLE 0x300600 | ||
| 53 | #define NEXT_KBD_TIMING 50 | ||
| 54 | |||
| 55 | extern uint8_t next_kbd_error; | ||
| 56 | |||
| 57 | /* host role */ | ||
| 58 | void next_kbd_init(void); | ||
| 59 | void next_kbd_set_leds(bool left, bool right); | ||
| 60 | uint32_t next_kbd_recv(void); | ||
diff --git a/tmk_core/protocol/usb_hid/parser.h b/tmk_core/protocol/usb_hid/parser.h index 036281fa6..ba35b7af5 100644 --- a/tmk_core/protocol/usb_hid/parser.h +++ b/tmk_core/protocol/usb_hid/parser.h | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #ifndef PARSER_H | 1 | #pragma once |
| 2 | #define PARSER_H | ||
| 3 | 2 | ||
| 4 | #include "hid.h" | 3 | #include "hid.h" |
| 5 | #include "report.h" | 4 | #include "report.h" |
| @@ -11,5 +10,3 @@ public: | |||
| 11 | uint16_t time_stamp; | 10 | uint16_t time_stamp; |
| 12 | virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); | 11 | virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); |
| 13 | }; | 12 | }; |
| 14 | |||
| 15 | #endif | ||
diff --git a/tmk_core/protocol/usb_hid/usb_hid.h b/tmk_core/protocol/usb_hid/usb_hid.h index 083b68d1f..5cb5f5d03 100644 --- a/tmk_core/protocol/usb_hid/usb_hid.h +++ b/tmk_core/protocol/usb_hid/usb_hid.h | |||
| @@ -1,10 +1,6 @@ | |||
| 1 | #ifndef USB_HID_H | 1 | #pragma once |
| 2 | #define USB_HID_H | ||
| 3 | 2 | ||
| 4 | #include "report.h" | 3 | #include "report.h" |
| 5 | 4 | ||
| 6 | |||
| 7 | extern report_keyboard_t usb_hid_keyboard_report; | 5 | extern report_keyboard_t usb_hid_keyboard_report; |
| 8 | extern uint16_t usb_hid_time_stamp; | 6 | extern uint16_t usb_hid_time_stamp; |
| 9 | |||
| 10 | #endif | ||
