From 2f1f8fb0755051f61e813dd832e246db99cfbd8c Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 6 May 2021 12:51:06 +0200 Subject: [PATCH] machine: move PinMode to central location It is always implemented exactly the same way (as an uint8) so there is no reason to implement it in each target separately. This also makes it easier to add some documentation to it. --- src/machine/machine.go | 5 +++++ src/machine/machine_atsamd21.go | 2 -- src/machine/machine_atsamd51.go | 2 -- src/machine/machine_avr.go | 2 -- src/machine/machine_esp32.go | 2 -- src/machine/machine_esp8266.go | 2 -- src/machine/machine_fe310.go | 2 -- src/machine/machine_gameboyadvance.go | 2 -- src/machine/machine_generic.go | 2 -- src/machine/machine_k210.go | 1 - src/machine/machine_mimxrt1062.go | 2 -- src/machine/machine_nrf.go | 2 -- src/machine/machine_nxpmk66f18.go | 2 -- src/machine/machine_stm32.go | 2 -- 14 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/machine/machine.go b/src/machine/machine.go index d40c39f0..aa1a2f6b 100644 --- a/src/machine/machine.go +++ b/src/machine/machine.go @@ -10,6 +10,11 @@ var ( ErrNoPinChangeChannel = errors.New("machine: no channel available for pin interrupt") ) +// PinMode sets the direction and pull mode of the pin. For example, PinOutput +// sets the pin as an output and PinInputPullup sets the pin as an input with a +// pull-up. +type PinMode uint8 + type PinConfig struct { Mode PinMode } diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index aca801c5..4bacd2aa 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -16,8 +16,6 @@ import ( "unsafe" ) -type PinMode uint8 - const ( PinAnalog PinMode = 1 PinSERCOM PinMode = 2 diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 0ce476cc..f8b0a865 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -20,8 +20,6 @@ func CPUFrequency() uint32 { return 120000000 } -type PinMode uint8 - const ( PinAnalog PinMode = 1 PinSERCOM PinMode = 2 diff --git a/src/machine/machine_avr.go b/src/machine/machine_avr.go index 5cf70cca..14ba5020 100644 --- a/src/machine/machine_avr.go +++ b/src/machine/machine_avr.go @@ -8,8 +8,6 @@ import ( "unsafe" ) -type PinMode uint8 - const ( PinInput PinMode = iota PinInputPullup diff --git a/src/machine/machine_esp32.go b/src/machine/machine_esp32.go index 1526fc16..fd4fa062 100644 --- a/src/machine/machine_esp32.go +++ b/src/machine/machine_esp32.go @@ -21,8 +21,6 @@ var ( ErrInvalidSPIBus = errors.New("machine: invalid SPI bus") ) -type PinMode uint8 - const ( PinOutput PinMode = iota PinInput diff --git a/src/machine/machine_esp8266.go b/src/machine/machine_esp8266.go index 5570e7e0..19c5dd0a 100644 --- a/src/machine/machine_esp8266.go +++ b/src/machine/machine_esp8266.go @@ -11,8 +11,6 @@ func CPUFrequency() uint32 { return 80000000 // 80MHz } -type PinMode uint8 - const ( PinOutput PinMode = iota PinInput diff --git a/src/machine/machine_fe310.go b/src/machine/machine_fe310.go index ae618e58..3af8acc4 100644 --- a/src/machine/machine_fe310.go +++ b/src/machine/machine_fe310.go @@ -12,8 +12,6 @@ func CPUFrequency() uint32 { return 16000000 } -type PinMode uint8 - const ( PinInput PinMode = iota PinOutput diff --git a/src/machine/machine_gameboyadvance.go b/src/machine/machine_gameboyadvance.go index d592a1eb..100c2bce 100644 --- a/src/machine/machine_gameboyadvance.go +++ b/src/machine/machine_gameboyadvance.go @@ -30,8 +30,6 @@ const ( // Make it easier to directly write to I/O RAM. var ioram = (*[0x400]volatile.Register8)(unsafe.Pointer(uintptr(0x04000000))) -type PinMode uint8 - // Set has not been implemented. func (p Pin) Set(value bool) { // do nothing diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go index d482e0e3..16948a49 100644 --- a/src/machine/machine_generic.go +++ b/src/machine/machine_generic.go @@ -10,8 +10,6 @@ var ( UART0 = UART{0} ) -type PinMode uint8 - const ( PinInput PinMode = iota PinOutput diff --git a/src/machine/machine_k210.go b/src/machine/machine_k210.go index 3baef329..f009e152 100644 --- a/src/machine/machine_k210.go +++ b/src/machine/machine_k210.go @@ -14,7 +14,6 @@ func CPUFrequency() uint32 { return 390000000 } -type PinMode uint8 type fpioaPullMode uint8 type PinChange uint8 diff --git a/src/machine/machine_mimxrt1062.go b/src/machine/machine_mimxrt1062.go index 42586c42..38cb71f7 100644 --- a/src/machine/machine_mimxrt1062.go +++ b/src/machine/machine_mimxrt1062.go @@ -15,8 +15,6 @@ func CPUFrequency() uint32 { return 600000000 } -type PinMode uint8 - const ( // GPIO PinInput PinMode = iota diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index e8488c79..c49096e8 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -13,8 +13,6 @@ var ( ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size") ) -type PinMode uint8 - const ( PinInput PinMode = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) | (nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos) PinInputPullup PinMode = PinInput | (nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos) diff --git a/src/machine/machine_nxpmk66f18.go b/src/machine/machine_nxpmk66f18.go index 63f7b58e..35e48e5c 100644 --- a/src/machine/machine_nxpmk66f18.go +++ b/src/machine/machine_nxpmk66f18.go @@ -37,8 +37,6 @@ import ( "unsafe" ) -type PinMode uint8 - const ( PinInput PinMode = iota PinInputPullUp diff --git a/src/machine/machine_stm32.go b/src/machine/machine_stm32.go index 8ef5fed7..363036ca 100644 --- a/src/machine/machine_stm32.go +++ b/src/machine/machine_stm32.go @@ -17,8 +17,6 @@ const ( portJ ) -type PinMode uint8 - // Peripheral operations sequence: // 1. Enable the clock to the alternate function. // 2. Enable clock to corresponding GPIO