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