extmod: Add and reorganise compilation guards and includes.

To reduce dependencies on header files when extmod components are disabled.

Signed-off-by: Damien George <damien.p.george@gmail.com>
This commit is contained in:
Damien George 2022-11-11 15:43:55 +11:00
parent 2f05653673
commit a513558e3a
8 changed files with 26 additions and 10 deletions

View File

@ -28,6 +28,9 @@
#include <string.h>
#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);

View File

@ -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;

View File

@ -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"

View File

@ -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

View File

@ -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;

View File

@ -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[] = {

View File

@ -24,6 +24,9 @@
* THE SOFTWARE.
*/
// This file should be compiled when included from vfs_lfs.c.
#if defined(LFS_BUILD_VERSION)
#include <stdio.h>
#include <string.h>
@ -518,3 +521,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
);
#undef VFS_LFSx_QSTR
#endif // defined(LFS_BUILD_VERSION)

View File

@ -24,6 +24,9 @@
* THE SOFTWARE.
*/
// This file should be compiled when included from vfs_lfs.c.
#if defined(LFS_BUILD_VERSION)
#include <stdio.h>
#include <string.h>
@ -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)