Vehicle Control Unit 0.01
This is the c library for controlling the car.
|
#include "stm32f7xx.h"
#include "stm32f7xx_hal.h"
#include "stm32f7xx_hal_adc.h"
#include "stm32f7xx_hal_dma.h"
#include "stm32f7xx_hal_uart.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "Sensor.h"
Go to the source code of this file.
Classes | |
struct | AnalogSensor |
struct | ADCSample |
Macros | |
#define | ADC_CHANNELS 16 |
#define | UART_BUF_SIZE 100 |
#define | BUFFER_SIZE 1000 |
Functions | |
void | initAnalogSensor (AnalogSensor *analogSensor, const char *name, int hz, int channel) |
Initializes an analog sensor and configures the corresponding GPIO pin. More... | |
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. More... | |
ADCSample | getLatestSample (void) |
Retrieves the latest ADC sample from the buffer. More... | |
uint32_t | getRecentSamples (ADCSample *samples, uint32_t num_samples) |
Retrieves a specified number of recent samples from the buffer. More... | |
int | getAnalogSensorData (AnalogSensor *sensor) |
Retrieves analog sensor data for a specific channel. More... | |
Variables | |
ADC_HandleTypeDef | hadc1 |
ADC_HandleTypeDef | hadc2 |
ADC_HandleTypeDef | hadc3 |
DMA_HandleTypeDef | hdma_adc1 |
DMA_HandleTypeDef | hdma_adc2 |
DMA_HandleTypeDef | hdma_adc3 |
UART_HandleTypeDef | huart2 |
uint16_t | adc1_buffer [6] |
uint16_t | adc2_buffer [6] |
uint16_t | adc3_buffer [4] |
char | uart_buf [UART_BUF_SIZE] |
#define ADC_CHANNELS 16 |
Definition at line 22 of file AnalogSensor.h.
#define BUFFER_SIZE 1000 |
Definition at line 24 of file AnalogSensor.h.
#define UART_BUF_SIZE 100 |
Definition at line 23 of file AnalogSensor.h.
int getAnalogSensorData | ( | AnalogSensor * | sensor | ) |
Retrieves analog sensor data for a specific channel.
sensor | Pointer to the AnalogSensor structure |
This function returns the latest ADC value for the channel specified in the AnalogSensor structure. If an invalid channel is specified, it returns 0.
Definition at line 193 of file AnalogSensor.c.
ADCSample getLatestSample | ( | void | ) |
Retrieves the latest ADC sample from the buffer.
If the buffer is empty, this function returns a sample with all channels set to 0.
Definition at line 152 of file AnalogSensor.c.
uint32_t getRecentSamples | ( | ADCSample * | samples, |
uint32_t | num_samples | ||
) |
Retrieves a specified number of recent samples from the buffer.
samples | Pointer to an array to store the retrieved samples |
num_samples | Number of samples to retrieve |
This function copies the most recent samples from the circular buffer to the provided array. It returns the actual number of samples copied, which may be less than requested if the buffer is not full.
Definition at line 173 of file AnalogSensor.c.
void initAnalogSensor | ( | AnalogSensor * | analogSensor, |
const char * | name, | ||
int | hz, | ||
int | channel | ||
) |
Initializes an analog sensor and configures the corresponding GPIO pin.
sensor | Pointer to the AnalogSensor structure to initialize |
name | Name of the sensor (string) |
hz | Sampling frequency in Hertz |
channel | ADC channel number for the sensor (0-16) |
This function initializes the base sensor properties, sets the ADC channel, and configures the corresponding GPIO pin based on the channel number.
Definition at line 44 of file AnalogSensor.c.
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.
adc1_data | Pointer to ADC1 data buffer (channels 0-5) |
adc2_data | Pointer to ADC2 data buffer (channels 6-11) |
adc3_data | Pointer to ADC3 data buffer (channels 12-15) |
This function combines data from all three ADCs into a single ADCSample and adds it to the circular buffer. It also sends debug information via UART.
Definition at line 114 of file AnalogSensor.c.
|
extern |
|
extern |
|
extern |
ADC_HandleTypeDef hadc2 |
Definition at line 45 of file AnalogSensor.h.
ADC_HandleTypeDef hadc3 |
Definition at line 45 of file AnalogSensor.h.
DMA_HandleTypeDef hdma_adc2 |
Definition at line 46 of file AnalogSensor.h.
DMA_HandleTypeDef hdma_adc3 |
Definition at line 46 of file AnalogSensor.h.
|
extern |
|
extern |