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:
Ron Evans
2023-10-14 13:17:24 +02:00
committed by GitHub
parent 72b715fa99
commit 935a293106
11 changed files with 104 additions and 42 deletions
+3 -2
View File
@@ -732,12 +732,13 @@ func (i2c *I2C) Configure(config I2CConfig) error {
return nil
}
// SetBaudRate sets the communication speed for the I2C.
func (i2c *I2C) SetBaudRate(br uint32) {
// SetBaudRate sets the communication speed for I2C.
func (i2c *I2C) SetBaudRate(br uint32) error {
// Synchronous arithmetic baudrate, via Arduino SAMD implementation:
// SystemCoreClock / ( 2 * baudrate) - 5 - (((SystemCoreClock / 1000000) * WIRE_RISE_TIME_NANOSECONDS) / (2 * 1000));
baud := CPUFrequency()/(2*br) - 5 - (((CPUFrequency() / 1000000) * riseTimeNanoseconds) / (2 * 1000))
i2c.Bus.BAUD.Set(baud)
return nil
}
// Tx does a single I2C transaction at the specified address.