Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
5e9bbd9a
Commit
5e9bbd9a
authored
Jul 08, 2019
by
Gerd
Committed by
Rahix
Jul 08, 2019
Browse files
feat(modules): Add vibra module
parent
9203ed39
Changes
7
Hide whitespace changes
Inline
Side-by-side
epicardium/epicardium.h
View file @
5e9bbd9a
...
...
@@ -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
));
// turn vibration motor on or off
#define API_VIBRA_SET 0x4
API
(
API_VIBRA_SET
,
void
epic_vibra_set
(
int
status
));
#endif
/* _EPICARDIUM_H */
epicardium/modules/meson.build
View file @
5e9bbd9a
module_sources = files(
'leds.c',
'serial.c',
'vibra.c'
)
epicardium/modules/vibra.c
0 → 100644
View file @
5e9bbd9a
#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
);
}
}
pycardium/meson.build
View file @
5e9bbd9a
...
...
@@ -3,6 +3,7 @@ name = 'pycardium'
modsrc = files(
'modules/utime.c',
'modules/leds.c',
'modules/vibra.c',
)
#################################
...
...
pycardium/modules/qstrdefs.h
View file @
5e9bbd9a
...
...
@@ -21,3 +21,6 @@ Q(ticks_us)
Q
(
ticks_cpu
)
Q
(
ticks_add
)
Q
(
ticks_diff
)
/* vibra */
Q
(
vibra
)
\ No newline at end of file
pycardium/modules/vibra.c
0 → 100644
View file @
5e9bbd9a
#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
);
pycardium/mpconfigport.h
View file @
5e9bbd9a
...
...
@@ -25,6 +25,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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment