Skip to content
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

[NOT AN ISSUE] How to convert this to a micropython module? #1

Open
athusrv opened this issue Sep 10, 2020 · 6 comments
Open

[NOT AN ISSUE] How to convert this to a micropython module? #1

athusrv opened this issue Sep 10, 2020 · 6 comments

Comments

@athusrv
Copy link

athusrv commented Sep 10, 2020

First of all, thanks for your code. It's been hard to find some code over the internet that can generate QR codes.

I'm new to micropython and I don't know how to turn this into a micropython module. Could you please update your README with that instructions or maybe give me some idea on how I can achieve that?

Thank you!

@pkdhital
Copy link

pkdhital commented Feb 9, 2021

Hi athusrv,
use link below to understand how to add user c module right into micropython binary
https://docs.micropython.org/en/latest/develop/cmodules.html

After that clone this repo on your c module directory and add micropython.mk file inside mpy-qr folder with following content:
UQR_MOD_DIR := $(USERMOD_DIR) SRC_USERMOD += $(addprefix $(UQR_MOD_DIR)/, \ moduqr.c \ ) CFLAGS_USERMOD += -I$(UQR_MOD_DIR) -DMODULE_UQR_ENABLED=1

after that follow micropython docs to build and and flash custom build.

Note: you might get compilation error about re-declared variables. Just find those variables in code and replace them with something else.

@doc-hex
Copy link
Contributor

doc-hex commented Feb 9, 2021

I think the above still works, but just now I've pushed some changes that include a micropython.mk which is what you need to just "drop in" this code as a USER_C_MODULES of your mpy build.

@bmsleight
Copy link

Hi - I am getting an error - any clues on what I am doing wrong ?

/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: /tmp/ccE9bnqF.ltrans1.ltrans.o: in function rendered_qr_del.lto_priv.585': /tmp/wasp-os/wasp/modules/mpy-qr/moduqr.c:272: undefined reference to free'
/usr/lib/gcc/arm-none-eabi/8.3.1/../../../arm-none-eabi/bin/ld: /tmp/ccE9bnqF.ltrans1.ltrans.o: in function rendered_qr_make_new.lto_priv.581': /tmp/wasp-os/wasp/modules/mpy-qr/moduqr.c:155: undefined reference to malloc'

Full build at - https://pastebin.pl/view/raw/a6a02df3

Trying to build as part of https://github.com/daniel-thompson/wasp-os.git

@petrkr
Copy link
Contributor

petrkr commented Dec 28, 2021

Confirmed it works with 1.13 source base.
But for 1.17 they changed those makefiles to Cmake. So I think it need some changes for that. If you know out-of-box how, it would be easier than again developing wheel.

@petrkr
Copy link
Contributor

petrkr commented Dec 28, 2021

Well it was not so hard...

Test build based on revision 81f706aee

http://iot.petrkr.net/olab/micropython-1.17-octopus-uqr-20211228.bin

@Carglglz
Copy link
Contributor

Carglglz commented Jan 3, 2022

Hi, I've tried to build this for stm32 and nrf port but I was getting same undefined reference error as @bmsleight.
After digging a bit in micropython py/malloc.c it turns out that free and malloc are undefined and replaced by m_free and m_malloc. https://github.com/micropython/micropython/blob/8af9dbbde1fca07371aa13a8276c8e764edac28c/py/malloc.c#L56
So after replacing free and malloc both stm32 and nrf ports builds work. I've done a bit of testing and so far module uqr works great in both. I've not tried to build esp32 port with these changes but I expect it to work too. I will test it ASAP and confirm. 👍🏼
Here is the PR: #3

[UPDATE]:
Just tested esp32 port and it works too. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants