Closed ewoudwijma closed 1 year ago
Same applies for
(HW_PIN_DATASPI, HW_PIN_MISOSPI, HW_PIN_CLOCKSPI)
They do, as a placeholder (remove -1 or any other input by deleting digits). This is intentional as to not allocate GPIO during boot. HWPIN... macros are just informational which GPIO is reserved (if used) for hardware accelerated IO.
Not a bug but intentional behaviour.
I saw the placeholder functionality. It's info only, not assigned to anything
I would say setting hw_pin_sda/scl (or not setting) determines if gpio should be allocated or not. Might be confusing for end users as build flags normally are shown as default in the ui.
We are currently reviewing the sda/scl functionality. After review will let you know our advice.
I would say setting hw_pin_sda/scl (or not setting) determines if gpio should be allocated or not. Might be confusing for end users as build flags normally are shown as default in the ui.
Well, it is not intended in the way you think. Confusing or not these setting are meant for advanced users who know how are they compiling and for what. If you want to pre-allocate I2C and/or SPI GPIO pins, do so by introducing new compile time options. These may have nothing in common with HWPIN...
We are currently reviewing the sda/scl functionality. After review will let you know our advice.
I wish you luck. I stumbled to a roadblock when trying to use 2 I2C devices on the same HW pins. Looks like a bug in Espressif/Arduino implementation. Since I2C is not used for LEDs and global SPI may conflict if using APS102 they are secondary in priority so I dropped any further development.
Well, it is not intended in the way you think. Confusing or not these setting are meant for advanced users who know how are they compiling and for what.
Is it documented anywhere? Discord links also okay. Any names of advanced users to check ?
Not to criticize your approach but get a general understanding how it is supposed to be used in different scenarios, improve documentation if needed and also test together multiple i2c devices
I2C SPI Scrapbook:
highest level declarations are in pins_arduino.h:
If no HW_PIN values set in platformio and above variables commented out we see where these vars are used due to errors:
SCK and MOSI
NeoPixelBus/src/internal/*DotStarGenericMethod.h (T_TWOWIRE)
NeoPixelBus/src/internal/DotStarEsp32DmaSpiMethod.h
const.h
pinmanager.cpp
.platformio/packages/framework-arduinoespressif32@src-e9b1fbd6563a55e19ddae15e1fc09589/libraries/SPI/src/SPI.cpp
.platformio/packages/framework-arduinoespressif32@src-e9b1fbd6563a55e19ddae15e1fc09589/libraries/Wire/src/Wire.cpp
U8g2/src/U8x8lib.cpp
libraries/SD/src/SD.h
Conclusion from above:
wled.h defines global variables which are used to set and get persistent values
platformio has currently only one entry where standard values for an environment are defined (lolin_s2_mini):
SPI values (HW_PIN_CLOCKSPI, HW_PIN_DATASPI, HW_PIN_MISOSPI) used in usermod_v2_four_line_display_ALT.h in case the global variables are -1
setup()
addToConfig()
readFromConfig()
and used in pin_manager.cpp and xml.cpp for display purposes in set.cpp to overwrite in case of esp8266 (cannot change pins on 8266) but they are also undeffed in const.h for esp8266???
SPI values (HW_PIN_SCL, HW_PIN_SDA) used in above SPI cases in case the global variables are -1
U8X8_PIN_I2C_DATA and U8X8_PIN_I2C_DATA
u8x8.h
U8x8lib.cpp
Conclusions:
Use of FLDPIN* values in usermod_v2_four_line_display_ALT.h setup of ion array using FLDPIN and if -1 use global variables and if they are -1 use HW_PIN values
Conclusion:
... to be continued ...
Search in #dev-general for the "I2C" keyword on Discord. There was no documentation but a lot of discussion. Happened somewhere in September.
The advanced users in question were @softhack007 and @Matoran ( #2740 )
As for documentation: If you want clarifications or complaint about missing information/documentation open different kind of issue. Or ask on Discord.
As noted above the implementation of shareable I2C and SPI failed and since it is not crucial for workings of WLED, further development stopped beyond the entry fields in usermod settings. Which work as intended. As shareable pins are exclusively used by usermods (except SPI which in case of APA102 cannot be shared ATM) it is up to usermods to implement proper use of I2C and SPI buses. They do get the information about which GPIO ports are intended as HW accelerated via global variables. HWPIN... constants are informational and only meant for intended override of platform default values. You do not need to define them to have HW accelerated I2C or SPI.
I do admit that this information (how & why) needs to be added somewhere. Perhaps in WLED-docs by someone that has time and will to do that and has played with usermods that use them.
In current implementation you have global variables i2c_sda
, i2c_scl
, spi_mosi
, spi_miso
and spi_sclk
which are filled at boot with values entered in usermod settings page. Their intention is to represent HW accelerated GPIO pins. If they are set to anything other than -1 the appropriate interface is initialised (assuming no other code did that prior) with Wire.begin()
and SPI.begin()
. In such case pins are also pre-allocated to prevent unintended use in other patrs of WLED. They do not do anything beyond that.
Usermods that use I2C or SPI and use the same GPIO as global pre-allocated ones do not need to call Wire.begin()
or SPI.begin()
as it has been done at the boot time.
Hi, thanks @blazoncek and @ewoudwijma, this explains a lot how WLED behaves today.
Proposal: give me some time to digest & numbercrunch this in my head. I'll need liquid cooling (beer) for this, so can do it on the weekend. Then i'll make a proposal in discord (SR-to-WLED team), about how I2C sharing could/should behave (kind of one-line requirements) including user perspective. We discuss in discord, then I try to improve the current implementation. Agreed?
SPI sharing seems to be a different beast:
So we could first try to improve I2C only, and then see what can be done for SPI.
resolved by #2955
What happened?
Usermod settings do not show values for build flags HW_PIN_SCL and HW_PIN_SDA on new install. Show -1 instead:
To Reproduce Bug
erase flash: pio run --target erase
Set in platformio environment xyz -D HW_PIN_SCL=22 -D HW_PIN_SDA=21
build xyz
go to settings / usermod
Expected Behavior
Install Method
Self-Compiled
What version of WLED?
0.14.0 latest
Which microcontroller/board are you seeing the problem on?
ESP32
Relevant log/trace output
No response
Anything else?
No response
Code of Conduct