Loading...
Searching...
No Matches
ltc4150.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
62#ifndef LTC4150_H
63#define LTC4150_H
64
65#include <stdint.h>
66
67#include "mutex.h"
68#include "periph/gpio.h"
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
77enum {
90};
91
99
104
120typedef struct {
130 void (*pulse)(ltc4150_dev_t *dev, ltc4150_dir_t dir, uint64_t now_usec, void *arg);
141 void (*reset)(ltc4150_dev_t *dev, uint64_t now_usec, void *arg);
143
147typedef struct {
151 gpio_t interrupt;
158 gpio_t polarity;
164 gpio_t shutdown;
182 uint16_t flags;
197
208
212typedef struct {
217 uint16_t charged;
221 uint16_t discharged;
225 uint8_t buf_charged[7];
229 uint8_t buf_discharged[7];
230 uint8_t ring_pos;
232
237
249
258
270
285int ltc4150_charge(ltc4150_dev_t *dev, uint32_t *charged, uint32_t *discharged);
286
304int ltc4150_avg_current(ltc4150_dev_t *dev, int16_t *dest);
305
324 uint32_t *charged, uint32_t *discharged);
325
339 uint32_t *charged, uint32_t *discharged,
340 uint32_t raw_charged,
341 uint32_t raw_discharged);
342#ifdef __cplusplus
343}
344#endif
345
346#endif /* LTC4150_H */
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:95
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.
@ LTC4150_CHARGE
The battery is charged.
Definition ltc4150.h:96
@ LTC4150_DISCHARGE
Charge is drawn from the battery.
Definition ltc4150.h:97
@ LTC4150_EXT_PULL_UP
External pull on the /INT and the /POL pin is present.
Definition ltc4150.h:89
@ LTC4150_POL_EXT_PULL_UP
External pull on the /POL pin is present.
Definition ltc4150.h:85
@ LTC4150_INT_EXT_PULL_UP
External pull on the /INT pin is present.
Definition ltc4150.h:81
Mutex for thread synchronization.
LTC4150 coulomb counter.
Definition ltc4150.h:201
uint32_t discharged
Definition ltc4150.h:206
uint32_t last_update_sec
Time stamp of last pulse.
Definition ltc4150.h:204
ltc4150_params_t params
Parameter of the LTC4150 coulomb counter.
Definition ltc4150.h:202
uint32_t charged
Definition ltc4150.h:205
uint32_t start_sec
Time stamp when started counting.
Definition ltc4150.h:203
Data structure used by ltc4150_last_minute.
Definition ltc4150.h:212
uint16_t discharged
Pulses in discharging direction recorded in the last minute.
Definition ltc4150.h:221
uint8_t ring_pos
Position in the ring buffer.
Definition ltc4150.h:230
uint16_t charged
Pulses in charging direction recorded in the last minute.
Definition ltc4150.h:217
uint32_t last_rotate_sec
Time stamp of the last ring "rotation".
Definition ltc4150.h:213
Parameters required to set up the LTC4150 coulomb counter.
Definition ltc4150.h:147
uint16_t pulses_per_ah
Pulse per ampere hour of charge.
Definition ltc4150.h:174
gpio_t polarity
Pin indicating (dis-)charging, labeled POL.
Definition ltc4150.h:158
const ltc4150_recorder_t ** recorders
NULL or a NULL-terminated array of data recorders
Definition ltc4150.h:187
gpio_t interrupt
Pin going LOW every time a specific charge is drawn, labeled INT.
Definition ltc4150.h:151
void ** recorder_data
NULL or an array of the user defined data for each recorder
Definition ltc4150.h:195
gpio_t shutdown
Pin to power off the LTC4150 coulomb counter, labeled SHDN.
Definition ltc4150.h:164
uint16_t flags
Configuration flags controlling if inter pull ups are required.
Definition ltc4150.h:182
Interface to allow recording of the drawn current in a user defined resolution.
Definition ltc4150.h:120