Omega2S+ gpiomux embedded C control
I am working on a project with the Onion Omega2S+ that requires the use of pin 33 (GPIO 6/SPI_CS1) to be used as a GPIO. However, the gpiomux default is to use the pin as SPI_CS1.
The overall goal is to be able to persistently use that pin as a GPIO, even after reboot. Additionally, I will be triggering the GPIO toggling through an embedded C program with the sysfs system. I have two possible solution paths that I've thought of, but don't know if possible to implement:
Ideal solution—Is it possible to accomplish the
omega2-ctrl gpiomux set spi_cs1 gpiocommand in a C program? Would a
system()call work (something like
system(omega2-ctrl gpiomux set spi_cs1 gpio))? Is that the best way to accomplish it?
Secondary solution—If the above isn't possible, can I have the gpiomux command at least save my non-default setup so that it persists on reboot?
crispyoz last edited by
@teddylambert I am no expert on this, but if you check out the DTSi files in the build source and perhaps search the forums, I think you can default the pin registers using this method.
luz last edited by
Ideal solution—Is it possible to accomplish the omega2-ctrl gpiomux set spi_cs1 gpio command in a C program?
What it does is setting and clearing bits in the
GPIO2_MODEregisters of the MT7688 SoC (see MT7688 Datasheet page 61ff).
These registers are at 0x10000060 and 0x10000064 in the physical address space - so to access these from user space (any regular program runs in user space),
omega2-ctrlneeds to map that part of physical addresses into user space.
gpiomux.cmaps 0x10000000..0x100003FF into the
gpio_mmap_regpointer, using the linux
mmapfunction. After that, SoC registers can be accessed via that pointer (i.e.
Would a system() call work (something like system(omega2-ctrl gpiomux set spi_cs1 gpio))? Is that the best way to accomplish it?
systemworks too, and is much less code. So that might be the best way in your case
However, I mentioned all of the above because via
mmapyou could access all SoC registers, and do many more things (superpower, be careful!) not exposed by omega2-ctrl.
Another reason to directly access SoC registers and bypass all Linux tools would be speed -
system()is orders of magnitude slower (several milliseconds) because it involves forking a shell which in turn forks omega2-ctrl. That's fine for a one-time setup operation, but sometimes one needs nanosecond order speed, which is what
mmap-ed direct access to SoC registers can deliver.