mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-09-03 05:19:01 +00:00
mpu6050: add functions to configure clock, and scaling for accelerometer and gyroscope
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+16
-1
@@ -32,7 +32,7 @@ func (d Device) Connected() bool {
|
||||
|
||||
// Configure sets up the device for communication.
|
||||
func (d Device) Configure() error {
|
||||
return d.bus.WriteRegister(uint8(d.Address), PWR_MGMT_1, []uint8{0})
|
||||
return d.SetClockSource(CLOCK_INTERNAL)
|
||||
}
|
||||
|
||||
// ReadAcceleration reads the current acceleration from the device and returns
|
||||
@@ -78,3 +78,18 @@ func (d Device) ReadRotation() (x int32, y int32, z int32) {
|
||||
z = int32(int16((uint16(data[4])<<8)|uint16(data[5]))) * 15625 / 2048 * 1000
|
||||
return
|
||||
}
|
||||
|
||||
// SetClockSource allows the user to configure the clock source.
|
||||
func (d Device) SetClockSource(source uint8) error {
|
||||
return d.bus.WriteRegister(uint8(d.Address), PWR_MGMT_1, []uint8{source})
|
||||
}
|
||||
|
||||
// SetFullScaleGyroRange allows the user to configure the scale range for the gyroscope.
|
||||
func (d Device) SetFullScaleGyroRange(rng uint8) error {
|
||||
return d.bus.WriteRegister(uint8(d.Address), GYRO_CONFIG, []uint8{rng})
|
||||
}
|
||||
|
||||
// SetFullScaleAccelRange allows the user to configure the scale range for the accelerometer.
|
||||
func (d Device) SetFullScaleAccelRange(rng uint8) error {
|
||||
return d.bus.WriteRegister(uint8(d.Address), ACCEL_CONFIG, []uint8{rng})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user