Skip to content

Commit c375207

Browse files
committed
wiringPi: Refactor source codes
Change-Id: Id121bfc6cb211b78b7ade56d235d43bdf11fc690
1 parent 175d1f6 commit c375207

19 files changed

+180
-2862
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ lib*.so.*
55
debian-template/wiringPi
66
debian-template/wiringpi-*.deb
77
gpio/gpio
8+
*.aux
9+
*.dvi
10+
*.log
11+
.DS_Store
12+
.vscode

gpio/gpio_odroid.c

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <sys/stat.h>
3434

3535
#include <wiringPi.h>
36-
#include <wiringOdroid.h>
3736
#include <wpiExtensions.h>
3837

3938
#include <gertboard.h>
@@ -625,52 +624,6 @@ static void doPadDrive (int argc, char *argv [])
625624
}
626625

627626

628-
/*
629-
* doUsbP:
630-
* Control USB Power - High (1.2A) or Low (600mA)
631-
* gpio usbp high/low
632-
*********************************************************************************
633-
*/
634-
635-
static void doUsbP (int argc, char *argv [])
636-
{
637-
int model, rev, mem, maker, overVolted ;
638-
639-
if (argc != 3) {
640-
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
641-
exit (1) ;
642-
}
643-
644-
// Make sure we're on a B+
645-
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
646-
647-
if (!((model == PI_MODEL_BP) || (model == PI_MODEL_2))) {
648-
fprintf (stderr, "USB power contol is applicable to B+ and v2 boards only.\n") ;
649-
exit (1) ;
650-
}
651-
652-
// Make sure we start in BCM_GPIO mode
653-
wiringPiSetupGpio () ;
654-
655-
if ((strcasecmp (argv [2], "high") == 0) || (strcasecmp (argv [2], "hi") == 0)) {
656-
digitalWrite (PI_USB_POWER_CONTROL, 1) ;
657-
pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
658-
printf ("Switched to HIGH current USB (1.2A)\n") ;
659-
return ;
660-
}
661-
662-
if ((strcasecmp (argv [2], "low") == 0) || (strcasecmp (argv [2], "lo") == 0)) {
663-
digitalWrite (PI_USB_POWER_CONTROL, 0) ;
664-
pinMode (PI_USB_POWER_CONTROL, OUTPUT) ;
665-
printf ("Switched to LOW current USB (600mA)\n") ;
666-
return ;
667-
}
668-
669-
fprintf (stderr, "Usage: %s usbp high|low\n", argv [0]) ;
670-
exit (1) ;
671-
}
672-
673-
674627
/*
675628
* doGbw:
676629
* gpio gbw channel value
@@ -1189,29 +1142,29 @@ int main (int argc, char *argv [])
11891142
for (i = 2 ; i < argc ; ++i)
11901143
argv [i - 1] = argv [i] ;
11911144
--argc ;
1192-
wpMode = WPI_MODE_GPIO ;
1145+
wpMode = MODE_GPIO ;
11931146
} else if (strcasecmp (argv [1], "-1") == 0) { // Check for -1 argument
11941147
wiringPiSetupPhys () ;
11951148

11961149
for (i = 2 ; i < argc ; ++i)
11971150
argv [i - 1] = argv [i] ;
11981151
--argc ;
1199-
wpMode = WPI_MODE_PHYS ;
1152+
wpMode = MODE_PHYS ;
12001153
} else if (strcasecmp (argv [1], "-p") == 0) { // Check for -p argument for PiFace
12011154
piFaceSetup (200) ;
12021155

12031156
for (i = 2 ; i < argc ; ++i)
12041157
argv [i - 1] = argv [i] ;
12051158
--argc ;
1206-
wpMode = WPI_MODE_PIFACE ;
1159+
wpMode = MODE_PIFACE ;
12071160
} else if (strcasecmp (argv [1], "-z") == 0) { // Check for -z argument so we don't actually initialise wiringPi
12081161
for (i = 2 ; i < argc ; ++i)
12091162
argv [i - 1] = argv [i] ;
12101163
--argc ;
1211-
wpMode = WPI_MODE_UNINITIALISED ;
1164+
wpMode = MODE_UNINITIALISED ;
12121165
} else { // Default to wiringPi mode
12131166
wiringPiSetup () ;
1214-
wpMode = WPI_MODE_PINS ;
1167+
wpMode = MODE_PINS ;
12151168
}
12161169

12171170
// Check for -x argument to load in a new extension

gpio/readall_odroid.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
#include <wiringPi.h>
3535
/*----------------------------------------------------------------------------*/
36-
#include <wiringOdroid.h>
3736

3837
extern int wpMode ;
3938

