First working version

This commit is contained in:
Stefan Thoss
2023-12-21 20:47:39 -08:00
parent f215521303
commit 89adb157fa
4 changed files with 136 additions and 121 deletions

View File

@@ -1,12 +1,8 @@
# ESPHome AXP2101 Component
*Work in progress*
This custom component implements AXP2101 support for the M5Stack Core2 V1.1, building on top of https://github.com/martydingo/esphome-axp192. The Core2 uses an AXP192 while the Core2 V1.1 uses an AXP2101.
This custom component it to implement support for the AXP192 for both the M5Stick-C, and the M5Stack Core2, building on top of airy10's code.
*Update - 17th April 2023*
@paulchilton has added support for the M5Tough, which requires a different register configuration for the M5Tough ILI9342C display. Other changes include a fix to stop the log being spammed with brightness values continually, these are only logged on change. Also the M5Tough needs resetting once the axp192 registers are set for the display to properly initialise so this version sets up the axp and then resets the ESP32 automatically.
*This component does not offer full functionality yet, it only covers part of the AXP2101 features and is not fully tested.*
## Installation
@@ -16,67 +12,45 @@ Copy the components to a custom_components directory next to your .yaml configur
Sample configurations are found in the `/sample-config` folder.
This component adds a new model configuration to the AXP192 sensor which determines which registers are needed for each device. Available models are `model: M5CORE2`, `model: M5STICKC` and `model: M5TOUGH`.
This component adds a new model configuration to the AXP2101 sensor which determines which registers are needed for each device. The only available model is `model: M5CORE2`.
### Include axp192 component
### Include AXP2101 Component
```yaml
external_components:
- source: github://martydingo/esphome-axp192
components: [axp192]
- source: github://stefanthoss/esphome-axp2101
components: [ axp2101 ]
```
### M5Stick-C
### M5Stack Core2 V1.1
```yaml
sensor:
- platform: axp192
model: M5STICKC
address: 0x34
i2c_id: bus_a
update_interval: 30s
battery_level:
name: "M5Stick Battery Level"
id: "m5stick_batterylevel"
```
### M5Stack Core2
```yaml
sensor:
- platform: axp192
- platform: axp2101
model: M5CORE2
address: 0x34
i2c_id: bus_a
update_interval: 30s
brightness: 75%
battery_level:
name: "${upper_devicename} Battery Level"
id: "${devicename}_batterylevel"
name: "Battery Level"
id: battery_level
```
### M5Tough
The display component required for the M5Stack Core2 V1.1 is as follows:
```yaml
sensor:
- platform: axp192
model: M5Tough
address: 0x34
i2c_id: bus_a
update_interval: 30s
battery_level:
name: "${upper_devicename} Battery Level"
id: "${devicename}_batterylevel"
```
font:
- file: "gfonts://Roboto"
id: roboto
size: 24
The display component required for the M5Tough is as follows:
```yaml
display:
- platform: ili9341
# 320x240
- platform: ili9xxx
model: M5STACK
dimensions: 320x240
cs_pin: GPIO5
dc_pin: GPIO15
lambda: |-
it.print(160, 0, id(title_font), id(color_white), TextAlign::TOP_CENTER, "Hello World");
it.print(0, 0, id(roboto), "Hello World");
```

View File

@@ -3,6 +3,30 @@
#include "esp_sleep.h"
#include <Esp.h>
#ifndef CONFIG_PMU_SDA
#define CONFIG_PMU_SDA 21
#endif
#ifndef CONFIG_PMU_SCL
#define CONFIG_PMU_SCL 22
#endif
#ifndef CONFIG_PMU_IRQ
#define CONFIG_PMU_IRQ 35
#endif
bool pmu_flag = 0;
XPowersPMU PMU;
const uint8_t i2c_sda = CONFIG_PMU_SDA;
const uint8_t i2c_scl = CONFIG_PMU_SCL;
const uint8_t pmu_irq_pin = CONFIG_PMU_IRQ;
void setFlag(void)
{
pmu_flag = true;
}
namespace esphome {
namespace axp2101 {
@@ -71,7 +95,7 @@ void AXP2101Component::setup()
//ALDO3 IMAX=300mA
//500~3500mV, 100mV/step,31steps
PMU.setALDO3Voltage(3300);
// PMU.setALDO3Voltage(3300);
//ALDO4 IMAX=300mA
//500~3500mV, 100mV/step,31steps
@@ -91,11 +115,11 @@ void AXP2101Component::setup()
//DLDO1 IMAX=300mA
//500~3400mV, 100mV/step,29steps
PMU.setDLDO1Voltage(3300);
// PMU.setDLDO1Voltage(3300);
//DLDO2 IMAX=300mA
//500~1400mV, 50mV/step,2steps
PMU.setDLDO2Voltage(3300);
// PMU.setDLDO2Voltage(3300);
// PMU.enableDC1();
@@ -105,13 +129,13 @@ void AXP2101Component::setup()
PMU.enableDC5();
PMU.enableALDO1();
PMU.enableALDO2();
PMU.enableALDO3();
// PMU.enableALDO3(); // This is the speaker
PMU.enableALDO4();
PMU.enableBLDO1();
PMU.enableBLDO2();
PMU.enableCPUSLDO();
PMU.enableDLDO1();
PMU.enableDLDO2();
// PMU.enableDLDO1(); // This is the vibration motor
// PMU.enableDLDO2();
Serial.println("DCDC=======================================================================");
@@ -398,24 +422,12 @@ void AXP2101Component::UpdateBrightness()
ubri = c_max;
}
switch (this->model_) {
case AXP2101_M5STICKC:
{
uint8_t buf = Read8bit( 0x28 );
Write1Byte( 0x28 , ((buf & 0x0f) | (ubri << 4)) );
break;
}
case AXP2101_M5CORE2:
{
uint8_t buf = Read8bit( 0x27 );
Write1Byte( 0x27 , ((buf & 0x80) | (ubri << 3)) );
break;
}
case AXP2101_M5TOUGH:
{
uint8_t buf = Read8bit( 0x27 );
Write1Byte( 0x27 , ((buf & 0x80) | (ubri << 3)) );
break;
}
}
}

