30#include "../../../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_PMIC_AXP517
39bool readPmicRegisters(
AXP517Core &core, uint8_t firstReg, uint8_t *buffer,
42 for (
size_t i = 0;
i < length; ++
i) {
43 int value = core.
readReg(
static_cast<uint8_t
>(firstReg +
i));
44 if (value < 0)
return false;
45 buffer[
i] =
static_cast<uint8_t
>(value);
50bool writePmicRegisters(
AXP517Core &core, uint8_t firstReg,
51 const uint8_t *buffer,
size_t length)
53 for (
size_t i = 0;
i < length; ++
i) {
54 if (core.
writeReg(
static_cast<uint8_t
>(firstReg +
i), buffer[
i]) < 0) {
68 mask &= ~IRQ_RESERVED_MASK;
76 uint64_t current = (
static_cast<uint64_t
>(buffer[0]) << 24) |
77 (
static_cast<uint64_t
>(buffer[1]) << 16) |
78 (
static_cast<uint64_t
>(buffer[2]) << 8) |
79 (
static_cast<uint64_t
>(buffer[3]));
80 current &= (~IRQ_RESERVED_MASK);
82 buffer[0] =
static_cast<uint8_t
>((current >> 24) & 0xFF);
83 buffer[1] =
static_cast<uint8_t
>((current >> 16) & 0xFF);
84 buffer[2] =
static_cast<uint8_t
>((current >> 8) & 0xFF);
85 buffer[3] =
static_cast<uint8_t
>(current & 0xFF);
94 mask &= ~IRQ_RESERVED_MASK;
101 uint64_t current = (
static_cast<uint64_t
>(buffer[0]) << 24) |
102 (
static_cast<uint64_t
>(buffer[1]) << 16) |
103 (
static_cast<uint64_t
>(buffer[2]) << 8) |
104 (
static_cast<uint64_t
>(buffer[3]));
106 current &= (~IRQ_RESERVED_MASK);
108 buffer[0] =
static_cast<uint8_t
>((current >> 24) & 0xFF);
109 buffer[1] =
static_cast<uint8_t
>((current >> 16) & 0xFF);
110 buffer[2] =
static_cast<uint8_t
>((current >> 8) & 0xFF);
111 buffer[3] =
static_cast<uint8_t
>(current & 0xFF);
121 int pdAlertL = _core.
readReg(axp517::tcpc::PD_ALERTL);
122 int pdAlertH = _core.
readReg(axp517::tcpc::PD_ALERTH);
123 if (pdAlertL < 0 || pdAlertH < 0) {
133 uint16_t pdAlert =
static_cast<uint16_t
>(pdAlertL) |
134 (
static_cast<uint16_t
>(pdAlertH) << 8);
135 uint64_t mask = (
static_cast<uint64_t
>(pdAlert) << 32) |
136 (
static_cast<uint64_t
>(buffer[0]) << 24) |
137 (
static_cast<uint64_t
>(buffer[1]) << 16) |
138 (
static_cast<uint64_t
>(buffer[2]) << 8) |
139 (
static_cast<uint64_t
>(buffer[3]));
140 mask &= (~IRQ_RESERVED_MASK);
141 if (clear && mask != 0) {
149 uint8_t buffer[4] = {0xFF, 0xFF, 0xFF, 0xFF};
150 int fault = _core.
readReg(axp517::tcpc::FAULT_STATUS);
155 uint8_t faultStatus =
static_cast<uint8_t
>(fault);
156 if (faultStatus && _core.
writeReg(axp517::tcpc::FAULT_STATUS, faultStatus) < 0) {
160 if (_core.
writeReg(axp517::tcpc::PD_ALERTL, 0xFF) < 0 ||
161 _core.
writeReg(axp517::tcpc::PD_ALERTH, 0xFF) < 0) {
#define SENSORLIB_LOG_E(...)
AXP517 low-level core driver.
bool enable(uint64_t mask) override
Enable one or more PMIC IRQ sources.
bool disable(uint64_t mask) override
Disable one or more PMIC IRQ sources.
uint64_t readStatus(bool clear=true) override
Read the current IRQ status.
AXP517Irq(AXP517Core &core)
Construct an AXP517 IRQ helper.
bool clearStatus() override
Clear all pending PMIC IRQ and TCPC alert status bits.
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
static constexpr uint8_t ENABLE0
IRQ Enable 0.
static constexpr uint8_t STATUS0
IRQ Status 0.