3 #include "host_driver.h"
11 static uint8_t keyboard_leds(void);
12 static void send_keyboard(report_keyboard_t
*report
);
13 static void send_mouse(report_mouse_t
*report
);
14 static void send_system(uint16_t data
);
15 static void send_consumer(uint16_t data
);
17 host_driver_t rn42_driver
= {
28 // JTAG disable for PORT F. write JTD bit twice within four cycles.
32 // PF7: BT connection control(high: connect, low: disconnect)
35 // PF6: linked(input without pull-up)
39 // PF1: RTS(low: allowed to send, high: not allowed)
43 // PD5: CTS(low: allow to send, high:not allow)
50 void rn42_putc(uint8_t c
)
55 bool rn42_autoconnecting(void)
57 // GPIO6 for control connection(high: auto connect, low: disconnect)
58 // Note that this needs config: SM,4(Auto-Connect DTR Mode)
59 return (PORTF
& (1<<7) ? true : false);
62 void rn42_autoconnect(void)
69 void rn42_disconnect(void)
78 // low when RN-42 is powered and ready to receive
82 void rn42_cts_hi(void)
88 void rn42_cts_lo(void)
94 bool rn42_linked(void)
100 static uint8_t keyboard_leds(void) { return 0; }
102 static void send_keyboard(report_keyboard_t
*report
)
104 // wake from deep sleep
106 PORTD |= (1<<5); // high
108 PORTD &= ~(1<<5); // low
111 serial_send(0xFD); // Raw report mode
112 serial_send(9); // length
113 serial_send(1); // descriptor type
114 serial_send(report
->mods
);
116 serial_send(report
->keys
[0]);
117 serial_send(report
->keys
[1]);
118 serial_send(report
->keys
[2]);
119 serial_send(report
->keys
[3]);
120 serial_send(report
->keys
[4]);
121 serial_send(report
->keys
[5]);
124 static void send_mouse(report_mouse_t
*report
)
126 // wake from deep sleep
128 PORTD |= (1<<5); // high
130 PORTD &= ~(1<<5); // low
133 serial_send(0xFD); // Raw report mode
134 serial_send(5); // length
135 serial_send(2); // descriptor type
136 serial_send(report
->buttons
);
137 serial_send(report
->x
);
138 serial_send(report
->y
);
139 serial_send(report
->v
);
142 static void send_system(uint16_t data
)
144 // Table 5-6 of RN-BT-DATA-UB
145 // 81,82,83 scan codes can be used?
149 static uint16_t usage2bits(uint16_t usage
)
152 case AC_HOME
: return 0x01;
153 case AL_EMAIL
: return 0x02;
154 case AC_SEARCH
: return 0x04;
155 //case AL_KBD_LAYOUT: return 0x08; // Apple virtual keybaord toggle
156 case AUDIO_VOL_UP
: return 0x10;
157 case AUDIO_VOL_DOWN
: return 0x20;
158 case AUDIO_MUTE
: return 0x40;
159 case TRANSPORT_PLAY_PAUSE
: return 0x80;
160 case TRANSPORT_NEXT_TRACK
: return 0x100;
161 case TRANSPORT_PREV_TRACK
: return 0x200;
162 case TRANSPORT_STOP
: return 0x400;
163 case TRANSPORT_STOP_EJECT
: return 0x800;
164 //case return 0x1000; // Fast forward
165 //case return 0x2000; // Rewind
166 //case return 0x4000; // Stop/eject
167 //case return 0x8000; // Internet browser
172 static void send_consumer(uint16_t data
)
174 uint16_t bits
= usage2bits(data
);
175 serial_send(0xFD); // Raw report mode
176 serial_send(3); // length
177 serial_send(3); // descriptor type
178 serial_send(bits
&0xFF);
179 serial_send((bits
>>8)&0xFF);
183 /* Null driver for config_mode */
184 static uint8_t config_keyboard_leds(void);
185 static void config_send_keyboard(report_keyboard_t
*report
);
186 static void config_send_mouse(report_mouse_t
*report
);
187 static void config_send_system(uint16_t data
);
188 static void config_send_consumer(uint16_t data
);
190 host_driver_t rn42_config_driver
= {
191 config_keyboard_leds
,
192 config_send_keyboard
,
198 static uint8_t config_keyboard_leds(void) { return 0; }
199 static void config_send_keyboard(report_keyboard_t
*report
) {}
200 static void config_send_mouse(report_mouse_t
*report
) {}
201 static void config_send_system(uint16_t data
) {}
202 static void config_send_consumer(uint16_t data
) {}