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
73 PORTD |= (1<<5); // high
75 PORTD &= ~(1<<5); // low
77 serial_send(0xFD); // Raw report mode
78 serial_send(9); // length
79 serial_send(1); // descriptor type
80 serial_send(report->mods);
82 serial_send(report->keys[0]);
83 serial_send(report->keys[1]);
84 serial_send(report->keys[2]);
85 serial_send(report->keys[3]);
86 serial_send(report->keys[4]);
87 serial_send(report->keys[5]);
90 static void send_mouse(report_mouse_t *report)
92 // wake from deep sleep
93 PORTD |= (1<<5); // high
95 PORTD &= ~(1<<5); // low
97 serial_send(0xFD); // Raw report mode
98 serial_send(5); // length
99 serial_send(2); // descriptor type
100 serial_send(report->buttons);
101 serial_send(report->x);
102 serial_send(report->y);
103 serial_send(report->v);
106 static void send_system(uint16_t data)
108 // Table 5-6 of RN-BT-DATA-UB
109 // 81,82,83 scan codes can be used?
113 static uint16_t usage2bits(uint16_t usage)
116 case AC_HOME: return 0x01;
117 case AL_EMAIL: return 0x02;
118 case AC_SEARCH: return 0x04;
119 //case AL_KBD_LAYOUT: return 0x08; // Apple virtual keybaord toggle
120 case AUDIO_VOL_UP: return 0x10;
121 case AUDIO_VOL_DOWN: return 0x20;
122 case AUDIO_MUTE: return 0x40;
123 case TRANSPORT_PLAY_PAUSE: return 0x80;
124 case TRANSPORT_NEXT_TRACK: return 0x100;
125 case TRANSPORT_PREV_TRACK: return 0x200;
126 case TRANSPORT_STOP: return 0x400;
127 case TRANSPORT_STOP_EJECT: return 0x800;
128 //case return 0x1000; // Fast forward
129 //case return 0x2000; // Rewind
130 //case return 0x4000; // Stop/eject
131 //case return 0x8000; // Internet browser
136 static void send_consumer(uint16_t data)
138 uint16_t bits = usage2bits(data);
139 serial_send(0xFD); // Raw report mode
140 serial_send(3); // length
141 serial_send(3); // descriptor type
142 serial_send(bits&0xFF);
143 serial_send((bits>>8)&0xFF);
147 /* Null driver for config_mode */
148 static uint8_t config_keyboard_leds(void);
149 static void config_send_keyboard(report_keyboard_t *report);
150 static void config_send_mouse(report_mouse_t *report);
151 static void config_send_system(uint16_t data);
152 static void config_send_consumer(uint16_t data);
154 host_driver_t rn42_config_driver = {
155 config_keyboard_leds,
156 config_send_keyboard,
162 static uint8_t config_keyboard_leds(void) { return 0; }
163 static void config_send_keyboard(report_keyboard_t *report) {}
164 static void config_send_mouse(report_mouse_t *report) {}
165 static void config_send_system(uint16_t data) {}
166 static void config_send_consumer(uint16_t data) {}