nrf/boards/microbit: Use MICROPY_PY_BUILTINS_FLOAT to detect FP support.
This works for both single and double precision float.
This commit is contained in:
parent
9addc38af4
commit
6ac4304284
|
@ -605,9 +605,9 @@ microbit_image_obj_t *microbit_image_for_char(char c) {
|
||||||
return (microbit_image_obj_t *)result;
|
return (microbit_image_obj_t *)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t fval) {
|
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t fval) {
|
||||||
#else // MICROPY_FLOAT_IMPL_NONE
|
#else
|
||||||
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t fval) {
|
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t fval) {
|
||||||
#endif
|
#endif
|
||||||
if (fval < 0)
|
if (fval < 0)
|
||||||
|
@ -615,9 +615,9 @@ microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t fva
|
||||||
greyscale_t *result = greyscale_new(imageWidth(lhs), imageHeight(lhs));
|
greyscale_t *result = greyscale_new(imageWidth(lhs), imageHeight(lhs));
|
||||||
for (int x = 0; x < imageWidth(lhs); ++x) {
|
for (int x = 0; x < imageWidth(lhs); ++x) {
|
||||||
for (int y = 0; y < imageWidth(lhs); ++y) {
|
for (int y = 0; y < imageWidth(lhs); ++y) {
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
int val = min((int)imageGetPixelValue(lhs, x,y)*fval+0.5, MAX_BRIGHTNESS);
|
int val = min((int)imageGetPixelValue(lhs, x,y)*fval+0.5, MAX_BRIGHTNESS);
|
||||||
#else // MICROPY_FLOAT_IMPL_NONE
|
#else
|
||||||
int val = min((int)imageGetPixelValue(lhs, x,y)*fval, MAX_BRIGHTNESS);
|
int val = min((int)imageGetPixelValue(lhs, x,y)*fval, MAX_BRIGHTNESS);
|
||||||
#endif
|
#endif
|
||||||
greyscaleSetPixelValue(result, x, y, val);
|
greyscaleSetPixelValue(result, x, y, val);
|
||||||
|
@ -659,13 +659,13 @@ STATIC mp_obj_t image_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
|
||||||
case MP_BINARY_OP_SUBTRACT:
|
case MP_BINARY_OP_SUBTRACT:
|
||||||
break;
|
break;
|
||||||
case MP_BINARY_OP_MULTIPLY:
|
case MP_BINARY_OP_MULTIPLY:
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
return microbit_image_dim(lhs, mp_obj_get_float(rhs_in));
|
return microbit_image_dim(lhs, mp_obj_get_float(rhs_in));
|
||||||
#else
|
#else
|
||||||
return microbit_image_dim(lhs, mp_obj_get_int(rhs_in) * 10);
|
return microbit_image_dim(lhs, mp_obj_get_int(rhs_in) * 10);
|
||||||
#endif
|
#endif
|
||||||
case MP_BINARY_OP_TRUE_DIVIDE:
|
case MP_BINARY_OP_TRUE_DIVIDE:
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
return microbit_image_dim(lhs, 1.0/mp_obj_get_float(rhs_in));
|
return microbit_image_dim(lhs, 1.0/mp_obj_get_float(rhs_in));
|
||||||
#else
|
#else
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -89,7 +89,7 @@ extern const mp_obj_type_t microbit_image_type;
|
||||||
#define HEART_IMAGE (microbit_image_obj_t *)(µbit_const_image_heart_obj)
|
#define HEART_IMAGE (microbit_image_obj_t *)(µbit_const_image_heart_obj)
|
||||||
#define HAPPY_IMAGE (microbit_image_obj_t *)(µbit_const_image_happy_obj)
|
#define HAPPY_IMAGE (microbit_image_obj_t *)(µbit_const_image_happy_obj)
|
||||||
|
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t fval);
|
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_float_t fval);
|
||||||
#else
|
#else
|
||||||
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t val);
|
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t val);
|
||||||
|
|
|
@ -45,7 +45,7 @@ STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) {
|
||||||
mp_int_t ms = 0;
|
mp_int_t ms = 0;
|
||||||
if (mp_obj_is_integer(ms_in)) {
|
if (mp_obj_is_integer(ms_in)) {
|
||||||
ms = mp_obj_get_int(ms_in);
|
ms = mp_obj_get_int(ms_in);
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
} else {
|
} else {
|
||||||
ms = (mp_int_t)mp_obj_get_float(ms_in);
|
ms = (mp_int_t)mp_obj_get_float(ms_in);
|
||||||
#endif
|
#endif
|
||||||
|
@ -97,7 +97,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(microbit_panic_obj, 0, 1, microbit_panic);
|
||||||
|
|
||||||
STATIC mp_obj_t microbit_temperature(void) {
|
STATIC mp_obj_t microbit_temperature(void) {
|
||||||
int temp = nrf_temp_read();
|
int temp = nrf_temp_read();
|
||||||
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
|
#if MICROPY_PY_BUILTINS_FLOAT
|
||||||
return mp_obj_new_float(temp / 4);
|
return mp_obj_new_float(temp / 4);
|
||||||
#else
|
#else
|
||||||
return mp_obj_new_int(temp / 4);
|
return mp_obj_new_int(temp / 4);
|
||||||
|
|
Loading…
Reference in New Issue