-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Porting to ESP-IDF with C++ support #789
Comments
U8g2 itself is a pure C library. For Arduino however it calls the C++ Arduino HAL and adds a C++ lib API wrapper. Both, Arduino wrapper and HAL are put together in the same c++/h files. As a consequence: If you want the C++ U8g2 API but not the C++ Arduino HAL, then some code needs to be copied out the existing C++ code. I am not 100%, but I think this has been done by the nodemcu people already: https://nodemcu.readthedocs.io/en/dev-esp32/modules/u8g2/ In general porting instructions are here: https://github.com/olikraus/u8g2/wiki/Porting-to-new-MCU-platform |
Thank you. Now I think about architecture: is it good idea to place ESP32 specific stuff in Also, where can I find pure C exmples? I feel like there is a lack of them. |
I have no idea about this. CMakeLists.txt or component.mk in the u8g2 are part of a pull request. I can not tell you something about these files.
Have a look here: https://github.com/olikraus/u8g2/tree/master/sys Here is a "hello world" example for the STM32L031: Once I created a blog entry also:
I personally feel, that I created more docs and examples than many other Arduino libs... |
Thanks you again and sorry for blaming you about no docs. Your Arduino/C++ reference is just great! I just had some problems about pure C documentation. |
:-) Let me know if I can help you with u8g2 related problems. |
There are no problems with changing those files, just wonder is |
You mean below u8g2? Well sure, it you like to do so and send a corresponding pull request then I can accept this. |
Thank you! Another question: how presice should be all the There are three options: use I suggest using Thanks. |
Ok, I took a look at files.
Where code generator and template files are? It looks like I'll have to add ESP32 support there. My current idea it to leave |
It always can be more than requested, so: It does not need to be precise.
I think the only sensitive message is the I2C delay. But this is only required for software emulated I2C.
You probably do not need to take care on the code generator. "codebuild" only connects the displays with the communication interfaces: It defines which types of interfaces are available for which display. The hardware specific files are either in the sys//common directory or (an exception) for Arduino in the u8g2/cppsrc directory.
Yes please. "csrc" should not contain any hardware specific code. |
Are Arduino display C++ binding auto generated? If yes, because I want to support them on ESP-IDF too, it will require tweaking code generator. Am I right? My goal is to provide C++ bindings compatible with Arduino interface too, because C++ is commonly used on ESP32 too. |
If you mean the constructor classes here, then yes: |
I also want to auto generate bindings for ESP-IDF to make migration/usage as comfortable as possible. Therefore, I have to tweak generator, right? |
Or you create a copy of the codebuild Code and add your modifications there. |
To be fair, current code generator looks like hell for me ☺. I'll look at it when get pure C working. Do you have anything againist re-writing in in something non-C? I'm good (enough to write such thing) with C++ and lua. |
Can you take a look an my test implementation for
Are there any visible flaws? Thanks. |
then, it is better to work on a copy... ;-)
I do not care if you work on your own repo ;-) |
Hmm, seems there is a problem… Arduino introduce global SPI state, but ESP-IDF does not. Doing so would mean big problems with more than displays running in parallel. It would be really nice to have non-interputtable version where SPI state don't have to be stored between calls. Any ideas? Possible solution is to add SPI and I2C states to |
BTW, do you have an IRC/Jabber? It probably would be faster to communicate there (nothing personal, feel free to reject with or without reason). |
Allright, got it! There IS global state on hardware level ( |
Well, just got that I was doing HW SPI all wrong… It's better try to get ESP-IDF driver working and NOT try to adapt one from arduino-esp32. I have some questions now:
|
Yes, it will break the independence from SPI and I2C
No
I2C transfers are limited to 32 bytes. Any other transfers can have any length.
Against what?
U8g2 does not read from displays (but from GPIOs) Just a general notes: I do not have much time to work on U8G2. So I can not do more than give comments on your questions. |
Ok, thank you.
In this case syncronized means no caching in driver, i.e. use polling (write means waiting until transfer is complete) and not interrupt (things goes into queue and are done in background) SPI mode (ESP-IDF specific stuff). P.S.: I was talking about HW SPI transfers, or to be presice |
Also, if adding stuff to |
Hi. My porting is going ok yet. There is a question: can I be sure that memory pointed by |
Yes, sure, that is the purpose of the user ptr
probably not. |
Interesting thing: it's possible to use two displays with all same pins except CS (and DC I think) which is handled by driver (even from two cores)! However, I want to know one thing: is it possible to trace destruction of u8x8? I know that it's rare thing, but it would be nice to delete device in such a case. Thanks. |
And another (more actual) question: can I make few SPI transactions instead of one? |
https://github.com/olikraus/u8g2/wiki/u8g2setupc#max7219-32x8 is a good example. There are also ones which have the same size as full one. Removing eqal ones would work as hint to developer that they can use full mode with same memory usage.
I've already called them somehow, don't remember how exactly. Under args/vars/functions I mean ones in code/docs generation.
Did the same. Turns out I actually removed them at some point of editing reply before posting… I've solved them in temporary way and plan to discuss later when making PR. I also think that generating big portions of constructor references is bad idea especially when there are two different C++ constructors sets. I plan to generate table like this:
This allows having one table for C and both C++ interfaces. As for constructor reference, I want to put it like this:
What do you think about it? I'll continue working in this direction until you answer, so that would be sad if I'll have to throw out just written piece of code :-P |
No doubt, this looks better than the current wiki :-)
ok.... |
Ok, I said it looks better. However i think the constructor name should be mentioned. |
I partially agree with you. At first, constructors creation/docs generation are now united: if there is constructor, there will be docs and vice versa. But you make a good point for
I'll think about it… don't think that listing all constructors like now is required, but giving good examples and description is important. BTW |
Not sure what you mean. In general the generated docs are a little bit less frequently used. Most users just see the constructor list in the examples :-( I really like the effort, you put into this topic. Hope it is worth to do all this. |
u8x8setupc.md contain only generated list and no hints at all.
Thank you! I really want to make ESP-IDF support feel complete: have C++ bindings (done) and nice docs (WIP). To keep thing in one place I do the same to Arduino part obviously (united docs/C++ generator). Hope this will be useful for other ESP-IDF community members too. |
That's some progress on docs: https://github.com/v1993/u8g2/blob/master/tools/newcodebuild/docs/u8g2setupcpp.md. What do you think? NOTE: interface tables are auto-generated. Look at https://github.com/v1993/u8g2/blob/master/tools/newcodebuild/resources/Arduino/interfaces.lua and https://github.com/v1993/u8g2/blob/master/tools/newcodebuild/resources/ESP-32/interfaces.lua to see original data (it is also used for constructor generation). |
Here it is — controller/display interface table: https://github.com/v1993/u8g2/blob/master/tools/newcodebuild/docs/u8x8controllertable.md! |
Looks good. Still a list of all constructors would be good. |
Well, I personally think that list of all C++ constructors is pretty bad idea: having only Arduino one seems kind of unfair to ESP-IDF users and having both would result in giant page. |
Wow! Thanks to table I've just fixed generation for I²C constructors. Turns out it is really helpful tool even for development stage. |
@olikraus I've noticed that U8x8 C++ Setup and U8g2 C++ Setup are extremely close to each other. Do you think that it is good idea to merge them into one file? I'll do so myself. Also, how can I send you non-generated changed/added docs from wiki? |
U8g2 and u8x8 are split to allow projects with pure u8x8 code. What do you mean by send code? My email is mentioned in all c codes. |
I was talking about doc pages there…
Well, I know that. For code part I can make pull request via GitHub, but what about docs? What would be a convinient way to review and merge wiki changes for you? |
@olikraus If it isn't clear, I'm waiting for response. |
@olikraus Umm, sorry to annoy you a bit more again… just saw that you're active in other issues. I'm waiting for your help here too. I'll have less free time in next few weeks, so I would be happy to finish docs as soon as possible (also complete notes while I do remember some details about code) and merge pull request. |
Sorry, as mentioned before, I am away from all kinds of computer hardware. Only mobile phone is there. I will be absent for another 7 days Regarding wiki pull requests. I'd not know how to do this. But: is it required? Docs should be generated and not added via pull requests. |
Yep, but… I'm going to change non-generated docs (and write some new from scratch). What about those? Again, do you thing that it is a good idea to merge u8g2 c++ setup and u8x8 c++ setup because they are very close and basicly dublicate each other in most places? |
I could give you access rights. u8g2 c++ setup and u8x8 c++ setup should be kept separatly. |
Would it be ok to create some docs before pull reuest?
Why? If I was unclear once again, I'm talking about their docs, not headers. I said that in previous reply. |
If someone wants to work with u8x8 only, then why shell that user read about u8g2? I think it is better to have two different setup docs. |
@olikraus Eh, u8g2 setup and u8x8 setup (references) are basicly dublicates (they literally contain tons of eqal text) with very minor changes. Merging them is rather trivial and removes requiment to support two copies of docs. |
@olikraus Oh, and before I forget: ESP-IDF CMakeLists.txt include Do you think that it is a good idea to auto-generate it too? Can I assume any platform (linux/windows/etc.) in such case and for example run |
How can I answer this? |
Why? There is no way merging two docs which repeat each other a lot may hurt development!
Well, it may apply to new codebuild, but not to docs. In fact, lua it rather easy to understand in most casesand I'll be glad to help with it.
So again, what is a problem of merging two pretty much dublicated docs? Also, what about my last reply? You repo contain |
I just think it is better to just get exactly the information which you want to see.
Yes, I do all the development with Linux |
Oh, I see. I'll still try to megre them, but will keep what you said in mind.
Great! Means that I can freely run |
Sure all the usual commands are there... |
@olikraus I can't merge your last changes because of C++ part. Can you, please, tell what was changed in generation mechanism what I have to incorportate? New displays/controllers, different functions, etc.? |
I have added a new display. |
Hello, I'm interested in porting this great library to ESP32 without Arduino compatiblity layer. However, for me it seems that there is a problem with
cppsrc/U8x8lib.cpp
: it use arduino specific stuff.Is it possible to add support for other platform in it or it isn't required for C-side calls implementations and headers will be enough (i. e. not build this file at all)?
Is it doing only low-level stuff which I can do in any plain C file, or some things which are reqired to get C++ working too?
The text was updated successfully, but these errors were encountered: