aboutsummaryrefslogtreecommitdiff
path: root/gyroscope.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-03-05 13:29:45 +0100
committerLars-Dominik Braun <lars@6xq.net>2014-03-05 13:29:45 +0100
commit88b71e25e2463aa6425a01b60b171f36f1029ea6 (patch)
tree94fd522a4ea789c1cfb03040d529befce918e0d9 /gyroscope.c
parent85ec57bb6f545084426527ecc80269544b904067 (diff)
downloadhourglass-88b71e25e2463aa6425a01b60b171f36f1029ea6.tar.gz
hourglass-88b71e25e2463aa6425a01b60b171f36f1029ea6.tar.bz2
hourglass-88b71e25e2463aa6425a01b60b171f36f1029ea6.zip
i2c: Add multi write
Diffstat (limited to 'gyroscope.c')
-rw-r--r--gyroscope.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/gyroscope.c b/gyroscope.c
index 0f932c2..23fa197 100644
--- a/gyroscope.c
+++ b/gyroscope.c
@@ -41,23 +41,16 @@ void gyroscopeInit () {
/* XXX: make nonblocking */
void gyroscopeStart () {
- /* XXX: implement multi-write */
- /* disable power-down-mode */
- if (!twWrite (L3GD20, L3GD20_CTRLREG1, 0b00001111)) {
- printf ("cannot start write\n");
- }
- sleepwhile (twr.status == TWST_WAIT);
- printf ("final twi status was %i\n", twr.status);
-
- /* enable drdy interrupt */
- if (!twWrite (L3GD20, L3GD20_CTRLREG3, 0b00001000)) {
- printf ("cannot start write\n");
- }
- sleepwhile (twr.status == TWST_WAIT);
- printf ("final twi status was %i\n", twr.status);
+ /* configuration:
+ * disable power-down-mode
+ * defaults
+ * enable drdy interrupt
+ * select 500dps
+ */
+ uint8_t data[] = {0b00001111, 0b0, 0b00001000, 0b00010000};
- /* select 500dps */
- if (!twWrite (L3GD20, L3GD20_CTRLREG4, 0b00010000)) {
+ if (!twRequest (TWM_WRITE, L3GD20, L3GD20_CTRLREG1, data,
+ sizeof (data)/sizeof (*data))) {
printf ("cannot start write\n");
}
sleepwhile (twr.status == TWST_WAIT);
@@ -68,7 +61,7 @@ bool gyroscopeRead () {
if (drdy) {
drdy = false;
- if (!twReadMulti (L3GD20, 0x28, (uint8_t *) val, 6)) {
+ if (!twRequest (TWM_READ, L3GD20, 0x28, (uint8_t *) val, 6)) {
printf ("cannot start read\n");
}