forked from xiaozhi/xiaozhi-esp32
adjust board structure
This commit is contained in:
@@ -4,17 +4,7 @@
|
||||
|
||||
static const char *TAG = "AXP2101";
|
||||
|
||||
bool Axp2101::Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address) {
|
||||
i2c_device_config_t axp2101_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = (uint16_t)i2c_device_address,
|
||||
.scl_speed_hz = 100000,
|
||||
.scl_wait_us = 0,
|
||||
.flags = {
|
||||
.disable_ack_check = 0,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus, &axp2101_cfg, &i2c_device_));
|
||||
Axp2101::Axp2101(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
|
||||
|
||||
WriteReg(0x93, 0x1c); // 配置aldo2输出为3.3v
|
||||
|
||||
@@ -46,20 +36,6 @@ bool Axp2101::Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address
|
||||
|
||||
WriteReg(0x24, 0x01); // set Vsys for PWROFF threshold to 3.2V (default - 2.6V and kill battery)
|
||||
WriteReg(0x50, 0x14); // set TS pin to EXTERNAL input (not temperature)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Axp2101::WriteReg(uint8_t reg, uint8_t value) {
|
||||
uint8_t buffer[2];
|
||||
buffer[0] = reg;
|
||||
buffer[1] = value;
|
||||
ESP_ERROR_CHECK(i2c_master_transmit(i2c_device_, buffer, 2, 100));
|
||||
}
|
||||
|
||||
uint8_t Axp2101::ReadReg(uint8_t reg) {
|
||||
uint8_t buffer[1];
|
||||
ESP_ERROR_CHECK(i2c_master_transmit_receive(i2c_device_, ®, 1, buffer, 1, 100));
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
bool Axp2101::IsCharging() {
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
#ifndef __AXP2101_H__
|
||||
#define __AXP2101_H__
|
||||
|
||||
#include <driver/i2c_master.h>
|
||||
#include "i2c_device.h"
|
||||
|
||||
class Axp2101 {
|
||||
class Axp2101 : public I2cDevice {
|
||||
public:
|
||||
Axp2101() = default;
|
||||
bool Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address);
|
||||
Axp2101(i2c_master_bus_handle_t i2c_bus, uint8_t addr);
|
||||
bool IsCharging();
|
||||
bool IsChargingDone();
|
||||
int GetBatteryLevel();
|
||||
void PowerOff();
|
||||
|
||||
private:
|
||||
i2c_master_dev_handle_t i2c_device_ = nullptr;
|
||||
|
||||
void WriteReg(uint8_t reg, uint8_t value);
|
||||
uint8_t ReadReg(uint8_t reg);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "boards/ml307_board.h"
|
||||
#include "ml307_board.h"
|
||||
#include "audio_codecs/box_audio_codec.h"
|
||||
#include "display/ssd1306_display.h"
|
||||
#include "application.h"
|
||||
@@ -18,7 +18,7 @@ class KevinBoxBoard : public Ml307Board {
|
||||
private:
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||
Axp2101 axp2101_;
|
||||
Axp2101* axp2101_ = nullptr;
|
||||
Button boot_button_;
|
||||
Button volume_up_button_;
|
||||
Button volume_down_button_;
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
||||
InitializeDisplayI2c();
|
||||
InitializeCodecI2c();
|
||||
axp2101_.Initialize(codec_i2c_bus_, AXP2101_I2C_ADDR);
|
||||
axp2101_ = new Axp2101(codec_i2c_bus_, AXP2101_I2C_ADDR);
|
||||
|
||||
MountStorage();
|
||||
Enable4GModule();
|
||||
@@ -158,8 +158,8 @@ public:
|
||||
}
|
||||
|
||||
virtual bool GetBatteryLevel(int &level, bool& charging) override {
|
||||
level = axp2101_.GetBatteryLevel();
|
||||
charging = axp2101_.IsCharging();
|
||||
level = axp2101_->GetBatteryLevel();
|
||||
charging = axp2101_->IsCharging();
|
||||
ESP_LOGI(TAG, "Battery level: %d, Charging: %d", level, charging);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user