Skip to content

analogRead buggy pin handling #720

Closed
@louisrubet

Description

@louisrubet

This code is found in uint32_t analogRead(uint32_t pin):

uint32_t analogRead(uint32_t pin)
{
  (...)
  if (pin < A0) {
    pin += A0;
  }
  (...)

The pin passed as an argument is deliberately changed if it doesn't fulfill a certain requirement.
This seems inappropriate:

  • This forces a particular (and arbitrary) order in the pin map (and the user doesn't know it),
  • Variables called pin always refer to an index in g_APinDescription and never something else,
  • It's present in analogRead but not in in analogWrite
  • This induces issues, one example :
    • I change PA10 to analog on my mkrzero board by changing PIO_DIGITAL to PIO_ANALOG in g_APinDescription[2]
    • when I call analogRead(2) it does analogRead(17)

Imo it's really worth removing these 3 lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions