Slight optimization to libmaple analogRead()

What could be included in further releases, or for the forum.
Post Reply
arpruss
Posts: 98
Joined: Sat Sep 30, 2017 3:34 am

Slight optimization to libmaple analogRead()

Post by arpruss » 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);
}

victor_pv
Posts: 1746
Joined: Mon Apr 27, 2015 12:12 pm

Re: Slight optimization to libmaple analogRead()

Post by victor_pv » Thu Nov 30, 2017 4:11 pm

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?

Post Reply