From 7e7af715271c8c3ca3ec8c600b835aa388624461 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 20 Oct 2023 16:00:36 +1100 Subject: [PATCH] extmod/machine_pwm: Remove header file and move decls to .c file. With public declarations moved to extmod/modmachine.h. It's now mandatory for a port to define MICROPY_PY_MACHINE_PWM_INCLUDEFILE if it enables MICROPY_PY_MACHINE_PWM. This follows how extmod/machine_wdt.c works. All ports have been updated to work with this modified scheme. Signed-off-by: Damien George --- extmod/machine_pwm.c | 21 ++++++++-- extmod/machine_pwm.h | 55 -------------------------- extmod/modmachine.h | 2 + ports/esp32/machine_pwm.c | 6 +-- ports/esp32/modmachine.c | 1 - ports/esp8266/machine_pwm.c | 6 +-- ports/esp8266/modmachine.c | 1 - ports/mimxrt/machine_pwm.c | 5 ++- ports/mimxrt/modmachine.h | 1 - ports/nrf/modules/machine/modmachine.c | 1 + ports/nrf/modules/machine/pwm.c | 41 +++++++------------ ports/nrf/modules/machine/pwm.h | 2 - ports/nrf/modules/machine/soft_pwm.c | 15 ++----- ports/renesas-ra/machine_pwm.c | 10 ++--- ports/renesas-ra/modmachine.c | 2 +- ports/rp2/machine_pwm.c | 6 +-- ports/rp2/modmachine.c | 1 - ports/samd/machine_pwm.c | 9 +---- ports/samd/modmachine.h | 3 -- 19 files changed, 57 insertions(+), 131 deletions(-) delete mode 100644 extmod/machine_pwm.h diff --git a/extmod/machine_pwm.c b/extmod/machine_pwm.c index 8a633b3793..13b96eb5d4 100644 --- a/extmod/machine_pwm.c +++ b/extmod/machine_pwm.c @@ -28,11 +28,26 @@ #if MICROPY_PY_MACHINE_PWM -#include "extmod/machine_pwm.h" +#include "extmod/modmachine.h" -#ifdef MICROPY_PY_MACHINE_PWM_INCLUDEFILE -#include MICROPY_PY_MACHINE_PWM_INCLUDEFILE +// The port must provide implementations of these low-level PWM functions. +STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); +STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); +STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); +STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self); +STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self); +STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); +#if MICROPY_PY_MACHINE_PWM_DUTY +STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self); +STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty); #endif +STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self); +STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); +STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self); +STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); + +// The port provides implementations of the above in this file. +#include MICROPY_PY_MACHINE_PWM_INCLUDEFILE STATIC mp_obj_t machine_pwm_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_machine_pwm_init_helper(args[0], n_args - 1, args + 1, kw_args); diff --git a/extmod/machine_pwm.h b/extmod/machine_pwm.h deleted file mode 100644 index f0953014ca..0000000000 --- a/extmod/machine_pwm.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2021 Damien P. George - * - * 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. - */ - -#ifndef MICROPY_INCLUDED_EXTMOD_MACHINE_PWM_H -#define MICROPY_INCLUDED_EXTMOD_MACHINE_PWM_H - -#include "py/obj.h" - -// A port must provide this type, but it's otherwise opaque. -typedef struct _machine_pwm_obj_t machine_pwm_obj_t; - -// This PWM class is implemented by machine_pwm.c. -extern const mp_obj_type_t machine_pwm_type; - -// A port must provide implementations of these low-level PWM functions, either as global -// linker symbols, or included directly if MICROPY_PY_MACHINE_PWM_INCLUDEFILE is defined. -#ifndef MICROPY_PY_MACHINE_PWM_INCLUDEFILE -void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); -mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); -void mp_machine_pwm_deinit(machine_pwm_obj_t *self); -mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self); -void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); -mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self); -void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty); -mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self); -void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); -mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self); -void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); -#endif - -#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_PWM_H diff --git a/extmod/modmachine.h b/extmod/modmachine.h index 794c62cde2..22bd0d6258 100644 --- a/extmod/modmachine.h +++ b/extmod/modmachine.h @@ -30,12 +30,14 @@ #include "py/obj.h" // A port must provide these types, but they are otherwise opaque. +typedef struct _machine_pwm_obj_t machine_pwm_obj_t; typedef struct _machine_wdt_obj_t machine_wdt_obj_t; // These classes correspond to machine.Type entries in the machine module. // Their Python bindings are implemented in extmod, and their implementation // is provided by a port. extern const mp_obj_type_t machine_i2c_type; +extern const mp_obj_type_t machine_pwm_type; extern const mp_obj_type_t machine_spi_type; extern const mp_obj_type_t machine_timer_type; extern const mp_obj_type_t machine_wdt_type; diff --git a/ports/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c index 462d0fa79c..03ef2d77fd 100644 --- a/ports/esp32/machine_pwm.c +++ b/ports/esp32/machine_pwm.c @@ -27,11 +27,11 @@ * THE SOFTWARE. */ +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. + #include - -#include "py/runtime.h" #include "py/mphal.h" - #include "driver/ledc.h" #include "esp_err.h" #include "soc/gpio_sig_map.h" diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index f8567973b0..fe6d18e786 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -44,7 +44,6 @@ #include "extmod/machine_mem.h" #include "extmod/machine_signal.h" #include "extmod/machine_pulse.h" -#include "extmod/machine_pwm.h" #include "extmod/machine_i2c.h" #include "extmod/machine_spi.h" #include "extmod/modmachine.h" diff --git a/ports/esp8266/machine_pwm.c b/ports/esp8266/machine_pwm.c index 58c8fa915f..b9e499d252 100644 --- a/ports/esp8266/machine_pwm.c +++ b/ports/esp8266/machine_pwm.c @@ -24,10 +24,10 @@ * THE SOFTWARE. */ -#include "py/runtime.h" -#include "py/mphal.h" -#include "modmachine.h" +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. +#include "py/mphal.h" #include "esppwm.h" typedef struct _machine_pwm_obj_t { diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c index eee5f3c683..95048952c4 100644 --- a/ports/esp8266/modmachine.c +++ b/ports/esp8266/modmachine.c @@ -40,7 +40,6 @@ #include "extmod/machine_mem.h" #include "extmod/machine_signal.h" #include "extmod/machine_pulse.h" -#include "extmod/machine_pwm.h" #include "extmod/machine_i2c.h" #include "extmod/machine_spi.h" #include "extmod/modmachine.h" diff --git a/ports/mimxrt/machine_pwm.c b/ports/mimxrt/machine_pwm.c index a50b67cc8c..7b95d78877 100644 --- a/ports/mimxrt/machine_pwm.c +++ b/ports/mimxrt/machine_pwm.c @@ -25,9 +25,10 @@ * THE SOFTWARE. */ -#include "py/runtime.h" +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. + #include "py/mphal.h" -#include "modmachine.h" #include "pin.h" #include "fsl_clock.h" #include "fsl_iomuxc.h" diff --git a/ports/mimxrt/modmachine.h b/ports/mimxrt/modmachine.h index cf40505ea5..92d875b4d0 100644 --- a/ports/mimxrt/modmachine.h +++ b/ports/mimxrt/modmachine.h @@ -32,7 +32,6 @@ extern const mp_obj_type_t machine_adc_type; extern const mp_obj_type_t machine_i2c_type; extern const mp_obj_type_t machine_i2s_type; -extern const mp_obj_type_t machine_pwm_type; extern const mp_obj_type_t machine_rtc_type; extern const mp_obj_type_t machine_sdcard_type; extern const mp_obj_type_t machine_spi_type; diff --git a/ports/nrf/modules/machine/modmachine.c b/ports/nrf/modules/machine/modmachine.c index 616757a96a..59f163dee2 100644 --- a/ports/nrf/modules/machine/modmachine.c +++ b/ports/nrf/modules/machine/modmachine.c @@ -33,6 +33,7 @@ #include "extmod/machine_mem.h" #include "extmod/machine_pulse.h" #include "extmod/machine_i2c.h" +#include "extmod/modmachine.h" #include "shared/runtime/pyexec.h" #include "lib/oofatfs/ff.h" #include "lib/oofatfs/diskio.h" diff --git a/ports/nrf/modules/machine/pwm.c b/ports/nrf/modules/machine/pwm.c index 96917769ee..f0c11fa8fc 100644 --- a/ports/nrf/modules/machine/pwm.c +++ b/ports/nrf/modules/machine/pwm.c @@ -25,15 +25,11 @@ * THE SOFTWARE. */ -#include +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. + #include - -#include "py/nlr.h" -#include "py/runtime.h" #include "py/mphal.h" - -#if MICROPY_PY_MACHINE_HW_PWM - #include "pin.h" #include "genhdr/pins.h" #include "pwm.h" @@ -154,11 +150,6 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p /* MicroPython bindings for machine API */ STATIC void machine_hard_pwm_start(const machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_deinit(const machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_freq_set(const machine_pwm_obj_t *self, mp_int_t freq); -STATIC void mp_machine_pwm_duty_set(const machine_pwm_obj_t *self, mp_int_t duty); -STATIC void mp_machine_pwm_duty_set_u16(const machine_pwm_obj_t *self, mp_int_t duty_u16); -STATIC void mp_machine_pwm_duty_set_ns(const machine_pwm_obj_t *self, mp_int_t duty_ns); static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -171,7 +162,7 @@ static const mp_arg_t allowed_args[] = { { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, }; -STATIC void mp_machine_pwm_init_helper(const machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_pin, ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns, ARG_invert, ARG_device, ARG_channel }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -245,7 +236,7 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args // start the PWM running for this channel mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args); - mp_machine_pwm_init_helper(self, n_args, all_args, &kw_args); + mp_machine_pwm_init_helper((machine_pwm_obj_t *)self, n_args, all_args, &kw_args); return MP_OBJ_FROM_PTR(self); } @@ -253,23 +244,23 @@ STATIC mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args // Stop all PWM modules and release them void pwm_deinit_all(void) { for (int i = 0; i < MP_ARRAY_SIZE(machine_hard_pwm_instances); i++) { - mp_machine_pwm_deinit(&machine_hard_pwm_obj[i * NRF_PWM_CHANNEL_COUNT]); + mp_machine_pwm_deinit((machine_pwm_obj_t *)&machine_hard_pwm_obj[i * NRF_PWM_CHANNEL_COUNT]); } pwm_init0(); } // Stop the PWM module, but do not release it. -STATIC void mp_machine_pwm_deinit(const machine_pwm_obj_t *self) { +STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self) { self->p_config->active = STOPPED; nrfx_pwm_stop(self->p_pwm, true); nrfx_pwm_uninit(self->p_pwm); } -STATIC mp_obj_t mp_machine_pwm_freq_get(const machine_pwm_obj_t *self) { +STATIC mp_obj_t mp_machine_pwm_freq_get(machine_pwm_obj_t *self) { return MP_OBJ_NEW_SMALL_INT(self->p_config->freq); } -STATIC void mp_machine_pwm_freq_set(const machine_pwm_obj_t *self, mp_int_t freq) { +STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq) { uint8_t div = 0; if (freq > (PWM_MAX_BASE_FREQ / 3) || freq <= (PWM_MIN_BASE_FREQ / PWM_MAX_PERIOD)) { @@ -285,7 +276,7 @@ STATIC void mp_machine_pwm_freq_set(const machine_pwm_obj_t *self, mp_int_t freq machine_hard_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get(const machine_pwm_obj_t *self) { +STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) { if (self->p_config->duty_mode[self->channel] == DUTY_PERCENT) { return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]); } else if (self->p_config->duty_mode[self->channel] == DUTY_U16) { @@ -295,13 +286,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get(const machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set(const machine_pwm_obj_t *self, mp_int_t duty) { +STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty) { self->p_config->duty[self->channel] = duty; self->p_config->duty_mode[self->channel] = DUTY_PERCENT; machine_hard_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_u16(const machine_pwm_obj_t *self) { +STATIC mp_obj_t mp_machine_pwm_duty_get_u16(machine_pwm_obj_t *self) { if (self->p_config->duty_mode[self->channel] == DUTY_U16) { return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]); } else if (self->p_config->duty_mode[self->channel] == DUTY_PERCENT) { @@ -311,13 +302,13 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_u16(const machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_u16(const machine_pwm_obj_t *self, mp_int_t duty) { +STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty) { self->p_config->duty[self->channel] = duty; self->p_config->duty_mode[self->channel] = DUTY_U16; machine_hard_pwm_start(self); } -STATIC mp_obj_t mp_machine_pwm_duty_get_ns(const machine_pwm_obj_t *self) { +STATIC mp_obj_t mp_machine_pwm_duty_get_ns(machine_pwm_obj_t *self) { if (self->p_config->duty_mode[self->channel] == DUTY_NS) { return MP_OBJ_NEW_SMALL_INT(self->p_config->duty[self->channel]); } else { @@ -325,7 +316,7 @@ STATIC mp_obj_t mp_machine_pwm_duty_get_ns(const machine_pwm_obj_t *self) { } } -STATIC void mp_machine_pwm_duty_set_ns(const machine_pwm_obj_t *self, mp_int_t duty) { +STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty) { self->p_config->duty[self->channel] = duty; self->p_config->duty_mode[self->channel] = DUTY_NS; machine_hard_pwm_start(self); @@ -393,5 +384,3 @@ STATIC void machine_hard_pwm_start(const machine_pwm_obj_t *self) { 0, // Loop disabled. 0); } - -#endif // MICROPY_PY_MACHINE_HW_PWM diff --git a/ports/nrf/modules/machine/pwm.h b/ports/nrf/modules/machine/pwm.h index 4c0528fb4c..aceb76ba06 100644 --- a/ports/nrf/modules/machine/pwm.h +++ b/ports/nrf/modules/machine/pwm.h @@ -26,5 +26,3 @@ void pwm_init0(void); void pwm_deinit_all(void); - -extern const mp_obj_type_t machine_pwm_type; diff --git a/ports/nrf/modules/machine/soft_pwm.c b/ports/nrf/modules/machine/soft_pwm.c index 27783328eb..c69b5f0bbe 100644 --- a/ports/nrf/modules/machine/soft_pwm.c +++ b/ports/nrf/modules/machine/soft_pwm.c @@ -24,12 +24,10 @@ * THE SOFTWARE. */ -#include -#include "py/runtime.h" +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. + #include "py/mphal.h" - -#if MICROPY_PY_MACHINE_SOFT_PWM - #include "softpwm.h" typedef enum { @@ -62,11 +60,6 @@ STATIC void mp_machine_pwm_print(const mp_print_t *print, mp_obj_t self_in, mp_p // MicroPython bindings for machine API STATIC void machine_soft_pwm_start(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_deinit(machine_pwm_obj_t *self); -STATIC void mp_machine_pwm_freq_set(machine_pwm_obj_t *self, mp_int_t freq); -STATIC void mp_machine_pwm_duty_set(machine_pwm_obj_t *self, mp_int_t duty); -STATIC void mp_machine_pwm_duty_set_u16(machine_pwm_obj_t *self, mp_int_t duty_u16); -STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns); STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_freq, ARG_duty, ARG_duty_u16, ARG_duty_ns }; @@ -210,5 +203,3 @@ STATIC void machine_soft_pwm_start(machine_pwm_obj_t *self) { pwm_set_duty_cycle(self->pwm_pin, duty_width); } } - -#endif // MICROPY_PY_MACHINE_HW_PWM diff --git a/ports/renesas-ra/machine_pwm.c b/ports/renesas-ra/machine_pwm.c index f2199805a1..936f698e33 100644 --- a/ports/renesas-ra/machine_pwm.c +++ b/ports/renesas-ra/machine_pwm.c @@ -25,15 +25,13 @@ * THE SOFTWARE. */ -#include "py/runtime.h" +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. + #include "py/mphal.h" #include "py/mperrno.h" -#include "extmod/machine_pwm.h" #include "pin.h" #include "ra/ra_gpt.h" -#include "modmachine.h" - -#if MICROPY_HW_ENABLE_HW_PWM typedef struct _machine_pwm_obj_t { mp_obj_base_t base; @@ -353,5 +351,3 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns } } } - -#endif // MICROPY_HW_ENABLE_HW_PWM diff --git a/ports/renesas-ra/modmachine.c b/ports/renesas-ra/modmachine.c index bc85d9b7f8..6f7b8b8c07 100644 --- a/ports/renesas-ra/modmachine.c +++ b/ports/renesas-ra/modmachine.c @@ -40,7 +40,7 @@ #include "extmod/machine_pulse.h" #include "extmod/machine_i2c.h" #include "extmod/machine_spi.h" -#include "extmod/machine_pwm.h" +#include "extmod/modmachine.h" #include "shared/runtime/pyexec.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs.h" diff --git a/ports/rp2/machine_pwm.c b/ports/rp2/machine_pwm.c index a14ba0a43a..0248b3142a 100644 --- a/ports/rp2/machine_pwm.c +++ b/ports/rp2/machine_pwm.c @@ -24,10 +24,10 @@ * THE SOFTWARE. */ -#include "py/runtime.h" -#include "py/mphal.h" -#include "modmachine.h" +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. +#include "py/mphal.h" #include "hardware/clocks.h" #include "hardware/pwm.h" diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index eedeca1e3b..11de929e7b 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -32,7 +32,6 @@ #include "extmod/machine_i2c.h" #include "extmod/machine_mem.h" #include "extmod/machine_pulse.h" -#include "extmod/machine_pwm.h" #include "extmod/machine_signal.h" #include "extmod/machine_spi.h" #include "extmod/modmachine.h" diff --git a/ports/samd/machine_pwm.c b/ports/samd/machine_pwm.c index 1b5f6c3ed8..196a9b1435 100644 --- a/ports/samd/machine_pwm.c +++ b/ports/samd/machine_pwm.c @@ -25,15 +25,12 @@ * THE SOFTWARE. */ -#include "py/runtime.h" - -#if MICROPY_PY_MACHINE_PWM +// This file is never compiled standalone, it's included directly from +// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE. #include #include "py/mphal.h" -#include "modmachine.h" #include "clock_config.h" - #include "sam.h" #include "pin_af.h" @@ -396,5 +393,3 @@ STATIC void mp_machine_pwm_duty_set_ns(machine_pwm_obj_t *self, mp_int_t duty_ns duty_type_flags[self->device] &= ~(1 << self->channel); mp_machine_pwm_start(self); } - -#endif diff --git a/ports/samd/modmachine.h b/ports/samd/modmachine.h index d62b14a0aa..faa43b7af7 100644 --- a/ports/samd/modmachine.h +++ b/ports/samd/modmachine.h @@ -39,9 +39,6 @@ extern const mp_obj_type_t machine_dac_type; extern const mp_obj_type_t machine_i2c_type; #endif extern const mp_obj_type_t machine_pin_type; -#if MICROPY_PY_MACHINE_PWM -extern const mp_obj_type_t machine_pwm_type; -#endif #if MICROPY_PY_MACHINE_SPI extern const mp_obj_type_t machine_spi_type; #endif