Skip to content

Commit b4be04e

Browse files
authored
Merge pull request #9592 from jamesbowman/main
Change BitmapTransformA-F() methods to accept a single float...
2 parents 63a8db8 + b6dc9f0 commit b4be04e

File tree

3 files changed

+93
-42
lines changed

3 files changed

+93
-42
lines changed

ports/atmel-samd/boards/metro_m4_airlift_lite/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ QSPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ"
1111
LONGINT_IMPL = MPZ
1212

13-
CIRCUITPY__EVE = 1
13+
CIRCUITPY__EVE = 0
1414
CIRCUITPY_FLOPPYIO = 0
1515
CIRCUITPY_JPEGIO = 0
1616
CIRCUITPY_SYNTHIO = 0

shared-bindings/_eve/__init__.c

Lines changed: 91 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ static mp_obj_t _register(mp_obj_t self, mp_obj_t o) {
4646
}
4747
static MP_DEFINE_CONST_FUN_OBJ_2(register_obj, _register);
4848

49+
//| def setmodel(self, m: int) -> None: ...
50+
static mp_obj_t _setmodel(mp_obj_t self, mp_obj_t m) {
51+
common_hal__eve_t *eve = EVEHAL(self);
52+
eve->model = mp_obj_get_int_truncated(m);
53+
return mp_const_none;
54+
}
55+
static MP_DEFINE_CONST_FUN_OBJ_2(setmodel_obj, _setmodel);
56+
4957
//| def flush(self) -> None:
5058
//| """Send any queued drawing commands directly to the hardware.
5159
//|
@@ -236,113 +244,153 @@ static mp_obj_t _bitmapswizzle(size_t n_args, const mp_obj_t *args) {
236244
}
237245
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmapswizzle_obj, 5, 5, _bitmapswizzle);
238246

239-
//| def BitmapTransformA(self, p: int, v: int) -> None:
247+
//| def BitmapTransformA(self, v: float) -> None:
240248
//| """Set the :math:`a` component of the bitmap transform matrix
241249
//|
242-
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
243-
//| :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
250+
//| :param float v: The :math:`a` component of the bitmap transform matrix
244251
//|
245-
//| The initial value is **p** = 0, **v** = 256. This represents the value 1.0.
252+
//| The initial value 1.0.
246253
//|
247254
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
248255
//| """
249256
//| ...
250257

251-
static mp_obj_t _bitmaptransforma(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
252-
uint32_t p = mp_obj_get_int_truncated(a0);
253-
uint32_t v = mp_obj_get_int_truncated(a1);
254-
common_hal__eve_BitmapTransformA(EVEHAL(self), p, v);
258+
static void _transform1(uint32_t *p, uint32_t *v, size_t n_args, const mp_obj_t *args) {
259+
common_hal__eve_t *eve = EVEHAL(args[0]);
260+
mp_float_t a;
261+
262+
if (eve->model == 0) {
263+
// Backwards-compatible case for legacy code
264+
if (n_args != 3) {
265+
mp_raise_TypeError_varg(MP_ERROR_TEXT("function takes %d positional arguments but %d were given"), 2, n_args - 1);
266+
}
267+
*p = mp_obj_get_int_truncated(args[1]);
268+
*v = mp_obj_get_int_truncated(args[2]);
269+
} else {
270+
if (n_args != 2) {
271+
mp_raise_TypeError_varg(MP_ERROR_TEXT("function takes %d positional arguments but %d were given"), 1, n_args - 1);
272+
}
273+
a = mp_obj_get_float(args[1]);
274+
if ((eve->model > 810) && (-2.0 <= a) && (a < 2.0)) {
275+
*p = 1;
276+
*v = (int)(32768.0 * a);
277+
} else {
278+
*p = 0;
279+
*v = (int)(256.0 * a);
280+
}
281+
}
282+
}
283+
284+
static mp_obj_t _bitmaptransforma(size_t n_args, const mp_obj_t *args) {
285+
uint32_t p, v;
286+
_transform1(&p, &v, n_args, args);
287+
common_hal__eve_BitmapTransformA(EVEHAL(args[0]), p, v);
255288
return mp_const_none;
256289
}
257-
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransforma_obj, _bitmaptransforma);
290+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransforma_obj, 2, 3, _bitmaptransforma);
258291

259-
//| def BitmapTransformB(self, p: int, v: int) -> None:
292+
//| def BitmapTransformB(self, v: float) -> None:
260293
//| """Set the :math:`b` component of the bitmap transform matrix
261294
//|
262-
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
263-
//| :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
295+
//| :param float v: The :math:`b` component of the bitmap transform matrix
264296
//|
265-
//| The initial value is **p** = 0, **v** = 0. This represents the value 0.0.
297+
//| The initial value 0.0.
266298
//|
267299
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
268300
//| """
269301
//| ...
270302

271-
static mp_obj_t _bitmaptransformb(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
272-
uint32_t p = mp_obj_get_int_truncated(a0);
273-
uint32_t v = mp_obj_get_int_truncated(a1);
274-
common_hal__eve_BitmapTransformB(EVEHAL(self), p, v);
303+
static mp_obj_t _bitmaptransformb(size_t n_args, const mp_obj_t *args) {
304+
uint32_t p, v;
305+
_transform1(&p, &v, n_args, args);
306+
common_hal__eve_BitmapTransformB(EVEHAL(args[0]), p, v);
275307
return mp_const_none;
276308
}
277-
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransformb_obj, _bitmaptransformb);
309+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransformb_obj, 2, 3, _bitmaptransformb);
278310

