Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
AnalogSensor.h
Go to the documentation of this file.
1#ifndef RENSSELAERMOTORSPORT_ANALOGSENSOR_H
2#define RENSSELAERMOTORSPORT_ANALOGSENSOR_H
3
4#ifndef TEST_MODE
5// STM32 HAL includes
6#include "stm32f7xx.h"
7#include "stm32f7xx_hal.h"
8#include "stm32f7xx_hal_adc.h"
9#include "stm32f7xx_hal_dma.h"
10#include "stm32f7xx_hal_uart.h"
11#endif
12
13// Standard C includes
14#include <stdio.h>
15#include <string.h>
16#include <stdint.h>
17
18// User includes
19#include "Sensor.h"
20
21// Defines
22#define ADC_CHANNELS 16 // Total number of ADC channels
23#define UART_BUF_SIZE 100
24#define BUFFER_SIZE 1000 // Size of the circular buffer, change in the future if needed
25
26// Structures
27typedef struct {
31
32typedef struct {
33 uint16_t adc[ADC_CHANNELS]; // Array to hold all 16 ADC values
34} ADCSample;
35
36// Function declarations
37void initAnalogSensor(AnalogSensor* analogSensor, const char* name, int hz, int channel);
38void ProcessADCData(uint16_t* adc1_data, uint16_t* adc2_data, uint16_t* adc3_data);
40uint32_t getRecentSamples(ADCSample* samples, uint32_t num_samples);
42
43#ifndef TEST_MODE
44// External variable declarations
45extern ADC_HandleTypeDef hadc1, hadc2, hadc3;
46extern DMA_HandleTypeDef hdma_adc1, hdma_adc2, hdma_adc3;
47extern UART_HandleTypeDef huart2;
48#endif
49
50// ADC buffers
51extern uint16_t adc1_buffer[6];
52extern uint16_t adc2_buffer[6];
53extern uint16_t adc3_buffer[4];
54
55extern char uart_buf[UART_BUF_SIZE];
56
57#endif // RENSSELAERMOTORSPORT_ANALOGSENSOR_H
58
int getAnalogSensorData(AnalogSensor *sensor)
Retrieves analog sensor data for a specific channel.
Definition: AnalogSensor.c:193
#define ADC_CHANNELS
Definition: AnalogSensor.h:22
DMA_HandleTypeDef hdma_adc1
Definition: main.c:47
void initAnalogSensor(AnalogSensor *analogSensor, const char *name, int hz, int channel)
Initializes an analog sensor and configures the corresponding GPIO pin.
Definition: AnalogSensor.c:44
ADC_HandleTypeDef hadc1
Definition: main.c:44
void ProcessADCData(uint16_t *adc1_data, uint16_t *adc2_data, uint16_t *adc3_data)
Processes ADC data from all three ADCs and stores it in the circular buffer.
Definition: AnalogSensor.c:114
DMA_HandleTypeDef hdma_adc3
Definition: AnalogSensor.h:46
ADCSample getLatestSample(void)
Retrieves the latest ADC sample from the buffer.
Definition: AnalogSensor.c:152
uint32_t getRecentSamples(ADCSample *samples, uint32_t num_samples)
Retrieves a specified number of recent samples from the buffer.
Definition: AnalogSensor.c:173
uint16_t adc1_buffer[6]
uint16_t adc2_buffer[6]
ADC_HandleTypeDef hadc3
Definition: AnalogSensor.h:45
char uart_buf[UART_BUF_SIZE]
UART_HandleTypeDef huart2
#define UART_BUF_SIZE
Definition: AnalogSensor.h:23
uint16_t adc3_buffer[4]
ADC_HandleTypeDef hadc2
Definition: AnalogSensor.h:45
DMA_HandleTypeDef hdma_adc2
Definition: AnalogSensor.h:46
Sensor sensor
Definition: AnalogSensor.h:28
Definition: Sensor.h:14