From 1451eeaf414176f2b96298516f3bf2c3296f8037 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 30 Jun 2020 13:24:29 +0200 Subject: [PATCH] machine: change machine.Pin type to uint8 The `machine.Pin` type was a int8, which works fine but limits the number of pin numbers to 127. This patch changes the type to uint8 and changes NoPin to 0xff, which allows more pins to be used. Some boards might not have that many pins but their internal organization requires more pin numbers to be used (because it is organized in pin ports and not all pins in a port have a physical connection). Therefore the range of a int8 is too low to address these higher pins. This patch also has the surprising side effect of reducing binary size in a number of cases. If there is a reduction it's usually just a few bytes, with one outlier: the driver example amg88xx when compiled for the pybadge board. I have not seen any increases in binary size. --- src/machine/machine.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/machine/machine.go b/src/machine/machine.go index e4e1dcb7..ce519f64 100644 --- a/src/machine/machine.go +++ b/src/machine/machine.go @@ -17,11 +17,11 @@ type PinConfig struct { // Pin is a single pin on a chip, which may be connected to other hardware // devices. It can either be used directly as GPIO pin or it can be used in // other peripherals like ADC, I2C, etc. -type Pin int8 +type Pin uint8 // NoPin explicitly indicates "not a pin". Use this pin if you want to leave one // of the pins in a peripheral unconfigured (if supported by the hardware). -const NoPin = Pin(-1) +const NoPin = Pin(0xff) // High sets this GPIO pin to high, assuming it has been configured as an output // pin. It is hardware dependent (and often undefined) what happens if you set a