summaryrefslogtreecommitdiff
path: root/keyboard/hhkb_rn42
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-07-17 13:06:48 +0900
committertmk <nobody@nowhere>2014-07-30 14:38:26 +0900
commitfa545c87f74833856761572ef631d20accc1d026 (patch)
tree4cc7c02660a2401a9b7638ade6b460c7c573ff93 /keyboard/hhkb_rn42
parent862f519e241b83113566eebde71841958b2d00b7 (diff)
Fix rn42.h API
Diffstat (limited to 'keyboard/hhkb_rn42')
-rw-r--r--keyboard/hhkb_rn42/main.c68
-rw-r--r--keyboard/hhkb_rn42/rn42.c41
-rw-r--r--keyboard/hhkb_rn42/rn42.h10
3 files changed, 60 insertions, 59 deletions
diff --git a/keyboard/hhkb_rn42/main.c b/keyboard/hhkb_rn42/main.c
index 0b455193fb..edab699784 100644
--- a/keyboard/hhkb_rn42/main.c
+++ b/keyboard/hhkb_rn42/main.c
@@ -45,9 +45,6 @@ static void SetupHardware(void)
PORTD |= (1<<0);
DDRD &= ~(1<<1);
PORTD |= (1<<1);
-
- // CTS control
- CTS_INIT();
}
static bool force_usb = false;
@@ -75,7 +72,7 @@ int main(void)
/* init modules */
keyboard_init();
- if (rn42_ready()) {
+ if (!rn42_rts()) {
host_set_driver(&rn42_driver);
} else {
host_set_driver(&lufa_driver);
@@ -112,9 +109,9 @@ int main(void)
if (config_mode) {
while ((c = serial_recv2()) != -1) {
// without flow control it'll fail to receive data when flooded
- CTS_HI();
+ rn42_cts_hi();
xprintf("%c", c);
- CTS_LO();
+ rn42_cts_lo();
}
} else {
while ((c = serial_recv2()) != -1) {
@@ -148,10 +145,10 @@ int main(void)
/* Bluetooth mode when ready */
if (!config_mode && !force_usb) {
- if (rn42_ready() && host_get_driver() != &rn42_driver) {
+ if (!rn42_rts() && host_get_driver() != &rn42_driver) {
clear_keyboard();
host_set_driver(&rn42_driver);
- } else if (!rn42_ready() && host_get_driver() != &lufa_driver) {
+ } else if (rn42_rts() && host_get_driver() != &lufa_driver) {
clear_keyboard();
host_set_driver(&lufa_driver);
}
@@ -159,7 +156,10 @@ int main(void)
}
}
-static bool local_echo = false;
+
+/******************************************************************************
+ * Command
+ ******************************************************************************/
bool command_extra(uint8_t code)
{
static host_driver_t *prev_driver = &rn42_driver;
@@ -167,46 +167,37 @@ bool command_extra(uint8_t code)
case KC_H:
case KC_SLASH: /* ? */
print("\n\n----- Bluetooth RN-42 Help -----\n");
- print("w: toggle RN-42 config mode(enter/exit)\n");
- print("l: toggle print module output(local echo)\n");
- print("a: Bluetooth auto connect\n");
- print("del: Bluetooth disconnect\n");
- print("i: info\n");
+ print("Del: auto_connect/disconnect(enter/exit config mode)\n");
+ print("i: RN-42 info\n");
print("b: battery voltage\n");
if (config_mode) {
return true;
} else {
- print("u: force USB mode\n");
+ print("u: Force USB mode\n");
return false; // to display default command help
}
- case KC_W:
- if (!config_mode) {
- print("\nEnter RN-42 config mode\n");
- print("type $$$ to enter RN-42 command mode\n");
- print("type Delete to disconnect Bluetooth connection\n");
+ case KC_DELETE:
+ if (rn42_autoconnecting()) {
+ rn42_disconnect();
+ print("\nRN-42: disconnect\n");
+ print("Enter config mode\n");
+ print("type $$$ to start and + for local echo\n");
command_state = CONSOLE;
config_mode = true;
prev_driver = host_get_driver();
clear_keyboard();
- host_set_driver(&rn42_config_driver);
+ host_set_driver(&rn42_config_driver); // null driver; not to send a key to host
} else {
- print("\nExit RN-42 config mode\n");
+ rn42_autoconnect();
+ print("\nRN-42: auto_connect\n");
+ print("Exit config mode\n");
command_state = ONESHOT;
config_mode = false;
clear_keyboard();
host_set_driver(prev_driver);
}
return true;
- case KC_L:
- if (local_echo) {
- print("local echo off\n");
- local_echo = false;
- } else {
- print("local echo on\n");
- local_echo = true;
- }
- return true;
case KC_U:
if (config_mode) return false;
if (force_usb) {
@@ -219,20 +210,12 @@ bool command_extra(uint8_t code)
host_set_driver(&lufa_driver);
}
return true;
- case KC_A:
- print("auto connect\n");
- rn42_autoconnect();
- return true;
- case KC_DELETE:
- print("disconnect\n");
- rn42_disconnect();
- //rn42_putc('\0'); // see 5.3.4.4 DISCONNECT KEY of User's Guide
- return true;
case KC_I:
- print("\nRN-42 info\n");
+ print("\n----- RN-42 info -----\n");
xprintf("protocol: %s\n", (host_get_driver() == &rn42_driver) ? "RN-42" : "LUFA");
xprintf("force_usb: %X\n", force_usb);
- xprintf("rn42_ready(): %X\n", rn42_ready());
+ xprintf("rn42_autoconnecting(): %X\n", rn42_autoconnecting());
+ xprintf("rn42_rts(): %X\n", rn42_rts());
xprintf("config_mode: %X\n", config_mode);
return true;
case KC_B:
@@ -266,7 +249,6 @@ bool command_console_extra(uint8_t code)
switch (code) {
default:
rn42_putc(code2asc(code));
- if (local_echo) xprintf("%c", code2asc(code));
return true;
}
return false;
diff --git a/keyboard/hhkb_rn42/rn42.c b/keyboard/hhkb_rn42/rn42.c
index 89ecb199ca..a041cc366f 100644
--- a/keyboard/hhkb_rn42/rn42.c
+++ b/keyboard/hhkb_rn42/rn42.c
@@ -24,17 +24,17 @@ host_driver_t rn42_driver = {
void rn42_init(void)
{
- // PF1: check RTS(active low)
- DDRF &= ~(1<<1);
- PORTF &= ~(1<<1);
-
// PF7: BT connection control(HiZ: connect, low: disconnect)
// JTAG disable for PORT F. write JTD bit twice within four cycles.
MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);
rn42_autoconnect();
- // PD5: CTS (low: allow to send, high:not allowed)
+ // PF1: RTS(low: allowed to send, high: not allowed)
+ DDRF &= ~(1<<1);
+ PORTF &= ~(1<<1);
+
+ // PD5: CTS(low: allow to send, high:not allow)
DDRD |= (1<<5);
PORTD &= ~(1<<5);
@@ -46,22 +46,43 @@ void rn42_putc(uint8_t c)
serial_send(c);
}
+bool rn42_autoconnecting(void)
+{
+ // GPIO6 for control connection(high: auto connect, low: disconnect)
+ // Note that this needs config: SM,4(Auto-Connect DTR Mode)
+ return (PORTF & (1<<7) ? true : false);
+}
+
void rn42_autoconnect(void)
{
- DDRF &= ~(1<<7);
- PORTF &= ~(1<<7);
+ // hi to auto connect
+ DDRF |= (1<<7);
+ PORTF |= (1<<7);
}
void rn42_disconnect(void)
{
+ // low to disconnect
DDRF |= (1<<7);
PORTF &= ~(1<<7);
}
-bool rn42_ready(void)
+bool rn42_rts(void)
+{
+ // low when RN-42 is powered and ready to receive
+ return PINF&(1<<1);
+}
+
+void rn42_cts_hi(void)
{
- // RTS low
- return PINF&(1<<1) ? false : true;
+ // not allow to send
+ PORTD |= (1<<5);
+}
+
+void rn42_cts_lo(void)
+{
+ // allow to send
+ PORTD &= ~(1<<5);
}
diff --git a/keyboard/hhkb_rn42/rn42.h b/keyboard/hhkb_rn42/rn42.h
index a967a70d8a..4189733b49 100644
--- a/keyboard/hhkb_rn42/rn42.h
+++ b/keyboard/hhkb_rn42/rn42.h
@@ -3,18 +3,16 @@
#include <stdbool.h>
-// RN-42 CTS pin
-#define CTS_INIT() (DDRD |= (1<<5))
-#define CTS_HI() (PORTD |= (1<<5))
-#define CTS_LO() (PORTD &= ~(1<<5))
-
host_driver_t rn42_driver;
host_driver_t rn42_config_driver;
void rn42_init(void);
void rn42_putc(uint8_t c);
+bool rn42_autoconnecting(void);
void rn42_autoconnect(void);
void rn42_disconnect(void);
-bool rn42_ready(void);
+bool rn42_rts(void);
+void rn42_cts_hi(void);
+void rn42_cts_lo(void);
#endif