mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-01 18:29:03 +00:00
machine/esp32c3: handle defaults for I2C configuration
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -626,6 +626,16 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (i2c *I2C) Configure(config I2CConfig) error {
|
func (i2c *I2C) Configure(config I2CConfig) error {
|
||||||
|
if config.Frequency == 0 {
|
||||||
|
config.Frequency = 400 * KHz
|
||||||
|
}
|
||||||
|
if config.SCL == 0 {
|
||||||
|
config.SCL = SCL_PIN
|
||||||
|
}
|
||||||
|
if config.SDA == 0 {
|
||||||
|
config.SDA = SDA_PIN
|
||||||
|
}
|
||||||
|
|
||||||
i2c.initClock(config)
|
i2c.initClock(config)
|
||||||
i2c.initNoiseFilter()
|
i2c.initNoiseFilter()
|
||||||
i2c.initPins(config)
|
i2c.initPins(config)
|
||||||
@@ -907,7 +917,7 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error {
|
|||||||
// bytes and stores them in r, and generates a stop condition on the bus.
|
// bytes and stores them in r, and generates a stop condition on the bus.
|
||||||
func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) {
|
func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) {
|
||||||
// timeout in microseconds.
|
// timeout in microseconds.
|
||||||
const timeout = 100 * 1000 // 40ms is a reasonable time for a real-time system.
|
const timeout = 40 // 40ms is a reasonable time for a real-time system.
|
||||||
|
|
||||||
cmd := make([]i2cCommand, 0, 8)
|
cmd := make([]i2cCommand, 0, 8)
|
||||||
cmd = append(cmd, i2cCommand{cmd: i2cCMD_RSTART})
|
cmd = append(cmd, i2cCommand{cmd: i2cCMD_RSTART})
|
||||||
@@ -921,3 +931,7 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) {
|
|||||||
|
|
||||||
return i2c.transmit(addr, cmd, timeout)
|
return i2c.transmit(addr, cmd, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i2c *I2C) SetBaudRate(br uint32) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user