Tweaked the mcp3422 code altered the build script to let me build staticpull/22/head
@@ -51,18 +51,30 @@ fi | |||||
echo "WiringPi Library" | echo "WiringPi Library" | ||||
cd wiringPi | cd wiringPi | ||||
sudo make uninstall | sudo make uninstall | ||||
make | |||||
check_make_ok | |||||
sudo make install | |||||
if [ x$1 = "xstatic" ]; then | |||||
make static | |||||
check_make_ok | |||||
sudo make install-static | |||||
else | |||||
make | |||||
check_make_ok | |||||
sudo make install | |||||
fi | |||||
check_make_ok | check_make_ok | ||||
echo | echo | ||||
echo "WiringPi Devices Library" | echo "WiringPi Devices Library" | ||||
cd ../devLib | cd ../devLib | ||||
sudo make uninstall | sudo make uninstall | ||||
make | |||||
check_make_ok | |||||
sudo make install | |||||
if [ x$1 = "xstatic" ]; then | |||||
make static | |||||
check_make_ok | |||||
sudo make install-static | |||||
else | |||||
make | |||||
check_make_ok | |||||
sudo make install | |||||
fi | |||||
check_make_ok | check_make_ok | ||||
echo | echo | ||||
@@ -1,9 +1,10 @@ | |||||
# | # | ||||
# Makefile: | # Makefile: | ||||
# wiringPi - Wiring Compatable library for the Raspberry Pi | |||||
# The gpio command: | |||||
# A swiss-army knige of GPIO shenanigans. | |||||
# https://projects.drogon.net/wiring-pi | # https://projects.drogon.net/wiring-pi | ||||
# | # | ||||
# Copyright (c) 2012 Gordon Henderson | |||||
# Copyright (c) 2012-2013 Gordon Henderson | |||||
################################################################################# | ################################################################################# | ||||
# This file is part of wiringPi: | # This file is part of wiringPi: | ||||
# Wiring Compatable library for the Raspberry Pi | # Wiring Compatable library for the Raspberry Pi | ||||
@@ -28,7 +29,7 @@ PREFIX=/local | |||||
#DEBUG = -g -O0 | #DEBUG = -g -O0 | ||||
DEBUG = -O2 | DEBUG = -O2 | ||||
CC = gcc | CC = gcc | ||||
INCLUDE = -I$(DESTDIR)$(PREFIX)/usr/local/include | |||||
INCLUDE = -I$(DESTDIR)$(PREFIX)/include | |||||
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe | CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe | ||||
LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib | LDFLAGS = -L$(DESTDIR)$(PREFIX)/lib | ||||
@@ -50,6 +50,7 @@ | |||||
#include <mcp4802.h> | #include <mcp4802.h> | ||||
#include <mcp3422.h> | #include <mcp3422.h> | ||||
#include <sn3218.h> | #include <sn3218.h> | ||||
#include <drcSerial.h> | |||||
#include "extensions.h" | #include "extensions.h" | ||||
@@ -99,6 +100,43 @@ static char *extractInt (char *progName, char *p, int *num) | |||||
} | } | ||||
/* | |||||
* extractStr: | |||||
* Check & return a string at the given location (prefixed by a :) | |||||
********************************************************************************* | |||||
*/ | |||||
static char *extractStr (char *progName, char *p, char **str) | |||||
{ | |||||
char *q, *r ; | |||||
if (*p != ':') | |||||
{ | |||||
fprintf (stderr, "%s: colon expected\n", progName) ; | |||||
return NULL ; | |||||
} | |||||
++p ; | |||||
if (!isprint (*p)) | |||||
{ | |||||
fprintf (stderr, "%s: character expected\n", progName) ; | |||||
return NULL ; | |||||
} | |||||
q = p ; | |||||
while ((*q != 0) && (*q != ':')) | |||||
++q ; | |||||
*str = r = calloc (q - p + 2, 1) ; // Zeros it | |||||
while (p != q) | |||||
*r++ = *p++ ; | |||||
return p ; | |||||
} | |||||
/* | /* | ||||
* doExtensionMcp23008: | * doExtensionMcp23008: | ||||
@@ -524,6 +562,51 @@ static int doExtensionMcp3422 (char *progName, int pinBase, char *params) | |||||
return TRUE ; | return TRUE ; | ||||
} | } | ||||
/* | |||||
* doExtensionDrcS: | |||||
* Interface to a DRC Serial system | |||||
* drcs:base:pins:serialPort:baud | |||||
********************************************************************************* | |||||
*/ | |||||
static int doExtensionDrcS (char *progName, int pinBase, char *params) | |||||
{ | |||||
char *port ; | |||||
int pins, baud ; | |||||
if ((params = extractInt (progName, params, &pins)) == NULL) | |||||
return FALSE ; | |||||
if ((pins < 1) || (pins > 100)) | |||||
{ | |||||
fprintf (stderr, "%s: pins (%d) out of range (2-100)\n", progName, pins) ; | |||||
return FALSE ; | |||||
} | |||||
if ((params = extractStr (progName, params, &port)) == NULL) | |||||
return FALSE ; | |||||
if (strlen (port) == 0) | |||||
{ | |||||
fprintf (stderr, "%s: serial port device name required\n", progName) ; | |||||
return FALSE ; | |||||
} | |||||
if ((params = extractInt (progName, params, &baud)) == NULL) | |||||
return FALSE ; | |||||
if ((baud < 1) || (baud > 4000000)) | |||||
{ | |||||
fprintf (stderr, "%s: baud rate (%d) out of range\n", progName, baud) ; | |||||
return FALSE ; | |||||
} | |||||
drcSetupSerial (pinBase, pins, port, baud) ; | |||||
return TRUE ; | |||||
} | |||||
/* | /* | ||||
* Function list | * Function list | ||||
@@ -547,6 +630,7 @@ struct extensionFunctionStruct extensionFunctions [] = | |||||
{ "max31855", &doExtensionMax31855 }, | { "max31855", &doExtensionMax31855 }, | ||||
{ "max5322", &doExtensionMax5322 }, | { "max5322", &doExtensionMax5322 }, | ||||
{ "sn3218", &doExtensionSn3218 }, | { "sn3218", &doExtensionSn3218 }, | ||||
{ "drcs", &doExtensionDrcS }, | |||||
{ NULL, NULL }, | { NULL, NULL }, | ||||
} ; | } ; | ||||
@@ -55,7 +55,7 @@ SRC = wiringPi.c \ | |||||
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \ | mcp3002.c mcp3004.c mcp4802.c mcp3422.c \ | ||||
max31855.c max5322.c \ | max31855.c max5322.c \ | ||||
sn3218.c \ | sn3218.c \ | ||||
drc.c | |||||
drcSerial.c | |||||
OBJ = $(SRC:.c=.o) | OBJ = $(SRC:.c=.o) | ||||
@@ -99,6 +99,7 @@ install-headers: | |||||
@install -m 0644 softTone.h $(DESTDIR)$(PREFIX)/include | @install -m 0644 softTone.h $(DESTDIR)$(PREFIX)/include | ||||
@install -m 0644 wiringPiSPI.h $(DESTDIR)$(PREFIX)/include | @install -m 0644 wiringPiSPI.h $(DESTDIR)$(PREFIX)/include | ||||
@install -m 0644 wiringPiI2C.h $(DESTDIR)$(PREFIX)/include | @install -m 0644 wiringPiI2C.h $(DESTDIR)$(PREFIX)/include | ||||
@install -m 0644 drcSerial.h $(DESTDIR)$(PREFIX)/include | |||||
@install -m 0644 mcp23008.h $(DESTDIR)$(PREFIX)/include | @install -m 0644 mcp23008.h $(DESTDIR)$(PREFIX)/include | ||||
@install -m 0644 mcp23016.h $(DESTDIR)$(PREFIX)/include | @install -m 0644 mcp23016.h $(DESTDIR)$(PREFIX)/include | ||||
@install -m 0644 mcp23017.h $(DESTDIR)$(PREFIX)/include | @install -m 0644 mcp23017.h $(DESTDIR)$(PREFIX)/include | ||||
@@ -139,6 +140,7 @@ uninstall: | |||||
@rm -f $(DESTDIR)$(PREFIX)/include/softTone.h | @rm -f $(DESTDIR)$(PREFIX)/include/softTone.h | ||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiSPI.h | @rm -f $(DESTDIR)$(PREFIX)/include/wiringPiSPI.h | ||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiI2C.h | @rm -f $(DESTDIR)$(PREFIX)/include/wiringPiI2C.h | ||||
@rm -f $(DESTDIR)$(PREFIX)/include/drcSerial.h | |||||
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23008.h | @rm -f $(DESTDIR)$(PREFIX)/include/mcp23008.h | ||||
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23016.h | @rm -f $(DESTDIR)$(PREFIX)/include/mcp23016.h | ||||
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23017.h | @rm -f $(DESTDIR)$(PREFIX)/include/mcp23017.h | ||||
@@ -1,203 +0,0 @@ | |||||
/* | |||||
* drc.c: | |||||
* Extend wiringPi with the DRC control protocll to Arduino | |||||
* 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/>. | |||||
*********************************************************************** | |||||
*/ | |||||
#include <stdio.h> | |||||
#include <time.h> | |||||
#include <string.h> | |||||
#include <errno.h> | |||||
#include "wiringPi.h" | |||||
#include "wiringSerial.h" | |||||
#include "drc.h" | |||||
#ifndef TRUE | |||||
# define TRUE (1==1) | |||||
# define FALSE (1==2) | |||||
#endif | |||||
/* | |||||
* myPinMode: | |||||
* Change the pin mode on the remote DRC device | |||||
********************************************************************************* | |||||
*/ | |||||
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode) | |||||
{ | |||||
/**/ if (mode == OUTPUT) | |||||
serialPutchar (node->fd, 'o') ; // Input | |||||
else if (mode == PWM_OUTPUT) | |||||
serialPutchar (node->fd, 'p') ; // PWM | |||||
else | |||||
serialPutchar (node->fd, 'i') ; // Default to input | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
} | |||||
/* | |||||
* myPullUpDnControl: | |||||
* ATmegas only have pull-up's on of off. No pull-downs. | |||||
********************************************************************************* | |||||
*/ | |||||
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode) | |||||
{ | |||||
// Force pin into input mode | |||||
serialPutchar (node->fd, 'i' ) ; | |||||
serialPutchar (node->fd, pin) ; | |||||
/**/ if (mode == PUD_UP) | |||||
{ | |||||
serialPutchar (node->fd, '1') ; | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
} | |||||
else if (mode == PUD_OFF) | |||||
{ | |||||
serialPutchar (node->fd, '0') ; | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
} | |||||
} | |||||
/* | |||||
* myDigitalWrite: | |||||
********************************************************************************* | |||||
*/ | |||||
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value) | |||||
{ | |||||
serialPutchar (node->fd, value == 0 ? '0' : '1') ; | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
} | |||||
/* | |||||
* myPwmWrite: | |||||
********************************************************************************* | |||||
*/ | |||||
static void myPwmWrite (struct wiringPiNodeStruct *node, int pin, int value) | |||||
{ | |||||
serialPutchar (node->fd, 'v') ; | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
serialPutchar (node->fd, value & 0xFF) ; | |||||
} | |||||
/* | |||||
* myAnalogRead: | |||||
********************************************************************************* | |||||
*/ | |||||
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) | |||||
{ | |||||
int vHi, vLo ; | |||||
serialPutchar (node->fd, 'a') ; | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
vHi = serialGetchar (node->fd) ; | |||||
vLo = serialGetchar (node->fd) ; | |||||
return (vHi << 8) | vLo ; | |||||
} | |||||
/* | |||||
* myDigitalRead: | |||||
********************************************************************************* | |||||
*/ | |||||
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin) | |||||
{ | |||||
serialPutchar (node->fd, 'r') ; // Send read command | |||||
serialPutchar (node->fd, pin - node->pinBase) ; | |||||
return (serialGetchar (node->fd) == '0') ? 0 : 1 ; | |||||
} | |||||
/* | |||||
* drcSetup: | |||||
* Create a new instance of an DRC GPIO interface. | |||||
* Could be a variable nunber of pins here - we might not know in advance | |||||
* if it's an ATmega with 14 pins, or something with less or more! | |||||
********************************************************************************* | |||||
*/ | |||||
int drcSetup (const int pinBase, const int numPins, const char *device) | |||||
{ | |||||
int fd ; | |||||
int ok, tries ; | |||||
time_t then ; | |||||
struct wiringPiNodeStruct *node ; | |||||
if ((fd = serialOpen (device, 115200)) < 0) | |||||
return wiringPiFailure (WPI_ALMOST, "Unable to open DRC device (%s): %s", device, strerror (errno)) ; | |||||
delay (10) ; // May need longer if it's an Uno that reboots on the open... | |||||
// Flush any pending input | |||||
while (serialDataAvail (fd)) | |||||
(void)serialGetchar (fd) ; | |||||
ok = FALSE ; | |||||
for (tries = 1 ; tries < 5 ; ++tries) | |||||
{ | |||||
serialPutchar (fd, '@') ; | |||||
then = time (NULL) + 2 ; | |||||
while (time (NULL) < then) | |||||
if (serialDataAvail (fd)) | |||||
{ | |||||
if (serialGetchar (fd) == '@') | |||||
{ | |||||
ok = TRUE ; | |||||
break ; | |||||
} | |||||
} | |||||
if (ok) | |||||
break ; | |||||
} | |||||
if (!ok) | |||||
{ | |||||
serialClose (fd) ; | |||||
return wiringPiFailure (WPI_FATAL, "Unable to communidate with DRC device") ; | |||||
} | |||||
node = wiringPiNewNode (pinBase, numPins) ; | |||||
node->fd = fd ; | |||||
node->pinMode = myPinMode ; | |||||
node->pullUpDnControl = myPullUpDnControl ; | |||||
node->analogRead = myAnalogRead ; | |||||
node->digitalRead = myDigitalRead ; | |||||
node->digitalWrite = myDigitalWrite ; | |||||
node->pwmWrite = myPwmWrite ; | |||||
return 0 ; | |||||
} |
@@ -1,34 +0,0 @@ | |||||
/* | |||||
* drc.h: | |||||
* Extend wiringPi with the DRC control protocll to Arduino | |||||
* 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 | |||||
int drcSetup (const int pinBase, const int numPins, const char *device) ; | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif |
@@ -25,6 +25,7 @@ | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <unistd.h> | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
@@ -44,7 +45,8 @@ | |||||
int myAnalogRead (struct wiringPiNodeStruct *node, int chan) | int myAnalogRead (struct wiringPiNodeStruct *node, int chan) | ||||
{ | { | ||||
unsigned char config, b0, b1, b2, b3 ; | |||||
unsigned char config ; | |||||
unsigned char buffer [4] ; | |||||
int value = 0 ; | int value = 0 ; | ||||
// One-shot mode, trigger plus the other configs. | // One-shot mode, trigger plus the other configs. | ||||
@@ -57,35 +59,26 @@ int myAnalogRead (struct wiringPiNodeStruct *node, int chan) | |||||
{ | { | ||||
case MCP3422_SR_3_75: // 18 bits | case MCP3422_SR_3_75: // 18 bits | ||||
delay (270) ; | delay (270) ; | ||||
b0 = wiringPiI2CRead (node->fd) ; | |||||
b1 = wiringPiI2CRead (node->fd) ; | |||||
b2 = wiringPiI2CRead (node->fd) ; | |||||
b3 = wiringPiI2CRead (node->fd) ; | |||||
value = ((b0 & 3) << 16) | (b1 << 8) | b2 ; | |||||
read (node->fd, buffer, 4) ; | |||||
value = ((buffer [0] & 3) << 16) | (buffer [1] << 8) | buffer [0] ; | |||||
break ; | break ; | ||||
case MCP3422_SR_15: // 16 bits | case MCP3422_SR_15: // 16 bits | ||||
delay ( 70) ; | delay ( 70) ; | ||||
b0 = wiringPiI2CRead (node->fd) ; | |||||
b1 = wiringPiI2CRead (node->fd) ; | |||||
b2 = wiringPiI2CRead (node->fd) ; | |||||
value = (b0 << 8) | b1 ; | |||||
read (node->fd, buffer, 3) ; | |||||
value = (buffer [0] << 8) | buffer [1] ; | |||||
break ; | break ; | ||||
case MCP3422_SR_60: // 14 bits | case MCP3422_SR_60: // 14 bits | ||||
delay ( 17) ; | delay ( 17) ; | ||||
b0 = wiringPiI2CRead (node->fd) ; | |||||
b1 = wiringPiI2CRead (node->fd) ; | |||||
b2 = wiringPiI2CRead (node->fd) ; | |||||
value = ((b0 & 0x3F) << 8) | b1 ; | |||||
read (node->fd, buffer, 3) ; | |||||
value = ((buffer [0] & 0x3F) << 8) | buffer [1] ; | |||||
break ; | break ; | ||||
case MCP3422_SR_240: // 12 bits | case MCP3422_SR_240: // 12 bits | ||||
delay ( 5) ; | delay ( 5) ; | ||||
b0 = wiringPiI2CRead (node->fd) ; | |||||
b1 = wiringPiI2CRead (node->fd) ; | |||||
b2 = wiringPiI2CRead (node->fd) ; | |||||
value = ((b0 & 0x0F) << 8) | b1 ; | |||||
read (node->fd, buffer, 3) ; | |||||
value = ((buffer [0] & 0x0F) << 8) | buffer [0] ; | |||||
break ; | break ; | ||||
} | } | ||||