mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
machine/i2c: add interface check and implementation where missing for SetBaudRate() (#3406)
* machine/i2c: add interface check and placeholder implementation where missing for SetBaudRate()
This commit is contained in:
@@ -246,13 +246,8 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
||||
i2c.setPins(config.SCL, config.SDA)
|
||||
|
||||
i2c.mode = config.Mode
|
||||
|
||||
if i2c.mode == I2CModeController {
|
||||
if config.Frequency >= 400*KHz {
|
||||
i2c.Bus.FREQUENCY.Set(nrf.TWI_FREQUENCY_FREQUENCY_K400)
|
||||
} else {
|
||||
i2c.Bus.FREQUENCY.Set(nrf.TWI_FREQUENCY_FREQUENCY_K100)
|
||||
}
|
||||
i2c.SetBaudRate(config.Frequency)
|
||||
|
||||
i2c.enableAsController()
|
||||
} else {
|
||||
@@ -262,6 +257,23 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetBaudRate sets the I2C frequency. It has the side effect of also
|
||||
// enabling the I2C hardware if disabled beforehand.
|
||||
//
|
||||
//go:inline
|
||||
func (i2c *I2C) SetBaudRate(br uint32) error {
|
||||
switch {
|
||||
case br >= 400*KHz:
|
||||
i2c.Bus.SetFREQUENCY(nrf.TWI_FREQUENCY_FREQUENCY_K400)
|
||||
case br >= 250*KHz:
|
||||
i2c.Bus.SetFREQUENCY(nrf.TWI_FREQUENCY_FREQUENCY_K250)
|
||||
default:
|
||||
i2c.Bus.SetFREQUENCY(nrf.TWI_FREQUENCY_FREQUENCY_K100)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// signalStop sends a stop signal to the I2C peripheral and waits for confirmation.
|
||||
func (i2c *I2C) signalStop() error {
|
||||
tries := 0
|
||||
|
||||
Reference in New Issue
Block a user