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 17KB

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