wiringpi2 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/wiringpi/WiringPi/examples/blink.c +50 -0
- data/ext/wiringpi/WiringPi/examples/delayTest.c +107 -0
- data/ext/wiringpi/WiringPi/examples/ds1302.c +238 -0
- data/ext/wiringpi/WiringPi/examples/gertboard.c +94 -0
- data/ext/wiringpi/WiringPi/examples/header.h +23 -0
- data/ext/wiringpi/WiringPi/examples/isr-osc.c +118 -0
- data/ext/wiringpi/WiringPi/examples/isr.c +99 -0
- data/ext/wiringpi/WiringPi/examples/lcd.c +129 -0
- data/ext/wiringpi/WiringPi/examples/nes.c +67 -0
- data/ext/wiringpi/WiringPi/examples/okLed.c +83 -0
- data/ext/wiringpi/WiringPi/examples/piface.c +74 -0
- data/ext/wiringpi/WiringPi/examples/pwm.c +93 -0
- data/ext/wiringpi/WiringPi/examples/serialRead.c +48 -0
- data/ext/wiringpi/WiringPi/examples/serialTest.c +75 -0
- data/ext/wiringpi/WiringPi/examples/servo.c +57 -0
- data/ext/wiringpi/WiringPi/examples/speed.c +123 -0
- data/ext/wiringpi/WiringPi/examples/test1.c +111 -0
- data/ext/wiringpi/WiringPi/examples/test2.c +58 -0
- data/ext/wiringpi/WiringPi/examples/tone.c +59 -0
- data/ext/wiringpi/WiringPi/examples/wfi.c +161 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +1371 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.c +239 -0
- data/ext/wiringpi/WiringPi/wiringPi/ds1302.h +44 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.c +166 -0
- data/ext/wiringpi/WiringPi/wiringPi/gertboard.h +40 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.c +380 -0
- data/ext/wiringpi/WiringPi/wiringPi/lcd.h +46 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +155 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +195 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +236 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x08.h +73 -0
- data/ext/wiringpi/WiringPi/wiringPi/mcp23x0817.h +87 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.c +179 -0
- data/ext/wiringpi/WiringPi/wiringPi/piFace.h +32 -0
- data/ext/wiringpi/WiringPi/wiringPi/piHiPri.c +50 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.c +113 -0
- data/ext/wiringpi/WiringPi/wiringPi/piNes.h +45 -0
- data/ext/wiringpi/WiringPi/wiringPi/piThread.c +63 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.c +130 -0
- data/ext/wiringpi/WiringPi/wiringPi/softPwm.h +34 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.c +211 -0
- data/ext/wiringpi/WiringPi/wiringPi/softServo.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.c +121 -0
- data/ext/wiringpi/WiringPi/wiringPi/softTone.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +108 -0
- data/ext/wiringpi/WiringPi/wiringPi/sr595.h +33 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +1664 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +168 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.c +227 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiI2C.h +42 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.c +119 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringPiSPI.h +35 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.c +213 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringSerial.h +38 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.c +83 -0
- data/ext/wiringpi/WiringPi/wiringPi/wiringShift.h +41 -0
- data/ext/wiringpi/extconf.rb +8 -0
- data/ext/wiringpi/wiringpi_wrap.c +4378 -0
- data/lib/wiringpi/event.rb +21 -0
- data/lib/wiringpi/gpio.rb +131 -0
- data/lib/wiringpi/i2c.rb +26 -0
- data/lib/wiringpi/mcp23x17.rb +31 -0
- data/lib/wiringpi/serial.rb +49 -0
- data/lib/wiringpi/spi.rb +15 -0
- data/lib/wiringpi2.rb +42 -0
- metadata +122 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piFace.:
|
|
3
|
+
* Arduino compatable (ish) Wiring library for the Raspberry Pi
|
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
|
5
|
+
*
|
|
6
|
+
* This file to interface with the PiFace peripheral device which
|
|
7
|
+
* has an MCP23S17 GPIO device connected via the SPI bus.
|
|
8
|
+
***********************************************************************
|
|
9
|
+
* This file is part of wiringPi:
|
|
10
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
11
|
+
*
|
|
12
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
13
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
14
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
15
|
+
* License, or (at your option) any later version.
|
|
16
|
+
*
|
|
17
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
18
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
* GNU Lesser General Public License for more details.
|
|
21
|
+
*
|
|
22
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
23
|
+
* License along with wiringPi.
|
|
24
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
25
|
+
***********************************************************************
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#include <stdio.h>
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
|
|
32
|
+
#include "wiringPi.h"
|
|
33
|
+
#include "wiringPiSPI.h"
|
|
34
|
+
|
|
35
|
+
#include "piFace.h"
|
|
36
|
+
|
|
37
|
+
#define PIFACE_SPEED 4000000
|
|
38
|
+
#define PIFACE_DEVNO 0
|
|
39
|
+
|
|
40
|
+
#include "mcp23x0817.h"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* writeByte:
|
|
45
|
+
* Write a byte to a register on the MCP23S17 on the SPI bus.
|
|
46
|
+
*********************************************************************************
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
static void writeByte (uint8_t reg, uint8_t data)
|
|
50
|
+
{
|
|
51
|
+
uint8_t spiData [4] ;
|
|
52
|
+
|
|
53
|
+
spiData [0] = CMD_WRITE ;
|
|
54
|
+
spiData [1] = reg ;
|
|
55
|
+
spiData [2] = data ;
|
|
56
|
+
|
|
57
|
+
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* readByte:
|
|
62
|
+
* Read a byte from a register on the MCP23S17 on the SPI bus.
|
|
63
|
+
*********************************************************************************
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
static uint8_t readByte (uint8_t reg)
|
|
67
|
+
{
|
|
68
|
+
uint8_t spiData [4] ;
|
|
69
|
+
|
|
70
|
+
spiData [0] = CMD_READ ;
|
|
71
|
+
spiData [1] = reg ;
|
|
72
|
+
|
|
73
|
+
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
|
|
74
|
+
|
|
75
|
+
return spiData [2] ;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* digitalWrite:
|
|
81
|
+
* Perform the digitalWrite function on the PiFace board
|
|
82
|
+
*********************************************************************************
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
void digitalWritePiFace (struct wiringPiNodeStruct *node, int pin, int value)
|
|
86
|
+
{
|
|
87
|
+
uint8_t mask, old ;
|
|
88
|
+
|
|
89
|
+
pin -= node->pinBase ;
|
|
90
|
+
mask = 1 << pin ;
|
|
91
|
+
old = readByte (MCP23x17_GPIOA) ;
|
|
92
|
+
|
|
93
|
+
if (value == 0)
|
|
94
|
+
old &= (~mask) ;
|
|
95
|
+
else
|
|
96
|
+
old |= mask ;
|
|
97
|
+
|
|
98
|
+
writeByte (MCP23x17_GPIOA, old) ;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
* digitalReadPiFace:
|
|
104
|
+
* Perform the digitalRead function on the PiFace board
|
|
105
|
+
*********************************************************************************
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
int digitalReadPiFace (struct wiringPiNodeStruct *node, int pin)
|
|
109
|
+
{
|
|
110
|
+
uint8_t mask, reg ;
|
|
111
|
+
|
|
112
|
+
pin -= node->pinBase ;
|
|
113
|
+
mask = 1 << (pin & 7) ;
|
|
114
|
+
|
|
115
|
+
if (pin < 8)
|
|
116
|
+
reg = MCP23x17_GPIOB ; // Input regsiter
|
|
117
|
+
else
|
|
118
|
+
reg = MCP23x17_OLATA ; // Output latch regsiter
|
|
119
|
+
|
|
120
|
+
if ((readByte (reg) & mask) != 0)
|
|
121
|
+
return HIGH ;
|
|
122
|
+
else
|
|
123
|
+
return LOW ;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
* pullUpDnControlPiFace:
|
|
129
|
+
* Perform the pullUpDnControl function on the PiFace board
|
|
130
|
+
*********************************************************************************
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
void pullUpDnControlPiFace (struct wiringPiNodeStruct *node, int pin, int pud)
|
|
134
|
+
{
|
|
135
|
+
uint8_t mask, old ;
|
|
136
|
+
|
|
137
|
+
pin -= node->pinBase ;
|
|
138
|
+
mask = 1 << pin ;
|
|
139
|
+
old = readByte (MCP23x17_GPPUB) ;
|
|
140
|
+
|
|
141
|
+
if (pud == 0)
|
|
142
|
+
old &= (~mask) ;
|
|
143
|
+
else
|
|
144
|
+
old |= mask ;
|
|
145
|
+
|
|
146
|
+
writeByte (MCP23x17_GPPUB, old) ;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* piFaceSetup
|
|
152
|
+
* Setup the SPI interface and initialise the MCP23S17 chip
|
|
153
|
+
* We create one node with 16 pins - each if the first 8 pins being read
|
|
154
|
+
* and write - although the operations actually go to different
|
|
155
|
+
* hardware ports. The top 8 let you read the state of the output register.
|
|
156
|
+
*********************************************************************************
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
int piFaceSetup (int pinBase)
|
|
160
|
+
{
|
|
161
|
+
int x ;
|
|
162
|
+
struct wiringPiNodeStruct *node ;
|
|
163
|
+
|
|
164
|
+
if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0)
|
|
165
|
+
return x ;
|
|
166
|
+
|
|
167
|
+
// Setup the MCP23S17
|
|
168
|
+
|
|
169
|
+
writeByte (MCP23x17_IOCON, IOCON_INIT) ;
|
|
170
|
+
writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs
|
|
171
|
+
writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs
|
|
172
|
+
|
|
173
|
+
node = wiringPiNewNode (pinBase, 16) ;
|
|
174
|
+
node->digitalRead = digitalReadPiFace ;
|
|
175
|
+
node->digitalWrite = digitalWritePiFace ;
|
|
176
|
+
node->pullUpDnControl = pullUpDnControlPiFace ;
|
|
177
|
+
|
|
178
|
+
return 0 ;
|
|
179
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piFace.h:
|
|
3
|
+
* Control the PiFace Interface board for the Raspberry Pi
|
|
4
|
+
* Copyright (c) 2012-2013 Gordon Henderson
|
|
5
|
+
***********************************************************************
|
|
6
|
+
* This file is part of wiringPi:
|
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
8
|
+
*
|
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU Lesser General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
20
|
+
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
+
***********************************************************************
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#ifdef __cplusplus
|
|
25
|
+
extern "C" {
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
extern int piFaceSetup (int pinBase) ;
|
|
29
|
+
|
|
30
|
+
#ifdef __cplusplus
|
|
31
|
+
}
|
|
32
|
+
#endif
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piHiPri:
|
|
3
|
+
* Simple way to get your program running at high priority
|
|
4
|
+
* with realtime schedulling.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2012 Gordon Henderson
|
|
7
|
+
***********************************************************************
|
|
8
|
+
* This file is part of wiringPi:
|
|
9
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
10
|
+
*
|
|
11
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
+
* License, or (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU Lesser General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
22
|
+
* License along with wiringPi.
|
|
23
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
+
***********************************************************************
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <sched.h>
|
|
28
|
+
#include <string.h>
|
|
29
|
+
|
|
30
|
+
#include "wiringPi.h"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* piHiPri:
|
|
35
|
+
* Attempt to set a high priority schedulling for the running program
|
|
36
|
+
*********************************************************************************
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
int piHiPri (int pri)
|
|
40
|
+
{
|
|
41
|
+
struct sched_param sched ;
|
|
42
|
+
|
|
43
|
+
memset (&sched, 0, sizeof(sched)) ;
|
|
44
|
+
|
|
45
|
+
if (pri > sched_get_priority_max (SCHED_RR))
|
|
46
|
+
pri = sched_get_priority_max (SCHED_RR) ;
|
|
47
|
+
|
|
48
|
+
sched.sched_priority = pri ;
|
|
49
|
+
return sched_setscheduler (0, SCHED_RR, &sched) ;
|
|
50
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piNes.c:
|
|
3
|
+
* Driver for the NES Joystick controller on the Raspberry Pi
|
|
4
|
+
* Copyright (c) 2012 Gordon Henderson
|
|
5
|
+
***********************************************************************
|
|
6
|
+
* This file is part of wiringPi:
|
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
8
|
+
*
|
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
12
|
+
* License, or (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU Lesser General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
20
|
+
* License along with wiringPi.
|
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
***********************************************************************
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include "wiringPi.h"
|
|
26
|
+
|
|
27
|
+
#include "piNes.h"
|
|
28
|
+
|
|
29
|
+
#define MAX_NES_JOYSTICKS 8
|
|
30
|
+
|
|
31
|
+
#define NES_RIGHT 0x01
|
|
32
|
+
#define NES_LEFT 0x02
|
|
33
|
+
#define NES_DOWN 0x04
|
|
34
|
+
#define NES_UP 0x08
|
|
35
|
+
#define NES_START 0x10
|
|
36
|
+
#define NES_SELECT 0x20
|
|
37
|
+
#define NES_B 0x40
|
|
38
|
+
#define NES_A 0x80
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#define PULSE_TIME 25
|
|
42
|
+
|
|
43
|
+
// Data to store the pins for each controller
|
|
44
|
+
|
|
45
|
+
struct nesPinsStruct
|
|
46
|
+
{
|
|
47
|
+
unsigned int cPin, dPin, lPin ;
|
|
48
|
+
} ;
|
|
49
|
+
|
|
50
|
+
static struct nesPinsStruct nesPins [MAX_NES_JOYSTICKS] ;
|
|
51
|
+
|
|
52
|
+
static int joysticks = 0 ;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* setupNesJoystick:
|
|
57
|
+
* Create a new NES joystick interface, program the pins, etc.
|
|
58
|
+
*********************************************************************************
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
int setupNesJoystick (int dPin, int cPin, int lPin)
|
|
62
|
+
{
|
|
63
|
+
if (joysticks == MAX_NES_JOYSTICKS)
|
|
64
|
+
return -1 ;
|
|
65
|
+
|
|
66
|
+
nesPins [joysticks].dPin = dPin ;
|
|
67
|
+
nesPins [joysticks].cPin = cPin ;
|
|
68
|
+
nesPins [joysticks].lPin = lPin ;
|
|
69
|
+
|
|
70
|
+
digitalWrite (lPin, LOW) ;
|
|
71
|
+
digitalWrite (cPin, LOW) ;
|
|
72
|
+
|
|
73
|
+
pinMode (lPin, OUTPUT) ;
|
|
74
|
+
pinMode (cPin, OUTPUT) ;
|
|
75
|
+
pinMode (dPin, INPUT) ;
|
|
76
|
+
|
|
77
|
+
return joysticks++ ;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* readNesJoystick:
|
|
83
|
+
* Do a single scan of the NES Joystick.
|
|
84
|
+
*********************************************************************************
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
unsigned int readNesJoystick (int joystick)
|
|
88
|
+
{
|
|
89
|
+
unsigned int value = 0 ;
|
|
90
|
+
int i ;
|
|
91
|
+
|
|
92
|
+
struct nesPinsStruct *pins = &nesPins [joystick] ;
|
|
93
|
+
|
|
94
|
+
// Toggle Latch - which presents the first bit
|
|
95
|
+
|
|
96
|
+
digitalWrite (pins->lPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
|
|
97
|
+
digitalWrite (pins->lPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
|
|
98
|
+
|
|
99
|
+
// Read first bit
|
|
100
|
+
|
|
101
|
+
value = digitalRead (pins->dPin) ;
|
|
102
|
+
|
|
103
|
+
// Now get the next 7 bits with the clock
|
|
104
|
+
|
|
105
|
+
for (i = 0 ; i < 7 ; ++i)
|
|
106
|
+
{
|
|
107
|
+
digitalWrite (pins->cPin, HIGH) ; delayMicroseconds (PULSE_TIME) ;
|
|
108
|
+
digitalWrite (pins->cPin, LOW) ; delayMicroseconds (PULSE_TIME) ;
|
|
109
|
+
value = (value << 1) | digitalRead (pins->dPin) ;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return value ^ 0xFF ;
|
|
113
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piNes.h:
|
|
3
|
+
* Driver for the NES Joystick controller on the Raspberry Pi
|
|
4
|
+
* Copyright (c) 2012 Gordon Henderson
|
|
5
|
+
***********************************************************************
|
|
6
|
+
* This file is part of wiringPi:
|
|
7
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
8
|
+
*
|
|
9
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
11
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
12
|
+
* License, or (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU Lesser General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
20
|
+
* License along with wiringPi.
|
|
21
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
***********************************************************************
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#define MAX_NES_JOYSTICKS 8
|
|
26
|
+
|
|
27
|
+
#define NES_RIGHT 0x01
|
|
28
|
+
#define NES_LEFT 0x02
|
|
29
|
+
#define NES_DOWN 0x04
|
|
30
|
+
#define NES_UP 0x08
|
|
31
|
+
#define NES_START 0x10
|
|
32
|
+
#define NES_SELECT 0x20
|
|
33
|
+
#define NES_B 0x40
|
|
34
|
+
#define NES_A 0x80
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
extern "C" {
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
extern int setupNesJoystick (int dPin, int cPin, int lPin) ;
|
|
41
|
+
extern unsigned int readNesJoystick (int joystick) ;
|
|
42
|
+
|
|
43
|
+
#ifdef __cplusplus
|
|
44
|
+
}
|
|
45
|
+
#endif
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* piThread.c:
|
|
3
|
+
* Provide a simplified interface to pthreads
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2012 Gordon Henderson
|
|
6
|
+
***********************************************************************
|
|
7
|
+
* This file is part of wiringPi:
|
|
8
|
+
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
|
9
|
+
*
|
|
10
|
+
* wiringPi is free software: you can redistribute it and/or modify
|
|
11
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
12
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
13
|
+
* License, or (at your option) any later version.
|
|
14
|
+
*
|
|
15
|
+
* wiringPi is distributed in the hope that it will be useful,
|
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
* GNU Lesser General Public License for more details.
|
|
19
|
+
*
|
|
20
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
21
|
+
* License along with wiringPi.
|
|
22
|
+
* If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
***********************************************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <pthread.h>
|
|
27
|
+
#include "wiringPi.h"
|
|
28
|
+
|
|
29
|
+
static pthread_mutex_t piMutexes [4] ;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
* piThreadCreate:
|
|
35
|
+
* Create and start a thread
|
|
36
|
+
*********************************************************************************
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
int piThreadCreate (void *(*fn)(void *))
|
|
40
|
+
{
|
|
41
|
+
pthread_t myThread ;
|
|
42
|
+
|
|
43
|
+
return pthread_create (&myThread, NULL, fn, NULL) ;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* piLock: piUnlock:
|
|
48
|
+
* Activate/Deactivate a mutex.
|
|
49
|
+
* We're keeping things simple here and only tracking 4 mutexes which
|
|
50
|
+
* is more than enough for out entry-level pthread programming
|
|
51
|
+
*********************************************************************************
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
void piLock (int key)
|
|
55
|
+
{
|
|
56
|
+
pthread_mutex_lock (&piMutexes [key]) ;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void piUnlock (int key)
|
|
60
|
+
{
|
|
61
|
+
pthread_mutex_unlock (&piMutexes [key]) ;
|
|
62
|
+
}
|
|
63
|
+
|