build library error conversion double to float

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
P@T
Posts: 33
Joined: Tue Nov 06, 2018 2:37 pm

build library error conversion double to float

Post by P@T » Fri Dec 31, 2021 5:45 pm

Hello,
I have built a port for my STM32L496 and I would like to include this library:
https://github.com/russhughes/st7789_mpy

I followed the instructions but I don't understand how the link between the port and the library.

I have :

Code: Select all

ls /Documents
micropython st7789_mpy

Code: Select all

cd /Documents/st7789_mpy
make USER_C_MODULES=../../../../st7789_mpy/st7789/micropython.cmake ... ok
For my port :

Code: Select all

cd /Documents/micropython
make -C mpy-cross .... ok

Code: Select all

cd /Documents/micropython/port/stm32
make BOARD=STM32L496G-DISC submodules ... ok
make BOARD=STM32L496G-DISC deploy-stlink ... ok
At which step I have to include the st7789 library?
I don't understand the process
Happy New year !!!
Update

Now i have an error of build

Code: Select all

/home/pat/Documents/st7789_mpy/st7789/st7789.c: In function 'RotatePolygon':
/home/pat/Documents/st7789_mpy/st7789/st7789.c:1687:24: error: conversion from 'double' to 'mp_float_t' {aka 'float'} may change value [-Werror=float-conversion]
 1687 |  mp_float_t cosAngle = cos(angle);
      |                        ^~~
/home/pat/Documents/st7789_mpy/st7789/st7789.c:1688:24: error: conversion from 'double' to 'mp_float_t' {aka 'float'} may change value [-Werror=float-conversion]
 1688 |  mp_float_t sinAngle = sin(angle);
      |                        ^~~
cc1: all warnings being treated as errors
make: *** [../../py/mkrules.mk:77: build-STM32L496GDISC/st7789/st7789.o] Error 1
Why math.cos(90) return "double" ?

Thank you

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: build library error conversion double to float

Post by russ_h » Sat Jan 01, 2022 5:30 pm

The math library uses doubles for sin and cos. I'll see what I can do to fix this, until then, you can get around the error by changing sin and cos to sinf and cosf if they are supported. Failing that you should be able to cast the results of sin and cos to floats.

Code: Select all

mp_float_t cosAngle = cosf(angle);
mp_float_t sinAngle = sinf(angle);
or possibly:

Code: Select all

mp_float_t cosAngle = (mp_float_t) cos(angle);
mp_float_t sinAngle = (mp_float_t) sin(angle);
Russ

P@T
Posts: 33
Joined: Tue Nov 06, 2018 2:37 pm

Re: build library error conversion double to float

Post by P@T » Wed Jan 05, 2022 9:57 am

Hi,

I have modified :

Code: Select all

mp_float_t cosAngle = cosf(angle);
mp_float_t sinAngle = sinf(angle);
perfect ! It's works

Post Reply