]> git.gir.st - tmk_keyboard.git/blob - keyboard/hhkb_rn42/MEMO.txt
Add FET swtich for battery ADC
[tmk_keyboard.git] / keyboard / hhkb_rn42 / MEMO.txt
1 Roving RN-42
2 ============
3
4 TODO
5 ----
6 Bug:
7 - with Nexus5 keyboard and mouse are very laggy.
8
9 Power saving:
10 - 8MHz clock
11 - When not connected in a few minutes get into deep sleep to save battery life
12 - CTS is needed for waking up from deep sleep? How deep sleep is activated?
13 - firmware controlled 3.3V DC converter to switch on/off BT module
14 - sleep MCU and BT module(keyboard is not used)
15 - deep sleep MCU and BT module(keyboard is not used for long time)
16 - deep sleep MCU and turn off BT module(keyboard is not used and not connected)
17 - Battery ADC; switching, high resistance
18 - switching gnd end of divider with PF4
19 - high resistor 100K/1M?
20 capacitor 10nF
21 http://www.eevblog.com/forum/beginners/measuring-battery-voltage-without-consuming-current/
22
23 Improving:
24 - BT LED; connecting, linked, sleeping, deep sleeping
25 - Battry LED; blink(using timer?)
26 - move rn42 to protocol directory when it becomes reusable stack
27 - LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256).
28 - ADC resolution
29 AVR120
30 AVR32138
31
32 Testing:
33 - Factroy reset doesn't work; need to **test again** 10K pull-up is too high?
34 - Lipo voltage ADC value is not stabilized
35 - DCDC converter: squeaky inducter; try other inductors
36
37 - Keymap layer bug: during space is pressed(mousekey) press Fn(HHKB) then release space before Fn, in result HHKB layer is locked(toggled) unintentionally.
38
39
40 Done:
41 - low battery alert(solid light) 09/04
42
43
44 Power routing
45 -------------
46 Current:
47 (USB) +---(Lipo)
48 | | |
49 | | +------+ DPDT
50 | | |Switch/-----------------------+
51 | | +------+ |
52 | +-------+ | |
53 +-|Charger| | |
54 | +-------+ | +---+ |
55 | | |MCU| |
56 | | +---+ |
57 | | | |
58 | | | |
59 +--------------+ +-----+ +------+ +---/--+ +-----+
60 |Power Selector|--|DC 5V|--|DC3.3V|---|Switch|----|RN-42|
61 +--------------+ +-----+ +------+ +------+ +-----+
62 USB Power is boosted unnecessarily, not harmful?
63
64 Idea 1:
65 (USB) +---(Lipo)
66 | | |
67 | | +------+ DPDT
68 | | |Switch/----------+
69 | | +------+ |
70 | +-------+ | |
71 +-|Charger| | |
72 | +-------+ | +---+ |
73 | +-----+ |MCU| |
74 | |DC 5V| +---+ |
75 | +-----+ | |
76 | | | |
77 +--------------+ | +---/--+ +------+ +-----+
78 |Power Selector|-----+---|Switch|----|DC3.3V|-----|RN-42|
79 +--------------+ +------+ +------+ +-----+
80 To enable BT when USB powered it still needs to turn siwtch on, Lipo consumes quinscent current at 5V converter in vain.(Not good)
81
82 Idea 2:
83 (USB) +---(Lipo)
84 | | |
85 | | +------+
86 | | |Switch|
87 | | +------+
88 | +-------+ |
89 +-|Charger| |
90 | +-------+ | +---+
91 | +-----+ |MCU|----+ Controlled by firmware
92 | |DC 5V| +---+ | On: Lipo powered
93 | +-----+ | | Off: USB powered
94 | | | |enable
95 +--------------+ | +------+ +-----+
96 |Power Selector|-----+---|DC3.3V|-----|RN-42|
97 +--------------+ +------+ +-----+
98 MCU can controlled power of RN-42 without hardware switch.
99 When USB powered and switch is on Lipo consumes quinscent current at 5V converter in vain.(Not good)
100
101 Idea 3:
102 (USB) +---(Lipo)
103 | | |
104 | | +------+
105 | | |Switch|SPST(or without)
106 | | +------+
107 | +-------+ |
108 +-|Charger| |
109 | +-------+ | +---+
110 | | |MCU|----+ Controlled by firmware
111 | | +---+ | On: Lipo powered
112 | | | | Off: USB powered
113 | | | |enable
114 +--------------+ +-----+ +------+ +-----+
115 |Power Selector|-|DC 5V|-|DC3.3V|-----|RN-42|
116 +--------------+ +-----+ +------+ +-----+
117 Switch is needed to save Lipo when not used because decent power saving is not available now. If firmware can turn off BT module completely and make MCU deep sleep the switch will be not even needed.
118
119
120
121
122
123 DONE:
124 - BT_INDICATOR LED turns on wrongly when touching line or pin. -- pull-up enabled on PF6/GPIO2 08/30
125 - Lipo charger configuration: fast charge time: USB charger spec? -- used 2kohm
126 - use LED of charger to alarm low battery. LED should be powered directly from Lipo? - cancel; powered from VUSB
127 - Use RTS in serial_uart.c to resolve missing chars from help message of RN-42 - done
128 - CTS/RTS lines are needed? just connect in loop back if no flow control is needed. - done
129 - add IO pin to charger status CHRG; LED control(low) and detect charge status(input HiZ) 07.24
130 - LINKED: add trace on PIO2 to PF6 07.24
131 - Lipo voltage ADC sensing
132 - Lipo charger MCP73831: needs capacitor 4.7uF *2
133 - USB connection check - 07.01
134 - BT on/off check: whether RX line is pulled up? - checking RTS 07.01
135 - USB/BT switching BT is on -> BT, BT is off -> USB - 07.01
136 - Under voltage lock out UVLO for protection of Lipo - Lipo has discharge protection at 3.100V 07.01
137 - Power saving: HHKB scan, BT radio control - 9h with 850mAh, this is enough 07.01
138 - Power selector doesn't work; Q4 MOSFET leaks from Lipo to USB power line. -- use Schottky instead 07/04
139
140
141
142 TROUBLE SHOOT
143 -------------
144 07/16 After fix of voltage dividor on GPIO6, had a trouble that it could not send a char to BT module, though could receive.
145 Found R8 had wrong 1K resistor and changed to 10K, after that it can send to the module again. Not sure how it had sent with the wrong 1K before.
146
147 07/18 On Linux, had an USB related trouble; keyobard or console didn't work for some reason. Changing PID cured this problem. Very annoying, took very long time before resolved it.
148
149
150
151 Lipo
152 ----
153 850mA lasts around 9 hours(07/28)
154
155 Sparkfun Polymer Lithium Ion Battery 850mAh:
156 https://www.sparkfun.com/products/341
157 Lipo Cell spec:
158 https://www.sparkfun.com/datasheets/Batteries/063048%20Li-polymer.pdf
159 Protection spec:
160 http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Prototyping/BatteryProtection.pdf
161 min typical max
162 over-charge 4.255 4.280 4.305
163 over-charge discover? 4.030 4.080 4.130
164 over-discharge 2.827 2.900 2.973
165 over-discharge discover 3.022 3.100 3.178
166
167 ADC voltage monitor: voltage divider 10K+10K(0.5)
168 ADC=V*0.5/2.56*1024
169
170 V ADC
171 ------------------
172 4.20 0x347(839)
173 3.10 0x26b(619)
174
175
176
177
178 Configuration
179 -------------
180 Ver 6.15 04/26/2013
181 (c) Roving Networks
182 ***Settings***
183 BTA=0006664B3AE3
184 BTName=tmkBT-3AE3
185 Baudrt(SW4)=115K
186 Mode =DTR
187 Authen=2
188 Bonded=0
189 Rem=000000000000
190 ***ADVANCED Settings***
191 SrvName= keyboard/mouse
192 SrvClass=0000
193 DevClass=0000
194 InqWindw=0100
195 PagWindw=0100
196 CfgTimer=255
197 StatuStr=NULL
198 HidFlags=3c
199 DTRtimer=8
200 KeySwapr=0
201 ***OTHER Settings***
202 Profile= HID
203 CfgChar= $
204 SniffEna=8010
205 LowPower=0
206 TX Power=0
207 IOPorts= 0
208 IOValues=0
209 Sleeptmr=0
210 DebugMod=0
211 RoleSwch=0
212
213
214
215 Serial connection
216 -----------------
217 Serial line: 115200bps, 8bit, 1-stopbit, non-parity, no flow control
218 SSP: 115200bps, 8bit, 1-stopbit, non-parity, no flow control(via Bluetooth)
219
220 To enter command mode disconnect the module from host and type '$$$'.(you will see 'CMD')
221 To exit type '---'(you will see 'END') and '+' to get local echo.
222
223
224
225 Setting command mode
226 --------------------
227 S-,tmkBT // Device name
228 SS,keyboard/mouse // service name
229 SM,4 // Auto Connect DTR mode
230 SW,8010 // Sniff enable 0x10*0.625ms=10ms; 50ms is laggish and not much power save
231 S~,6 // HID profile
232 SH,003C // HID register
233 SY,0004 // Transmit power
234
235
236
237
238 Other options:
239 SC,0000 // COD: 000005C0 (see HID spec/Bluegiga doc)
240 SD,05C0 // bit 12-8 7 6 5-0
241 // 00101 1 1 0
242 // peripheral pointing keybaord joystick, gamepad, ...
243 SM,6 // Pairing mode: auto connect
244 SM,4 // Master mode: Connection can be controled with GPIO6
245
246
247
248
249 HID profile
250 -----------
251 S~,6 HID profile
252 S~,0 SPP profile
253 R,1 reboot
254
255
256 Apple iOS
257 ---------
258 Keyboard can be used with iPhone, but mouse cannot.
259 To operate iOS with keyboard is not so useful, though.
260 There may be iOS specific scancodes?
261
262
263 HID flag register
264 -----------------
265 SH,0200
266 GH
267
268 10 0000 0000(0200) default
269 00 0011 1000(0038) Combo
270 || | | |\_\____ number of paired devices to which the module can reconnect
271 || | | \_______ send out reports over UART (0xFF <len> <data>)
272 || \__\_________ descriptor type
273 |\______________ toggle virtual keyboard on iOS when first connected
274 \_______________ Force HID mode if GPIO11 is high on power-up
275
276 Descriptor type:
277 0000: keybaord
278 0001: Game Pad
279 0010: Mouse
280 0011: Combo
281 0100: Joystick
282 1xxx: reserved
283
284
285 Out report - Indicator
286 ----------------------
287 0xFE 0x02 0x01 <LED_state>
288
289
290 LED Status
291 ----------
292 Configuring 10 times per sec
293 Startup/configuration timer 2 times per sec
294 Discoverable/Inquiring/Idle once per sec
295 Connected solid on
296
297
298 Pairing
299 -------
300 First, host initiates pairing process and once it is done, auto connect will work thereafter.
301 SM,3 Master mode
302 SM,4 Auto Connect DTR Mode uses GPIO6 to make and break connection(Mode =DTR)
303 confirm: auto connect works and control connection with GPIO6
304 SM,5 Auto Connect ANY Mode (Mode =ANY)
305 each time GPIO is set, make inquiry and connect to the first found device
306 SM,6 automatically reconnect(Mode =Pair)
307 confirm: auto connect works well but difficult to enter command mode.
308
309
310 Fast data mode
311 --------------
312 The module enters fast data mode after 'remote configuration timer' window is passed from power on.
313 In this mode the module does not accept '$$$' to enter command mode.
314
315 Power Management
316 ----------------
317 Inquiry and Page window Idle or Active (3.1.1)
318 Downside: delay in discovery or connection time
319 SI, // set inquiry scan window(discovery) on/off duty?
320 SJ, // set page scan window(connection)
321 This reduces averaege power >20mA to 5mA(3mA in Sniff mode)
322
323 Sniff mode Transmit
324 Sniff mode is disabled by default and radio is active continuously when connected.(25-30mA)
325 In Sniff mode the radio wakes up intermittently and sleeps in very low power mode.(2mA)
326 SW,<val> // set interval timer(*0.625ms) 0000-7FFF
327
328 Deep sleep Idle (3.1.2)
329 In this mode the module shuts down completly and only draws about 300uA. To enable this set the most signifant bit(0x8000) of Sniff interaval timer.
330 SW,8320 // deep sleep enable(interval=0x320*0.625=500ms)
331 In normal sleep the firmware is still running in idle mode, and wakes up about 20 times per second to check ports, update LEDs, etc. During deep sleep, the firmware actually stops runnig some tasks and the LEDs only update about once per second.
332 To wake from deep sleep there are three ways: (in worst case wake up takes 5ms)
333 *send a charactor to the UART(first charactor will be lost)
334 *toggle CTS low to high and wait 5ms
335 *wake automatically every slot time(<val>*0.625ms)
336 Once the radio is awake it stay active for exactly 1 second of inactivity and then sleeps again.
337 Downside: latency and data loss
338
339 Disable Output driver Idle or Active (3.1.3)
340 S%,1000 // set all GPIO pins(0-11) to inputs.
341
342 Lower Transmit Power Idle or Active (3.1.4)
343 SY,<hex> // transmit power setting(takes effect after a power cycle and reboot)
344 Downside: reducing effective range
345
346
347 Optimizig for Latency
348 ---------------------
349 By default the firmware is optimized for throughput.
350 SQ,16 // set latency bit
351 SQ,0 // unset latency bit
352
353
354 Configuration timer settings
355 ----------------------------
356 Remote configuration is used for the module to be configured with various commands over Bluetooth(SPP profile only?).
357
358 The module has remote configuration timer to allow remote configuration over Bluetooth after power up in Slave mode. In Master modes the remote configuration timer is set to 0(no remote configuration). (In Trigger Master mode the timer is used as an idle timer to break the connection after time expires with no charactors receive.)
359 ST,0 // no remote, no local when connected
360 ST,<1-252> // local and remote with timeout in seconds from power up
361 ST,253 // local only without timeout
362 ST,254 // remote only without timeout
363 ST,255 // local and remote without timeout
364
365
366 Android
367 -------
368 3.7.1.5 Note: To connect with Android phone the modules must wake up 11ms every 2.5seconds.
369
370
371 Commands
372 --------
373 SC,
374 SM,<val>
375 SD,
376 SP,<string> Pin code(alpahnumeric)
377 SQ,<mask> Special configuration(GPIO, discovery mode, low latency, reboot, UART)
378 SR,<hex> Store remote address
379 SR,Z Erase all address
380 SS,<string> Set service name(1-20)**
381 ST,<val> Remote configuration timer(Master:0, Slave:0-255, Triger:as idle timer)
382 SU,<val> UART baud rate
383 SW,<val> low-power sniff mode** deep sleep and wake up every 625us * <val>
384 SX,<0|1> bonding enable only acceps device that matches the stored address
385 SY,<hex> power setting**
386 SZ,<val> non-standard raw baud rate <val>=baud*0.004096
387 S~,<val> Profile 0:SPP, 5:APL, 6:HID
388 S-,<string> Device name -15 alphanumeric charactors
389 S?,<0|1> role switch enable
390 S$,<char> command mode char
391 $|,<hex> low-power connect mode deep sleep/active(discoverable and connectable) cycle
392 D display basic setting
393 E display extended setting
394 GB display the device's Bluetooth address
395 GF display Bluetooth address of connected device
396 GK show connection status
397 GR show remote address for reconnecting
398 G& show GPIO pin
399 G<char> show stored setting
400 + toggle local echo on/off
401 & show GPIO 3,4,6,7(DIP switch)
402 C connect to stored remote address
403 C,<address> connect last address
404 CFI connect and go into fast data mode
405 CFR connect and go into fast data mode
406 CT,<address>,<val> connect to the address and disconnect after val?
407 F,1 fast data mod:
408 H display help
409 I,<time>,<cod> inquiry scan with <cod>
410 IN
411 IQ scan
412 IS inquiry scan with 001F00
413 J hide pin code
414 K, kill disconnects current connection
415 L link quality
416 M show modem signlal status
417 O display other settings
418 P,<car> pass through?
419 Q quiet mode make the module not discoverable
420 Q,0 discoverable and connectable
421 Q,1 not discoverable and not connectable
422 Q,2 not discoverable and connectable
423 Q,? display current quiet mode
424 R,1 reboot
425 T,<0|1> pass received data while in command mode
426 U,<baud>,<parity> change UART setting tentatively
427 V display firmware version
428 W wake from quiet mode enable discovery and connection
429 Z deep sleep mode(<2mA)
430
431
432
433 help
434 ----
435 *** SET COMMANDS ***
436 SA,<3,0> - Authentication
437 SC,<hex> - Service Class
438 SD,<hex> - Device Class
439 SE,<1-16> - UUID
440 SF,1 - Factory Defaults
441 SH,<hex> - HID flags
442 SI,<hex> - Inquiry Scan Window
443 SJ,<hex> - Page Scan Window
444 SL,<E,O,N> - Parity
445 SM,<0-5> - Mode (0=slav,1=mstr,2=trig,3=auto,4=DTR,5=Any)
446 SN,<name> - Name
447 SO,<text> - conn/discon Status
448 SP,<text> - Pin Code
449 SR,<adr> - Remote Address
450 SS,<text> - Service Name
451 ST,<num> - Config Timer
452 SU,<rate> - Baudrate
453 SW,<hex> - Sniff Rate
454 SX,<1,0> - Bonding
455 SY,<hex> - TX power
456 SZ,<num> - Raw Baudrate
457 S~,<0-6> - Profile (0=SPP,1=DCE,2=DTE,3=MDM,4=D&S,6=HID
458 S?,<0-1> - role switch
459 S$,<char> - CMD mode char
460 S@,<hex> - io port dir
461 S&,<hex> - io port val
462 S%,<hex> - io boot dir
463 S^,<hex> - io boot val
464 S*,<hex> - pio(8-11) set
465 S|,<hex> - low power timers
466 S+,<num> - DTR timer
467 S=,<hex> - Key mapper
468 S:,<num> - sleep timer
469 *** DISPLAY ***
470 D - Basic Settings
471 E - Extended Settings
472 G<X> - Stored setting
473 GB - BT Address
474 GF - BT Address of Last Connection
475 GK - Connect Status
476 G& - I/O Ports
477 V - Firmare version
478 *** OTHER ***
479 C,<adr> - Connect
480 F,1 - Fast Mode
481 I,<time>,<cod> - Device Scan Inquiry
482 J - Hide Pin Code
483 K, - Kill (disconnect)
484 L, - toggle local echo
485 P,<text> - Pass Thru
486 Q - Quiet (no discovery)
487 R,1 - Reboot
488 T,<0,1> - send data in CMD mode
489 U,<rate>,<E,O,N> - Temp Uart Change
490 Z - low power sleep
491 & - Read switches
Imprint / Impressum