Implementation of analogread and analogwrite error checking


#1

In keeping with Lisp’s policy of providing run-time error checking, the functions analogread and analogwrite give an error if the pin number provided doesn’t support analogue input or output respectively. In previous releases of uLisp this check was performed by a board-specific test, such as:

#if defined(ARDUINO_GRAND_CENTRAL_M4)
  if (!((pin>=67 && pin<=74) || (pin>=54 && pin<=61)))
    error(invalidpin, number(pin));

However, I’ve recently realised that in most Arduino cores there are functions that will perform this test automatically for every board supported by that core. For example, on the Grand Central M4 and all other SAMD cores this would become:

#if defined(ARDUINO_ARCH_SAMD)
  if g_APinDescription[pin].ulADCChannelNumber == No_ADC_Channel
    error(invalidpin, number(pin));

It would also be possible to add error checking to digitalread and digitalwrite in a similar way.

Does anyone foresee any problems with this? Otherwise I’ll consider changing it next release.