Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MEMO.txt 19KB

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