From 2e464737aa9f83fb08dbd7a252b75d028475aa04 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 26 Dec 2016 12:15:39 +0900 Subject: [PATCH] hhkb: Move functions which communicate with RN42 --- keyboard/hhkb/rn42/rn42.c | 28 ++++++++++++++++++++++++++ keyboard/hhkb/rn42/rn42.h | 7 +++++++ keyboard/hhkb/rn42/rn42_task.c | 36 +--------------------------------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/keyboard/hhkb/rn42/rn42.c b/keyboard/hhkb/rn42/rn42.c index 710169ef..88951be4 100644 --- a/keyboard/hhkb/rn42/rn42.c +++ b/keyboard/hhkb/rn42/rn42.c @@ -134,6 +134,34 @@ static uint8_t leds = 0; static uint8_t keyboard_leds(void) { return leds; } void rn42_set_leds(uint8_t l) { leds = l; } + +void rn42_send_str(const char *str) +{ + uint8_t c; + while ((c = pgm_read_byte(str++))) + rn42_putc(c); +} + +const char *rn42_send_command(const char *cmd) +{ + static const char *s; + rn42_send_str(cmd); + wait_ms(500); + s = rn42_gets(100); + xprintf("%s\r\n", s); + rn42_print_response(); + return s; +} + +void rn42_print_response(void) +{ + int16_t c; + while ((c = rn42_getc()) != -1) { + xprintf("%c", c); + } +} + + static void send_keyboard(report_keyboard_t *report) { // wake from deep sleep diff --git a/keyboard/hhkb/rn42/rn42.h b/keyboard/hhkb/rn42/rn42.h index db6916fe..dee214cc 100644 --- a/keyboard/hhkb/rn42/rn42.h +++ b/keyboard/hhkb/rn42/rn42.h @@ -2,6 +2,7 @@ #define RN42_H #include +#include "host_driver.h" host_driver_t rn42_driver; host_driver_t rn42_config_driver; @@ -20,4 +21,10 @@ void rn42_cts_lo(void); bool rn42_linked(void); void rn42_set_leds(uint8_t l); +const char *rn42_send_command(const char *cmd); +void rn42_send_str(const char *str); +void rn42_print_response(void); +#define SEND_STR(str) rn42_send_str(PSTR(str)) +#define SEND_COMMAND(cmd) rn42_send_command(PSTR(cmd)) + #endif diff --git a/keyboard/hhkb/rn42/rn42_task.c b/keyboard/hhkb/rn42/rn42_task.c index 5107fef4..cef6a547 100644 --- a/keyboard/hhkb/rn42/rn42_task.c +++ b/keyboard/hhkb/rn42/rn42_task.c @@ -125,40 +125,6 @@ void rn42_task(void) ******************************************************************************/ static host_driver_t *prev_driver = &rn42_driver; -static void print_rn42(void) -{ - int16_t c; - while ((c = rn42_getc()) != -1) { - xprintf("%c", c); - } -} - -static void clear_rn42(void) -{ - while (rn42_getc() != -1) ; -} - -#define SEND_STR(str) send_str(PSTR(str)) -#define SEND_COMMAND(cmd) send_command(PSTR(cmd)) - -static void send_str(const char *str) -{ - uint8_t c; - while ((c = pgm_read_byte(str++))) - rn42_putc(c); -} - -static const char *send_command(const char *cmd) -{ - static const char *s; - send_str(cmd); - wait_ms(500); - s = rn42_gets(100); - xprintf("%s\r\n", s); - print_rn42(); - return s; -} - static void enter_command_mode(void) { prev_driver = host_get_driver(); @@ -171,7 +137,7 @@ static void enter_command_mode(void) wait_ms(1100); // need 1 sec SEND_COMMAND("$$$"); wait_ms(600); // need 1 sec - print_rn42(); + rn42_print_response(); const char *s = SEND_COMMAND("v\r\n"); if (strncmp("v", s, 1) != 0) SEND_COMMAND("+\r\n"); // local echo on }