Skip to content

Commit

Permalink
Updated INA226 driver (#190)
Browse files Browse the repository at this point in the history
* (First draft) Added functions for reading/writing registers and converting to real current, power, and voltage

* Removed some comments

* Added public functions to INA226.h

* Added missing #endif to INA226.h

* Fixed various issues that were preventing building
  • Loading branch information
bjackson312006 authored Nov 7, 2024
1 parent 8325863 commit e230b02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions general/include/INA226.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#ifndef INA226_H
#define INA226_H
#include <stdint.h>
#include <math.h>

// REGISTERS
#define INA226_CONFIGURATION 0x00
Expand Down Expand Up @@ -65,10 +67,12 @@ int ina226_configure(ina226_t *ina, uint8_t mode, uint8_t vshct, uint8_t vbusct,
uint8_t avg);

// Resets all registers to default values
int ina226_reset(ina226_t ina);
int ina226_reset(ina226_t *ina);

// Reads manufacturer id register
int ina226_read_manufacturer_id(ina226_t ina, uint16_t *data);
int ina226_read_manufacturer_id(ina226_t *ina, uint16_t *data);

// Reads die id
int ina226_read_die_id(ina226_t ina, uint16_t *data);
int ina226_read_die_id(ina226_t *ina, uint16_t *data);

#endif //INA226_H
6 changes: 3 additions & 3 deletions general/src/INA226.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ int ina226_configure(ina226_t *ina, uint8_t mode, uint8_t vshct, uint8_t vbusct,
}

// Resets all registers to default values
int ina226_reset(ina226_t ina)
int ina226_reset(ina226_t *ina)
{
uint16_t reset = INA226_CONFIG_RESET_MASK;
return ina226_write_reg(ina, INA226_CONFIGURATION, &reset);
}

// Reads manufacturer id register
int ina226_read_manufacturer_id(ina226_t ina, uint16_t *data)
int ina226_read_manufacturer_id(ina226_t *ina, uint16_t *data)
{
uint16_t manufacturer_id;

Expand All @@ -131,7 +131,7 @@ int ina226_read_manufacturer_id(ina226_t ina, uint16_t *data)
}

// Reads die id
int ina226_read_die_id(ina226_t ina, uint16_t *data)
int ina226_read_die_id(ina226_t *ina, uint16_t *data)
{
uint16_t die_id;

Expand Down

0 comments on commit e230b02

Please sign in to comment.