Skip to content

Commit 8e5eda1

Browse files
committed
codal_port/modthis: Add this module from micro:bit v1.
Taken from ahttps://github.com/bbcmicrobit/micropython commit a92ca9b1f907c07a01116b0eb464ca4743a28bf1 Signed-off-by: Damien George <[email protected]>
1 parent 3c9983e commit 8e5eda1

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/codal_port/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ SRC_C += \
8484
modos.c \
8585
modradio.c \
8686
modspeech.c \
87+
modthis.c \
8788
modutime.c \
8889
mphalport.c \
8990

src/codal_port/modthis.c

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2015 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 "py/runtime.h"
28+
29+
STATIC const char *this_text =
30+
"The Zen of MicroPython, by Nicholas H. Tollervey\n"
31+
"\n"
32+
"Code,\n"
33+
"Hack it,\n"
34+
"Less is more,\n"
35+
"Keep it simple,\n"
36+
"Small is beautiful,\n"
37+
"\n"
38+
"Be brave! Break things! Learn and have fun!\n"
39+
"Express yourself with MicroPython.\n"
40+
"\n"
41+
"Happy hacking! :-)\n";
42+
43+
// If you contribute code to this project, add your name here.
44+
STATIC const char *authors_text =
45+
"MicroPython on the micro:bit is brought to you by:\n"
46+
"Damien P. George, Mark Shannon, Radomir Dopieralski, Matthew Else,\n"
47+
"Carol Willing, Tom Viner, Alan Jackson, Nick Coghlan, Joseph Haig,\n"
48+
"Alex Chan, Andrea Grandi, Paul Egan, Piotr Kasprzyk, Andrew Mulholland,\n"
49+
"Matt Wheeler, Joe Glancy, Abbie Brooks and Nicholas H. Tollervey.\n";
50+
51+
STATIC mp_obj_t this__init__(void) {
52+
mp_printf(&mp_plat_print, "%s", this_text);
53+
return mp_const_none;
54+
}
55+
MP_DEFINE_CONST_FUN_OBJ_0(this___init___obj, this__init__);
56+
57+
STATIC mp_obj_t this_authors(void) {
58+
mp_printf(&mp_plat_print, "%s", authors_text);
59+
return mp_const_none;
60+
}
61+
MP_DEFINE_CONST_FUN_OBJ_0(this_authors_obj, this_authors);
62+
63+
STATIC const mp_rom_map_elem_t this_module_globals_table[] = {
64+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_this) },
65+
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&this___init___obj) },
66+
{ MP_ROM_QSTR(MP_QSTR_authors), MP_ROM_PTR(&this_authors_obj) },
67+
};
68+
STATIC MP_DEFINE_CONST_DICT(this_module_globals, this_module_globals_table);
69+
70+
const mp_obj_module_t this_module = {
71+
.base = { &mp_type_module },
72+
.globals = (mp_obj_dict_t *)&this_module_globals,
73+
};

src/codal_port/mpconfigport.h

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extern const struct _mp_obj_module_t music_module;
109109
extern const struct _mp_obj_module_t os_module;
110110
extern const struct _mp_obj_module_t radio_module;
111111
extern const struct _mp_obj_module_t speech_module;
112+
extern const struct _mp_obj_module_t this_module;
112113
extern const struct _mp_obj_module_t utime_module;
113114

114115
#define MICROPY_PORT_BUILTIN_MODULES \
@@ -121,6 +122,7 @@ extern const struct _mp_obj_module_t utime_module;
121122
{ MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&os_module) }, \
122123
{ MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&radio_module) }, \
123124
{ MP_ROM_QSTR(MP_QSTR_speech), MP_ROM_PTR(&speech_module) }, \
125+
{ MP_ROM_QSTR(MP_QSTR_this), MP_ROM_PTR(&this_module) }, \
124126
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&utime_module) }, \
125127

126128
#define MICROPY_PORT_ROOT_POINTERS \

0 commit comments

Comments
 (0)