machine: redesign I2C interface

This commit is contained in:
Ayke van Laethem
2018-11-11 19:26:11 +01:00
parent 100901574b
commit 1ba463c7ee
4 changed files with 120 additions and 66 deletions
+5 -6
View File
@@ -11,11 +11,10 @@ func main() {
machine.I2C0.Configure(machine.I2CConfig{})
// Init BlinkM
machine.I2C0.WriteTo(0x09, []byte("o"))
machine.I2C0.WriteRegister(0x09, 'o', nil)
version := []byte{0, 0}
machine.I2C0.WriteTo(0x09, []byte("Z"))
machine.I2C0.ReadFrom(0x09, version)
machine.I2C0.ReadRegister(0x09, 'Z', version)
println("Firmware version:", string(version[0]), string(version[1]))
count := 0
@@ -23,15 +22,15 @@ func main() {
switch count {
case 0:
// Crimson
machine.I2C0.WriteTo(0x09, []byte{'n', 0xdc, 0x14, 0x3c})
machine.I2C0.WriteRegister(0x09, 'n', []byte{0xdc, 0x14, 0x3c})
count = 1
case 1:
// MediumPurple
machine.I2C0.WriteTo(0x09, []byte{'n', 0x93, 0x70, 0xdb})
machine.I2C0.WriteRegister(0x09, 'n', []byte{0x93, 0x70, 0xdb})
count = 2
case 2:
// MediumSeaGreen
machine.I2C0.WriteTo(0x09, []byte{'n', 0x3c, 0xb3, 0x71})
machine.I2C0.WriteRegister(0x09, 'n', []byte{0x3c, 0xb3, 0x71})
count = 0
}