Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Refactoring LTC4015 Ticket #167

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .github/workflows/format-check.yml

This file was deleted.

4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.vscode/
__pycache__/
*.egg-info/

*.nix
*.egg-info/
16 changes: 0 additions & 16 deletions ftdi_flash.cfg

This file was deleted.

1 change: 0 additions & 1 deletion general/.clang-format-ignore

This file was deleted.

32 changes: 20 additions & 12 deletions general/include/LTC4015.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,49 @@
//Enable Coulomb Counter Low Alert.(0xOD Bit 13)
//Enable Coulomb Counter High Alert.(0xOD Bit 12)

typedef int (*Read_Ptr)(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);

typedef int (*Write_Ptr)(uint16_t DevAddress, uint16_t MemAddress,
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);

typedef struct {
I2C_HandleTypeDef *i2cHandle;
uint16_t chargeFaults; //Stores error faults from CHGSTATE register
uint16_t qcount;
uint16_t limitAlerts;

Read_Ptr read;
Write_Ptr write;
} LTC4015_T;
dnakhooda marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Initializes the LTC4015EUHF#PBF
*
* @param dev
* @param hi2c
* @return HAL_StatusTypeDef
* @return int
*/
HAL_StatusTypeDef LTC4015_Init(LTC4015_T *dev, I2C_HandleTypeDef *i2cHandle);
int LTC4015_Init(LTC4015_T *dev, Read_Ptr read, Write_Ptr write);

/**
* @brief Reads from the LTC4015EUHF#PBF load switch
* @note always reads from both input registers
*
* @param dev
* @param i2c_handle
* @param reg
* @param data
*/
HAL_StatusTypeDef LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data);
int LTC4015_read(LTC4015_T *dev, uint16_t reg, uint16_t *data);

/**
* @brief Writes to the LTC4015EUHF#PBF load switch
*
* @param device
* @param dev
* @param reg
* @param data
* @param i2c_handle
* @return HAL_StatusTypeDef
* @return int
*/
HAL_StatusTypeDef LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data);
int LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data);

/**
* @brief Checks coulombs of charger to see if within a given range, more info on page 38-40
Expand All @@ -83,10 +91,10 @@ HAL_StatusTypeDef LTC4015_write(LTC4015_T *dev, uint16_t reg, uint16_t data);
* @param highAlert
* @param prescaler
* @param lowAlert
* @return HAL_StatusTypeDef, QCOUNT, Faulted
* @return int
*/
HAL_StatusTypeDef LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler,
uint16_t highAlert, uint16_t lowAlert);
int LTC4015_Qcounter(LTC4015_T *dev, uint16_t prescaler, uint16_t highAlert,
uint16_t lowAlert);

#ifndef MAX_NUM_LTC4015_INSTANCES
#define MAX_NUM_LTC4015_INSTANCES 1
Expand Down
8 changes: 4 additions & 4 deletions general/include/ads131m04.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "stm32xx_hal.h"

typedef struct {
SPI_HandleTypeDef *spi;
GPIO_TypeDef *gpio;
uint8_t cs_pin;
SPI_HandleTypeDef *spi;
GPIO_TypeDef *gpio;
uint8_t cs_pin;
} ads131_t;

/* Method to initialize communication over SPI and configure the ADC into
* Continuous Conversion Mode*/
void ads131m04_init(ads131_t *adc, SPI_HandleTypeDef *hspi, GPIO_TypeDef *hgpio,
uint8_t cs_pin);
uint8_t cs_pin);

