fix: support SH1106 on bread compact NT26
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
#include "board.h"
|
||||
#include "nt26_board.h"
|
||||
#include "codecs/no_audio_codec.h"
|
||||
#include "display/oled_display.h"
|
||||
#include "application.h"
|
||||
#include "assets/lang_config.h"
|
||||
#include "board.h"
|
||||
#include "button.h"
|
||||
#include "codecs/no_audio_codec.h"
|
||||
#include "config.h"
|
||||
#include "display/oled_display.h"
|
||||
#include "lamp_controller.h"
|
||||
#include "led/single_led.h"
|
||||
#include "assets/lang_config.h"
|
||||
#include "nt26_board.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#ifdef SH1106
|
||||
#include <esp_lcd_panel_sh1106.h>
|
||||
#endif
|
||||
|
||||
#define TAG "CompactNt26Board"
|
||||
|
||||
@@ -36,15 +40,16 @@ private:
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
.flags =
|
||||
{
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &display_i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeSsd1306Display() {
|
||||
// SSD1306 config
|
||||
void InitializeOledDisplay() {
|
||||
// OLED config
|
||||
esp_lcd_panel_io_i2c_config_t io_config = {
|
||||
.dev_addr = 0x3C,
|
||||
.scl_speed_hz = 400 * 1000,
|
||||
@@ -54,15 +59,16 @@ private:
|
||||
.lcd_param_bits = 8,
|
||||
.on_color_trans_done = nullptr,
|
||||
.user_ctx = nullptr,
|
||||
.flags = {
|
||||
.dc_low_on_data = 0,
|
||||
.disable_control_phase = 0,
|
||||
},
|
||||
.flags =
|
||||
{
|
||||
.dc_low_on_data = 0,
|
||||
.disable_control_phase = 0,
|
||||
},
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(display_i2c_bus_, &io_config, &panel_io_));
|
||||
|
||||
ESP_LOGI(TAG, "Install SSD1306 driver");
|
||||
ESP_LOGI(TAG, "Install OLED driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = GPIO_NUM_NC;
|
||||
panel_config.bits_per_pixel = 1;
|
||||
@@ -72,8 +78,12 @@ private:
|
||||
};
|
||||
panel_config.vendor_config = &ssd1306_config;
|
||||
|
||||
#ifdef SH1106
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_sh1106(panel_io_, &panel_config, &panel_));
|
||||
#else
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(panel_io_, &panel_config, &panel_));
|
||||
ESP_LOGI(TAG, "SSD1306 driver installed");
|
||||
#endif
|
||||
ESP_LOGI(TAG, "OLED driver installed");
|
||||
|
||||
// Reset the display
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_));
|
||||
@@ -82,25 +92,21 @@ private:
|
||||
display_ = new NoDisplay();
|
||||
return;
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_, false));
|
||||
|
||||
// Set the display to on
|
||||
ESP_LOGI(TAG, "Turning display on");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true));
|
||||
|
||||
display_ = new OledDisplay(panel_io_, panel_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
display_ = new OledDisplay(panel_io_, panel_, DISPLAY_WIDTH, DISPLAY_HEIGHT,
|
||||
DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([]() {
|
||||
Application::GetInstance().ToggleChatState();
|
||||
});
|
||||
boot_button_.OnClick([]() { Application::GetInstance().ToggleChatState(); });
|
||||
|
||||
touch_button_.OnPressDown([]() {
|
||||
Application::GetInstance().StartListening();
|
||||
});
|
||||
touch_button_.OnPressUp([]() {
|
||||
Application::GetInstance().StopListening();
|
||||
});
|
||||
touch_button_.OnPressDown([]() { Application::GetInstance().StartListening(); });
|
||||
touch_button_.OnPressUp([]() { Application::GetInstance().StopListening(); });
|
||||
|
||||
volume_up_button_.OnClick([this]() {
|
||||
auto codec = GetAudioCodec();
|
||||
@@ -134,20 +140,17 @@ private:
|
||||
}
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeTools() {
|
||||
static LampController lamp(LAMP_GPIO);
|
||||
}
|
||||
void InitializeTools() { static LampController lamp(LAMP_GPIO); }
|
||||
|
||||
public:
|
||||
CompactNt26Board() :
|
||||
Nt26Board(NT26_TX_PIN, NT26_RX_PIN, NT26_DTR_PIN, NT26_RI_PIN),
|
||||
boot_button_(BOOT_BUTTON_GPIO),
|
||||
touch_button_(TOUCH_BUTTON_GPIO),
|
||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
||||
|
||||
CompactNt26Board()
|
||||
: Nt26Board(NT26_TX_PIN, NT26_RX_PIN, NT26_DTR_PIN, NT26_RI_PIN),
|
||||
boot_button_(BOOT_BUTTON_GPIO),
|
||||
touch_button_(TOUCH_BUTTON_GPIO),
|
||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
||||
InitializeDisplayI2c();
|
||||
InitializeSsd1306Display();
|
||||
InitializeOledDisplay();
|
||||
InitializeButtons();
|
||||
InitializeTools();
|
||||
}
|
||||
@@ -165,17 +168,18 @@ public:
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
#ifdef AUDIO_I2S_METHOD_SIMPLEX
|
||||
static NoAudioCodecSimplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
|
||||
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK,
|
||||
AUDIO_I2S_SPK_GPIO_DOUT, AUDIO_I2S_MIC_GPIO_SCK,
|
||||
AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN);
|
||||
#else
|
||||
static NoAudioCodecDuplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
|
||||
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS,
|
||||
AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN);
|
||||
#endif
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
virtual Display* GetDisplay() override { return display_; }
|
||||
};
|
||||
|
||||
DECLARE_BOARD(CompactNt26Board);
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
#define DISPLAY_HEIGHT 32
|
||||
#elif CONFIG_OLED_SSD1306_128X64
|
||||
#define DISPLAY_HEIGHT 64
|
||||
#elif CONFIG_OLED_SH1106_128X64
|
||||
#define DISPLAY_HEIGHT 64
|
||||
#define SH1106
|
||||
#else
|
||||
#error "OLED display type is not selected"
|
||||
#endif
|
||||
|
||||
@@ -1062,6 +1062,15 @@ class BuildOptionTests(unittest.TestCase):
|
||||
).read_text(encoding="utf-8")
|
||||
self.assertIn("CONFIG_OLED_SH1106_128X64", config_header)
|
||||
|
||||
def test_bread_compact_nt26_supports_sh1106(self):
|
||||
board_dir = ROOT / "main/boards/bread-compact-nt26"
|
||||
config_header = (board_dir / "config.h").read_text(encoding="utf-8")
|
||||
board_source = (board_dir / "compact_nt26_board.cc").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
self.assertIn("CONFIG_OLED_SH1106_128X64", config_header)
|
||||
self.assertIn("esp_lcd_new_panel_sh1106", board_source)
|
||||
|
||||
def test_non_default_style_disables_multiline_chat(self):
|
||||
definitions = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user