View File

@@ -8,21 +8,11 @@
#define XPOWERS_CHIP_AXP2101
#include "XPowersLib.h"
bool pmu_flag = 0;
XPowersPMU PMU;
void setFlag(void)
{
pmu_flag = true;
}
namespace esphome {
namespace axp2101 {
enum AXP2101Model {
AXP2101_M5STICKC = 0,
AXP2101_M5CORE2,
AXP2101_M5TOUGH,
};
#define SLEEP_MSEC(us) (((uint64_t)us) * 1000L)
@@ -61,14 +51,7 @@ protected:
float curr_brightness_{-1.0f};
AXP2101Model model_;
/** M5 Stick Values
* LDO2: Display backlight
* LDO3: Display Control
* RTC: Don't set GPIO1 as LDO
* DCDC1: Main rail. When not set the controller shuts down.
* DCDC3: Use unknown
***********************
* M5Stack Core2 Values
/** M5Stack Core2 Values
* LDO2: ILI9342C PWR (Display)
* LD03: Vibration Motor
*/
@@ -137,4 +120,4 @@ protected:
}
}
#endif
#endif

View File

@@ -1,38 +1,52 @@
esphome:
name: m5stack-core2
platform: ESP32
board: m5stack-core-esp32
# Use this to hardlink the component if it is not discovered
# includes:
# - /config/custom_components/axp192/axp192.h
friendly_name: M5Stack Core2
wifi:
ssid: "SSID"
password: "PASSPHRASE"
esp32:
board: m5stack-core2
framework:
type: arduino
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "XXX"
password: "XXX"
substitutions:
devicename: ${devicename}
upper_devicename: ${upper_devicename}
captive_portal:
external_components:
- source: github://stefanthoss/esphome-axp2101
components: [ axp2101 ]
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "XXX"
ota:
password: "XXX"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "XXX"
password: "XXX"
captive_portal:
web_server:
port: 80
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO38
i2c:
- id: bus_a
sda: GPIO21
scl: GPIO22
scan: True
# axp2101 power management - must be present to initialize TFT power on
sensor:
- platform: axp2101
model: M5CORE2
@@ -42,33 +56,65 @@ sensor:
brightness: 75%
battery_level:
name: "Battery Level"
id: battery_level
- platform: wifi_signal
name: WiFi Signal
- platform: mpu6886
address: 0x68
accel_x:
name: "Accel X"
accel_y:
name: "Accel Y"
accel_z:
name: "Accel z"
gyro_x:
name: "Gyro X"
gyro_y:
name: "Gyro Y"
gyro_z:
name: "Gyro z"
temperature:
name: "Temperature"
- platform: uptime
name: Uptime Sensor
touchscreen:
- platform: ft63x6
i2c_id: bus_a
on_touch:
- logger.log:
format: Touch %d at (%d, %d)
args: [touch.id, touch.x, touch.y]
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO38
i2c:
- id: bus_a
sda: GPIO21
scl: GPIO22
scan: True
binary_sensor:
- platform: touchscreen
name: Left Touch Button
x_min: 0
x_max: 106
y_min: 120
y_max: 140
- platform: touchscreen
name: Middle Touch Button
x_min: 107
x_max: 213
y_min: 120
y_max: 140
- platform: touchscreen
name: Right Touch Button
x_min: 214
x_max: 320
y_min: 120
y_max: 140
font:
- file: 'fonts/arial.ttf'
id: font1
size: 8
- file: "gfonts://Roboto"
id: roboto
size: 24
display:
- platform: ili9xxx
model: ILI9342
model: M5STACK
dimensions: 320x240
cs_pin: GPIO5
dc_pin: GPIO15
lambda: |-
it.print(80, 0, id(my_font), id(my_red), TextAlign::TOP_CENTER, "Hello World!");
it.print(0, 0, id(roboto), "Hello World");