From a513558e3a72b47880faa847de64949e7fc746f6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 11 Nov 2022 15:43:55 +1100 Subject: [PATCH] extmod: Add and reorganise compilation guards and includes. To reduce dependencies on header files when extmod components are disabled. Signed-off-by: Damien George --- extmod/machine_spi.c | 5 +++-- extmod/machine_timer.c | 3 ++- extmod/modnetwork.c | 5 +++-- extmod/modusocket.c | 5 +++-- extmod/uos_dupterm.c | 3 ++- extmod/vfs_lfs.c | 5 +++-- extmod/vfs_lfsx.c | 5 +++++ extmod/vfs_lfsx_file.c | 5 +++++ 8 files changed, 26 insertions(+), 10 deletions(-) diff --git a/extmod/machine_spi.c b/extmod/machine_spi.c index bb35cff38e..8c4d91a3cf 100644 --- a/extmod/machine_spi.c +++ b/extmod/machine_spi.c @@ -28,6 +28,9 @@ #include #include "py/runtime.h" + +#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI + #include "extmod/machine_spi.h" // if a port didn't define MSB/LSB constants then provide them @@ -39,8 +42,6 @@ /******************************************************************************/ // MicroPython bindings for generic machine.SPI -#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI - STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]); mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol); diff --git a/extmod/machine_timer.c b/extmod/machine_timer.c index cdace4ee24..68702cb74f 100644 --- a/extmod/machine_timer.c +++ b/extmod/machine_timer.c @@ -26,10 +26,11 @@ #include "py/runtime.h" #include "py/mphal.h" -#include "shared/runtime/softtimer.h" #if MICROPY_PY_MACHINE_TIMER +#include "shared/runtime/softtimer.h" + typedef soft_timer_entry_t machine_timer_obj_t; const mp_obj_type_t machine_timer_type; diff --git a/extmod/modnetwork.c b/extmod/modnetwork.c index b698ee4cf4..0ff8683b74 100644 --- a/extmod/modnetwork.c +++ b/extmod/modnetwork.c @@ -31,11 +31,12 @@ #include "py/objlist.h" #include "py/runtime.h" #include "py/mphal.h" -#include "shared/netutils/netutils.h" -#include "modnetwork.h" #if MICROPY_PY_NETWORK +#include "shared/netutils/netutils.h" +#include "modnetwork.h" + #if MICROPY_PY_LWIP #include "lwip/netif.h" #include "lwip/timeouts.h" diff --git a/extmod/modusocket.c b/extmod/modusocket.c index 194ee6899e..0006465924 100644 --- a/extmod/modusocket.c +++ b/extmod/modusocket.c @@ -32,11 +32,12 @@ #include "py/runtime.h" #include "py/stream.h" #include "py/mperrno.h" -#include "shared/netutils/netutils.h" -#include "modnetwork.h" #if MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP +#include "shared/netutils/netutils.h" +#include "modnetwork.h" + /******************************************************************************/ // socket class diff --git a/extmod/uos_dupterm.c b/extmod/uos_dupterm.c index 826bf1715d..981d05a638 100644 --- a/extmod/uos_dupterm.c +++ b/extmod/uos_dupterm.c @@ -33,10 +33,11 @@ #include "py/objarray.h" #include "py/stream.h" #include "extmod/misc.h" -#include "shared/runtime/interrupt_char.h" #if MICROPY_PY_OS_DUPTERM +#include "shared/runtime/interrupt_char.h" + void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) { mp_obj_t term = MP_STATE_VM(dupterm_objs[dupterm_idx]); MP_STATE_VM(dupterm_objs[dupterm_idx]) = MP_OBJ_NULL; diff --git a/extmod/vfs_lfs.c b/extmod/vfs_lfs.c index f6a9a24623..4fb86b89b7 100644 --- a/extmod/vfs_lfs.c +++ b/extmod/vfs_lfs.c @@ -26,12 +26,13 @@ #include "py/runtime.h" #include "py/mphal.h" + +#if MICROPY_VFS && (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2) + #include "shared/timeutils/timeutils.h" #include "extmod/vfs.h" #include "extmod/vfs_lfs.h" -#if MICROPY_VFS && (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2) - enum { LFS_MAKE_ARG_bdev, LFS_MAKE_ARG_readsize, LFS_MAKE_ARG_progsize, LFS_MAKE_ARG_lookahead, LFS_MAKE_ARG_mtime }; static const mp_arg_t lfs_make_allowed_args[] = { diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index d9617817f9..de1f421977 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -24,6 +24,9 @@ * THE SOFTWARE. */ +// This file should be compiled when included from vfs_lfs.c. +#if defined(LFS_BUILD_VERSION) + #include #include @@ -518,3 +521,5 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #undef VFS_LFSx_QSTR + +#endif // defined(LFS_BUILD_VERSION) diff --git a/extmod/vfs_lfsx_file.c b/extmod/vfs_lfsx_file.c index 2c87fd5b99..5f0155d3c5 100644 --- a/extmod/vfs_lfsx_file.c +++ b/extmod/vfs_lfsx_file.c @@ -24,6 +24,9 @@ * THE SOFTWARE. */ +// This file should be compiled when included from vfs_lfs.c. +#if defined(LFS_BUILD_VERSION) + #include #include @@ -244,3 +247,5 @@ MP_DEFINE_CONST_OBJ_TYPE( protocol, &MP_VFS_LFSx(textio_stream_p), locals_dict, &MP_VFS_LFSx(file_locals_dict) ); + +#endif // defined(LFS_BUILD_VERSION)