Core
Loading...
Searching...
No Matches
adc.h
Go to the documentation of this file.
1
84#include <stdint.h>
85#include <stdbool.h>
86#include <stm32g4xx_hal.h>
87
88#ifndef CORE_ADC_H
89#define CORE_ADC_H
90
91#define CORE_ADC_ALLOWED_ADC1 0x0001
92#define CORE_ADC_ALLOWED_ADC2 0x0002
93#define CORE_ADC_ALLOWED_ADC3 0x0004
94#define CORE_ADC_ALLOWED_ADC4 0x0008
95#define CORE_ADC_ALLOWED_ADC5 0x0010
96#define CORE_ADC_ALLOWED_OPAMP1 0x0100
97#define CORE_ADC_ALLOWED_OPAMP2 0x0200
98#define CORE_ADC_ALLOWED_OPAMP3 0x0400
99#define CORE_ADC_ALLOWED_OPAMP4 0x0800
100#define CORE_ADC_ALLOWED_OPAMP5 0x1000
101#define CORE_ADC_ALLOWED_OPAMP6 0x2000
102#define CORE_ADC_ALLOWED_ADC_MASK 0x001f
103#define CORE_ADC_ALLOWED_OPAMP_MASK 0x3f00
104
105typedef struct core_ADC_def_s {
106 // Constant fields
107 GPIO_TypeDef *port;
108 uint32_t pin;
109 uint16_t allowed_connections;
110 uint8_t chan[5];
111 uint16_t opamp_chan;
112 // Fields edited by the program
113 ADC_TypeDef *adc;
114 OPAMP_TypeDef *opamp;
115 uint8_t adc_chan_sel;
116 uint8_t opamp_chan_sel;
118
119
128bool core_ADC_init(ADC_TypeDef *adc);
129
139bool core_ADC_setup_pin(GPIO_TypeDef *port, uint32_t pin, uint8_t opamp);
140
150bool core_ADC_read_channel(GPIO_TypeDef *port, uint32_t pin, uint16_t *result);
151
157uint16_t core_ADC_read_vrefint();
158
159#endif
bool core_ADC_read_channel(GPIO_TypeDef *port, uint32_t pin, uint16_t *result)
Read the value of an analog input as a value between 0 and 4095.
Definition adc.c:231
uint16_t core_ADC_read_vrefint()
Read the value of the internal voltage reference with respect to the VREF pin.
Definition adc.c:124
bool core_ADC_init(ADC_TypeDef *adc)
Initialize an ADC module, including its clock. Also performs calibration. GPIO ports are not initiali...
Definition adc.c:75
bool core_ADC_setup_pin(GPIO_TypeDef *port, uint32_t pin, uint8_t opamp)
Set up a pin as an analog input.
Definition adc.c:153
Definition adc.h:105