mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 19:44:00 +00:00
Use a jump table instead of if-then-else
This commit is contained in:
committed by
Jaden Weiss
parent
19e0f4709e
commit
6ad6f14a04
@@ -187,17 +187,18 @@ func (p Pin) reg() (*nxp.GPIO_Type, *volatile.Register32, uint8) {
|
|||||||
var gpio *nxp.GPIO_Type
|
var gpio *nxp.GPIO_Type
|
||||||
var pcr *nxp.PORT_Type
|
var pcr *nxp.PORT_Type
|
||||||
|
|
||||||
if p < 32 {
|
switch p / 32 {
|
||||||
|
case 0:
|
||||||
gpio, pcr = nxp.GPIOA, nxp.PORTA
|
gpio, pcr = nxp.GPIOA, nxp.PORTA
|
||||||
} else if p < 64 {
|
case 1:
|
||||||
gpio, pcr = nxp.GPIOB, nxp.PORTB
|
gpio, pcr = nxp.GPIOB, nxp.PORTB
|
||||||
} else if p < 96 {
|
case 2:
|
||||||
gpio, pcr = nxp.GPIOC, nxp.PORTC
|
gpio, pcr = nxp.GPIOC, nxp.PORTC
|
||||||
} else if p < 128 {
|
case 3:
|
||||||
gpio, pcr = nxp.GPIOD, nxp.PORTD
|
gpio, pcr = nxp.GPIOD, nxp.PORTD
|
||||||
} else if p < 160 {
|
case 5:
|
||||||
gpio, pcr = nxp.GPIOE, nxp.PORTE
|
gpio, pcr = nxp.GPIOE, nxp.PORTE
|
||||||
} else {
|
default:
|
||||||
panic("invalid pin number")
|
panic("invalid pin number")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user