You've already forked Core2forAWS-MicroPython
mirror of
https://github.com/m5stack/Core2forAWS-MicroPython.git
synced 2026-05-20 10:30:31 -07:00
nrf/boards/microbit: Add copy of microbit display and image files.
From micro:bit port repository, https://github.com/bbcmicrobit/micropython
This commit is contained in:
committed by
Damien George
parent
a248db6916
commit
7a2e136049
@@ -0,0 +1,9 @@
|
||||
Damien P. George (@dpgeorge)
|
||||
Nicholas H. Tollervey (@ntoll)
|
||||
Matthew Else (@matthewelse)
|
||||
Alan M. Jackson (@alanmjackson)
|
||||
Mark Shannon (@markshannon)
|
||||
Larry Hastings (@larryhastings)
|
||||
Mariia Koroliuk (@marichkakorolyuk)
|
||||
Andrew Mulholland (@gbaman)
|
||||
Joe Glancy (@JoeGlancy)
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed
|
||||
in the accompanying AUTHORS file
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015/6 Mark Shannon
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "lib/iters.h"
|
||||
|
||||
|
||||
typedef struct _repeat_iterator_t {
|
||||
mp_obj_base_t base;
|
||||
mp_obj_t iterable;
|
||||
mp_int_t index;
|
||||
} repeat_iterator_t;
|
||||
|
||||
static mp_obj_t microbit_repeat_iter_next(mp_obj_t iter_in) {
|
||||
repeat_iterator_t *iter = (repeat_iterator_t *)iter_in;
|
||||
iter->index++;
|
||||
if (iter->index >= mp_obj_get_int(mp_obj_len(iter->iterable))) {
|
||||
iter->index = 0;
|
||||
}
|
||||
return mp_obj_subscr(iter->iterable, MP_OBJ_NEW_SMALL_INT(iter->index), MP_OBJ_SENTINEL);
|
||||
}
|
||||
|
||||
const mp_obj_type_t microbit_repeat_iterator_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_iterator,
|
||||
.print = NULL,
|
||||
.make_new = NULL,
|
||||
.call = NULL,
|
||||
.unary_op = NULL,
|
||||
.binary_op = NULL,
|
||||
.attr = NULL,
|
||||
.subscr = NULL,
|
||||
.getiter = mp_identity,
|
||||
.iternext = microbit_repeat_iter_next,
|
||||
.buffer_p = {NULL},
|
||||
.stream_p = NULL,
|
||||
.bases_tuple = MP_OBJ_NULL,
|
||||
MP_OBJ_NULL
|
||||
};
|
||||
|
||||
mp_obj_t microbit_repeat_iterator(mp_obj_t iterable) {
|
||||
repeat_iterator_t *result = m_new_obj(repeat_iterator_t);
|
||||
result->base.type = µbit_repeat_iterator_type;
|
||||
result->iterable = iterable;
|
||||
result->index = -1;
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
mp_obj_t microbit_repeat_iterator(mp_obj_t iterable);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Mark Shannon
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "modmicrobit.h"
|
||||
|
||||
const mp_obj_tuple_t microbit_const_image_all_clocks_tuple_obj = {
|
||||
{&mp_type_tuple},
|
||||
.len = 12,
|
||||
.items = {
|
||||
(mp_obj_t)µbit_const_image_clock12_obj,
|
||||
(mp_obj_t)µbit_const_image_clock1_obj,
|
||||
(mp_obj_t)µbit_const_image_clock2_obj,
|
||||
(mp_obj_t)µbit_const_image_clock3_obj,
|
||||
(mp_obj_t)µbit_const_image_clock4_obj,
|
||||
(mp_obj_t)µbit_const_image_clock5_obj,
|
||||
(mp_obj_t)µbit_const_image_clock6_obj,
|
||||
(mp_obj_t)µbit_const_image_clock7_obj,
|
||||
(mp_obj_t)µbit_const_image_clock8_obj,
|
||||
(mp_obj_t)µbit_const_image_clock9_obj,
|
||||
(mp_obj_t)µbit_const_image_clock10_obj,
|
||||
(mp_obj_t)µbit_const_image_clock11_obj
|
||||
}
|
||||
};
|
||||
|
||||
const mp_obj_tuple_t microbit_const_image_all_arrows_tuple_obj = {
|
||||
{&mp_type_tuple},
|
||||
.len = 8,
|
||||
.items = {
|
||||
(mp_obj_t)µbit_const_image_arrow_n_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_ne_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_e_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_se_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_s_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_sw_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_w_obj,
|
||||
(mp_obj_t)µbit_const_image_arrow_nw_obj
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
|
||||
#ifndef __MICROPY_INCLUDED_MICROBIT_DISPLAY_H__
|
||||
#define __MICROPY_INCLUDED_MICROBIT_DISPLAY_H__
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "microbitimage.h"
|
||||
|
||||
typedef struct _microbit_display_obj_t {
|
||||
mp_obj_base_t base;
|
||||
uint8_t image_buffer[5][5];
|
||||
uint8_t previous_brightness;
|
||||
bool active;
|
||||
/* Current row for strobing */
|
||||
uint8_t strobe_row;
|
||||
/* boolean histogram of brightness in buffer */
|
||||
uint16_t brightnesses;
|
||||
uint16_t pins_for_brightness[MAX_BRIGHTNESS+1];
|
||||
|
||||
void advanceRow();
|
||||
inline void setPinsForRow(uint8_t brightness);
|
||||
|
||||
|
||||
} microbit_display_obj_t;
|
||||
|
||||
#define ASYNC_MODE_STOPPED 0
|
||||
#define ASYNC_MODE_ANIMATION 1
|
||||
#define ASYNC_MODE_CLEAR 2
|
||||
|
||||
extern microbit_display_obj_t microbit_display_obj;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
void microbit_display_show(microbit_display_obj_t *display, microbit_image_obj_t *image);
|
||||
|
||||
void microbit_display_animate(microbit_display_obj_t *display, mp_obj_t iterable, mp_int_t delay, bool clear, bool wait);
|
||||
|
||||
void microbit_display_scroll(microbit_display_obj_t *display, const char* str, bool wait);
|
||||
|
||||
mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y);
|
||||
|
||||
void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y, mp_int_t val);
|
||||
|
||||
void microbit_display_clear(void);
|
||||
|
||||
void microbit_display_init(void);
|
||||
|
||||
void microbit_display_tick(void);
|
||||
|
||||
bool microbit_display_active_animation(void);
|
||||
|
||||
}
|
||||
|
||||
#endif // __MICROPY_INCLUDED_MICROBIT_DISPLAY_H__
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,92 @@
|
||||
#ifndef __MICROPY_INCLUDED_MICROBIT_IMAGE_H__
|
||||
#define __MICROPY_INCLUDED_MICROBIT_IMAGE_H__
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#define MAX_BRIGHTNESS 9
|
||||
|
||||
/** Monochrome images are immutable, which means that
|
||||
* we only need one bit per pixel which saves quite a lot
|
||||
* of memory */
|
||||
|
||||
/* we reserve a couple of bits, so we won't need to modify the
|
||||
* layout if we need to add more functionality or subtypes. */
|
||||
#define TYPE_AND_FLAGS \
|
||||
mp_obj_base_t base; \
|
||||
uint8_t five:1; \
|
||||
uint8_t reserved1:1; \
|
||||
uint8_t reserved2:1
|
||||
|
||||
typedef struct _image_base_t {
|
||||
TYPE_AND_FLAGS;
|
||||
} image_base_t;
|
||||
|
||||
typedef struct _monochrome_5by5_t {
|
||||
TYPE_AND_FLAGS;
|
||||
uint8_t pixel44: 1;
|
||||
uint8_t bits24[3];
|
||||
|
||||
/* This is an internal method it is up to the caller to validate the inputs */
|
||||
uint8_t getPixelValue(mp_int_t x, mp_int_t y);
|
||||
|
||||
} monochrome_5by5_t;
|
||||
|
||||
typedef struct _greyscale_t {
|
||||
TYPE_AND_FLAGS;
|
||||
uint8_t height;
|
||||
uint8_t width;
|
||||
uint8_t byte_data[]; /* Static initializer for this will have to be C, not C++ */
|
||||
void clear();
|
||||
|
||||
/* Thiese are internal methods and it is up to the caller to validate the inputs */
|
||||
uint8_t getPixelValue(mp_int_t x, mp_int_t y);
|
||||
void setPixelValue(mp_int_t x, mp_int_t y, mp_int_t val);
|
||||
void fill(mp_int_t val);
|
||||
} greyscale_t;
|
||||
|
||||
typedef union _microbit_image_obj_t {
|
||||
image_base_t base;
|
||||
monochrome_5by5_t monochrome_5by5;
|
||||
greyscale_t greyscale;
|
||||
|
||||
mp_int_t height();
|
||||
mp_int_t width();
|
||||
greyscale_t *copy();
|
||||
greyscale_t *invert();
|
||||
|
||||
/* This is an internal method it is up to the caller to validate the inputs */
|
||||
uint8_t getPixelValue(mp_int_t x, mp_int_t y);
|
||||
|
||||
} microbit_image_obj_t;
|
||||
|
||||
/** Return a facade object that presents the string as a sequence of images */
|
||||
mp_obj_t microbit_string_facade(mp_obj_t string);
|
||||
|
||||
void microbit_image_set_from_char(greyscale_t *img, char c);
|
||||
microbit_image_obj_t *microbit_image_for_char(char c);
|
||||
mp_obj_t microbit_image_slice(microbit_image_obj_t *img, mp_int_t start, mp_int_t width, mp_int_t stride);
|
||||
/* ref exists so that we can pull a string out of an object and not have it GC'ed while oterating over it */
|
||||
mp_obj_t scrolling_string_image_iterable(const char* str, mp_uint_t len, mp_obj_t ref, bool monospace, bool repeat);
|
||||
|
||||
#define SMALL_IMAGE(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p44) \
|
||||
{ \
|
||||
{ µbit_image_type }, \
|
||||
1, 0, 0, (p44), \
|
||||
{ \
|
||||
(p0)|((p1)<<1)|((p2)<<2)|((p3)<<3)|((p4)<<4)|((p5)<<5)|((p6)<<6)|((p7)<<7), \
|
||||
(p8)|((p9)<<1)|((p10)<<2)|((p11)<<3)|((p12)<<4)|((p13)<<5)|((p14)<<6)|((p15)<<7), \
|
||||
(p16)|((p17)<<1)|((p18)<<2)|((p19)<<3)|((p20)<<4)|((p21)<<5)|((p22)<<6)|((p23)<<7) \
|
||||
} \
|
||||
}
|
||||
|
||||
extern const monochrome_5by5_t microbit_blank_image;
|
||||
extern const monochrome_5by5_t microbit_const_image_heart_obj;
|
||||
|
||||
#define BLANK_IMAGE (microbit_image_obj_t *)(µbit_blank_image)
|
||||
#define HEART_IMAGE (microbit_image_obj_t *)(µbit_const_image_heart_obj)
|
||||
#define HAPPY_IMAGE (microbit_image_obj_t *)(µbit_const_image_happy_obj)
|
||||
|
||||
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t fval);
|
||||
microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_image_obj_t *rhs, bool add);
|
||||
|
||||
#endif // __MICROPY_INCLUDED_MICROBIT_IMAGE_H__
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/mphal.h"
|
||||
#include "modmicrobit.h"
|
||||
#include "microbitdisplay.h"
|
||||
#include "microbitimage.h"
|
||||
|
||||
extern uint32_t ticks;
|
||||
|
||||
STATIC mp_obj_t microbit_reset_(void) {
|
||||
NVIC_SystemReset();
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_reset_obj, microbit_reset_);
|
||||
|
||||
STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) {
|
||||
mp_int_t ms;
|
||||
if (mp_obj_is_integer(ms_in)) {
|
||||
ms = mp_obj_get_int(ms_in);
|
||||
} else {
|
||||
ms = (mp_int_t)mp_obj_get_float(ms_in);
|
||||
}
|
||||
if (ms > 0) {
|
||||
mp_hal_delay_ms(ms);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(microbit_sleep_obj, microbit_sleep);
|
||||
|
||||
STATIC mp_obj_t microbit_running_time(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(ticks);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_running_time_obj, microbit_running_time);
|
||||
|
||||
static const monochrome_5by5_t panic = SMALL_IMAGE(
|
||||
1,1,0,1,1,
|
||||
1,1,0,1,1,
|
||||
0,0,0,0,0,
|
||||
0,1,1,1,0,
|
||||
1,0,0,0,1
|
||||
);
|
||||
|
||||
STATIC mp_obj_t microbit_panic(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
while(true) {
|
||||
microbit_display_show(µbit_display_obj, (microbit_image_obj_t*)&panic);
|
||||
mp_hal_delay_ms(1000);
|
||||
char num[4];
|
||||
int code;
|
||||
if (n_args) {
|
||||
code = mp_obj_get_int(args[0]);
|
||||
} else {
|
||||
code = 0;
|
||||
}
|
||||
num[2] = code%10 + '0';
|
||||
code /= 10;
|
||||
num[1] = code%10 + '0';
|
||||
code /= 10;
|
||||
num[0] = code%10 + '0';
|
||||
for (int i = 0; i < 3; i++) {
|
||||
microbit_display_show(µbit_display_obj, microbit_image_for_char(num[i]));
|
||||
mp_hal_delay_ms(1000);
|
||||
}
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_panic_obj, 0, 1, microbit_panic);
|
||||
|
||||
STATIC mp_obj_t microbit_temperature(void) {
|
||||
int temp;
|
||||
NRF_TEMP->TASKS_START = 1;
|
||||
while (NRF_TEMP->EVENTS_DATARDY == 0);
|
||||
NRF_TEMP->EVENTS_DATARDY = 0;
|
||||
temp = NRF_TEMP->TEMP;
|
||||
NRF_TEMP->TASKS_STOP = 1;
|
||||
return mp_obj_new_float(temp/4.0);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(microbit_temperature_obj, microbit_temperature);
|
||||
|
||||
STATIC const mp_map_elem_t microbit_module_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_microbit) },
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_Image), (mp_obj_t)µbit_image_type },
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_display), (mp_obj_t)µbit_display_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_button_a), (mp_obj_t)µbit_button_a_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_button_b), (mp_obj_t)µbit_button_b_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_accelerometer), (mp_obj_t)µbit_accelerometer_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_compass), (mp_obj_t)µbit_compass_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_i2c), (mp_obj_t)µbit_i2c_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_uart), (mp_obj_t)µbit_uart_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_spi), (mp_obj_t)µbit_spi_obj },
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_reset), (mp_obj_t)µbit_reset_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)µbit_sleep_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_running_time), (mp_obj_t)µbit_running_time_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_panic), (mp_obj_t)µbit_panic_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_temperature), (mp_obj_t)µbit_temperature_obj },
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin0), (mp_obj_t)µbit_p0_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin1), (mp_obj_t)µbit_p1_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin2), (mp_obj_t)µbit_p2_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin3), (mp_obj_t)µbit_p3_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin4), (mp_obj_t)µbit_p4_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin5), (mp_obj_t)µbit_p5_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin6), (mp_obj_t)µbit_p6_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin7), (mp_obj_t)µbit_p7_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin8), (mp_obj_t)µbit_p8_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin9), (mp_obj_t)µbit_p9_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin10), (mp_obj_t)µbit_p10_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin11), (mp_obj_t)µbit_p11_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin12), (mp_obj_t)µbit_p12_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin13), (mp_obj_t)µbit_p13_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin14), (mp_obj_t)µbit_p14_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin15), (mp_obj_t)µbit_p15_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin16), (mp_obj_t)µbit_p16_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin19), (mp_obj_t)µbit_p19_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pin20), (mp_obj_t)µbit_p20_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(microbit_module_globals, microbit_module_globals_table);
|
||||
|
||||
const mp_obj_module_t microbit_module = {
|
||||
.base = { &mp_type_module },
|
||||
.name = MP_QSTR_microbit,
|
||||
.globals = (mp_obj_dict_t*)µbit_module_globals,
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef __MICROPY_INCLUDED_MICROBIT_MODMICROBIT_H__
|
||||
#define __MICROPY_INCLUDED_MICROBIT_MODMICROBIT_H__
|
||||
|
||||
#include "py/objtuple.h"
|
||||
|
||||
extern const mp_obj_type_t microbit_ad_pin_type;
|
||||
extern const mp_obj_type_t microbit_dig_pin_type;
|
||||
extern const mp_obj_type_t microbit_touch_pin_type;
|
||||
|
||||
extern const struct _microbit_pin_obj_t microbit_p0_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p1_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p2_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p3_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p4_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p5_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p6_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p7_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p8_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p9_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p10_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p11_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p12_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p13_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p14_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p15_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p16_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p19_obj;
|
||||
extern const struct _microbit_pin_obj_t microbit_p20_obj;
|
||||
|
||||
extern const mp_obj_type_t microbit_const_image_type;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_heart_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_heart_small_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_happy_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_smile_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_sad_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_confused_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_angry_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_asleep_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_surprised_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_silly_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_fabulous_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_meh_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_yes_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_no_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock12_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock1_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock2_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock3_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock4_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock5_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock6_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock7_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock8_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock9_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock10_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_clock11_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_n_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_ne_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_e_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_se_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_s_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_sw_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_w_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_arrow_nw_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_triangle_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_triangle_left_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_chessboard_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_diamond_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_diamond_small_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_square_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_square_small_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_rabbit;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_cow;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_music_crotchet_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_music_quaver_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_music_quavers_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_pitchfork_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_xmas_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_pacman_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_target_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_const_image_all_clocks_tuple_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_const_image_all_arrows_tuple_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_tshirt_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_rollerskate_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_duck_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_house_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_tortoise_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_butterfly_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_stickfigure_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_ghost_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_sword_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_giraffe_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_skull_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_umbrella_obj;
|
||||
extern const struct _monochrome_5by5_t microbit_const_image_snake_obj;
|
||||
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_dadadadum_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_entertainer_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_prelude_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_ode_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_nyan_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_ringtone_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_funk_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_blues_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_birthday_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_wedding_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_funeral_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_punchline_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_python_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_baddy_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_chase_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_ba_ding_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_wawawawaa_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_jump_up_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_jump_down_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_power_up_obj;
|
||||
extern const struct _mp_obj_tuple_t microbit_music_tune_power_down_obj;
|
||||
|
||||
extern const mp_obj_type_t microbit_image_type;
|
||||
|
||||
extern const mp_obj_type_t microbit_accelerometer_type;
|
||||
extern const struct _microbit_accelerometer_obj_t microbit_accelerometer_obj;
|
||||
|
||||
extern struct _microbit_display_obj_t microbit_display_obj;
|
||||
extern const struct _microbit_button_obj_t microbit_button_a_obj;
|
||||
extern const struct _microbit_button_obj_t microbit_button_b_obj;
|
||||
extern const struct _microbit_compass_obj_t microbit_compass_obj;
|
||||
extern const struct _microbit_i2c_obj_t microbit_i2c_obj;
|
||||
extern struct _microbit_uart_obj_t microbit_uart_obj;
|
||||
extern struct _microbit_spi_obj_t microbit_spi_obj;
|
||||
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_reset_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_sleep_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_random_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_running_time_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_temperature_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_panic_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_accelerometer_get_x_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_accelerometer_get_y_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_accelerometer_get_z_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_button_is_pressed_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_button_was_pressed_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_button_get_presses_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_is_calibrated_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_heading_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_calibrate_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_is_calibrating_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_clear_calibration_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_get_x_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_get_y_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_get_z_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_compass_get_field_strength_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_show_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_scroll_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_clear_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_get_pixel_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_set_pixel_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_on_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_off_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_display_is_on_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_read_digital_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_write_digital_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_read_analog_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_write_analog_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_is_touched_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_set_analog_period_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_pin_set_analog_period_microseconds_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_i2c_init_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_i2c_read_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_i2c_write_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_width_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_height_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_get_pixel_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_set_pixel_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_shift_left_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_shift_right_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_shift_up_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_shift_down_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_copy_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_crop_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_invert_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_image_slice_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_uart_init_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_uart_any_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_stream_read_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_stream_readall_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_stream_unbuffered_readline_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_stream_readinto_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_stream_write_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_spi_init_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_spi_write_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_spi_read_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_spi_write_readinto_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_music_set_tempo_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_music_pitch_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_music_play_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_music_get_tempo_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_music_stop_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(microbit_music_reset_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(love_badaboom_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(this_authors_obj);
|
||||
|
||||
extern const mp_obj_module_t microbit_module;
|
||||
extern const mp_obj_module_t music_module;
|
||||
extern const mp_obj_module_t love_module;
|
||||
extern const mp_obj_module_t antigravity_module;
|
||||
extern const mp_obj_module_t this_module;
|
||||
|
||||
#endif // __MICROPY_INCLUDED_MICROBIT_MODMICROBIT_H__
|
||||
Reference in New Issue
Block a user