HI Paul,
good argument, here some thoughts to consider.
There are two strategies to have a robust and simple API
1) hide the number of ADC's under an analogPin() class.
- The enduser can instantiate an object for every pin she uses.
- The class internals (+helper classes) solves the distribution over the available ADC's by means of a request queue.
- Both blocking and async calls are added to the queue.
- Option to make it a priority queue (deque) so some pin will be served faster than others (additional param)
- the analogRead interrupt helps to implement the queue handling work in the background.
2) make the number of ADC's explicit and create an ADC() class
- for every ADC on the device you can have an instance (like HW serial on MEGA)
- the ADC has a method ADC.analogRead(pin) = synchronous call
- the ADC has methods ADC.start(pin), ADC.completed(), ADC.value() = async call
- the ADC has methods ADC.maxValue() --> returns 1023 for an UNO and 4095 for a 12 bit ADC
Both classes can have additional methods like
- get/set prescaler
- get/set noiseThreshold
- whatEverOneCanComeUpWith()
At the moment of writing this I prefer option 2 as this class shows exactly what is in the chip.
Furthermore it could be the base class e.g. for a fast SPI based ADC component giving
both internal and external ADC's the same base interface.
Think implementation would also be simpler and less errorprone.
my 2 cents,
Rob