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

Make interrupt handling configurable #109

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
15 changes: 8 additions & 7 deletions light_ws2812_AVR/Light_WS2812/light_ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>

// Normally ws2812_sendarray_mask() runs under disabled-interrupt condition,
// undefine if you want to accept interrupts in that function.
#define interrupt_is_disabled

// Setleds for standard RGB
void inline ws2812_setleds(struct cRGB *ledarray, uint16_t leds)
Expand Down Expand Up @@ -113,7 +109,7 @@ void ws2812_sendarray(uint8_t *data,uint16_t datlen)
#endif

#define w_nop1 "nop \n\t"
#ifdef interrupt_is_disabled
#if (ws2812_interrupt_handling)
#define w_nop2 "brid .+0 \n\t"
#else
#define w_nop2 "brtc .+0 \n\t"
Expand All @@ -140,7 +136,7 @@ void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)

sreg_prev=SREG;

#ifdef interrupt_is_disabled
#if (ws2812_interrupt_handling)
cli();
#endif

Expand All @@ -149,7 +145,7 @@ void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi)

__asm__ volatile(
" ldi %0,8 \n\t"
#ifndef interrupt_is_disabled
#if (ws2812_interrupt_handling)
" clt \n\t"
#endif
"loop%=: \n\t"
Expand Down Expand Up @@ -239,4 +235,9 @@ w_nop16
}

SREG=sreg_prev;

#if (ws2812_interrupt_handling)
sei();
#endif

}
12 changes: 12 additions & 0 deletions light_ws2812_AVR/Light_WS2812/light_ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
#define ws2812_pin 0 // Data out pin
#endif

///////////////////////////////////////////////////////////////////////
// Define interrupt behaviour
//
// Set to 1 if you want the library to handle interrupt toggling
// (i.e. turning off interrupts when sending data and reverting back after).
// Set to 0 if you need to allow interrupts (can introduce flickering!).
//
///////////////////////////////////////////////////////////////////////
#if !defined(ws2812_interrupt_handling)
#define ws2812_interrupt_handling 1
#endif

/*
* Structure of the LED array
*
Expand Down
11 changes: 11 additions & 0 deletions light_ws2812_AVR/Light_WS2812/ws2812_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@
#define ws2812_port B // Data port
#define ws2812_pin 0 // Data out pin

///////////////////////////////////////////////////////////////////////
// Define interrupt behaviour
//
// Set to 1 if you want the library to handle interrupt toggling
// (i.e. turning off interrupts when sending data and reverting back after).
// Set to 0 if you need to allow interrupts (can introduce flickering!).
//
///////////////////////////////////////////////////////////////////////

#define ws2812_interrupt_handling 1

#endif /* WS2812_CONFIG_H_ */
Loading