Prusa MINI Firmware overview
adc.c File Reference
#include "adc.h"
#include "stm32f4xx_hal.h"

Macros

#define ADC_SIM_MSK   0
 

Functions

void ADC_READY (uint8_t index)
 
uint8_t ADC_SEQ2IDX (uint8_t seq)
 
void Error_Handler (void)
 This function is executed in case of error occurrence. More...
 
void adc_init_sim_vals (void)
 
uint8_t adc_chan (uint8_t idx)
 
void adc_set_mux (uint8_t chn)
 
void adc_init (void)
 
void adc_cycle (void)
 

Variables

ADC_HandleTypeDef hadc1
 
uint32_t adc_val [ADC_CHAN_CNT]
 
uint8_t adc_cnt [ADC_CHAN_CNT]
 
uint8_t adc_chn [ADC_CHAN_CNT]
 
uint8_t adc_sta = 0xff
 
int8_t adc_idx = 0
 
uint32_t adc_sim_val [ADC_CHAN_CNT]
 
uint32_t adc_sim_msk = ADC_SIM_MSK
 

Macro Definition Documentation

◆ ADC_SIM_MSK

#define ADC_SIM_MSK   0

Function Documentation

◆ ADC_READY()

void ADC_READY ( uint8_t  index)
Here is the caller graph for this function:

◆ ADC_SEQ2IDX()

uint8_t ADC_SEQ2IDX ( uint8_t  seq)
Here is the caller graph for this function:

◆ Error_Handler()

void Error_Handler ( void  )

This function is executed in case of error occurrence.

Return values
None
1057  {
1058  /* USER CODE BEGIN Error_Handler_Debug */
1059  /* User can add his own implementation to report the HAL error return state */
1060  app_error();
1061  /* USER CODE END Error_Handler_Debug */
1062 }
Here is the caller graph for this function:

◆ adc_init_sim_vals()

void adc_init_sim_vals ( void  )
97  {
98 #ifdef ADC_SIM_VAL0
100 #endif //ADC_SIM_VAL0
101 #ifdef ADC_SIM_VAL1
103 #endif //ADC_SIM_VAL1
104 #ifdef ADC_SIM_VAL2
106 #endif //ADC_SIM_VAL2
107 #ifdef ADC_SIM_VAL3
109 #endif //ADC_SIM_VAL3
110 #ifdef ADC_SIM_VAL4
112 #endif //ADC_SIM_VAL4
113 #ifdef ADC_SIM_VAL5
114  adc_sim_val[5] = ADC_SIM_VAL5;
115 #endif //ADC_SIM_VAL4
116 }
Here is the caller graph for this function:

◆ adc_chan()

uint8_t adc_chan ( uint8_t  idx)
29  {
30  uint8_t chan = 0;
31  uint16_t mask = 1;
32  while (mask) {
33  if ((mask & ADC_CHAN_MSK) && (idx-- == 0))
34  break;
35  mask <<= 1;
36  chan++;
37  }
38  return chan;
39 }
Here is the caller graph for this function:

◆ adc_set_mux()

void adc_set_mux ( uint8_t  chn)
42  {
43  ADC_ChannelConfTypeDef sConfig = { 0 };
44  sConfig.Channel = chn;
45  sConfig.Rank = 1;
47  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
48  Error_Handler();
49  }
50 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_init()

