Skip to content
Snippets Groups Projects
Verified Commit e84673c0 authored by rahix's avatar rahix
Browse files

Add buzzer

parent 3ca07eb5
Branches
Tags
No related merge requests found
...@@ -44,6 +44,7 @@ LIBS = ...@@ -44,6 +44,7 @@ LIBS =
SRC_C = \ SRC_C = \
main.c \ main.c \
uart_core.c \ uart_core.c \
buzzer.c \
lib/utils/printf.c \ lib/utils/printf.c \
lib/utils/stdout_helpers.c \ lib/utils/stdout_helpers.c \
lib/utils/pyexec.c \ lib/utils/pyexec.c \
...@@ -52,6 +53,9 @@ SRC_C = \ ...@@ -52,6 +53,9 @@ SRC_C = \
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
SRC_QSTR += buzzer.c
USER_C_MODULES += buzzer.c
# SDK compilation hack # SDK compilation hack
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
......
#include "py/obj.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include <stdio.h>
#include "gpio.h"
static const gpio_cfg_t motor_pin = {
PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE
};
STATIC mp_obj_t buzzer_set(mp_obj_t state_obj)
{
if (state_obj == mp_const_true) {
printf("Buzzer ON!\n");
GPIO_OutSet(&motor_pin);
} else if (state_obj == mp_const_false){
printf("Buzzer OFF!\n");
GPIO_OutClr(&motor_pin);
} else {
mp_raise_TypeError("expected bool");
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(buzzer_set_obj, buzzer_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 buzzer_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buzzer) },
{ MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&buzzer_set_obj) },
};
STATIC MP_DEFINE_CONST_DICT(buzzer_module_globals, buzzer_module_globals_table);
// Define module object.
const mp_obj_module_t buzzer_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&buzzer_module_globals,
};
// Register the module to make it available in Python
MP_REGISTER_MODULE(MP_QSTR_buzzer, buzzer_module, MODULE_BUZZER_ENABLED);
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_LONGLONG)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
#define MICROPY_PY_UTIME_MP_HAL (1) #define MICROPY_PY_UTIME_MP_HAL (1)
#define MODULE_BUZZER_ENABLED (1)
// type definitions for the specific machine // type definitions for the specific machine
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment