From c6bef66427c75cb963cde3754edc1967966e6d80 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 4 Dec 2012 07:27:49 -0300 Subject: [PATCH] tornado/fw/led.[ch]: add led_show_pgm to display row from Flash --- tornado/fw/led.c | 22 +++++++++++++++++++--- tornado/fw/led.h | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tornado/fw/led.c b/tornado/fw/led.c index 680bae0..defbd6d 100644 --- a/tornado/fw/led.c +++ b/tornado/fw/led.c @@ -15,6 +15,7 @@ #include #include +#include #define F_CPU 8000000UL #include @@ -26,7 +27,7 @@ void led_show(const uint8_t p[LED_BYTES]) { uint8_t i; - for (i = 0; i != 8; i++) { + for (i = 0; i != LED_BYTES; i++) { while (!(UCSR0A & (1 << UDRE0))); UDR0 = p[i]; } @@ -52,11 +53,26 @@ void led_show(const uint8_t p[LED_BYTES]) } +void led_show_pgm(const prog_uint8_t p[LED_BYTES]) +{ + uint8_t i; + + for (i = 0; i != LED_BYTES; i++) { + while (!(UCSR0A & (1 << UDRE0))); + UDR0 = pgm_read_byte(p+i); + } + + _delay_us(4); /* 16 bits at 4 MHz */ + SET(LED_LCLK); + CLR(LED_LCLK); +} + + void led_off(void) { - static uint8_t zero[LED_BYTES]; + static uint8_t zero[LED_BYTES] PROGMEM = { 0, }; - led_show(zero); + led_show_pgm(zero); } diff --git a/tornado/fw/led.h b/tornado/fw/led.h index 3ec539b..7d86be6 100644 --- a/tornado/fw/led.h +++ b/tornado/fw/led.h @@ -16,12 +16,15 @@ #include +#include + #define N_LEDS 64 #define LED_BYTES (N_LEDS/8) void led_show(const uint8_t p[LED_BYTES]); +void led_show_pgm(const prog_uint8_t p[LED_BYTES]); void led_off(void); void led_init(void);