diff options
| author | tmk <nobody@nowhere> | 2014-07-17 13:06:48 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-07-30 14:38:26 +0900 |
| commit | fa545c87f74833856761572ef631d20accc1d026 (patch) | |
| tree | 4cc7c02660a2401a9b7638ade6b460c7c573ff93 /keyboard/hhkb_rn42 | |
| parent | 862f519e241b83113566eebde71841958b2d00b7 (diff) | |
| download | qmk_firmware-fa545c87f74833856761572ef631d20accc1d026.tar.gz qmk_firmware-fa545c87f74833856761572ef631d20accc1d026.zip | |
Fix rn42.h API
Diffstat (limited to 'keyboard/hhkb_rn42')
| -rw-r--r-- | keyboard/hhkb_rn42/main.c | 68 | ||||
| -rw-r--r-- | keyboard/hhkb_rn42/rn42.c | 41 | ||||
| -rw-r--r-- | keyboard/hhkb_rn42/rn42.h | 10 |
3 files changed, 60 insertions, 59 deletions
diff --git a/keyboard/hhkb_rn42/main.c b/keyboard/hhkb_rn42/main.c index 0b455193f..edab69978 100644 --- a/keyboard/hhkb_rn42/main.c +++ b/keyboard/hhkb_rn42/main.c | |||
| @@ -45,9 +45,6 @@ static void SetupHardware(void) | |||
| 45 | PORTD |= (1<<0); | 45 | PORTD |= (1<<0); |
| 46 | DDRD &= ~(1<<1); | 46 | DDRD &= ~(1<<1); |
| 47 | PORTD |= (1<<1); | 47 | PORTD |= (1<<1); |
| 48 | |||
| 49 | // CTS control | ||
| 50 | CTS_INIT(); | ||
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | static bool force_usb = false; | 50 | static bool force_usb = false; |
| @@ -75,7 +72,7 @@ int main(void) | |||
| 75 | /* init modules */ | 72 | /* init modules */ |
| 76 | keyboard_init(); | 73 | keyboard_init(); |
| 77 | 74 | ||
| 78 | if (rn42_ready()) { | 75 | if (!rn42_rts()) { |
| 79 | host_set_driver(&rn42_driver); | 76 | host_set_driver(&rn42_driver); |
| 80 | } else { | 77 | } else { |
| 81 | host_set_driver(&lufa_driver); | 78 | host_set_driver(&lufa_driver); |
| @@ -112,9 +109,9 @@ int main(void) | |||
| 112 | if (config_mode) { | 109 | if (config_mode) { |
| 113 | while ((c = serial_recv2()) != -1) { | 110 | while ((c = serial_recv2()) != -1) { |
| 114 | // without flow control it'll fail to receive data when flooded | 111 | // without flow control it'll fail to receive data when flooded |
| 115 | CTS_HI(); | 112 | rn42_cts_hi(); |
| 116 | xprintf("%c", c); | 113 | xprintf("%c", c); |
| 117 | CTS_LO(); | 114 | rn42_cts_lo(); |
| 118 | } | 115 | } |
| 119 | } else { | 116 | } else { |
| 120 | while ((c = serial_recv2()) != -1) { | 117 | while ((c = serial_recv2()) != -1) { |
| @@ -148,10 +145,10 @@ int main(void) | |||
| 148 | 145 | ||
| 149 | /* Bluetooth mode when ready */ | 146 | /* Bluetooth mode when ready */ |
| 150 | if (!config_mode && !force_usb) { | 147 | if (!config_mode && !force_usb) { |
| 151 | if (rn42_ready() && host_get_driver() != &rn42_driver) { | 148 | if (!rn42_rts() && host_get_driver() != &rn42_driver) { |
| 152 | clear_keyboard(); | 149 | clear_keyboard(); |
| 153 | host_set_driver(&rn42_driver); | 150 | host_set_driver(&rn42_driver); |
| 154 | } else if (!rn42_ready() && host_get_driver() != &lufa_driver) { | 151 | } else if (rn42_rts() && host_get_driver() != &lufa_driver) { |
| 155 | clear_keyboard(); | 152 | clear_keyboard(); |
| 156 | host_set_driver(&lufa_driver); | 153 | host_set_driver(&lufa_driver); |
| 157 | } | 154 | } |
| @@ -159,7 +156,10 @@ int main(void) | |||
| 159 | } | 156 | } |
| 160 | } | 157 | } |
| 161 | 158 | ||
| 162 | static bool local_echo = false; | 159 | |
| 160 | /****************************************************************************** | ||
| 161 | * Command | ||
| 162 | ******************************************************************************/ | ||
| 163 | bool command_extra(uint8_t code) | 163 | bool command_extra(uint8_t code) |
| 164 | { | 164 | { |
| 165 | static host_driver_t *prev_driver = &rn42_driver; | 165 | static host_driver_t *prev_driver = &rn42_driver; |
| @@ -167,46 +167,37 @@ bool command_extra(uint8_t code) | |||
| 167 | case KC_H: | 167 | case KC_H: |
| 168 | case KC_SLASH: /* ? */ | 168 | case KC_SLASH: /* ? */ |
| 169 | print("\n\n----- Bluetooth RN-42 Help -----\n"); | 169 | print("\n\n----- Bluetooth RN-42 Help -----\n"); |
| 170 | print("w: toggle RN-42 config mode(enter/exit)\n"); | 170 | print("Del: auto_connect/disconnect(enter/exit config mode)\n"); |
| 171 | print("l: toggle print module output(local echo)\n"); | 171 | print("i: RN-42 info\n"); |
| 172 | print("a: Bluetooth auto connect\n"); | ||
| 173 | print("del: Bluetooth disconnect\n"); | ||
| 174 | print("i: info\n"); | ||
| 175 | print("b: battery voltage\n"); | 172 | print("b: battery voltage\n"); |
| 176 | 173 | ||
| 177 | if (config_mode) { | 174 | if (config_mode) { |
| 178 | return true; | 175 | return true; |
| 179 | } else { | 176 | } else { |
| 180 | print("u: force USB mode\n"); | 177 | print("u: Force USB mode\n"); |
| 181 | return false; // to display default command help | 178 | return false; // to display default command help |
| 182 | } | 179 | } |
| 183 | case KC_W: | 180 | case KC_DELETE: |
| 184 | if (!config_mode) { | 181 | if (rn42_autoconnecting()) { |
| 185 | print("\nEnter RN-42 config mode\n"); | 182 | rn42_disconnect(); |
| 186 | print("type $$$ to enter RN-42 command mode\n"); | 183 | print("\nRN-42: disconnect\n"); |
| 187 | print("type Delete to disconnect Bluetooth connection\n"); | 184 | print("Enter config mode\n"); |
| 185 | print("type $$$ to start and + for local echo\n"); | ||
| 188 | command_state = CONSOLE; | 186 | command_state = CONSOLE; |
| 189 | config_mode = true; | 187 | config_mode = true; |
| 190 | prev_driver = host_get_driver(); | 188 | prev_driver = host_get_driver(); |
| 191 | clear_keyboard(); | 189 | clear_keyboard(); |
| 192 | host_set_driver(&rn42_config_driver); | 190 | host_set_driver(&rn42_config_driver); // null driver; not to send a key to host |
| 193 | } else { | 191 | } else { |
| 194 | print("\nExit RN-42 config mode\n"); | 192 | rn42_autoconnect(); |
| 193 | print("\nRN-42: auto_connect\n"); | ||
| 194 | print("Exit config mode\n"); | ||
| 195 | command_state = ONESHOT; | 195 | command_state = ONESHOT; |
| 196 | config_mode = false; | 196 | config_mode = false; |
| 197 | clear_keyboard(); | 197 | clear_keyboard(); |
| 198 | host_set_driver(prev_driver); | 198 | host_set_driver(prev_driver); |
| 199 | } | 199 | } |
| 200 | return true; | 200 | return true; |
| 201 | case KC_L: | ||
| 202 | if (local_echo) { | ||
| 203 | print("local echo off\n"); | ||
| 204 | local_echo = false; | ||
| 205 | } else { | ||
| 206 | print("local echo on\n"); | ||
| 207 | local_echo = true; | ||
| 208 | } | ||
| 209 | return true; | ||
| 210 | case KC_U: | 201 | case KC_U: |
| 211 | if (config_mode) return false; | 202 | if (config_mode) return false; |
| 212 | if (force_usb) { | 203 | if (force_usb) { |
| @@ -219,20 +210,12 @@ bool command_extra(uint8_t code) | |||
| 219 | host_set_driver(&lufa_driver); | 210 | host_set_driver(&lufa_driver); |
| 220 | } | 211 | } |
| 221 | return true; | 212 | return true; |
| 222 | case KC_A: | ||
| 223 | print("auto connect\n"); | ||
| 224 | rn42_autoconnect(); | ||
| 225 | return true; | ||
| 226 | case KC_DELETE: | ||
| 227 | print("disconnect\n"); | ||
| 228 | rn42_disconnect(); | ||
| 229 | //rn42_putc('\0'); // see 5.3.4.4 DISCONNECT KEY of User's Guide | ||
| 230 | return true; | ||
| 231 | case KC_I: | 213 | case KC_I: |
| 232 | print("\nRN-42 info\n"); | 214 | print("\n----- RN-42 info -----\n"); |
| 233 | xprintf("protocol: %s\n", (host_get_driver() == &rn42_driver) ? "RN-42" : "LUFA"); | 215 | xprintf("protocol: %s\n", (host_get_driver() == &rn42_driver) ? "RN-42" : "LUFA"); |
| 234 | xprintf("force_usb: %X\n", force_usb); | 216 | xprintf("force_usb: %X\n", force_usb); |
| 235 | xprintf("rn42_ready(): %X\n", rn42_ready()); | 217 | xprintf("rn42_autoconnecting(): %X\n", rn42_autoconnecting()); |
| 218 | xprintf("rn42_rts(): %X\n", rn42_rts()); | ||
| 236 | xprintf("config_mode: %X\n", config_mode); | 219 | xprintf("config_mode: %X\n", config_mode); |
| 237 | return true; | 220 | return true; |
| 238 | case KC_B: | 221 | case KC_B: |
| @@ -266,7 +249,6 @@ bool command_console_extra(uint8_t code) | |||
| 266 | switch (code) { | 249 | switch (code) { |
| 267 | default: | 250 | default: |
| 268 | rn42_putc(code2asc(code)); | 251 | rn42_putc(code2asc(code)); |
| 269 | if (local_echo) xprintf("%c", code2asc(code)); | ||
| 270 | return true; | 252 | return true; |
| 271 | } | 253 | } |
| 272 | return false; | 254 | return false; |
diff --git a/keyboard/hhkb_rn42/rn42.c b/keyboard/hhkb_rn42/rn42.c index 89ecb199c..a041cc366 100644 --- a/keyboard/hhkb_rn42/rn42.c +++ b/keyboard/hhkb_rn42/rn42.c | |||
| @@ -24,17 +24,17 @@ host_driver_t rn42_driver = { | |||
| 24 | 24 | ||
| 25 | void rn42_init(void) | 25 | void rn42_init(void) |
| 26 | { | 26 | { |
| 27 | // PF1: check RTS(active low) | ||
| 28 | DDRF &= ~(1<<1); | ||
| 29 | PORTF &= ~(1<<1); | ||
| 30 | |||
| 31 | // PF7: BT connection control(HiZ: connect, low: disconnect) | 27 | // PF7: BT connection control(HiZ: connect, low: disconnect) |
| 32 | // JTAG disable for PORT F. write JTD bit twice within four cycles. | 28 | // JTAG disable for PORT F. write JTD bit twice within four cycles. |
| 33 | MCUCR |= (1<<JTD); | 29 | MCUCR |= (1<<JTD); |
| 34 | MCUCR |= (1<<JTD); | 30 | MCUCR |= (1<<JTD); |
| 35 | rn42_autoconnect(); | 31 | rn42_autoconnect(); |
| 36 | 32 | ||
| 37 | // PD5: CTS (low: allow to send, high:not allowed) | 33 | // PF1: RTS(low: allowed to send, high: not allowed) |
| 34 | DDRF &= ~(1<<1); | ||
| 35 | PORTF &= ~(1<<1); | ||
| 36 | |||
| 37 | // PD5: CTS(low: allow to send, high:not allow) | ||
| 38 | DDRD |= (1<<5); | 38 | DDRD |= (1<<5); |
| 39 | PORTD &= ~(1<<5); | 39 | PORTD &= ~(1<<5); |
| 40 | 40 | ||
| @@ -46,22 +46,43 @@ void rn42_putc(uint8_t c) | |||
| 46 | serial_send(c); | 46 | serial_send(c); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | bool rn42_autoconnecting(void) | ||
| 50 | { | ||
| 51 | // GPIO6 for control connection(high: auto connect, low: disconnect) | ||
| 52 | // Note that this needs config: SM,4(Auto-Connect DTR Mode) | ||
| 53 | return (PORTF & (1<<7) ? true : false); | ||
| 54 | } | ||
| 55 | |||
| 49 | void rn42_autoconnect(void) | 56 | void rn42_autoconnect(void) |
| 50 | { | 57 | { |
| 51 | DDRF &= ~(1<<7); | 58 | // hi to auto connect |
| 52 | PORTF &= ~(1<<7); | 59 | DDRF |= (1<<7); |
| 60 | PORTF |= (1<<7); | ||
| 53 | } | 61 | } |
| 54 | 62 | ||
| 55 | void rn42_disconnect(void) | 63 | void rn42_disconnect(void) |
| 56 | { | 64 | { |
| 65 | // low to disconnect | ||
| 57 | DDRF |= (1<<7); | 66 | DDRF |= (1<<7); |
| 58 | PORTF &= ~(1<<7); | 67 | PORTF &= ~(1<<7); |
| 59 | } | 68 | } |
| 60 | 69 | ||
| 61 | bool rn42_ready(void) | 70 | bool rn42_rts(void) |
| 71 | { | ||
| 72 | // low when RN-42 is powered and ready to receive | ||
| 73 | return PINF&(1<<1); | ||
| 74 | } | ||
| 75 | |||
| 76 | void rn42_cts_hi(void) | ||
| 62 | { | 77 | { |
| 63 | // RTS low | 78 | // not allow to send |
| 64 | return PINF&(1<<1) ? false : true; | 79 | PORTD |= (1<<5); |
| 80 | } | ||
| 81 | |||
| 82 | void rn42_cts_lo(void) | ||
| 83 | { | ||
| 84 | // allow to send | ||
| 85 | PORTD &= ~(1<<5); | ||
| 65 | } | 86 | } |
| 66 | 87 | ||
| 67 | 88 | ||
diff --git a/keyboard/hhkb_rn42/rn42.h b/keyboard/hhkb_rn42/rn42.h index a967a70d8..4189733b4 100644 --- a/keyboard/hhkb_rn42/rn42.h +++ b/keyboard/hhkb_rn42/rn42.h | |||
| @@ -3,18 +3,16 @@ | |||
| 3 | 3 | ||
| 4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 5 | 5 | ||
| 6 | // RN-42 CTS pin | ||
| 7 | #define CTS_INIT() (DDRD |= (1<<5)) | ||
| 8 | #define CTS_HI() (PORTD |= (1<<5)) | ||
| 9 | #define CTS_LO() (PORTD &= ~(1<<5)) | ||
| 10 | |||
| 11 | host_driver_t rn42_driver; | 6 | host_driver_t rn42_driver; |
| 12 | host_driver_t rn42_config_driver; | 7 | host_driver_t rn42_config_driver; |
| 13 | 8 | ||
| 14 | void rn42_init(void); | 9 | void rn42_init(void); |
| 15 | void rn42_putc(uint8_t c); | 10 | void rn42_putc(uint8_t c); |
| 11 | bool rn42_autoconnecting(void); | ||
| 16 | void rn42_autoconnect(void); | 12 | void rn42_autoconnect(void); |
| 17 | void rn42_disconnect(void); | 13 | void rn42_disconnect(void); |
| 18 | bool rn42_ready(void); | 14 | bool rn42_rts(void); |
| 15 | void rn42_cts_hi(void); | ||
| 16 | void rn42_cts_lo(void); | ||
| 19 | 17 | ||
| 20 | #endif | 18 | #endif |
