Merge develop into main (#368)
New boards: - LilyGO T-Dongle S3 - M5Stack StickC Plus - M5Stack StickC Plus2 New drivers: - AXP192: power control via I2C - ButtonControl: GPIO button input as LVGL device Other changes: - Updated implementation of AXP192 driver for Core2 board - Fix launcher UX for vertical layout - Fix error when properties file had an empty line - Add `__floatsidf` to `tt_init.cpp`
This commit is contained in:
committed by
GitHub
parent
3a59540365
commit
d8346998ce
@@ -1,51 +0,0 @@
|
||||
#include "axp192/axp192.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
#include <Tactility/CoreDefines.h>
|
||||
|
||||
#include <driver/i2c.h>
|
||||
#include <driver/spi_master.h>
|
||||
|
||||
constexpr auto* TAG = "Core2";
|
||||
|
||||
axp192_t axpDevice;
|
||||
|
||||
static int32_t axpI2cRead(TT_UNUSED void* handle, uint8_t address, uint8_t reg, uint8_t* buffer, uint16_t size) {
|
||||
if (tt::hal::i2c::masterReadRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS)) {
|
||||
return AXP192_OK;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t axpI2cWrite(TT_UNUSED void* handle, uint8_t address, uint8_t reg, const uint8_t* buffer, uint16_t size) {
|
||||
if (tt::hal::i2c::masterWriteRegister(I2C_NUM_0, address, reg, buffer, size, 50 / portTICK_PERIOD_MS)) {
|
||||
return AXP192_OK;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void initAxp() {
|
||||
axpDevice.read = axpI2cRead;
|
||||
axpDevice.write = axpI2cWrite;
|
||||
|
||||
axp192_ioctl(&axpDevice, AXP192_LDO2_SET_VOLTAGE, 3300); // LCD + SD
|
||||
axp192_ioctl(&axpDevice, AXP192_LDO3_SET_VOLTAGE, 0); // VIB_MOTOR STOP
|
||||
axp192_ioctl(&axpDevice, AXP192_DCDC3_SET_VOLTAGE, 3300);
|
||||
|
||||
axp192_ioctl(&axpDevice, AXP192_LDO2_ENABLE);
|
||||
axp192_ioctl(&axpDevice, AXP192_LDO3_DISABLE);
|
||||
axp192_ioctl(&axpDevice, AXP192_DCDC3_ENABLE);
|
||||
|
||||
axp192_write(&axpDevice, AXP192_PWM1_DUTY_CYCLE_2, 255); // PWM 255 (LED OFF)
|
||||
axp192_write(&axpDevice, AXP192_GPIO1_CONTROL, 0x02); // GPIO1 PWM
|
||||
// TODO: We could charge at 390mA according to the M5Unified code, but the AXP driver in M5Unified limits to 132mA, so it's unclear what the AXP supports.
|
||||
}
|
||||
|
||||
bool initBoot() {
|
||||
TT_LOG_I(TAG, "initBoot");
|
||||
initAxp();
|
||||
return true;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
bool initBoot();
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "M5stackCore2.h"
|
||||
#include "InitBoot.h"
|
||||
#include "devices/Display.h"
|
||||
#include "devices/Core2Power.h"
|
||||
#include "devices/SdCard.h"
|
||||
#include "devices/Power.h"
|
||||
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
@@ -11,9 +10,16 @@
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
constexpr auto* TAG = "Core2";
|
||||
|
||||
bool initBoot() {
|
||||
TT_LOG_I(TAG, "initBoot");
|
||||
return initAxp();
|
||||
}
|
||||
|
||||
static DeviceVector createDevices() {
|
||||
return {
|
||||
createPower(),
|
||||
getAxp192(),
|
||||
createSdCard(),
|
||||
createDisplay()
|
||||
};
|
||||
@@ -41,7 +47,7 @@ extern const Configuration m5stack_core2 = {
|
||||
}
|
||||
},
|
||||
i2c::Configuration {
|
||||
.name = "External", // (Grove)
|
||||
.name = "Port A", // Grove
|
||||
.port = I2C_NUM_1,
|
||||
.initMode = i2c::InitMode::ByTactility,
|
||||
.isMutable = true,
|
||||
@@ -85,7 +91,7 @@ extern const Configuration m5stack_core2 = {
|
||||
},
|
||||
.uart {
|
||||
uart::Configuration {
|
||||
.name = "Grove",
|
||||
.name = "Port A", // Grove
|
||||
.port = UART_NUM_1,
|
||||
.rxPin = GPIO_NUM_32,
|
||||
.txPin = GPIO_NUM_33,
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2021 Mika Tuupola
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,4 +0,0 @@
|
||||
From https://github.com/tuupola/axp192
|
||||
|
||||
Changed some code for Tactility:
|
||||
- `axp192_write()` now accepts a byte value instead of a byte pointer
|
||||
@@ -1,440 +0,0 @@
|
||||
/*
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2021 Mika Tuupola
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
-cut-
|
||||
|
||||
This file is part of hardware agnostic I2C driver for AXP192:
|
||||
https://github.com/tuupola/axp192
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
Version: 0.6.0
|
||||
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "axp192_config.h"
|
||||
#include "axp192.h"
|
||||
|
||||
static axp192_err_t read_coloumb_counter(const axp192_t *axp, float *buffer);
|
||||
static axp192_err_t read_battery_power(const axp192_t *axp, float *buffer);
|
||||
|
||||
static const axp192_init_command_t init_commands[] = {
|
||||
#ifdef AXP192_INCLUDE_SDKCONFIG_H
|
||||
/* Currently you have to use menuconfig to be able to use axp192_init() */
|
||||
{AXP192_DCDC1_VOLTAGE, {CONFIG_AXP192_DCDC1_VOLTAGE}, 1},
|
||||
{AXP192_DCDC3_VOLTAGE, {CONFIG_AXP192_DCDC3_VOLTAGE}, 1},
|
||||
{AXP192_LDO23_VOLTAGE, {CONFIG_AXP192_LDO23_VOLTAGE}, 1},
|
||||
{AXP192_GPIO0_LDOIO0_VOLTAGE, {CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE}, 1},
|
||||
{AXP192_DCDC13_LDO23_CONTROL, {CONFIG_AXP192_DCDC13_LDO23_CONTROL}, 1},
|
||||
{AXP192_EXTEN_DCDC2_CONTROL, {CONFIG_AXP192_EXTEN_DCDC2_CONTROL}, 1},
|
||||
{AXP192_GPIO0_CONTROL, {CONFIG_AXP192_GPIO0_CONTROL}, 1},
|
||||
{AXP192_GPIO1_CONTROL, {CONFIG_AXP192_GPIO1_CONTROL}, 1},
|
||||
{AXP192_GPIO2_CONTROL, {CONFIG_AXP192_GPIO2_CONTROL}, 1},
|
||||
{AXP192_GPIO43_FUNCTION_CONTROL, {CONFIG_AXP192_GPIO43_FUNCTION_CONTROL}, 1},
|
||||
{AXP192_ADC_ENABLE_1, {CONFIG_AXP192_ADC_ENABLE_1}, 1},
|
||||
{AXP192_CHARGE_CONTROL_1, {CONFIG_AXP192_CHARGE_CONTROL_1}, 1},
|
||||
{AXP192_BATTERY_CHARGE_CONTROL, {CONFIG_AXP192_BATTERY_CHARGE_CONTROL}, 1},
|
||||
#endif /* AXP192_INCLUDE_SDKCONFIG_H */
|
||||
/* End of commands. */
|
||||
{0, {0}, 0xff},
|
||||
};
|
||||
|
||||
axp192_err_t axp192_init(const axp192_t *axp)
|
||||
{
|
||||
uint8_t cmd = 0;
|
||||
axp192_err_t status;
|
||||
|
||||
/* Send all the commands. */
|
||||
while (init_commands[cmd].count != 0xff) {
|
||||
status = axp->write(
|
||||
axp->handle,
|
||||
AXP192_ADDRESS,
|
||||
init_commands[cmd].command,
|
||||
init_commands[cmd].data,
|
||||
init_commands[cmd].count & 0x1f
|
||||
);
|
||||
if (AXP192_OK != status) {
|
||||
return status;
|
||||
}
|
||||
cmd++;
|
||||
}
|
||||
|
||||
return AXP192_OK;
|
||||
}
|
||||
|
||||
static axp192_err_t axp192_read_adc(const axp192_t *axp, uint8_t reg, float *buffer)
|
||||
{
|
||||
uint8_t tmp[4];
|
||||
float sensitivity = 1.0;
|
||||
float offset = 0.0;
|
||||
axp192_err_t status;
|
||||
|
||||
switch (reg) {
|
||||
case AXP192_ACIN_VOLTAGE:
|
||||
case AXP192_VBUS_VOLTAGE:
|
||||
/* 1.7mV per LSB */
|
||||
sensitivity = 1.7 / 1000;
|
||||
break;
|
||||
case AXP192_ACIN_CURRENT:
|
||||
/* 0.375mA per LSB */
|
||||
sensitivity = 0.625 / 1000;
|
||||
break;
|
||||
case AXP192_VBUS_CURRENT:
|
||||
/* 0.375mA per LSB */
|
||||
sensitivity = 0.375 / 1000;
|
||||
break;
|
||||
case AXP192_TEMP:
|
||||
/* 0.1C per LSB, 0x00 = -144.7C */
|
||||
sensitivity = 0.1;
|
||||
offset = -144.7;
|
||||
break;
|
||||
case AXP192_TS_INPUT:
|
||||
/* 0.8mV per LSB */
|
||||
sensitivity = 0.8 / 1000;
|
||||
break;
|
||||
case AXP192_BATTERY_POWER:
|
||||
/* 1.1mV * 0.5mA per LSB */
|
||||
return read_battery_power(axp, buffer);
|
||||
break;
|
||||
case AXP192_BATTERY_VOLTAGE:
|
||||
/* 1.1mV per LSB */
|
||||
sensitivity = 1.1 / 1000;
|
||||
break;
|
||||
case AXP192_CHARGE_CURRENT:
|
||||
case AXP192_DISCHARGE_CURRENT:
|
||||
/* 0.5mV per LSB */
|
||||
sensitivity = 0.5 / 1000;
|
||||
break;
|
||||
case AXP192_APS_VOLTAGE:
|
||||
/* 1.4mV per LSB */
|
||||
sensitivity = 1.4 / 1000;
|
||||
break;
|
||||
case AXP192_COULOMB_COUNTER:
|
||||
/* This is currently untested. */
|
||||
return read_coloumb_counter(axp, buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
status = axp->read(axp->handle, AXP192_ADDRESS, reg, tmp, 2);
|
||||
if (AXP192_OK != status) {
|
||||
return status;
|
||||
}
|
||||
*buffer = (((tmp[0] << 4) + tmp[1]) * sensitivity) + offset;
|
||||
|
||||
return AXP192_OK;
|
||||
}
|
||||
|
||||
axp192_err_t axp192_read(const axp192_t *axp, uint8_t reg, void *buffer) {
|
||||
switch (reg) {
|
||||
case AXP192_ACIN_VOLTAGE:
|
||||
case AXP192_VBUS_VOLTAGE:
|
||||
case AXP192_ACIN_CURRENT:
|
||||
case AXP192_VBUS_CURRENT:
|
||||
case AXP192_TEMP:
|
||||
case AXP192_TS_INPUT:
|
||||
case AXP192_BATTERY_POWER:
|
||||
case AXP192_BATTERY_VOLTAGE:
|
||||
case AXP192_CHARGE_CURRENT:
|
||||
case AXP192_DISCHARGE_CURRENT:
|
||||
case AXP192_APS_VOLTAGE:
|
||||
case AXP192_COULOMB_COUNTER:
|
||||
/* Return ADC value. */
|
||||
return axp192_read_adc(axp, reg, buffer);
|
||||
break;
|
||||
default:
|
||||
/* Return raw register value. */
|
||||
return axp->read(axp->handle, AXP192_ADDRESS, reg, buffer, 1);
|
||||
}
|
||||
}
|
||||
|
||||
axp192_err_t axp192_write(const axp192_t *axp, uint8_t reg, uint8_t value) {
|
||||
switch (reg) {
|
||||
case AXP192_ACIN_VOLTAGE:
|
||||
case AXP192_VBUS_VOLTAGE:
|
||||
case AXP192_ACIN_CURRENT:
|
||||
case AXP192_VBUS_CURRENT:
|
||||
case AXP192_TEMP:
|
||||
case AXP192_TS_INPUT:
|
||||
case AXP192_BATTERY_POWER:
|
||||
case AXP192_BATTERY_VOLTAGE:
|
||||
case AXP192_CHARGE_CURRENT:
|
||||
case AXP192_DISCHARGE_CURRENT:
|
||||
case AXP192_APS_VOLTAGE:
|
||||
case AXP192_COULOMB_COUNTER:
|
||||
/* Read only register. */
|
||||
return AXP192_ERROR_ENOTSUP;
|
||||
break;
|
||||
default:
|
||||
/* Write raw register value. */
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &value, 1);
|
||||
}
|
||||
}
|
||||
|
||||
axp192_err_t axp192_ioctl(const axp192_t *axp, int command, ...)
|
||||
{
|
||||
uint8_t reg = command >> 8;
|
||||
uint8_t tmp;
|
||||
uint16_t argument;
|
||||
va_list ap;
|
||||
|
||||
switch (command) {
|
||||
case AXP192_COULOMB_COUNTER_ENABLE:
|
||||
tmp = 0b10000000;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_COULOMB_COUNTER_DISABLE:
|
||||
tmp = 0b00000000;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_COULOMB_COUNTER_SUSPEND:
|
||||
tmp = 0b11000000;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_COULOMB_COUNTER_CLEAR:
|
||||
tmp = 0b10100000;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_LDOIO0_ENABLE:
|
||||
/* 0x02 = LDO */
|
||||
tmp = 0b00000010;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_LDOIO0_DISABLE:
|
||||
/* 0x07 = float */
|
||||
tmp = 0b00000111;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_LDO2_ENABLE:
|
||||
/* This is currently untested. */
|
||||
case AXP192_EXTEN_ENABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp |= 0b00000100;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_LDO2_DISABLE:
|
||||
/* This is currently untested. */
|
||||
case AXP192_EXTEN_DISABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp &= ~0b00000100;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_GPIO2_SET_LEVEL:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
va_start(ap, command);
|
||||
argument = (uint8_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
if (argument) {
|
||||
tmp |= 0b00000100;
|
||||
} else {
|
||||
tmp &= ~0b00000100;
|
||||
}
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_LDO3_ENABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp |= 0b00001000;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_LDO3_DISABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp &= ~0b00001000;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_DCDC1_ENABLE:
|
||||
/* This is currently untested. */
|
||||
case AXP192_DCDC2_ENABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp |= 0b00000001;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_DCDC1_DISABLE:
|
||||
/* This is currently untested. */
|
||||
case AXP192_DCDC2_DISABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp &= ~0b00000001;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_DCDC3_ENABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp |= 0b00000010;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_DCDC3_DISABLE:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
tmp &= ~0b00000010;
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_GPIO1_SET_LEVEL:
|
||||
case AXP192_GPIO4_SET_LEVEL:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
va_start(ap, command);
|
||||
argument = (uint8_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
if (argument) {
|
||||
tmp |= 0b00000010;
|
||||
} else {
|
||||
tmp &= ~0b00000010;
|
||||
}
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_GPIO0_SET_LEVEL:
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
va_start(ap, command);
|
||||
argument = (uint8_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
if (argument) {
|
||||
tmp |= 0b00000001;
|
||||
} else {
|
||||
tmp &= ~0b00000001;
|
||||
}
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
case AXP192_DCDC1_SET_VOLTAGE:
|
||||
case AXP192_DCDC3_SET_VOLTAGE:
|
||||
va_start(ap, command);
|
||||
argument = (uint16_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
|
||||
/* 700-3500mv 25mV per step */
|
||||
if ((argument < 700) || (argument > 3500)) {
|
||||
return AXP192_ERROR_EINVAL;
|
||||
}
|
||||
tmp = (argument - 700) / 25;
|
||||
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_DCDC2_SET_VOLTAGE:
|
||||
va_start(ap, command);
|
||||
argument = (uint16_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
|
||||
/* 700-2275mV 25mV per step */
|
||||
if ((argument < 700) || (argument > 2275)) {
|
||||
return AXP192_ERROR_EINVAL;
|
||||
}
|
||||
tmp = (argument - 700) / 25;
|
||||
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_LDO2_SET_VOLTAGE:
|
||||
va_start(ap, command);
|
||||
argument = (uint16_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
|
||||
/* 1800-3300mV 100mV per step */
|
||||
if ((argument < 1800) || (argument > 3300)) {
|
||||
return AXP192_ERROR_EINVAL;
|
||||
}
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
|
||||
tmp &= ~0xf0;
|
||||
tmp |= (((argument - 1800) / 100) << 4);
|
||||
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_LDO3_SET_VOLTAGE:
|
||||
va_start(ap, command);
|
||||
argument = (uint16_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
|
||||
/* 1800-3300mV 100mV per step */
|
||||
if ((argument < 1800) || (argument > 3300)) {
|
||||
return AXP192_ERROR_EINVAL;
|
||||
}
|
||||
axp->read(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
|
||||
tmp &= ~0x0f;
|
||||
tmp |= ((argument - 1800) / 100);
|
||||
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
/* This is currently untested. */
|
||||
case AXP192_LDOIO0_SET_VOLTAGE:
|
||||
va_start(ap, command);
|
||||
argument = (uint16_t) va_arg(ap, int);
|
||||
va_end(ap);
|
||||
|
||||
/* 1800-3300mV 100mV per step, 2800mV default. */
|
||||
if ((argument < 1800) || (argument > 3300)) {
|
||||
return AXP192_ERROR_EINVAL;
|
||||
}
|
||||
tmp = (((argument - 1800) / 100) << 4);
|
||||
|
||||
return axp->write(axp->handle, AXP192_ADDRESS, reg, &tmp, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
return AXP192_ERROR_NOTTY;
|
||||
}
|
||||
|
||||
static axp192_err_t read_coloumb_counter(const axp192_t *axp, float *buffer)
|
||||
{
|
||||
uint8_t tmp[4];
|
||||
int32_t coin, coout;
|
||||
axp192_err_t status;
|
||||
|
||||
status = axp->read(axp->handle, AXP192_ADDRESS, AXP192_CHARGE_COULOMB, tmp, sizeof(coin));
|
||||
if (AXP192_OK != status) {
|
||||
return status;
|
||||
}
|
||||
coin = (tmp[0] << 24) + (tmp[1] << 16) + (tmp[2] << 8) + tmp[3];
|
||||
|
||||
status = axp->read(axp->handle, AXP192_ADDRESS, AXP192_DISCHARGE_COULOMB, tmp, sizeof(coout));
|
||||
if (AXP192_OK != status) {
|
||||
return status;
|
||||
}
|
||||
coout = (tmp[0] << 24) + (tmp[1] << 16) + (tmp[2] << 8) + tmp[3];
|
||||
|
||||
/* CmAh = 65536 * 0.5mA *(coin - cout) / 3600 / ADC sample rate */
|
||||
*buffer = 32768 * (coin - coout) / 3600 / 25;
|
||||
|
||||
return AXP192_OK;
|
||||
}
|
||||
|
||||
static axp192_err_t read_battery_power(const axp192_t *axp, float *buffer)
|
||||
{
|
||||
uint8_t tmp[4];
|
||||
float sensitivity;
|
||||
axp192_err_t status;
|
||||
|
||||
/* 1.1mV * 0.5mA per LSB */
|
||||
sensitivity = 1.1 * 0.5 / 1000;
|
||||
status = axp->read(axp->handle, AXP192_ADDRESS, AXP192_BATTERY_POWER, tmp, 3);
|
||||
if (AXP192_OK != status) {
|
||||
return status;
|
||||
}
|
||||
*buffer = (((tmp[0] << 16) + (tmp[1] << 8) + tmp[2]) * sensitivity);
|
||||
return AXP192_OK;
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2021 Mika Tuupola
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
-cut-
|
||||
|
||||
This file is part of hardware agnostic I2C driver for AXP192:
|
||||
https://github.com/tuupola/axp192
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
Version: 0.6.0
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _AXP192_H
|
||||
#define _AXP192_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define AXP192_ADDRESS (0x34)
|
||||
|
||||
/* Power control registers */
|
||||
#define AXP192_POWER_STATUS (0x00)
|
||||
#define AXP192_CHARGE_STATUS (0x01)
|
||||
#define AXP192_OTG_VBUS_STATUS (0x04)
|
||||
#define AXP192_DATA_BUFFER0 (0x06)
|
||||
#define AXP192_DATA_BUFFER1 (0x07)
|
||||
#define AXP192_DATA_BUFFER2 (0x08)
|
||||
#define AXP192_DATA_BUFFER3 (0x09)
|
||||
#define AXP192_DATA_BUFFER4 (0x0a)
|
||||
#define AXP192_DATA_BUFFER5 (0x0b)
|
||||
/* Output control: 2 EXTEN, 0 DCDC2 */
|
||||
#define AXP192_EXTEN_DCDC2_CONTROL (0x10)
|
||||
/* Power output control: 6 EXTEN, 4 DCDC2, 3 LDO3, 2 LDO2, 1 DCDC3, 0 DCDC1 */
|
||||
#define AXP192_DCDC13_LDO23_CONTROL (0x12)
|
||||
#define AXP192_DCDC2_VOLTAGE (0x23)
|
||||
#define AXP192_DCDC2_SLOPE (0x25)
|
||||
#define AXP192_DCDC1_VOLTAGE (0x26)
|
||||
#define AXP192_DCDC3_VOLTAGE (0x27)
|
||||
/* Output voltage control: 7-4 LDO2, 3-0 LDO3 */
|
||||
#define AXP192_LDO23_VOLTAGE (0x28)
|
||||
#define AXP192_VBUS_IPSOUT_CHANNEL (0x30)
|
||||
#define AXP192_SHUTDOWN_VOLTAGE (0x31)
|
||||
#define AXP192_SHUTDOWN_BATTERY_CHGLED_CONTROL (0x32)
|
||||
#define AXP192_CHARGE_CONTROL_1 (0x33)
|
||||
#define AXP192_CHARGE_CONTROL_2 (0x34)
|
||||
#define AXP192_BATTERY_CHARGE_CONTROL (0x35)
|
||||
#define AXP192_PEK (0x36)
|
||||
#define AXP192_DCDC_FREQUENCY (0x37)
|
||||
#define AXP192_BATTERY_CHARGE_LOW_TEMP (0x38)
|
||||
#define AXP192_BATTERY_CHARGE_HIGH_TEMP (0x39)
|
||||
#define AXP192_APS_LOW_POWER1 (0x3A)
|
||||
#define AXP192_APS_LOW_POWER2 (0x3B)
|
||||
#define AXP192_BATTERY_DISCHARGE_LOW_TEMP (0x3c)
|
||||
#define AXP192_BATTERY_DISCHARGE_HIGH_TEMP (0x3d)
|
||||
#define AXP192_DCDC_MODE (0x80)
|
||||
#define AXP192_ADC_ENABLE_1 (0x82)
|
||||
#define AXP192_ADC_ENABLE_2 (0x83)
|
||||
#define AXP192_ADC_RATE_TS_PIN (0x84)
|
||||
#define AXP192_GPIO30_INPUT_RANGE (0x85)
|
||||
#define AXP192_GPIO0_ADC_IRQ_RISING (0x86)
|
||||
#define AXP192_GPIO0_ADC_IRQ_FALLING (0x87)
|
||||
#define AXP192_TIMER_CONTROL (0x8a)
|
||||
#define AXP192_VBUS_MONITOR (0x8b)
|
||||
#define AXP192_TEMP_SHUTDOWN_CONTROL (0x8f)
|
||||
|
||||
/* GPIO control registers */
|
||||
#define AXP192_GPIO0_CONTROL (0x90)
|
||||
#define AXP192_GPIO0_LDOIO0_VOLTAGE (0x91)
|
||||
#define AXP192_GPIO1_CONTROL (0x92)
|
||||
#define AXP192_GPIO2_CONTROL (0x93)
|
||||
#define AXP192_GPIO20_SIGNAL_STATUS (0x94)
|
||||
#define AXP192_GPIO43_FUNCTION_CONTROL (0x95)
|
||||
#define AXP192_GPIO43_SIGNAL_STATUS (0x96)
|
||||
#define AXP192_GPIO20_PULLDOWN_CONTROL (0x97)
|
||||
#define AXP192_PWM1_FREQUENCY (0x98)
|
||||
#define AXP192_PWM1_DUTY_CYCLE_1 (0x99)
|
||||
#define AXP192_PWM1_DUTY_CYCLE_2 (0x9a)
|
||||
#define AXP192_PWM2_FREQUENCY (0x9b)
|
||||
#define AXP192_PWM2_DUTY_CYCLE_1 (0x9c)
|
||||
#define AXP192_PWM2_DUTY_CYCLE_2 (0x9d)
|
||||
#define AXP192_N_RSTO_GPIO5_CONTROL (0x9e)
|
||||
|
||||
/* Interrupt control registers */
|
||||
#define AXP192_ENABLE_CONTROL_1 (0x40)
|
||||
#define AXP192_ENABLE_CONTROL_2 (0x41)
|
||||
#define AXP192_ENABLE_CONTROL_3 (0x42)
|
||||
#define AXP192_ENABLE_CONTROL_4 (0x43)
|
||||
#define AXP192_ENABLE_CONTROL_5 (0x4a)
|
||||
#define AXP192_IRQ_STATUS_1 (0x44)
|
||||
#define AXP192_IRQ_STATUS_2 (0x45)
|
||||
#define AXP192_IRQ_STATUS_3 (0x46)
|
||||
#define AXP192_IRQ_STATUS_4 (0x47)
|
||||
#define AXP192_IRQ_STATUS_5 (0x4d)
|
||||
|
||||
/* ADC data registers */
|
||||
#define AXP192_ACIN_VOLTAGE (0x56)
|
||||
#define AXP192_ACIN_CURRENT (0x58)
|
||||
#define AXP192_VBUS_VOLTAGE (0x5a)
|
||||
#define AXP192_VBUS_CURRENT (0x5c)
|
||||
#define AXP192_TEMP (0x5e)
|
||||
#define AXP192_TS_INPUT (0x62)
|
||||
#define AXP192_GPIO0_VOLTAGE (0x64)
|
||||
#define AXP192_GPIO1_VOLTAGE (0x66)
|
||||
#define AXP192_GPIO2_VOLTAGE (0x68)
|
||||
#define AXP192_GPIO3_VOLTAGE (0x6a)
|
||||
#define AXP192_BATTERY_POWER (0x70)
|
||||
#define AXP192_BATTERY_VOLTAGE (0x78)
|
||||
#define AXP192_CHARGE_CURRENT (0x7a)
|
||||
#define AXP192_DISCHARGE_CURRENT (0x7c)
|
||||
#define AXP192_APS_VOLTAGE (0x7e)
|
||||
#define AXP192_CHARGE_COULOMB (0xb0)
|
||||
#define AXP192_DISCHARGE_COULOMB (0xb4)
|
||||
#define AXP192_COULOMB_COUNTER_CONTROL (0xb8)
|
||||
|
||||
/* Computed ADC */
|
||||
#define AXP192_COULOMB_COUNTER (0xff)
|
||||
|
||||
/* IOCTL commands */
|
||||
#define AXP192_READ_POWER_STATUS (0x0001)
|
||||
#define AXP192_READ_CHARGE_STATUS (0x0101)
|
||||
|
||||
#define AXP192_COULOMB_COUNTER_ENABLE (0xb801)
|
||||
#define AXP192_COULOMB_COUNTER_DISABLE (0xb802)
|
||||
#define AXP192_COULOMB_COUNTER_SUSPEND (0xb803)
|
||||
#define AXP192_COULOMB_COUNTER_CLEAR (0xb804)
|
||||
|
||||
#define AXP192_LDOIO0_ENABLE (0x9000)
|
||||
#define AXP192_LDOIO0_DISABLE (0x9001)
|
||||
|
||||
#define AXP192_DCDC2_ENABLE (0x1000)
|
||||
#define AXP192_DCDC2_DISABLE (0x1001)
|
||||
#define AXP192_EXTEN_ENABLE (0x1002)
|
||||
#define AXP192_EXTEN_DISABLE (0x1003)
|
||||
|
||||
#define AXP192_LDO2_ENABLE (0x1200)
|
||||
#define AXP192_LDO2_DISABLE (0x1201)
|
||||
#define AXP192_LDO3_ENABLE (0x1202)
|
||||
#define AXP192_LDO3_DISABLE (0x1203)
|
||||
#define AXP192_DCDC1_ENABLE (0x1204)
|
||||
#define AXP192_DCDC1_DISABLE (0x1205)
|
||||
#define AXP192_DCDC3_ENABLE (0x1206)
|
||||
#define AXP192_DCDC3_DISABLE (0x1207)
|
||||
|
||||
#define AXP192_DCDC1_SET_VOLTAGE (0x2600)
|
||||
#define AXP192_DCDC2_SET_VOLTAGE (0x2300)
|
||||
#define AXP192_DCDC3_SET_VOLTAGE (0x2700)
|
||||
#define AXP192_LDO2_SET_VOLTAGE (0x2800)
|
||||
#define AXP192_LDO3_SET_VOLTAGE (0x2801)
|
||||
#define AXP192_LDOIO0_SET_VOLTAGE (0x9100)
|
||||
|
||||
#define AXP192_LOW (0)
|
||||
#define AXP192_HIGH (1)
|
||||
|
||||
#define AXP192_GPIO0_SET_LEVEL (0x9400)
|
||||
#define AXP192_GPIO1_SET_LEVEL (0x9401)
|
||||
#define AXP192_GPIO2_SET_LEVEL (0x9402)
|
||||
#define AXP192_GPIO4_SET_LEVEL (0x9601)
|
||||
|
||||
/* Error codes */
|
||||
#define AXP192_OK (0)
|
||||
#define AXP192_ERROR_NOTTY (-1)
|
||||
#define AXP192_ERROR_EINVAL (-22)
|
||||
#define AXP192_ERROR_ENOTSUP (-95)
|
||||
|
||||
typedef struct {
|
||||
uint8_t command;
|
||||
uint8_t data[2];
|
||||
uint8_t count;
|
||||
} axp192_init_command_t;
|
||||
|
||||
/* These should be provided by the HAL. */
|
||||
typedef struct {
|
||||
int32_t (* read)(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size);
|
||||
int32_t (* write)(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size);
|
||||
void *handle;
|
||||
} axp192_t;
|
||||
|
||||
typedef int32_t axp192_err_t;
|
||||
|
||||
axp192_err_t axp192_init(const axp192_t *axp);
|
||||
axp192_err_t axp192_read(const axp192_t *axp, uint8_t reg, void *buffer);
|
||||
axp192_err_t axp192_write(const axp192_t *axp, uint8_t reg, uint8_t value);
|
||||
axp192_err_t axp192_ioctl(const axp192_t *axp, int command, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2021 Mika Tuupola
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
-cut-
|
||||
|
||||
This file is part of hardware agnostic I2C driver for AXP192:
|
||||
https://github.com/tuupola/axp192
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
Version: 0.6.0
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _AXP192_CONFIG_H
|
||||
#define _AXP192_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef AXP192_INCLUDE_SDKCONFIG_H
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* This requires you to run menuconfig first. */
|
||||
|
||||
#define CONFIG_AXP192_EXTEN_DCDC2_CONTROL ( \
|
||||
CONFIG_AXP192_EXTEN_DCDC2_CONTROL_BIT2 | \
|
||||
CONFIG_AXP192_EXTEN_DCDC2_CONTROL_BIT0 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_DCDC13_LDO23_CONTROL ( \
|
||||
CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT6 | \
|
||||
CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT4 | \
|
||||
CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT3 | \
|
||||
CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT2 | \
|
||||
CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT1 | \
|
||||
CONFIG_AXP192_DCDC13_LDO23_CONTROL_BIT0 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_LDO23_VOLTAGE ( \
|
||||
CONFIG_AXP192_LDO23_VOLTAGE_BIT74 | \
|
||||
CONFIG_AXP192_LDO23_VOLTAGE_BIT30 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_DCDC1_VOLTAGE ( \
|
||||
CONFIG_AXP192_DCDC1_VOLTAGE_BIT60 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_DCDC3_VOLTAGE ( \
|
||||
CONFIG_AXP192_DCDC3_VOLTAGE_BIT60 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_ADC_ENABLE_1 ( \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT7 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT6 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT5 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT4 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT3 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT2 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT1 | \
|
||||
CONFIG_AXP192_ADC_ENABLE_1_BIT0 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_CHARGE_CONTROL_1 ( \
|
||||
CONFIG_AXP192_CHARGE_CONTROL_1_BIT7 | \
|
||||
CONFIG_AXP192_CHARGE_CONTROL_1_BIT65 | \
|
||||
CONFIG_AXP192_CHARGE_CONTROL_1_BIT4 | \
|
||||
CONFIG_AXP192_CHARGE_CONTROL_1_BIT30 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_BATTERY_CHARGE_CONTROL ( \
|
||||
CONFIG_AXP192_BATTERY_CHARGE_CONTROL_BIT7 | \
|
||||
CONFIG_AXP192_BATTERY_CHARGE_CONTROL_BIT65 | \
|
||||
CONFIG_AXP192_BATTERY_CHARGE_CONTROL_BIT10 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_GPIO0_CONTROL ( \
|
||||
CONFIG_AXP192_GPIO0_CONTROL_BIT20 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_GPIO1_CONTROL ( \
|
||||
CONFIG_AXP192_GPIO1_CONTROL_BIT20 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_GPIO2_CONTROL ( \
|
||||
CONFIG_AXP192_GPIO2_CONTROL_BIT20 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_GPIO43_FUNCTION_CONTROL ( \
|
||||
CONFIG_AXP192_GPIO43_FUNCTION_CONTROL_BIT7 | \
|
||||
CONFIG_AXP192_GPIO43_FUNCTION_CONTROL_BIT32 | \
|
||||
CONFIG_AXP192_GPIO43_FUNCTION_CONTROL_BIT10 \
|
||||
)
|
||||
|
||||
#define CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE ( \
|
||||
CONFIG_AXP192_GPIO0_LDOIO0_VOLTAGE_BIT74 \
|
||||
)
|
||||
|
||||
#endif /* AXP192_INCLUDE_SDKCONFIG_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,108 +0,0 @@
|
||||
#include "Core2Power.h"
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include "axp192/axp192.h"
|
||||
|
||||
constexpr auto TAG = "Core2Power";
|
||||
|
||||
extern axp192_t axpDevice;
|
||||
|
||||
bool Core2Power::supportsMetric(MetricType type) const {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case BatteryVoltage:
|
||||
case ChargeLevel:
|
||||
case IsCharging:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Core2Power::getMetric(MetricType type, MetricData& data) {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case BatteryVoltage: {
|
||||
float voltage;
|
||||
if (axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &voltage) == ESP_OK) {
|
||||
data.valueAsUint32 = (uint32_t)std::max((voltage * 1000.f), 0.0f);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case ChargeLevel: {
|
||||
float vbat, charge_current;
|
||||
if (
|
||||
axp192_read(&axpDevice, AXP192_BATTERY_VOLTAGE, &vbat) == ESP_OK &&
|
||||
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK
|
||||
) {
|
||||
float max_voltage = 4.20f;
|
||||
float min_voltage = 2.69f; // From M5Unified
|
||||
float voltage_correction = (charge_current > 0.01f) ? -0.1f : 0.f; // Roughly 0.1V drop when ccharging
|
||||
float corrected_voltage = vbat + voltage_correction;
|
||||
if (corrected_voltage > 2.69f) {
|
||||
float charge_factor = (corrected_voltage - min_voltage) / (max_voltage - min_voltage);
|
||||
data.valueAsUint8 = (uint8_t)(charge_factor * 100.f);
|
||||
} else {
|
||||
data.valueAsUint8 = 0;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case IsCharging: {
|
||||
float charge_current;
|
||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK) {
|
||||
data.valueAsBool = charge_current > 0.001f;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
case Current: {
|
||||
float charge_current, discharge_current;
|
||||
if (
|
||||
axp192_read(&axpDevice, AXP192_CHARGE_CURRENT, &charge_current) == ESP_OK &&
|
||||
axp192_read(&axpDevice, AXP192_DISCHARGE_CURRENT, &discharge_current) == ESP_OK
|
||||
) {
|
||||
if (charge_current > 0.0f) {
|
||||
data.valueAsInt32 = (int32_t) (charge_current * 1000.0f);
|
||||
} else {
|
||||
data.valueAsInt32 = -(int32_t) (discharge_current * 1000.0f);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Core2Power::isAllowedToCharge() const {
|
||||
uint8_t buffer;
|
||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) {
|
||||
return buffer & 0x80;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Core2Power::setAllowedToCharge(bool canCharge) {
|
||||
uint8_t buffer;
|
||||
if (axp192_read(&axpDevice, AXP192_CHARGE_CONTROL_1, &buffer) == ESP_OK) {
|
||||
buffer = (buffer & 0x7F) + (canCharge ? 0x80 : 0x00);
|
||||
axp192_write(&axpDevice, AXP192_CHARGE_CONTROL_1, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<PowerDevice> power;
|
||||
|
||||
std::shared_ptr<PowerDevice> createPower() {
|
||||
if (power == nullptr) {
|
||||
power = std::make_shared<Core2Power>();
|
||||
}
|
||||
return power;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/power/PowerDevice.h"
|
||||
#include <memory>
|
||||
|
||||
using tt::hal::power::PowerDevice;
|
||||
|
||||
class Core2Power : public PowerDevice {
|
||||
|
||||
public:
|
||||
|
||||
Core2Power() = default;
|
||||
~Core2Power() override = default;
|
||||
|
||||
std::string getName() const final { return "AXP192 Power"; }
|
||||
std::string getDescription() const final { return "Power management via I2C"; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
bool supportsChargeControl() const override { return true; }
|
||||
bool isAllowedToCharge() const override;
|
||||
void setAllowedToCharge(bool canCharge) override;
|
||||
};
|
||||
|
||||
std::shared_ptr<PowerDevice> createPower();
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <Axp192.h>
|
||||
|
||||
static std::shared_ptr<Axp192> axp192 = nullptr;
|
||||
|
||||
std::shared_ptr<Axp192> createAxp192() {
|
||||
assert(axp192 == nullptr);
|
||||
auto configuration = std::make_unique<Axp192::Configuration>(I2C_NUM_0);
|
||||
axp192 = std::make_shared<Axp192>(std::move(configuration));
|
||||
return axp192;
|
||||
}
|
||||
|
||||
std::shared_ptr<Axp192> getAxp192() {
|
||||
assert(axp192 != nullptr);
|
||||
return axp192;
|
||||
}
|
||||
|
||||
bool initAxp() {
|
||||
const auto axp = createAxp192();
|
||||
return axp->init([](auto* driver) {
|
||||
axp192_ioctl(driver, AXP192_LDO2_SET_VOLTAGE, 3300); // LCD + SD
|
||||
axp192_ioctl(driver, AXP192_LDO3_SET_VOLTAGE, 0); // VIB_MOTOR STOP
|
||||
axp192_ioctl(driver, AXP192_DCDC3_SET_VOLTAGE, 3300);
|
||||
|
||||
axp192_ioctl(driver, AXP192_LDO2_ENABLE);
|
||||
axp192_ioctl(driver, AXP192_LDO3_DISABLE);
|
||||
axp192_ioctl(driver, AXP192_DCDC3_ENABLE);
|
||||
|
||||
axp192_write(driver, AXP192_PWM1_DUTY_CYCLE_2, 255); // PWM 255 (LED OFF)
|
||||
axp192_write(driver, AXP192_GPIO1_CONTROL, 0x02); // GPIO1 PWM
|
||||
|
||||
// TODO: We could charge at 390mA according to the M5Unified code, but the AXP driver in M5Unified limits to 132mA, so it's unclear what the AXP supports.
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Axp192.h>
|
||||
|
||||
bool initAxp();
|
||||
|
||||
// Must call initAxp() first before this returns a non-nullptr response
|
||||
std::shared_ptr<Axp192> getAxp192();
|
||||
|
||||
Reference in New Issue
Block a user