Skip to content
Snippets Groups Projects
Commit 5e9bbd9a authored by Gerd's avatar Gerd Committed by rahix
Browse files

feat(modules): Add vibra module

parent 9203ed39
No related branches found
No related tags found
No related merge requests found
...@@ -53,4 +53,8 @@ API(API_UART_READ, char epic_uart_read_chr(void)); ...@@ -53,4 +53,8 @@ API(API_UART_READ, char epic_uart_read_chr(void));
*/ */
API(API_LEDS_SET, void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b)); 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 */ #endif /* _EPICARDIUM_H */
module_sources = files( module_sources = files(
'leds.c', 'leds.c',
'serial.c', 'serial.c',
'vibra.c'
) )
#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' ...@@ -3,6 +3,7 @@ name = 'pycardium'
modsrc = files( modsrc = files(
'modules/utime.c', 'modules/utime.c',
'modules/leds.c', 'modules/leds.c',
'modules/vibra.c',
) )
################################# #################################
......
...@@ -21,3 +21,6 @@ Q(ticks_us) ...@@ -21,3 +21,6 @@ Q(ticks_us)
Q(ticks_cpu) Q(ticks_cpu)
Q(ticks_add) Q(ticks_add)
Q(ticks_diff) 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);
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);
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
/* Modules */ /* Modules */
#define MODULE_UTIME_ENABLED (1) #define MODULE_UTIME_ENABLED (1)
#define MODULE_LEDS_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 * 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.
Finish editing this message first!
Please register or to comment