diff options
author | Uros Majstorovic <majstor@majstor.org> | 2025-02-16 20:17:43 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2025-02-16 20:17:43 +0100 |
commit | d979b344e5d10c8ecb075554008b707c490db672 (patch) | |
tree | 9f3561e9bc9f42a375788c8680c7eabdeb8ea42a /fw/fe310/eos/dev/batt.c | |
parent | 2e17dd17ee9777084b2f211f08c4231dd5f8b906 (diff) |
Diffstat (limited to 'fw/fe310/eos/dev/batt.c')
-rw-r--r-- | fw/fe310/eos/dev/batt.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/fw/fe310/eos/dev/batt.c b/fw/fe310/eos/dev/batt.c new file mode 100644 index 0000000..6f1eb97 --- /dev/null +++ b/fw/fe310/eos/dev/batt.c @@ -0,0 +1,54 @@ +#include <stdlib.h> +#include <stdint.h> + +#include "eos.h" +#include "soc/pwr.h" + +#include "drv/bq25895.h" + +#ifdef EOS_DEBUG +#include <stdio.h> +#endif + +int eos_batt_init(void) { + uint8_t wakeup_cause; + int rst, rv; +#ifdef EOS_DEBUG + uint8_t data; + int i; +#endif + + rv = EOS_OK; + + wakeup_cause = eos_pwr_wakeup_cause(); + rst = (wakeup_cause == EOS_PWR_WAKE_RST); + if (rst) { + // if (!rv) rv = bq25895_reg_write(0x14, 0x80); // reset + // if (!rv) rv = bq25895_reg_write(0x14, 0x00); + if (!rv) rv = bq25895_reg_write(0x07, 0x8d); // disable watchdog + if (!rv) rv = bq25895_reg_write(0x03, 0x2e); // disable charging, 3.7V minimum output + } + if (rv) return rv; + +#ifdef EOS_DEBUG + printf("BQ25895:\n"); + for (i=0; i<0x15; i++) { + rv = bq25895_reg_read(i, &data); + if (!rv) printf(" REG%.2X: %.2X\n", i, data); + } +#endif + + return EOS_OK; +} + +int eos_batt_read_fault(uint8_t *fault0, uint8_t *fault1) { + int rv; + + rv = bq25895_read_fault(fault0); + if (rv) return rv; + + rv = bq25895_read_fault(fault1); + if (rv) return rv; + + return EOS_OK; +}
\ No newline at end of file |