/* Enable the selected ADC channel and configure its sample time. Please use this function if you want to be compatible with older versions of the library.  */
void ADC_RegularChannelConfig(ADC_TypeDef *adc, u32 channel, u8 rank, u32 sample_time)
/* Enable the selected ADC channel and configure its sample time. Please use this function if you want to be compatible with older versions of the library.  */
void ADC_RegularChannelConfig(ADC_TypeDef *adc, u32 channel, u8 rank, u32 sample_time)
{
    u32 tempchan;
    sample_time = sample_time & 0xF;
    tempchan = channel;
    if(tempchan > 8) {
        tempchan = tempchan & 0xF;
        tempchan = tempchan - 8;
        adc->SMPR2 &= ~(0xF << tempchan);
        adc->SMPR2 |= (sample_time << tempchan);
    }
    else {
        adc->SMPR1 &= ~(0xF << tempchan);
        adc->SMPR1 |= (sample_time << tempchan);
    }
    adc->ADCHS &= ~(1 << channel);
    adc->ADCHS |=  (1 << channel);
    if (channel & ADC_CHSR_CHT)
        ADC_TempSensorVrefintCmd(ENABLE);
    else if (channel & ADC_CHSR_CHV)
        ADC_TempSensorVrefintCmd(ENABLE);
}