Skip to content

Commit

Permalink
Merge pull request #9592 from jamesbowman/main
Browse files Browse the repository at this point in the history
Change BitmapTransformA-F() methods to accept a single float...
  • Loading branch information
dhalbert authored Sep 5, 2024
2 parents 63a8db8 + b6dc9f0 commit b4be04e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ"
LONGINT_IMPL = MPZ

CIRCUITPY__EVE = 1
CIRCUITPY__EVE = 0
CIRCUITPY_FLOPPYIO = 0
CIRCUITPY_JPEGIO = 0
CIRCUITPY_SYNTHIO = 0
Expand Down
132 changes: 91 additions & 41 deletions shared-bindings/_eve/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ static mp_obj_t _register(mp_obj_t self, mp_obj_t o) {
}
static MP_DEFINE_CONST_FUN_OBJ_2(register_obj, _register);

//| def setmodel(self, m: int) -> None: ...
static mp_obj_t _setmodel(mp_obj_t self, mp_obj_t m) {
common_hal__eve_t *eve = EVEHAL(self);
eve->model = mp_obj_get_int_truncated(m);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_2(setmodel_obj, _setmodel);

//| def flush(self) -> None:
//| """Send any queued drawing commands directly to the hardware.
//|
Expand Down Expand Up @@ -236,113 +244,153 @@ static mp_obj_t _bitmapswizzle(size_t n_args, const mp_obj_t *args) {
}
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmapswizzle_obj, 5, 5, _bitmapswizzle);

//| def BitmapTransformA(self, p: int, v: int) -> None:
//| def BitmapTransformA(self, v: float) -> None:
//| """Set the :math:`a` component of the bitmap transform matrix
//|
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
//| :param int v: The :math:`a` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 256
//| :param float v: The :math:`a` component of the bitmap transform matrix
//|
//| The initial value is **p** = 0, **v** = 256. This represents the value 1.0.
//| The initial value 1.0.
//|
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...

static mp_obj_t _bitmaptransforma(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t p = mp_obj_get_int_truncated(a0);
uint32_t v = mp_obj_get_int_truncated(a1);
common_hal__eve_BitmapTransformA(EVEHAL(self), p, v);
static void _transform1(uint32_t *p, uint32_t *v, size_t n_args, const mp_obj_t *args) {
common_hal__eve_t *eve = EVEHAL(args[0]);
mp_float_t a;

if (eve->model == 0) {
// Backwards-compatible case for legacy code
if (n_args != 3) {
mp_raise_TypeError_varg(MP_ERROR_TEXT("function takes %d positional arguments but %d were given"), 2, n_args - 1);
}
*p = mp_obj_get_int_truncated(args[1]);
*v = mp_obj_get_int_truncated(args[2]);
} else {
if (n_args != 2) {
mp_raise_TypeError_varg(MP_ERROR_TEXT("function takes %d positional arguments but %d were given"), 1, n_args - 1);
}
a = mp_obj_get_float(args[1]);
if ((eve->model > 810) && (-2.0 <= a) && (a < 2.0)) {
*p = 1;
*v = (int)(32768.0 * a);
} else {
*p = 0;
*v = (int)(256.0 * a);
}
}
}

static mp_obj_t _bitmaptransforma(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
_transform1(&p, &v, n_args, args);
common_hal__eve_BitmapTransformA(EVEHAL(args[0]), p, v);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransforma_obj, _bitmaptransforma);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransforma_obj, 2, 3, _bitmaptransforma);

//| def BitmapTransformB(self, p: int, v: int) -> None:
//| def BitmapTransformB(self, v: float) -> None:
//| """Set the :math:`b` component of the bitmap transform matrix
//|
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
//| :param int v: The :math:`b` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 0
//| :param float v: The :math:`b` component of the bitmap transform matrix
//|
//| The initial value is **p** = 0, **v** = 0. This represents the value 0.0.
//| The initial value 0.0.
//|
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...

static mp_obj_t _bitmaptransformb(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t p = mp_obj_get_int_truncated(a0);
uint32_t v = mp_obj_get_int_truncated(a1);
common_hal__eve_BitmapTransformB(EVEHAL(self), p, v);
static mp_obj_t _bitmaptransformb(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
_transform1(&p, &v, n_args, args);
common_hal__eve_BitmapTransformB(EVEHAL(args[0]), p, v);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransformb_obj, _bitmaptransformb);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransformb_obj, 2, 3, _bitmaptransformb);

//| def BitmapTransformC(self, v: int) -> None:
//| def BitmapTransformC(self, v: float) -> None:
//| """Set the :math:`c` component of the bitmap transform matrix
//|
//| :param int v: The :math:`c` component of the bitmap transform matrix, in signed 15.8 bit fixed-point form. Range 0-16777215. The initial value is 0
//| :param int v: The :math:`c` component of the bitmap transform matrix
//|
//| The initial value 0.0.
//|
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...

