From d6cdf8ca289487b75d6310998eba45aa56545156 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 4 Feb 2021 19:18:49 +0100 Subject: [PATCH] machine: make I2C.Configure signature consistent It's better to always return an error value (even if it is nil) for consistency. --- src/machine/machine_atmega.go | 4 +++- src/machine/machine_generic.go | 3 ++- src/machine/machine_nrf.go | 4 +++- src/machine/machine_stm32_i2c.go | 4 +++- src/machine/machine_stm32f103.go | 4 +++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/machine/machine_atmega.go b/src/machine/machine_atmega.go index 6e6307d5..e2854560 100644 --- a/src/machine/machine_atmega.go +++ b/src/machine/machine_atmega.go @@ -13,7 +13,7 @@ type I2CConfig struct { } // Configure is intended to setup the I2C interface. -func (i2c I2C) Configure(config I2CConfig) { +func (i2c I2C) Configure(config I2CConfig) error { // Default I2C bus speed is 100 kHz. if config.Frequency == 0 { config.Frequency = TWI_FREQ_100KHZ @@ -33,6 +33,8 @@ func (i2c I2C) Configure(config I2CConfig) { // Enable twi module. avr.TWCR.Set(avr.TWCR_TWEN) + + return nil } // Tx does a single I2C transaction at the specified address. diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go index 65be3c96..e78e257e 100644 --- a/src/machine/machine_generic.go +++ b/src/machine/machine_generic.go @@ -115,8 +115,9 @@ type I2CConfig struct { } // Configure is intended to setup the I2C interface. -func (i2c I2C) Configure(config I2CConfig) { +func (i2c I2C) Configure(config I2CConfig) error { i2cConfigure(i2c.Bus, config.SCL, config.SDA) + return nil } // Tx does a single I2C transaction at the specified address. diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index f2e6777e..76fb161c 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -220,7 +220,7 @@ type I2CConfig struct { } // Configure is intended to setup the I2C interface. -func (i2c I2C) Configure(config I2CConfig) { +func (i2c I2C) Configure(config I2CConfig) error { // Default I2C bus speed is 100 kHz. if config.Frequency == 0 { config.Frequency = TWI_FREQ_100KHZ @@ -254,6 +254,8 @@ func (i2c I2C) Configure(config I2CConfig) { i2c.Bus.ENABLE.Set(nrf.TWI_ENABLE_ENABLE_Enabled) i2c.setPins(config.SCL, config.SDA) + + return nil } // Tx does a single I2C transaction at the specified address. diff --git a/src/machine/machine_stm32_i2c.go b/src/machine/machine_stm32_i2c.go index 471077d5..9453a24d 100644 --- a/src/machine/machine_stm32_i2c.go +++ b/src/machine/machine_stm32_i2c.go @@ -142,7 +142,7 @@ type I2CConfig struct { } // Configure is intended to setup the STM32 I2C interface. -func (i2c I2C) Configure(config I2CConfig) { +func (i2c I2C) Configure(config I2CConfig) error { // The following is the required sequence in controller mode. // 1. Program the peripheral input clock in I2C_CR2 Register in order to @@ -188,6 +188,8 @@ func (i2c I2C) Configure(config I2CConfig) { // enable I2C interface i2c.Bus.CR1.ClearBits(stm32.I2C_CR1_PE) + + return nil } func (i2c I2C) Tx(addr uint16, w, r []byte) error { diff --git a/src/machine/machine_stm32f103.go b/src/machine/machine_stm32f103.go index 28b4b814..4d422733 100644 --- a/src/machine/machine_stm32f103.go +++ b/src/machine/machine_stm32f103.go @@ -217,7 +217,7 @@ type I2CConfig struct { } // Configure is intended to setup the I2C interface. -func (i2c I2C) Configure(config I2CConfig) { +func (i2c I2C) Configure(config I2CConfig) error { // Default I2C bus speed is 100 kHz. if config.Frequency == 0 { config.Frequency = TWI_FREQ_100KHZ @@ -285,6 +285,8 @@ func (i2c I2C) Configure(config I2CConfig) { // re-enable the selected I2C peripheral i2c.Bus.CR1.SetBits(stm32.I2C_CR1_PE) + + return nil } // Tx does a single I2C transaction at the specified address.