mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 22:13:39 +00:00
machine/samd21: use PinMode for SPI SERCOM peripheral to allow for more configuration options on boards like Arduino Nano33-IoT that have many predefined pin mappings
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
@@ -876,12 +876,13 @@ func waitForSync() {
|
||||
|
||||
// SPI
|
||||
type SPI struct {
|
||||
Bus *sam.SERCOM_SPI_Type
|
||||
SCK Pin
|
||||
MOSI Pin
|
||||
MISO Pin
|
||||
DOpad int
|
||||
DIpad int
|
||||
Bus *sam.SERCOM_SPI_Type
|
||||
SCK Pin
|
||||
MOSI Pin
|
||||
MISO Pin
|
||||
DOpad int
|
||||
DIpad int
|
||||
PinMode PinMode
|
||||
}
|
||||
|
||||
// SPIConfig is used to store config info for SPI.
|
||||
@@ -896,7 +897,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
|
||||
@@ -904,6 +904,8 @@ func (spi SPI) Configure(config SPIConfig) {
|
||||
doPad := spi.DOpad
|
||||
diPad := spi.DIpad
|
||||
|
||||
pinMode := spi.PinMode
|
||||
|
||||
// set default frequency
|
||||
if config.Frequency == 0 {
|
||||
config.Frequency = 4000000
|
||||
@@ -915,9 +917,9 @@ 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})
|
||||
config.SCK.Configure(PinConfig{Mode: pinMode})
|
||||
config.MOSI.Configure(PinConfig{Mode: pinMode})
|
||||
config.MISO.Configure(PinConfig{Mode: pinMode})
|
||||
|
||||
// reset SERCOM
|
||||
spi.Bus.CTRLA.SetBits(sam.SERCOM_SPI_CTRLA_SWRST)
|
||||
|
||||
Reference in New Issue
Block a user