Keyboard firmwares for Atmel AVR and Cortex-M
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MEMO.txt 19KB

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