]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - keyboard/hhkb_rn42/rn42.c
Add rn42_task
[tmk_firmware.git] / keyboard / hhkb_rn42 / rn42.c
index dceea72ca056888579fc13eca5e2cfc30c050bce..3fcd64ad6a5276b8775d35d1f9b9b106ef6cfb04 100644 (file)
@@ -1,3 +1,4 @@
+#include <avr/io.h>
 #include "host.h"
 #include "host_driver.h"
 #include "serial.h"
@@ -24,17 +25,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 +47,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)
+{
+    // not allow to send
+    PORTD |= (1<<5);
+}
+
+void rn42_cts_lo(void)
 {
-    // RTS low
-    return PINF&(1<<1) ? false : true;
+    // allow to send
+    PORTD &= ~(1<<5);
 }
 
 
@@ -70,9 +92,11 @@ static uint8_t keyboard_leds(void) { return 0; }
 static void send_keyboard(report_keyboard_t *report)
 {
     // wake from deep sleep
+/*
     PORTD |= (1<<5);    // high
     wait_ms(5);
     PORTD &= ~(1<<5);   // low
+*/
 
     serial_send(0xFD);  // Raw report mode
     serial_send(9);     // length
@@ -90,9 +114,11 @@ static void send_keyboard(report_keyboard_t *report)
 static void send_mouse(report_mouse_t *report)
 {
     // wake from deep sleep
+/*
     PORTD |= (1<<5);    // high
     wait_ms(5);
     PORTD &= ~(1<<5);   // low
+*/
 
     serial_send(0xFD);  // Raw report mode
     serial_send(5);     // length
@@ -139,8 +165,8 @@ static void send_consumer(uint16_t data)
     serial_send(0xFD);  // Raw report mode
     serial_send(3);     // length
     serial_send(3);     // descriptor type
-    serial_send((bits>>8)&0xFF);
     serial_send(bits&0xFF);
+    serial_send((bits>>8)&0xFF);
 }