machine/spi: use interface to ensure uniformity for all machine implementations
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
7019c4e8fc
коммит
fa4ca63ff2
6 изменённых файлов: 25 добавлений и 5 удалений
|
@ -57,8 +57,9 @@ type SPIConfig struct {
|
|||
Mode uint8
|
||||
}
|
||||
|
||||
func (spi SPI) Configure(config SPIConfig) {
|
||||
func (spi SPI) Configure(config SPIConfig) error {
|
||||
spiConfigure(spi.Bus, config.SCK, config.SDO, config.SDI)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Transfer writes/reads a single byte using the SPI interface.
|
||||
|
|
|
@ -68,7 +68,7 @@ var (
|
|||
)
|
||||
|
||||
// Configure is intended to setup an SPI interface for transmit/receive.
|
||||
func (spi *SPI) Configure(config SPIConfig) {
|
||||
func (spi *SPI) Configure(config SPIConfig) error {
|
||||
|
||||
const defaultSpiFreq = 4000000 // 4 MHz
|
||||
|
||||
|
@ -132,6 +132,8 @@ func (spi *SPI) Configure(config SPIConfig) {
|
|||
spi.Bus.CR.Set(nxp.LPSPI_CR_MEN)
|
||||
|
||||
spi.configured = true
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Transfer writes/reads a single byte using the SPI interface.
|
||||
|
|
|
@ -49,7 +49,7 @@ type SPIConfig struct {
|
|||
}
|
||||
|
||||
// Configure is intended to setup the SPI interface.
|
||||
func (spi SPI) Configure(config SPIConfig) {
|
||||
func (spi SPI) Configure(config SPIConfig) error {
|
||||
// Disable bus to configure it
|
||||
spi.Bus.ENABLE.Set(nrf.SPI_ENABLE_ENABLE_Disabled)
|
||||
|
||||
|
@ -117,6 +117,8 @@ func (spi SPI) Configure(config SPIConfig) {
|
|||
|
||||
// Re-enable bus now that it is configured.
|
||||
spi.Bus.ENABLE.Set(nrf.SPI_ENABLE_ENABLE_Enabled)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Transfer writes/reads a single byte using the SPI interface.
|
||||
|
|
|
@ -197,7 +197,7 @@ type SPIConfig struct {
|
|||
}
|
||||
|
||||
// Configure is intended to setup the SPI interface.
|
||||
func (spi SPI) Configure(config SPIConfig) {
|
||||
func (spi SPI) Configure(config SPIConfig) error {
|
||||
// Disable bus to configure it
|
||||
spi.Bus.ENABLE.Set(nrf.SPIM_ENABLE_ENABLE_Disabled)
|
||||
|
||||
|
@ -265,6 +265,8 @@ func (spi SPI) Configure(config SPIConfig) {
|
|||
|
||||
// Re-enable bus now that it is configured.
|
||||
spi.Bus.ENABLE.Set(nrf.SPIM_ENABLE_ENABLE_Enabled)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Transfer writes/reads a single byte using the SPI interface.
|
||||
|
|
|
@ -21,7 +21,7 @@ type SPIConfig struct {
|
|||
}
|
||||
|
||||
// Configure is intended to setup the STM32 SPI1 interface.
|
||||
func (spi SPI) Configure(config SPIConfig) {
|
||||
func (spi SPI) Configure(config SPIConfig) error {
|
||||
|
||||
// -- CONFIGURING THE SPI IN MASTER MODE --
|
||||
//
|
||||
|
@ -93,6 +93,8 @@ func (spi SPI) Configure(config SPIConfig) {
|
|||
|
||||
// enable SPI
|
||||
spi.Bus.CR1.SetBits(stm32.SPI_CR1_SPE)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Transfer writes/reads a single byte using the SPI interface.
|
||||
|
|
|
@ -16,3 +16,14 @@ var (
|
|||
ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size")
|
||||
errSPIInvalidMachineConfig = errors.New("SPI port was not configured properly by the machine")
|
||||
)
|
||||
|
||||
// If you are getting a compile error on this line please check to see you've
|
||||
// correctly implemented the methods on the SPI type. They must match
|
||||
// the interface method signatures type to type perfectly.
|
||||
// If not implementing the SPI type please remove your target from the build tags
|
||||
// at the top of this file.
|
||||
var _ interface { // 2
|
||||
Configure(config SPIConfig) error
|
||||
Tx(w, r []byte) error
|
||||
Transfer(w byte) (byte, error)
|
||||
} = (*SPI)(nil)
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче