From 4f82c231cb0d7d977099da50580dea7503fc1bdf Mon Sep 17 00:00:00 2001 From: sago35 Date: Fri, 24 Sep 2021 10:15:02 +0900 Subject: [PATCH] i2csoft: add source code for each target --- i2csoft/i2csoft_atsamd51.go | 16 +++++----------- i2csoft/i2csoft_esp32.go | 12 +++--------- i2csoft/i2csoft_nrf52840.go | 17 +++++++++++++++++ i2csoft/i2csoft_other.go | 14 ++++---------- i2csoft/i2csoft_rp2040.go | 17 +++++++++++++++++ i2csoft/i2csoft_stm32f4.go | 17 +++++++++++++++++ 6 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 i2csoft/i2csoft_nrf52840.go create mode 100644 i2csoft/i2csoft_rp2040.go create mode 100644 i2csoft/i2csoft_stm32f4.go diff --git a/i2csoft/i2csoft_atsamd51.go b/i2csoft/i2csoft_atsamd51.go index 8b8b384..9d342af 100644 --- a/i2csoft/i2csoft_atsamd51.go +++ b/i2csoft/i2csoft_atsamd51.go @@ -4,20 +4,14 @@ package i2csoft import ( - "device/arm" + "device" ) +// wait waits for half the time of the SCL operation interval. It is set to +// about 100 kHz. func (i2c *I2C) wait() { - // atsamd51 - // 1 : about 388kHz - // 17 : about 97kHz - - wait := 1 - if i2c.baudrate < 400*1e3 { - wait = 17 - } - + wait := 20 for i := 0; i < wait; i++ { - arm.Asm(`nop`) + device.Asm(`nop`) } } diff --git a/i2csoft/i2csoft_esp32.go b/i2csoft/i2csoft_esp32.go index b9bee10..6f765e2 100644 --- a/i2csoft/i2csoft_esp32.go +++ b/i2csoft/i2csoft_esp32.go @@ -7,16 +7,10 @@ import ( "device" ) +// wait waits for half the time of the SCL operation interval. It is set to +// about 100 kHz. func (i2c *I2C) wait() { - // atsamd51 - // 10 : about 387kHz - // 56 : about 99kHz - - wait := 10 - if i2c.baudrate < 400*1e3 { - wait = 56 - } - + wait := 60 for i := 0; i < wait; i++ { device.Asm(`nop`) } diff --git a/i2csoft/i2csoft_nrf52840.go b/i2csoft/i2csoft_nrf52840.go new file mode 100644 index 0000000..6bc05f4 --- /dev/null +++ b/i2csoft/i2csoft_nrf52840.go @@ -0,0 +1,17 @@ +//go:build nrf52840 +// +build nrf52840 + +package i2csoft + +import ( + "device" +) + +// wait waits for half the time of the SCL operation interval. It is set to +// about 100 kHz. +func (i2c *I2C) wait() { + wait := 26 + for i := 0; i < wait; i++ { + device.Asm(`nop`) + } +} diff --git a/i2csoft/i2csoft_other.go b/i2csoft/i2csoft_other.go index f305533..412838e 100644 --- a/i2csoft/i2csoft_other.go +++ b/i2csoft/i2csoft_other.go @@ -1,5 +1,5 @@ -//go:build !esp32 && !atsamd51 && !atsame5x -// +build !esp32,!atsamd51,!atsame5x +//go:build !esp32 && !atsamd51 && !atsame5x && !stm32f4 && !rp2040 && ! nrf52840 +// +build !esp32,!atsamd51,!atsame5x,!stm32f4,!rp2040,!nrf52840 package i2csoft @@ -7,15 +7,9 @@ import ( "device" ) +// wait waits for half the time of the SCL operation interval. func (i2c *I2C) wait() { - // atsamd21 @ 48MHz - // 1 : about 360kHz - // 24 : about 96kHz - wait := 1 - if i2c.baudrate < 400*1e3 { - wait = 19 - } - + wait := 20 for i := 0; i < wait; i++ { device.Asm(`nop`) } diff --git a/i2csoft/i2csoft_rp2040.go b/i2csoft/i2csoft_rp2040.go new file mode 100644 index 0000000..b72bf2a --- /dev/null +++ b/i2csoft/i2csoft_rp2040.go @@ -0,0 +1,17 @@ +//go:build rp2040 +// +build rp2040 + +package i2csoft + +import ( + "device" +) + +// wait waits for half the time of the SCL operation interval. It is set to +// about 100 kHz. +func (i2c *I2C) wait() { + wait := 50 + for i := 0; i < wait; i++ { + device.Asm(`nop`) + } +} diff --git a/i2csoft/i2csoft_stm32f4.go b/i2csoft/i2csoft_stm32f4.go new file mode 100644 index 0000000..b09e827 --- /dev/null +++ b/i2csoft/i2csoft_stm32f4.go @@ -0,0 +1,17 @@ +//go:build stm32f4 +// +build stm32f4 + +package i2csoft + +import ( + "device" +) + +// wait waits for half the time of the SCL operation interval. It is set to +// about 100 kHz. +func (i2c *I2C) wait() { + wait := 77 + for i := 0; i < wait; i++ { + device.Asm(`nop`) + } +}