~ruther/uni-mam-arm

uni-mam-arm/arm07/include/adc.h -rw-r--r-- 1.5 KiB
f80d4fd6 — Rutherther chore(arm07): add few image upload commands 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef ADC_H
#define ADC_H

#include <stm32f4xx.h>
#include <stdbool.h>

typedef struct {
  ADC_TypeDef* periph;
} adc_t;

typedef enum {
  ADC_EXT_REG_TIM1_CH1 = 0,
  ADC_EXT_REG_TIM1_CH2 = 1,
  ADC_EXT_REG_TIM1_CH3 = 2,
  ADC_EXT_REG_TIM2_CH2 = 3,
  ADC_EXT_REG_TIM2_CH3 = 4,
  ADC_EXT_REG_TIM2_CH4 = 5,
  ADC_EXT_REG_TIM2_TRGO = 6,
  ADC_EXT_REG_TIM3_CH1 = 7,
  ADC_EXT_REG_TIM3_TRGO = 8,
  ADC_EXT_REG_TIM4_CH4 = 9,
  ADC_EXT_REG_TIM4_CH1 = 10,
  ADC_EXT_REG_TIM5_CH2 = 11,
  ADC_EXT_REG_TIM5_CH3 = 12,
  ADC_EXT_REG_EXTI_LINE_11 = 15,
} adc_external_trigger_source_regular_t;

typedef enum {
  ADC_EXT_DISABLED = 0,
  ADC_EXT_RISING_EDGE = 1,
  ADC_EXT_FALLING_EDGE = 2,
  ADC_EXT_BOTH_EDGES = 2,
} adc_external_trigger_regular_t;

typedef enum {
  ADC_RES_6BIT = 3,
  ADC_RES_8BIT = 2,
  ADC_RES_10BIT = 1,
  ADC_RES_12BIT = 0,
} adc_resolution_t;

typedef enum {
  ADC_ALIGN_LEFT = 1,
  ADC_ALIGN_RIGHT = 0,
} adc_alignment_t;

void adc_init(adc_t* adc, ADC_TypeDef* periph);
void adc_configure(adc_t* adc, adc_resolution_t resolution, adc_alignment_t alignment, bool continuous);
void adc_enable(adc_t* adc, bool enable);

void adc_sequence(adc_t* adc, uint8_t count);
void adc_select(adc_t* adc, uint8_t conversion_idx, uint8_t channel);

void adc_external_trigger(adc_t* adc, adc_external_trigger_regular_t config, adc_external_trigger_source_regular_t source);

/* void adc_start_capture(adc_t* adc); */

bool adc_is_captured(adc_t* adc);
uint32_t adc_captured_value(adc_t* adc);
uint32_t adc_convert_voltage(uint32_t capture, uint32_t min, uint32_t max);

#endif // ADC_H
Do not follow this link