From 5055ee55d1330b52182a35378f5b4f8055cefc54 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 22 Jul 2014 16:24:43 +0200 Subject: Convert printf into puts Removes ~1.5k code size, still not working. --- accel.c | 9 +++++---- common.h | 14 ++++++++++++-- gyro.c | 8 ++++---- i2c.c | 9 ++++----- main.c | 4 ++-- pwm.c | 1 - speaker.c | 1 - ui.c | 21 ++++++++++----------- 8 files changed, 37 insertions(+), 30 deletions(-) diff --git a/accel.c b/accel.c index 1bca794..127cc0f 100644 --- a/accel.c +++ b/accel.c @@ -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; } diff --git a/common.h b/common.h index 26b371d..5957da3 100644 --- a/common.h +++ b/common.h @@ -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 +#include +#include +#define assert(x) if (!(x)) { \ + puts("assert in " __FILE__ ":" #x); \ + sleep_enable (); \ + while (1) { \ + sleep_cpu (); \ + } \ + } #endif /* COMMON_H */ diff --git a/gyro.c b/gyro.c index 6a32ef3..35ec76b 100644 --- a/gyro.c +++ b/gyro.c @@ -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; } diff --git a/i2c.c b/i2c.c index 84479a1..d7e5058 100644 --- a/i2c.c +++ b/i2c.c @@ -2,7 +2,6 @@ #include #include #include -#include #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; } } diff --git a/main.c b/main.c index c5a7b1d..de3cda2 100644 --- a/main.c +++ b/main.c @@ -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 (); diff --git a/pwm.c b/pwm.c index 669d9c3..a504c36 100644 --- a/pwm.c +++ b/pwm.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "speaker.h" diff --git a/speaker.c b/speaker.c index 92c1e78..ec5da36 100644 --- a/speaker.c +++ b/speaker.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "speaker.h" diff --git a/ui.c b/ui.c index cadbcbf..8d621e4 100644 --- a/ui.c +++ b/ui.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #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 (); } } -- cgit v1.2.3