SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
542 stars 140 forks source link

ADCPowerOptions() ADC_ENABLE and ADC_DISABLE appear to be exchanged (re-open #1078) #1082

Closed andrewwatkin closed 3 months ago

andrewwatkin commented 3 months ago

2dad406 does not fix #1078

The problem is that ADC_ENABLE disables the ADC and ADC_DISABLE enables it.

To make sense, the code in wiring_analog.c around line 419 requires that ADC_ENABLE == _ADC_ENABLE_CTRL | _ADC_ENABLE_VAL

But this is not the case in Arduino.h around line 224.

  #define ADC_ENABLE        0x20
  #define ADC_DISABLE       0x30

There is also the same problem for the series-0 / series-1 code.

Sorry I am not in a position to retest at the moment - this is just inferred by code inspection.

SpenceKonde commented 3 months ago

I belive this has been corrected now with 5e3147bb

andrewwatkin commented 3 months ago

Looks functionally correct now. Thank you.

Wiring_analog.c around line 650 (series 0/1 code path) would benefit from the same changes from numeric constants to _ADCENABLE* #defines as you did in the same file around line 420 (series 2 code path)

Wiring_analog.c around line 890 is similar for the ADC1 code path

A search in this file for all three occurrences of “temp |= 1; // ADC on” shows the way.