Skip to content

LED strip refactor #3158

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

Merged
merged 12 commits into from
Jan 6, 2021
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
1 change: 1 addition & 0 deletions app/include/user_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
//#define LUA_USE_MODULES_PCM
//#define LUA_USE_MODULES_PERF
//#define LUA_USE_MODULES_PIPE
//#define LUA_USE_MODULES_PIXBUF
//#define LUA_USE_MODULES_PWM
//#define LUA_USE_MODULES_PWM2
//#define LUA_USE_MODULES_RFSWITCH
Expand Down
25 changes: 22 additions & 3 deletions app/modules/apa102.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "platform.h"
#include "user_interface.h"

#include "pixbuf.h"


#define NOP asm volatile(" nop \n\t")

Expand Down Expand Up @@ -79,9 +81,26 @@ static int apa102_write(lua_State* L) {
MOD_CHECK_ID(gpio, clock_pin);
uint32_t alt_clock_pin = pin_num[clock_pin];

size_t buf_len;
const char *buf = luaL_checklstring(L, 3, &buf_len);
uint32_t nbr_frames = buf_len / 4;
const char *buf;
uint32_t nbr_frames;

switch(lua_type(L, 3)) {
case LUA_TSTRING: {
size_t buf_len;
buf = luaL_checklstring(L, 3, &buf_len);
nbr_frames = buf_len / 4;
break;
}
case LUA_TUSERDATA: {
pixbuf *buffer = pixbuf_from_lua_arg(L, 3);
luaL_argcheck(L, buffer->nchan == 4, 3, "Pixbuf not 4-channel");
buf = (const char *)buffer->values;
nbr_frames = buffer->npix;
break;
}
default:
return luaL_argerror(L, 3, "String or pixbuf expected");
}

if (nbr_frames > 100000) {
return luaL_error(L, "The supplied buffer is too long, and might cause the callback watchdog to bark.");
Expand Down
Loading