|
|
|
@ -31,72 +31,72 @@
|
|
|
|
|
#include "py/runtime.h"
|
|
|
|
|
#include "py/binary.h"
|
|
|
|
|
|
|
|
|
|
//| :mod:`eveL` --- low-level BridgeTek EVE bindings
|
|
|
|
|
//| :mod:`_eve` --- low-level BridgeTek EVE bindings
|
|
|
|
|
//| ================================================
|
|
|
|
|
//|
|
|
|
|
|
//| .. module:: eveL
|
|
|
|
|
//| .. module:: _eve
|
|
|
|
|
//| :synopsis: low-level BridgeTek EVE bindings
|
|
|
|
|
//| :platform: SAMD21/SAMD51
|
|
|
|
|
//|
|
|
|
|
|
//| The `eveL` module provides a class EVEL which
|
|
|
|
|
//| The `_eve` module provides a class _EVE which
|
|
|
|
|
//| contains methods for constructing EVE command
|
|
|
|
|
//| buffers and appending basic graphics commands.
|
|
|
|
|
//|
|
|
|
|
|
|
|
|
|
|
typedef struct _mp_obj_EVEL_t {
|
|
|
|
|
typedef struct _mp_obj__EVE_t {
|
|
|
|
|
mp_obj_base_t base;
|
|
|
|
|
mp_obj_t dest[3];
|
|
|
|
|
size_t n;
|
|
|
|
|
uint8_t buf[512];
|
|
|
|
|
} mp_obj_EVEL_t;
|
|
|
|
|
} mp_obj__EVE_t;
|
|
|
|
|
|
|
|
|
|
STATIC const mp_obj_type_t EVEL_type;
|
|
|
|
|
STATIC const mp_obj_type_t _EVE_type;
|
|
|
|
|
|
|
|
|
|
STATIC void _write(mp_obj_EVEL_t *EVEL, mp_obj_t b) {
|
|
|
|
|
EVEL->dest[2] = b;
|
|
|
|
|
mp_call_method_n_kw(1, 0, EVEL->dest);
|
|
|
|
|
STATIC void _write(mp_obj__EVE_t *_EVE, mp_obj_t b) {
|
|
|
|
|
_EVE->dest[2] = b;
|
|
|
|
|
mp_call_method_n_kw(1, 0, _EVE->dest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC mp_obj_t _register(mp_obj_t self, mp_obj_t o) {
|
|
|
|
|
mp_obj_EVEL_t *EVEL = mp_instance_cast_to_native_base(self, &EVEL_type);
|
|
|
|
|
EVEL->n = 0;
|
|
|
|
|
mp_load_method(o, MP_QSTR_write, EVEL->dest);
|
|
|
|
|
mp_obj__EVE_t *_EVE = mp_instance_cast_to_native_base(self, &_EVE_type);
|
|
|
|
|
_EVE->n = 0;
|
|
|
|
|
mp_load_method(o, MP_QSTR_write, _EVE->dest);
|
|
|
|
|
return mp_const_none;
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(register_obj, _register);
|
|
|
|
|
|
|
|
|
|
STATIC mp_obj_t _flush(mp_obj_t self) {
|
|
|
|
|
mp_obj_EVEL_t *EVEL = mp_instance_cast_to_native_base(self, &EVEL_type);
|
|
|
|
|
if (EVEL->n != 0) {
|
|
|
|
|
_write(EVEL, mp_obj_new_bytearray_by_ref(EVEL->n, EVEL->buf));
|
|
|
|
|
EVEL->n = 0;
|
|
|
|
|
mp_obj__EVE_t *_EVE = mp_instance_cast_to_native_base(self, &_EVE_type);
|
|
|
|
|
if (_EVE->n != 0) {
|
|
|
|
|
_write(_EVE, mp_obj_new_bytearray_by_ref(_EVE->n, _EVE->buf));
|
|
|
|
|
_EVE->n = 0;
|
|
|
|
|
}
|
|
|
|
|
return mp_const_none;
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(flush_obj, _flush);
|
|
|
|
|
|
|
|
|
|
STATIC void *append(mp_obj_t self, size_t m) {
|
|
|
|
|
mp_obj_EVEL_t *EVEL = mp_instance_cast_to_native_base(self, &EVEL_type);
|
|
|
|
|
if ((EVEL->n + m) > sizeof(EVEL->buf))
|
|
|
|
|
_flush((mp_obj_t)EVEL);
|
|
|
|
|
uint8_t *r = EVEL->buf + EVEL->n;
|
|
|
|
|
EVEL->n += m;
|
|
|
|
|
mp_obj__EVE_t *_EVE = mp_instance_cast_to_native_base(self, &_EVE_type);
|
|
|
|
|
if ((_EVE->n + m) > sizeof(_EVE->buf))
|
|
|
|
|
_flush((mp_obj_t)_EVE);
|
|
|
|
|
uint8_t *r = _EVE->buf + _EVE->n;
|
|
|
|
|
_EVE->n += m;
|
|
|
|
|
return (void*)r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC mp_obj_t _cc(mp_obj_t self, mp_obj_t b) {
|
|
|
|
|
mp_obj_EVEL_t *EVEL = mp_instance_cast_to_native_base(self, &EVEL_type);
|
|
|
|
|
mp_obj__EVE_t *_EVE = mp_instance_cast_to_native_base(self, &_EVE_type);
|
|
|
|
|
mp_buffer_info_t buffer_info;
|
|
|
|
|
mp_get_buffer_raise(b, &buffer_info, MP_BUFFER_READ);
|
|
|
|
|
if (buffer_info.len <= sizeof(EVEL->buf)) {
|
|
|
|
|
uint8_t *p = (uint8_t*)append(EVEL, buffer_info.len);
|
|
|
|
|
if (buffer_info.len <= sizeof(_EVE->buf)) {
|
|
|
|
|
uint8_t *p = (uint8_t*)append(_EVE, buffer_info.len);
|
|
|
|
|
// memcpy(p, buffer_info.buf, buffer_info.len);
|
|
|
|
|
uint8_t *s = buffer_info.buf;
|
|
|
|
|
for (size_t i = 0; i < buffer_info.len; i++)
|
|
|
|
|
*p++ = *s++;
|
|
|
|
|
} else {
|
|
|
|
|
_flush(self);
|
|
|
|
|
_write(EVEL, b);
|
|
|
|
|
_write(_EVE, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mp_const_none;
|
|
|
|
@ -105,7 +105,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(cc_obj, _cc);
|
|
|
|
|
|
|
|
|
|
#define C4(self, u) (*(uint32_t*)append((self), sizeof(uint32_t)) = (u))
|
|
|
|
|
|
|
|
|
|
#include "modeveL-gen.h"
|
|
|
|
|
#include "mod_eve-gen.h"
|
|
|
|
|
|
|
|
|
|
// Hand-written functions {
|
|
|
|
|
|
|
|
|
@ -175,7 +175,7 @@ STATIC mp_obj_t _cmd(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
}
|
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cmd_obj, 4, 4, _cmd);
|
|
|
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t EVEL_locals_dict_table[] = {
|
|
|
|
|
STATIC const mp_rom_map_elem_t _EVE_locals_dict_table[] = {
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_register), MP_ROM_PTR(®ister_obj) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_cc), MP_ROM_PTR(&cc_obj) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&flush_obj) },
|
|
|
|
@ -184,40 +184,40 @@ STATIC const mp_rom_map_elem_t EVEL_locals_dict_table[] = {
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_cmd0), MP_ROM_PTR(&cmd0_obj) },
|
|
|
|
|
ROM_DECLS
|
|
|
|
|
};
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(EVEL_locals_dict, EVEL_locals_dict_table);
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(_EVE_locals_dict, _EVE_locals_dict_table);
|
|
|
|
|
|
|
|
|
|
STATIC void EVEL_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
|
|
|
|
STATIC void _EVE_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
|
|
|
|
(void)self_in;
|
|
|
|
|
(void)kind;
|
|
|
|
|
mp_printf(print, "<EVEL>");
|
|
|
|
|
mp_printf(print, "<_EVE>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC mp_obj_t EVEL_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
|
|
|
|
STATIC mp_obj_t _EVE_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
|
|
|
|
// mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
|
|
|
|
mp_obj_EVEL_t *o = m_new_obj(mp_obj_EVEL_t);
|
|
|
|
|
mp_printf(&mp_plat_print, "EVEL %p make_new\n", o);
|
|
|
|
|
o->base.type = &EVEL_type;
|
|
|
|
|
mp_obj__EVE_t *o = m_new_obj(mp_obj__EVE_t);
|
|
|
|
|
mp_printf(&mp_plat_print, "_EVE %p make_new\n", o);
|
|
|
|
|
o->base.type = &_EVE_type;
|
|
|
|
|
return MP_OBJ_FROM_PTR(o);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC const mp_obj_type_t EVEL_type = {
|
|
|
|
|
STATIC const mp_obj_type_t _EVE_type = {
|
|
|
|
|
{ &mp_type_type },
|
|
|
|
|
// Save on qstr's, reuse same as for module
|
|
|
|
|
.name = MP_QSTR_EVEL,
|
|
|
|
|
.print = EVEL_print,
|
|
|
|
|
.make_new = EVEL_make_new,
|
|
|
|
|
// .attr = EVEL_attr,
|
|
|
|
|
.locals_dict = (void*)&EVEL_locals_dict,
|
|
|
|
|
.name = MP_QSTR__EVE,
|
|
|
|
|
.print = _EVE_print,
|
|
|
|
|
.make_new = _EVE_make_new,
|
|
|
|
|
// .attr = _EVE_attr,
|
|
|
|
|
.locals_dict = (void*)&_EVE_locals_dict,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t mp_module_eveL_globals_table[] = {
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_eveL) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_EVEL), MP_OBJ_FROM_PTR(&EVEL_type) },
|
|
|
|
|
STATIC const mp_rom_map_elem_t mp_module__eve_globals_table[] = {
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__eve) },
|
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR__EVE), MP_OBJ_FROM_PTR(&_EVE_type) },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(mp_module_eveL_globals, mp_module_eveL_globals_table);
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(mp_module__eve_globals, mp_module__eve_globals_table);
|
|
|
|
|
|
|
|
|
|
const mp_obj_module_t eveL_module = {
|
|
|
|
|
const mp_obj_module_t _eve_module = {
|
|
|
|
|
.base = { &mp_type_module },
|
|
|
|
|
.globals = (mp_obj_dict_t*)&mp_module_eveL_globals,
|
|
|
|
|
.globals = (mp_obj_dict_t*)&mp_module__eve_globals,
|
|
|
|
|
};
|