Midnight Sun Firmware
Loading...
Searching...
No Matches
current_acs37800.h
1#pragma once
2
3/************************************************************************************************
4 * @file current_sense_acs37800.h
5 *
6 * @brief Header file to implement the current sensing from the ACS37800 sensor
7 *
8 * @date 2025-07-29
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14#include <stdint.h>
15
16/* Inter-component Headers */
17#include "gpio.h"
18#include "i2c.h"
19#include "status.h"
20
21/* Intra-component Headers */
22#include "current_acs37800_defs.h"
23
30typedef struct {
31 I2CPort i2c_port;
32 I2CAddress i2c_address;
33
34 // convert raw data to valid units
35 float current_per_amp;
36 float voltage_per_volt;
37 float power_per_watt;
39
46StatusCode acs37800_init(ACS37800_Storage *storage, I2CPort *i2c_port, I2CAddress *i2c_address);
47
53StatusCode acs37800_get_current(ACS37800_Storage *storage, float *out_current_amps);
54
60StatusCode acs37800_get_voltage(ACS37800_Storage *storage, float *out_voltage_mV);
61
67StatusCode acs37800_get_active_power(ACS37800_Storage *storage, float *out_power_mW);
68
74StatusCode acs37800_get_overcurrent_flag(ACS37800_Storage *storage, bool *overcurrent_flag);
75
81
87StatusCode acs37800_get_overvoltage_flag(ACS37800_Storage *storage, bool *overvoltage_flag);
88
94StatusCode acs37800_get_undervoltage_flag(ACS37800_Storage *storage, bool *undervoltage_flag);
95
102StatusCode acs37800_get_register(ACS37800_Storage *storage, ACS37800_Registers reg, uint32_t *out_raw);
103
StatusCode acs37800_get_undervoltage_flag(ACS37800_Storage *storage, bool *undervoltage_flag)
Gets if the ACS37800 unit detects under-voltage.
Definition: current_acs37800.c:184
StatusCode acs37800_get_voltage(ACS37800_Storage *storage, float *out_voltage_mV)
Gets the instantaneous voltage in volts.
Definition: current_acs37800.c:74
StatusCode acs37800_get_overcurrent_flag(ACS37800_Storage *storage, bool *overcurrent_flag)
Gets if the ACS37800 unit detects over-current (latched)
Definition: current_acs37800.c:114
StatusCode acs37800_get_current(ACS37800_Storage *storage, float *out_current_amps)
Gets the instantaneous current in amps.
Definition: current_acs37800.c:54
StatusCode acs37800_get_overvoltage_flag(ACS37800_Storage *storage, bool *overvoltage_flag)
Gets if the ACS37800 unit detects over-voltage.
Definition: current_acs37800.c:161
StatusCode acs37800_get_register(ACS37800_Storage *storage, ACS37800_Registers reg, uint32_t *out_raw)
Gets the 16 bit value from the ACS37800 volatile register.
Definition: current_acs37800.c:35
StatusCode acs37800_reset_overcurrent_flag(ACS37800_Storage *storage)
Resets the latched overcurrent fault, needs to write 1 to 0x2D register.
Definition: current_acs37800.c:137
StatusCode acs37800_get_active_power(ACS37800_Storage *storage, float *out_power_mW)
Gets the instantaneous power in milliwatts.
Definition: current_acs37800.c:94
StatusCode acs37800_init(ACS37800_Storage *storage, I2CPort *i2c_port, I2CAddress *i2c_address)
Initialize the ACS37800 driver.
Definition: current_acs37800.c:18
uint8_t I2CAddress
I2C address type.
Definition: i2c.h:34
I2CPort
I2C Port selection.
Definition: i2c.h:37
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Definition: current_acs37800.h:30