Przeglądaj źródła

Merge pull request #159 from heyuanjie87/master

优化:新加模块时可引用用户定义的头文件,这样不需要再修改软件包的代码
朱天龙 (Armink) 5 lat temu
rodzic
commit
e61a496d70
3 zmienionych plików z 23 dodań i 0 usunięć
  1. 17 0
      port/mpconfigport.h
  2. 3 0
      py/qstr.c
  3. 3 0
      py/qstr.h

+ 17 - 0
port/mpconfigport.h

@@ -281,6 +281,22 @@
     } while (0);
     } while (0);
 #endif
 #endif
 
 
+/*****************************************************************************/
+/* Modules define in your project
+   You must provide 'moddefs.user.extmods.h'
+   and 'qstrdefs.user.extmods.h'
+*/
+
+#ifdef MICROPYTHON_USING_USEREXTMODS
+#define MICROPY_USER_EXTMODS     (1)
+#include <moddefs.user.extmods.h>
+#else
+#define MICROPY_USER_EXTMODS     (0)
+#endif
+#ifndef MICROPY_USER_MODULES
+#define MICROPY_USER_MODULES
+#endif
+
 #if defined(__CC_ARM)
 #if defined(__CC_ARM)
 #include <sys/types.h>
 #include <sys/types.h>
 #define MICROPY_NO_ALLOCA           1
 #define MICROPY_NO_ALLOCA           1
@@ -498,6 +514,7 @@ extern const struct _mp_obj_module_t mp_module_userfunc;
     MODFFI_PORT_BUILTIN_MODULES \
     MODFFI_PORT_BUILTIN_MODULES \
     MODNETWORK_PORT_BUILTIN_MODULES \
     MODNETWORK_PORT_BUILTIN_MODULES \
     USERFUNC_PORT_BUILTIN_MODULES \
     USERFUNC_PORT_BUILTIN_MODULES \
+    MICROPY_USER_MODULES \
 
 
 #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
 #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
     MODUTIME_PORT_BUILTIN_MODULE_WEAK_LINKS \
     MODUTIME_PORT_BUILTIN_MODULE_WEAK_LINKS \

+ 3 - 0
py/qstr.c

@@ -109,6 +109,9 @@ const qstr_pool_t mp_qstr_const_pool = {
 #ifndef NO_QSTR
 #ifndef NO_QSTR
 #define QDEF(id, str) str,
 #define QDEF(id, str) str,
 #include "genhdr/qstrdefs.generated.h"
 #include "genhdr/qstrdefs.generated.h"
+#if (MICROPY_USER_EXTMODS == 1)
+#include <qstrdefs.user.extmods.h>
+#endif
 #undef QDEF
 #undef QDEF
 #endif
 #endif
     },
     },

+ 3 - 0
py/qstr.h

@@ -40,6 +40,9 @@ enum {
 #ifndef NO_QSTR
 #ifndef NO_QSTR
 #define QDEF(id, str) id,
 #define QDEF(id, str) id,
 #include "genhdr/qstrdefs.generated.h"
 #include "genhdr/qstrdefs.generated.h"
+#if (MICROPY_USER_EXTMODS == 1)
+#include <qstrdefs.user.extmods.h>
+#endif
 #undef QDEF
 #undef QDEF
 #endif
 #endif
     MP_QSTRnumber_of, // no underscore so it can't clash with any of the above
     MP_QSTRnumber_of, // no underscore so it can't clash with any of the above