mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 22:43:40 +00:00
nrf: add I2C timeout
This commit adds I2C timeouts for nrf51 and nrf52 (but not yet for others like nrf52840). Tested on the PineTime, where I now got a timeout instead of hanging and resetting due to a watchdog reset.
This commit is contained in:
committed by
Ron Evans
parent
a7b205c26c
commit
14ddba8519
@@ -203,6 +203,8 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
|
||||
}
|
||||
}
|
||||
|
||||
const i2cTimeout = 0xffff // this is around 29ms on a nrf52
|
||||
|
||||
// I2CConfig is used to store config info for I2C.
|
||||
type I2CConfig struct {
|
||||
Frequency uint32
|
||||
@@ -261,11 +263,17 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
||||
}
|
||||
|
||||
// signalStop sends a stop signal to the I2C peripheral and waits for confirmation.
|
||||
func (i2c *I2C) signalStop() {
|
||||
func (i2c *I2C) signalStop() error {
|
||||
tries := 0
|
||||
i2c.Bus.TASKS_STOP.Set(1)
|
||||
for i2c.Bus.EVENTS_STOPPED.Get() == 0 {
|
||||
tries++
|
||||
if tries >= i2cTimeout {
|
||||
return errI2CSignalStopTimeout
|
||||
}
|
||||
}
|
||||
i2c.Bus.EVENTS_STOPPED.Set(0)
|
||||
return nil
|
||||
}
|
||||
|
||||
var rngStarted = false
|
||||
|
||||
Reference in New Issue
Block a user