void adc_init ( void  )
53  {
54  for (int i = 0; i < ADC_CHAN_CNT; i++) {
55  adc_val[i] = 0;
56  adc_cnt[i] = 0;
57  adc_chn[i] = adc_chan(i);
58  }
59  adc_idx = 0;
60  adc_sta = 0x00;
62 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ adc_cycle()

void adc_cycle ( void  )
65  {
66  uint8_t seq;
67  uint32_t val;
68  if (adc_sta == 0xff)
69  return; //skip sampling if not initialized
70  if (adc_sta & 0x80) {
72  if ((1 << adc_idx) & adc_sim_msk)
73  val = adc_sim_val[adc_idx];
74  else
75  val = HAL_ADC_GetValue(&hadc1);
76  adc_val[adc_idx] += val;
77  if (++adc_cnt[adc_idx] >= ADC_OVRSAMPL) {
79  adc_val[adc_idx] = 0;
80  adc_cnt[adc_idx] = 0;
81  }
82  seq = (adc_sta & 0x1f) + 1;
83  if (seq >= ADC_SEQ_LEN)
84  seq = 0;
85  adc_idx = ADC_SEQ2IDX(seq);
87  adc_sta = seq;
88  } else {
89  Error_Handler();
90  }
91  } else {
93  adc_sta |= 0x80;
94  }
95 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hadc1

◆ adc_val

uint32_t adc_val[ADC_CHAN_CNT]

◆ adc_cnt

◆ adc_chn

◆ adc_sta

uint8_t adc_sta = 0xff

◆ adc_idx

int8_t adc_idx = 0

◆ adc_sim_val

uint32_t adc_sim_val[ADC_CHAN_CNT]

◆ adc_sim_msk

uint32_t adc_sim_msk = ADC_SIM_MSK
HAL_OK
Definition: stm32f4xx_hal_def.h:57
adc_init_sim_vals
void adc_init_sim_vals(void)
Definition: adc.c:97
HAL_ADC_Start
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc)
ADC_FLAG_EOC
#define ADC_FLAG_EOC
Definition: stm32f4xx_hal_adc.h:430
app_error
void app_error(void)
Definition: appmain.cpp:145
ADC_SAMPLETIME_3CYCLES
#define ADC_SAMPLETIME_3CYCLES
Definition: stm32f4xx_hal_adc.h:370
adc_sim_val
uint32_t adc_sim_val[ADC_CHAN_CNT]
Definition: adc.c:23
i
uint8_t i
Definition: screen_test_graph.c:72
ADC_CHAN_MSK
#define ADC_CHAN_MSK
Definition: config_a3ides2209_02.h:29
HAL_ADC_GetValue
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc)
ADC_ChannelConfTypeDef::Channel
uint32_t Channel
Definition: stm32f4xx_hal_adc.h:133
adc_cnt
uint8_t adc_cnt[ADC_CHAN_CNT]
Definition: adc.c:18
ADC_ChannelConfTypeDef::Rank
uint32_t Rank
Definition: stm32f4xx_hal_adc.h:135
ADC_SEQ_LEN
#define ADC_SEQ_LEN
Definition: config_a3ides2209_02.h:32
ADC_ChannelConfTypeDef
Structure definition of ADC channel for regular group.
Definition: stm32f4xx_hal_adc.h:131
adc_chan
uint8_t adc_chan(uint8_t idx)
Definition: adc.c:29
adc_val
uint32_t adc_val[ADC_CHAN_CNT]
Definition: adc.c:17
ADC_SIM_VAL1
#define ADC_SIM_VAL1
Definition: config_a3ides2209_02.h:38
ADC_ChannelConfTypeDef::SamplingTime
uint32_t SamplingTime
Definition: stm32f4xx_hal_adc.h:137
hadc1
ADC_HandleTypeDef hadc1
Definition: main.c:75
ADC_SEQ2IDX
uint8_t ADC_SEQ2IDX(uint8_t seq)
uint8_t
const uint8_t[]
Definition: 404_html.c:3
ADC_OVRSAMPL
#define ADC_OVRSAMPL
Definition: config_a3ides2209_02.h:31
ADC_SIM_VAL4
#define ADC_SIM_VAL4
Definition: config_a3ides2209_02.h:41
Error_Handler
void Error_Handler(void)
This function is executed in case of error occurrence.
Definition: main.c:1057
adc_sta
uint8_t adc_sta
Definition: adc.c:20
HAL_ADC_ConfigChannel
HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, ADC_ChannelConfTypeDef *sConfig)
adc_idx
int8_t adc_idx
Definition: adc.c:21
ADC_SIM_VAL2
#define ADC_SIM_VAL2
Definition: config_a3ides2209_02.h:39
ADC_CHAN_CNT
#define ADC_CHAN_CNT
Definition: config_a3ides2209_02.h:30
adc_set_mux
void adc_set_mux(uint8_t chn)
Definition: adc.c:42
adc_chn
uint8_t adc_chn[ADC_CHAN_CNT]
Definition: adc.c:19
adc_sim_msk
uint32_t adc_sim_msk
Definition: adc.c:24
__HAL_ADC_GET_FLAG
#define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__)
Get the selected ADC's flag status.
Definition: stm32f4xx_hal_adc.h:515
ADC_READY
void ADC_READY(uint8_t index)
ADC_SIM_VAL3
#define ADC_SIM_VAL3
Definition: config_a3ides2209_02.h:40
ADC_SIM_VAL0
#define ADC_SIM_VAL0
Definition: config_a3ides2209_02.h:37