|
| 1 | +#include "wifi_board.h" |
| 2 | +#include "audio/codecs/es8311_audio_codec.h" |
| 3 | +// Display |
| 4 | +#include "display/display.h" |
| 5 | +#include "display/lcd_display.h" |
| 6 | +// Backlight |
| 7 | +// PwmBacklight is declared in backlight headers pulled by display/lcd_display includes via lvgl stack |
| 8 | + |
| 9 | +#include "application.h" |
| 10 | +#include "button.h" |
| 11 | +#include "config.h" |
| 12 | + |
| 13 | +#include <wifi_station.h> |
| 14 | +#include <esp_log.h> |
| 15 | +#include <inttypes.h> |
| 16 | +#include <driver/i2c_master.h> |
| 17 | +#include <esp_lvgl_port.h> |
| 18 | +// SD card |
| 19 | +#include <esp_vfs_fat.h> |
| 20 | +#include <sdmmc_cmd.h> |
| 21 | +#include <driver/sdmmc_host.h> |
| 22 | +#include <driver/sdspi_host.h> |
| 23 | +// SD power control (on-chip LDO) |
| 24 | +#include "sd_pwr_ctrl_by_on_chip_ldo.h" |
| 25 | + |
| 26 | +// MIPI-DSI / LCD vendor includes (library may replace some) |
| 27 | +#include "esp_lcd_panel_ops.h" |
| 28 | +#include "esp_lcd_mipi_dsi.h" |
| 29 | +#include "esp_ldo_regulator.h" |
| 30 | +#include "esp_lcd_ek79007.h" |
| 31 | +#include "esp_lcd_touch_gt911.h" |
| 32 | + |
| 33 | +// Library includes |
| 34 | +#include "bsp/esp32_p4_function_ev_board.h" |
| 35 | +#include "bsp/touch.h" |
| 36 | + |
| 37 | +#define TAG "ESP32P4FuncEV" |
| 38 | + |
| 39 | +class ESP32P4FunctionEvBoard : public WifiBoard |
| 40 | +{ |
| 41 | +private: |
| 42 | + i2c_master_bus_handle_t codec_i2c_bus_ = nullptr; |
| 43 | + Button boot_button_; |
| 44 | + LcdDisplay *display_ = nullptr; |
| 45 | + esp_lcd_touch_handle_t tp_ = nullptr; |
| 46 | + |
| 47 | + void InitializeI2cBuses() |
| 48 | + { |
| 49 | + ESP_ERROR_CHECK(bsp_i2c_init()); |
| 50 | + codec_i2c_bus_ = bsp_i2c_get_handle(); |
| 51 | + } |
| 52 | + |
| 53 | + // Touch I2C bus initialization is not required for this board (handled elsewhere) |
| 54 | + void InitializeTouchI2cBus() |
| 55 | + { |
| 56 | + // No implementation needed |
| 57 | + } |
| 58 | + |
| 59 | + void InitializeLCD() |
| 60 | + { |
| 61 | + bsp_display_config_t config = { |
| 62 | + .hdmi_resolution = BSP_HDMI_RES_NONE, |
| 63 | + .dsi_bus = { |
| 64 | + .phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT, |
| 65 | + .lane_bit_rate_mbps = 1000, |
| 66 | + }, |
| 67 | + }; |
| 68 | + |
| 69 | + bsp_lcd_handles_t handles; |
| 70 | + ESP_ERROR_CHECK(bsp_display_new_with_handles(&config, &handles)); |
| 71 | + |
| 72 | + display_ = new MipiLcdDisplay(handles.io, handles.panel, 1024, 600, 0, 0, true, true, false); |
| 73 | + } |
| 74 | + |
| 75 | + void InitializeButtons() |
| 76 | + { |
| 77 | + boot_button_.OnClick([this]() |
| 78 | + { |
| 79 | + auto& app = Application::GetInstance(); |
| 80 | + if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) { |
| 81 | + ResetWifiConfiguration(); |
| 82 | + } |
| 83 | + app.ToggleChatState(); }); |
| 84 | + } |
| 85 | + |
| 86 | + void InitializeTouch() |
| 87 | + { |
| 88 | + ESP_ERROR_CHECK(bsp_touch_new(NULL, &tp_)); |
| 89 | + } |
| 90 | + |
| 91 | +public: |
| 92 | + |
| 93 | + ESP32P4FunctionEvBoard() : boot_button_(0) |
| 94 | + { |
| 95 | + InitializeI2cBuses(); |
| 96 | + // Audio is initialized by Es8311AudioCodec |
| 97 | + InitializeLCD(); |
| 98 | + InitializeButtons(); |
| 99 | + InitializeTouch(); |
| 100 | + GetBacklight()->RestoreBrightness(); |
| 101 | + } |
| 102 | + |
| 103 | + ~ESP32P4FunctionEvBoard() |
| 104 | + { |
| 105 | + // Clean up display pointer |
| 106 | + delete display_; |
| 107 | + display_ = nullptr; |
| 108 | + // If other resources need cleanup, add here |
| 109 | + } |
| 110 | + |
| 111 | + virtual AudioCodec *GetAudioCodec() override |
| 112 | + { |
| 113 | + static Es8311AudioCodec audio_codec( |
| 114 | + codec_i2c_bus_, (i2c_port_t)BSP_I2C_NUM, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE, |
| 115 | + BSP_I2S_MCLK, BSP_I2S_SCLK, BSP_I2S_LCLK, BSP_I2S_DOUT, BSP_I2S_DSIN, |
| 116 | + BSP_POWER_AMP_IO, ES8311_CODEC_DEFAULT_ADDR, true, false); |
| 117 | + return &audio_codec; |
| 118 | + } |
| 119 | + |
| 120 | + virtual Display *GetDisplay() override { return display_; } |
| 121 | + |
| 122 | + virtual Backlight *GetBacklight() override |
| 123 | + { |
| 124 | + static PwmBacklight backlight(BSP_LCD_BACKLIGHT, DISPLAY_BACKLIGHT_OUTPUT_INVERT); |
| 125 | + return &backlight; |
| 126 | + } |
| 127 | +}; |
| 128 | + |
| 129 | +DECLARE_BOARD(ESP32P4FunctionEvBoard); |
0 commit comments