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