waveshare-s3-touch-lcd-3.5b.cc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #include "wifi_board.h"
  2. #include "codecs/es8311_audio_codec.h"
  3. #include "display/lcd_display.h"
  4. #include "system_reset.h"
  5. #include "application.h"
  6. #include "button.h"
  7. #include "config.h"
  8. #include <esp_log.h>
  9. #include "i2c_device.h"
  10. #include <driver/i2c_master.h>
  11. #include <driver/ledc.h>
  12. #include <wifi_station.h>
  13. #include <esp_lcd_panel_vendor.h>
  14. #include <esp_lcd_panel_io.h>
  15. #include <esp_lcd_panel_ops.h>
  16. #include <esp_timer.h>
  17. #include "esp_io_expander_tca9554.h"
  18. #include "axp2101.h"
  19. #include "power_save_timer.h"
  20. #include "esp_lcd_axs15231b.h"
  21. #include "custom_lcd_display.h"
  22. #include <esp_lcd_touch_ft5x06.h>
  23. #include <esp_lvgl_port.h>
  24. #include <lvgl.h>
  25. #include "esp32_camera.h"
  26. #define TAG "waveshare_lcd_3_5b"
  27. LV_FONT_DECLARE(font_puhui_16_4);
  28. LV_FONT_DECLARE(font_awesome_16_4);
  29. static const axs15231b_lcd_init_cmd_t lcd_init_cmds[] = {
  30. {0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5}, 8, 0},
  31. {0xA0, (uint8_t[]){0xC0, 0x10, 0x00, 0x02, 0x00, 0x00, 0x04, 0x3F, 0x20, 0x05, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00}, 17, 0},
  32. {0xA2, (uint8_t[]){0x30, 0x3C, 0x24, 0x14, 0xD0, 0x20, 0xFF, 0xE0, 0x40, 0x19, 0x80, 0x80, 0x80, 0x20, 0xf9, 0x10, 0x02, 0xff, 0xff, 0xF0, 0x90, 0x01, 0x32, 0xA0, 0x91, 0xE0, 0x20, 0x7F, 0xFF, 0x00, 0x5A}, 31, 0},
  33. {0xD0, (uint8_t[]){0xE0, 0x40, 0x51, 0x24, 0x08, 0x05, 0x10, 0x01, 0x20, 0x15, 0x42, 0xC2, 0x22, 0x22, 0xAA, 0x03, 0x10, 0x12, 0x60, 0x14, 0x1E, 0x51, 0x15, 0x00, 0x8A, 0x20, 0x00, 0x03, 0x3A, 0x12}, 30, 0},
  34. {0xA3, (uint8_t[]){0xA0, 0x06, 0xAa, 0x00, 0x08, 0x02, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x55, 0x55}, 22, 0},
  35. {0xC1, (uint8_t[]){0x31, 0x04, 0x02, 0x02, 0x71, 0x05, 0x24, 0x55, 0x02, 0x00, 0x41, 0x00, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0x52, 0x00, 0x4F, 0x52, 0x00, 0x45, 0x3B, 0x0B, 0x02, 0x0d, 0x00, 0xFF, 0x40}, 30, 0},
  36. {0xC3, (uint8_t[]){0x00, 0x00, 0x00, 0x50, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01}, 11, 0},
  37. {0xC4, (uint8_t[]){0x00, 0x24, 0x33, 0x80, 0x00, 0xea, 0x64, 0x32, 0xC8, 0x64, 0xC8, 0x32, 0x90, 0x90, 0x11, 0x06, 0xDC, 0xFA, 0x00, 0x00, 0x80, 0xFE, 0x10, 0x10, 0x00, 0x0A, 0x0A, 0x44, 0x50}, 29, 0},
  38. {0xC5, (uint8_t[]){0x18, 0x00, 0x00, 0x03, 0xFE, 0x3A, 0x4A, 0x20, 0x30, 0x10, 0x88, 0xDE, 0x0D, 0x08, 0x0F, 0x0F, 0x01, 0x3A, 0x4A, 0x20, 0x10, 0x10, 0x00}, 23, 0},
  39. {0xC6, (uint8_t[]){0x05, 0x0A, 0x05, 0x0A, 0x00, 0xE0, 0x2E, 0x0B, 0x12, 0x22, 0x12, 0x22, 0x01, 0x03, 0x00, 0x3F, 0x6A, 0x18, 0xC8, 0x22}, 20, 0},
  40. {0xC7, (uint8_t[]){0x50, 0x32, 0x28, 0x00, 0xa2, 0x80, 0x8f, 0x00, 0x80, 0xff, 0x07, 0x11, 0x9c, 0x67, 0xff, 0x24, 0x0c, 0x0d, 0x0e, 0x0f}, 20, 0},
  41. {0xC9, (uint8_t[]){0x33, 0x44, 0x44, 0x01}, 4, 0},
  42. {0xCF, (uint8_t[]){0x2C, 0x1E, 0x88, 0x58, 0x13, 0x18, 0x56, 0x18, 0x1E, 0x68, 0x88, 0x00, 0x65, 0x09, 0x22, 0xC4, 0x0C, 0x77, 0x22, 0x44, 0xAA, 0x55, 0x08, 0x08, 0x12, 0xA0, 0x08}, 27, 0},
  43. {0xD5, (uint8_t[]){0x40, 0x8E, 0x8D, 0x01, 0x35, 0x04, 0x92, 0x74, 0x04, 0x92, 0x74, 0x04, 0x08, 0x6A, 0x04, 0x46, 0x03, 0x03, 0x03, 0x03, 0x82, 0x01, 0x03, 0x00, 0xE0, 0x51, 0xA1, 0x00, 0x00, 0x00}, 30, 0},
  44. {0xD6, (uint8_t[]){0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x93, 0x00, 0x01, 0x83, 0x07, 0x07, 0x00, 0x07, 0x07, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x84, 0x00, 0x20, 0x01, 0x00}, 30, 0},
  45. {0xD7, (uint8_t[]){0x03, 0x01, 0x0b, 0x09, 0x0f, 0x0d, 0x1E, 0x1F, 0x18, 0x1d, 0x1f, 0x19, 0x40, 0x8E, 0x04, 0x00, 0x20, 0xA0, 0x1F}, 19, 0},
  46. {0xD8, (uint8_t[]){0x02, 0x00, 0x0a, 0x08, 0x0e, 0x0c, 0x1E, 0x1F, 0x18, 0x1d, 0x1f, 0x19}, 12, 0},
  47. {0xD9, (uint8_t[]){0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}, 12, 0},
  48. {0xDD, (uint8_t[]){0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}, 12, 0},
  49. {0xDF, (uint8_t[]){0x44, 0x73, 0x4B, 0x69, 0x00, 0x0A, 0x02, 0x90}, 8, 0},
  50. {0xE0, (uint8_t[]){0x3B, 0x28, 0x10, 0x16, 0x0c, 0x06, 0x11, 0x28, 0x5c, 0x21, 0x0D, 0x35, 0x13, 0x2C, 0x33, 0x28, 0x0D}, 17, 0},
  51. {0xE1, (uint8_t[]){0x37, 0x28, 0x10, 0x16, 0x0b, 0x06, 0x11, 0x28, 0x5C, 0x21, 0x0D, 0x35, 0x14, 0x2C, 0x33, 0x28, 0x0F}, 17, 0},
  52. {0xE2, (uint8_t[]){0x3B, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x35, 0x44, 0x32, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0D}, 17, 0},
  53. {0xE3, (uint8_t[]){0x37, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x35, 0x44, 0x32, 0x0C, 0x14, 0x14, 0x36, 0x32, 0x2F, 0x0F}, 17, 0},
  54. {0xE4, (uint8_t[]){0x3B, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x39, 0x44, 0x2E, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0D}, 17, 0},
  55. {0xE5, (uint8_t[]){0x37, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x39, 0x44, 0x2E, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0F}, 17, 0},
  56. {0xA4, (uint8_t[]){0x85, 0x85, 0x95, 0x82, 0xAF, 0xAA, 0xAA, 0x80, 0x10, 0x30, 0x40, 0x40, 0x20, 0xFF, 0x60, 0x30}, 16, 0},
  57. {0xA4, (uint8_t[]){0x85, 0x85, 0x95, 0x85}, 4, 0},
  58. {0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 0},
  59. {0x13, (uint8_t[]){0x00}, 0, 0},
  60. {0x11, (uint8_t[]){0x00}, 0, 120},
  61. {0x2C, (uint8_t[]){0x00, 0x00, 0x00, 0x00}, 4, 0},
  62. {0x2a, (uint8_t[]){0x00, 0x00, 0x01, 0x3f}, 4, 0},
  63. {0x2b, (uint8_t[]){0x00, 0x00, 0x01, 0xdf}, 4, 0}};
  64. class Pmic : public Axp2101 {
  65. public:
  66. Pmic(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : Axp2101(i2c_bus, addr) {
  67. WriteReg(0x22, 0b110); // PWRON > OFFLEVEL as POWEROFF Source enable
  68. WriteReg(0x27, 0x10); // hold 4s to power off
  69. // Disable All DCs but DC1
  70. WriteReg(0x80, 0x01);
  71. // Disable All LDOs
  72. WriteReg(0x90, 0x00);
  73. WriteReg(0x91, 0x00);
  74. // Set DC1 to 3.3V
  75. WriteReg(0x82, (3300 - 1500) / 100);
  76. // Set ALDO1 to 3.3V
  77. WriteReg(0x92, (3300 - 500) / 100);
  78. WriteReg(0x96, (1500 - 500) / 100);
  79. WriteReg(0x97, (2800 - 500) / 100);
  80. // Enable ALDO1 BLDO1 BLDO2
  81. WriteReg(0x90, 0x31);
  82. WriteReg(0x64, 0x02); // CV charger voltage setting to 4.1V
  83. WriteReg(0x61, 0x02); // set Main battery precharge current to 50mA
  84. WriteReg(0x62, 0x08); // set Main battery charger current to 400mA ( 0x08-200mA, 0x09-300mA, 0x0A-400mA )
  85. WriteReg(0x63, 0x01); // set Main battery term charge current to 25mA
  86. }
  87. };
  88. class CustomBoard : public WifiBoard {
  89. private:
  90. Button boot_button_;
  91. Pmic* pmic_ = nullptr;
  92. i2c_master_bus_handle_t i2c_bus_;
  93. esp_io_expander_handle_t io_expander = NULL;
  94. LcdDisplay* display_;
  95. PowerSaveTimer* power_save_timer_;
  96. Esp32Camera* camera_;
  97. void InitializePowerSaveTimer() {
  98. power_save_timer_ = new PowerSaveTimer(-1, 60, 300);
  99. power_save_timer_->OnEnterSleepMode([this]() {
  100. ESP_LOGI(TAG, "Enabling sleep mode");
  101. auto display = GetDisplay();
  102. display->SetChatMessage("system", "");
  103. display->SetEmotion("sleepy");
  104. GetBacklight()->SetBrightness(20);
  105. });
  106. power_save_timer_->OnExitSleepMode([this]() {
  107. auto display = GetDisplay();
  108. display->SetChatMessage("system", "");
  109. display->SetEmotion("neutral");
  110. GetBacklight()->RestoreBrightness();
  111. });
  112. power_save_timer_->OnShutdownRequest([this]() {
  113. pmic_->PowerOff();
  114. });
  115. power_save_timer_->SetEnabled(true);
  116. }
  117. void InitializeI2c() {
  118. // Initialize I2C peripheral
  119. i2c_master_bus_config_t i2c_bus_cfg = {
  120. .i2c_port = (i2c_port_t)I2C_NUM_0,
  121. .sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
  122. .scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
  123. .clk_source = I2C_CLK_SRC_DEFAULT,
  124. .glitch_ignore_cnt = 7,
  125. .intr_priority = 0,
  126. .trans_queue_depth = 0,
  127. .flags = {
  128. .enable_internal_pullup = 1,
  129. },
  130. };
  131. ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
  132. }
  133. void InitializeTca9554(void)
  134. {
  135. esp_err_t ret = esp_io_expander_new_i2c_tca9554(i2c_bus_, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander);
  136. if(ret != ESP_OK)
  137. ESP_LOGE(TAG, "TCA9554 create returned error");
  138. ret = esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, IO_EXPANDER_OUTPUT);
  139. ESP_ERROR_CHECK(ret);
  140. vTaskDelay(pdMS_TO_TICKS(100));
  141. ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, 0);
  142. ESP_ERROR_CHECK(ret);
  143. vTaskDelay(pdMS_TO_TICKS(100));
  144. ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 1);
  145. ESP_ERROR_CHECK(ret);
  146. }
  147. void InitializeAxp2101() {
  148. ESP_LOGI(TAG, "Init AXP2101");
  149. pmic_ = new Pmic(i2c_bus_, 0x34);
  150. }
  151. void InitializeSpi() {
  152. ESP_LOGI(TAG, "Initialize QSPI bus");
  153. spi_bus_config_t buscfg = {};
  154. buscfg.data0_io_num = DISPLAY_DATA0_PIN;
  155. buscfg.data1_io_num = DISPLAY_DATA1_PIN;
  156. buscfg.data2_io_num = DISPLAY_DATA2_PIN;
  157. buscfg.data3_io_num = DISPLAY_DATA3_PIN;
  158. buscfg.sclk_io_num = DISPLAY_CLK_PIN;
  159. buscfg.max_transfer_sz = DISPLAY_TRANS_SIZE * sizeof(uint16_t);
  160. ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO));
  161. }
  162. void InitializeCamera() {
  163. camera_config_t config = {};
  164. config.pin_pwdn = CAM_PIN_PWDN;
  165. config.pin_reset = CAM_PIN_RESET;
  166. config.pin_xclk = CAM_PIN_XCLK;
  167. config.pin_sccb_sda = CAM_PIN_SIOD;
  168. config.pin_sccb_scl = CAM_PIN_SIOC;
  169. config.sccb_i2c_port = I2C_NUM_0;
  170. config.pin_d7 = CAM_PIN_D7;
  171. config.pin_d6 = CAM_PIN_D6;
  172. config.pin_d5 = CAM_PIN_D5;
  173. config.pin_d4 = CAM_PIN_D4;
  174. config.pin_d3 = CAM_PIN_D3;
  175. config.pin_d2 = CAM_PIN_D2;
  176. config.pin_d1 = CAM_PIN_D1;
  177. config.pin_d0 = CAM_PIN_D0;
  178. config.pin_vsync = CAM_PIN_VSYNC;
  179. config.pin_href = CAM_PIN_HREF;
  180. config.pin_pclk = CAM_PIN_PCLK;
  181. /* XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental) */
  182. config.xclk_freq_hz = 10000000;
  183. config.ledc_timer = LEDC_TIMER_1;
  184. config.ledc_channel = LEDC_CHANNEL_0;
  185. config.pixel_format = PIXFORMAT_RGB565; /* YUV422,GRAYSCALE,RGB565,JPEG */
  186. config.frame_size = FRAMESIZE_240X240; /* QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates */
  187. config.jpeg_quality = 12; /* 0-63, for OV series camera sensors, lower number means higher quality */
  188. config.fb_count = 2; /* When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode */
  189. config.fb_location = CAMERA_FB_IN_PSRAM;
  190. config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
  191. esp_err_t err = esp_camera_init(&config); // 测试相机是否存在
  192. if (err != ESP_OK) {
  193. ESP_LOGE(TAG, "Camera is not plugged in or not supported, error: %s", esp_err_to_name(err));
  194. // 如果摄像头初始化失败,设置 camera_ 为 nullptr
  195. camera_ = nullptr;
  196. return;
  197. }else
  198. {
  199. esp_camera_deinit();// 释放之前的摄像头资源,为正确初始化做准备
  200. camera_ = new Esp32Camera(config);
  201. }
  202. }
  203. void InitializeLcdDisplay() {
  204. esp_lcd_panel_io_handle_t panel_io = nullptr;
  205. esp_lcd_panel_handle_t panel = nullptr;
  206. // 液晶屏控制IO初始化
  207. ESP_LOGI(TAG, "Install panel IO");
  208. esp_lcd_panel_io_spi_config_t io_config = AXS15231B_PANEL_IO_QSPI_CONFIG(
  209. DISPLAY_CS_PIN,
  210. NULL,
  211. NULL);
  212. ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &panel_io));
  213. // 初始化液晶屏驱动芯片
  214. ESP_LOGI(TAG, "Install LCD driver");
  215. const axs15231b_vendor_config_t vendor_config = {
  216. .init_cmds = lcd_init_cmds, // Uncomment these line if use custom initialization commands
  217. .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]),
  218. .flags = {
  219. .use_qspi_interface = 1,
  220. },
  221. };
  222. esp_lcd_panel_dev_config_t panel_config = {
  223. .reset_gpio_num = DISPLAY_RST_PIN,
  224. .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
  225. .bits_per_pixel = 16,
  226. .vendor_config = (void *)&vendor_config,
  227. };
  228. esp_lcd_new_panel_axs15231b(panel_io, &panel_config, &panel);
  229. esp_lcd_panel_reset(panel);
  230. esp_lcd_panel_init(panel);
  231. esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR);
  232. // esp_lcd_panel_disp_on_off(panel, false);
  233. esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
  234. esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
  235. display_ = new CustomLcdDisplay(panel_io, panel,
  236. DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
  237. {
  238. .text_font = &font_puhui_16_4,
  239. .icon_font = &font_awesome_16_4,
  240. .emoji_font = font_emoji_32_init(),
  241. });
  242. // display_ = new CustomLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
  243. // DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
  244. }
  245. void InitializeButtons() {
  246. boot_button_.OnClick([this]() {
  247. auto& app = Application::GetInstance();
  248. if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
  249. ResetWifiConfiguration();
  250. }
  251. app.ToggleChatState();
  252. });
  253. }
  254. void InitializeTouch()
  255. {
  256. esp_lcd_touch_handle_t tp;
  257. esp_lcd_touch_config_t tp_cfg = {
  258. .x_max = DISPLAY_WIDTH,
  259. .y_max = DISPLAY_HEIGHT,
  260. .rst_gpio_num = GPIO_NUM_NC,
  261. .int_gpio_num = GPIO_NUM_NC,
  262. .levels = {
  263. .reset = 0,
  264. .interrupt = 0,
  265. },
  266. .flags = {
  267. .swap_xy = 1,
  268. .mirror_x = 1,
  269. .mirror_y = 1,
  270. },
  271. };
  272. esp_lcd_panel_io_handle_t tp_io_handle = NULL;
  273. esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG();
  274. tp_io_config.scl_speed_hz = 400 * 1000;
  275. ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus_, &tp_io_config, &tp_io_handle));
  276. ESP_LOGI(TAG, "Initialize touch controller");
  277. ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_axs15231b(tp_io_handle, &tp_cfg, &tp));
  278. const lvgl_port_touch_cfg_t touch_cfg = {
  279. .disp = lv_display_get_default(),
  280. .handle = tp,
  281. };
  282. lvgl_port_add_touch(&touch_cfg);
  283. ESP_LOGI(TAG, "Touch panel initialized successfully");
  284. }
  285. public:
  286. CustomBoard() :
  287. boot_button_(BOOT_BUTTON_GPIO) {
  288. InitializeI2c();
  289. InitializeTca9554();
  290. InitializeAxp2101();
  291. #if PMIC_ENABLE
  292. InitializePowerSaveTimer();
  293. #endif
  294. InitializeSpi();
  295. InitializeLcdDisplay();
  296. #if TOUCH_ENABLE
  297. InitializeTouch();
  298. #endif
  299. InitializeButtons();
  300. InitializeCamera();
  301. GetBacklight()->RestoreBrightness();
  302. }
  303. virtual AudioCodec* GetAudioCodec() override {
  304. static Es8311AudioCodec audio_codec(i2c_bus_, I2C_NUM_0, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
  305. AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
  306. AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR);
  307. return &audio_codec;
  308. }
  309. virtual Display* GetDisplay() override {
  310. return display_;
  311. }
  312. virtual Backlight* GetBacklight() override {
  313. static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
  314. return &backlight;
  315. }
  316. virtual Camera* GetCamera() override {
  317. return camera_;
  318. }
  319. #if PMIC_ENABLE
  320. virtual bool GetBatteryLevel(int &level, bool& charging, bool& discharging) override {
  321. static bool last_discharging = false;
  322. charging = pmic_->IsCharging();
  323. discharging = pmic_->IsDischarging();
  324. if (discharging != last_discharging) {
  325. power_save_timer_->SetEnabled(discharging);
  326. last_discharging = discharging;
  327. }
  328. level = pmic_->GetBatteryLevel();
  329. return true;
  330. }
  331. virtual void SetPowerSaveMode(bool enabled) override {
  332. if (!enabled) {
  333. power_save_timer_->WakeUp();
  334. }
  335. WifiBoard::SetPowerSaveMode(enabled);
  336. }
  337. #endif
  338. };
  339. DECLARE_BOARD(CustomBoard);