convert color[3][16] to color[16][3]

This commit is contained in:
Olaf Rempel 2012-03-11 12:42:29 +01:00
parent 0d9b9ba985
commit f92a03776d
4 changed files with 35 additions and 41 deletions

22
main.c
View File

@ -163,32 +163,24 @@ int main(void)
/* wait for complete update */
rgb_update(COLOR_MASK, 1);
_delay_ms(1);
// _delay_ms(1);
#if 1
step++;
if (step == 16) {
step = 0;
x = sequence_chase(x, &xdir, 0x1F1F);
}
#if 1
uint8_t color[3] = { 0, 0, 0 };
ramp = color_ramp(ramp +1, color);
ramp = color_ramp(ramp +1, chan_value[x]);
uint8_t i, j;
for (i = 0; i < 16; i++) {
for (j = 0; j < 3; j++) {
#if 1
if (x == i) {
chan_value[j][i] = color[j];
} else if (chan_value[j][i] > 0) {
uint8_t tmp = (chan_value[j][i] >> 5);
chan_value[j][i] -= (tmp > 0) ? tmp : 1;
}
#else
chan_value[j][i] = color[j];
#endif
if (x != i) {
chan_value[i][0] = 0;
chan_value[i][1] = 0;
chan_value[i][2] = 0;
}
}
#endif

View File

@ -217,7 +217,7 @@ void mpm_check_transfer(void)
uint8_t pos = 1;
uint8_t cause = CAUSE_SUCCESS;
uint8_t (*baseptr)[3][16] = (rx_cmd == CMD_WRITE_RAW_COLOR) ? &chan_value : &nvram_data.initialRGB;
uint8_t (*baseptr)[16][3] = (rx_cmd == CMD_WRITE_RAW_COLOR) ? &chan_value : &nvram_data.initialRGB;
while ((pos < rx_length)) {
if ((chan >= 16) || ((pos +2) >= MPM_MAX_DATA_SIZE)) {
@ -225,9 +225,9 @@ void mpm_check_transfer(void)
break;
}
baseptr[0][COLOR_RED][chan] = mpm_data[pos++];
baseptr[0][COLOR_GREEN][chan] = mpm_data[pos++];
baseptr[0][COLOR_BLUE][chan] = mpm_data[pos++];
baseptr[0][chan][COLOR_RED] = mpm_data[pos++];
baseptr[0][chan][COLOR_GREEN] = mpm_data[pos++];
baseptr[0][chan][COLOR_BLUE] = mpm_data[pos++];
chan++;
}
@ -250,7 +250,7 @@ void mpm_check_transfer(void)
uint8_t pos = 0;
uint8_t cause = CAUSE_SUCCESS;
uint8_t (*baseptr)[3][16] = (rx_cmd == CMD_READ_RAW_COLOR) ? &chan_value : &nvram_data.initialRGB;
uint8_t (*baseptr)[16][3] = (rx_cmd == CMD_READ_RAW_COLOR) ? &chan_value : &nvram_data.initialRGB;
while (count--) {
if ((chan >= 16) || ((pos +2) >= MPM_MAX_DATA_SIZE)) {
@ -258,9 +258,9 @@ void mpm_check_transfer(void)
break;
}
mpm_data[pos++] = baseptr[0][COLOR_RED][chan];
mpm_data[pos++] = baseptr[0][COLOR_GREEN][chan];
mpm_data[pos++] = baseptr[0][COLOR_BLUE][chan];
mpm_data[pos++] = baseptr[0][chan][COLOR_RED];
mpm_data[pos++] = baseptr[0][chan][COLOR_GREEN];
mpm_data[pos++] = baseptr[0][chan][COLOR_BLUE];
chan++;
}

View File

@ -30,14 +30,16 @@
struct _nvdata {
uint16_t nvram_size; /* first */
uint8_t initialRGB[3][16]; /* initial color values */
uint8_t initialRGB[16][3]; /* initial color values */
uint16_t nvram_crc; /* last */
};
#define NVRAM_DEFAULTS {\
.initialRGB = { { 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0x20, 0x40, 0x80, 0xFF, }, \
{ 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x40, 0x80, 0xFF, }, \
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x20, 0x40, 0x80, 0xFF, } }, \
.initialRGB = { { 0xFF, 0x00, 0x00 }, { 0xFF, 0x80, 0x00 }, { 0xFF, 0xFF, 0x00 }, { 0x80, 0xFF, 0x00 }, \
{ 0x00, 0xFF, 0x00 }, { 0x00, 0xFF, 0x80 }, { 0x00, 0xFF, 0xFF }, { 0x00, 0x80, 0xFF }, \
{ 0x00, 0x00, 0xFF }, { 0x80, 0x00, 0xFF }, { 0xFF, 0x00, 0xFF }, { 0xFF, 0x00, 0x80 }, \
{ 0x20, 0x20, 0x20 }, { 0x40, 0x40, 0x40 }, { 0x80, 0x80, 0x80 }, { 0xFF, 0xFF, 0xFF } \
}, \
};
/* eeprom.c vars */
@ -52,7 +54,7 @@ void mpm_init(void);
void mpm_check_transfer(void);
/* rgbctrl.c vars */
extern uint8_t chan_value[3][16];
extern uint8_t chan_value[16][3];
/* rgbctrl.c funcs */
void rgb_init(void);

