flat assembler
Message board for the users of flat assembler.
Index
> Projects and Ideas > color encoding for ws2812, MCU and why not, x86 |
Author |
|
revolution 22 Jan 2022, 02:44
Would a 3:3:2 distribution give more colour choices?
You could use either RGB or YUV encoding for the bit fields. |
|||
22 Jan 2022, 02:44 |
|
FlierMate 22 Jan 2022, 09:17
LED stick can be fun! I use WS2318 with ATmega328P, to create an audio visualizer:
|
|||
22 Jan 2022, 09:17 |
|
edfed 18 Feb 2022, 00:31
yeppee, i had the time to code.
the lib can use a palette or a direct value. if it uses a palette, the pixels are stored in one byte. with direct value, it is like original with 3bytes. the palette can be any size (no check at runtime) between 0 and 256 colors, stored as 4 bytes. https://gitlab.com/foolavr/ws2812 here is the atomic part responsible of the NRZ transmission with palette. the timings seems to be ok even if i use dirty C adressing to lookup the palette. Code: if (isPalette) { i = numBytes; volatile uint8_t c; volatile uint16_t p; while (i != 0) { p = *ptr; for (c = 0; c < 3; c++) { bit = 8; b = ((uint8_t*)(palette))[(p<<2)+c]; asm volatile( "head201:" "\n\t" // Clk Pseudocode (T = 0) "st %a[port], %[hi]" "\n\t" // 2 PORT = hi (T = 2) "sbrc %[byte], 7" "\n\t" // 1-2 if(b & 128) "mov %[next], %[hi]" "\n\t" // 0-1 next = hi (T = 4) "dec %[bit]" "\n\t" // 1 bit-- (T = 5) "st %a[port], %[next]" "\n\t" // 2 PORT = next (T = 7) "mov %[next] , %[lo]" "\n\t" // 1 next = lo (T = 8) "breq nextbyte201" "\n\t" // 1-2 if(bit == 0) (from dec above) "rol %[byte]" "\n\t" // 1 b <<= 1 (T = 10) "rjmp .+0" "\n\t" // 2 nop nop (T = 12) "nop" "\n\t" // 1 nop (T = 13) "st %a[port], %[lo]" "\n\t" // 2 PORT = lo (T = 15) "nop" "\n\t" // 1 nop (T = 16) "rjmp .+0" "\n\t" // 2 nop nop (T = 18) "rjmp head201" "\n\t" // 2 -> head20 (next bit out) "nextbyte201:" "\n\t" // (T = 10) "st %a[port], %[lo]" "\n\t" // 2 PORT = lo (T = 15) : [port] "+e" (port), [byte] "+r" (b), [bit] "+r" (bit), [next] "+r" (next) : [hi] "r" (hi), [lo] "r" (lo) ); } ptr++; i--; } } this is a trim of adafruit lib to fit my specific requirements, WS2812 with a ATMEGA328 at 16MHz, using arduino IDE. it looks to work very well with my 16*16 matrix and i can now return to the project that needed this ram use reduction. |
|||
18 Feb 2022, 00:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.