24
24
* THE SOFTWARE.
25
25
*/
26
26
27
- #include " MicroBit.h "
27
+ #include < string.h >
28
28
#include " microbitobj.h"
29
29
#include " nrf_gpio.h"
30
30
31
31
extern " C" {
32
-
33
32
#include " py/runtime.h"
34
33
#include " modmicrobit.h"
35
34
#include " microbitimage.h"
36
35
#include " microbitdisplay.h"
37
36
#include " lib/iters.h"
38
37
#include " lib/ticker.h"
39
38
39
+ #define min (a,b ) (((a)<(b))?(a):(b))
40
+
40
41
void microbit_display_show (microbit_display_obj_t *display, microbit_image_obj_t *image) {
41
42
mp_int_t w = min (image->width (), 5 );
42
43
mp_int_t h = min (image->height (), 5 );
@@ -61,6 +62,9 @@ void microbit_display_show(microbit_display_obj_t *display, microbit_image_obj_t
61
62
display->brightnesses = brightnesses;
62
63
}
63
64
65
+ #define DEFAULT_PRINT_SPEED 400
66
+
67
+
64
68
mp_obj_t microbit_display_show_func (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
65
69
66
70
// Cancel any animations.
@@ -69,7 +73,7 @@ mp_obj_t microbit_display_show_func(mp_uint_t n_args, const mp_obj_t *pos_args,
69
73
70
74
static const mp_arg_t show_allowed_args[] = {
71
75
{ MP_QSTR_image, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
72
- { MP_QSTR_delay, MP_ARG_INT, {.u_int = MICROBIT_DEFAULT_PRINT_SPEED } },
76
+ { MP_QSTR_delay, MP_ARG_INT, {.u_int = DEFAULT_PRINT_SPEED } },
73
77
{ MP_QSTR_clear, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } },
74
78
{ MP_QSTR_wait, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true } },
75
79
{ MP_QSTR_loop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } },
@@ -158,7 +162,10 @@ struct DisplayPoint {
158
162
159
163
#define NO_CONN 0
160
164
161
- static const DisplayPoint display_map[MICROBIT_DISPLAY_COLUMN_COUNT][MICROBIT_DISPLAY_ROW_COUNT] = {
165
+ #define ROW_COUNT 3
166
+ #define COLUMN_COUNT 9
167
+
168
+ static const DisplayPoint display_map[COLUMN_COUNT][ROW_COUNT] = {
162
169
{{0 ,0 }, {4 ,2 }, {2 ,4 }},
163
170
{{2 ,0 }, {0 ,2 }, {4 ,4 }},
164
171
{{4 ,0 }, {2 ,2 }, {0 ,4 }},
@@ -193,7 +200,7 @@ void microbit_display_obj_t::advanceRow() {
193
200
strobe_row++;
194
201
195
202
// Reset the row counts and bit mask when we have hit the max.
196
- if (strobe_row == MICROBIT_DISPLAY_ROW_COUNT ) {
203
+ if (strobe_row == ROW_COUNT ) {
197
204
strobe_row = 0 ;
198
205
}
199
206
@@ -202,7 +209,7 @@ void microbit_display_obj_t::advanceRow() {
202
209
for (int i = 0 ; i <= MAX_BRIGHTNESS; i++) {
203
210
pins_for_brightness[i] = 0 ;
204
211
}
205
- for (int i = 0 ; i < MICROBIT_DISPLAY_COLUMN_COUNT ; i++) {
212
+ for (int i = 0 ; i < COLUMN_COUNT ; i++) {
206
213
int x = display_map[i][strobe_row].x ;
207
214
int y = display_map[i][strobe_row].y ;
208
215
uint8_t brightness = microbit_display_obj.image_buffer [x][y];
@@ -247,7 +254,7 @@ static int32_t callback(void) {
247
254
248
255
249
256
static void microbit_display_update (void ) {
250
- async_tick += FIBER_TICK_PERIOD_MS ;
257
+ async_tick += MILLISECONDS_PER_MACRO_TICK ;
251
258
if (async_tick < async_delay) {
252
259
return ;
253
260
}
@@ -337,16 +344,20 @@ void microbit_display_animate(microbit_display_obj_t *self, mp_obj_t iterable, m
337
344
}
338
345
}
339
346
347
+
348
+ // Delay in ms in between moving display one column to the left.
349
+ #define DEFAULT_SCROLL_SPEED 150
350
+
340
351
void microbit_display_scroll (microbit_display_obj_t *self, const char * str) {
341
352
mp_obj_t iterable = scrolling_string_image_iterable (str, strlen (str), NULL , false );
342
- microbit_display_animate (self, iterable, MICROBIT_DEFAULT_SCROLL_SPEED , false , true );
353
+ microbit_display_animate (self, iterable, DEFAULT_SCROLL_SPEED , false , true );
343
354
}
344
355
345
356
346
357
mp_obj_t microbit_display_scroll_func (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
347
358
static const mp_arg_t scroll_allowed_args[] = {
348
359
{ MP_QSTR_text, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
349
- { MP_QSTR_delay, MP_ARG_INT, {.u_int = MICROBIT_DEFAULT_SCROLL_SPEED } },
360
+ { MP_QSTR_delay, MP_ARG_INT, {.u_int = DEFAULT_SCROLL_SPEED } },
350
361
{ MP_QSTR_wait, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true } },
351
362
{ MP_QSTR_monospace, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } },
352
363
{ MP_QSTR_loop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } },
@@ -370,7 +381,7 @@ void microbit_display_clear(void) {
370
381
// Reset repeat state, cancel animation and clear screen.
371
382
wakeup_event = false ;
372
383
async_mode = ASYNC_MODE_CLEAR;
373
- async_tick = async_delay - FIBER_TICK_PERIOD_MS ;
384
+ async_tick = async_delay - MILLISECONDS_PER_MACRO_TICK ;
374
385
wait_for_event ();
375
386
}
376
387
@@ -452,9 +463,7 @@ microbit_display_obj_t microbit_display_obj = {
452
463
453
464
void microbit_display_init (void ) {
454
465
// Set pins as output.
455
- nrf_gpio_range_cfg_output (MICROBIT_DISPLAY_COLUMN_START,MICROBIT_DISPLAY_COLUMN_START + MICROBIT_DISPLAY_COLUMN_COUNT + MICROBIT_DISPLAY_ROW_COUNT);
456
-
457
- uBit.display .disable ();
466
+ nrf_gpio_range_cfg_output (MIN_COLUMN_PIN, MIN_COLUMN_PIN + COLUMN_COUNT + ROW_COUNT);
458
467
}
459
468
460
469
}
0 commit comments