2 #include "host_driver.h"
10 static uint8_t keyboard_leds(void);
11 static void send_keyboard(report_keyboard_t *report);
12 static void send_mouse(report_mouse_t *report);
13 static void send_system(uint16_t data);
14 static void send_consumer(uint16_t data);
16 host_driver_t rn42_driver = {
27 // PF1: check RTS(active low)
31 // PF7: BT connection control(HiZ: connect, low: disconnect)
32 // JTAG disable for PORT F. write JTD bit twice within four cycles.
37 // PD5: CTS (low: allow to send, high:not allowed)
44 void rn42_putc(uint8_t c)
49 void rn42_autoconnect(void)
55 void rn42_disconnect(void)
64 return PINF&(1<<1) ? false : true;
68 static uint8_t keyboard_leds(void) { return 0; }
70 static void send_keyboard(report_keyboard_t *report)
72 // wake from deep sleep
74 PORTD |= (1<<5); // high
76 PORTD &= ~(1<<5); // low
79 serial_send(0xFD); // Raw report mode
80 serial_send(9); // length
81 serial_send(1); // descriptor type
82 serial_send(report->mods);
84 serial_send(report->keys[0]);
85 serial_send(report->keys[1]);
86 serial_send(report->keys[2]);
87 serial_send(report->keys[3]);
88 serial_send(report->keys[4]);
89 serial_send(report->keys[5]);
92 static void send_mouse(report_mouse_t *report)
94 // wake from deep sleep
96 PORTD |= (1<<5); // high
98 PORTD &= ~(1<<5); // low
101 serial_send(0xFD); // Raw report mode
102 serial_send(5); // length
103 serial_send(2); // descriptor type
104 serial_send(report->buttons);
105 serial_send(report->x);
106 serial_send(report->y);
107 serial_send(report->v);
110 static void send_system(uint16_t data)
112 // Table 5-6 of RN-BT-DATA-UB
113 // 81,82,83 scan codes can be used?
117 static uint16_t usage2bits(uint16_t usage)
120 case AC_HOME: return 0x01;
121 case AL_EMAIL: return 0x02;
122 case AC_SEARCH: return 0x04;
123 //case AL_KBD_LAYOUT: return 0x08; // Apple virtual keybaord toggle
124 case AUDIO_VOL_UP: return 0x10;
125 case AUDIO_VOL_DOWN: return 0x20;
126 case AUDIO_MUTE: return 0x40;
127 case TRANSPORT_PLAY_PAUSE: return 0x80;
128 case TRANSPORT_NEXT_TRACK: return 0x100;
129 case TRANSPORT_PREV_TRACK: return 0x200;
130 case TRANSPORT_STOP: return 0x400;
131 case TRANSPORT_STOP_EJECT: return 0x800;
132 //case return 0x1000; // Fast forward
133 //case return 0x2000; // Rewind
134 //case return 0x4000; // Stop/eject
135 //case return 0x8000; // Internet browser
140 static void send_consumer(uint16_t data)
142 uint16_t bits = usage2bits(data);
143 serial_send(0xFD); // Raw report mode
144 serial_send(3); // length
145 serial_send(3); // descriptor type
146 serial_send(bits&0xFF);
147 serial_send((bits>>8)&0xFF);
151 /* Null driver for config_mode */
152 static uint8_t config_keyboard_leds(void);
153 static void config_send_keyboard(report_keyboard_t *report);
154 static void config_send_mouse(report_mouse_t *report);
155 static void config_send_system(uint16_t data);
156 static void config_send_consumer(uint16_t data);
158 host_driver_t rn42_config_driver = {
159 config_keyboard_leds,
160 config_send_keyboard,
166 static uint8_t config_keyboard_leds(void) { return 0; }
167 static void config_send_keyboard(report_keyboard_t *report) {}
168 static void config_send_mouse(report_mouse_t *report) {}
169 static void config_send_system(uint16_t data) {}
170 static void config_send_consumer(uint16_t data) {}