diff --git a/examples/gps/i2c/main.go b/examples/gps/i2c/main.go index 8f7873c..123cc26 100644 --- a/examples/gps/i2c/main.go +++ b/examples/gps/i2c/main.go @@ -10,7 +10,7 @@ import ( func main() { println("GPS I2C Example") machine.I2C0.Configure(machine.I2CConfig{}) - ublox := gps.NewI2C(machine.I2C0) + ublox := gps.NewI2CWithAddress(machine.I2C0, gps.UBLOX_I2C_ADDRESS) parser := gps.NewParser() var fix gps.Fix for { diff --git a/gps/gps.go b/gps/gps.go index 86bfd6a..16ba870 100644 --- a/gps/gps.go +++ b/gps/gps.go @@ -69,10 +69,16 @@ func NewUART(uart drivers.UART) Device { } // NewI2C creates a new I2C GPS connection. +// Uses the default i2c address (0x42) for backward compatibility reasons. func NewI2C(bus drivers.I2C) Device { + return NewI2CWithAddress(bus, I2C_ADDRESS) +} + +// NewI2CWithAddress creates a new I2C GPS connection on the provided address +func NewI2CWithAddress(bus drivers.I2C, i2cAddress uint16) Device { return Device{ bus: bus, - address: I2C_ADDRESS, + address: i2cAddress, buffer: make([]byte, bufferSize), bufIdx: bufferSize, sentence: strings.Builder{}, diff --git a/gps/registers.go b/gps/registers.go index 5ef9918..6d74d87 100644 --- a/gps/registers.go +++ b/gps/registers.go @@ -4,7 +4,11 @@ package gps // The I2C address which this device listens to. const ( - I2C_ADDRESS = 0x42 + // To ensure backward compatibility + I2C_ADDRESS = UBLOX_I2C_ADDRESS + + UBLOX_I2C_ADDRESS = 0x42 + PA1010D_I2C_ADDRESS = 0x10 ) const (