@@ -277,9 +276,9 @@ static void readallPhysOdroid (int model, int rev, int physPin, const char *phys
277276
if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1))
278277
printf (" | | ") ;
279278
else {
280-
if (wpMode == WPI_MODE_GPIO)
279+
if (wpMode == MODE_GPIO)
281280
pin = physPinToGpio (physPin);
282-
else if (wpMode == WPI_MODE_PHYS)
281+
else if (wpMode == MODE_PHYS)
283282
pin = physPin ;
284283
else
285284
pin = physToWpi [physPin];
@@ -297,9 +296,9 @@ static void readallPhysOdroid (int model, int rev, int physPin, const char *phys
297296
if ((physToWpi [physPin] == -1) || (physPinToGpio (physPin) == -1))
298297
printf (" | | ") ;
299298
else {
300-
if (wpMode == WPI_MODE_GPIO)
299+
if (wpMode == MODE_GPIO)
301300
pin = physPinToGpio (physPin);
302-
else if (wpMode == WPI_MODE_PHYS)
301+
else if (wpMode == MODE_PHYS)
303302
pin = physPin ;
304303
else
305304
pin = physToWpi [physPin];

pins/odroid_c1.pdf

17.1 KB
Binary file not shown.

pins/odroid_c2.pdf

17 KB
Binary file not shown.

pins/odroid_n1.pdf

17.4 KB
Binary file not shown.

pins/odroid_xu3.pdf

17.8 KB
Binary file not shown.

wiringPi/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ LIBS = -lm -lpthread -lrt -lcrypt
5151
SRC = wiring${BRAND_NAME}.c \
5252
wiringSerial.c wiringShift.c \
5353
piHiPri.c piThread.c \
54-
wiringPiSPI.c wiringPiI2C.c \
54+
wiring${BRAND_NAME}SPI.c \
55+
wiring${BRAND_NAME}I2C.c \
5556
softPwm.c softTone.c \
5657
mcp23008.c mcp23016.c mcp23017.c \
5758
mcp23s08.c mcp23s17.c \
@@ -60,13 +61,12 @@ SRC = wiring${BRAND_NAME}.c \
6061
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
6162
max31855.c max5322.c ads1115.c \
6263
sn3218.c \
63-
bmp180.c htu21d.c ds18b20.c rht03.c \
64+
bmp180.c htu21d.c ds18b20.c \
6465
drcSerial.c drcNet.c \
6566
pseudoPins.c \
6667
wpiExtensions.c
6768

6869
ifeq ($(BRAND_NAME), Odroid)
69-
DEFS += -D BOARD_ODROID
7070
SRC += odroidc1.c \
7171
odroidc2.c \
7272
odroidxu3.c \

wiringPi/wiringOdroid.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
#include "softTone.h"
3030

3131
/*----------------------------------------------------------------------------*/
32-
#include "wiringPi.h"
33-
#include "../version.h"
34-
3532
#include "wiringOdroid.h"
33+
#include "../version.h"
3634

3735
#include "odroidc1.h"
3836
#include "odroidc2.h"
@@ -432,7 +430,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
432430
int wpiPinToGpio (int wpiPin)
433431
{
434432
if (libwiring.getModeToGpio)
435-
return libwiring.getModeToGpio(WPI_MODE_PINS, wpiPin);
433+
return libwiring.getModeToGpio(MODE_PINS, wpiPin);
436434

437435
return -1;
438436
}
@@ -447,7 +445,7 @@ int wpiPinToGpio (int wpiPin)
447445
int physPinToGpio (int physPin)
448446
{
449447
if (libwiring.getModeToGpio)
450-
return libwiring.getModeToGpio(WPI_MODE_PHYS, physPin);
448+
return libwiring.getModeToGpio(MODE_PHYS, physPin);
451449

452450
return -1;
453451
}
@@ -582,7 +580,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
582580
char c;
583581
int GpioPin;
584582

585-
if (libwiring.mode == WPI_MODE_UNINITIALISED)
583+
if (libwiring.mode == MODE_UNINITIALISED)
586584
return wiringPiFailure (
587585
WPI_FATAL,
588586
"wiringPiISR: wiringPi has not been initialised. " \
@@ -801,7 +799,7 @@ int wiringPiSetup (void)
801799
for(i = 0; i < 256; i++)
802800
libwiring.sysFds[i] = -1;
803801
// init wiringPi mode
804-
libwiring.mode = WPI_MODE_UNINITIALISED;
802+
libwiring.mode = MODE_UNINITIALISED;
805803

806804
if (getenv (ENV_DEBUG) != NULL)
807805
wiringPiDebug = TRUE;
@@ -839,7 +837,7 @@ int wiringPiSetup (void)
839837

840838
initialiseEpoch ();
841839

842-
libwiring.mode = WPI_MODE_PINS;
840+
libwiring.mode = MODE_PINS;
843841
return 0;
844842
}
845843

@@ -859,7 +857,7 @@ int wiringPiSetupGpio (void)
859857
if (wiringPiDebug)
860858
printf ("wiringPi: wiringPiSetupGpio called\n") ;
861859

862-
libwiring.mode = WPI_MODE_GPIO;
860+
libwiring.mode = MODE_GPIO;
863861
return 0 ;
864862
}
865863

@@ -879,7 +877,7 @@ int wiringPiSetupPhys (void)
879877
if (wiringPiDebug)
880878
printf ("wiringPi: wiringPiSetupPhys called\n") ;
881879

882-
libwiring.mode = WPI_MODE_PHYS ;
880+
libwiring.mode = MODE_PHYS ;
883881
return 0 ;
884882
}
885883

@@ -922,7 +920,7 @@ int wiringPiSetupSys (void)
922920

923921
initialiseEpoch ();
924922

925-
libwiring.mode = WPI_MODE_GPIO_SYS;
923+
libwiring.mode = MODE_GPIO_SYS;
926924
return 0;
927925
}
928926

