Skip to content

Commit

Permalink
Doing a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nwdepatie committed Jun 4, 2024
1 parent 045c06a commit e5c8d36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
12 changes: 4 additions & 8 deletions general/include/ADS131M04.h
Original file line number Diff line number Diff line change
@@ -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);
13 changes: 6 additions & 7 deletions general/src/ADS131M04.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit e5c8d36

Please sign in to comment.