Skip to content

Commit 427d33c

Browse files
committed
atmel-samd: Add help() and remove mem_info functions from smallest builds to make room.
1 parent 5763735 commit 427d33c

File tree

6 files changed

+133
-4
lines changed

6 files changed

+133
-4
lines changed

atmel-samd/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ SRC_C = \
197197
lib/fatfs/ff.c \
198198
lib/fatfs/option/ccsbcs.c \
199199
lib/timeutils/timeutils.c \
200-
lib/utils/stdout_helpers.c \
201200
lib/utils/pyexec.c \
201+
lib/utils/pyhelp.c \
202+
lib/utils/stdout_helpers.c \
202203
lib/libc/string0.c \
203204
lib/mp-readline/readline.c
204205

@@ -236,6 +237,7 @@ SRC_BINDINGS_EXPANDED += common-hal/nativeio/TouchIn.c
236237
endif
237238

238239
SRC_SHARED_MODULE = \
240+
help.c \
239241
bitbangio/__init__.c \
240242
bitbangio/I2C.c \
241243
bitbangio/SPI.c \

atmel-samd/mpconfigport.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
77

8+
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
9+
810
// options to control how Micro Python is built
911

1012
#define MICROPY_QSTR_BYTES_IN_HASH (1)
@@ -77,14 +79,13 @@
7779

7880
#define MICROPY_VFS_FAT (1)
7981
#define MICROPY_PY_MACHINE (1)
80-
#define MICROPY_MODULE_WEAK_LINKS (1)
82+
#define MICROPY_MODULE_WEAK_LINKS (0)
8183
#define MICROPY_REPL_AUTO_INDENT (1)
8284
#define MICROPY_HW_ENABLE_DAC (1)
8385
#define MICROPY_ENABLE_FINALISER (1)
8486
#define MICROPY_USE_INTERNAL_PRINTF (1)
8587
#define MICROPY_PY_SYS_STDFILES (1)
8688
#define MICROPY_PY_IO_FILEIO (1)
87-
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
8889
#define MICROPY_PERSISTENT_CODE_LOAD (1)
8990
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
9091

@@ -109,6 +110,7 @@ typedef long mp_off_t;
109110

110111
// extra built in names to add to the global namespace
111112
#define MICROPY_PORT_BUILTINS \
113+
{ MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
112114
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
113115

114116
// board specific definitions
@@ -125,10 +127,13 @@ extern const struct _mp_obj_module_t neopixel_write_module;
125127
extern const struct _mp_obj_module_t uheap_module;
126128
extern const struct _mp_obj_module_t samd_module;
127129

130+
// Internal flash size dependent settings.
128131
#if BOARD_FLASH_SIZE > 192000
132+
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
129133
#define EXTRA_BUILTIN_MODULES \
130134
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module }
131135
#else
136+
#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
132137
#define EXTRA_BUILTIN_MODULES
133138
#endif
134139

py/objmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
225225
#endif
226226
};
227227

228-
STATIC MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table);
228+
MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table);
229229

230230
void mp_module_init(void) {
231231
mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), 3);

shared-bindings/help.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "lib/utils/pyhelp.h"
28+
#include "shared-bindings/help.h"
29+
30+
//| .. method:: help(object=None)
31+
//|
32+
//| Prints a help method about the given object. When ``object`` is none,
33+
//| prints general port information.
34+
//|
35+
STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) {
36+
if (n_args == 0) {
37+
shared_module_help();
38+
} else {
39+
// try to print something sensible about the given object
40+
pyhelp_print_obj(args[0]);
41+
}
42+
43+
return mp_const_none;
44+
}
45+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, pyb_help);

shared-bindings/help.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_HELP_H__
28+
#define __MICROPY_INCLUDED_SHARED_BINDINGS_HELP_H__
29+
30+
#include "py/obj.h"
31+
32+
extern void shared_module_help(void);
33+
34+
#endif // __MICROPY_INCLUDED_SHARED_BINDINGS_HELP_H__

shared-module/help.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "genhdr/mpversion.h"
28+
#include "py/mpprint.h"
29+
#include "shared-bindings/help.h"
30+
31+
extern const mp_map_t mp_builtin_module_map;
32+
33+
void shared_module_help(void) {
34+
mp_printf(&mp_plat_print,
35+
"Welcome to Adafruit MicroPython " MICROPY_GIT_TAG "!\r\n"
36+
"\r\n"
37+
"Please visit learn.adafruit.com/category/micropython for project guides.\r\n"
38+
"\r\n"
39+
"Built in modules:\r\n");
40+
for (int i = 0; i < mp_builtin_module_map.used; i++) {
41+
mp_printf(&mp_plat_print, "\t%q\r\n", MP_OBJ_QSTR_VALUE(mp_builtin_module_map.table[i].key));
42+
}
43+
}

0 commit comments

Comments
 (0)