summaryrefslogtreecommitdiff
path: root/keyboard/hhkb_rn42
diff options
context:
space:
mode:
authortmk <hasu@tmk-kbd.com>2015-01-11 02:39:32 +0900
committertmk <hasu@tmk-kbd.com>2015-01-15 17:08:49 +0900
commit4f121de7ad7782cde7d9d5c04adb3ef2561c5eaf (patch)
tree1a1ad73e9dd9e546ca97c7574bae5b3bd30e13a8 /keyboard/hhkb_rn42
parenta679928620c68e346fcfc864e8de632ce8c997c3 (diff)
downloadqmk_firmware-4f121de7ad7782cde7d9d5c04adb3ef2561c5eaf.tar.gz
qmk_firmware-4f121de7ad7782cde7d9d5c04adb3ef2561c5eaf.zip
rn42: Add rn42_getc and rn42_gets
Diffstat (limited to 'keyboard/hhkb_rn42')
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42.c29
-rw-r--r--keyboard/hhkb_rn42/rn42/rn42.h3
2 files changed, 32 insertions, 0 deletions
diff --git a/keyboard/hhkb_rn42/rn42/rn42.c b/keyboard/hhkb_rn42/rn42/rn42.c
index 1565b4cf14..aa6015cbf2 100644
--- a/keyboard/hhkb_rn42/rn42/rn42.c
+++ b/keyboard/hhkb_rn42/rn42/rn42.c
@@ -4,6 +4,7 @@
#include "serial.h"
#include "rn42.h"
#include "print.h"
+#include "timer.h"
#include "wait.h"
@@ -47,11 +48,39 @@ void rn42_init(void)
serial_init();
}
+int16_t rn42_getc(void)
+{
+ return serial_recv2();
+}
+
+char *rn42_gets(uint16_t timeout)
+{
+ static char s[16];
+ uint16_t t = timer_read();
+ uint8_t i = 0;
+ int16_t c;
+ while (i < 15 && timer_elapsed(t) < timeout) {
+ if ((c = rn42_getc()) != -1) {
+ if ((char)c == '\r') continue;
+ if ((char)c == '\n') break;
+ s[i++] = c;
+ }
+ }
+ s[i] = '\0';
+ return s;
+}
+
void rn42_putc(uint8_t c)
{
serial_send(c);
}
+void rn42_puts(char *s)
+{
+ while (*s)
+ serial_send(*s++);
+}
+
bool rn42_autoconnecting(void)
{
// GPIO6 for control connection(high: auto connect, low: disconnect)
diff --git a/keyboard/hhkb_rn42/rn42/rn42.h b/keyboard/hhkb_rn42/rn42/rn42.h
index 5283a3648c..86090be7c5 100644
--- a/keyboard/hhkb_rn42/rn42/rn42.h
+++ b/keyboard/hhkb_rn42/rn42/rn42.h
@@ -7,7 +7,10 @@ host_driver_t rn42_driver;
host_driver_t rn42_config_driver;
void rn42_init(void);
+int16_t rn42_getc(void);
+char *rn42_gets(uint16_t timeout);
void rn42_putc(uint8_t c);
+void rn42_puts(char *s);
bool rn42_autoconnecting(void);
void rn42_autoconnect(void);
void rn42_disconnect(void);