Custom user C module can not import on rpi (LCD driver) #17530
Unanswered
boognevatz
asked this question in
Libraries & Drivers
Replies: 1 comment
-
Your "lcd" module needs to be written in a special structure and registered with the firmware. Here is a minimum example: #include "py/obj.h"
#include "py/runtime.h"
// Function to return a constant
STATIC mp_obj_t mymod_hello(void) {
return mp_obj_new_str("Hello from C!", 14);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mymod_hello_obj, mymod_hello);
// Module globals
STATIC const mp_rom_map_elem_t mymod_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_hello), MP_ROM_PTR(&mymod_hello_obj) },
};
STATIC MP_DEFINE_CONST_DICT(mymod_module_globals, mymod_globals_table);
// Module definition
const mp_obj_module_t mymod_user_cmodule = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mymod_module_globals,
};
// Register the module to make it available in Python
MP_REGISTER_MODULE(MP_QSTR_mymod, mymod_user_cmodule); Here, we register the module "mymod," which has one function, "hello." We can then do the following in a MicroPython script: from mymod import hello
print(hello()) # Output: Hello from C! So, you need to wrap all your "lcd" functions, register them in the module globals table, and register "lcd" as a module, as shown in the simple example above. I don't see a structure like that in your "LCD_2in.c" file. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a Waveshare LCD 2" rp2350 board:
https://www.waveshare.com/wiki/RP2350-Touch-LCD-2
Features:
There is an example C code on their wiki:
https://files.waveshare.com/wiki/RP2350-Touch-LCD-2/RP2350-Touch-LCD-2.zip
I managed to compile the UF2 file. What it does is display the camera image on the LCD in real time.
I want to port the LCD driver from this example project.
I uploaded my code to this github repo:
https://github.com/boognevatz/lcd_2in
It compiles without error, along with the official two "cexample" and "cppexample" modules.
On the target device (the uf2 boots) there I can issue:
And it works. However
import lcd
does not work.Here is the modules list:
Also here is the
micropython.cmake
file:This is the command line option I built with:
The custom board definition is here:
https://github.com/boognevatz/micropython/tree/rp2350_touch_boot_failure/ports/rp2/boards/RP2350_TOUCH_LCD_2
Also I needed to add a file under pico-sdk too:
The general project structure:
These are the directories I modified. My module what I want to build is
modules/lcd
directory.It compiles without error. I can see compiled .o files under:
directory.
However the
.module
files are missing undermicropython/ports/rp2/build-RP2350_TOUCH_LCD_2/genhdr/module
directory.What am I missing? Any help is greatly appreciated.
I attached the buildlog, and also the resulted .uf2 file.
buildlog.txt
firmware.uf2.zip
Beta Was this translation helpful? Give feedback.
All reactions