From e5c8d3668b50ffbc574890fa198d933a781092bf Mon Sep 17 00:00:00 2001 From: nwdepatie Date: Tue, 4 Jun 2024 17:16:12 -0400 Subject: [PATCH] Doing a bit of cleanup --- general/include/ADS131M04.h | 12 ++++-------- general/src/ADS131M04.c | 13 ++++++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/general/include/ADS131M04.h b/general/include/ADS131M04.h index 34b070b..3f3bac3 100644 --- a/general/include/ADS131M04.h +++ b/general/include/ADS131M04.h @@ -1,20 +1,16 @@ #ifndef ADS131M04_H #define ADS131M04_H -#include "stm32f4xx_hal.h" -#include "stm32f4xx_hal_spi.h" +#include "stm32xx_hal.h" -typedef struct -{ +typedef struct { 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_initialize(ads131_t *adc, SPI_HandleTypeDef *hspi, GPIO_TypeDef *hgpio, - uint8_t cs_pin); +void ads131m04_init(ads131_t *adc, SPI_HandleTypeDef *hspi, GPIO_TypeDef *hgpio, uint8_t cs_pin); /* Method to read values out of the ADC */ -HAL_StatusTypeDef ads131m04_read_ADC(ads131_t *adc); +HAL_StatusTypeDef ads131m04_read_adc(ads131_t *adc); diff --git a/general/src/ADS131M04.c b/general/src/ADS131M04.c index ea6953e..bd10dba 100644 --- a/general/src/ADS131M04.c +++ b/general/src/ADS131M04.c @@ -12,11 +12,11 @@ /* Private Function Prototypes*/ /* Method to abstract writing to a register, will use SPI commands under the hood */ -void ads131m04_write_reg(ads131_t *adc, uint8_t reg, uint16_t value); +static void ads131m04_write_reg(ads131_t *adc, uint8_t reg, uint16_t value); /* Method to abstract reading from a register, will use SPI commands under the hood to do */ -uint16_t ads131m04_read_reg(ads131_t *adc, uint8_t reg); +static uint16_t ads131m04_read_reg(ads131_t *adc, uint8_t reg); /* Method to abstract sending a command to SPI */ -void ads131m04_send_command(ads131_t *adc, uint16_t cmd); +static void ads131m04_send_command(ads131_t *adc, uint16_t cmd); /* Method to initialize communication over SPI and configure the ADC into Continuous Conversion Mode*/ void ads131m04_initialize(ads131_t *adc, SPI_HandleTypeDef *hspi, GPIO_TypeDef *hgpio, @@ -35,7 +35,7 @@ void ads131m04_initialize(ads131_t *adc, SPI_HandleTypeDef *hspi, GPIO_TypeDef * } /* Method to abstract writing to a register, will use SPI commands under the hood, value is MSB aligned */ -void ads131m04_write_reg(ads131_t *adc, uint8_t reg, uint16_t value) +static void ads131m04_write_reg(ads131_t *adc, uint8_t reg, uint16_t value) { // Ensure register address is within 6-bit range reg &= 0x3F; @@ -57,7 +57,7 @@ void ads131m04_write_reg(ads131_t *adc, uint8_t reg, uint16_t value) } /* Method to abstract reading from a register, will use SPI commands under the hood to do */ -uint16_t ads131m04_read_reg(ads131_t *adc, uint8_t reg) +static uint16_t ads131m04_read_reg(ads131_t *adc, uint8_t reg) { // Ensure register address is within 6-bit range reg &= 0x3F; @@ -92,8 +92,7 @@ HAL_StatusTypeDef ads131m04_read_ADC(ads131_t *adc, uint32_t *adc_values) ret = HAL_SPI_Receive(adc->hspi, data, 6 * 3, HAL_MAX_DELAY); // Process received data into ADC values - for (int i = 0; i < 4; i++) - { + for (int i = 0; i < 4; i++) { adc_values[i] = (data[(i + 1) * 3] << 16) | (data[(i + 1) * 3 + 1] << 8) | data[(i + 1) * 3 + 2]; }