uugear / Witty-Pi-4

Software and Firmware for Witty Pi 4
MIT License
22 stars 17 forks source link

Confusing GPIO naming in the documentation #26

Closed JeromeBriot closed 5 months ago

JeromeBriot commented 5 months ago

Hello,

The names of the GPIO are non consistent in the documentation (chapters 15.3 and 15.5).

The function doReadAll in gpio-util.sh produces the table below:

 +-----+-----+---------+------+---+   Pi 4B  +---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |  OUT | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |  OUT | 0 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |  OUT | 0 | 31 || 32 | 0 | OUT  | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+   Pi 4B  +---+------+---------+-----+-----+

The GPIO names are based on the WiringPi ones.

I think that it would be easier for the reader to have the names based on the BCM numbers:

 +-----+-----+---------+------+---+   Pi 4B  +---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | Gnd     |     |     |
 |   4 |   7 | GPIO-04 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |     Gnd |      |   |  9 || 10 | 1 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO-17 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO-18 | 1   | 18  |
 |  27 |   2 | GPIO-27 |   IN | 0 | 13 || 14 |   |      | Gnd     |     |     |
 |  22 |   3 | GPIO-22 |  OUT | 0 | 15 || 16 | 0 | IN   | GPIO-23 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO-24 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | Gnd     |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO-25 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |     Gnd |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO-05 |  OUT | 0 | 29 || 30 |   |      | Gnd     |     |     |
 |   6 |  22 | GPIO-06 |  OUT | 0 | 31 || 32 | 0 | OUT  | GPIO-12 | 26  | 12  |
 |  13 |  23 | GPIO-13 |   IN | 0 | 33 || 34 |   |      | Gnd     |     |     |
 |  19 |  24 | GPIO-19 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO-16 | 27  | 16  |
 |  26 |  25 | GPIO-26 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO-20 | 28  | 20  |
 |     |     |     Gnd |      |   | 39 || 40 | 0 | IN   | GPIO-21 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+   Pi 4B  +---+------+---------+-----+-----+

Here is the modified array in gpio-util.sh:

readonly PHY_NAMES=(
  ''
  '   3.3v'  '5v     '  #  1-2
  '  SDA.1'  '5v     '  #  3-4
  '  SCL.1'  'Gnd    '  #  5-6
  'GPIO-04'  'TxD    '  #  7-8
  '    Gnd'  'RxD    '  #  9-10
  'GPIO-17'  'GPIO-18'  # 11-12
  'GPIO-27'  'Gnd    '  # 13-14
  'GPIO-22'  'GPIO-23'  # 15-16
  '   3.3v'  'GPIO-24'  # 17-18
  '   MOSI'  'Gnd    '  # 19-20
  '   MISO'  'GPIO-25'  # 21-22
  '   SCLK'  'CE0    '  # 23-24
  '    Gnd'  'CE1    '  # 25-26
  '  SDA.0'  'SCL.0  '  # 27-28
  'GPIO-05'  'Gnd    '  # 29-30
  'GPIO-06'  'GPIO-12'  # 31-32
  'GPIO-13'  'Gnd    '  # 33-34
  'GPIO-19'  'GPIO-16'  # 35-36
  'GPIO-26'  'GPIO-20'  # 37-38
  '    Gnd'  'GPIO-21'  # 39-40
)
uugear commented 5 months ago

Thanks for the suggestion.

As introduced in the comment at the begining of gpio-util.sh file, it defines a BASH function named "gpio", which can be used like a simplified version of "gpio" utility in WiringPi library. The gpio-util.sh file is the substitute of the absent "gpio" utility from WiringPi, so we let it emulate the output of the "gpio" utlity.

I do think your modified version is more friendly to Raspberry Pi users. However we will not include it in our distribution, because we want to keep the consistency with wiringPi, and we do believe one day we can switch back to the real WiringPi.