wiringPi/wiringOdroid.h

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#include <stdlib.h>
3232

3333
/*----------------------------------------------------------------------------*/
34+
35+
#ifndef TRUE
36+
#define TRUE (1==1)
37+
#define FALSE (!TRUE)
38+
#endif
39+
40+
#define UNU __attribute__((unused))
41+
3442
#define ENV_DEBUG "WIRINGPI_DEBUG"
3543
#define ENV_CODES "WIRINGPI_CODES"
3644
#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
@@ -70,15 +78,33 @@
7078
#define PUD_DOWN 1
7179
#define PUD_UP 2
7280

81+
// Interrupt levels
82+
#define INT_EDGE_SETUP 0
83+
#define INT_EDGE_FALLING 1
84+
#define INT_EDGE_RISING 2
85+
#define INT_EDGE_BOTH 3
86+
7387
// Module names
7488
#define AML_MODULE_I2C "aml_i2c"
7589

90+
// Threads
91+
#define PI_THREAD(X) void *X (UNU void *dummy)
92+
93+
// Failure modes
94+
#define WPI_FATAL (1==1)
95+
#define WPI_ALMOST (1==2)
96+
97+
extern const char *piModelNames [16];
98+
extern const char *piRevisionNames [16];
99+
extern const char *piMakerNames [16];
100+
extern const int piMemorySize [ 8];
101+
76102
/*----------------------------------------------------------------------------*/
77103
#define PAGE_SIZE (4*1024)
78104
#define BLOCK_SIZE (4*1024)
79105

80106
/*----------------------------------------------------------------------------*/
81-
/* Debuf message display function */
107+
/* Debug message display function */
82108
/*----------------------------------------------------------------------------*/
83109
#define MSG_ERR -1
84110
#define MSG_WARN -2
@@ -98,6 +124,45 @@ extern int moduleLoaded(char *);
98124
}
99125
#endif
100126

127+
/*----------------------------------------------------------------------------*/
128+
// wiringPiNodeStruct:
129+
// This describes additional device nodes in the extended wiringPi
130+
// 2.0 scheme of things.
131+
// It's a simple linked list for now, but will hopefully migrate to
132+
// a binary tree for efficiency reasons - but then again, the chances
133+
// of more than 1 or 2 devices being added are fairly slim, so who
134+
// knows....
135+
/*----------------------------------------------------------------------------*/
136+
struct wiringPiNodeStruct
137+
{
138+
int pinBase;
139+
int pinMax;
140+
141+
int fd; // Node specific
142+
unsigned int data0; // ditto
143+
unsigned int data1; // ditto
144+
unsigned int data2; // ditto
145+
unsigned int data3; // ditto
146+
147+
void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode);
148+
void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode);
149+
int (*digitalRead) (struct wiringPiNodeStruct *node, int pin);
150+
// unsigned int (*digitalRead8) (struct wiringPiNodeStruct *node, int pin);
151+
void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value);
152+
// void (*digitalWrite8) (struct wiringPiNodeStruct *node, int pin, int value);
153+
void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value);
154+
int (*analogRead) (struct wiringPiNodeStruct *node, int pin);
155+
void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value);
156+
157+
struct wiringPiNodeStruct *next;
158+
};
159+
160+
extern struct wiringPiNodeStruct *wiringPiNodes;
161+
extern struct wiringPiNodeStruct *wiringPiFindNode (int pin);
162+
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins);
163+
164+
extern int wiringPiFailure (int fatal, const char *message, ...) ;
165+
101166
/*----------------------------------------------------------------------------*/
102167
struct libodroid
103168
{

0 commit comments

Comments
 (0)