3 * This file to interface with the PiFace peripheral device which
4 * has an MCP23S17 GPIO device connected via the SPI bus.
6 * Copyright (c) 2012-2013 Gordon Henderson
7 ***********************************************************************
8 * This file is part of wiringPi:
9 * https://projects.drogon.net/raspberry-pi/wiringpi/
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.
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.
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 ***********************************************************************
39 * Perform the digitalWrite function on the PiFace board
40 *********************************************************************************
43 void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
45 digitalWrite (pin + 16, value) ;
51 * Perform the digitalRead function on the PiFace board
52 * With a slight twist - if we read from base + 8, then we
53 * read from the output latch...
54 *********************************************************************************
57 int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
59 if ((pin - node->pinBase) >= 8)
60 return digitalRead (pin + 8) ;
62 return digitalRead (pin + 16 + 8) ;
68 * Perform the pullUpDnControl function on the PiFace board
69 *********************************************************************************
72 void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
74 pullUpDnControl (pin + 16 + 8, pud) ;
80 * We're going to create an instance of the mcp23s17 here, then
81 * provide our own read/write routines on-top of it...
82 * The supplied PiFace code (in Pithon) treats it as an 8-bit device
83 * where you write the output ports and read the input port using the
84 * same pin numbers, however I have had a request to be able to read
85 * the output port, so reading 8..15 will read the output latch.
86 *********************************************************************************
89 int piFaceSetup (const int pinBase)
92 struct wiringPiNodeStruct *node ;
94 // Create an mcp23s17 instance:
96 mcp23s17Setup (pinBase + 16, 0, 0) ;
98 // Set the direction bits
100 for (i = 0 ; i < 8 ; ++i)
102 pinMode (pinBase + 16 + i, OUTPUT) ; // Port A is the outputs
103 pinMode (pinBase + 16 + 8 + i, INPUT) ; // Port B inputs.
106 node = wiringPiNewNode (pinBase, 16) ;
107 node->digitalRead = myDigitalRead ;
108 node->digitalWrite = myDigitalWrite ;
109 node->pullUpDnControl = myPullUpDnControl ;