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.

244 lines
12 KiB

  1. < [Known issues](known_issues.md) | [Index](../README.md) | [Sponsoring](sponsoring.md) >
  2. # Hardware information
  3. In this section, you can find some of the information that was gathered
  4. during the reverse engineering of the Bedside Lamp 2 hardware.
  5. Table of contents:
  6. * [High level overview](#high-level-overview)
  7. * [ESP32 pinout](#esp32-pinout)
  8. * [Front panel](#front-panel)
  9. ## High level overview
  10. No documentation is complete without some ASCII art schematics.
  11. ```
  12. RX/TX/GND for
  13. 12V power supply flashing and logs
  14. | |
  15. v | Front panel
  16. +---------------+ +---------------+ .---.
  17. | Power supply |---- 3.3V -.----->| ESP-WROOM-32D | | O | -- color
  18. +---------------+ \ | single core | | | button
  19. | \ | 4 MB flash | | | |
  20. 12V \ +---------------+ | | |
  21. | \ | ^ | | | | -- slider
  22. | `------|--|--|--- 3.3V ---->| | |
  23. | | | | | | |
  24. v | | +--- I2C ------| | |
  25. +---------------+ | | | | |
  26. | RGB and white |<---- RGBW + master ---+ +------ IRQ ------| | power
  27. | LED circuitry | PWM on/off | O | -- button
  28. +---------------+ `---`
  29. ```
  30. The LED circuitry provides two light modes:
  31. * Colored RGB light;
  32. * Warm to cool white light.
  33. The front panel of the device contains a two touch buttons (power on/off and
  34. color selection) and a touch slider (for setting the brightness level). This
  35. panel is lit when the device is turned on. The light behind the slider will
  36. represent the actual brightness setting of the device.
  37. ## ESP32 pinout
  38. In the following image, you can find the pinout as used for the ESP32:
  39. <img src="images/hardware/ESP32_pinout.jpg" width="400">
  40. Here's an overview of all exposed pins of the chip, starting at the GND +
  41. 3.3V pins, and going anti-clockwise. The table shows not only the functions
  42. of the pins that are actually in use by the lamp's circuitry, but also the
  43. pins that are not in use and their possible applications.
  44. | PIN | GPIO# | Function | Description | Possible use |
  45. |------|--------|-----------|--------------------------------|--------------|
  46. | GND | | Ground | Connected to ground | - |
  47. | 3.3V | | Power | Power supply input | - |
  48. | 9 | | Reset | Can be pulled to GND to reset | - |
  49. | 5 | GPIO36 | - | | IN |
  50. | 8 | GPIO39 | - | | IN |
  51. | 10 | GPIO34 | - | | IN |
  52. | 11 | GPIO35 | - | | IN |
  53. | 12 | GPIO32 | - | | IN/OUT |
  54. | 13 | GPIO33 | LEDs | LEDs, master switch 1 | - |
  55. | 14 | GPIO25 | ??? | 10k pull up, unknown function | IN/OUT (1) |
  56. | 15 | GPIO26 | - | | IN/OUT |
  57. | 16 | GPIO27 | - | | IN/OUT |
  58. | 17 | GPIO14 | LEDs | LEDs, green PWM channel | - |
  59. | 18 | GPIO12 | LEDs | LEDs, white PWM channel | - |
  60. | GND | | Ground | Connected to ground | - |
  61. | 20 | GPIO13 | LEDs | LEDs, red PWM channel | - |
  62. | 28 | GPIO9 | SPI | SPI flash memory | - |
  63. | 29 | GPIO10 | SPI | SPI flash memory | - |
  64. | 30 | GPIO11 | SPI | SPI flash memory | - |
  65. | 31 | GPIO6 | SPI | SPI flash memory | - |
  66. | 32 | GPIO7 | SPI | SPI flash memory | - |
  67. | 33 | GPIO8 | SPI | SPI flash memory | - |
  68. | 21 | GPIO15 | - | | IN/OUT (2) |
  69. | 22 | GPIO2 | ??? | Debug pad, unknown function | IN/OUT (3) |
  70. | 23 | GPIO0 | Boot mode | Pull to GND for flashing mode | - |
  71. | 24 | GPIO4 | LEDs | LEDs, master switch 2 | - |
  72. | 25 | GPIO16 | Front pnl | Front panel interrupt | - |
  73. | 27 | GPIO17 | EEPROM | EEPROM I2C SDA (4) | - |
  74. | 34 | GPIO5 | LEDs | LEDs, blue PWM channel | - |
  75. | 35 | GPIO18 | EEPROM | EEPROM I2C CLK (4) | - |
  76. | 38 | GPIO19 | Front pnl | Front panel I2C SCL | - |
  77. | N/C | | | | |
  78. | 42 | GPIO21 | Front pnl | Front panel I2C SDA | - |
  79. | 40 | GPIO3 | Serial | Debug pad, RX (flashing, logs) | - |
  80. | 41 | GPIO1 | Serial | Debug pad, TX (flashing, logs) | - |
  81. | 39 | GPIO22 | - | | IN/OUT |
  82. | 36 | GPIO23 | - | | IN/OUT |
  83. | GND | | Ground | Connected to ground | - |
  84. 1. GPIO25 is connected to a 10k pull up resistor. This suggests that it
  85. might have some function in the lamp, but I have not found that function
  86. yet. If you find the actual use for this pin, or find that you can indeed
  87. repurpose it, then please let me know.
  88. 1. Beware that GPIO15 outputs a PWM signal at boot. This might make the pin
  89. less useful for your use case.
  90. 1. Often, GPIO2 is used for an on-board LED, but it looks like it is only
  91. connected to the debug pad here. I think the pin is usable, and that it
  92. might only be used for testing purposes in the original firmware.
  93. 1. The connected IC, using I2C address 0x10, looks a lot like an EEPROM,
  94. but this has yet to be confirmed. It uses a decicated I2C bus, separate
  95. from the I2C bus of the front panel.
  96. [This picture](images/hardware/IC_on_I2C_GPIO1718.jpg) shows the IC.
  97. For more information on the use of pins on the ESP32 chip, please check out
  98. this [ESP32 pinout reference information](https://randomnerdtutorials.com/esp32-pinout-reference-gpios/).
  99. ## Front panel
  100. <img src="images/hardware/front_panel.jpg" width="400">
  101. The front panel is a stand-alone component, with its own control chip
  102. (KungFu KF8TS2716). Communication between the ESP32 and the front panel
  103. is done using:
  104. - **An I2C bus**
  105. - the front panel is the I2C slave, the ESP32 is the I2C master
  106. (pardon the standard terminology, I am aware of the controversy)
  107. - the front panel device ID is 0x2C
  108. - SDA is connected to ESP32 pin GPIO21
  109. - SCL is connected to ESP32 pin GPIO19
  110. - **An interrupt data line to signal the ESP32 about new events**
  111. - this line is connected to ESP32 pin GPIO16
  112. - the default state is HIGH
  113. - line is pulled LOW for at least 6 ms when a new event is available
  114. Commands can be written to and data can be read from the front panel
  115. component using I2C. The I2C protocol is fairly simple. All read and write
  116. operations uses 6 bytes of data. No register selection is done before
  117. reading or writing.
  118. The interrupt data line is used by the front panel, to signal the ESP32 that
  119. a new button or slider event is available. Further details on this can be
  120. found below.
  121. **Connection to the main board**
  122. The front panel is connected to the main board using a flat cable.
  123. The picture below shows the connector on the main board, including the
  124. functions of the cable pins:
  125. <img src="images/hardware/front_panel_flat_cable_connection.jpg" width="400">
  126. **Writing commands to the front panel**
  127. Commands can be written to the front panel at any time.
  128. The available commands are:
  129. | Command | Byte sequence to send |
  130. |-------------------|-----------------------|
  131. | `TURN PANEL ON` | 02 03 5E 00 64 00 00 |
  132. | `TURN PANEL OFF` | 02 03 0C 00 64 00 00 |
  133. | `SET LEVEL 1` | 02 03 5E 00 64 00 00 |
  134. | `SET LEVEL 2` | 02 03 5F 00 64 00 00 |
  135. | `SET LEVEL 3` | 02 03 5F 80 64 00 00 |
  136. | `SET LEVEL 4` | 02 03 5F C0 64 00 00 |
  137. | `SET LEVEL 5` | 02 03 5F E0 64 00 00 |
  138. | `SET LEVEL 6` | 02 03 5F F0 64 00 00 |
  139. | `SET LEVEL 7` | 02 03 5F F8 64 00 00 |
  140. | `SET LEVEL 8` | 02 03 5F FC 64 00 00 |
  141. | `SET LEVEL 9` | 02 03 5F FE 64 00 00 |
  142. | `SET LEVEL 10` | 02 03 5F FF 64 00 00 |
  143. | `READY FOR EVENT` | 01 00 00 00 00 00 01 |
  144. *Note: The `READY FOR EVENT` command is only used when a new event is provided
  145. by the front panel. Information about this command can be found in the next
  146. section.*
  147. **Reading events from the front panel**
  148. The types of events that can occur can be summarized as:
  149. - Touch or release the power button
  150. - Touch or release the color button
  151. - Touch or release the slider at a certain level
  152. Because the front panel is an I2C slave device, it cannot contact the ESP32 via
  153. I2C. Only an I2C master device can initiate communication. Therefore, when the
  154. front panel has a new event available, it will pull down the interrupt line for
  155. a short period of time, to signal the ESP32 about this new event.
  156. *Note that the ESP32 needs to poll the interrupt line at least at 667 Hz to be
  157. able to trustworthy detect the 6 ms signal. Unfortunately, the interrupt line
  158. does not wait for the ESP32 to respond to its signalling. The best way to
  159. handle signals from this line, is to use an actual interrupt handler.*
  160. After detecting this signal, the ESP32 must first write the "READY FOR EVENT"
  161. command (`01 00 00 00 00 00 01`) via I2C to the front panel.
  162. After the front panel has ACK'ed this command, the ESP32 can read 6 bytes,
  163. which will represent the event that occurred.
  164. Here's the mapping for the events and their corresponding byte sequences:
  165. | | Touch event | Release event |
  166. |-----------------|----------------------|----------------------|
  167. | POWER BUTTON | 04 04 01 00 01 01 03 | 04 04 01 00 01 02 04 |
  168. | COLOR BUTTON | 04 04 01 00 02 01 04 | 04 04 01 00 02 02 05 |
  169. | SLIDER LEVEL 1 | 04 04 01 00 03 16 1A | 04 04 01 00 04 16 1B |
  170. | SLIDER LEVEL 2 | 04 04 01 00 03 15 19 | 04 04 01 00 04 15 1A |
  171. | SLIDER LEVEL 3 | 04 04 01 00 03 14 18 | 04 04 01 00 04 14 19 |
  172. | SLIDER LEVEL 4 | 04 04 01 00 03 13 17 | 04 04 01 00 04 13 18 |
  173. | SLIDER LEVEL 5 | 04 04 01 00 03 12 16 | 04 04 01 00 04 12 17 |
  174. | SLIDER LEVEL 6 | 04 04 01 00 03 11 15 | 04 04 01 00 04 11 16 |
  175. | SLIDER LEVEL 7 | 04 04 01 00 03 10 14 | 04 04 01 00 04 10 15 |
  176. | SLIDER LEVEL 8 | 04 04 01 00 03 0F 13 | 04 04 01 00 04 0F 14 |
  177. | SLIDER LEVEL 9 | 04 04 01 00 03 0E 12 | 04 04 01 00 04 0E 13 |
  178. | SLIDER LEVEL 10 | 04 04 01 00 03 0D 11 | 04 04 01 00 04 0D 12 |
  179. | SLIDER LEVEL 11 | 04 04 01 00 03 0C 10 | 04 04 01 00 04 0C 11 |
  180. | SLIDER LEVEL 12 | 04 04 01 00 03 0B 0F | 04 04 01 00 04 0B 10 |
  181. | SLIDER LEVEL 13 | 04 04 01 00 03 0A 0E | 04 04 01 00 04 0A 0F |
  182. | SLIDER LEVEL 14 | 04 04 01 00 03 09 0D | 04 04 01 00 04 09 0E |
  183. | SLIDER LEVEL 15 | 04 04 01 00 03 08 0C | 04 04 01 00 04 08 0D |
  184. | SLIDER LEVEL 16 | 04 04 01 00 03 07 0B | 04 04 01 00 04 07 0C |
  185. | SLIDER LEVEL 17 | 04 04 01 00 03 06 0A | 04 04 01 00 04 06 0B |
  186. | SLIDER LEVEL 18 | 04 04 01 00 03 05 09 | 04 04 01 00 04 05 0A |
  187. | SLIDER LEVEL 19 | 04 04 01 00 03 04 08 | 04 04 01 00 04 04 09 |
  188. | SLIDER LEVEL 20 | 04 04 01 00 03 03 07 | 04 04 01 00 04 03 08 |
  189. | SLIDER LEVEL 21 | 04 04 01 00 03 02 06 | 04 04 01 00 04 02 07 |
  190. | SLIDER LEVEL 22 | 04 04 01 00 03 01 05 | 04 04 01 00 04 01 06 |
  191. **Behavior when more events come in than can be handled**
  192. The front panel does not queue events. When a new event occurs, before the
  193. previous event has be read by the ESP32, the new event will replace the old
  194. event and a new signal is sent over the interrupt line.
  195. The ESP32 can read the last event multiple times. It will not be cleared
  196. by the front panel after reading it.
  197. < [Known issues](known_issues.md) | [Index](../README.md) | [Sponsoring](sponsoring.md) >