Skip to content

Commit 9014214

Browse files
committed
Reduce dependency on DAL for display and image.
1 parent 754668c commit 9014214

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

inc/microbit/MicroBitCustomConfig.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@
2020
#define MICROBIT_BLE_DEVICE_INFORMATION_SERVICE 0
2121
#define MICROBIT_BLE_PAIRING_MODE 0
2222

23-
// Slow this down a bit as proportional spacing reduces length
24-
#define MICROBIT_DEFAULT_SCROLL_SPEED 150
25-
2623
#endif

inc/microbit/microbitobj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
extern "C" {
3030

3131
#include "py/obj.h"
32+
#include "PinNames.h"
3233

3334
class MicroBitPin *microbit_obj_get_pin(mp_obj_t o);
3435
PinName microbit_obj_get_pin_name(mp_obj_t o);

source/microbit/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void __register_exitproc() {
7474
}
7575

7676
void microbit_init(void) {
77+
uBit.display.disable();
7778
microbit_display_init();
7879

7980
// Start the ticker.

source/microbit/microbitconstimage.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "MicroBit.h"
2827
#include "microbitobj.h"
2928

3029
extern "C" {

source/microbit/microbitdisplay.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "MicroBit.h"
27+
#include <string.h>
2828
#include "microbitobj.h"
2929
#include "nrf_gpio.h"
3030

3131
extern "C" {
32-
3332
#include "py/runtime.h"
3433
#include "modmicrobit.h"
3534
#include "microbitimage.h"
3635
#include "microbitdisplay.h"
3736
#include "lib/iters.h"
3837
#include "lib/ticker.h"
3938

39+
#define min(a,b) (((a)<(b))?(a):(b))
40+
4041
void microbit_display_show(microbit_display_obj_t *display, microbit_image_obj_t *image) {
4142
mp_int_t w = min(image->width(), 5);
4243
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
6162
display->brightnesses = brightnesses;
6263
}
6364

65+
#define DEFAULT_PRINT_SPEED 400
66+
67+
6468
mp_obj_t microbit_display_show_func(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6569

6670
// 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,
6973

7074
static const mp_arg_t show_allowed_args[] = {
7175
{ 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} },
7377
{ MP_QSTR_clear, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
7478
{ MP_QSTR_wait, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
7579
{ MP_QSTR_loop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
@@ -158,7 +162,10 @@ struct DisplayPoint {
158162

159163
#define NO_CONN 0
160164

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] = {
162169
{{0,0}, {4,2}, {2,4}},
163170
{{2,0}, {0,2}, {4,4}},
164171
{{4,0}, {2,2}, {0,4}},
@@ -193,7 +200,7 @@ void microbit_display_obj_t::advanceRow() {
193200
strobe_row++;
194201

195202
// 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) {
197204
strobe_row = 0;
198205
}
199206

@@ -202,7 +209,7 @@ void microbit_display_obj_t::advanceRow() {
202209
for (int i = 0; i <= MAX_BRIGHTNESS; i++) {
203210
pins_for_brightness[i] = 0;
204211
}
205-
for (int i = 0; i < MICROBIT_DISPLAY_COLUMN_COUNT; i++) {
212+
for (int i = 0; i < COLUMN_COUNT; i++) {
206213
int x = display_map[i][strobe_row].x;
207214
int y = display_map[i][strobe_row].y;
208215
uint8_t brightness = microbit_display_obj.image_buffer[x][y];
@@ -247,7 +254,7 @@ static int32_t callback(void) {
247254

248255

249256
static void microbit_display_update(void) {
250-
async_tick += FIBER_TICK_PERIOD_MS;
257+
async_tick += MILLISECONDS_PER_MACRO_TICK;
251258
if (async_tick < async_delay) {
252259
return;
253260
}
@@ -337,16 +344,20 @@ void microbit_display_animate(microbit_display_obj_t *self, mp_obj_t iterable, m
337344
}
338345
}
339346

347+
348+
// Delay in ms in between moving display one column to the left.
349+
#define DEFAULT_SCROLL_SPEED 150
350+
340351
void microbit_display_scroll(microbit_display_obj_t *self, const char* str) {
341352
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);
343354
}
344355

345356

346357
mp_obj_t microbit_display_scroll_func(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
347358
static const mp_arg_t scroll_allowed_args[] = {
348359
{ 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} },
350361
{ MP_QSTR_wait, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
351362
{ MP_QSTR_monospace, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
352363
{ MP_QSTR_loop, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
@@ -370,7 +381,7 @@ void microbit_display_clear(void) {
370381
// Reset repeat state, cancel animation and clear screen.
371382
wakeup_event = false;
372383
async_mode = ASYNC_MODE_CLEAR;
373-
async_tick = async_delay - FIBER_TICK_PERIOD_MS;
384+
async_tick = async_delay - MILLISECONDS_PER_MACRO_TICK;
374385
wait_for_event();
375386
}
376387

@@ -452,9 +463,7 @@ microbit_display_obj_t microbit_display_obj = {
452463

453464
void microbit_display_init(void) {
454465
// 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);
458467
}
459468

460469
}

source/microbit/microbitimage.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "MicroBit.h"
27+
#include <string.h>
2828
#include "microbitobj.h"
29+
#include "MicroBitFont.h"
2930

3031
extern "C" {
3132

@@ -34,6 +35,9 @@ extern "C" {
3435
#include "microbitimage.h"
3536
#include "py/runtime0.h"
3637

38+
#define min(a,b) (((a)<(b))?(a):(b))
39+
#define max(a,b) (((a)>(b))?(a):(b))
40+
3741
const monochrome_5by5_t microbit_blank_image = {
3842
{ &microbit_image_type },
3943
1, 0, 0, 0,
@@ -523,15 +527,17 @@ STATIC const mp_map_elem_t microbit_image_locals_dict_table[] = {
523527

524528
STATIC MP_DEFINE_CONST_DICT(microbit_image_locals_dict, microbit_image_locals_dict_table);
525529

530+
#define THE_FONT MicroBitFont::defaultFont
531+
532+
#define ASCII_START 32
533+
#define ASCII_END 126
526534

527535
STATIC const unsigned char *get_font_data_from_char(char c) {
528-
MicroBitFont font = uBit.display.getFont();
529-
if (c < MICROBIT_FONT_ASCII_START || c > font.asciiEnd) {
536+
if (c < ASCII_START || c > ASCII_END) {
530537
c = '?';
531538
}
532-
/* The following logic belongs in MicroBitFont */
533-
int offset = (c-MICROBIT_FONT_ASCII_START) * 5;
534-
return font.characters + offset;
539+
int offset = (c-ASCII_START) * 5;
540+
return THE_FONT + offset;
535541
}
536542

537543
STATIC mp_int_t get_pixel_from_font_data(const unsigned char *data, int x, int y) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy