diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index d5af7aefe1262e31df689181ceba6f903ba4c079..c46b09facad3ff0805edc7a1634ed1633d6df55a 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -15,4 +15,8 @@ API(API_UART_READ, char epic_uart_read_chr(void)); #define API_LEDS_SET 0x3 API(API_LEDS_SET, void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b)); +// turn vibration motor on or off +#define API_VIBRA_SET 0x4 +API(API_VIBRA_SET, void epic_vibra_set(int status)); + #endif /* _EPICARDIUM_H */ diff --git a/epicardium/meson.build b/epicardium/meson.build index 88726887b7d67b9644ceff2a8b1f2c0d45d20002..4ab377cb9d04abaa9a2430c5589cd23aa7dfb034 100644 --- a/epicardium/meson.build +++ b/epicardium/meson.build @@ -67,6 +67,7 @@ elf = executable( 'main.c', 'serial.c', 'support.c', + 'modules/vibra.c', dependencies: [libcard10, max32665_startup_core0, maxusb], link_with: [api_dispatcher_lib, freertos], link_whole: [max32665_startup_core0_lib, board_card10_lib], diff --git a/epicardium/modules/vibra.c b/epicardium/modules/vibra.c new file mode 100644 index 0000000000000000000000000000000000000000..e02721a59903eeeaf0cadfb4735d370f06b3c934 --- /dev/null +++ b/epicardium/modules/vibra.c @@ -0,0 +1,13 @@ +#include "gpio.h" + +static const gpio_cfg_t motor_pin = { + PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE +}; + +void epic_vibra_set(int status) { + if(status) { + GPIO_OutSet(&motor_pin); + } else { + GPIO_OutClr(&motor_pin); + } +} diff --git a/pycardium/meson.build b/pycardium/meson.build index 0c839aaaa8b9fc783feb3ba37dea424632dd144c..0e02f357ec1916d38a0ca8efb075cb023d920be7 100644 --- a/pycardium/meson.build +++ b/pycardium/meson.build @@ -3,6 +3,7 @@ name = 'pycardium' modsrc = files( 'modules/utime.c', 'modules/leds.c', + 'modules/vibra.c', ) ################################# diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index a6fbb5dfe5e5e1cb92cc116ee733faf87281fa59..632b6c6733c76c1b0d2282f7c312919098fa9461 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -13,3 +13,6 @@ Q(ticks_us) Q(ticks_cpu) Q(ticks_add) Q(ticks_diff) + +/* vibra */ +Q(vibra) \ No newline at end of file diff --git a/pycardium/modules/vibra.c b/pycardium/modules/vibra.c new file mode 100644 index 0000000000000000000000000000000000000000..1fac77cc3c2b251b3430e526c4d7ee1205f873ab --- /dev/null +++ b/pycardium/modules/vibra.c @@ -0,0 +1,37 @@ +#include "py/obj.h" +#include "py/runtime.h" +#include "py/builtin.h" +#include "epicardium.h" + +STATIC mp_obj_t mp_vibra_set(mp_obj_t state_obj) +{ + if (state_obj == mp_const_true) { + epic_vibra_set(1); + } else if (state_obj == mp_const_false){ + epic_vibra_set(0); + } else { + mp_raise_TypeError("expected bool"); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(vibra_set_obj, mp_vibra_set); + +// Define all properties of the example module. +// Table entries are key/value pairs of the attribute name (a string) +// and the MicroPython object reference. +// All identifiers and strings are written as MP_QSTR_xxx and will be +// optimized to word-sized integers by the build system (interned strings). +STATIC const mp_rom_map_elem_t vibra_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_vibra) }, + { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&vibra_set_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(vibra_module_globals, vibra_module_globals_table); + +// Define module object. +const mp_obj_module_t vibra_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&vibra_module_globals, +}; + +// Register the module to make it available in Python +MP_REGISTER_MODULE(MP_QSTR_vibra, vibra_module, MODULE_VIBRA_ENABLED); diff --git a/pycardium/mpconfigport.h b/pycardium/mpconfigport.h index c4e6a6cb0d86208d840d78e74b0fd1de40a3ae72..5156b1b1412adb219401a78640482d672a8e110e 100644 --- a/pycardium/mpconfigport.h +++ b/pycardium/mpconfigport.h @@ -26,6 +26,7 @@ /* Modules */ #define MODULE_UTIME_ENABLED (1) #define MODULE_LEDS_ENABLED (1) +#define MODULE_VIBRA_ENABLED (1) /* * This port is intended to be 32-bit, but unfortunately, int32_t for