From 9bc9c57fb279cca8ab679d3daa25dbbad9984b82 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 20 Jun 2012 10:41:27 -0300 Subject: [PATCH] fw/: simple image test mode (still untested) --- fw/antorcha.c | 12 ++++++++++++ fw/sweep.c | 17 +++++++++++++---- fw/sweep.h | 5 ++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/fw/antorcha.c b/fw/antorcha.c index e2d8c0b..3aab083 100644 --- a/fw/antorcha.c +++ b/fw/antorcha.c @@ -17,6 +17,16 @@ #include "rf.h" #include "dispatch.h" #include "sweep.h" +#include "image.h" + + +static struct sweep sweep = { + .wait_ticks = 100000, /* 100 ms */ + .pixel_ticks = 5000, /* 5 ms */ + .left = 0, + .right = MAX_LINES, + .forward = 1, +}; static const struct handler *protos[] = { @@ -42,5 +52,7 @@ int main(void) got = rf_recv(buf, sizeof(buf)); if (got > 2) dispatch(buf, got-2, protos); + if (!sweeping) + sweep_image(&sweep); } } diff --git a/fw/sweep.c b/fw/sweep.c index 0c1ce39..2f86442 100644 --- a/fw/sweep.c +++ b/fw/sweep.c @@ -21,7 +21,10 @@ #include "sweep.h" -static uint32_t t_sw; /* cumulative number of timer ticks in sweep */ +volatile bool sweeping = 0; + + +static volatile uint32_t t_sw; /* cumulative number of timer ticks in sweep */ static uint16_t wait_periods; /* number of periods to wait before image */ static uint16_t wait_period; /* ticks in wait period */ @@ -67,14 +70,16 @@ ISR(TIMER1_OVF_vect) /* wait until the next pixel (or slow down if we're done) */ - if (curr_line == end_line) + if (curr_line == end_line) { OCR1A = 0xffff; - else + sweeping = 0; + } else { OCR1A = pixel_ticks; + } } -void image_sweep(const struct sweep *sweep) +void sweep_image(const struct sweep *sweep) { TCCR1B = 0; /* stop the timer */ @@ -129,6 +134,10 @@ void image_sweep(const struct sweep *sweep) 1 << WGM13 | /* WG Mode 15, continued */ 1 << WGM12 | 1 << CS11; /* clkIO/8 */ + + sweeping = 1; + + sei(); } diff --git a/fw/sweep.h b/fw/sweep.h index 564976e..dbd914a 100644 --- a/fw/sweep.h +++ b/fw/sweep.h @@ -27,7 +27,10 @@ struct sweep { }; -void image_sweep(const struct sweep *sweep); +extern volatile bool sweeping; + + +void sweep_image(const struct sweep *sweep); void sweep_init(void); #endif /* !SWEEP_H */