Commit 684ac29e authored by Adrian's avatar Adrian Committed by Rahix
Browse files

feat(modules): Add timed vibrate function

parent fd5e6c36
......@@ -11,6 +11,7 @@
#define API_UART_READ 0x2
#define API_LEDS_SET 0x3
#define API_VIBRA_SET 0x4
#define API_VIBRA_VIBRATE 0x5
/* clang-format on */
/**
......@@ -66,4 +67,11 @@ API(API_LEDS_SET, void epic_leds_set(int led, uint8_t r, uint8_t g, uint8_t b));
*/
API(API_VIBRA_SET, void epic_vibra_set(int status));
/**
* Turn vibration motor on for a given time
*
* :param millis: number of milliseconds to run the vibration motor.
*/
API(API_VIBRA_VIBRATE, void epic_vibra_vibrate(int millis));
#endif /* _EPICARDIUM_H */
#include "gpio.h"
#include "FreeRTOS.h"
#include "timers.h"
static const gpio_cfg_t motor_pin = {
PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE
};
static TimerHandle_t vibra_timer;
void epic_vibra_set(int status)
{
if (status) {
......@@ -12,3 +16,17 @@ void epic_vibra_set(int status)
GPIO_OutClr(&motor_pin);
}
}
void vTimerCallback()
{
epic_vibra_set(0);
}
void epic_vibra_vibrate(int millis)
{
int ticks = millis * (configTICK_RATE_HZ / 1000);
epic_vibra_set(1);
vibra_timer =
xTimerCreate("vibratimer", ticks, pdFALSE, 0, vTimerCallback);
xTimerStart(vibra_timer, 0);
}
......@@ -24,3 +24,4 @@ Q(ticks_diff)
/* vibra */
Q(vibra)
Q(vibrate)
......@@ -16,9 +16,18 @@ STATIC mp_obj_t mp_vibra_set(mp_obj_t state_obj)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(vibra_set_obj, mp_vibra_set);
STATIC mp_obj_t mp_vibra_vibrate(mp_obj_t a_obj)
{
int millis = mp_obj_get_int(a_obj);
epic_vibra_vibrate(millis);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(vibra_vibrate_obj, mp_vibra_vibrate);
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) },
{ MP_ROM_QSTR(MP_QSTR_vibrate), MP_ROM_PTR(&vibra_vibrate_obj) }
};
STATIC MP_DEFINE_CONST_DICT(vibra_module_globals, vibra_module_globals_table);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment