summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-10-20 16:00:36 +1100
committerDamien George <damien@micropython.org>2023-10-20 16:24:46 +1100
commit7e7af715271c8c3ca3ec8c600b835aa388624461 (patch)
treede39d7337588ff32ddf786ee398df6cf52ccde2f
parent60929ec7e2c19b896487491192361e44f7cee0d9 (diff)
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 <damien@micropython.org>
-rw-r--r--extmod/machine_pwm.c21
-rw-r--r--extmod/machine_pwm.h55
-rw-r--r--extmod/modmachine.h2
-rw-r--r--ports/esp32/machine_pwm.c6
-rw-r--r--ports/esp32/modmachine.c1
-rw-r--r--ports/esp8266/machine_pwm.c6
-rw-r--r--ports/esp8266/modmachine.c1
-rw-r--r--ports/mimxrt/machine_pwm.c5
-rw-r--r--ports/mimxrt/modmachine.h1
-rw-r--r--ports/nrf/modules/machine/modmachine.c1
-rw-r--r--ports/nrf/modules/machine/pwm.c41
-rw-r--r--ports/nrf/modules/machine/pwm.h2
-rw-r--r--ports/nrf/modules/machine/soft_pwm.c15
-rw-r--r--ports/renesas-ra/machine_pwm.c10
-rw-r--r--ports/renesas-ra/modmachine.c2
-rw-r--r--ports/rp2/machine_pwm.c6
-rw-r--r--ports/rp2/modmachine.c1
-rw-r--r--ports/samd/machine_pwm.c9
-rw-r--r--ports/samd/modmachine.h3
19 files changed, 57 insertions, 131 deletions
diff --git a/extmod/machine_pwm.c b/extmod/machine_pwm.c
index 8a633b379..13b96eb5d 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 f0953014c..000000000
--- 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 794c62cde..22bd0d625 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 462d0fa79..03ef2d77f 100644
--- a/ports/esp32/machine_pwm.c
+++ b/ports/esp32/machine_pwm.c
@@ -27,11 +27,11 @@
* THE SOFTWARE.
*/
-#include <math.h>
+// This file is never compiled standalone, it's included directly from
+// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE.
-#include "py/runtime.h"
+#include <math.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 f8567973b..fe6d18e78 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 58c8fa915..b9e499d25 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 eee5f3c68..95048952c 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 a50b67cc8..7b95d7887 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 cf40505ea..92d875b4d 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 616757a96..59f163dee 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 96917769e..f0c11fa8f 100644
--- a/ports/nrf/modules/machine/pwm.c
+++ b/ports/nrf/modules/machine/pwm.c
@@ -25,15 +25,11 @@
* THE SOFTWARE.
*/
-#include <stdio.h>
-#include <string.h>
+// This file is never compiled standalone, it's included directly from
+// extmod/machine_pwm.c via MICROPY_PY_MACHINE_PWM_INCLUDEFILE.
-#include "py/nlr.h"
-#include "py/runtime.h"
+#include <string.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 4c0528fb4..aceb76ba0 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 27783328e..c69b5f0bb 100644
--- a/ports/nrf/modules/machine/soft_pwm.c
+++ b/ports/nrf/modules/machine/soft_pwm.c
@@ -24,12 +24,10 @@
* THE SOFTWARE.
*/
-#include <stdio.h>
-#include "py/runtime.h"
-#include "py/mphal.h"
-
-#if MICROPY_PY_MACHINE_SOFT_PWM
+// 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 "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 f2199805a..936f698e3 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 bc85d9b7f..6f7b8b8c0 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 a14ba0a43..0248b3142 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 eedeca1e3..11de929e7 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 1b5f6c3ed..196a9b143 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 <string.h>
#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 d62b14a0a..faa43b7af 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