Skip to content

Commit aac959e

Browse files
aykevldeadprogram
authored andcommitted
i2csoft: use cycle counting for delays
This should make the software I2C driver more portable, and potentially usable on chips that aren't yet supported. More importantly, it avoids some guesswork in the various chip-specific timing code.
1 parent 9fdf0d6 commit aac959e

7 files changed

+8
-95
lines changed

i2csoft/i2csoft.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package i2csoft
33
import (
44
"errors"
55
"machine"
6+
"time"
7+
8+
"tinygo.org/x/drivers/delay"
69
)
710

811
// I2C is an I2C implementation by Software. Since it is implemented by
@@ -278,3 +281,8 @@ func (i2c *I2C) WriteRegister(address uint8, register uint8, data []byte) error
278281
func (i2c *I2C) ReadRegister(address uint8, register uint8, data []byte) error {
279282
return i2c.Tx(uint16(address), []byte{register}, data)
280283
}
284+
285+
// wait waits for half the time of the SCL operation interval.
286+
func (i2c *I2C) wait() {
287+
delay.Sleep(50 * time.Microsecond) // half of a 100kHz cycle (50µs)
288+
}

i2csoft/i2csoft_atsamd51.go

-16
This file was deleted.

i2csoft/i2csoft_esp32.go

-16
This file was deleted.

i2csoft/i2csoft_nrf52840.go

-16
This file was deleted.

i2csoft/i2csoft_other.go

-15
This file was deleted.

i2csoft/i2csoft_rp2040.go

-16
This file was deleted.

i2csoft/i2csoft_stm32f4.go

-16
This file was deleted.

0 commit comments

Comments
 (0)