Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit b6a544b

Browse files
Daniel ThompsonPaul Sokolovsky
Daniel Thompson
authored and
Paul Sokolovsky
committed
zephyr: Implement the help() function.
The boot issue text mentions a help() function and encourages the user to run it. It is very disconcerting to find that the function does not exist... Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
1 parent 06ee5e9 commit b6a544b

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

zephyr/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ INC += -I$(ZEPHYR_BASE)/net/ip/contiki
3333
INC += -I$(ZEPHYR_BASE)/net/ip/contiki/os
3434

3535
SRC_C = main.c \
36+
help.c \
3637
uart_core.c \
3738
lib/utils/stdout_helpers.c \
3839
lib/utils/printf.c \
3940
lib/utils/pyexec.c \
4041
lib/utils/interrupt_char.c \
42+
lib/utils/pyhelp.c \
4143
lib/mp-readline/readline.c \
4244
$(BUILD)/frozen.c \
4345
$(SRC_MOD)

zephyr/help.c

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2016 Damien P. George
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 <stdio.h>
28+
29+
#include "lib/utils/pyhelp.h"
30+
31+
STATIC const char *help_text =
32+
"Welcome to MicroPython!\n"
33+
"\n"
34+
"Control commands:\n"
35+
" CTRL-A -- on a blank line, enter raw REPL mode\n"
36+
" CTRL-B -- on a blank line, enter normal REPL mode\n"
37+
" CTRL-C -- interrupt a running program\n"
38+
" CTRL-D -- on a blank line, do a soft reset of the board\n"
39+
" CTRL-E -- on a blank line, enter paste mode\n"
40+
"\n"
41+
"For further help on a specific object, type help(obj)\n"
42+
;
43+
44+
STATIC mp_obj_t builtin_help(uint n_args, const mp_obj_t *args) {
45+
if (n_args == 0) {
46+
// print a general help message
47+
printf("%s", help_text);
48+
49+
} else {
50+
// try to print something sensible about the given object
51+
pyhelp_print_obj(args[0]);
52+
}
53+
54+
return mp_const_none;
55+
}
56+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, builtin_help);

zephyr/mpconfigport.h

+5
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ typedef long mp_off_t;
5151

5252
// Include Zephyr's autoconf.h, which should be made first by Zephyr makefiles
5353
#include "autoconf.h"
54+
55+
// extra built in names to add to the global namespace
56+
#define MICROPY_PORT_BUILTINS \
57+
{ MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
58+

0 commit comments

Comments
 (0)