Skip to content
Snippets Groups Projects
Verified Commit 179dbb7e authored by Gerd's avatar Gerd
Browse files

Add vibra module

parent 1a693480
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......@@ -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],
......
#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);
}
}
......@@ -3,6 +3,7 @@ name = 'pycardium'
modsrc = files(
'modules/utime.c',
'modules/leds.c',
'modules/vibra.c',
)
#################################
......
......@@ -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
#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);
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment