/* ADC Set a Regular Channel Conversion Sequence. 
Define a sequence of channels to be converted as a regular group with a length from 1 to 18 channels. If this is called during conversion, the current conversion is reset and conversion begins again with the newly defined group. */
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
/* ADC Set a Regular Channel Conversion Sequence. 
Define a sequence of channels to be converted as a regular group with a length from 1 to 18 channels. If this is called during conversion, the current conversion is reset and conversion begins again with the newly defined group. */
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
{
	uint32_t reg32 = 0;
	uint8_t i = 0;
	bool stepup = false, stepdn = false;
	if (length == 0) {
		ADC_CHSELR(adc) = 0;
		return;
	}
	reg32 |= (1 << channel[0]);
	for (i = 1; i < length; i++) {
		reg32 |= (1 << channel[i]);
		stepup |= channel[i-1] < channel[i];
		stepdn |= channel[i-1] > channel[i];
	}
	if (stepup && stepdn) {
		cm3_assert_not_reached();
	}
	if (stepdn) {
		ADC_CFGR1(adc) |= ADC_CFGR1_SCANDIR;
	} else {
		ADC_CFGR1(adc) &= ~ADC_CFGR1_SCANDIR;
	}
	ADC_CHSELR(adc) = reg32;
}