Closed knieriem closed 1 year ago
The mapping is intentionally a private variable. Duplicate it, and chose the right table based on the CPU. Better than trying to make one table address both configurations.
Something like:
var mapping = [][6]pin.Func
var mapping2835 = [...][6]pin.Func{...}
var mapping2711 = [...][6]pin.Func{...}
if isRPi4 {
mapping = mapping2711
} else {
mapping = mapping2835
}
It's just simpler for everyone IMO.
Thanks for suggesting to create a second table. I have tried to implement that approach in the commit linked above. If appropriate, I will create a pull request from it. The new mapping2711 table has been generated from the specification using scripts from knieriem/bcm2711-alt-funcs-gen.
Please send as a PR, it's hard for me to visualize the end result. Thanks.
In an RPi 4 project I needed to switch pin functions of GPIO4/5 at runtime between the Input function and the ALT4 alternate function TXD3/RXD3.
While
rpi
andbcm283x
packages mostly appear to work fine on an RPi 4 regarding GPIO functionality, the RPi 4, which is based on the bcm2711, provides quite some more alternate functions that are not covered by the mapping table in bcm283x/gpio.c.As a workaround, I simply added entries for UART3_TX and UART3_RX to that table:
What would be an appropriate way to add the more extensive settings for the bcm2711? Alternate function tables of bcm2835 and bcm2711 suggest that the bcm2711 is mostly compatible, an extension, to the bcm2835 in this regard. So the
mapping
table could just be extended to contain the additional functions of the bcm2711. The problem with this approach is that the table then would be misleading for users of RPis smaller than 4, as it would contain alternate functions that are not available on the bcm2835. Code callingrpi.P1_7.(pin.PinFunc).SetFunc("UART_TX")
would not work as expected when running it on an RPi 3.Perhaps an approach could be to extend mapping table entries by a prefix, like in the following example:
... with prefixes
bcm2711:
or+
meaning available only on the bcm2711 resp. extended MCUs. Depending on a packagebcm283x
global variable, configured duringhost.Init()
, the additional alt functions then would be available, or not. (Additional code would be needed to strip the prefix withinbcm283x/gpio.go
where needed)Do you see another approach that you would prefer?