8000 extmod: Add and reorganise compilation guards and includes. · pybricks/micropython@a513558 · GitHub
[go: up one dir, main page]

Skip to content

Commit a513558

Browse files
committed
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>
1 parent 2f05653 commit a513558

File tree

8 files changed

+26
-10
lines changed

8 files changed

+26
-10
lines changed

extmod/machine_spi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <string.h>
2929

3030
#include "py/runtime.h"
31+
32+
#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI
33+
3134
#include "extmod/machine_spi.h"
3235

3336
// if a port didn't define MSB/LSB constants then provide them
@@ -39,8 +42,6 @@
3942
/******************************************************************************/
4043
// MicroPython bindings for generic machine.SPI
4144

42-
#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI
43-
4445
STATIC mp_obj_t machine_spi_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
4546
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(args[0]);
4647
mp_machine_spi_p_t *spi_p = (mp_machine_spi_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol);

extmod/machine_timer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626

2727
#include "py/runtime.h"
2828
#include "py/mphal.h"
29-
#include "shared/runtime/softtimer.h"
3029

3130
#if MICROPY_PY_MACHINE_TIMER
3231

32+
#include "shared/runtime/softtimer.h"
33+
3334
typedef soft_timer_entry_t machine_timer_obj_t;
3435

3536
const mp_obj_type_t machine_timer_type;

extmod/modnetwork.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
#include "py/objlist.h"
3232
#include "py/runtime.h"
3333
#include "py/mphal.h"
34-
#include "shared/netutils/netutils.h"
35-
#include "modnetwork.h"
3634

3735
#if MICROPY_PY_NETWORK
3836

37+
#include "shared/netutils/netutils.h"
38+
#include "modnetwork.h"
39+
3940
#if MICROPY_PY_LWIP
4041
#include "lwip/netif.h"
4142
#include "lwip/timeouts.h"

extmod/modusocket.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
#include "py/runtime.h"
3333
#include "py/stream.h"
3434
#include "py/mperrno.h"
35-
#include "shared/netutils/netutils.h"
36-
#include "modnetwork.h"
3735

3836
#if MICROPY_PY_NETWORK && MICROPY_PY_USOCKET && !MICROPY_PY_LWIP
3937

38+
#include "shared/netutils/netutils.h"
39+
#include "modnetwork.h"
40+
4041
/******************************************************************************/
4142
// socket class
4243

extmod/uos_dupterm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
#include "py/objarray.h"
3434
#include "py/stream.h"
3535
#include "extmod/misc.h"
36-
#include "shared/runtime/interrupt_char.h"
3736

3837
#if MICROPY_PY_OS_DUPTERM
3938

39+
#include "shared/runtime/interrupt_char.h"
40+
4041
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) {
4142
mp_obj_t term = MP_STATE_VM(dupterm_objs[dupterm_idx]);
4243
MP_STATE_VM(dupterm_objs[dupterm_idx]) = MP_OBJ_NULL;

extmod/vfs_lfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626

2727
#include "py/runtime.h"
2828
#include "py/mphal.h"
29+
30+
#if MICROPY_VFS && (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2)
31+
2932
#include "shared/timeutils/timeutils.h"
3033
#include "extmod/vfs.h"
3134
#include "extmod/vfs_lfs.h"
3235

33-
#if MICROPY_VFS && (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2)
34-
3536
enum { LFS_MAKE_ARG_bdev, LFS_MAKE_ARG_readsize, LFS_MAKE_ARG_progsize, LFS_MAKE_ARG_lookahead, LFS_MAKE_ARG_mtime };
3637

3738
static const mp_arg_t lfs_make_allowed_args[] = {

extmod/vfs_lfsx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
// This file should be compiled when included from vfs_lfs.c.
28+
#if defined(LFS_BUILD_VERSION)
29+
2730
#include <stdio.h>
2831
#include <string.h>
2932

@@ -518,3 +521,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
518521
);
519522

520523
#undef VFS_LFSx_QSTR
524+
525+
#endif // defined(LFS_BUILD_VERSION)

extmod/vfs_lfsx_file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
// This file should be compiled when included from vfs_lfs.c.
28+
#if defined(LFS_BUILD_VERSION)
29+
2730
#include <stdio.h>
2831
#include <string.h>
2932

@@ -244,3 +247,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
244247
protocol, &MP_VFS_LFSx(textio_stream_p),
245248
locals_dict, &MP_VFS_LFSx(file_locals_dict)
246249
);
250+
251+
#endif // defined(LFS_BUILD_VERSION)

0 commit comments

Comments
 (0)
0