Loading...
Searching...
No Matches
ltc4150.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Otto-von-Guericke-Universität Magdeburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
60
61#include <stdint.h>
62
63#include "mutex.h"
64#include "periph/gpio.h"
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
73enum {
86};
87
95
100
116typedef struct {
126 void (*pulse)(ltc4150_dev_t *dev, ltc4150_dir_t dir, uint64_t now_usec, void *arg);
137 void (*reset)(ltc4150_dev_t *dev, uint64_t now_usec, void *arg);
139
143typedef struct {
147 gpio_t interrupt;
154 gpio_t polarity;
160 gpio_t shutdown;
178 uint16_t flags;
193
204
208typedef struct {
213 uint16_t charged;
217 uint16_t discharged;
221 uint8_t buf_charged[7];
225 uint8_t buf_discharged[7];
226 uint8_t ring_pos;
228
233
245
254
266
281int ltc4150_charge(ltc4150_dev_t *dev, uint32_t *charged, uint32_t *discharged);
282
300int ltc4150_avg_current(ltc4150_dev_t *dev, int16_t *dest);
301
320 uint32_t *charged, uint32_t *discharged);
321
335 uint32_t *charged, uint32_t *discharged,
336 uint32_t raw_charged,
337 uint32_t raw_discharged);
338#ifdef __cplusplus
339}
340#endif
341
Low-level GPIO peripheral driver interface definitions.
int ltc4150_reset_counters(ltc4150_dev_t *dev)
Clear current counters of the given LTC4150 device.
const ltc4150_recorder_t ltc4150_last_minute
Records the charge transferred within the last minute using.
int ltc4150_shutdown(ltc4150_dev_t *dev)
Disable the interrupt handler and turn the chip off.
int ltc4150_last_minute_charge(ltc4150_dev_t *dev, ltc4150_last_minute_data_t *data, uint32_t *charged, uint32_t *discharged)
Get the measured charge in the last minute.
int ltc4150_init(ltc4150_dev_t *dev, const ltc4150_params_t *params)
Initialize the LTC4150 driver.
int ltc4150_charge(ltc4150_dev_t *dev, uint32_t *charged, uint32_t *discharged)
Get the measured charge since boot or last reset in millicoulomb.
int ltc4150_avg_current(ltc4150_dev_t *dev, int16_t *dest)
Get the average current drawn in E-01 milliampere.
ltc4150_dir_t
Enumeration of directions in which the charge can be transferred.
Definition ltc4150.h:91
void ltc4150_pulses2c(const ltc4150_dev_t *dev, uint32_t *charged, uint32_t *discharged, uint32_t raw_charged, uint32_t raw_discharged)
Convert the raw data (# pulses) acquired by the LTC4150 device to charge information in millicoulomb.
struct ltc4150_dev ltc4150_dev_t
LTC4150 coulomb counter.
Definition ltc4150.h:99
@ LTC4150_EXT_PULL_UP
External pull on the /INT and the /POL pin is present.
Definition ltc4150.h:85
@ LTC4150_POL_EXT_PULL_UP
External pull on the /POL pin is present.
Definition ltc4150.h:81
@ LTC4150_INT_EXT_PULL_UP
External pull on the /INT pin is present.
Definition ltc4150.h:77
@ LTC4150_CHARGE
The battery is charged.
Definition ltc4150.h:92
@ LTC4150_DISCHARGE
Charge is drawn from the battery.
Definition ltc4150.h:93
Mutex for thread synchronization.
LTC4150 coulomb counter.
Definition ltc4150.h:197
uint32_t discharged
Definition ltc4150.h:202
uint32_t last_update_sec
Time stamp of last pulse.
Definition ltc4150.h:200
ltc4150_params_t params
Parameter of the LTC4150 coulomb counter.
Definition ltc4150.h:198
uint32_t charged
Definition ltc4150.h:201
uint32_t start_sec
Time stamp when started counting.
Definition ltc4150.h:199
Data structure used by ltc4150_last_minute.
Definition ltc4150.h:208
uint16_t discharged
Pulses in discharging direction recorded in the last minute.
Definition ltc4150.h:217
uint8_t ring_pos
Position in the ring buffer.
Definition ltc4150.h:226
uint16_t charged
Pulses in charging direction recorded in the last minute.
Definition ltc4150.h:213
uint32_t last_rotate_sec
Time stamp of the last ring "rotation".
Definition ltc4150.h:209
uint8_t buf_discharged[7]
As above, but in discharging direction.
Definition ltc4150.h:225
uint8_t buf_charged[7]
Ring-buffer to store charge information in 10 sec resolution.
Definition ltc4150.h:221
Parameters required to set up the LTC4150 coulomb counter.
Definition ltc4150.h:143
uint16_t pulses_per_ah
Pulse per ampere hour of charge.
Definition ltc4150.h:170
gpio_t polarity
Pin indicating (dis-)charging, labeled POL.
Definition ltc4150.h:154
const ltc4150_recorder_t ** recorders
NULL or a NULL-terminated array of data recorders
Definition ltc4150.h:183
gpio_t interrupt
Pin going LOW every time a specific charge is drawn, labeled INT.
Definition ltc4150.h:147
void ** recorder_data
NULL or an array of the user defined data for each recorder
Definition ltc4150.h:191
gpio_t shutdown
Pin to power off the LTC4150 coulomb counter, labeled SHDN.
Definition ltc4150.h:160
uint16_t flags
Configuration flags controlling if inter pull ups are required.
Definition ltc4150.h:178
Interface to allow recording of the drawn current in a user defined resolution.
Definition ltc4150.h:116
void(* reset)(ltc4150_dev_t *dev, uint64_t now_usec, void *arg)
Function to call upon driver initialization or reset.
Definition ltc4150.h:137
void(* pulse)(ltc4150_dev_t *dev, ltc4150_dir_t dir, uint64_t now_usec, void *arg)
Function to call on every pulse received from the LTC4150.
Definition ltc4150.h:126