diff --git a/main.c b/main.c index 714c26e..b4da684 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/mpmctrl.c b/mpmctrl.c index bd801c1..b5ad055 100644 --- a/mpmctrl.c +++ b/mpmctrl.c @@ -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++; } diff --git a/rgb16mpm.h b/rgb16mpm.h index 63ae1dd..a4214cc 100644 --- a/rgb16mpm.h +++ b/rgb16mpm.h @@ -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); diff --git a/rgbctrl.c b/rgbctrl.c index 6864d2b..a64bcf6 100644 --- a/rgbctrl.c +++ b/rgbctrl.c @@ -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<