diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2014-09-30 16:09:51 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2014-09-30 16:24:52 +0200 |
commit | 0de25bc37cddc63fbb7f83867a786eeb853aff5a (patch) | |
tree | 19f154d08580bb1efd3fe2cd1883d652def0e476 | |
parent | 74a2f8409f3bfb462de36bca04ad44ac65473f7b (diff) | |
download | hourglass-0de25bc37cddc63fbb7f83867a786eeb853aff5a.tar.gz hourglass-0de25bc37cddc63fbb7f83867a786eeb853aff5a.tar.bz2 hourglass-0de25bc37cddc63fbb7f83867a786eeb853aff5a.zip |
Reliable reboot, idle status LED indicator
-rw-r--r-- | accel.c | 2 | ||||
-rw-r--r-- | gyro.c | 2 | ||||
-rw-r--r-- | main.c | 14 | ||||
-rw-r--r-- | ui.c | 25 |
4 files changed, 29 insertions, 14 deletions
@@ -15,6 +15,7 @@ /* registers */ #define LIS302DL_WHOAMI 0xf #define LIS302DL_CTRLREG1 0x20 +#define LIS302DL_CTRLREG2 0x21 #define LIS302DL_UNUSED1 0x28 #define LIS302DL_OUTZ 0x2D @@ -84,6 +85,7 @@ void accelStart () { puts ("cannot start write"); } sleepwhile (twr.status == TWST_WAIT); + assert (twr.status == TWST_OK); puts ("accelStart done"); disableWakeup (WAKE_I2C); } @@ -17,6 +17,7 @@ #define L3GD20_CTRLREG1 0x20 #define L3GD20_CTRLREG3 0x22 #define L3GD20_CTRLREG4 0x23 +#define L3GD20_CTRLREG5 0x24 #define L3GD20_OUTZ 0x2c /* raw z value */ @@ -65,6 +66,7 @@ void gyroStart () { puts ("cannot start write"); } sleepwhile (twr.status == TWST_WAIT); + assert (twr.status == TWST_OK); puts ("gyroStart done"); disableWakeup (WAKE_I2C); } @@ -37,24 +37,10 @@ int main () { gyroInit (); accelInit (); pwmInit (); - pwmStart (); set_sleep_mode (SLEEP_MODE_IDLE); - puts ("initialization done"); - - /* global interrupt enable */ sei (); - gyroStart (); - accelStart (); - uiLoop (); - - timerStop (); - pwmStop (); - - puts ("stopped"); - - /* global interrupt disable */ cli (); while (1); @@ -149,6 +149,8 @@ static void doSelectFine () { /* Idle function, waits for timer start or select commands */ static void doIdle () { + pwmSet (horizonLed (0), 1); + if (horizonChanged) { /* start timer */ for (uint8_t i = 0; i < PWM_LED_COUNT; i++) { @@ -244,6 +246,11 @@ static void doInit () { /* get initial orientation */ h = accelGetHorizon (); if (h != HORIZON_NONE) { + /* init done */ + for (uint8_t i = 0; i < PWM_LED_COUNT; i++) { + pwmSet (horizonLed (i), PWM_OFF); + } + mode = UIMODE_IDLE; puts ("init->idle"); @@ -319,6 +326,21 @@ void uiLoop () { } #endif + /* startup, test all LED’s */ + pwmStart (); + for (uint8_t i = 0; i < PWM_LED_COUNT; i++) { + pwmSet (i, PWM_ON); + } + gyroStart (); + pwmSet (0, PWM_OFF); + accelStart (); + pwmSet (1, PWM_OFF); + + /* make sure data is read even when missing the first interrupt (i.e. + * reboot) */ + enableWakeup (WAKE_ACCEL); + enableWakeup (WAKE_GYRO); + while (1) { processSensors (); @@ -374,5 +396,8 @@ void uiLoop () { accelval[1], accelval[3], accelval[5]); #endif } + + timerStop (); + pwmStop (); } |