mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 08:23:41 +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:
@@ -563,7 +563,19 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
||||
config.SCL.SetFPIOAFunction(FUNC_I2C2_SCLK)
|
||||
}
|
||||
|
||||
div := CPUFrequency() / config.Frequency / 16
|
||||
i2c.SetBaudRate(config.Frequency)
|
||||
|
||||
i2c.Bus.INTR_MASK.Set(0)
|
||||
i2c.Bus.DMA_CR.Set(0x03)
|
||||
i2c.Bus.DMA_RDLR.Set(0)
|
||||
i2c.Bus.DMA_TDLR.Set(0x4)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetBaudRate sets the communication speed for I2C.
|
||||
func (i2c *I2C) SetBaudRate(br uint32) error {
|
||||
div := CPUFrequency() / br / 16
|
||||
|
||||
// Disable controller before setting the prescale register.
|
||||
i2c.Bus.ENABLE.Set(0)
|
||||
@@ -574,11 +586,6 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
||||
i2c.Bus.SS_SCL_HCNT.Set(uint32(div))
|
||||
i2c.Bus.SS_SCL_LCNT.Set(uint32(div))
|
||||
|
||||
i2c.Bus.INTR_MASK.Set(0)
|
||||
i2c.Bus.DMA_CR.Set(0x03)
|
||||
i2c.Bus.DMA_RDLR.Set(0)
|
||||
i2c.Bus.DMA_TDLR.Set(0x4)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user