static mp_obj_t _bitmaptransformc(mp_obj_t self, mp_obj_t a0) {
uint32_t v = mp_obj_get_int_truncated(a0);
common_hal__eve_t *eve = EVEHAL(self);
int v;

if (eve->model == 0) {
v = mp_obj_get_int_truncated(a0);
} else {
v = (int)(256.0 * mp_obj_get_float(a0));
}
common_hal__eve_BitmapTransformC(EVEHAL(self), v);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_2(bitmaptransformc_obj, _bitmaptransformc);

//| def BitmapTransformD(self, p: int, v: int) -> None:
//| def BitmapTransformD(self, v: float) -> None:
//| """Set the :math:`d` component of the bitmap transform matrix
//|
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
//| :param int v: The :math:`d` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 0
//| :param float v: The :math:`d` component of the bitmap transform matrix
//|
//| The initial value is **p** = 0, **v** = 0. This represents the value 0.0.
//| The initial value 0.0.
//|
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...

static mp_obj_t _bitmaptransformd(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t p = mp_obj_get_int_truncated(a0);
uint32_t v = mp_obj_get_int_truncated(a1);
common_hal__eve_BitmapTransformD(EVEHAL(self), p, v);
static mp_obj_t _bitmaptransformd(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
_transform1(&p, &v, n_args, args);
common_hal__eve_BitmapTransformD(EVEHAL(args[0]), p, v);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransformd_obj, _bitmaptransformd);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransformd_obj, 2, 3, _bitmaptransformd);

//| def BitmapTransformE(self, p: int, v: int) -> None:
//| def BitmapTransformE(self, v: float) -> None:
//| """Set the :math:`e` component of the bitmap transform matrix
//|
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
//| :param int v: The :math:`e` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 256
//| :param float v: The :math:`e` component of the bitmap transform matrix
//|
//| The initial value is **p** = 0, **v** = 256. This represents the value 1.0.
//| The initial value 1.0.
//|
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...

static mp_obj_t _bitmaptransforme(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t p = mp_obj_get_int_truncated(a0);
uint32_t v = mp_obj_get_int_truncated(a1);
common_hal__eve_BitmapTransformE(EVEHAL(self), p, v);
static mp_obj_t _bitmaptransforme(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
_transform1(&p, &v, n_args, args);
common_hal__eve_BitmapTransformE(EVEHAL(args[0]), p, v);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransforme_obj, _bitmaptransforme);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransforme_obj, 2, 3, _bitmaptransforme);

//| def BitmapTransformF(self, v: int) -> None:
//| """Set the :math:`f` component of the bitmap transform matrix
//|
//| :param int v: The :math:`f` component of the bitmap transform matrix, in signed 15.8 bit fixed-point form. Range 0-16777215. The initial value is 0
//| :param int v: The :math:`f` component of the bitmap transform matrix
//|
//| The initial value 0.0.
//|
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...

static mp_obj_t _bitmaptransformf(mp_obj_t self, mp_obj_t a0) {
uint32_t v = mp_obj_get_int_truncated(a0);
common_hal__eve_t *eve = EVEHAL(self);
int v;

if (eve->model == 0) {
v = mp_obj_get_int_truncated(a0);
} else {
v = (int)(256.0 * mp_obj_get_float(a0));
}
common_hal__eve_BitmapTransformF(EVEHAL(self), v);
return mp_const_none;
}
Expand Down Expand Up @@ -1057,6 +1105,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cmd_obj, 4, 4, _cmd);

static const mp_rom_map_elem_t _EVE_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_register), MP_ROM_PTR(&register_obj) },
{ MP_ROM_QSTR(MP_QSTR_setmodel), MP_ROM_PTR(&setmodel_obj) },
{ MP_ROM_QSTR(MP_QSTR_cc), MP_ROM_PTR(&cc_obj) },
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&flush_obj) },
{ MP_ROM_QSTR(MP_QSTR_Vertex2f), MP_ROM_PTR(&vertex2f_obj) },
Expand All @@ -1071,6 +1120,7 @@ static mp_obj_t _EVE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
mp_obj__EVE_t *o = mp_obj_malloc(mp_obj__EVE_t, &_EVE_type);
o->_eve.n = 0;
o->_eve.vscale = 16;
o->_eve.model = 0; // default is legacy behavior
return MP_OBJ_FROM_PTR(o);
}

Expand Down
1 change: 1 addition & 0 deletions shared-module/_eve/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

typedef struct _common_hal__eve_t {
mp_obj_t dest[3]; // Own 'write' method, plus argument
int model; // 0 for unknown, or 810, 815, 817 for the three EVE generations
int vscale; // fixed-point scaling used for Vertex2f
size_t n; // Current size of command buffer
uint8_t buf[512]; // Command buffer
Expand Down

0 comments on commit b4be04e

Please sign in to comment.