-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gen_mpy.py small issues and potential fixes #279
Comments
Hi @chunis thank you for these suggestions! I'm glad to hear that you find gen_mpy.py useful.
Both your suggestions about
That's correct. Could you explain the use case for a struct that appears in the API but is never "used" in any function?
Until now I only tested v1.20 with LVGL API and it works there (you can see the unix tests are passing), but of course there could be issues with other headers. Could you show a short reproducible example of an H file that causes this? |
Hi, @amirgon Thanks for your quick response, and glad my fixes are useful. The library I work on is the SX128x driver: https://github.com/Lora-net/SWSD001/tree/master/lora_basics_modem/lora_basics_modem/smtc_modem_core/radio_drivers/sx128x_driver. The problem for the 3rd item is as below code shows: typedef struct sx128x_pkt_status_gfsk_flrc_ble_s
{
int8_t rssi; //!< FSK/FLRC/BLE packet RSSI (dBm)
sx128x_pkt_status_errors_t errors; //!< FSK/FLRC/BLE packet error bit mask
sx128x_pkt_status_t status; //!< FSK/FLRC/BLE packet status bit mask
sx128x_pkt_status_sync_t sync; //!< FSK/FLRC/BLE packet sync bit mask
} sx128x_pkt_status_gfsk_flrc_ble_t;
typedef sx128x_pkt_status_gfsk_flrc_ble_t sx128x_pkt_status_gfsk_t;
typedef sx128x_pkt_status_gfsk_flrc_ble_t sx128x_pkt_status_flrc_t;
typedef sx128x_pkt_status_gfsk_flrc_ble_t sx128x_pkt_status_ble_t;
sx128x_status_t sx128x_get_gfsk_pkt_status( const void* context, sx128x_pkt_status_gfsk_t* pkt_status );
sx128x_status_t sx128x_get_flrc_pkt_status( const void* context, sx128x_pkt_status_flrc_t* pkt_status );
sx128x_status_t sx128x_get_ble_pkt_status( const void* context, sx128x_pkt_status_ble_t* pkt_status ); The API doesn't use the struct I understand that unused struct should be ignored; but looks like the typedef is not handled correctly for this case. For the v1.20 compile issue:
This seems happen with the enum type. I can reproduce it with below files (all files put under folder
typedef enum sx128x_status_e
{
SX128X_STATUS_OK = 0,
SX128X_STATUS_UNSUPPORTED_FEATURE,
SX128X_STATUS_UNKNOWN_VALUE,
SX128X_STATUS_ERROR,
} sx128x_status_t;
sx128x_status_t sx128x_wakeup( const void* context );
#include "sx128x.h"
sx128x_status_t sx128x_wakeup( const void* context )
{
return SX128X_STATUS_OK;
}
EXAMPLE_MOD_DIR := $(USERMOD_DIR)
SRC_USERMOD += $(EXAMPLE_MOD_DIR)/sx128x.c
SRC_USERMOD += $(EXAMPLE_MOD_DIR)/sx128x_wrapper.c
CFLAGS_USERMOD += -I$(EXAMPLE_MOD_DIR)
CEXAMPLE_MOD_DIR := $(USERMOD_DIR) Produce the C code with command: ./gen_mpy-v1.20.py -M sx1280 sx128x.h > sx128x_wrapper.c Then go to folder make USER_C_MODULES=../../lora will produce error as:
|
Right. If a struct is used indirectly through typedef, it should be generated.
Thank you for the example. I will look into it. |
@amirgon I checked the latest script (merged from branch v1.20), and the enum type compatibility issue disappeared, and the compile process goes all right. Thanks. |
Thanks for the great work. I'm using the gen_mpy.py script and it works amazing!
Still I think I found a few small issues, and figured out some workarounds but I'm not sure they're the right solution, as below.
1. bool type support seems don't work
Given below head file:
The produced code shows:
For workaround, I added the map to the dictionaries as:
2. uint32_t overflow
I've a function for setting frequency has a argument with type uint32_t. When I pass it with 2400000000, it fails with "OverflowError: overflow converting long int to machine word".
The value is 0x8f0d1800, I guess it is converted to int32_t first by (uint32_t)mp_obj_get_int, and causes this overflow. It's too late to convert it back to uint32_t later.
My solution:
3. typedef issue
Given below code:
The produced code won't contain the definition of my_info, unless un-comment the do_nothing( ) line.
My understanding is: unless my_info is used in function declaration, it will be ignored, even it's been used as the source of typedef.
This doesn't feel right to me, but I don't know how to fix it besides of the extra do_nothing() declaration or define struct info_x and struct info_y directly.
4. v1.20 compile issue
I also checked the v1.20 branch, but the script produced code compiled giving below error:
The text was updated successfully, but these errors were encountered: