But the http://elinux.org/RPi_Low-level_peripherals describes what kind of support for GPIO is in the kernel. This text also mentions the Arduino style of accessing pins over I2C and SPI networks.
In the schematics I posted you may notice the texts WiringPi XX. These numbers are the Arduino-style pins recognized automatically by the wiringPi libraries. There is also C-libraries that support pin numbering directly over SPI devices.
The benefit with SPI or I2C chips is that they support internal pullups, mode change to inputs or outputs and interrupts.
The multiplexing approach requires constant polling of the data which is not currently in the mainstream of Raspberry Pi. So I am afraid that there would be poor software support and we would have to maintain more code if we take the latch approach. And I am a bit lazy...
But if someone has started to support libraries using latch techniques I have nothing against this approach either.
Here is a small snippet of the SPI approach. This is a very straight forward way to deal with extended I/O. And there is very little code to maintain. I could have used the individual I/O pin approach here that might have been easier to read. But now I decided to write the code using byte reads for faster speed. So there exists also a pin-by-pin API. As well as python APIs if you don't like C.
Python is a good choice for sending OSC messages to QLC+ as there is a generic OSC library available.
Code: Select all
void spiSetup (int speed)
{
if ((myFd = wiringPiSPISetup (SPI_CHAN, speed)) < 0)
{
fprintf (stderr, "Can't open the SPI bus: %s\n", strerror (errno)) ;
exit (EXIT_FAILURE) ;
}
}
// Write a byte to the SPI I/O pins
void writereg(int chip, int reg, unsigned char data)
{
unsigned char buf[3];
int status;
int i;
buf[0] = (0x40 | (chip << 1)) & 0xff;
buf[1] = reg & 0xff;
buf[2] = data;
status = wiringPiSPIDataRW(0, buf, 3);
}
// Read a byte from the SPI I/O pins
unsigned char readreg(int chip, int reg)
{
unsigned char buf[3];
int status;
buf[0] = (0x41 | (chip << 1)) & 0xff;
buf[1] = reg & 0xff;
buf[2] = 0;
status = wiringPiSPIDataRW(0, buf, 3);
return buf[2];
}
void setDataInputs()
{
writereg(0, 0, 0xff); // IODIRA all bits as inputs
writereg(0, 6, 0xff); // IODIRA set pullups active
}