|
20 | 20 | #include <zephyr/drivers/uart.h>
|
21 | 21 | #include <zephyr/dt-bindings/gpio/gpio.h>
|
22 | 22 | #include <zephyr/kernel.h>
|
| 23 | +#include <zephyr/drivers/led_strip.h> |
23 | 24 |
|
24 | 25 | #include <chrono>
|
25 | 26 | #include <cmath>
|
|
32 | 33 | #include "../Utils/util.h"
|
33 | 34 | #include "primitives.h"
|
34 | 35 |
|
35 |
| -#define ALL_PRIMITIVES 9 |
| 36 | +#define ALL_PRIMITIVES 7 |
36 | 37 |
|
37 | 38 | // Global index for installing primitives
|
38 | 39 | int prim_index = 0;
|
@@ -262,53 +263,9 @@ def_prim(print_int, oneToNoneU32) {
|
262 | 263 | return true;
|
263 | 264 | }
|
264 | 265 |
|
265 |
| -#include <zephyr/drivers/led_strip.h> |
266 |
| -#define RGB(_r, _g, _b) { .r = (_r), .g = (_g), .b = (_b) } |
267 |
| -static const struct device *const strip = DEVICE_DT_GET(DT_ALIAS(led_strip)); |
| 266 | +static const device *const strip = DEVICE_DT_GET(DT_ALIAS(led_strip)); |
268 | 267 | const size_t strip_length = 64;//led_strip_length(device);
|
269 |
| -struct led_rgb pixels[strip_length] = {0}; |
270 |
| - |
271 |
| -void fun() { |
272 |
| - size_t color = 0; |
273 |
| - int rc; |
274 |
| - |
275 |
| - if (device_is_ready(strip)) { |
276 |
| - printf("Found LED strip device %s\n", strip->name); |
277 |
| - } else { |
278 |
| - printf("LED strip device %s is not ready\n", strip->name); |
279 |
| - return; |
280 |
| - } |
281 |
| - |
282 |
| - printf("Displaying pattern on strip\n"); |
283 |
| - const struct led_rgb colors[] = { |
284 |
| - RGB(16, 0x00, 0x00), // red |
285 |
| - RGB(0x00, 16, 0x00), // green |
286 |
| - RGB(0x00, 0x00, 16), // blue |
287 |
| - }; |
288 |
| - size_t width = 3; |
289 |
| - while (1) { |
290 |
| - for (size_t cursor = 0; cursor < ARRAY_SIZE(pixels) - width + 1; cursor++) { |
291 |
| - memset(&pixels, 0x00, sizeof(pixels)); |
292 |
| - for (size_t i = 0; i < width; i++) { |
293 |
| - memcpy(&pixels[cursor + i], &colors[color], sizeof(struct led_rgb)); |
294 |
| - color = (color + 1) % ARRAY_SIZE(colors); |
295 |
| - } |
296 |
| - |
297 |
| - printf("Update strip!\n"); |
298 |
| - rc = led_strip_update_rgb(strip, pixels, strip_length); |
299 |
| - if (rc) { |
300 |
| - printf("couldn't update strip: %d", rc); |
301 |
| - } |
302 |
| - |
303 |
| - k_sleep(K_MSEC(100)); |
304 |
| - } |
305 |
| - } |
306 |
| -} |
307 |
| - |
308 |
| -def_prim(led_fun, NoneToNoneU32) { |
309 |
| - fun(); |
310 |
| - return true; |
311 |
| -} |
| 268 | +led_rgb pixels[strip_length] = {0}; |
312 | 269 |
|
313 | 270 | def_prim(show_pixels, NoneToNoneU32) {
|
314 | 271 | int rc = led_strip_update_rgb(strip, pixels, strip_length);
|
@@ -366,7 +323,6 @@ void install_primitives() {
|
366 | 323 | install_primitive(chip_digital_write);
|
367 | 324 | install_primitive(chip_digital_read);
|
368 | 325 | install_primitive(print_int);
|
369 |
| - install_primitive(led_fun); |
370 | 326 | install_primitive(set_pixel_color);
|
371 | 327 | install_primitive_reverse(set_pixel_color);
|
372 | 328 | install_primitive(show_pixels);
|
@@ -415,28 +371,14 @@ bool resolve_external_memory(char *symbol, Memory **val) {
|
415 | 371 | //------------------------------------------------------
|
416 | 372 | void restore_external_state(Module *m,
|
417 | 373 | const std::vector<IOStateElement> &external_state) {
|
418 |
| - uint8_t opcode = *m->pc_ptr; |
419 |
| - // TODO: Maybe primitives can also be called using the other call |
420 |
| - // instructions such as call_indirect |
421 |
| - // maybe there should just be a function that checks if a certain function |
422 |
| - // is being called that handles all these cases? |
423 |
| - /*if (opcode == 0x10) { // call opcode |
424 |
| - uint8_t *pc_copy = m->pc_ptr + 1; |
425 |
| - uint32_t fidx = read_LEB_32(&pc_copy); |
426 |
| - if (fidx < m->import_count) {*/ |
427 |
| - for (int i = 0; i < ALL_PRIMITIVES; i++) { |
428 |
| - auto primitive = primitives[i]; |
429 |
| - printf("%s\n", primitive.name); |
430 |
| - //if (!strcmp(primitive.name, m->functions[fidx].import_field)) { |
431 |
| - if (primitive.f_reverse) { |
432 |
| - debug("Reversing action for primitive %s\n", |
433 |
| - primitive.name); |
434 |
| - primitive.f_reverse(m, external_state); |
435 |
| - } |
436 |
| - //} |
437 |
| - } |
438 |
| - /*} |
439 |
| - }*/ |
| 374 | + for (int i = 0; i < ALL_PRIMITIVES; i++) { |
| 375 | + auto primitive = primitives[i]; |
| 376 | + if (primitive.f_reverse) { |
| 377 | + debug("Reversing action for primitive %s\n", |
| 378 | + primitive.name); |
| 379 | + primitive.f_reverse(m, external_state); |
| 380 | + } |
| 381 | + } |
440 | 382 | }
|
441 | 383 |
|
442 | 384 | std::vector<IOStateElement *> get_io_state(Module *m) {
|
|
0 commit comments