Skip to content

Commit

Permalink
fix(src/machine/nrf52xxx): tests
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schroeder <[email protected]>
  • Loading branch information
milkpirate committed Dec 15, 2024
1 parent 7121e23 commit b2c7f93
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/machine/machine_nrf52xxx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import (
)

const (
SPI_CPHA0_CPOL0 SPIMode = iota
SPI_CPHA1_CPOL0
SPI_CPHA1_CPOL1
SPI_CPHA0_CPOL1
SPI_MODE_CPHA0_CPOL0 SPIMode = iota
SPI_MODE_CPHA1_CPOL0
SPI_MODE_CPHA1_CPOL1
SPI_MODE_CPHA0_CPOL1

SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_LOW = SPI_MODE_CPHA0_CPOL0
SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_LOW = SPI_MODE_CPHA1_CPOL0
SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_HIGH = SPI_MODE_CPHA1_CPOL1
SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_HIGH = SPI_MODE_CPHA0_CPOL1
)

// There are 3 SPI interfaces on the NRF528xx.
Expand All @@ -26,17 +31,17 @@ type SPIMode uint8

func (m *SPIMode) ApplyTo(conf uint32) uint32 {
// see https://de.wikipedia.org/wiki/Serial_Peripheral_Interface#/media/Datei:SPI_timing_diagram2.svg
switch m {
case SPI_CPHA1_CPOL0:
switch &m {
case SPI_MODE_CPHA1_CPOL0, SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_LOW:

Check failure on line 35 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA1_CPOL0 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 35 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_LOW in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 35 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA1_CPOL0 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 35 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_LOW in switch on &m (mismatched types SPIMode and **SPIMode)
conf &^= (nrf.SPIM_CONFIG_CPOL_ActiveHigh << nrf.SPIM_CONFIG_CPOL_Pos)
conf |= (nrf.SPIM_CONFIG_CPHA_Trailing << nrf.SPIM_CONFIG_CPHA_Pos)
case SPI_CPHA1_CPOL1:
case SPI_MODE_CPHA1_CPOL1, SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_LOW:

Check failure on line 38 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA1_CPOL1 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 38 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_LOW in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 38 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA1_CPOL1 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 38 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_LOW in switch on &m (mismatched types SPIMode and **SPIMode)
conf |= (nrf.SPIM_CONFIG_CPOL_ActiveLow << nrf.SPIM_CONFIG_CPOL_Pos)
conf &^= (nrf.SPIM_CONFIG_CPHA_Leading << nrf.SPIM_CONFIG_CPHA_Pos)
case SPI_CPHA0_CPOL1:
case SPI_MODE_CPHA0_CPOL1, SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_HIGH:

Check failure on line 41 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA0_CPOL1 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 41 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_HIGH in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 41 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA0_CPOL1 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 41 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA_RISING_EDGE_CPOL_ACTIVE_HIGH in switch on &m (mismatched types SPIMode and **SPIMode)
conf |= (nrf.SPIM_CONFIG_CPOL_ActiveLow << nrf.SPIM_CONFIG_CPOL_Pos)
conf |= (nrf.SPIM_CONFIG_CPHA_Trailing << nrf.SPIM_CONFIG_CPHA_Pos)
case SPI_CPHA0_CPOL0:
case SPI_MODE_CPHA0_CPOL0, SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_HIGH:

Check failure on line 44 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA0_CPOL0 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 44 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / build-macos (macos-14)

invalid case SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_HIGH in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 44 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA0_CPOL0 in switch on &m (mismatched types SPIMode and **SPIMode)

Check failure on line 44 in src/machine/machine_nrf52xxx.go

View workflow job for this annotation

GitHub Actions / assert-test-linux

invalid case SPI_MODE_CPHA_FALLING_EDGE_CPOL_ACTIVE_HIGH in switch on &m (mismatched types SPIMode and **SPIMode)
conf &^= (nrf.SPIM_CONFIG_CPOL_ActiveHigh << nrf.SPIM_CONFIG_CPOL_Pos)
conf &^= (nrf.SPIM_CONFIG_CPHA_Leading << nrf.SPIM_CONFIG_CPHA_Pos)
}
Expand All @@ -63,15 +68,15 @@ func (a *ADC) Configure(config ADCConfig) {
var resolution uint32
switch config.Resolution {
case 8:
resolution = SAADC_RESOLUTION_VAL_8bit
resolution = nrf.SAADC_RESOLUTION_VAL_8bit
case 10:
resolution = SAADC_RESOLUTION_VAL_10bit
resolution = nrf.SAADC_RESOLUTION_VAL_10bit
case 12:
resolution = SAADC_RESOLUTION_VAL_12bit
resolution = nrf.SAADC_RESOLUTION_VAL_12bit
case 14:
resolution = SAADC_RESOLUTION_VAL_14bit
resolution = nrf.SAADC_RESOLUTION_VAL_14bit
default:
resolution = SAADC_RESOLUTION_VAL_12bit
resolution = nrf.SAADC_RESOLUTION_VAL_12bit
}
nrf.SAADC.RESOLUTION.Set(resolution)

Expand Down Expand Up @@ -254,7 +259,7 @@ func (spi *SPI) Configure(config SPIConfig) error {
}

// set mode
conf = config.Mode.Apply(conf)
conf = config.Mode.ApplyTo(conf)
spi.Bus.CONFIG.Set(conf)

// set pins
Expand Down Expand Up @@ -329,12 +334,12 @@ func (spi *SPI) Tx(w, r []byte) error {

// Read implements [io.Reader]. And reads as many bytes as the given buffer is long
func (spi *SPI) Read(r []byte) (int, error) {
return spi.Tx(nil, r), len(r)
return len(r), spi.Tx(nil, r)
}

// Write implements [io.Writer]. And writes as long as there are bytes in w.
func (spi *SPI) Write(w []byte) (int, error) {
return spi.Tx(w, nil), len(w)
return len(w), spi.Tx(w, nil)
}

// PWM is one PWM peripheral, which consists of a counter and multiple output
Expand Down

0 comments on commit b2c7f93

Please sign in to comment.