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
9#pragma once
10
63
64#include <stdint.h>
65
66#include "mutex.h"
67#include "periph/gpio.h"
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
76enum {
89};
90
98
103
119typedef struct {
129 void (*pulse)(ltc4150_dev_t *dev, ltc4150_dir_t dir, uint64_t now_usec, void *arg);
140 void (*reset)(ltc4150_dev_t *dev, uint64_t now_usec, void *arg);
142
146typedef struct {
150 gpio_t interrupt;
157 gpio_t polarity;
163 gpio_t shutdown;
181 uint16_t flags;
196
207
211typedef struct {
216 uint16_t charged;
220 uint16_t discharged;
224 uint8_t buf_charged[7];
228 uint8_t buf_discharged[7];
229 uint8_t ring_pos;
231
236
248
257
269
284int ltc4150_charge(ltc4150_dev_t *dev, uint32_t *charged, uint32_t *discharged);
285
303int ltc4150_avg_current(ltc4150_dev_t *dev, int16_t *dest);
304
323 uint32_t *charged, uint32_t *discharged);
324
338 uint32_t *charged, uint32_t *discharged,
339 uint32_t raw_charged,
340 uint32_t raw_discharged);
341#ifdef __cplusplus
342}
343#endif
344
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:94
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:102
@ LTC4150_EXT_PULL_UP
External pull on the /INT and the /POL pin is present.
Definition ltc4150.h:88
@ LTC4150_POL_EXT_PULL_UP
External pull on the /POL pin is present.
Definition ltc4150.h:84
@ LTC4150_INT_EXT_PULL_UP
External pull on the /INT pin is present.
Definition ltc4150.h:80
@ LTC4150_CHARGE
The battery is charged.
Definition ltc4150.h:95
@ LTC4150_DISCHARGE
Charge is drawn from the battery.
Definition ltc4150.h:96
Mutex for thread synchronization.
LTC4150 coulomb counter.
Definition ltc4150.h:200
uint32_t discharged
Definition ltc4150.h:205
uint32_t last_update_sec
Time stamp of last pulse.
Definition ltc4150.h:203
ltc4150_params_t params
Parameter of the LTC4150 coulomb counter.
Definition ltc4150.h:201
uint32_t charged
Definition ltc4150.h:204
uint32_t start_sec
Time stamp when started counting.
Definition ltc4150.h:202
Data structure used by ltc4150_last_minute.
Definition ltc4150.h:211
uint16_t discharged
Pulses in discharging direction recorded in the last minute.
Definition ltc4150.h:220
uint8_t ring_pos
Position in the ring buffer.
Definition ltc4150.h:229
uint16_t charged
Pulses in charging direction recorded in the last minute.
Definition ltc4150.h:216
uint32_t last_rotate_sec
Time stamp of the last ring "rotation".
Definition ltc4150.h:212
uint8_t buf_discharged[7]
As above, but in discharging direction.
Definition ltc4150.h:228
uint8_t buf_charged[7]
Ring-buffer to store charge information in 10 sec resolution.
Definition ltc4150.h:224
Parameters required to set up the LTC4150 coulomb counter.
Definition ltc4150.h:146
uint16_t pulses_per_ah
Pulse per ampere hour of charge.
Definition ltc4150.h:173
gpio_t polarity
Pin indicating (dis-)charging, labeled POL.
Definition ltc4150.h:157
const ltc4150_recorder_t ** recorders
NULL or a NULL-terminated array of data recorders
Definition ltc4150.h:186
gpio_t interrupt
Pin going LOW every time a specific charge is drawn, labeled INT.
Definition ltc4150.h:150
void ** recorder_data
NULL or an array of the user defined data for each recorder
Definition ltc4150.h:194
gpio_t shutdown
Pin to power off the LTC4150 coulomb counter, labeled SHDN.
Definition ltc4150.h:163
uint16_t flags
Configuration flags controlling if inter pull ups are required.
Definition ltc4150.h:181
Interface to allow recording of the drawn current in a user defined resolution.
Definition ltc4150.h:119
void(* reset)(ltc4150_dev_t *dev, uint64_t now_usec, void *arg)
Function to call upon driver initialization or reset.
Definition ltc4150.h:140
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:129