Interactive MicroPython read-eval-print-loop See also the micropython library and its README file.

Dependencies:   mbed micropython

This program needs the micropython library - see there for Getting Started information.

See the mbed MicroPython wiki for more information.

Committer:
infinnovation
Date:
Wed Apr 27 21:20:06 2016 +0000
Revision:
18:04bb73e9e912
Parent:
15:0eb1e7e4152d
Update library version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Colin Hogben 15:0eb1e7e4152d 1 /*
Colin Hogben 15:0eb1e7e4152d 2 * The MIT License (MIT)
Colin Hogben 15:0eb1e7e4152d 3 *
Colin Hogben 15:0eb1e7e4152d 4 * Copyright (c) 2016 Colin Hogben
Colin Hogben 15:0eb1e7e4152d 5 *
Colin Hogben 15:0eb1e7e4152d 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
Colin Hogben 15:0eb1e7e4152d 7 * of this software and associated documentation files (the "Software"), to deal
Colin Hogben 15:0eb1e7e4152d 8 * in the Software without restriction, including without limitation the rights
Colin Hogben 15:0eb1e7e4152d 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Colin Hogben 15:0eb1e7e4152d 10 * copies of the Software, and to permit persons to whom the Software is
Colin Hogben 15:0eb1e7e4152d 11 * furnished to do so, subject to the following conditions:
Colin Hogben 15:0eb1e7e4152d 12 *
Colin Hogben 15:0eb1e7e4152d 13 * The above copyright notice and this permission notice shall be included in
Colin Hogben 15:0eb1e7e4152d 14 * all copies or substantial portions of the Software.
Colin Hogben 15:0eb1e7e4152d 15 *
Colin Hogben 15:0eb1e7e4152d 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Colin Hogben 15:0eb1e7e4152d 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Colin Hogben 15:0eb1e7e4152d 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Colin Hogben 15:0eb1e7e4152d 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Colin Hogben 15:0eb1e7e4152d 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Colin Hogben 15:0eb1e7e4152d 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Colin Hogben 15:0eb1e7e4152d 22 * THE SOFTWARE.
Colin Hogben 15:0eb1e7e4152d 23 */
Colin Hogben 15:0eb1e7e4152d 24 #include <stdio.h>
Colin Hogben 15:0eb1e7e4152d 25 #include "py/runtime.h"
Colin Hogben 15:0eb1e7e4152d 26 #include "lib/utils/pyhelp.h"
Colin Hogben 15:0eb1e7e4152d 27
Colin Hogben 15:0eb1e7e4152d 28 STATIC const char help_text[] =
Colin Hogben 15:0eb1e7e4152d 29 "Welcome to the (unofficial) mbed port of MicroPython!\n"
Colin Hogben 15:0eb1e7e4152d 30 "For online help please visit http://micropython.org/help/.\n"
Colin Hogben 15:0eb1e7e4152d 31 "For further help on a specific object, type help(obj)\n"
Colin Hogben 15:0eb1e7e4152d 32 "\n"
Colin Hogben 15:0eb1e7e4152d 33 "The following modules are available:\n"
Colin Hogben 15:0eb1e7e4152d 34 #if MICROPY_PY_SYS
Colin Hogben 15:0eb1e7e4152d 35 " sys\n"
Colin Hogben 15:0eb1e7e4152d 36 #endif
Colin Hogben 15:0eb1e7e4152d 37 #if MICROPY_PY_STRUCT
Colin Hogben 15:0eb1e7e4152d 38 " ustruct -- cut-down version of struct\n"
Colin Hogben 15:0eb1e7e4152d 39 #endif
Colin Hogben 15:0eb1e7e4152d 40 " machine -- direct memory access and reset function\n"
Colin Hogben 15:0eb1e7e4152d 41 " mbed -- equivalents to mbed API classes:\n"
Colin Hogben 15:0eb1e7e4152d 42 #if MICROPY_MBED_DIGITALOUT
Colin Hogben 15:0eb1e7e4152d 43 " DigitalOut\n"
Colin Hogben 15:0eb1e7e4152d 44 #endif
Colin Hogben 15:0eb1e7e4152d 45 #if MICROPY_MBED_DIGITALIN
Colin Hogben 15:0eb1e7e4152d 46 " DigitalIn\n"
Colin Hogben 15:0eb1e7e4152d 47 #endif
Colin Hogben 15:0eb1e7e4152d 48 #if MICROPY_MBED_SERIAL
Colin Hogben 15:0eb1e7e4152d 49 " Serial\n"
Colin Hogben 15:0eb1e7e4152d 50 #endif
Colin Hogben 15:0eb1e7e4152d 51 " pins -- board-specific and generic named pins e.g. USBTX\n"
Colin Hogben 15:0eb1e7e4152d 52 ;
Colin Hogben 15:0eb1e7e4152d 53
Colin Hogben 15:0eb1e7e4152d 54 STATIC mp_obj_t mbed_help(size_t n_args, const mp_obj_t *args) {
Colin Hogben 15:0eb1e7e4152d 55 if (n_args == 0) {
Colin Hogben 15:0eb1e7e4152d 56 // print a general help message
Colin Hogben 15:0eb1e7e4152d 57 printf("%s", help_text);
Colin Hogben 15:0eb1e7e4152d 58 }
Colin Hogben 15:0eb1e7e4152d 59 else {
Colin Hogben 15:0eb1e7e4152d 60 // try to print something sensible about the given object
Colin Hogben 15:0eb1e7e4152d 61 pyhelp_print_obj(args[0]);
Colin Hogben 15:0eb1e7e4152d 62 }
Colin Hogben 15:0eb1e7e4152d 63 return mp_const_none;
Colin Hogben 15:0eb1e7e4152d 64 }
Colin Hogben 15:0eb1e7e4152d 65 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, mbed_help);