From d739f5934cbe1b8efaa93856e09cd0b421761379 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Wed, 19 Jun 2019 00:08:00 +0200 Subject: [PATCH] feat(pycardium): Add leds module Signed-off-by: Rahix <rahix@rahix.de> --- pycardium/meson.build | 1 + pycardium/modules/leds.c | 29 +++++++++++++++++++++++++++++ pycardium/modules/qstrdefs.h | 3 +++ pycardium/mpconfigport.h | 1 + 4 files changed, 34 insertions(+) create mode 100644 pycardium/modules/leds.c diff --git a/pycardium/meson.build b/pycardium/meson.build index a8de25d1..c2421e6a 100644 --- a/pycardium/meson.build +++ b/pycardium/meson.build @@ -2,6 +2,7 @@ name = 'pycardium' modsrc = files( 'modules/utime.c', + 'modules/leds.c', ) ################################# diff --git a/pycardium/modules/leds.c b/pycardium/modules/leds.c new file mode 100644 index 00000000..6010d213 --- /dev/null +++ b/pycardium/modules/leds.c @@ -0,0 +1,29 @@ +#include "py/obj.h" +#include "epicardium.h" + +static mp_obj_t mp_leds_set(size_t n_args, const mp_obj_t *args) +{ + int led = mp_obj_get_int(args[0]); + uint8_t r = mp_obj_get_int(args[1]); + uint8_t g = mp_obj_get_int(args[2]); + uint8_t b = mp_obj_get_int(args[3]); + + epic_leds_set(led, r, g, b); + + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(leds_set_obj, 4, 4, mp_leds_set); + +static const mp_rom_map_elem_t leds_module_globals_table[] = { + {MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_leds)}, + {MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&leds_set_obj)}, +}; +static MP_DEFINE_CONST_DICT(leds_module_globals, leds_module_globals_table); + +const mp_obj_module_t leds_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&leds_module_globals, +}; + +/* Register the module to make it available in Python */ +MP_REGISTER_MODULE(MP_QSTR_leds, leds_module, MODULE_LEDS_ENABLED); diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index 26644086..a6fbb5df 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -1,5 +1,8 @@ #include "py/mpconfig.h" +/* leds */ +Q(leds) + /* utime */ Q(utime) Q(sleep) diff --git a/pycardium/mpconfigport.h b/pycardium/mpconfigport.h index 48bdf1c8..0b8cba3a 100644 --- a/pycardium/mpconfigport.h +++ b/pycardium/mpconfigport.h @@ -21,6 +21,7 @@ /* Modules */ #define MODULE_UTIME_ENABLED (1) +#define MODULE_LEDS_ENABLED (1) /* * This port is intended to be 32-bit, but unfortunately, int32_t for -- GitLab