Implemented power management (#67)

- Implemented HAL for for power management
- Implemented the Power app (accessible via Settings app)
- Implemented status bar icon for battery status
This commit is contained in:
Ken Van Hoeylandt
2024-11-02 23:40:26 +01:00
committed by GitHub
parent 6520655795
commit 632d7ccccf
29 changed files with 373 additions and 26 deletions
+5
View File
@@ -32,7 +32,12 @@ lv_disp_t* core2_display_init() {
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = GPIO_NUM_NC,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
.data_endian = LCD_RGB_DATA_ENDIAN_BIG,
.bits_per_pixel = CORE2_LCD_BITS_PER_PIXEL,
.flags = {
.reset_active_high = false
},
.vendor_config = nullptr
};
esp_lcd_panel_handle_t panel_handle;
+3 -1
View File
@@ -3,6 +3,7 @@
#include "lvgl_i.h"
extern const SdCard core2_sdcard;
extern Power core2_power; // Making it const fails the build
const HardwareConfig m5stack_core2 = {
.bootstrap = &core2_bootstrap,
@@ -10,5 +11,6 @@ const HardwareConfig m5stack_core2 = {
.set_backlight_duty = NULL
},
.init_graphics = &core2_lvgl_init,
.sdcard = &core2_sdcard
.sdcard = &core2_sdcard,
.power = &core2_power
};
+34
View File
@@ -0,0 +1,34 @@
#include "power.h"
#include "M5Unified.hpp"
#ifdef __cplusplus
extern "C" {
#endif
static bool power_is_charging() {
return M5.Power.isCharging() == m5::Power_Class::is_charging;
}
static void power_set_charging_enabled(bool enabled) {
M5.Power.setBatteryCharge(enabled);
}
static uint8_t power_get_charge_level() {
uint16_t scaled = (uint16_t)M5.Power.getBatteryLevel() * 255 / 100;
return (uint8_t)scaled;
}
static int32_t power_get_current() {
return M5.Power.getBatteryCurrent();
}
Power core2_power = {
.is_charging = &power_is_charging,
.set_charging_enabled = &power_set_charging_enabled,
.get_charge_level = &power_get_charge_level,
.get_current = &power_get_current
};
#ifdef __cplusplus
}
#endif
+1 -1
View File
@@ -9,7 +9,7 @@ extern "C" {
#endif
static void read_touch(TT_UNUSED lv_indev_t* indev, lv_indev_data_t* data) {
static lgfx::touch_point_t point;
lgfx::touch_point_t point; // Making it static makes it unreliable
bool touched = M5.Lcd.getTouch(&point) > 0;
if (touched) {
data->point.x = point.x;