View File

@ -25,7 +25,7 @@
#include "rgb16mpm.h"
/* 16 values per color */
uint8_t chan_value[3][16];
uint8_t chan_value[16][3];
/* (16 +1) * 4 values (portA, portC, OCR0, flags) per color */
static uint8_t chan_rawdata[3][17 * 4];
@ -189,9 +189,9 @@ ISR(TIMER0_COMP_vect, ISR_NAKED)
}
/* calc chan_valueX => chan_rawdataX */
static void calculate_timer_values(uint8_t *value, uint8_t *pDataStart)
static void calculate_timer_values(uint8_t color)
{
uint8_t *pData = pDataStart +4; /* skip first entry (init) */
uint8_t *pData = &chan_rawdata[color][4]; /* skip first entry (init) */
uint8_t index = 0;
uint16_t chan_used = 0xFFFF;
uint16_t chan_init = 0xFFFF;
@ -205,22 +205,22 @@ static void calculate_timer_values(uint8_t *value, uint8_t *pDataStart)
uint16_t chan_mask = 0x0001;
for (i = 0; i < 16; i++) {
uint8_t value = chan_value[i][color];
/* skip if channel already used */
if (chan_used & chan_mask)
{
if (chan_used & chan_mask) {
/* channel is not used (value 0x00) */
if (value[i] == 0x00) {
if (value == 0x00) {
chan_init &= (~chan_mask);
chan_used &= (~chan_mask);
/* found a new lower value */
} else if (value[i] < min_value) {
min_value = value[i];
} else if (value < min_value) {
min_value = value;
chan_tmp = chan_used & (~chan_mask);
/* found another value with the same value */
} else if (value[i] == min_value) {
} else if (value == min_value) {
chan_tmp &= (~chan_mask);
}
}
@ -257,7 +257,7 @@ static void calculate_timer_values(uint8_t *value, uint8_t *pDataStart)
}
/* first slot/init: enable only channels that are > 0 */
pData = pDataStart;
pData = &chan_rawdata[color][0];
*pData++ = (chan_init & 0xFF); /* PORTA */
*pData++ = ((chan_init >> 8) & 0xFF); /* PORTC */
}
@ -270,15 +270,15 @@ uint8_t rgb_update(uint8_t dirty_mask, uint8_t blocking)
do {
if ((chan_dirty & (1<<COLOR_RED)) && (nextColor == COLOR_BLUE)) {
calculate_timer_values(chan_value[COLOR_RED], chan_rawdata[COLOR_RED]);
calculate_timer_values(COLOR_RED);
chan_dirty &= ~(1<<COLOR_RED);
} else if ((chan_dirty & (1<<COLOR_GREEN)) && (nextColor == COLOR_RED)) {
calculate_timer_values(chan_value[COLOR_GREEN], chan_rawdata[COLOR_GREEN]);
calculate_timer_values(COLOR_GREEN);
chan_dirty &= ~(1<<COLOR_GREEN);
} else if ((chan_dirty & (1<<COLOR_BLUE)) && (nextColor == COLOR_GREEN)) {
calculate_timer_values(chan_value[COLOR_BLUE], chan_rawdata[COLOR_BLUE]);
calculate_timer_values(COLOR_BLUE);
chan_dirty &= ~(1<<COLOR_BLUE);
} else if (!blocking) {