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