Skip to content
Snippets Groups Projects
Commit da6791e0 authored by q3k's avatar q3k
Browse files

badge23: work around ctx initialization race condition

Sometimes mpy code requests ctx too early, before the display (and thus
ctx) are initialized.

This is a quick-and-dirty workaround as we're planning on getting rid of
this code path anyway.
parent 06812a1c
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@
#include "../../usermodule/uctx/uctx/ctx.h"
Ctx *the_ctx = NULL;
volatile Ctx *the_ctx = NULL;
uint16_t *pixels;
......
......@@ -12,4 +12,4 @@ void display_draw_pixel(uint8_t x, uint8_t y, uint16_t col);
uint16_t display_get_pixel(uint8_t x, uint8_t y);
void display_fill(uint16_t col);
extern Ctx *the_ctx;
extern volatile Ctx *the_ctx;
......@@ -20,7 +20,6 @@
#include "badge23_hwconfig.h"
mp_obj_t mp_ctx_from_ctx(Ctx *ctx);
mp_obj_t mp_ctx = NULL;
STATIC mp_obj_t mp_init_done(void) {
return mp_obj_new_int(hardware_is_initialized());
......@@ -190,7 +189,12 @@ STATIC mp_obj_t mp_version(void) {
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_version_obj, mp_version);
STATIC mp_obj_t mp_get_ctx(size_t n_args, const mp_obj_t *args) {
mp_ctx = mp_ctx_from_ctx(the_ctx);
// This might be called before the ctx is ready.
// HACK: this will go away with the new drawing API.
while (the_ctx == NULL) {
vTaskDelay(100 / portTICK_PERIOD_MS);
}
mp_obj_t mp_ctx = mp_ctx_from_ctx(the_ctx);
return mp_ctx;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_get_ctx_obj, 0, 0, mp_get_ctx);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment