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. 12
      src/machine/board_itsybitsy-m4.go
  2. 35
      src/machine/machine_atsamd51.go

12
src/machine/board_itsybitsy-m4.go

@ -75,9 +75,11 @@ const (
// SPI on the ItsyBitsy M4. // SPI on the ItsyBitsy M4.
var ( var (
SPI0 = SPI{Bus: sam.SERCOM1_SPIM, SPI0 = SPI{Bus: sam.SERCOM1_SPIM,
SCK: SPI0_SCK_PIN, SCK: SPI0_SCK_PIN,
MOSI: SPI0_MOSI_PIN, MOSI: SPI0_MOSI_PIN,
MISO: SPI0_MISO_PIN, MISO: SPI0_MISO_PIN,
DOpad: spiTXPad2SCK3, DOpad: spiTXPad2SCK3,
DIpad: sercomRXPad0} DIpad: sercomRXPad3,
MISOPinMode: PinSERCOM,
}
) )

35
src/machine/machine_atsamd51.go

@ -884,12 +884,15 @@ func (i2c I2C) readByte() byte {
// SPI // SPI
type SPI struct { type SPI struct {
Bus *sam.SERCOM_SPIM_Type Bus *sam.SERCOM_SPIM_Type
SCK Pin SCK Pin
MOSI Pin MOSI Pin
MISO Pin MISO Pin
DOpad int DOpad int
DIpad int DIpad int
SCKPinMode PinMode
MOSIPinMode PinMode
MISOPinMode PinMode
} }
// SPIConfig is used to store config info for SPI. // SPIConfig is used to store config info for SPI.
@ -904,10 +907,6 @@ type SPIConfig struct {
// Configure is intended to setup the SPI interface. // Configure is intended to setup the SPI interface.
func (spi SPI) Configure(config SPIConfig) { func (spi SPI) Configure(config SPIConfig) {
config.SCK = spi.SCK
config.MOSI = spi.MOSI
config.MISO = spi.MISO
doPad := spi.DOpad doPad := spi.DOpad
diPad := spi.DIpad diPad := spi.DIpad
@ -922,9 +921,19 @@ func (spi SPI) Configure(config SPIConfig) {
} }
// enable pins // enable pins
config.SCK.Configure(PinConfig{Mode: PinSERCOMAlt}) if spi.SCKPinMode == 0 {
config.MOSI.Configure(PinConfig{Mode: PinSERCOMAlt}) spi.SCKPinMode = PinSERCOMAlt
config.MISO.Configure(PinConfig{Mode: 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 // reset SERCOM
spi.Bus.CTRLA.SetBits(sam.SERCOM_SPIM_CTRLA_SWRST) spi.Bus.CTRLA.SetBits(sam.SERCOM_SPIM_CTRLA_SWRST)

Loading…
Cancel
Save