diff options
Diffstat (limited to 'keyboard/hhkb_rn42/main.c')
| -rw-r--r-- | keyboard/hhkb_rn42/main.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/keyboard/hhkb_rn42/main.c b/keyboard/hhkb_rn42/main.c index a2c217a2d..0b455193f 100644 --- a/keyboard/hhkb_rn42/main.c +++ b/keyboard/hhkb_rn42/main.c | |||
| @@ -12,10 +12,16 @@ | |||
| 12 | #include "action.h" | 12 | #include "action.h" |
| 13 | #include "action_util.h" | 13 | #include "action_util.h" |
| 14 | #include "wait.h" | 14 | #include "wait.h" |
| 15 | 15 | #include "suart.h" | |
| 16 | 16 | ||
| 17 | bool config_mode = false; | 17 | bool config_mode = false; |
| 18 | 18 | ||
| 19 | static int8_t sendchar_func(uint8_t c) | ||
| 20 | { | ||
| 21 | sendchar(c); // LUFA | ||
| 22 | xmit(c); // SUART | ||
| 23 | } | ||
| 24 | |||
| 19 | static void SetupHardware(void) | 25 | static void SetupHardware(void) |
| 20 | { | 26 | { |
| 21 | /* Disable watchdog if enabled by bootloader/fuses */ | 27 | /* Disable watchdog if enabled by bootloader/fuses */ |
| @@ -32,7 +38,16 @@ static void SetupHardware(void) | |||
| 32 | 38 | ||
| 33 | // for Console_Task | 39 | // for Console_Task |
| 34 | USB_Device_EnableSOFEvents(); | 40 | USB_Device_EnableSOFEvents(); |
| 35 | print_set_sendchar(sendchar); | 41 | print_set_sendchar(sendchar_func); |
| 42 | |||
| 43 | // SUART PD0:output, PD1:input | ||
| 44 | DDRD |= (1<<0); | ||
| 45 | PORTD |= (1<<0); | ||
| 46 | DDRD &= ~(1<<1); | ||
| 47 | PORTD |= (1<<1); | ||
| 48 | |||
| 49 | // CTS control | ||
| 50 | CTS_INIT(); | ||
| 36 | } | 51 | } |
| 37 | 52 | ||
| 38 | static bool force_usb = false; | 53 | static bool force_usb = false; |
| @@ -70,6 +85,12 @@ int main(void) | |||
| 70 | sleep_led_init(); | 85 | sleep_led_init(); |
| 71 | #endif | 86 | #endif |
| 72 | 87 | ||
| 88 | // ADC for battery | ||
| 89 | //ADMUX = (1<<REFS0); // Ref:AVCC, Input:ADC0(PF0) | ||
| 90 | ADMUX = (1<<REFS1) | (1<<REFS0); // Ref:AVCC, Input:ADC0(PF0) | ||
| 91 | ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // Prescale:128 | ||
| 92 | ADCSRA |= (1<<ADEN); // enable ADC | ||
| 93 | |||
| 73 | print("Keyboard start.\n"); | 94 | print("Keyboard start.\n"); |
| 74 | while (1) { | 95 | while (1) { |
| 75 | /* | 96 | /* |
| @@ -89,7 +110,12 @@ int main(void) | |||
| 89 | 110 | ||
| 90 | int16_t c; | 111 | int16_t c; |
| 91 | if (config_mode) { | 112 | if (config_mode) { |
| 92 | while ((c = serial_recv2()) != -1) xprintf("%c", c); | 113 | while ((c = serial_recv2()) != -1) { |
| 114 | // without flow control it'll fail to receive data when flooded | ||
| 115 | CTS_HI(); | ||
| 116 | xprintf("%c", c); | ||
| 117 | CTS_LO(); | ||
| 118 | } | ||
| 93 | } else { | 119 | } else { |
| 94 | while ((c = serial_recv2()) != -1) { | 120 | while ((c = serial_recv2()) != -1) { |
| 95 | // LED Out report: 0xFE, 0x02, 0x01, <leds> | 121 | // LED Out report: 0xFE, 0x02, 0x01, <leds> |
| @@ -146,6 +172,7 @@ bool command_extra(uint8_t code) | |||
| 146 | print("a: Bluetooth auto connect\n"); | 172 | print("a: Bluetooth auto connect\n"); |
| 147 | print("del: Bluetooth disconnect\n"); | 173 | print("del: Bluetooth disconnect\n"); |
| 148 | print("i: info\n"); | 174 | print("i: info\n"); |
| 175 | print("b: battery voltage\n"); | ||
| 149 | 176 | ||
| 150 | if (config_mode) { | 177 | if (config_mode) { |
| 151 | return true; | 178 | return true; |
| @@ -208,6 +235,22 @@ bool command_extra(uint8_t code) | |||
| 208 | xprintf("rn42_ready(): %X\n", rn42_ready()); | 235 | xprintf("rn42_ready(): %X\n", rn42_ready()); |
| 209 | xprintf("config_mode: %X\n", config_mode); | 236 | xprintf("config_mode: %X\n", config_mode); |
| 210 | return true; | 237 | return true; |
| 238 | case KC_B: | ||
| 239 | // battery monitor | ||
| 240 | ADCSRA |= (1<<ADEN) | (1<<ADSC); | ||
| 241 | while (ADCSRA & (1<<ADSC)) ; | ||
| 242 | uint16_t bat = ADCL; | ||
| 243 | bat = ADCH<<8 | bat; | ||
| 244 | xprintf("BAT: %04X\n", bat); | ||
| 245 | |||
| 246 | ADCSRA |= (1<<ADEN) | (1<<ADSC); | ||
| 247 | while (ADCSRA & (1<<ADSC)) ; | ||
| 248 | bat = ADCL; | ||
| 249 | bat = ADCH<<8 | bat; | ||
| 250 | xprintf("BAT: %04X\n", bat); | ||
| 251 | |||
| 252 | ADCSRA &= ~(1<<ADEN); | ||
| 253 | return true; | ||
| 211 | default: | 254 | default: |
| 212 | if (config_mode) | 255 | if (config_mode) |
| 213 | return true; | 256 | return true; |
