void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[]) { uint32_t fifth6 = 0; uint32_t fourth6 = 0; uint32_t third6 = 0; uint32_t second6 = 0; uint32_t first6 = 0; uint8_t i = 0; if (length > ADC_SQR_MAX_CHANNELS_REGULAR) { return; } for (i = 1; i <= length; i++) { if (i <= 6) { first6 |= (channel[i - 1] << ((i - 1) * 5)); } if ((i > 6) & (i <= 12)) { second6 |= (channel[i - 1] << ((i - 6 - 1) * 5)); } if ((i > 12) & (i <= 18)) { third6 |= (channel[i - 1] << ((i - 12 - 1) * 5)); } if ((i > 18) & (i <= 24)) { fourth6 |= (channel[i - 1] << ((i - 18 - 1) * 5)); } if ((i > 24) & (i <= 28)) { fifth6 |= (channel[i - 1] << ((i - 24 - 1) * 5)); } } #if defined(ADC_SQR5) ADC_SQR1(adc) = fifth6 | ((length - 1) << ADC_SQR1_L_LSB); ADC_SQR2(adc) = fourth6; ADC_SQR3(adc) = third6; ADC_SQR4(adc) = second6; ADC_SQR5(adc) = first6; #else ADC_SQR1(adc) = third6 | ((length - 1) << ADC_SQR1_L_LSB); ADC_SQR2(adc) = second6; ADC_SQR3(adc) = first6; #endif }
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[]) { uint32_t reg32[5] = {0,0,0,0,0}; uint8_t i = 0; /* Maximum sequence length is 28 channels. */ if (length > 28) return; for (i = 0; i < length; i++) reg32[4 - i/6] |= (channel[i] << ((i%6)*5)); reg32[0] |= ((length -1) << ADC_SQR1_L_LSB); ADC_SQR1(adc) = reg32[0]; ADC_SQR2(adc) = reg32[1]; ADC_SQR3(adc) = reg32[2]; ADC_SQR4(adc) = reg32[3]; ADC_SQR5(adc) = reg32[4]; }