|
| 1 | +#include "wifi_board.h" |
| 2 | +#include "audio_codecs/es8311_audio_codec.h" |
| 3 | +#include "display/lcd_display.h" |
| 4 | +#include "application.h" |
| 5 | +#include "button.h" |
| 6 | +#include "led/single_led.h" |
| 7 | +#include "pin_config.h" |
| 8 | + |
| 9 | +#include "config.h" |
| 10 | +#include "iot/thing_manager.h" |
| 11 | + |
| 12 | +#include <wifi_station.h> |
| 13 | +#include <esp_log.h> |
| 14 | +#include <driver/i2c_master.h> |
| 15 | +#include "esp_lcd_gc9503.h" |
| 16 | +#include <esp_lcd_panel_io.h> |
| 17 | +#include <esp_lcd_panel_ops.h> |
| 18 | +#include <esp_lcd_panel_io_additions.h> |
| 19 | + |
| 20 | +#include "audio_codecs/box_audio_codec.h" |
| 21 | +#include "esp_io_expander_tca9554.h" |
| 22 | + |
| 23 | +#define TAG "ESP_S3_LCD_EV_Board" |
| 24 | + |
| 25 | +LV_FONT_DECLARE(font_puhui_30_4); |
| 26 | +LV_FONT_DECLARE(font_awesome_30_4); |
| 27 | + |
| 28 | +class ESP_S3_LCD_EV_Board : public WifiBoard { |
| 29 | +private: |
| 30 | + i2c_master_bus_handle_t codec_i2c_bus_; |
| 31 | + Button boot_button_; |
| 32 | + LcdDisplay* display_; |
| 33 | + |
| 34 | + //add support ev board lcd |
| 35 | + esp_io_expander_handle_t expander = NULL; |
| 36 | + |
| 37 | + void InitializeRGB_GC9503V_Display() { |
| 38 | + ESP_LOGI(TAG, "Init GC9503V"); |
| 39 | + |
| 40 | + esp_lcd_panel_io_handle_t panel_io = nullptr; |
| 41 | + |
| 42 | + //add support ev board lcd |
| 43 | + gpio_config_t io_conf = { |
| 44 | + .pin_bit_mask = BIT64(GC9503V_PIN_NUM_VSYNC), |
| 45 | + .mode = GPIO_MODE_OUTPUT, |
| 46 | + .pull_up_en = GPIO_PULLUP_ENABLE, |
| 47 | + }; |
| 48 | + |
| 49 | + gpio_config(&io_conf); |
| 50 | + gpio_set_level(GC9503V_PIN_NUM_VSYNC, 1); |
| 51 | + |
| 52 | + ESP_LOGI(TAG, "Install 3-wire SPI panel IO"); |
| 53 | + spi_line_config_t line_config = { |
| 54 | + .cs_io_type = IO_TYPE_EXPANDER, |
| 55 | + .cs_expander_pin = GC9503V_LCD_IO_SPI_CS_1, |
| 56 | + .scl_io_type = IO_TYPE_EXPANDER, |
| 57 | + .scl_expander_pin = GC9503V_LCD_IO_SPI_SCL_1, |
| 58 | + .sda_io_type = IO_TYPE_EXPANDER, |
| 59 | + .sda_expander_pin = GC9503V_LCD_IO_SPI_SDO_1, |
| 60 | + .io_expander = expander, |
| 61 | + }; |
| 62 | + |
| 63 | + esp_lcd_panel_io_3wire_spi_config_t io_config = GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0); |
| 64 | + int espok = esp_lcd_new_panel_io_3wire_spi(&io_config, &panel_io); |
| 65 | + ESP_LOGI(TAG, "Install 3-wire SPI panel IO:%d",espok); |
| 66 | + |
| 67 | + |
| 68 | + ESP_LOGI(TAG, "Install RGB LCD panel driver"); |
| 69 | + esp_lcd_panel_handle_t panel_handle = NULL; |
| 70 | + esp_lcd_rgb_panel_config_t rgb_config = { |
| 71 | + .clk_src = LCD_CLK_SRC_PLL160M, |
| 72 | + //.timings = GC9503_376_960_PANEL_60HZ_RGB_TIMING(), |
| 73 | + //add support ev board |
| 74 | + .timings = GC9503_480_480_PANEL_60HZ_RGB_TIMING(), |
| 75 | + .data_width = 16, // RGB565 in parallel mode, thus 16bit in width |
| 76 | + .bits_per_pixel = 16, |
| 77 | + .num_fbs = GC9503V_LCD_RGB_BUFFER_NUMS, |
| 78 | + .bounce_buffer_size_px = GC9503V_LCD_H_RES * GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT, |
| 79 | + .dma_burst_size = 64, |
| 80 | + .hsync_gpio_num = GC9503V_PIN_NUM_HSYNC, |
| 81 | + .vsync_gpio_num = GC9503V_PIN_NUM_VSYNC, |
| 82 | + .de_gpio_num = GC9503V_PIN_NUM_DE, |
| 83 | + .pclk_gpio_num = GC9503V_PIN_NUM_PCLK, |
| 84 | + .disp_gpio_num = GC9503V_PIN_NUM_DISP_EN, |
| 85 | + .data_gpio_nums = { |
| 86 | + GC9503V_PIN_NUM_DATA0, |
| 87 | + GC9503V_PIN_NUM_DATA1, |
| 88 | + GC9503V_PIN_NUM_DATA2, |
| 89 | + GC9503V_PIN_NUM_DATA3, |
| 90 | + GC9503V_PIN_NUM_DATA4, |
| 91 | + GC9503V_PIN_NUM_DATA5, |
| 92 | + GC9503V_PIN_NUM_DATA6, |
| 93 | + GC9503V_PIN_NUM_DATA7, |
| 94 | + GC9503V_PIN_NUM_DATA8, |
| 95 | + GC9503V_PIN_NUM_DATA9, |
| 96 | + GC9503V_PIN_NUM_DATA10, |
| 97 | + GC9503V_PIN_NUM_DATA11, |
| 98 | + GC9503V_PIN_NUM_DATA12, |
| 99 | + GC9503V_PIN_NUM_DATA13, |
| 100 | + GC9503V_PIN_NUM_DATA14, |
| 101 | + GC9503V_PIN_NUM_DATA15, |
| 102 | + }, |
| 103 | + .flags= { |
| 104 | + .fb_in_psram = true, // allocate frame buffer in PSRAM |
| 105 | + } |
| 106 | + }; |
| 107 | + |
| 108 | + ESP_LOGI(TAG, "Initialize RGB LCD panel"); |
| 109 | + |
| 110 | + gc9503_vendor_config_t vendor_config = { |
| 111 | + .rgb_config = &rgb_config, |
| 112 | + .flags = { |
| 113 | + .mirror_by_cmd = 0, |
| 114 | + .auto_del_panel_io = 1, |
| 115 | + }, |
| 116 | + }; |
| 117 | + const esp_lcd_panel_dev_config_t panel_config = { |
| 118 | + .reset_gpio_num = -1, |
| 119 | + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, |
| 120 | + // .bits_per_pixel = 16, |
| 121 | + //add surpport ev board |
| 122 | + .bits_per_pixel = 18, |
| 123 | + .vendor_config = &vendor_config, |
| 124 | + }; |
| 125 | + (esp_lcd_new_panel_gc9503(panel_io, &panel_config, &panel_handle)); |
| 126 | + (esp_lcd_panel_reset(panel_handle)); |
| 127 | + (esp_lcd_panel_init(panel_handle)); |
| 128 | + |
| 129 | + display_ = new RgbLcdDisplay(panel_io, panel_handle, |
| 130 | + DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, |
| 131 | + DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, |
| 132 | + { |
| 133 | + .text_font = &font_puhui_30_4, |
| 134 | + .icon_font = &font_awesome_30_4, |
| 135 | + .emoji_font = font_emoji_64_init(), |
| 136 | + }); |
| 137 | + } |
| 138 | + void InitializeCodecI2c() { |
| 139 | + // Initialize I2C peripheral |
| 140 | + i2c_master_bus_config_t i2c_bus_cfg = { |
| 141 | + .i2c_port = I2C_NUM_0, |
| 142 | + .sda_io_num = AUDIO_CODEC_I2C_SDA_PIN, |
| 143 | + .scl_io_num = AUDIO_CODEC_I2C_SCL_PIN, |
| 144 | + .clk_source = I2C_CLK_SRC_DEFAULT, |
| 145 | + .glitch_ignore_cnt = 7, |
| 146 | + .intr_priority = 0, |
| 147 | + .trans_queue_depth = 0, |
| 148 | + .flags = { |
| 149 | + .enable_internal_pullup = 1, |
| 150 | + }, |
| 151 | + }; |
| 152 | + ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &codec_i2c_bus_)); |
| 153 | + |
| 154 | + //add support ev board lcd amp |
| 155 | + //初始化扩展io口 |
| 156 | + esp_io_expander_new_i2c_tca9554(codec_i2c_bus_, 0x20, &expander); |
| 157 | + /* Setup power amplifier pin, set default to enable */ |
| 158 | + esp_io_expander_set_dir(expander, BSP_POWER_AMP_IO, IO_EXPANDER_OUTPUT); |
| 159 | + esp_io_expander_set_level(expander, BSP_POWER_AMP_IO, true); |
| 160 | + |
| 161 | + } |
| 162 | + |
| 163 | + void InitializeButtons() { |
| 164 | + boot_button_.OnClick([this]() { |
| 165 | + auto& app = Application::GetInstance(); |
| 166 | + if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) { |
| 167 | + ResetWifiConfiguration(); |
| 168 | + } |
| 169 | + }); |
| 170 | + boot_button_.OnPressDown([this]() { |
| 171 | + Application::GetInstance().StartListening(); |
| 172 | + }); |
| 173 | + boot_button_.OnPressUp([this]() { |
| 174 | + Application::GetInstance().StopListening(); |
| 175 | + }); |
| 176 | + } |
| 177 | + |
| 178 | + // 物联网初始化,添加对 AI 可见设备 |
| 179 | + void InitializeIot() { |
| 180 | + auto& thing_manager = iot::ThingManager::GetInstance(); |
| 181 | + thing_manager.AddThing(iot::CreateThing("Speaker")); |
| 182 | + } |
| 183 | + |
| 184 | +public: |
| 185 | + ESP_S3_LCD_EV_Board() : boot_button_(BOOT_BUTTON_GPIO) { |
| 186 | + InitializeCodecI2c(); |
| 187 | + InitializeButtons(); |
| 188 | + InitializeIot(); |
| 189 | + InitializeRGB_GC9503V_Display(); |
| 190 | + } |
| 191 | + |
| 192 | + |
| 193 | + //es7210用作音频采集 |
| 194 | + virtual AudioCodec* GetAudioCodec() override { |
| 195 | + static BoxAudioCodec audio_codec( |
| 196 | + codec_i2c_bus_, |
| 197 | + AUDIO_INPUT_SAMPLE_RATE, |
| 198 | + AUDIO_OUTPUT_SAMPLE_RATE, |
| 199 | + AUDIO_I2S_GPIO_MCLK, |
| 200 | + AUDIO_I2S_GPIO_BCLK, |
| 201 | + AUDIO_I2S_GPIO_WS, |
| 202 | + AUDIO_I2S_GPIO_DOUT, |
| 203 | + AUDIO_I2S_GPIO_DIN, |
| 204 | + GPIO_NUM_NC, |
| 205 | + AUDIO_CODEC_ES8311_ADDR, |
| 206 | + AUDIO_CODEC_ES7210_ADDR, |
| 207 | + true); |
| 208 | + return &audio_codec; |
| 209 | + } |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + virtual Display* GetDisplay() override { |
| 214 | + return display_; |
| 215 | + } |
| 216 | + |
| 217 | + //添加彩灯显示状态,如果亮度太暗可以去更改默认亮度值 DEFAULT_BRIGHTNESS 在led的sigle_led.cc中 |
| 218 | + virtual Led* GetLed() override { |
| 219 | + static SingleLed led(BUILTIN_LED_GPIO); |
| 220 | + return &led; |
| 221 | + } |
| 222 | + |
| 223 | + |
| 224 | +}; |
| 225 | + |
| 226 | +DECLARE_BOARD(ESP_S3_LCD_EV_Board); |
0 commit comments