Page 1 of 1

Slight optimization to libmaple analogRead()

Posted: Thu Nov 30, 2017 2:41 pm
by arpruss
On all the f1 boards, it seems that every analog pin works with both ADC1 and ADC2, so one could ever so slightly optimize analogRead() not to look up the ADC device in PIN_MAP[], and just use ADC1 (which is what is listed in the PIN_MAP for every f1 board):

Code: Select all

uint16 analogRead(uint8 pin) {
    const uint8_t channel = PIN_MAP[pin].adc_channel;
    if (channel == ADCx) {
        return 0;
    }

    return adc_read(&adc1, channel);
}

Re: Slight optimization to libmaple analogRead()

Posted: Thu Nov 30, 2017 4:11 pm
by victor_pv
arpruss wrote:
Thu Nov 30, 2017 2:41 pm
On all the f1 boards, it seems that every analog pin works with both ADC1 and ADC2, so one could ever so slightly optimize analogRead() not to look up the ADC device in PIN_MAP[], and just use ADC1 (which is what is listed in the PIN_MAP for every f1 board):

Code: Select all

uint16 analogRead(uint8 pin) {
    const uint8_t channel = PIN_MAP[pin].adc_channel;
    if (channel == ADCx) {
        return 0;
    }

    return adc_read(&adc1, channel);
}
Is there a measurable improvement on this?