From e25b93b0cba7a9a49c6280f81f7c9c087eb8345f Mon Sep 17 00:00:00 2001 From: Stefan Rupp Date: Sun, 2 Mar 2014 07:18:48 +0100 Subject: [PATCH] implemented ledcontroller module --- Makefile | 6 +- led1642gw.c | 18 ----- ledcontroller.c | 117 +++++++++++++++++++++++++++++++++ led1642gw.h => ledcontroller.h | 14 ++-- main.c | 2 + 5 files changed, 130 insertions(+), 27 deletions(-) delete mode 100644 led1642gw.c create mode 100644 ledcontroller.c rename led1642gw.h => ledcontroller.h (67%) diff --git a/Makefile b/Makefile index c49d003..be88002 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PRG = rgbyteclock -OBJ = rgbyteclock.o timer.o lcd.o main.o rtc.o spi.o ringbuffer.o crc.o led1642gw.o +OBJ = rgbyteclock.o timer.o lcd.o main.o rtc.o spi.o ringbuffer.o crc.o ledcontroller.o MCU_TARGET = atmega164a OPTIMIZE = -Os @@ -25,7 +25,7 @@ $(PRG).elf: $(OBJ) @echo # dependency: -rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o spi.o led1642gw.o +rgbyteclock.o: timer.o lcd.o rgbyteclock.h rtc.o spi.o ledcontroller.o main.o: rgbyteclock.o lcd.o spi.o led1642gw.o timer.o: timer.h lcd.o: lcd.h timer.o @@ -33,7 +33,7 @@ rtc.o: rtc.h spi.o: spi.h crc.o ringbuffer.o ringbuffer.o: ringbuffer.h crc.o: crc.h -led1642gw.o: led1642gw.h +ledcontroller.o: ledcontroller.h clean: rm -rf *.o $(PRG).elf *.eps *.png *.pdf *.bak diff --git a/led1642gw.c b/led1642gw.c deleted file mode 100644 index bfdf031..0000000 --- a/led1642gw.c +++ /dev/null @@ -1,18 +0,0 @@ - -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. - * (c) 2014 Stefan Rupp - * ---------------------------------------------------------------------------- - */ - - - -void led1642_init(void) -{ - -} - diff --git a/ledcontroller.c b/ledcontroller.c new file mode 100644 index 0000000..d1a005c --- /dev/null +++ b/ledcontroller.c @@ -0,0 +1,117 @@ + +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. + * (c) 2014 Stefan Rupp + * ---------------------------------------------------------------------------- + */ + + +#include "ledcontroller.h" +#include + + +#define NUM_LED1642GW_ICs (3) +#define NUM_LED1642GW_CHANNELS (16) +#define NUM_CHANNELS (NUM_LED1642GW_CHANNELS*NUM_LED1642GW_ICs) + +static uint16_t ledbuffer[NUM_CHANNELS]; + +static int8_t get_channel_from_lednum(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b) +{ + uint8_t ret; + + if (lednum < 15) { + *channel_r = 3*lednum; + *channel_g = 3*lednum+1; + *channel_b = 3*lednum+2; + if ( lednum >= 10 ) { + *channel_r += 2; + *channel_g += 2; + *channel_b += 2; + } + else if ( lednum >= 5 ) { + *channel_r += 1; + *channel_g += 1; + *channel_b += 1; + } + ret = 1; + } + else { + ret = 0; + } + + return ret; +} + +static void write_data(uint16_t data, uint8_t le_clocks) +{ + PORTC &= ~(1<=le_clocks; bit--) { + if(data&mask) { PORTC |= (1<>= 1; + } + PORTC |= (1<=0; bit--) { + if(data&mask) { PORTC |= (1<>= 1; + } +} + +static void write_data_latch(uint16_t data) +{ + write_data(data, 4); +} + +static void write_global_latch(uint16_t data) +{ + write_data(data, 6); +} + + +void ledcontroller_init(void) +{ + + DDRC |= (1< 0 ) { + ledbuffer[c_r] = red; + ledbuffer[c_g] = green; + ledbuffer[c_b] = blue; + } +} + + +void led_flush(void) +{ + for (uint8_t i=0; i +#include // ==> _NOP() #include "timer.h" -#include -void led1642_init(void); +void ledcontroller_init(void); +void led_set(uint8_t lednum, uint16_t red, uint16_t green, uint16_t blue); +void led_flush(void); - -#endif //LED1642GW_H +#endif // LEDCONTROLLER_H diff --git a/main.c b/main.c index 226e855..5f63140 100644 --- a/main.c +++ b/main.c @@ -14,12 +14,14 @@ #include "lcd.h" #include "rgbyteclock.h" #include "spi.h" +#include "ledcontroller.h" int main(void) { timer_init(); spi_slave_init(); + ledcontroller_init(); lcd_init(); rgbyteclock();