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:
Damien George 2018-07-19 10:34:33 +10:00
parent 9addc38af4
commit 6ac4304284
3 changed files with 9 additions and 9 deletions

View File

@ -605,9 +605,9 @@ microbit_image_obj_t *microbit_image_for_char(char c) {
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) {
#else // MICROPY_FLOAT_IMPL_NONE
#else
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t fval) {
#endif
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));
for (int x = 0; x < imageWidth(lhs); ++x) {
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);
#else // MICROPY_FLOAT_IMPL_NONE
#else
int val = min((int)imageGetPixelValue(lhs, x,y)*fval, MAX_BRIGHTNESS);
#endif
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:
break;
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));
#else
return microbit_image_dim(lhs, mp_obj_get_int(rhs_in) * 10);
#endif
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));
#else
break;

View File

@ -89,7 +89,7 @@ extern const mp_obj_type_t microbit_image_type;
#define HEART_IMAGE (microbit_image_obj_t *)(&microbit_const_image_heart_obj)
#define HAPPY_IMAGE (microbit_image_obj_t *)(&microbit_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);
#else
microbit_image_obj_t *microbit_image_dim(microbit_image_obj_t *lhs, mp_int_t val);

View File

@ -45,7 +45,7 @@ STATIC mp_obj_t microbit_sleep(mp_obj_t ms_in) {
mp_int_t ms = 0;
if (mp_obj_is_integer(ms_in)) {
ms = mp_obj_get_int(ms_in);
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
#if MICROPY_PY_BUILTINS_FLOAT
} else {
ms = (mp_int_t)mp_obj_get_float(ms_in);
#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) {
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);
#else
return mp_obj_new_int(temp / 4);