279-
//| def BitmapTransformC(self, v: int) -> None:
311+
//| def BitmapTransformC(self, v: float) -> None:
280312
//| """Set the :math:`c` component of the bitmap transform matrix
281313
//|
282-
//| :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
314+
//| :param int v: The :math:`c` component of the bitmap transform matrix
315+
//|
316+
//| The initial value 0.0.
283317
//|
284318
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
285319
//| """
286320
//| ...
287321

288322
static mp_obj_t _bitmaptransformc(mp_obj_t self, mp_obj_t a0) {
289-
uint32_t v = mp_obj_get_int_truncated(a0);
323+
common_hal__eve_t *eve = EVEHAL(self);
324+
int v;
325+
326+
if (eve->model == 0) {
327+
v = mp_obj_get_int_truncated(a0);
328+
} else {
329+
v = (int)(256.0 * mp_obj_get_float(a0));
330+
}
290331
common_hal__eve_BitmapTransformC(EVEHAL(self), v);
291332
return mp_const_none;
292333
}
293334
static MP_DEFINE_CONST_FUN_OBJ_2(bitmaptransformc_obj, _bitmaptransformc);
294335

295-
//| def BitmapTransformD(self, p: int, v: int) -> None:
336+
//| def BitmapTransformD(self, v: float) -> None:
296337
//| """Set the :math:`d` component of the bitmap transform matrix
297338
//|
298-
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
299-
//| :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
339+
//| :param float v: The :math:`d` component of the bitmap transform matrix
300340
//|
301-
//| The initial value is **p** = 0, **v** = 0. This represents the value 0.0.
341+
//| The initial value 0.0.
302342
//|
303343
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
304344
//| """
305345
//| ...
306346

307-
static mp_obj_t _bitmaptransformd(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
308-
uint32_t p = mp_obj_get_int_truncated(a0);
309-
uint32_t v = mp_obj_get_int_truncated(a1);
310-
common_hal__eve_BitmapTransformD(EVEHAL(self), p, v);
347+
static mp_obj_t _bitmaptransformd(size_t n_args, const mp_obj_t *args) {
348+
uint32_t p, v;
349+
_transform1(&p, &v, n_args, args);
350+
common_hal__eve_BitmapTransformD(EVEHAL(args[0]), p, v);
311351
return mp_const_none;
312352
}
313-
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransformd_obj, _bitmaptransformd);
353+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransformd_obj, 2, 3, _bitmaptransformd);
314354

315-
//| def BitmapTransformE(self, p: int, v: int) -> None:
355+
//| def BitmapTransformE(self, v: float) -> None:
316356
//| """Set the :math:`e` component of the bitmap transform matrix
317357
//|
318-
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
319-
//| :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
358+
//| :param float v: The :math:`e` component of the bitmap transform matrix
320359
//|
321-
//| The initial value is **p** = 0, **v** = 256. This represents the value 1.0.
360+
//| The initial value 1.0.
322361
//|
323362
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
324363
//| """
325364
//| ...
326365

327-
static mp_obj_t _bitmaptransforme(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
328-
uint32_t p = mp_obj_get_int_truncated(a0);
329-
uint32_t v = mp_obj_get_int_truncated(a1);
330-
common_hal__eve_BitmapTransformE(EVEHAL(self), p, v);
366+
static mp_obj_t _bitmaptransforme(size_t n_args, const mp_obj_t *args) {
367+
uint32_t p, v;
368+
_transform1(&p, &v, n_args, args);
369+
common_hal__eve_BitmapTransformE(EVEHAL(args[0]), p, v);
331370
return mp_const_none;
332371
}
333-
static MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransforme_obj, _bitmaptransforme);
372+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransforme_obj, 2, 3, _bitmaptransforme);
334373

335374
//| def BitmapTransformF(self, v: int) -> None:
336375
//| """Set the :math:`f` component of the bitmap transform matrix
337376
//|
338-
//| :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
377+
//| :param int v: The :math:`f` component of the bitmap transform matrix
378+
//|
379+
//| The initial value 0.0.
339380
//|
340381
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
341382
//| """
342383
//| ...
343384

344385
static mp_obj_t _bitmaptransformf(mp_obj_t self, mp_obj_t a0) {
345-
uint32_t v = mp_obj_get_int_truncated(a0);
386+
common_hal__eve_t *eve = EVEHAL(self);
387+
int v;
388+
389+
if (eve->model == 0) {
390+
v = mp_obj_get_int_truncated(a0);
391+
} else {
392+
v = (int)(256.0 * mp_obj_get_float(a0));
393+
}
346394
common_hal__eve_BitmapTransformF(EVEHAL(self), v);
347395
return mp_const_none;
348396
}
@@ -1057,6 +1105,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(cmd_obj, 4, 4, _cmd);
10571105

10581106
static const mp_rom_map_elem_t _EVE_locals_dict_table[] = {
10591107
{ MP_ROM_QSTR(MP_QSTR_register), MP_ROM_PTR(&register_obj) },
1108+
{ MP_ROM_QSTR(MP_QSTR_setmodel), MP_ROM_PTR(&setmodel_obj) },
10601109
{ MP_ROM_QSTR(MP_QSTR_cc), MP_ROM_PTR(&cc_obj) },
10611110
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&flush_obj) },
10621111
{ MP_ROM_QSTR(MP_QSTR_Vertex2f), MP_ROM_PTR(&vertex2f_obj) },
@@ -1071,6 +1120,7 @@ static mp_obj_t _EVE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
10711120
mp_obj__EVE_t *o = mp_obj_malloc(mp_obj__EVE_t, &_EVE_type);
10721121
o->_eve.n = 0;
10731122
o->_eve.vscale = 16;
1123+
o->_eve.model = 0; // default is legacy behavior
10741124
return MP_OBJ_FROM_PTR(o);
10751125
}
10761126

shared-module/_eve/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

0 commit comments

Comments
 (0)