lvgl / lv_binding_micropython

LVGL binding for MicroPython
MIT License
237 stars 156 forks source link

Question with gen_mpy #250

Closed kdschlosser closed 1 year ago

kdschlosser commented 1 year ago

I am wanting to have the esp_lcd component added to the espidf module that gets created for micropython. I have gotten the component added to the build and I added the includes into the esp_idf.h file so the code will be generated. I am running into an issue with the output C code from gen_mpy.

There is a lot of this seen in the generated lv_espidf.c file

/*
 * Function NOT generated:
 * Missing 'user_data' as a field of the first parameter of the callback function 'esp_lcd_panel_t_reset_callback'
 * esp_err_t (*reset)(esp_lcd_panel_t *panel)
 */

/*
 * Function NOT generated:
 * Missing 'user_data' as a field of the first parameter of the callback function 'esp_lcd_panel_t_init_callback'
 * esp_err_t (*init)(esp_lcd_panel_t *panel)
 */

/*
 * Function NOT generated:
 * Missing 'user_data' as a field of the first parameter of the callback function 'esp_lcd_panel_t_del_callback'
 * esp_err_t (*del)(esp_lcd_panel_t *panel)
 */

and I am getting this as a compilation error

lv_espidf.c: In function 'mp_esp_lcd_panel_io_t_attr':
lv_espidf.c:9738:92: error: 'struct esp_lcd_panel_io_t' has no member named '_del'; did you mean 'del'?
             case MP_QSTR__del: dest[0] = mp_lv_funcptr(&mp_funcptr_del_mpobj, (void*)data->_del, NULL ,MP_QSTR_esp_lcd_panel_io_t__del, NULL); break; // converting from callback esp_err_t (*)(esp_lcd_panel_io_t *io);
                                                                                            ^~~~
                                                                                            del
lv_espidf.c:9750:42: error: 'struct esp_lcd_panel_io_t' has no member named '_del'; did you mean 'del'?
                 case MP_QSTR__del: data->_del = (void*)mp_lv_callback(dest[1], NULL ,MP_QSTR_esp_lcd_panel_io_t__del, NULL); break; // converting to callback esp_err_t (*)(esp_lcd_panel_io_t *io);
                                          ^~~~
                                          del
lv_espidf.c: In function 'mp_esp_lcd_panel_t_attr':
lv_espidf.c:10134:94: error: 'struct esp_lcd_panel_t' has no member named '_del'; did you mean 'del'?
             case MP_QSTR__del: dest[0] = mp_lv_funcptr(&mp_funcptr_reset_mpobj, (void*)data->_del, NULL ,MP_QSTR_esp_lcd_panel_t__del, NULL); break; // converting from callback esp_err_t (*)(esp_lcd_panel_t *panel);
                                                                                              ^~~~
                                                                                              del
lv_espidf.c:10151:42: error: 'struct esp_lcd_panel_t' has no member named '_del'; did you mean 'del'?
                 case MP_QSTR__del: data->_del = (void*)mp_lv_callback(dest[1], NULL ,MP_QSTR_esp_lcd_panel_t__del, NULL); break; // converting to callback esp_err_t (*)(esp_lcd_panel_t *panel);
                                          ^~~~
                                          del

I have attached the generated lv_espidf.c file so it can be looked at of needed. I am thinking that there is improper handling of "del" being used as a field name in a struct and I am not sure why there is a requirement for a field name of user_data to be in the structure for the first parameter of a callback

I am using idf version 4.4

I can fix the del issue pretty easily by writing a script to handle changing the del field names in the generated functions and add that script to be executed by make. The functions that are not getting generated is beyond my knowledge on how to fix and a point in the direction needed to fix it would be a HUGE help.

Thanks --Kevin

amirgon commented 1 year ago

Hi @kdschlosser ,

The Micropython Binding Script was created to automatically generate Micropython API from LVGL C API. As such, it expects from the C API certain structure and assumes it follows certain conventions. You can use the Micropython Binding Script to generate Micropython API for additional functions and libraries other than LVGL, but this needs to be done with care.
For example, we use it to provide Micropython API for parts of the ESP-IDF, and some other libraries.

Please read the documentation for all the details. Specifically the explanation about Callback Conventions.

In your case, your component does not follow these conventions. You can consider wrapping it with a thin API layer that does follow the conventions, and let the script process that layer instead.