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