machine/esp32c3: handle defaults for I2C configuration
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
94459cefe5
коммит
f91b6ad0df
1 изменённых файлов: 21 добавлений и 7 удалений
|
@ -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
|
||||||
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче