atmel-samd: Add help() and remove mem_info functions from smallest builds to make room.

This commit is contained in:
Scott Shawcroft 2016-12-19 16:38:35 -08:00
parent 576373552a
commit 427d33c706
6 changed files with 133 additions and 4 deletions

View File

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

View File

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

View File

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

45
shared-bindings/help.c Normal file
View File

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

34
shared-bindings/help.h Normal file
View File

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

43
shared-module/help.c Normal file
View File

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