Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address up to 256 LED per channel #2

Open
wants to merge 5 commits into
base: pro
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions light_ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,9 @@ void ws2812_sendarray(uint8_t *data,uint16_t datlen)
#define w_nop8 w_nop4 w_nop4
#define w_nop16 w_nop8 w_nop8

void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
{
uint8_t curbyte,ctr,masklo;
uint8_t sreg_prev;

masklo =~maskhi&ws2812_PORTREG;
maskhi |= ws2812_PORTREG;
sreg_prev=SREG;
cli();
inline void send_byte(uint8_t curbyte, uint8_t maskhi, uint8_t masklo){
uint8_t ctr;

while (datlen--) {
curbyte=*data++;

asm volatile(
" ldi %0,8 \n\t"
"loop%=: \n\t"
Expand Down Expand Up @@ -164,6 +154,57 @@ w_nop16
: "=&d" (ctr)
: "r" (curbyte), "I" (_SFR_IO_ADDR(ws2812_PORTREG)), "r" (maskhi), "r" (masklo)
);
}

void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
{
uint8_t curbyte, masklo;
uint8_t sreg_prev;

masklo =~maskhi&ws2812_PORTREG;
maskhi |= ws2812_PORTREG;
sreg_prev=SREG;
cli();

while (datlen--) {
curbyte=*data++;
send_byte(curbyte, maskhi, masklo);
}

SREG=sreg_prev;
}

void inline ws2812_sendarraylow_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
{
uint8_t curbyte, masklo;
uint8_t sreg_prev;

masklo =~maskhi&ws2812_PORTREG;
maskhi |= ws2812_PORTREG;
sreg_prev=SREG;
cli();

while (datlen--) {
curbyte=*data++;
send_byte(curbyte<<4, maskhi, masklo);
}

SREG=sreg_prev;
}

void inline ws2812_sendarrayhigh_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)
{
uint8_t curbyte, masklo;
uint8_t sreg_prev;

masklo =~maskhi&ws2812_PORTREG;
maskhi |= ws2812_PORTREG;
sreg_prev=SREG;
cli();

while (datlen--) {
curbyte=*data++;
send_byte(curbyte&240, maskhi, masklo);
}

SREG=sreg_prev;
Expand Down
2 changes: 2 additions & 0 deletions light_ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void ws2812_setleds_pin(struct cRGB *ledarray, uint16_t number_of_leds,uint8_t p

void ws2812_sendarray (uint8_t *array,uint16_t length);
void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
void ws2812_sendarraylow_mask(uint8_t *array,uint16_t length, uint8_t pinmask);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple variants of the sendarray function to send low and high 4 bits

void ws2812_sendarrayhigh_mask(uint8_t *array,uint16_t length, uint8_t pinmask);


/*
Expand Down
Loading