Sync with changes from wiringpi_2.50.orig.tar.gz

Sourced from http://archive.ubuntu.com/ubuntu/pool/universe/w/wiringpi/wiringpi_2.50.orig.tar.gz
This commit is contained in:
Steve Baker
2019-12-14 13:42:07 +13:00
parent 093e0a17a4
commit 03204c3807
6 changed files with 37 additions and 21 deletions

View File

@@ -23,7 +23,9 @@
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
@@ -39,8 +41,8 @@
// The SPI bus parameters
// Variables as they need to be passed as pointers later on
static const char *spiDev0 = "/dev/spidev0.0" ;
static const char *spiDev1 = "/dev/spidev0.1" ;
//static const char *spiDev0 = "/dev/spidev0.0" ;
//static const char *spiDev1 = "/dev/spidev0.1" ;
static const uint8_t spiBPW = 8 ;
static const uint16_t spiDelay = 0 ;
@@ -100,11 +102,16 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
int wiringPiSPISetupMode (int channel, int speed, int mode)
{
int fd ;
char spiDev [32] ;
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)) < 0)
// Channel can be anything - lets hope for the best
// channel &= 1 ; // Channel is 0 or 1
snprintf (spiDev, 31, "/dev/spidev0.%d", channel) ;
if ((fd = open (spiDev, O_RDWR)) < 0)
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
spiSpeeds [channel] = speed ;