From 40be60ff9b1b1011535330b8b0d81ff85f1ba38f Mon Sep 17 00:00:00 2001 From: netseye Date: Wed, 5 Mar 2025 23:18:48 +0800 Subject: [PATCH] Add M5CoreS3 IoT support (#277) Co-authored-by: Jeakin --- .../boards/m5stack-core-s3/m5stack_core_s3.cc | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/main/boards/m5stack-core-s3/m5stack_core_s3.cc b/main/boards/m5stack-core-s3/m5stack_core_s3.cc index 294ac2b5..1215f274 100644 --- a/main/boards/m5stack-core-s3/m5stack_core_s3.cc +++ b/main/boards/m5stack-core-s3/m5stack_core_s3.cc @@ -46,8 +46,29 @@ public: int GetBatteryLevel() { return ReadReg(0xA4); } + + void SetBrightness(uint8_t brightness) { + brightness = ((brightness + 641) >> 5); + WriteReg(0x99, brightness); + } }; +class Axp2101Backlight : public Backlight { +public: + Axp2101Backlight(Axp2101 *axp2101) : axp2101_(axp2101) {} + + ~Axp2101Backlight() { ESP_LOGI(TAG, "Destroy Axp2101Backlight"); } + + void SetBrightnessImpl(uint8_t brightness) override; + +private: + Axp2101 *axp2101_; +}; + +void Axp2101Backlight::SetBrightnessImpl(uint8_t brightness) { + axp2101_->SetBrightness(brightness); +} + class Aw9523 : public I2cDevice { public: // Exanpd IO Init @@ -275,6 +296,8 @@ private: void InitializeIot() { auto& thing_manager = iot::ThingManager::GetInstance(); thing_manager.AddThing(iot::CreateThing("Speaker")); + thing_manager.AddThing(iot::CreateThing("Backlight")); + thing_manager.AddThing(iot::CreateThing("Battery")); } public: @@ -287,6 +310,7 @@ public: InitializeIli9342Display(); InitializeIot(); InitializeFt6336TouchPad(); + GetBacklight()->SetBrightness(100); } virtual AudioCodec* GetAudioCodec() override { @@ -321,6 +345,11 @@ public: return true; } + virtual Backlight *GetBacklight() override { + static Axp2101Backlight backlight(axp2101_); + return &backlight; + } + Ft6336* GetTouchpad() { return ft6336_; }