Skip to content

Commit 81ea004

Browse files
markshannondpgeorge
authored andcommitted
Move init() from display to main. Add include guards where necessary.
1 parent 423233f commit 81ea004

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

inc/microbit/microbitdisplay.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
#ifndef __MICROPY_INCLUDED_MICROBIT_DISPLAY_H__
3+
#define __MICROPY_INCLUDED_MICROBIT_DISPLAY_H__
4+
5+
#include "py/runtime.h"
6+
#include "microbitimage.h"
27

38
typedef struct _microbit_display_obj_t {
49
mp_obj_base_t base;
@@ -23,6 +28,9 @@ typedef struct _microbit_display_obj_t {
2328

2429
extern microbit_display_obj_t microbit_display_obj;
2530

31+
32+
extern "C" {
33+
2634
void microbit_display_print(microbit_display_obj_t *display, microbit_image_obj_t *image);
2735

2836
void microbit_display_animate(microbit_display_obj_t *display, mp_obj_t iterable, mp_int_t delay, bool wait, bool loop);
@@ -33,5 +41,12 @@ mp_int_t microbit_display_get_pixel(microbit_display_obj_t *display, mp_int_t x,
3341

3442
void microbit_display_set_pixel(microbit_display_obj_t *display, mp_int_t x, mp_int_t y, mp_int_t val);
3543

44+
void microbit_display_clear(void);
45+
46+
void microbit_display_init(void);
47+
48+
void microbit_display_tick(void);
49+
50+
}
3651

37-
void microbit_display_clear(void);
52+
#endif // __MICROPY_INCLUDED_MICROBIT_DISPLAY_H__

inc/microbit/microbitimage.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
#ifndef __MICROPY_INCLUDED_MICROBIT_IMAGE_H__
2+
#define __MICROPY_INCLUDED_MICROBIT_IMAGE_H__
23

34
#include "py/runtime.h"
45

@@ -85,4 +86,4 @@ microbit_image_obj_t *microbit_image_for_char(char c);
8586
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t fval);
8687
microbit_image_obj_t *microbit_image_sum(microbit_image_obj_t *lhs, microbit_image_obj_t *rhs, bool add);
8788

88-
89+
#endif // __MICROPY_INCLUDED_MICROBIT_IMAGE_H__

source/microbit/main.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "MicroBit.h"
2+
#include "microbitdisplay.h"
23

34
extern "C" {
45
void mp_run(void);
5-
6-
void microbit_display_tick(void);
76

87
}
98

@@ -30,3 +29,37 @@ void app_main() {
3029
mp_run();
3130
}
3231
}
32+
33+
extern bool compass_up_to_date;
34+
extern bool accelerometer_up_to_date;
35+
36+
static void ticker(void) {
37+
38+
// increment our real-time counter.
39+
ticks += FIBER_TICK_PERIOD_MS;
40+
41+
if (uBit.compass.isCalibrating()) {
42+
uBit.compass.idleTick();
43+
}
44+
45+
compass_up_to_date = false;
46+
accelerometer_up_to_date = false;
47+
48+
// Update buttons
49+
uBit.buttonA.systemTick();
50+
uBit.buttonB.systemTick();
51+
52+
// Update the display.
53+
microbit_display_tick();
54+
}
55+
56+
extern "C" {
57+
58+
void microbit_init(void) {
59+
microbit_display_init();
60+
61+
// Hijack the DAL system ticker.
62+
uBit.systemTicker.attach(ticker, MICROBIT_DISPLAY_REFRESH_PERIOD);
63+
}
64+
65+
}

source/microbit/microbitdisplay.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ void microbit_display_tick(void) {
298298
}
299299
}
300300

301+
301302
void microbit_display_animate(microbit_display_obj_t *self, mp_obj_t iterable, mp_int_t delay, bool wait, bool loop) {
302303
// Reset the repeat state.
303304
MP_STATE_PORT(async_data)[0] = NULL;
@@ -461,37 +462,11 @@ microbit_display_obj_t microbit_display_obj = {
461462
.strobe_mask = 0x20
462463
};
463464

464-
extern bool compass_up_to_date;
465-
extern bool accelerometer_up_to_date;
466-
467-
static void ticker(void) {
468-
469-
// increment our real-time counter.
470-
ticks += FIBER_TICK_PERIOD_MS;
471-
472-
if (uBit.compass.isCalibrating()) {
473-
uBit.compass.idleTick();
474-
}
475-
476-
compass_up_to_date = false;
477-
accelerometer_up_to_date = false;
478-
479-
// Update buttons
480-
uBit.buttonA.systemTick();
481-
uBit.buttonB.systemTick();
482-
483-
// Update the display.
484-
microbit_display_tick();
485-
}
486-
487465
void microbit_display_init(void) {
488466
// Set pins as output.
489467
nrf_gpio_range_cfg_output(MICROBIT_DISPLAY_COLUMN_START,MICROBIT_DISPLAY_COLUMN_START + MICROBIT_DISPLAY_COLUMN_COUNT + MICROBIT_DISPLAY_ROW_COUNT);
490468

491469
uBit.display.disable();
492-
493-
// Hijack the DAL system ticker.
494-
uBit.systemTicker.attach(ticker, MICROBIT_DISPLAY_REFRESH_PERIOD);
495470
}
496471

497472
}

source/microbit/mprun.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "pyexec.h"
1212
#include MICROPY_HAL_H
1313

14-
extern void microbit_display_init(void);
14+
extern void microbit_init(void);
1515

1616
void microbit_display_exception(mp_obj_t exc_in) {
1717
mp_uint_t n, *values;
@@ -92,7 +92,8 @@ void mp_run(void) {
9292

9393
mp_init();
9494
mp_hal_init();
95-
microbit_display_init();
95+
96+
microbit_init();
9697

9798
if (APPENDED_SCRIPT->header[0] == 'M' && APPENDED_SCRIPT->header[1] == 'P') {
9899
// run appended script

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