-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add build flags for global i2c & SPI pins #2955
Conversation
Could it be that this already exists? |
No, these are just helpers that always have the HW default pin per board. Each board can have different HW pins and also different const defined in the Arduino lib. Hence WLED uses these HW_* to access the default HW pin for SPI/i2c, regardless of the board it's compiled for. Those are not even considered for these new global / usermod i2c/SPI pins, not sure why though... Maybe a better change would be instead of new pins (what I did) initialize these usermod i2c/SPI pins with these HW_* const, instead of -1 🤔 Let's see what maintainers say! |
Actually no... I don't want to set the default HW pin; I want to set the usermod i2c pin specifically... Still, maybe a change would be;
|
@softhack007 this actually aligns with what @ewoudwijma wanted to do with #2931. |
I fully agree. Still i'm not sure if a second There is only two I2C hardware units available, and only one can be used when doing a So my suggestion would be to avoid new preprocessor defines like |
I agree - this is problematic when you want to make a build that runs "out of the box" and utilizes all features of a specific board instantly. Another proposal could be to have one new define like |
This is very much the same thing. On ESP32, you can choose any GPIO as I2C pins, at the same time you only have one Wire and one Wire1 globally. So when one usermod chooses 40/41 for SCL/SDA, then all other usermods have to follow (if you want to run more than one usermod). Only exception is 4LD, which also offers "software i2C". But "software i2C" is a different beast and it causes lots of other trouble... |
When you put it that way it makes sense. 👍 |
I already had a bigger response typed, but realised I may not have all the understandings. So I actually first want to ask a few questions, maybe I have a misunderstanding here (for less confusion, let's only focus on i2c):
Because what I wanted to say (which I deleted because I'm not sure if I have the correct understanding), is that I think the purpose of the One comment though on this:
That's not true, I believe. I have been using Wire1 in a mod right now, while everything else uses Wire, because at the time I wrote it, I wasn't too experienced with i2c and didn't want to interfere with the other bus, hence I used Wire1. What do you mean with "all other have to follow"? Thanks already! |
You are correct, this area is still very much WIP.
You are correct with your thinking. |
Thanks for the answers, Blaz! Sooo, elaborating on your reply earlier:
Did you mean this / my current approach here? Or my suggestion to also initialize them with the HW_* macros? Or were you referencing the other issue you linked? 🙈 I got confused, sorry :D
With "added to built in platformio.ini" you mean you won't provide a build config in platform.io using them? That's totally fine; We provide our own builds / pre-flash controllers with these. It's just that we can build such a build (haha) and have factory pre-flash it to the controllers.
Totally makes sense, yeah. Thanks again! |
Yes, introducing new set of #defines for setting
Yes, exactly that. I would encourage you (or @intermittech) and @ewoudwijma (or @srg74) to provide |
@softhack007 and I worked together on the same topic, analysis can be found in #2931 What we did at least partly is overlapping with your ideas Very beta coding can be found here: @ezcGman , if you want you can give it a try with this bin: To see what we did best is to look at the commit diffs |
@ewoudwijma I think what you guys do there is on a whole other level / does more than I wanted to achieve with this tiny PR. So whatever you do there might (if my PR gets merged) overwrite what I did here ;) I was actually just looking for a way to set these pins via build flags, similar to how WLED does it for all the other pins (Relay, IR, buttons, LED outs...) :) So I'm still hoping to get this change merged, if it's acceptable / doesn't cause issues and I bet what you are doing there might overwrite what I did here, as you spent way more thought into this than I did ;) |
One point is still not clear for me. The problem is, it will not work properly when I2CSCLPIN and HW_PIN_SCL have different values. I have explained before, so I'm not gonna repeat myself about that. All you want can be achieved with setting HW_PIN_SCL, and then adding one new flag like INIT_I2C_AT_STARTUP that can be used to request initialization of global i2c_sda with HW_PIN_SCL, instead of initializing with -1 (and other i2c and spi pins alike). |
These are not the same. One assigns global
This very much depends on the implementation of software I2C driver. I am not saying we want to use it as such, but someone might.
I do not like this idea as it is counter intuitive compared to initialisation of other GPIOs like relay, button, etc. I would rather dump HW_PIN_SDA & HW_PIN_SCL as these are informational (and always were as such). More like helpers for usermod to decide if it uses SW or HW driver. |
Because they're not the same thing, see my detail questions and Blaz' answers above:
Thanks for not providing clarity on what you mean, if it seems to be unclear to people. I don't see an issue why this wouldn't work. |
This is what is confusing for me, build flags are normally initializing values, also for relay, button etc. Why shouldn't hw_pin values work similar. I don't see a point in making them informational only. |
I suggest that we go back to the start and re-define everything and build from there.
From this we may get:
All points, except 2. & (partially) 4., have been implemented in current version and this PR adds support for 2. as I see it. I propose to merge this PR and after that we only need to work on 4. (audio_source.h may need update to use Wire1 for the special microphone). |
I am afraid this ignores some of the things I and @softhack007 are currently working on. This introduces new build flags while we have already HW_PIN * flags (and FLD_PIN flags for FLD). I think we need to use the HW_PIN flags to implement what Is done in this PR (or rename them to I2CSDAPIN etc) but not have both. This as been worked on (and is WIP) as described in #2931. So I think we wait on advice of @softhack007 on this matter |
Hi @blazoncek, @ezcGman and @ewoudwijma, First I'd like to apologize, as my words seemed to cause frustration and I had the feeling of not being listened to at all. Current there is ongoing work to improve handling of I2C busses (and possibly SPI, too) which will be relevant for a future release of WLED, like 0.14.1. From this perspective, it is important to make good decisions already now, because everything that will be put into users hands today will become "the legacy" in 14.1 and we'll have to live with that once users made use of it. personally I am mainly working on the "low level" part of improved I2C support, while leaving it to @ewoudwijma and @blazoncek to find a good UI integration that is consistent with the overall concepts in WLED. There are some aspects where I fully agree with what was said before:
The ESP32 hardware is a bit tricky, because in reality there is no "Hardware (accelerated) I2C PIN" as you would have on other arduino environment. It works completely the other way. There are two I2C units on the chip, and you have "Wire" and "Wire1" respectively. Wire.begin(pin_sda, pin_scl) assigns GPIO pins to the first HW I2C unit, and likewise does Wire1.begin(...) for the second unit. Different to other arduino environments, Wire.begin() without parameter is not a good idea, and WLED 0.14 already has a way to prevent this. And it works basically, when you only have one I2C device you want to use. For more than one device, we need architecture changes for 0.14.1. When a usermod calls Wire.begin() without parameters, this means that - silently - the values from pins_arduino.h will be used as GPIO, no matter what is in HW_PIN_SDA etc - not really good from my POV. The other important point is, once that i2C pins were set during the very first Wire.begin(pin_sda, pin_scl), these pins become "the hardware pins". A reboot is needed to set other gpio. This brings me to the problem i see currently, when allowing users to independently define I2CSCLPIN and HW_PIN_SCL:
I hope this helps to understand my concerns. To say it again - I fully agree on the needs to have a way for users to define "preferred I2C pins" of their special board/shield. I am just saying that having both I2CSCLPIN and HW_PIN_SCL (that both can be set within build_flags) is not making much sense technically - it could lead to confusion, and might makes our life harder once we impement improvements for 0.14.1. What do you think? |
Both of you are still missing the point of this PR. From my perspective it is clear and approved. Please re-read my post above. Still if you want: This PR, combined with existing code in WLED (cfg.cpp, lines 294-322; set.cpp, lines 507-560) satisfies all needs for initialising I2C and SPI buses/interfaces. Once the variables What is needed is to modify existing usermods to heed these settings and notify them if pins change from set.cpp (may need a reboot, I understand this). Nothing more! If you and @ewoudwijma still cannot wrap your heads around HW_PIN_SDA or HW_PIN_SCL take another look at const.h, lines 395-433, where their definition is set. They are nothing more than constants with references to platform dependant or user specified values. Their purpose is to let any code identify if For clearer picture consider this: if (i2c_sda == HW_PIN_SDA) {
// we have SDA pin that corresponds to what is used in hardware/controller board
...
} else {
// warn user that setup is not according to his/her hardware
...
} @softhack007 you are comparing apples to oranges when you talk about IRPIN, etc. and HW_PIN_SDA/HW_PIN_SCL. IRPIN corresponds to I2CSCLPIN/I2CSDAPIN from this PR. HW_PIN_SDA/HW_PIN_SCL have to do with controller board design (like Dig-Octa or Wemos Shield) or hardware wiring so that any code may be aware of that. HW_PIN_... have nothing to do either with I2C interface or variable initialisation. They never did. If you still think this is confusing I may remove all references to HW_PIN_... and replace visual cue in xml.cpp, lines 700-704, with I2CSDAPIN, etc. The problem with this approach is that you will not be able to have "help for the user" when he/she later adds I2C sensor but has a binary that does not define |
Hi @blazoncek If you still think I'm talking gibberish and I don't know what I'm saying, then maybe we have a bigger problem It seems my opinion is to "brainy" or something, so I'll shut up for now and will stop making life miserable by comparing apples to oranges. Proceed as you prefer. I'll concentrate on MoonModules, as I don't want to get anybody into a situation where they fear of losing their faces, just because I dared to challenge their design choices. If you want, contact me on discord. Finito. |
Just in case anybody here was concerned about yesterday's disussion - all good. @blazoncek and myself agreed on a compromise that allows to merge this PR without possible problems later, and comments will be added to explain the purpose of new build flags. So approved from my side 👍 |
Thanks guys! And I feel a little bad for kicking off this heated discussion here <3 |
Don't worry. From my perspective this discussion was due any way, so you just gave a spark, but any other "spark" could have caused the same. What's important is that we were able to find a good way forward. |
I looked at latest dev: Is it correct HW_PIN_SCL should now only providing info ? If so, I see in code it is used to provide values and allocate pins with it. Is this correct? and should I2CSCLPIN be added to platform io entries where now HW_PIN_SCL is used? Same question for HW_PIN_CLOCKSPI and a bunch of other HW_PIN values |
Yes, this is all correct. EDIT: As noted above I2CSDAPIN & co. will not be added to platformio.ini because their purpose is different, as stated above. |
If all my statements are correct then it contradicts with the note you added. There is a lot written above. |
Defining All code should use Some usermods will require updates. |
Hey there,
it's me again! We also don't have enough build flags, do we? :) So please let me add some more!
This PR is to make the new global i2c and SPI pins configurable via build flags. Why would I want that? Because for the QuinLED boards, we compile a build that already has everything set (like LED outputs, relay pin, IR pin, etc.) using build flags. And now in combination with my new SHT usermod (#2942), we can also provide a build with that mod included, but we currently can't set the i2c pins; users would need to do that themselves still.
With this PR, we could pre-configure everything on the boards so boards are even more Plug-n-Play:
We only need the i2c pins, but I thought it would be stupid to not do the same for the SPI pins :)
Thanks for considering this PR and greetings,
Andy!