Browse Source

machine/samd51: allow setting pinmode for each of the SPI pins

Signed-off-by: Ron Evans <ron@hybridgroup.com>
pull/675/head
Ron Evans 5 years ago
committed by Ayke
parent
commit
3777791aa3
  1. 4
      src/machine/board_itsybitsy-m4.go
  2. 23
      src/machine/machine_atsamd51.go

4
src/machine/board_itsybitsy-m4.go

@ -79,5 +79,7 @@ var (
MOSI: SPI0_MOSI_PIN,
MISO: SPI0_MISO_PIN,
DOpad: spiTXPad2SCK3,
DIpad: sercomRXPad0}
DIpad: sercomRXPad3,
MISOPinMode: PinSERCOM,
}
)

23
src/machine/machine_atsamd51.go

@ -890,6 +890,9 @@ type SPI struct {
MISO Pin
DOpad int
DIpad int
SCKPinMode PinMode
MOSIPinMode PinMode
MISOPinMode PinMode
}
// SPIConfig is used to store config info for SPI.
@ -904,10 +907,6 @@ type SPIConfig struct {
// Configure is intended to setup the SPI interface.
func (spi SPI) Configure(config SPIConfig) {
config.SCK = spi.SCK
config.MOSI = spi.MOSI
config.MISO = spi.MISO
doPad := spi.DOpad
diPad := spi.DIpad
@ -922,9 +921,19 @@ func (spi SPI) Configure(config SPIConfig) {
}
// enable pins
config.SCK.Configure(PinConfig{Mode: PinSERCOMAlt})
config.MOSI.Configure(PinConfig{Mode: PinSERCOMAlt})
config.MISO.Configure(PinConfig{Mode: PinSERCOMAlt})
if spi.SCKPinMode == 0 {
spi.SCKPinMode = PinSERCOMAlt
}
if spi.MOSIPinMode == 0 {
spi.MOSIPinMode = PinSERCOMAlt
}
if spi.MISOPinMode == 0 {
spi.MISOPinMode = PinSERCOMAlt
}
spi.SCK.Configure(PinConfig{Mode: spi.SCKPinMode})
spi.MOSI.Configure(PinConfig{Mode: spi.MOSIPinMode})
spi.MISO.Configure(PinConfig{Mode: spi.MISOPinMode})
// reset SERCOM
spi.Bus.CTRLA.SetBits(sam.SERCOM_SPIM_CTRLA_SWRST)

Loading…
Cancel
Save