Skip to content

Commit d02d21e

Browse files
jphastingsdeadprogram
authored andcommitted
feat: allow gps init with address
Adafruit's Mini GPS PA1010D Module works with this device driver, but requires 0x10 as the address, rather than 0x42. This change allows the device to be initialised with whatever i2c address is needed, while maintaining backward compatibility. Adds new constants to allow easy configuration of both the ublox device and the PA1010D.
1 parent 805e2a0 commit d02d21e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

examples/gps/i2c/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func main() {
1111
println("GPS I2C Example")
1212
machine.I2C0.Configure(machine.I2CConfig{})
13-
ublox := gps.NewI2C(machine.I2C0)
13+
ublox := gps.NewI2CWithAddress(machine.I2C0, gps.UBLOX_I2C_ADDRESS)
1414
parser := gps.NewParser()
1515
var fix gps.Fix
1616
for {

gps/gps.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,16 @@ func NewUART(uart drivers.UART) Device {
6969
}
7070

7171
// NewI2C creates a new I2C GPS connection.
72+
// Uses the default i2c address (0x42) for backward compatibility reasons.
7273
func NewI2C(bus drivers.I2C) Device {
74+
return NewI2CWithAddress(bus, I2C_ADDRESS)
75+
}
76+
77+
// NewI2CWithAddress creates a new I2C GPS connection on the provided address
78+
func NewI2CWithAddress(bus drivers.I2C, i2cAddress uint16) Device {
7379
return Device{
7480
bus: bus,
75-
address: I2C_ADDRESS,
81+
address: i2cAddress,
7682
buffer: make([]byte, bufferSize),
7783
bufIdx: bufferSize,
7884
sentence: strings.Builder{},

gps/registers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ package gps
44

55
// The I2C address which this device listens to.
66
const (
7-
I2C_ADDRESS = 0x42
7+
// To ensure backward compatibility
8+
I2C_ADDRESS = UBLOX_I2C_ADDRESS
9+
10+
UBLOX_I2C_ADDRESS = 0x42
11+
PA1010D_I2C_ADDRESS = 0x10
812
)
913

1014
const (

0 commit comments

Comments
 (0)