wiringPi: Refactor source codes
Change-Id: Id121bfc6cb211b78b7ade56d235d43bdf11fc690
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -5,3 +5,8 @@ lib*.so.*
|
||||
debian-template/wiringPi
|
||||
debian-template/wiringpi-*.deb
|
||||
gpio/gpio
|
||||
*.aux
|
||||
*.dvi
|
||||
*.log
|
||||
.DS_Store
|
||||
.vscode
|
||||
@@ -33,7 +33,6 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringOdroid.h>
|
||||
#include <wpiExtensions.h>
|
||||
|
||||
#include <gertboard.h>
|
||||
@@ -625,52 +624,6 @@ static void doPadDrive (int argc, char *argv [])
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doUsbP:
|
||||
* Control USB Power - High (1.2A) or Low (600mA)
|
||||
* gpio usbp high/low
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doUsbP (int argc, char *argv [])
|
||||
{
|
||||
int model, rev, mem, maker, overVolted ;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
// Make sure we're on a B+
|
||||
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
||||
|
||||
if (!((model == PI_MODEL_BP) || (model == PI_MODEL_2))) {
|
||||
fprintf (stderr, "USB power contol is applicable to B+ and v2 boards only.\n") ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
// Make sure we start in BCM_GPIO mode
|
||||
wiringPiSetupGpio () ;
|
||||
|
||||
if ((strcasecmp (argv [2], "high") == 0) || (strcasecmp (argv [2], "hi") == 0)) {
|
||||
digitalWrite (PI_USB_POWER_CONTROL, 1) ;
|
||||
pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
|
||||
printf ("Switched to HIGH current USB (1.2A)\n") ;
|
||||
return ;
|
||||
}
|
||||
|
||||
if ((strcasecmp (argv [2], "low") == 0) || (strcasecmp (argv [2], "lo") == 0)) {
|
||||
digitalWrite (PI_USB_POWER_CONTROL, 0) ;
|
||||
pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
|
||||
printf ("Switched to LOW current USB (600mA)\n") ;
|
||||
return ;
|
||||
}
|
||||
|
||||
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doGbw:
|
||||
* gpio gbw channel value
|
||||
@@ -1189,29 +1142,29 @@ int main (int argc, char *argv [])
|
||||
for (i = 2 ; i < argc ; ++i)
|
||||
argv [i - 1] = argv [i] ;
|
||||
--argc ;
|
||||
wpMode = WPI_MODE_GPIO ;
|
||||
wpMode = MODE_GPIO ;
|
||||
} else if (strcasecmp (argv [1], "-1") == 0) { // Check for -1 argument
|
||||
wiringPiSetupPhys () ;
|
||||
|
||||
for (i = 2 ; i < argc ; ++i)
|
||||
argv [i - 1] = argv [i] ;
|
||||
--argc ;
|
||||
wpMode = WPI_MODE_PHYS ;
|
||||
wpMode = MODE_PHYS ;
|
||||
} else if (strcasecmp (argv [1], "-p") == 0) { // Check for -p argument for PiFace
|
||||
piFaceSetup (200) ;
|
||||
|
||||
for (i = 2 ; i < argc ; ++i)
|
||||
argv [i - 1] = argv [i] ;
|
||||
--argc ;
|
||||
wpMode = WPI_MODE_PIFACE ;
|
||||
wpMode = MODE_PIFACE ;
|
||||
} else if (strcasecmp (argv [1], "-z") == 0) { // Check for -z argument so we don't actually initialise wiringPi
|
||||
for (i = 2 ; i < argc ; ++i)
|
||||
argv [i - 1] = argv [i] ;
|
||||
--argc ;
|
||||
wpMode = WPI_MODE_UNINITIALISED ;
|
||||
wpMode = MODE_UNINITIALISED ;
|
||||
} else { // Default to wiringPi mode
|
||||
wiringPiSetup () ;
|
||||
wpMode = WPI_MODE_PINS ;
|
||||
wpMode = MODE_PINS ;
|
||||
}
|
||||
|
||||
// Check for -x argument to load in a new extension
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
#include <wiringPi.h>
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#include <wiringOdroid.h>
|
||||
|
||||
extern int wpMode ;
|
||||
|
||||
@@ -277,9 +276,9 @@ static void readallPhysOdroid (int model, int rev, int physPin, const char *phys
|
||||
if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1))
|
||||
printf (" | | ") ;
|
||||
else {
|
||||
if (wpMode == WPI_MODE_GPIO)
|
||||
if (wpMode == MODE_GPIO)
|
||||
pin = physPinToGpio (physPin);
|
||||
else if (wpMode == WPI_MODE_PHYS)
|
||||
else if (wpMode == MODE_PHYS)
|
||||
pin = physPin ;
|
||||
else
|
||||
pin = physToWpi [physPin];
|
||||
@@ -297,9 +296,9 @@ static void readallPhysOdroid (int model, int rev, int physPin, const char *phys
|
||||
if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1))
|
||||
printf (" | | ") ;
|
||||
else {
|
||||
if (wpMode == WPI_MODE_GPIO)
|
||||
if (wpMode == MODE_GPIO)
|
||||
pin = physPinToGpio (physPin);
|
||||
else if (wpMode == WPI_MODE_PHYS)
|
||||
else if (wpMode == MODE_PHYS)
|
||||
pin = physPin ;
|
||||
else
|
||||
pin = physToWpi [physPin];
|
||||
|
||||
BIN
pins/odroid_c1.pdf
Normal file
BIN
pins/odroid_c1.pdf
Normal file
Binary file not shown.
BIN
pins/odroid_c2.pdf
Normal file
BIN
pins/odroid_c2.pdf
Normal file
Binary file not shown.
BIN
pins/odroid_n1.pdf
Normal file
BIN
pins/odroid_n1.pdf
Normal file
Binary file not shown.
BIN
pins/odroid_xu3.pdf
Normal file
BIN
pins/odroid_xu3.pdf
Normal file
Binary file not shown.
@@ -51,7 +51,8 @@ LIBS = -lm -lpthread -lrt -lcrypt
|
||||
SRC = wiring${BRAND_NAME}.c \
|
||||
wiringSerial.c wiringShift.c \
|
||||
piHiPri.c piThread.c \
|
||||
wiringPiSPI.c wiringPiI2C.c \
|
||||
wiring${BRAND_NAME}SPI.c \
|
||||
wiring${BRAND_NAME}I2C.c \
|
||||
softPwm.c softTone.c \
|
||||
mcp23008.c mcp23016.c mcp23017.c \
|
||||
mcp23s08.c mcp23s17.c \
|
||||
@@ -60,13 +61,12 @@ SRC = wiring${BRAND_NAME}.c \
|
||||
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
|
||||
max31855.c max5322.c ads1115.c \
|
||||
sn3218.c \
|
||||
bmp180.c htu21d.c ds18b20.c rht03.c \
|
||||
bmp180.c htu21d.c ds18b20.c \
|
||||
drcSerial.c drcNet.c \
|
||||
pseudoPins.c \
|
||||
wpiExtensions.c
|
||||
|
||||
ifeq ($(BRAND_NAME), Odroid)
|
||||
DEFS += -D BOARD_ODROID
|
||||
SRC += odroidc1.c \
|
||||
odroidc2.c \
|
||||
odroidxu3.c \
|
||||
|
||||
@@ -29,10 +29,8 @@
|
||||
#include "softTone.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#include "wiringPi.h"
|
||||
#include "../version.h"
|
||||
|
||||
#include "wiringOdroid.h"
|
||||
#include "../version.h"
|
||||
|
||||
#include "odroidc1.h"
|
||||
#include "odroidc2.h"
|
||||
@@ -432,7 +430,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
|
||||
int wpiPinToGpio (int wpiPin)
|
||||
{
|
||||
if (libwiring.getModeToGpio)
|
||||
return libwiring.getModeToGpio(WPI_MODE_PINS, wpiPin);
|
||||
return libwiring.getModeToGpio(MODE_PINS, wpiPin);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -447,7 +445,7 @@ int wpiPinToGpio (int wpiPin)
|
||||
int physPinToGpio (int physPin)
|
||||
{
|
||||
if (libwiring.getModeToGpio)
|
||||
return libwiring.getModeToGpio(WPI_MODE_PHYS, physPin);
|
||||
return libwiring.getModeToGpio(MODE_PHYS, physPin);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -582,7 +580,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
|
||||
char c;
|
||||
int GpioPin;
|
||||
|
||||
if (libwiring.mode == WPI_MODE_UNINITIALISED)
|
||||
if (libwiring.mode == MODE_UNINITIALISED)
|
||||
return wiringPiFailure (
|
||||
WPI_FATAL,
|
||||
"wiringPiISR: wiringPi has not been initialised. " \
|
||||
@@ -801,7 +799,7 @@ int wiringPiSetup (void)
|
||||
for(i = 0; i < 256; i++)
|
||||
libwiring.sysFds[i] = -1;
|
||||
// init wiringPi mode
|
||||
libwiring.mode = WPI_MODE_UNINITIALISED;
|
||||
libwiring.mode = MODE_UNINITIALISED;
|
||||
|
||||
if (getenv (ENV_DEBUG) != NULL)
|
||||
wiringPiDebug = TRUE;
|
||||
@@ -839,7 +837,7 @@ int wiringPiSetup (void)
|
||||
|
||||
initialiseEpoch ();
|
||||
|
||||
libwiring.mode = WPI_MODE_PINS;
|
||||
libwiring.mode = MODE_PINS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -859,7 +857,7 @@ int wiringPiSetupGpio (void)
|
||||
if (wiringPiDebug)
|
||||
printf ("wiringPi: wiringPiSetupGpio called\n") ;
|
||||
|
||||
libwiring.mode = WPI_MODE_GPIO;
|
||||
libwiring.mode = MODE_GPIO;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
@@ -879,7 +877,7 @@ int wiringPiSetupPhys (void)
|
||||
if (wiringPiDebug)
|
||||
printf ("wiringPi: wiringPiSetupPhys called\n") ;
|
||||
|
||||
libwiring.mode = WPI_MODE_PHYS ;
|
||||
libwiring.mode = MODE_PHYS ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
@@ -922,7 +920,7 @@ int wiringPiSetupSys (void)
|
||||
|
||||
initialiseEpoch ();
|
||||
|
||||
libwiring.mode = WPI_MODE_GPIO_SYS;
|
||||
libwiring.mode = MODE_GPIO_SYS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,14 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1==1)
|
||||
#define FALSE (!TRUE)
|
||||
#endif
|
||||
|
||||
#define UNU __attribute__((unused))
|
||||
|
||||
#define ENV_DEBUG "WIRINGPI_DEBUG"
|
||||
#define ENV_CODES "WIRINGPI_CODES"
|
||||
#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
|
||||
@@ -70,15 +78,33 @@
|
||||
#define PUD_DOWN 1
|
||||
#define PUD_UP 2
|
||||
|
||||
// Interrupt levels
|
||||
#define INT_EDGE_SETUP 0
|
||||
#define INT_EDGE_FALLING 1
|
||||
#define INT_EDGE_RISING 2
|
||||
#define INT_EDGE_BOTH 3
|
||||
|
||||
// Module names
|
||||
#define AML_MODULE_I2C "aml_i2c"
|
||||
|
||||
// Threads
|
||||
#define PI_THREAD(X) void *X (UNU void *dummy)
|
||||
|
||||
// Failure modes
|
||||
#define WPI_FATAL (1==1)
|
||||
#define WPI_ALMOST (1==2)
|
||||
|
||||
extern const char *piModelNames [16];
|
||||
extern const char *piRevisionNames [16];
|
||||
extern const char *piMakerNames [16];
|
||||
extern const int piMemorySize [ 8];
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define PAGE_SIZE (4*1024)
|
||||
#define BLOCK_SIZE (4*1024)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Debuf message display function */
|
||||
/* Debug message display function */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#define MSG_ERR -1
|
||||
#define MSG_WARN -2
|
||||
@@ -98,6 +124,45 @@ extern int moduleLoaded(char *);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
// wiringPiNodeStruct:
|
||||
// This describes additional device nodes in the extended wiringPi
|
||||
// 2.0 scheme of things.
|
||||
// It's a simple linked list for now, but will hopefully migrate to
|
||||
// a binary tree for efficiency reasons - but then again, the chances
|
||||
// of more than 1 or 2 devices being added are fairly slim, so who
|
||||
// knows....
|
||||
/*----------------------------------------------------------------------------*/
|
||||
struct wiringPiNodeStruct
|
||||
{
|
||||
int pinBase;
|
||||
int pinMax;
|
||||
|
||||
int fd; // Node specific
|
||||
unsigned int data0; // ditto
|
||||
unsigned int data1; // ditto
|
||||
unsigned int data2; // ditto
|
||||
unsigned int data3; // ditto
|
||||
|
||||
void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode);
|
||||
void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode);
|
||||
int (*digitalRead) (struct wiringPiNodeStruct *node, int pin);
|
||||
// unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin);
|
||||
void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value);
|
||||
// void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value);
|
||||
void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value);
|
||||
int (*analogRead) (struct wiringPiNodeStruct *node, int pin);
|
||||
void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value);
|
||||
|
||||
struct wiringPiNodeStruct *next;
|
||||
};
|
||||
|
||||
extern struct wiringPiNodeStruct *wiringPiNodes;
|
||||
extern struct wiringPiNodeStruct *wiringPiFindNode (int pin);
|
||||
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins);
|
||||
|
||||
extern int wiringPiFailure (int fatal, const char *message, ...) ;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
struct libodroid
|
||||
{
|
||||
|
||||
22
wiringPi/wiringPiI2C.c → wiringPi/wiringOdroidI2C.c
Executable file → Normal file
22
wiringPi/wiringPiI2C.c → wiringPi/wiringOdroidI2C.c
Executable file → Normal file
@@ -216,9 +216,6 @@ int wiringPiI2CSetupInterface (const char *device, int devId)
|
||||
* Open the I2C device, and regsiter the target device
|
||||
*********************************************************************************
|
||||
*/
|
||||
#if defined(BOARD_ODROID)
|
||||
|
||||
#include "wiringOdroid.h"
|
||||
|
||||
int wiringPiI2CSetup (const int devId)
|
||||
{
|
||||
@@ -239,22 +236,3 @@ int wiringPiI2CSetup (const int devId)
|
||||
|
||||
return wiringPiI2CSetupInterface (device, devId) ;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int wiringPiI2CSetup (const int devId)
|
||||
{
|
||||
int rev ;
|
||||
const char *device ;
|
||||
|
||||
rev = piGpioLayout () ;
|
||||
|
||||
if (rev == 1)
|
||||
device = "/dev/i2c-0" ;
|
||||
else
|
||||
device = "/dev/i2c-1" ;
|
||||
|
||||
return wiringPiI2CSetupInterface (device, devId) ;
|
||||
}
|
||||
|
||||
#endif // #defined(BOARD_ODROID)
|
||||
42
wiringPi/wiringOdroidI2C.h
Normal file
42
wiringPi/wiringOdroidI2C.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* wiringPiI2C.h:
|
||||
* Simplified I2C access routines
|
||||
* Copyright (c) 2013 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with wiringPi.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int wiringPiI2CRead (int fd) ;
|
||||
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
|
||||
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
|
||||
|
||||
extern int wiringPiI2CWrite (int fd, int data) ;
|
||||
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
|
||||
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
|
||||
|
||||
extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
|
||||
extern int wiringPiI2CSetup (const int devId) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
49
wiringPi/wiringPiSPI.c → wiringPi/wiringOdroidSPI.c
Executable file → Normal file
49
wiringPi/wiringPiSPI.c → wiringPi/wiringOdroidSPI.c
Executable file → Normal file
@@ -32,17 +32,16 @@
|
||||
#include <linux/spi/spidev.h>
|
||||
|
||||
#include "wiringPi.h"
|
||||
|
||||
#include "wiringPiSPI.h"
|
||||
|
||||
|
||||
// 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 uint8_t spiBPW = 8 ;
|
||||
static const uint16_t spiDelay = 0 ;
|
||||
static const char *spiDevType0 = "/dev/spidev0.0";
|
||||
static const char *spiDevType1 = "/dev/spidev1.0";
|
||||
static const uint8_t spiBPW = 8;
|
||||
static const uint16_t spiDelay = 0;
|
||||
|
||||
static uint32_t spiSpeeds [2] ;
|
||||
static int spiFds [2] ;
|
||||
@@ -97,10 +96,6 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
#if defined(BOARD_ODROID)
|
||||
|
||||
#include "wiringOdroid.h"
|
||||
|
||||
int wiringPiSPISetupMode (int channel, int speed, int mode)
|
||||
{
|
||||
int fd ;
|
||||
@@ -112,18 +107,18 @@ int wiringPiSPISetupMode (int channel, int speed, int mode)
|
||||
mode &= 3 ; // Mode is 0, 1, 2 or 3
|
||||
channel &= 1 ; // Channel is 0 or 1
|
||||
|
||||
if (channel || model == MODEL_ODROID_C2) {
|
||||
if (model == MODEL_ODROID_C2) {
|
||||
return wiringPiFailure (WPI_ALMOST,
|
||||
"Can't support spi device. check model or spi channel.\n");
|
||||
}
|
||||
|
||||
switch(model) {
|
||||
case MODEL_ODROID_C1:
|
||||
device = "/dev/spidev0.0";
|
||||
device = spiDevType0;
|
||||
break;
|
||||
case MODEL_ODROID_XU3:
|
||||
case MODEL_ODROID_N1:
|
||||
device = "/dev/spidev1.0";
|
||||
device = spiDevType1;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -149,36 +144,6 @@ int wiringPiSPISetupMode (int channel, int speed, int mode)
|
||||
return fd ;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
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)) < 0)
|
||||
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) < 0)
|
||||
return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
|
||||
|
||||
if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
|
||||
return wiringPiFailure (WPI_ALMOST, "SPI BPW Change failure: %s\n", strerror (errno)) ;
|
||||
|
||||
if (ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0)
|
||||
return wiringPiFailure (WPI_ALMOST, "SPI Speed Change failure: %s\n", strerror (errno)) ;
|
||||
|
||||
return fd ;
|
||||
}
|
||||
|
||||
#endif // #defined(BOARD_ODROID)
|
||||
|
||||
/*
|
||||
* wiringPiSPISetup:
|
||||
36
wiringPi/wiringOdroidSPI.h
Normal file
36
wiringPi/wiringOdroidSPI.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* wiringPiSPI.h:
|
||||
* Simplified SPI access routines
|
||||
* Copyright (c) 2012-2015 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with wiringPi.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int wiringPiSPIGetFd (int channel) ;
|
||||
int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
|
||||
int wiringPiSPISetupMode (int channel, int speed, int mode) ;
|
||||
int wiringPiSPISetup (int channel, int speed) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
2373
wiringPi/wiringPi.c
2373
wiringPi/wiringPi.c
File diff suppressed because it is too large
Load Diff
@@ -1,254 +0,0 @@
|
||||
/*
|
||||
* wiringPi.h:
|
||||
* Arduino like Wiring library for the Raspberry Pi.
|
||||
* Copyright (c) 2012-2017 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __WIRING_PI_H__
|
||||
#define __WIRING_PI_H__
|
||||
|
||||
// C doesn't have true/false by default and I can never remember which
|
||||
// way round they are, so ...
|
||||
// (and yes, I know about stdbool.h but I like capitals for these and I'm old)
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1==1)
|
||||
# define FALSE (!TRUE)
|
||||
#endif
|
||||
|
||||
// GCC warning suppressor
|
||||
|
||||
#define UNU __attribute__((unused))
|
||||
|
||||
// Mask for the bottom 64 pins which belong to the Raspberry Pi
|
||||
// The others are available for the other devices
|
||||
|
||||
#define PI_GPIO_MASK (0xFFFFFFC0)
|
||||
|
||||
// Handy defines
|
||||
|
||||
// wiringPi modes
|
||||
|
||||
#define WPI_MODE_PINS 0
|
||||
#define WPI_MODE_GPIO 1
|
||||
#define WPI_MODE_GPIO_SYS 2
|
||||
#define WPI_MODE_PHYS 3
|
||||
#define WPI_MODE_PIFACE 4
|
||||
#define WPI_MODE_UNINITIALISED -1
|
||||
|
||||
// Pin modes
|
||||
|
||||
#define INPUT 0
|
||||
#define OUTPUT 1
|
||||
#define PWM_OUTPUT 2
|
||||
#define GPIO_CLOCK 3
|
||||
#define SOFT_PWM_OUTPUT 4
|
||||
#define SOFT_TONE_OUTPUT 5
|
||||
#define PWM_TONE_OUTPUT 6
|
||||
|
||||
#define LOW 0
|
||||
#define HIGH 1
|
||||
|
||||
// Pull up/down/none
|
||||
|
||||
#define PUD_OFF 0
|
||||
#define PUD_DOWN 1
|
||||
#define PUD_UP 2
|
||||
|
||||
// PWM
|
||||
|
||||
#define PWM_MODE_MS 0
|
||||
#define PWM_MODE_BAL 1
|
||||
|
||||
// Interrupt levels
|
||||
|
||||
#define INT_EDGE_SETUP 0
|
||||
#define INT_EDGE_FALLING 1
|
||||
#define INT_EDGE_RISING 2
|
||||
#define INT_EDGE_BOTH 3
|
||||
|
||||
// Pi model types and version numbers
|
||||
// Intended for the GPIO program Use at your own risk.
|
||||
|
||||
#define PI_MODEL_A 0
|
||||
#define PI_MODEL_B 1
|
||||
#define PI_MODEL_AP 2
|
||||
#define PI_MODEL_BP 3
|
||||
#define PI_MODEL_2 4
|
||||
#define PI_ALPHA 5
|
||||
#define PI_MODEL_CM 6
|
||||
#define PI_MODEL_07 7
|
||||
#define PI_MODEL_3 8
|
||||
#define PI_MODEL_ZERO 9
|
||||
#define PI_MODEL_CM3 10
|
||||
#define PI_MODEL_ZERO_W 12
|
||||
|
||||
#define PI_VERSION_1 0
|
||||
#define PI_VERSION_1_1 1
|
||||
#define PI_VERSION_1_2 2
|
||||
#define PI_VERSION_2 3
|
||||
|
||||
#define PI_MAKER_SONY 0
|
||||
#define PI_MAKER_EGOMAN 1
|
||||
#define PI_MAKER_EMBEST 2
|
||||
#define PI_MAKER_UNKNOWN 3
|
||||
|
||||
extern const char *piModelNames [16] ;
|
||||
extern const char *piRevisionNames [16] ;
|
||||
extern const char *piMakerNames [16] ;
|
||||
extern const int piMemorySize [ 8] ;
|
||||
|
||||
|
||||
// Intended for the GPIO program Use at your own risk.
|
||||
|
||||
// Threads
|
||||
|
||||
#define PI_THREAD(X) void *X (UNU void *dummy)
|
||||
|
||||
// Failure modes
|
||||
|
||||
#define WPI_FATAL (1==1)
|
||||
#define WPI_ALMOST (1==2)
|
||||
|
||||
|
||||
// wiringPiNodeStruct:
|
||||
// This describes additional device nodes in the extended wiringPi
|
||||
// 2.0 scheme of things.
|
||||
// It's a simple linked list for now, but will hopefully migrate to
|
||||
// a binary tree for efficiency reasons - but then again, the chances
|
||||
// of more than 1 or 2 devices being added are fairly slim, so who
|
||||
// knows....
|
||||
|
||||
struct wiringPiNodeStruct
|
||||
{
|
||||
int pinBase ;
|
||||
int pinMax ;
|
||||
|
||||
int fd ; // Node specific
|
||||
unsigned int data0 ; // ditto
|
||||
unsigned int data1 ; // ditto
|
||||
unsigned int data2 ; // ditto
|
||||
unsigned int data3 ; // ditto
|
||||
|
||||
void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
|
||||
void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
|
||||
int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
|
||||
//unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin) ;
|
||||
void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
|
||||
// void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value) ;
|
||||
void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
|
||||
int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
|
||||
void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
|
||||
|
||||
struct wiringPiNodeStruct *next ;
|
||||
} ;
|
||||
|
||||
extern struct wiringPiNodeStruct *wiringPiNodes ;
|
||||
|
||||
|
||||
// Function prototypes
|
||||
// c++ wrappers thanks to a comment by Nick Lott
|
||||
// (and others on the Raspberry Pi forums)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Data
|
||||
|
||||
// Internal
|
||||
|
||||
extern int wiringPiFailure (int fatal, const char *message, ...) ;
|
||||
|
||||
// Core wiringPi functions
|
||||
|
||||
extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
|
||||
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
|
||||
|
||||
extern void wiringPiVersion (int *major, int *minor) ;
|
||||
extern int wiringPiSetup (void) ;
|
||||
extern int wiringPiSetupSys (void) ;
|
||||
extern int wiringPiSetupGpio (void) ;
|
||||
extern int wiringPiSetupPhys (void) ;
|
||||
|
||||
extern void pinModeAlt (int pin, int mode) ;
|
||||
extern void pinMode (int pin, int mode) ;
|
||||
extern void pullUpDnControl (int pin, int pud) ;
|
||||
extern int digitalRead (int pin) ;
|
||||
extern void digitalWrite (int pin, int value) ;
|
||||
extern unsigned int digitalRead8 (int pin) ;
|
||||
extern void digitalWrite8 (int pin, int value) ;
|
||||
extern void pwmWrite (int pin, int value) ;
|
||||
extern int analogRead (int pin) ;
|
||||
extern void analogWrite (int pin, int value) ;
|
||||
|
||||
// PiFace specifics
|
||||
// (Deprecated)
|
||||
|
||||
extern int wiringPiSetupPiFace (void) ;
|
||||
extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
|
||||
|
||||
// On-Board Raspberry Pi hardware specific stuff
|
||||
|
||||
extern int piGpioLayout (void) ;
|
||||
extern int piBoardRev (void) ; // Deprecated
|
||||
extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
|
||||
extern int wpiPinToGpio (int wpiPin) ;
|
||||
extern int physPinToGpio (int physPin) ;
|
||||
extern void setPadDrive (int group, int value) ;
|
||||
extern int getAlt (int pin) ;
|
||||
extern void pwmToneWrite (int pin, int freq) ;
|
||||
extern void pwmSetMode (int mode) ;
|
||||
extern void pwmSetRange (unsigned int range) ;
|
||||
extern void pwmSetClock (int divisor) ;
|
||||
extern void gpioClockSet (int pin, int freq) ;
|
||||
extern unsigned int digitalReadByte (void) ;
|
||||
extern unsigned int digitalReadByte2 (void) ;
|
||||
extern void digitalWriteByte (int value) ;
|
||||
extern void digitalWriteByte2 (int value) ;
|
||||
|
||||
// Interrupts
|
||||
// (Also Pi hardware specific)
|
||||
|
||||
extern int waitForInterrupt (int pin, int mS) ;
|
||||
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
|
||||
|
||||
// Threads
|
||||
|
||||
extern int piThreadCreate (void *(*fn)(void *)) ;
|
||||
extern void piLock (int key) ;
|
||||
extern void piUnlock (int key) ;
|
||||
|
||||
// Schedulling priority
|
||||
|
||||
extern int piHiPri (const int pri) ;
|
||||
|
||||
// Extras from arduino land
|
||||
|
||||
extern void delay (unsigned int howLong) ;
|
||||
extern void delayMicroseconds (unsigned int howLong) ;
|
||||
extern unsigned int millis (void) ;
|
||||
extern unsigned int micros (void) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1
wiringPi/wiringPi.h
Symbolic link
1
wiringPi/wiringPi.h
Symbolic link
@@ -0,0 +1 @@
|
||||
wiringOdroid.h
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* wiringPiI2C.h:
|
||||
* Simplified I2C access routines
|
||||
* Copyright (c) 2013 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with wiringPi.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int wiringPiI2CRead (int fd) ;
|
||||
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
|
||||
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
|
||||
|
||||
extern int wiringPiI2CWrite (int fd, int data) ;
|
||||
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
|
||||
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
|
||||
|
||||
extern int wiringPiI2CSetupInterface (const char *device, int devId) ;
|
||||
extern int wiringPiI2CSetup (const int devId) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
1
wiringPi/wiringPiI2C.h
Symbolic link
1
wiringPi/wiringPiI2C.h
Symbolic link
@@ -0,0 +1 @@
|
||||
wiringOdroidI2C.h
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* wiringPiSPI.h:
|
||||
* Simplified SPI access routines
|
||||
* Copyright (c) 2012-2015 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with wiringPi.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int wiringPiSPIGetFd (int channel) ;
|
||||
int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
|
||||
int wiringPiSPISetupMode (int channel, int speed, int mode) ;
|
||||
int wiringPiSPISetup (int channel, int speed) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
1
wiringPi/wiringPiSPI.h
Symbolic link
1
wiringPi/wiringPiSPI.h
Symbolic link
@@ -0,0 +1 @@
|
||||
wiringOdroidSPI.h
|
||||
@@ -61,7 +61,6 @@
|
||||
#include "bmp180.h"
|
||||
#include "htu21d.h"
|
||||
#include "ds18b20.h"
|
||||
#include "rht03.h"
|
||||
|
||||
#include "wpiExtensions.h"
|
||||
|
||||
@@ -518,25 +517,6 @@ static int doExtensionDs18b20 (char *progName, int pinBase, char *params)
|
||||
return ds18b20Setup (pinBase, serialNum) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doExtensionRht03:
|
||||
* Maxdetect 1-Wire Temperature & Humidity
|
||||
* rht03:base:piPin
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static int doExtensionRht03 (char *progName, int pinBase, char *params)
|
||||
{
|
||||
int piPin ;
|
||||
|
||||
if ((params = extractInt (progName, params, &piPin)) == NULL)
|
||||
return FALSE ;
|
||||
|
||||
return rht03Setup (pinBase, piPin) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doExtensionMax31855:
|
||||
* Analog IO
|
||||
@@ -843,7 +823,6 @@ static struct extensionFunctionStruct extensionFunctions [] =
|
||||
{ "pseudoPins", &doExtensionPseudoPins },
|
||||
{ "htu21d", &doExtensionHtu21d },
|
||||
{ "ds18b20", &doExtensionDs18b20 },
|
||||
{ "rht03", &doExtensionRht03 },
|
||||
{ "mcp3002", &doExtensionMcp3002 },
|
||||
{ "mcp3004", &doExtensionMcp3004 },
|
||||
{ "mcp4802", &doExtensionMcp4802 },
|
||||
|
||||
Reference in New Issue
Block a user