Skip to content
Snippets Groups Projects
Commit 5b10eb73 authored by dx's avatar dx
Browse files

initialize a global ctx, expose it to python

parent 7a4c6f30
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,10 @@
#include "badge23/scope.h"
#include "esp_system.h"
#include "../../usermodule/uctx/uctx/ctx.h"
Ctx *the_ctx = NULL;
uint16_t *pixels;
typedef struct leds_cfg {
......@@ -28,6 +32,14 @@ static void _display_init() {
// GC9A01_Screen_Load(0,0,240,240,pixels);
GC9A01_Update();
the_ctx = ctx_new_for_framebuffer(
ScreenBuff,
GC9A01_Width,
GC9A01_Height,
GC9A01_Width * 2,
CTX_FORMAT_RGB565_BYTESWAPPED
);
/*
display_queue = xQueueCreate(1, sizeof(display_cfg_t));
TaskHandle_t handle;
......
......@@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "../../usermodule/uctx/uctx/ctx.h"
void display_init();
void display_draw_scope();
......@@ -9,3 +10,5 @@ void display_update();
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;
......@@ -19,6 +19,9 @@
#include "badge23/espan.h"
#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(size_t n_args, const mp_obj_t *args) {
return mp_obj_new_int(hardware_is_initialized());
}
......@@ -132,6 +135,15 @@ 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) {
if (mp_ctx == NULL) {
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);
STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_badge_audio) },
{ MP_ROM_QSTR(MP_QSTR_init_done), MP_ROM_PTR(&mp_init_done_obj) },
......@@ -149,6 +161,7 @@ STATIC const mp_rom_map_elem_t mp_module_hardware_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_display_get_pixel), MP_ROM_PTR(&mp_display_get_pixel_obj) },
{ MP_ROM_QSTR(MP_QSTR_display_fill), MP_ROM_PTR(&mp_display_fill_obj) },
{ MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&mp_version_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_ctx), MP_ROM_PTR(&mp_get_ctx_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_hardware_globals, mp_module_hardware_globals_table);
......
......@@ -99,39 +99,6 @@
/* we keep the ctx implementation here, this compilation taget changes less
* than the micropython target
*/
#define CTX_EXTERNAL_MALLOC
static inline void *ctx_malloc (size_t size)
{
return m_malloc (size);
}
static inline void *ctx_calloc (size_t nmemb, size_t size)
{
size_t byte_size = nmemb * size;
char *ret = (char *)m_malloc(byte_size);
for (size_t i = 0; i < byte_size; i++)
ret[i] = 0;
return ret;
}
static inline void *ctx_realloc (void *ptr, size_t old_size, size_t new_size)
{
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
return m_realloc(ptr, old_size, new_size);
#else
return m_realloc(ptr, new_size);
#endif
}
static inline void ctx_free (void *ptr)
{
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
return m_free(ptr, 0); // XXX !
#else
return m_free(ptr);
#endif
}
#define CTX_STATIC_FONT(font) \
ctx_load_font_ctx(ctx_font_##font##_name, \
......@@ -1074,6 +1041,13 @@ static int mp_ctx_update_fb (Ctx *ctx, void *user_data)
return 0;
}
mp_obj_t mp_ctx_from_ctx(Ctx *ctx) {
mp_ctx_obj_t *o = m_new_obj(mp_ctx_obj_t);
o->base.type = &mp_ctx_type;
o->ctx = ctx;
return MP_OBJ_FROM_PTR(o);
}
static mp_obj_t mp_ctx_make_new(
const mp_obj_type_t *type,
size_t n_args,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment