Skip to content

Commit b639ce2

Browse files
committed
esp8266/help: Implement help() builtin.
1 parent c10d303 commit b639ce2

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

esp8266/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ endif
5757
SRC_C = \
5858
strtoll.c \
5959
main.c \
60+
help.c \
6061
esp_mphal.c \
6162
gccollect.c \
6263
lexerstr32.c \
@@ -116,6 +117,7 @@ LIB_SRC_C = $(addprefix lib/,\
116117
netutils/netutils.c \
117118
timeutils/timeutils.c \
118119
utils/pyexec.c \
120+
utils/pyhelp.c \
119121
utils/printf.c \
120122
fatfs/ff.c \
121123
fatfs/option/ccsbcs.c \

esp8266/help.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
"For online docs please visit http://docs.micropython.org/en/latest/esp8266/ .\n"
35+
"To get diagnostic information to include in bug reports, execute 'import port_diag'.\n"
36+
"\n"
37+
"Control commands:\n"
38+
" CTRL-A -- on a blank line, enter raw REPL mode\n"
39+
" CTRL-B -- on a blank line, enter normal REPL mode\n"
40+
" CTRL-C -- interrupt a running program\n"
41+
" CTRL-D -- on a blank line, do a soft reset of the board\n"
42+
" CTRL-E -- on a blank line, enter paste mode\n"
43+
"\n"
44+
"For further help on a specific object, type help(obj)\n"
45+
;
46+
47+
STATIC mp_obj_t builtin_help(uint n_args, const mp_obj_t *args) {
48+
if (n_args == 0) {
49+
// print a general help message
50+
printf("%s", help_text);
51+
52+
} else {
53+
// try to print something sensible about the given object
54+
pyhelp_print_obj(args[0]);
55+
}
56+
57+
return mp_const_none;
58+
}
59+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, builtin_help);

esp8266/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef uint32_t sys_prot_t; // for modlwip
105105

106106
// extra built in names to add to the global namespace
107107
#define MICROPY_PORT_BUILTINS \
108+
{ MP_OBJ_NEW_QSTR(MP_QSTR_help), (mp_obj_t)&mp_builtin_help_obj }, \
108109
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
109110
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
110111

0 commit comments

Comments
 (0)