From 6ad6f14a04eb598c74a008d13856bddcc06c9fff Mon Sep 17 00:00:00 2001 From: Ethan Reesor Date: Sun, 12 Jul 2020 20:41:15 -0500 Subject: [PATCH] Use a jump table instead of if-then-else --- src/machine/machine_nxpmk66f18.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/machine/machine_nxpmk66f18.go b/src/machine/machine_nxpmk66f18.go index 3804b67b..63f7b58e 100644 --- a/src/machine/machine_nxpmk66f18.go +++ b/src/machine/machine_nxpmk66f18.go @@ -187,17 +187,18 @@ func (p Pin) reg() (*nxp.GPIO_Type, *volatile.Register32, uint8) { var gpio *nxp.GPIO_Type var pcr *nxp.PORT_Type - if p < 32 { + switch p / 32 { + case 0: gpio, pcr = nxp.GPIOA, nxp.PORTA - } else if p < 64 { + case 1: gpio, pcr = nxp.GPIOB, nxp.PORTB - } else if p < 96 { + case 2: gpio, pcr = nxp.GPIOC, nxp.PORTC - } else if p < 128 { + case 3: gpio, pcr = nxp.GPIOD, nxp.PORTD - } else if p < 160 { + case 5: gpio, pcr = nxp.GPIOE, nxp.PORTE - } else { + default: panic("invalid pin number") }