logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

memo.md (6065B)


  1. ## Hardware Information
  2. The YANG HHKB BLE controller design is similiar to hasu's
  3. controller. Most pins are compatiable.
  4. **MCU**: ATmega32U4
  5. **Bluetooth**: MDBT40 (nRF51822-based), with Adafruit Bluefruit LE UART Friend firmware.
  6. **Power**: 3.3V
  7. **CPU Frequency**: 8MHz
  8. **Bootloader**: Lufa MassStorage
  9. ## Pin usage
  10. | Description | HASU pin usage | YANG mod changed |
  11. |:------------------------------------ | ---------------------- | -------------------------- |
  12. | ~KEY: Lo(0) when key is pressed | PD7 input(with pullup) | |
  13. | Hysteresis: Hi(1) if key was pressed | PB7 output | |
  14. | Row selector bit0 | PB0 output | |
  15. | Row selector bit1 | PB1 output | |
  16. | Row selector bit2 | PB2 output | |
  17. | Col selector bit0 | PB3 output | |
  18. | Col selector bit1 | PB4 output | |
  19. | Col selector bit2 | PB5 output | |
  20. | Key unable | PB6 output | |
  21. | Switch power | PD4 output | PD6 output (PMOS FET) |
  22. | Bluetooth UART Rx | PC4 input | PD2 |
  23. | Bluetooth UART Tx | PC5 output | PD3 |
  24. | Bluetooth power | | PD5 output (low: power on) |
  25. | LED 0 | | PF4 |
  26. | LED 2 | | PF1 |
  27. | LED 4 | | PF0 |
  28. | Unused for PRO2 | PC6 | |
  29. | Unused for PRO2 | PC7 | |
  30. | Inner USB power | | PF7 |
  31. ## How to flash LUFA MassStorage bootloader on Linux
  32. The FAT filesystem on Linux very often cannot flush the write cache,
  33. leading to broken firmware in the flash.
  34. We can use `dd` to write to the virtual block storage directly to
  35. bypass the vfs layer.
  36. ```
  37. dd if=FLASH.bin of=<path of virtual block device> seek=4
  38. ```
  39. Skip 4 sectors because the default sector size of the virtual device
  40. and dd is 512 bytes and the emulated flash file starts at 5th sector.
  41. ## How to find the path of the virtual block device
  42. After the keyboard boots into flash mode, on Linux system you should
  43. be able to find the block device in `dmesg` logs.
  44. For exmaple if you type
  45. ```
  46. sudo dmesg
  47. ```
  48. You should find something like
  49. ```
  50. [357885.143593] usb 1-1.4: USB disconnect, device number 24
  51. [357885.627740] usb 1-1.4: new full-speed USB device number 25 using xhci_hcd
  52. [357885.729486] usb 1-1.4: New USB device found, idVendor=03eb, idProduct=1962, bcdDevice= 0.01
  53. [357885.729492] usb 1-1.4: New USB device strings: Mfr=0, Product=0, SerialNumber=0
  54. [357885.745620] SCSI subsystem initialized
  55. [357885.746712] usb-storage 1-1.4:1.0: USB Mass Storage device detected
  56. [357885.746818] scsi host0: usb-storage 1-1.4:1.0
  57. [357885.746919] usbcore: registered new interface driver usb-storage
  58. [357885.747689] usbcore: registered new interface driver uas
  59. [357886.766755] scsi 0:0:0:0: Direct-Access LUFA Bootloader 0.00 PQ: 0 ANSI: 0
  60. [357886.773216] scsi 0:0:0:0: Attached scsi generic sg0 type 0
  61. [357886.777474] sd 0:0:0:0: [sdx] 134 512-byte logical blocks: (68.6 kB/67.0 KiB)
  62. [357886.780300] sd 0:0:0:0: [sdx] Write Protect is off
  63. [357886.780302] sd 0:0:0:0: [sdx] Mode Sense: 00 00 00 00
  64. [357886.783113] sd 0:0:0:0: [sdx] Asking for cache data failed
  65. [357886.783114] sd 0:0:0:0: [sdx] Assuming drive cache: write through
  66. [357886.842676] sdx:
  67. [357886.859528] sd 0:0:0:0: [sdx] Attached SCSI removable disk
  68. ```
  69. The `sdx` is the block device name and the full path is at `/dev/sdx`
  70. The above flash command will become
  71. ```
  72. dd if=FLASH.bin of=/dev/sdx seek=4
  73. ```
  74. ## Adafruit Bluefruit LE UART configuraton
  75. The default baud rate used by the firmware is 76800 although adafruit
  76. do not recommend using higher baudrates than 9600 because the nRF51
  77. UART can drop characters.
  78. Double speed mode to get more accurate async reading because the F_CPU
  79. speed is 8MHz.
  80. ## Power saving mode design
  81. Power saving is only enabled when USB is detached and using battery
  82. power. Here we define several levels of power saving mode, each saves
  83. more power but takes longer to resume operation.
  84. 1. Level 1: idle mode is activated after a short configurable time
  85. (MATRIX_POWER_SAVE_TIMEOUT_MS) MCU is put into sleep mode and only
  86. scan the matrix per 15ms. PORTB pins are set to input with pull-up
  87. to save power. Sensing PCB is powered down between scans.
  88. 2. Level 2: after idling for longer (MATRIX_POWER_SAVE_TIMEOUT_L2_MS)
  89. we entry this state. Matrix scan is skipped until the time lapses
  90. 900ms.
  91. 2. Level 3: sleep mode is activated after a longer timeout
  92. (MATRIX_POWER_SAVE_TIMEOUT_L3_MS) Bluetooth module is powered down.
  93. ## Battery reading
  94. VBAT is connected to AIN6 pin on the MDBT40 module and the AREF pin is
  95. the reference voltage. Doing a ADC with AT+HWDAC=6 will return the
  96. difference between VBAT and VREF.
  97. It seems when fully charged the ADC read is 550. Likely VREF is 3311mV
  98. and the fully charged VBAT is thus 3861mV.
  99. Enable battery service with AT+BLEBATTEN=1 first then we can update the
  100. battery level by using AT+BLEBATTVAL=%d
  101. ## References
  102. * https://github.com/joric/qmk/wiki/hhkb_ble
  103. * https://github.com/tomsmalley/custom-topre-guide
  104. * https://github.com/abcminiuser/lufa/blob/master/Bootloaders/MassStorage/Lib/VirtualFAT.h