machine: add KHz, MHz, GHz constants, deprecate TWI_FREQ_* constants

There are two main issues with these constants:

  * They don't follow the Go naming convention.
  * They call themselves "TWI", while it makes a lot more sense to refer
    to the actual name which is I2C (or I²C).

I have not removed them but just deprecated them. Perhaps we can remove
them when we move towards version 1.0.
This commit is contained in:
Ayke van Laethem
2022-09-16 13:50:48 +02:00
committed by Ron Evans
parent bc946f346d
commit 7513fa2c96
11 changed files with 24 additions and 29 deletions
+2 -2
View File
@@ -230,7 +230,7 @@ func (i2c *I2C) Configure(config I2CConfig) error {
// Default I2C bus speed is 100 kHz.
if config.Frequency == 0 {
config.Frequency = TWI_FREQ_100KHZ
config.Frequency = 100 * KHz
}
// Default I2C pins if not set.
if config.SDA == 0 && config.SCL == 0 {
@@ -253,7 +253,7 @@ func (i2c *I2C) Configure(config I2CConfig) error {
(nrf.GPIO_PIN_CNF_DRIVE_S0D1 << nrf.GPIO_PIN_CNF_DRIVE_Pos) |
(nrf.GPIO_PIN_CNF_SENSE_Disabled << nrf.GPIO_PIN_CNF_SENSE_Pos))
if config.Frequency == TWI_FREQ_400KHZ {
if config.Frequency >= 400*KHz {
i2c.Bus.FREQUENCY.Set(nrf.TWI_FREQUENCY_FREQUENCY_K400)
} else {
i2c.Bus.FREQUENCY.Set(nrf.TWI_FREQUENCY_FREQUENCY_K100)