int wiringPiSPISetupMode (int channel, int speed, int mode)
{
int fd ;
mode &= 3 ;// Mode is 0, 1, 2 or 3
channel &= 1 ;// Channel is 0 or 1
if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR))
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
spiSpeeds [channel] = speed ;
spiFds [channel] = fd ;
// Set SPI parameters.
if (ioctl (fd, SPI_IOC_WR_MODE, &mode)
return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW)
return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;
if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed)
return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;
return fd ;
}How to install wiringPi
=======================
The easiest way is to use the supplied 'build' script:
./build
that should do a complete install or upgrade of wiringPi for you.
That will install a dynamic library.
cd wiringPi
make static
sudo make install-static
To un-install wiringPi:
./build uninstall
静态库的连接用法的确是 gcc -L libpath -llibname