Skip to content

Commit 6163664

Browse files
committed
chore(review): honor
Signed-off-by: Paul Schroeder <[email protected]>
1 parent e8aa554 commit 6163664

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/machine/machine_nrf52xxx.go

+19-24
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ var (
2929

3030
type SPIMode uint8
3131

32-
func (m SPIMode) ApplyTo(conf uint32) uint32 {
33-
// See:
34-
// - https://de.wikipedia.org/wiki/Serial_Peripheral_Interface#/media/Datei:SPI_timing_diagram2.svg
35-
// - https://docs-be.nordicsemi.com/bundle/ps_nrf52840/attach/nRF52840_PS_v1.11.pdf?_LANG=enus page 716, table 43
36-
switch m {
37-
case SPI_MODE_CPHA0_CPOL0:
38-
conf &^= (nrf.SPIM_CONFIG_CPOL_ActiveHigh << nrf.SPIM_CONFIG_CPOL_Pos)
39-
conf &^= (nrf.SPIM_CONFIG_CPHA_Leading << nrf.SPIM_CONFIG_CPHA_Pos)
40-
case SPI_MODE_CPHA1_CPOL0:
41-
conf &^= (nrf.SPIM_CONFIG_CPOL_ActiveHigh << nrf.SPIM_CONFIG_CPOL_Pos)
42-
conf |= (nrf.SPIM_CONFIG_CPHA_Trailing << nrf.SPIM_CONFIG_CPHA_Pos)
43-
case SPI_MODE_CPHA1_CPOL1:
44-
conf |= (nrf.SPIM_CONFIG_CPOL_ActiveLow << nrf.SPIM_CONFIG_CPOL_Pos)
45-
conf &^= (nrf.SPIM_CONFIG_CPHA_Leading << nrf.SPIM_CONFIG_CPHA_Pos)
46-
case SPI_MODE_CPHA0_CPOL1:
47-
conf |= (nrf.SPIM_CONFIG_CPOL_ActiveLow << nrf.SPIM_CONFIG_CPOL_Pos)
48-
conf |= (nrf.SPIM_CONFIG_CPHA_Trailing << nrf.SPIM_CONFIG_CPHA_Pos)
49-
}
50-
return conf
51-
}
52-
5332
func CPUFrequency() uint32 {
5433
return 64000000
5534
}
@@ -227,7 +206,7 @@ type SPIConfig struct {
227206
SDO Pin
228207
SDI Pin
229208
LSBFirst bool
230-
Mode SPIMode
209+
Mode uint8
231210
}
232211

233212
// Configure is intended to set up the SPI interface.
@@ -264,8 +243,24 @@ func (spi *SPI) Configure(config SPIConfig) error {
264243
conf = (nrf.SPIM_CONFIG_ORDER_LsbFirst << nrf.SPIM_CONFIG_ORDER_Pos)
265244
}
266245

267-
// set mode
268-
conf = config.Mode.ApplyTo(conf)
246+
// set mode, see:
247+
// - https://de.wikipedia.org/wiki/Serial_Peripheral_Interface#/media/Datei:SPI_timing_diagram2.svg
248+
// - https://docs-be.nordicsemi.com/bundle/ps_nrf52840/attach/nRF52840_PS_v1.11.pdf?_LANG=enus page 716, table 43
249+
switch SPIMode(config.Mode) {
250+
case SPI_MODE_CPHA0_CPOL0:
251+
conf &^= (nrf.SPIM_CONFIG_CPOL_ActiveHigh << nrf.SPIM_CONFIG_CPOL_Pos)
252+
conf &^= (nrf.SPIM_CONFIG_CPHA_Leading << nrf.SPIM_CONFIG_CPHA_Pos)
253+
case SPI_MODE_CPHA1_CPOL0:
254+
conf &^= (nrf.SPIM_CONFIG_CPOL_ActiveHigh << nrf.SPIM_CONFIG_CPOL_Pos)
255+
conf |= (nrf.SPIM_CONFIG_CPHA_Trailing << nrf.SPIM_CONFIG_CPHA_Pos)
256+
case SPI_MODE_CPHA1_CPOL1:
257+
conf |= (nrf.SPIM_CONFIG_CPOL_ActiveLow << nrf.SPIM_CONFIG_CPOL_Pos)
258+
conf &^= (nrf.SPIM_CONFIG_CPHA_Leading << nrf.SPIM_CONFIG_CPHA_Pos)
259+
case SPI_MODE_CPHA0_CPOL1:
260+
conf |= (nrf.SPIM_CONFIG_CPOL_ActiveLow << nrf.SPIM_CONFIG_CPOL_Pos)
261+
conf |= (nrf.SPIM_CONFIG_CPHA_Trailing << nrf.SPIM_CONFIG_CPHA_Pos)
262+
}
263+
269264
spi.Bus.CONFIG.Set(conf)
270265

271266
// set pins

0 commit comments

Comments
 (0)