Core
Loading...
Searching...
No Matches
adc.h
1#include <stdint.h>
2#include <stdbool.h>
3#include <stm32g4xx_hal.h>
4
5#ifndef CORE_ADC_H
6#define CORE_ADC_H
7
8#define CORE_ADC_ALLOWED_ADC1 0x0001
9#define CORE_ADC_ALLOWED_ADC2 0x0002
10#define CORE_ADC_ALLOWED_ADC3 0x0004
11#define CORE_ADC_ALLOWED_ADC4 0x0008
12#define CORE_ADC_ALLOWED_ADC5 0x0010
13#define CORE_ADC_ALLOWED_OPAMP1 0x0100
14#define CORE_ADC_ALLOWED_OPAMP2 0x0200
15#define CORE_ADC_ALLOWED_OPAMP3 0x0400
16#define CORE_ADC_ALLOWED_OPAMP4 0x0800
17#define CORE_ADC_ALLOWED_OPAMP5 0x1000
18#define CORE_ADC_ALLOWED_OPAMP6 0x2000
19#define CORE_ADC_ALLOWED_ADC_MASK 0x001f
20#define CORE_ADC_ALLOWED_OPAMP_MASK 0x3f00
21
22typedef struct core_ADC_def_s {
23 // Constant fields
24 GPIO_TypeDef *port;
25 uint32_t pin;
26 uint16_t allowed_connections;
27 uint8_t chan[5];
28 uint16_t opamp_chan;
29 // Fields edited by the program
30 ADC_TypeDef *adc;
31 OPAMP_TypeDef *opamp;
32 uint8_t adc_chan_sel;
33 uint8_t opamp_chan_sel;
35
36
37bool core_ADC_init(ADC_TypeDef *adc);
38bool core_ADC_setup_pin(GPIO_TypeDef *port, uint32_t pin, uint8_t opamp);
39bool core_ADC_read_channel(GPIO_TypeDef *port, uint32_t pin, uint16_t *result);
40uint16_t core_ADC_read_vrefint();
41
42#endif
Definition adc.h:22