/* Method to read values out of the ADC */
HAL_StatusTypeDef ads131m04_read_adc(ads131_t *adc, uint32_t *adc_values);
Expand Down
64 changes: 32 additions & 32 deletions general/include/lsm6dso.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@
#define LSM6DSO_I2C_ADDRESS 0x6A << 1 /* Shifted because datasheet said to */
// Not sure if these are all needed, also not sure if more need to be added
/* For register descriptions reference datasheet pages 47 - 98 */
#define LSM6DSO_REG_FUNC_CFG_ACCESS \
0x01 /* Enable embedded functions register */
#define LSM6DSO_REG_INTERRUPT_CTRL_1 \
0x0D /* INT1 pin control, used for interrupts */
#define LSM6DSO_REG_INTERRUPT_CTRL_2 \
0x0E /* INT2 pin control, used for interrupts */
#define LSM6DSO_REG_DEVICE_ID 0x0F /* Register for checking communication */
#define LSM6DSO_REG_FUNC_CFG_ACCESS \
0x01 /* Enable embedded functions register */
#define LSM6DSO_REG_INTERRUPT_CTRL_1 \
0x0D /* INT1 pin control, used for interrupts */
#define LSM6DSO_REG_INTERRUPT_CTRL_2 \
0x0E /* INT2 pin control, used for interrupts */
#define LSM6DSO_REG_DEVICE_ID 0x0F /* Register for checking communication */
#define LSM6DSO_REG_ACCEL_CTRL 0x10 /* Accelerometer Control Register */
#define LSM6DSO_REG_GYRO_CTRL 0x11 /* Gyroscope Control Register */
#define LSM6DSO_REG_ALL_INTERRUPT_SRC \
0x1A /* Source Register for all interupsts */
#define LSM6DSO_REG_WAKEUP_INTERRUPT_SRC \
0x1B /* Wake up interupt source register */
#define LSM6DSO_REG_GYRO_CTRL 0x11 /* Gyroscope Control Register */
#define LSM6DSO_REG_ALL_INTERRUPT_SRC \
0x1A /* Source Register for all interupsts */
#define LSM6DSO_REG_WAKEUP_INTERRUPT_SRC \
0x1B /* Wake up interupt source register */
#define LSM6DSO_REG_TAP_INTERRUPT_SRC 0x1C /* Tap Interrupt source register */
#define LSM6DSO_REG_6D_INTERRUPT_SRC \
0x1D /* 6-direction Interrupt source register */
#define LSM6DSO_REG_STATUS 0x1E /* Status register */
#define LSM6DSO_REG_GYRO_X_AXIS_L 0x22 /* Gyro pitch axis lower bits */
#define LSM6DSO_REG_GYRO_X_AXIS_H 0x23 /* Gyro pitch axis upper bits */
#define LSM6DSO_REG_GYRO_Y_AXIS_L 0x24 /* Gyro roll axis lower bits */
#define LSM6DSO_REG_GYRO_Y_AXIS_H 0x25 /* Gyro roll axis upper bits */
#define LSM6DSO_REG_GYRO_Z_AXIS_L 0x26 /* Gyro yaw axis lower bits */
#define LSM6DSO_REG_GYRO_Z_AXIS_H 0x27 /* Gyro yaw axis higher bits */
#define LSM6DSO_REG_6D_INTERRUPT_SRC \
0x1D /* 6-direction Interrupt source register */
#define LSM6DSO_REG_STATUS 0x1E /* Status register */
#define LSM6DSO_REG_GYRO_X_AXIS_L 0x22 /* Gyro pitch axis lower bits */
#define LSM6DSO_REG_GYRO_X_AXIS_H 0x23 /* Gyro pitch axis upper bits */
#define LSM6DSO_REG_GYRO_Y_AXIS_L 0x24 /* Gyro roll axis lower bits */
#define LSM6DSO_REG_GYRO_Y_AXIS_H 0x25 /* Gyro roll axis upper bits */
#define LSM6DSO_REG_GYRO_Z_AXIS_L 0x26 /* Gyro yaw axis lower bits */
#define LSM6DSO_REG_GYRO_Z_AXIS_H 0x27 /* Gyro yaw axis higher bits */
#define LSM6DSO_REG_ACCEL_X_AXIS_L 0x28 /* Accelerometer X axis lower bits */
#define LSM6DSO_REG_ACCEL_X_AXIS_H 0x29 /* Accelerometer X axis upper bits */
#define LSM6DSO_REG_ACCEL_Y_AXIS_L 0x2A /* Accelerometer Y axis lower bits */
Expand All @@ -49,26 +49,26 @@
*
*/
enum lsm6dso_axes {
LSM6DSO_X_AXIS = 0,
LSM6DSO_Y_AXIS = 1,
LSM6DSO_Z_AXIS = 2
LSM6DSO_X_AXIS = 0,
LSM6DSO_Y_AXIS = 1,
LSM6DSO_Z_AXIS = 2
};

/**
* @brief Struct containing data relevant to the LSM6DSO IMU
*
*/
typedef struct {
I2C_HandleTypeDef *i2c_handle;
I2C_HandleTypeDef *i2c_handle;

uint8_t accel_config; // TODO: We should make these cfg packed unions with
// bitfield structs
uint8_t accel_config; // TODO: We should make these cfg packed unions with
// bitfield structs

uint8_t gyro_config;
uint8_t gyro_config;

int16_t accel_data[3];
int16_t accel_data[3];

int16_t gyro_data[3];
int16_t gyro_data[3];

} lsm6dso_t;

Expand All @@ -92,7 +92,7 @@ HAL_StatusTypeDef lsm6dso_init(lsm6dso_t *imu, I2C_HandleTypeDef *i2c_handle);
* @return HAL_StatusTypeDef
*/
HAL_StatusTypeDef lsm6dso_set_accel_cfg(lsm6dso_t *imu, int8_t odr_sel,
int8_t fs_sel, int8_t lp_f2_enable);
int8_t fs_sel, int8_t lp_f2_enable);

/**
* @brief Configures the accelerometer of the LSM6DSO IMU
Expand All @@ -104,7 +104,7 @@ HAL_StatusTypeDef lsm6dso_set_accel_cfg(lsm6dso_t *imu, int8_t odr_sel,
* @return HAL_StatusTypeDef
*/
HAL_StatusTypeDef lsm6dso_set_gyro_cfg(lsm6dso_t *imu, int8_t odr_sel,
int8_t fs_sel, int8_t fs_125);
int8_t fs_sel, int8_t fs_125);

/* Data Aquisition */
/**
Expand Down
Loading
Loading