diff --git a/Makefile b/Makefile index 479251fe1..67c399cb1 100755 --- a/Makefile +++ b/Makefile @@ -191,11 +191,6 @@ MPY_CFLAGS += -DMICROPY_PY_TV=1 MPY_MKARGS += MICROPY_PY_TV=1 endif -ifeq ($(MICROPY_PY_BUZZER), 1) -MPY_CFLAGS += -DMICROPY_PY_BUZZER=1 -MPY_MKARGS += MICROPY_PY_BUZZER=1 -endif - ifeq ($(CUBEAI), 1) MPY_CFLAGS += -DMICROPY_PY_CUBEAI=1 MPY_MKARGS += MICROPY_PY_CUBEAI=1 diff --git a/boards/ARDUINO_NANO_33_BLE_SENSE/omv_boardconfig.mk b/boards/ARDUINO_NANO_33_BLE_SENSE/omv_boardconfig.mk index 7b9316aa0..9c3c05761 100755 --- a/boards/ARDUINO_NANO_33_BLE_SENSE/omv_boardconfig.mk +++ b/boards/ARDUINO_NANO_33_BLE_SENSE/omv_boardconfig.mk @@ -20,4 +20,3 @@ MICROPY_PY_ULAB=1 MICROPY_PY_AUDIO=1 MICROPY_PY_DISPLAY = 0 MICROPY_PY_TV = 0 -MICROPY_PY_BUZZER = 0 diff --git a/boards/ARDUINO_NANO_RP2040_CONNECT/omv_boardconfig.cmake b/boards/ARDUINO_NANO_RP2040_CONNECT/omv_boardconfig.cmake index 80c51d516..daa2f23d1 100644 --- a/boards/ARDUINO_NANO_RP2040_CONNECT/omv_boardconfig.cmake +++ b/boards/ARDUINO_NANO_RP2040_CONNECT/omv_boardconfig.cmake @@ -10,5 +10,4 @@ set(MICROPY_PY_AUDIO 1) set(MICROPY_PY_MICRO_SPEECH 0) set(MICROPY_PY_DISPLAY 0) set(MICROPY_PY_TV 0) -set(MICROPY_PY_BUZZER 0) set(CMSIS_MCU_H "RP2040.h") diff --git a/boards/ARDUINO_NICLA_VISION/omv_boardconfig.mk b/boards/ARDUINO_NICLA_VISION/omv_boardconfig.mk index d3ef57e31..45a04fea8 100755 --- a/boards/ARDUINO_NICLA_VISION/omv_boardconfig.mk +++ b/boards/ARDUINO_NICLA_VISION/omv_boardconfig.mk @@ -31,6 +31,5 @@ MICROPY_BLUETOOTH_NIMBLE = 1 MICROPY_PY_AUDIO = 1 MICROPY_PY_DISPLAY = 0 MICROPY_PY_TV = 0 -MICROPY_PY_BUZZER = 0 MICROPY_PY_ML = 1 MICROPY_PY_ML_TFLM = 1 diff --git a/boards/ARDUINO_PORTENTA_H7/omv_boardconfig.mk b/boards/ARDUINO_PORTENTA_H7/omv_boardconfig.mk index 39a50886d..cec8cb4bb 100755 --- a/boards/ARDUINO_PORTENTA_H7/omv_boardconfig.mk +++ b/boards/ARDUINO_PORTENTA_H7/omv_boardconfig.mk @@ -29,7 +29,6 @@ MICROPY_BLUETOOTH_NIMBLE = 1 MICROPY_PY_AUDIO = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 0 MICROPY_PY_OPENAMP = 1 MICROPY_PY_OPENAMP_REMOTEPROC = 1 MICROPY_PY_ML = 1 diff --git a/boards/OPENMV2/omv_boardconfig.mk b/boards/OPENMV2/omv_boardconfig.mk index 7e5982749..64c46974e 100755 --- a/boards/OPENMV2/omv_boardconfig.mk +++ b/boards/OPENMV2/omv_boardconfig.mk @@ -15,7 +15,6 @@ MICROPY_PY_FIR = 1 MICROPY_PY_WINC1500 = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 0 MICROPY_PY_LWIP = 0 MICROPY_PY_SSL = 1 MICROPY_PY_SSL_ECDSA_SIGN_ALT = 0 diff --git a/boards/OPENMV3/omv_boardconfig.mk b/boards/OPENMV3/omv_boardconfig.mk index 3a0b6b360..5f13d2305 100755 --- a/boards/OPENMV3/omv_boardconfig.mk +++ b/boards/OPENMV3/omv_boardconfig.mk @@ -16,7 +16,6 @@ MICROPY_PY_ULAB = 1 MICROPY_PY_WINC1500 = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 0 MICROPY_PY_ML = 1 MICROPY_PY_ML_TFLM = 1 MICROPY_PY_LWIP = 0 diff --git a/boards/OPENMV4/omv_boardconfig.mk b/boards/OPENMV4/omv_boardconfig.mk index 90c958c67..189e84dc6 100755 --- a/boards/OPENMV4/omv_boardconfig.mk +++ b/boards/OPENMV4/omv_boardconfig.mk @@ -17,7 +17,6 @@ MICROPY_PY_ULAB = 1 MICROPY_PY_WINC1500 = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 0 MICROPY_PY_ML = 1 MICROPY_PY_ML_TFLM = 1 MICROPY_PY_LWIP = 0 diff --git a/boards/OPENMV4P/omv_boardconfig.mk b/boards/OPENMV4P/omv_boardconfig.mk index 0f2a3f839..3a786178b 100755 --- a/boards/OPENMV4P/omv_boardconfig.mk +++ b/boards/OPENMV4P/omv_boardconfig.mk @@ -18,7 +18,6 @@ MICROPY_PY_ULAB = 1 MICROPY_PY_WINC1500 = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 0 MICROPY_PY_ML = 1 MICROPY_PY_ML_TFLM = 1 MICROPY_PY_LWIP = 0 diff --git a/boards/OPENMVPT/omv_boardconfig.h b/boards/OPENMVPT/omv_boardconfig.h index 642f53d19..7675bb406 100644 --- a/boards/OPENMVPT/omv_boardconfig.h +++ b/boards/OPENMVPT/omv_boardconfig.h @@ -367,16 +367,4 @@ #define OMV_FIR_LEPTON_MCLK_TIM_RELEASE_RESET() __HAL_RCC_TIM15_RELEASE_RESET() #define OMV_FIR_LEPTON_MCLK_TIM_PCLK_FREQ() HAL_RCC_GetPCLK2Freq() -// Buzzer -#define OMV_BUZZER_PIN (&omv_pin_A1_TIM2) -#define OMV_BUZZER_FREQ (4000) - -#define OMV_BUZZER_TIM (TIM2) -#define OMV_BUZZER_TIM_CHANNEL (TIM_CHANNEL_2) -#define OMV_BUZZER_TIM_CLK_ENABLE() __HAL_RCC_TIM2_CLK_ENABLE() -#define OMV_BUZZER_TIM_CLK_DISABLE() __HAL_RCC_TIM2_CLK_DISABLE() -#define OMV_BUZZER_TIM_FORCE_RESET() __HAL_RCC_TIM2_FORCE_RESET() -#define OMV_BUZZER_TIM_RELEASE_RESET() __HAL_RCC_TIM2_RELEASE_RESET() -#define OMV_BUZZER_TIM_PCLK_FREQ() HAL_RCC_GetPCLK1Freq() - #endif //__OMV_BOARDCONFIG_H__ diff --git a/boards/OPENMVPT/omv_boardconfig.mk b/boards/OPENMVPT/omv_boardconfig.mk index 7715db42d..189e84dc6 100755 --- a/boards/OPENMVPT/omv_boardconfig.mk +++ b/boards/OPENMVPT/omv_boardconfig.mk @@ -17,7 +17,6 @@ MICROPY_PY_ULAB = 1 MICROPY_PY_WINC1500 = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 1 MICROPY_PY_ML = 1 MICROPY_PY_ML_TFLM = 1 MICROPY_PY_LWIP = 0 diff --git a/boards/OPENMV_RT1060/omv_boardconfig.mk b/boards/OPENMV_RT1060/omv_boardconfig.mk index 6364ad530..84e525cd5 100755 --- a/boards/OPENMV_RT1060/omv_boardconfig.mk +++ b/boards/OPENMV_RT1060/omv_boardconfig.mk @@ -24,6 +24,5 @@ MICROPY_PY_BLUETOOTH = 1 MICROPY_BLUETOOTH_NIMBLE = 1 MICROPY_PY_DISPLAY = 1 MICROPY_PY_TV = 1 -MICROPY_PY_BUZZER = 0 MICROPY_PY_ML = 1 MICROPY_PY_ML_TFLM = 1 diff --git a/boards/RPI_PICO/omv_boardconfig.cmake b/boards/RPI_PICO/omv_boardconfig.cmake index 2e9175b36..191acc888 100644 --- a/boards/RPI_PICO/omv_boardconfig.cmake +++ b/boards/RPI_PICO/omv_boardconfig.cmake @@ -9,5 +9,4 @@ set(MICROPY_BLUETOOTH_NIMBLE 0) set(MICROPY_PY_AUDIO 0) set(MICROPY_PY_DISPLAY 0) set(MICROPY_PY_TV 0) -set(MICROPY_PY_BUZZER 0) set(CMSIS_MCU_H "RP2040.h") diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index a12d1609b..0b92a3496 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -101,9 +101,6 @@ soft_reset: #if MICROPY_PY_TV py_tv_init0(); #endif - #if MICROPY_PY_BUZZER - py_buzzer_init0(); - #endif // MICROPY_PY_BUZZER imlib_init_all(); readline_init0(); fb_alloc_init0(); diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 37448e0f2..35fdd5539 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -92,7 +92,6 @@ #include "py_image.h" #include "py_fir.h" #include "py_tv.h" -#include "py_buzzer.h" #include "py_imu.h" #include "py_audio.h" @@ -210,9 +209,6 @@ soft_reset: #if MICROPY_PY_TV py_tv_init0(); #endif - #if MICROPY_PY_BUZZER - py_buzzer_init0(); - #endif // MICROPY_PY_BUZZER imlib_init_all(); readline_init0(); pin_init0(); diff --git a/ports/stm32/modules/py_buzzer.c b/ports/stm32/modules/py_buzzer.c deleted file mode 100644 index 8df50fc1b..000000000 --- a/ports/stm32/modules/py_buzzer.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2013-2024 OpenMV, LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * Buzzer Python module. - */ -#include "py/obj.h" - -#include "omv_boardconfig.h" - -#if MICROPY_PY_BUZZER -#include STM32_HAL_H -#include "omv_gpio.h" - -static TIM_HandleTypeDef buzzer_tim_handle = {}; - -static int buzzer_freq = OMV_BUZZER_FREQ; -static int buzzer_duty = 0; - -static void buzzer_setup(int freq, int duty) { - int tclk = OMV_BUZZER_TIM_PCLK_FREQ() * 2; - int period = (tclk / freq) - 1; - int pulse = (period * duty) / 510; - - if (((buzzer_duty <= 0) || (255 < buzzer_duty)) && (0 < duty) && (duty <= 255)) { - omv_gpio_config(OMV_BUZZER_PIN, OMV_GPIO_MODE_ALT, OMV_GPIO_PULL_NONE, OMV_GPIO_SPEED_LOW, -1); - - buzzer_tim_handle.Instance = OMV_BUZZER_TIM; - buzzer_tim_handle.Init.Prescaler = 0; - buzzer_tim_handle.Init.CounterMode = TIM_COUNTERMODE_UP; - buzzer_tim_handle.Init.Period = period; - buzzer_tim_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - buzzer_tim_handle.Init.RepetitionCounter = 0; - buzzer_tim_handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; - - TIM_OC_InitTypeDef buzzer_tim_oc_handle; - buzzer_tim_oc_handle.Pulse = pulse; - buzzer_tim_oc_handle.OCMode = TIM_OCMODE_PWM1; - buzzer_tim_oc_handle.OCPolarity = TIM_OCPOLARITY_HIGH; - buzzer_tim_oc_handle.OCNPolarity = TIM_OCNPOLARITY_HIGH; - buzzer_tim_oc_handle.OCFastMode = TIM_OCFAST_DISABLE; - buzzer_tim_oc_handle.OCIdleState = TIM_OCIDLESTATE_RESET; - buzzer_tim_oc_handle.OCNIdleState = TIM_OCNIDLESTATE_RESET; - - HAL_TIM_PWM_Init(&buzzer_tim_handle); - HAL_TIM_PWM_ConfigChannel(&buzzer_tim_handle, &buzzer_tim_oc_handle, OMV_BUZZER_TIM_CHANNEL); - HAL_TIM_PWM_Start(&buzzer_tim_handle, OMV_BUZZER_TIM_CHANNEL); - } else if ((0 < buzzer_duty) && (buzzer_duty <= 255) && ((duty <= 0) || (255 < duty))) { - HAL_TIM_PWM_Stop(&buzzer_tim_handle, OMV_BUZZER_TIM_CHANNEL); - HAL_TIM_PWM_DeInit(&buzzer_tim_handle); - omv_gpio_deinit(OMV_BUZZER_PIN); - } else if ((0 < buzzer_duty) && (buzzer_duty <= 255) && (0 < duty) && (duty <= 255)) { - __HAL_TIM_SET_AUTORELOAD(&buzzer_tim_handle, period); - __HAL_TIM_SET_COMPARE(&buzzer_tim_handle, OMV_BUZZER_TIM_CHANNEL, pulse); - } - - buzzer_freq = freq; - buzzer_duty = duty; -} - -static mp_obj_t py_buzzer_freq(uint n_args, const mp_obj_t *args) { - if (!n_args) { - return mp_obj_new_int(buzzer_freq); - } else { - buzzer_setup(mp_obj_get_int(*args), buzzer_duty); - return mp_const_none; - } -} -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_buzzer_freq_obj, 0, 1, py_buzzer_freq); - -static mp_obj_t py_buzzer_duty(uint n_args, const mp_obj_t *args) { - if (!n_args) { - return mp_obj_new_int(buzzer_duty); - } else { - buzzer_setup(buzzer_freq, mp_obj_get_int(*args)); - return mp_const_none; - } -} -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(py_buzzer_duty_obj, 0, 1, py_buzzer_duty); - -static const mp_rom_map_elem_t globals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buzzer) }, - { MP_ROM_QSTR(MP_QSTR_RESONANT_FREQ), MP_ROM_INT(OMV_BUZZER_FREQ) }, - { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&py_buzzer_freq_obj) }, - { MP_ROM_QSTR(MP_QSTR_duty), MP_ROM_PTR(&py_buzzer_duty_obj) } -}; - -static MP_DEFINE_CONST_DICT(globals_dict, globals_dict_table); - -const mp_obj_module_t buzzer_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_t) &globals_dict, -}; - -void py_buzzer_init0() { - buzzer_setup(OMV_BUZZER_FREQ, 0); -} - -MP_REGISTER_MODULE(MP_QSTR_buzzer, buzzer_module); -#endif // MICROPY_PY_BUZZER diff --git a/ports/stm32/modules/py_buzzer.h b/ports/stm32/modules/py_buzzer.h deleted file mode 100644 index 70df17281..000000000 --- a/ports/stm32/modules/py_buzzer.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SPDX-License-Identifier: MIT - * - * Copyright (C) 2013-2024 OpenMV, LLC. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * Buzzer Python module. - */ -#ifndef __PY_BUZZER_H__ -#define __PY_BUZZER_H__ -void py_buzzer_init0(); -#endif // __PY_BUZZER_H__ diff --git a/ports/stm32/stm_hal.c b/ports/stm32/stm_hal.c index e1d7dd1c8..f89dda298 100644 --- a/ports/stm32/stm_hal.c +++ b/ports/stm32/stm_hal.c @@ -409,12 +409,6 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) { #endif } #endif // (OMV_CSI_TIM) - - #if defined(OMV_BUZZER_TIM) - if (htim->Instance == OMV_BUZZER_TIM) { - OMV_BUZZER_TIM_CLK_ENABLE(); - } - #endif } void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) { @@ -430,14 +424,6 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) { #endif } #endif // (OMV_CSI_TIM) - - #if defined(OMV_BUZZER_TIM) - if (htim->Instance == OMV_BUZZER_TIM) { - OMV_BUZZER_TIM_FORCE_RESET(); - OMV_BUZZER_TIM_RELEASE_RESET(); - OMV_BUZZER_TIM_CLK_DISABLE(); - } - #endif } void HAL_DCMI_MspInit(DCMI_HandleTypeDef *hdcmi) { diff --git a/scripts/examples/50-OpenMV-Boards/51-Pure-Thermal/00-HelloWorld/buzzer.py b/scripts/examples/50-OpenMV-Boards/51-Pure-Thermal/00-HelloWorld/buzzer.py new file mode 100644 index 000000000..a2d248dd7 --- /dev/null +++ b/scripts/examples/50-OpenMV-Boards/51-Pure-Thermal/00-HelloWorld/buzzer.py @@ -0,0 +1,29 @@ +# This work is licensed under the MIT license. +# Copyright (c) 2013-2025 OpenMV LLC. All rights reserved. +# https://github.com/openmv/openmv/blob/master/LICENSE +# +# Pure Thermal Buzzer Example Script +# +# Thanks for buying the Pure Thermal OpenMV! This is a simple example +# script showing off how to control the buzzer onboard. + +from pyb import Timer, Pin +import time + +# Timer2, Channel2 +tim2 = Timer(2, freq=4000) +ch2 = tim2.channel(2, Timer.PWM, pin=Pin("BUZZER"), pulse_width_percent=50) + +# Play a Catchy Jingle by controlling the buzzer frequency and duty cycle +# using a lookup table of freq and duty cycle values. +jingle = [ + (1000, 50), (1200, 60), (1400, 70), (1600, 80), + (1800, 90), (2000, 100), (2200, 90), (2400, 80), + (2600, 70), (2800, 60), (3000, 50), (3200, 40), +] + +while True: + for freq, duty in jingle: + tim2.freq(freq) + ch2.pulse_width_percent(duty) + time.sleep_ms(200)