Skip to content

Commit 1e30005

Browse files
committed
优化:新加模块时可引用用户定义的头文件,这样不需要再修改软件包的代码
1 parent 9d0a0ad commit 1e30005

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

port/mpconfigport.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,22 @@
281281
} while (0);
282282
#endif
283283

284+
/*****************************************************************************/
285+
/* Modules define in your project
286+
You must provide 'moddefsuserextmods.h'
287+
and 'qstrdefsuserextmods.h'
288+
*/
289+
290+
#ifdef MICROPYTHON_USING_USEREXTMODS
291+
#define MICROPY_USER_EXTMODS (1)
292+
#include <moddefsuserextmods.h>
293+
#else
294+
#define MICROPY_USER_EXTMODS (0)
295+
#endif
296+
#ifndef MICROPY_USER_MODULES
297+
#define MICROPY_USER_MODULES
298+
#endif
299+
284300
#if defined(__CC_ARM)
285301
#include <sys/types.h>
286302
#define MICROPY_NO_ALLOCA 1
@@ -498,6 +514,7 @@ extern const struct _mp_obj_module_t mp_module_userfunc;
498514
MODFFI_PORT_BUILTIN_MODULES \
499515
MODNETWORK_PORT_BUILTIN_MODULES \
500516
USERFUNC_PORT_BUILTIN_MODULES \
517+
MICROPY_USER_MODULES \
501518

502519
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
503520
MODUTIME_PORT_BUILTIN_MODULE_WEAK_LINKS \

py/qstr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ const qstr_pool_t mp_qstr_const_pool = {
109109
#ifndef NO_QSTR
110110
#define QDEF(id, str) str,
111111
#include "genhdr/qstrdefs.generated.h"
112+
#if (MICROPY_USER_EXTMODS == 1)
113+
#include <qstrdefsuserextmods.h>
114+
#endif
112115
#undef QDEF
113116
#endif
114117
},

py/qstr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ enum {
4040
#ifndef NO_QSTR
4141
#define QDEF(id, str) id,
4242
#include "genhdr/qstrdefs.generated.h"
43+
#if (MICROPY_USER_EXTMODS == 1)
44+
#include <qstrdefsuserextmods.h>
45+
#endif
4346
#undef QDEF
4447
#endif
4548
MP_QSTRnumber_of, // no underscore so it can't clash with any of the above

0 commit comments

Comments
 (0)