diff options
-rw-r--r-- | accel.c | 9 | ||||
-rw-r--r-- | common.h | 14 | ||||
-rw-r--r-- | gyro.c | 8 | ||||
-rw-r--r-- | i2c.c | 9 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | pwm.c | 1 | ||||
-rw-r--r-- | speaker.c | 1 | ||||
-rw-r--r-- | ui.c | 21 |
8 files changed, 37 insertions, 30 deletions
@@ -75,10 +75,10 @@ void accelStart () { if (!twRequest (TWM_WRITE, LIS302DL, LIS302DL_CTRLREG1, data, sizeof (data)/sizeof (*data))) { - printf ("cannot start write\n"); + puts ("cannot start write"); } sleepwhile (twr.status == TWST_WAIT); - printf ("final twi status was %i\n", twr.status); + puts ("accelStart done"); } /* register shake gesture @@ -162,7 +162,8 @@ bool accelProcess () { reading = false; return true; } else if (twr.status == TWST_ERR) { - printf ("accel i2c error %x at step %i\n", twr.error, twr.step); + puts ("accel i2c error: "); + fwrite ((void *) &twr.error, sizeof (twr.error), 1, stdout); reading = false; } } else { @@ -170,7 +171,7 @@ bool accelProcess () { /* new data available in device buffer and bus is free */ if (!twRequest (TWM_READ, LIS302DL, LIS302DL_OUTZ, (uint8_t *) &zval, sizeof (zval))) { - printf ("cannot start read\n"); + puts ("cannot start read"); } else { reading = true; } @@ -10,8 +10,18 @@ sleep_disable (); #define __unused__ __attribute__ ((unused)) -/* print assert messages */ -#define __ASSERT_USE_STDERR + +/* define lightweight assert (without printf) that halts the cpu */ +#include <stdio.h> +#include <avr/sleep.h> +#include <avr/interrupt.h> +#define assert(x) if (!(x)) { \ + puts("assert in " __FILE__ ":" #x); \ + sleep_enable (); \ + while (1) { \ + sleep_cpu (); \ + } \ + } #endif /* COMMON_H */ @@ -56,10 +56,10 @@ void gyroStart () { if (!twRequest (TWM_WRITE, L3GD20, L3GD20_CTRLREG1, data, sizeof (data)/sizeof (*data))) { - printf ("cannot start write\n"); + puts ("cannot start write"); } sleepwhile (twr.status == TWST_WAIT); - printf ("final twi status was %i\n", twr.status); + puts ("gyroStart done"); } /* calculate ticks for z rotation @@ -95,7 +95,7 @@ bool gyroProcess () { reading = false; return true; } else if (twr.status == TWST_ERR) { - printf ("gyro i2c error\n"); + puts ("gyro i2c error"); reading = false; } } else { @@ -103,7 +103,7 @@ bool gyroProcess () { /* new data available in device buffer and bus is free */ if (!twRequest (TWM_READ, L3GD20, L3GD20_OUTZ, (uint8_t *) &zval, sizeof (zval))) { - printf ("cannot start read\n"); + puts ("cannot start read"); } else { reading = true; } @@ -2,7 +2,6 @@ #include <util/twi.h> #include <avr/interrupt.h> #include <stdlib.h> -#include <assert.h> #include "i2c.h" #include "common.h" @@ -40,7 +39,7 @@ static void twWaitRaw () { static bool twWriteRaw (const uint8_t data) { TWDR = data; if (TWCR & (1 << TWWC)) { - printf("write collision\n"); + puts ("write collision"); return false; } else { return true; @@ -137,7 +136,7 @@ static void twIntWrite () { break; default: - printf ("nope\n"); + assert (0 && "nope"); break; } } @@ -237,7 +236,7 @@ static void twIntRead () { break; default: - printf ("twIntRead: nope\n"); + assert (0 && "twIntRead: nope\n"); break; } } @@ -253,7 +252,7 @@ ISR(TWI_vect) { break; default: - printf ("nope\n"); + assert (0 && "nope\n"); break; } } @@ -41,7 +41,7 @@ int main () { pwmInit (); set_sleep_mode (SLEEP_MODE_IDLE); - printf ("initialization done\n"); + puts ("initialization done"); /* global interrupt enable */ sei (); @@ -53,7 +53,7 @@ int main () { timerStop (); pwmStop (); - printf ("stopped\n"); + puts ("stopped"); /* global interrupt disable */ cli (); @@ -6,7 +6,6 @@ #include <avr/io.h> #include <avr/interrupt.h> #include <stdbool.h> -#include <assert.h> #include <stdlib.h> #include "speaker.h" @@ -7,7 +7,6 @@ #include <avr/interrupt.h> #include <util/delay.h> #include <stdbool.h> -#include <assert.h> #include <stdlib.h> #include "speaker.h" @@ -3,7 +3,6 @@ #include <util/delay.h> #include <avr/sleep.h> #include <stdio.h> -#include <assert.h> #include <stdlib.h> #include "ui.h" @@ -85,7 +84,7 @@ static void doSelectCoarse () { /* stop selection */ accelResetShakeCount (); mode = UIMODE_SELECT_FINE; - printf ("selectcoarse->selectfine(%i)\n", coarseSeconds); + puts ("selectcoarse->selectfine"); speakerStart (SPEAKER_BEEP); return; } @@ -95,7 +94,7 @@ static void doSelectCoarse () { if (abs (zticks) > 0) { gyroResetZTicks (); coarseSeconds = limits(coarseSeconds + zticks*60*5, 0, 60*60); - printf ("c:%it:%i\n", coarseSeconds, zticks); + //printf ("c:%it:%i\n", coarseSeconds, zticks); pwmStop (); const uint8_t tenminutes = coarseSeconds/60/10; @@ -117,7 +116,7 @@ static void doSelectFine () { substep = 3; secPerSubstep = (coarseSeconds + fineSeconds)/(6*3); mode = UIMODE_IDLE; - printf ("selectfine->idle(%u,%u)\n", coarseSeconds + fineSeconds, secPerSubstep); + puts ("selectfine->idle"); speakerStart (SPEAKER_BEEP); return; } @@ -127,7 +126,7 @@ static void doSelectFine () { if (abs (zticks) > 0) { gyroResetZTicks (); fineSeconds = limits(fineSeconds + zticks*30, -5*60, 5*60); - printf ("f:%it:%i\n", fineSeconds, zticks); + //printf ("f:%it:%i\n", fineSeconds, zticks); pwmStop (); const uint8_t minutes = abs (fineSeconds)/60; @@ -153,13 +152,13 @@ static void doIdle () { /* start timer */ mode = UIMODE_RUN; timerStart (); - printf ("idle->run\n"); + puts ("idle->run"); speakerStart (SPEAKER_BEEP); } else if (accelGetShakeCount () >= 2) { /* set timer */ accelResetShakeCount (); mode = UIMODE_SELECT_COARSE; - printf ("idle->select\n"); + puts ("idle->select"); speakerStart (SPEAKER_BEEP); return; } @@ -179,7 +178,7 @@ static void doRun () { substep = 3; substepsec = 0; } - printf("s:%uss:%u\n", step, substep); + //printf("s:%uss:%u\n", step, substep); if (step == 0) { /* blink all leds */ pwmStop (); @@ -189,7 +188,7 @@ static void doRun () { pwmStart (); step = ALARM_TIME; mode = UIMODE_ALARM; - printf ("run->alarm\n"); + puts ("run->alarm"); speakerStart (SPEAKER_BEEP); } else { pwmStop (); @@ -205,7 +204,7 @@ static void doRun () { } else if (horizonChanged) { /* stop timer */ mode = UIMODE_IDLE; - printf ("run->idle (stopped)\n"); + puts ("run->idle (stopped)"); speakerStart (SPEAKER_BEEP); } } @@ -232,7 +231,7 @@ static void doInit () { h = accelGetHorizon (); if (h != HORIZON_NONE) { mode = UIMODE_IDLE; - printf ("init->idle\n"); + puts ("init->idle"); pwmStop (); } } |