summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2016-12-19 16:38:35 -0800
committerScott Shawcroft <scott.shawcroft@gmail.com>2016-12-19 16:38:35 -0800
commit427d33c706236985dff950382e1c6b896b36b1bd (patch)
treed005ec600579bf605893abcfbb56228a1aa8d259
parent576373552a9e0f53c24b55c40fdeb8be61807597 (diff)
atmel-samd: Add help() and remove mem_info functions from smallest builds to make room.
-rw-r--r--atmel-samd/Makefile4
-rw-r--r--atmel-samd/mpconfigport.h9
-rw-r--r--py/objmodule.c2
-rw-r--r--shared-bindings/help.c45
-rw-r--r--shared-bindings/help.h34
-rw-r--r--shared-module/help.c43
6 files changed, 133 insertions, 4 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile
index a7d93ae56..e6f7534a0 100644
--- a/atmel-samd/Makefile
+++ b/atmel-samd/Makefile
@@ -197,8 +197,9 @@ SRC_C = \
lib/fatfs/ff.c \
lib/fatfs/option/ccsbcs.c \
lib/timeutils/timeutils.c \
- lib/utils/stdout_helpers.c \
lib/utils/pyexec.c \
+ lib/utils/pyhelp.c \
+ lib/utils/stdout_helpers.c \
lib/libc/string0.c \
lib/mp-readline/readline.c
@@ -236,6 +237,7 @@ SRC_BINDINGS_EXPANDED += common-hal/nativeio/TouchIn.c
endif
SRC_SHARED_MODULE = \
+ help.c \
bitbangio/__init__.c \
bitbangio/I2C.c \
bitbangio/SPI.c \
diff --git a/atmel-samd/mpconfigport.h b/atmel-samd/mpconfigport.h
index 8bb93bf19..b97eab29a 100644
--- a/atmel-samd/mpconfigport.h
+++ b/atmel-samd/mpconfigport.h
@@ -5,6 +5,8 @@
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
+#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
+
// options to control how Micro Python is built
#define MICROPY_QSTR_BYTES_IN_HASH (1)
@@ -77,14 +79,13 @@
#define MICROPY_VFS_FAT (1)
#define MICROPY_PY_MACHINE (1)
-#define MICROPY_MODULE_WEAK_LINKS (1)
+#define MICROPY_MODULE_WEAK_LINKS (0)
#define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_HW_ENABLE_DAC (1)
#define MICROPY_ENABLE_FINALISER (1)
#define MICROPY_USE_INTERNAL_PRINTF (1)
#define MICROPY_PY_SYS_STDFILES (1)
#define MICROPY_PY_IO_FILEIO (1)
-#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PERSISTENT_CODE_LOAD (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
@@ -109,6 +110,7 @@ typedef long mp_off_t;
// extra built in names to add to the global namespace
#define MICROPY_PORT_BUILTINS \
+ { MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
// board specific definitions
@@ -125,10 +127,13 @@ extern const struct _mp_obj_module_t neopixel_write_module;
extern const struct _mp_obj_module_t uheap_module;
extern const struct _mp_obj_module_t samd_module;
+// Internal flash size dependent settings.
#if BOARD_FLASH_SIZE > 192000
+ #define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define EXTRA_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }
#else
+ #define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
#define EXTRA_BUILTIN_MODULES
#endif
diff --git a/py/objmodule.c b/py/objmodule.c
index 48e373b84..524112f3d 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -225,7 +225,7 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
#endif
};
-STATIC MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table);
+MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table);
void mp_module_init(void) {
mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), 3);
diff --git a/shared-bindings/help.c b/shared-bindings/help.c
new file mode 100644
index 000000000..dfdd72680
--- /dev/null
+++ b/shared-bindings/help.c
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "lib/utils/pyhelp.h"
+#include "shared-bindings/help.h"
+
+//| .. method:: help(object=None)
+//|
+//| Prints a help method about the given object. When ``object`` is none,
+//| prints general port information.
+//|
+STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
+ if (n_args == 0) {
+ shared_module_help();
+ } else {
+ // try to print something sensible about the given object
+ pyhelp_print_obj(args[0]);
+ }
+
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, pyb_help);
diff --git a/shared-bindings/help.h b/shared-bindings/help.h
new file mode 100644
index 000000000..db62f96f9
--- /dev/null
+++ b/shared-bindings/help.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_HELP_H__
+#define __MICROPY_INCLUDED_SHARED_BINDINGS_HELP_H__
+
+#include "py/obj.h"
+
+extern void shared_module_help(void);
+
+#endif // __MICROPY_INCLUDED_SHARED_BINDINGS_HELP_H__
diff --git a/shared-module/help.c b/shared-module/help.c
new file mode 100644
index 000000000..fbde9a7ad
--- /dev/null
+++ b/shared-module/help.c
@@ -0,0 +1,43 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "genhdr/mpversion.h"
+#include "py/mpprint.h"
+#include "shared-bindings/help.h"
+
+extern const mp_map_t mp_builtin_module_map;
+
+void shared_module_help(void) {
+ mp_printf(&mp_plat_print,
+ "Welcome to Adafruit MicroPython " MICROPY_GIT_TAG "!\r\n"
+ "\r\n"
+ "Please visit learn.adafruit.com/category/micropython for project guides.\r\n"
+ "\r\n"
+ "Built in modules:\r\n");
+ for (int i = 0; i < mp_builtin_module_map.used; i++) {
+ mp_printf(&mp_plat_print, "\t%q\r\n", MP_OBJ_QSTR_VALUE(mp_builtin_module_map.table[i].key));
+ }
+}