Implemented new driver projects (#210)
Moved drivers from the `Boards` projects to `Drivers` folder: - BQ24295 - AW9523 - AXP2101 The I2C drivers are theoretically cross-platform, but for now they are only built for ESP32.
This commit is contained in:
committed by
GitHub
parent
c74006f8b6
commit
5b375c21bb
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source" "Source/hal" "Source/Axp2101" "Source/Aw9523"
|
||||
SRC_DIRS "Source" "Source/hal"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 ILI934x esp_lcd_touch_ft5x06 driver vfs fatfs
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 ILI934x AXP2101 AW9523 esp_lcd_touch_ft5x06 driver vfs fatfs
|
||||
)
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "Aw9523.h"
|
||||
|
||||
#define AW9523_REGISTER_P0 0x02
|
||||
#define AW9523_REGISTER_P1 0x03
|
||||
|
||||
bool Aw9523::readP0(uint8_t& output) const {
|
||||
return readRegister8(AW9523_REGISTER_P0, output);
|
||||
}
|
||||
|
||||
bool Aw9523::readP1(uint8_t& output) const {
|
||||
return readRegister8(AW9523_REGISTER_P1, output);
|
||||
}
|
||||
|
||||
bool Aw9523::writeP0(uint8_t value) const {
|
||||
return writeRegister8(AW9523_REGISTER_P0, value);
|
||||
}
|
||||
|
||||
bool Aw9523::writeP1(uint8_t value) const {
|
||||
return writeRegister8(AW9523_REGISTER_P1, value);
|
||||
}
|
||||
|
||||
bool Aw9523::bitOnP1(uint8_t bitmask) const {
|
||||
return bitOn(AW9523_REGISTER_P1, bitmask);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/i2c/I2cDevice.h>
|
||||
|
||||
#define AW9523_ADDRESS 0x58
|
||||
|
||||
class Aw9523 : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
public:
|
||||
|
||||
explicit Aw9523(i2c_port_t port) : I2cDevice(port, AW9523_ADDRESS) {}
|
||||
|
||||
std::string getName() const final { return "AW9523"; }
|
||||
std::string getDescription() const final { return "GPIO expander with LED driver and I2C interface."; }
|
||||
|
||||
bool readP0(uint8_t& output) const;
|
||||
bool readP1(uint8_t& output) const;
|
||||
|
||||
bool writeP0(uint8_t value) const;
|
||||
bool writeP1(uint8_t value) const;
|
||||
|
||||
bool bitOnP1(uint8_t bitmask) const;
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
#include "Axp2101.h"
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
bool Axp2101::getBatteryVoltage(float& vbatMillis) const {
|
||||
return readRegister14(0x34, vbatMillis);
|
||||
}
|
||||
|
||||
bool Axp2101::getChargeStatus(ChargeStatus& status) const {
|
||||
uint8_t value;
|
||||
if (readRegister8(0x01, value)) {
|
||||
value = (value >> 5) & 0b11;
|
||||
status = (value == 1) ? CHARGE_STATUS_CHARGING : ((value == 2) ? CHARGE_STATUS_DISCHARGING : CHARGE_STATUS_STANDBY);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::isChargingEnabled(bool& enabled) const {
|
||||
uint8_t value;
|
||||
if (readRegister8(0x18, value)) {
|
||||
enabled = value & 0b10;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::setChargingEnabled(bool enabled) const {
|
||||
uint8_t value;
|
||||
if (readRegister8(0x18, value)) {
|
||||
return writeRegister8(0x18, (value & 0xFD) | (enabled << 1));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::isVBus() const {
|
||||
uint8_t value;
|
||||
return readRegister8(0x00, value) && (value & 0x20);
|
||||
}
|
||||
|
||||
bool Axp2101::getVBusVoltage(float& out) const {
|
||||
if (!isVBus()) {
|
||||
return false;
|
||||
} else {
|
||||
float vbus;
|
||||
if (readRegister14(0x38, vbus) && vbus < 16375) {
|
||||
out = vbus / 1000.0f;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Axp2101::setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const {
|
||||
return tt::hal::i2c::masterWriteRegisterArray(port, address, bytePairs, bytePairsSize, DEFAULT_TIMEOUT);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/i2c/I2cDevice.h>
|
||||
|
||||
#define AXP2101_ADDRESS 0x34
|
||||
|
||||
/**
|
||||
* References:
|
||||
* - https://github.com/m5stack/M5Unified/blob/master/src/utility/AXP2101_Class.cpp
|
||||
* - http://file.whycan.com/files/members/6736/AXP2101_Datasheet_V1.0_en_3832.pdf
|
||||
*/
|
||||
class Axp2101 final : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
public:
|
||||
|
||||
enum ChargeStatus {
|
||||
CHARGE_STATUS_CHARGING = 0b01,
|
||||
CHARGE_STATUS_DISCHARGING = 0b10,
|
||||
CHARGE_STATUS_STANDBY = 0b00
|
||||
};
|
||||
|
||||
explicit Axp2101(i2c_port_t port) : I2cDevice(port, AXP2101_ADDRESS) {}
|
||||
|
||||
std::string getName() const final { return "AXP2101"; }
|
||||
std::string getDescription() const final { return "Power management with I2C interface."; }
|
||||
|
||||
bool setRegisters(uint8_t* bytePairs, size_t bytePairsSize) const;
|
||||
|
||||
bool getBatteryVoltage(float& vbatMillis) const;
|
||||
bool getChargeStatus(ChargeStatus& status) const;
|
||||
bool isChargingEnabled(bool& enabled) const;
|
||||
bool setChargingEnabled(bool enabled) const;
|
||||
|
||||
bool isVBus() const;
|
||||
bool getVBusVoltage(float& out) const;
|
||||
};
|
||||
@@ -1,9 +1,8 @@
|
||||
#include "Axp2101/Axp2101.h"
|
||||
#include "Aw9523/Aw9523.h"
|
||||
#include <Axp2101.h>
|
||||
#include <Aw9523.h>
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/kernel/Kernel.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#define TAG "cores3"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Axp2101/Axp2101.h"
|
||||
|
||||
#include <Axp2101.h>
|
||||
#include <Tactility/hal/Power.h>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source" "Source/hal" "Source/hx8357" "Source/bq24295"
|
||||
SRC_DIRS "Source" "Source/hal" "Source/hx8357"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_io_expander esp_io_expander_tca95xx_16bit esp_lcd_touch esp_lcd_touch_xpt2046
|
||||
REQUIRES Tactility esp_lvgl_port esp_io_expander esp_io_expander_tca95xx_16bit BQ24295 esp_lcd_touch esp_lcd_touch_xpt2046
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "bq24295/Bq24295.h"
|
||||
#include <Bq24295.h>
|
||||
#include <Tactility/Thread.h>
|
||||
#include <esp_io_expander_tca95xx_16bit.h>
|
||||
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
#include "Bq24295.h"
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#define TAG "bq24295"
|
||||
|
||||
/** Reference:
|
||||
* https://www.ti.com/lit/ds/symlink/bq24295.pdf
|
||||
* https://gitlab.com/hamishcunningham/unphonelibrary/-/blob/main/unPhone.h?ref_type=heads
|
||||
*/
|
||||
namespace registers {
|
||||
static const uint8_t CHARGE_TERMINATION = 0x05U; // Datasheet page 35: Charge end/timer cntrl
|
||||
static const uint8_t OPERATION_CONTROL = 0x07U; // Datasheet page 37: Misc operation control
|
||||
static const uint8_t STATUS = 0x08U; // Datasheet page 38: System status
|
||||
static const uint8_t VERSION = 0x0AU; // Datasheet page 38: Vendor/part/revision status
|
||||
} // namespace registers
|
||||
|
||||
bool Bq24295::readChargeTermination(uint8_t& out) const {
|
||||
return readRegister8(registers::CHARGE_TERMINATION, out);
|
||||
}
|
||||
|
||||
// region Watchdog
|
||||
bool Bq24295::getWatchDogTimer(WatchDogTimer& out) const {
|
||||
uint8_t value;
|
||||
if (readChargeTermination(value)) {
|
||||
uint8_t relevant_bits = value & (BIT(4) | BIT(5));
|
||||
switch (relevant_bits) {
|
||||
case 0b000000:
|
||||
out = WatchDogTimer::Disabled;
|
||||
return true;
|
||||
case 0b010000:
|
||||
out = WatchDogTimer::Enabled40s;
|
||||
return true;
|
||||
case 0b100000:
|
||||
out = WatchDogTimer::Enabled80s;
|
||||
return true;
|
||||
case 0b110000:
|
||||
out = WatchDogTimer::Enabled160s;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Bq24295::setWatchDogTimer(WatchDogTimer in) const {
|
||||
uint8_t value;
|
||||
if (readChargeTermination(value)) {
|
||||
uint8_t bits_to_set = 0b00110000 & static_cast<uint8_t>(in);
|
||||
uint8_t value_cleared = value & 0b11001111;
|
||||
uint8_t to_set = bits_to_set & value_cleared;
|
||||
TT_LOG_I(TAG, "WatchDogTimer: %02x -> %02x", value, to_set);
|
||||
return writeRegister8(registers::CHARGE_TERMINATION, to_set);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// endregoin
|
||||
|
||||
// region Operation Control (REG07)
|
||||
|
||||
bool Bq24295::setBatFetOn(bool on) const {
|
||||
if (on) {
|
||||
// bit 5 low means bat fet is on
|
||||
return bitOff(registers::OPERATION_CONTROL, BIT(5));
|
||||
} else {
|
||||
// bit 5 high means bat fet is off
|
||||
return bitOn(registers::OPERATION_CONTROL, BIT(5));
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region Other
|
||||
|
||||
bool Bq24295::getStatus(uint8_t& value) const {
|
||||
return readRegister8(registers::STATUS, value);
|
||||
}
|
||||
|
||||
bool Bq24295::isUsbPowerConnected() const {
|
||||
uint8_t status;
|
||||
if (getStatus(status)) {
|
||||
return (status & BIT(2)) != 0U;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Bq24295::getVersion(uint8_t& value) const {
|
||||
return readRegister8(registers::VERSION, value);
|
||||
}
|
||||
|
||||
void Bq24295::printInfo() const {
|
||||
uint8_t version, status, charge_termination;
|
||||
if (getStatus(status) && getVersion(version) && readChargeTermination(charge_termination)) {
|
||||
TT_LOG_I(TAG, "Version %d, status %02x, charge termination %02x", version, status, charge_termination);
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Failed to retrieve version and/or status");
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
@@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/i2c/I2cDevice.h>
|
||||
|
||||
#define BQ24295_ADDRESS 0x6BU
|
||||
|
||||
class Bq24295 final : public tt::hal::i2c::I2cDevice {
|
||||
|
||||
private:
|
||||
|
||||
bool readChargeTermination(uint8_t& out) const;
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const final { return "BQ24295"; }
|
||||
|
||||
std::string getDescription() const final { return "I2C-controlled single cell USB charger"; }
|
||||
|
||||
enum class WatchDogTimer {
|
||||
Disabled = 0b000000,
|
||||
Enabled40s = 0b010000,
|
||||
Enabled80s = 0b100000,
|
||||
Enabled160s = 0b110000
|
||||
};
|
||||
|
||||
explicit Bq24295(i2c_port_t port) : I2cDevice(port, BQ24295_ADDRESS) {}
|
||||
|
||||
bool getWatchDogTimer(WatchDogTimer& out) const;
|
||||
bool setWatchDogTimer(WatchDogTimer in) const;
|
||||
|
||||
bool isUsbPowerConnected() const;
|
||||
|
||||
bool setBatFetOn(bool on) const;
|
||||
|
||||
bool getStatus(uint8_t& value) const;
|
||||
bool getVersion(uint8_t& value) const;
|
||||
|
||||
void printInfo() const;
|
||||
};
|
||||
Reference in New Issue
Block a user