fixed stuff in ledcontroller.c

This commit is contained in:
Stefan Rupp 2014-03-12 23:46:14 +01:00
parent bad75eb419
commit a1aa846050

View File

@ -18,13 +18,14 @@
#include "ledcontroller.h" #include "ledcontroller.h"
#include <string.h> #include <string.h>
#include <util/delay.h>
#define NUM_LED1642GW_ICs (3) #define NUM_LED1642GW_ICs (3)
#define NUM_LED1642GW_CHANNELS (16) #define NUM_LED1642GW_CHANNELS (16)
#define NUM_CHANNELS (NUM_LED1642GW_CHANNELS*NUM_LED1642GW_ICs) #define NUM_LED_CHANNELS (NUM_LED1642GW_CHANNELS*NUM_LED1642GW_ICs)
static uint16_t ledbuffer[NUM_CHANNELS]; static uint16_t ledbuffer[NUM_LED_CHANNELS];
static int8_t map_lednum_to_channels(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b) static int8_t map_lednum_to_channels(uint8_t lednum, uint8_t *channel_r, uint8_t *channel_g, uint8_t *channel_b)
{ {
@ -53,6 +54,7 @@ static int8_t map_lednum_to_channels(uint8_t lednum, uint8_t *channel_r, uint8_t
return ret; return ret;
} }
#if 0
static void write_data(uint16_t data, uint8_t le_clocks) static void write_data(uint16_t data, uint8_t le_clocks)
{ {
PORTC &= ~(1<<PC3); PORTC &= ~(1<<PC3);
@ -62,20 +64,55 @@ static void write_data(uint16_t data, uint8_t le_clocks)
for (bit=15; bit>=le_clocks; bit--) { for (bit=15; bit>=le_clocks; bit--) {
if(data&mask) { PORTC |= (1<<PC4); } if(data&mask) { PORTC |= (1<<PC4); }
else { PORTC &= ~(1<<PC4); } else { PORTC &= ~(1<<PC4); }
_NOP();
PORTC |= (1<<PC3); PORTC |= (1<<PC3);
PORTC &= ~(1<<PC3);
mask >>= 1; mask >>= 1;
PORTC &= ~(1<<PC3);
_NOP();
} }
PORTC |= (1<<PC2); PORTC |= (1<<PC2);
for (/*noting to initialize*/; bit>=0; bit--) { for (/*noting to initialize*/; bit>=0; bit--) {
if(data&mask) { PORTC |= (1<<PC4); } if(data&mask) { PORTC |= (1<<PC4); }
else { PORTC &= ~(1<<PC4); } else { PORTC &= ~(1<<PC4); }
_NOP();
PORTC |= (1<<PC3); PORTC |= (1<<PC3);
mask >>= 1;
PORTC &= ~(1<<PC3); PORTC &= ~(1<<PC3);
_NOP();
}
PORTC &= ~(1<<PC3);
}
#endif
static void write_data(uint16_t data, uint8_t le_clocks)
{
uint16_t mask = 0x8000;
int8_t bit;
PORTC &= ~(1<<PC2);
for (bit=15; bit>=le_clocks; bit--) {
PORTC &= ~(1<<PC3);
if(data&mask) { PORTC |= (1<<PC4); }
else { PORTC &= ~(1<<PC4); }
PORTC |= (1<<PC3);
mask >>= 1; mask >>= 1;
} }
PORTC |= (1<<PC2);
for (/*noting to initialize*/; bit>=0; bit--) {
PORTC &= ~(1<<PC3);
if(data&mask) { PORTC |= (1<<PC4); }
else { PORTC &= ~(1<<PC4); }
PORTC |= (1<<PC3);
mask >>= 1;
} }
PORTC &= ~(1<<PC3);
PORTC &= ~(1<<PC2);
PORTC &= ~(1<<PC4);
}
static void write_data_latch(uint16_t data) static void write_data_latch(uint16_t data)
{ {
write_data(data, 4); write_data(data, 4);
@ -91,19 +128,23 @@ void ledcontroller_turn_all_on(void)
{ {
write_data(0xffff, 2); write_data(0xffff, 2);
_delay_us(10);
write_data(0xffff, 2); write_data(0xffff, 2);
_delay_us(10);
write_data(0xffff, 2); write_data(0xffff, 2);
_delay_us(10);
} }
void ledcontroller_turn_all_off(void) void ledcontroller_turn_all_off(void)
{ {
write_data(0xffff, 2); write_data(0x0000, 2);
write_data(0xffff, 2); _delay_us(10);
write_data(0xffff, 2); write_data(0x0000, 2);
_delay_us(10);
write_data(0x0000, 2);
_delay_us(10);
} }
@ -135,9 +176,10 @@ void led_set(uint8_t lednum, uint16_t red, uint16_t green, uint16_t blue)
void led_flush(void) void led_flush(void)
{ {
for (uint8_t i=0; i<NUM_CHANNELS-1; i++) { for (uint8_t i=0; i<NUM_LED_CHANNELS-1; i++) {
write_data_latch(ledbuffer[i]); write_data_latch(ledbuffer[i]);
_delay_us(10);
} }
write_global_latch(ledbuffer[NUM_CHANNELS-1]); write_global_latch(ledbuffer[NUM_LED_CHANNELS-1]);
} }