More typos, added mcp3004/mcp3008

This commit is contained in:
Gordon Henderson
2013-05-21 22:38:16 +01:00
parent 41fb1b9e2a
commit 711017ec36
8 changed files with 247 additions and 5 deletions

View File

@@ -51,7 +51,7 @@ SRC = wiringPi.c \
mcp23s08.c mcp23s17.c \
sr595.c \
pcf8574.c pcf8591.c \
mcp3002.c mcp4802.c mcp3422.c \
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
drc.c
OBJ = $(SRC:.c=.o)
@@ -102,6 +102,7 @@ install-headers:
@install -m 0644 mcp23s08.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp23s17.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp3002.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp3004.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp4802.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp3422.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 sr595.h $(DESTDIR)$(PREFIX)/include
@@ -138,6 +139,7 @@ uninstall:
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23s08.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23s17.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp3002.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp3004.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp4802.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp3422.h
@rm -f $(DESTDIR)$(PREFIX)/include/sr595.h

73
wiringPi/mcp3004.c Normal file
View File

@@ -0,0 +1,73 @@
/*
* mcp3004.c:
* Extend wiringPi with the MCP3004 SPI Analog to Digital convertor
* Copyright (c) 2012-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 <wiringPi.h>
#include <wiringPiSPI.h>
#include "mcp3004.h"
/*
* myAnalogRead:
* Return the analog value of the given pin
*********************************************************************************
*/
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
{
unsigned char spiData [2] ;
unsigned char chanBits ;
int chan = pin - node->pinBase ;
chanBits = 0b11000000 | (chan << 3) ;
spiData [0] = chanBits ;
spiData [1] = 0 ;
wiringPiSPIDataRW (node->fd, spiData, 2) ;
return ((spiData [0] << 7) | (spiData [1] >> 1)) & 0x3FF ;
}
/*
* mcp3004Setup:
* Create a new wiringPi device node for an mcp3004 on the Pi's
* SPI interface.
*********************************************************************************
*/
int mcp3004Setup (const int pinBase, int spiChannel)
{
struct wiringPiNodeStruct *node ;
if (wiringPiSPISetup (spiChannel, 1000000) < 0)
return -1 ;
node = wiringPiNewNode (pinBase, 8) ;
node->fd = spiChannel ;
node->analogRead = myAnalogRead ;
return 0 ;
}

33
wiringPi/mcp3004.h Normal file
View File

@@ -0,0 +1,33 @@
/*
* mcp3004.c:
* Extend wiringPi with the MCP3004 SPI Analog to Digital convertor
* Copyright (c) 2012-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 mcp3004Setup (int pinBase, int spiChannel) ;
#ifdef __cplusplus
}
#endif

View File

@@ -1,6 +1,7 @@
/*
* mcp3422.c:
* Extend wiringPi with the MCP3422 I2C ADC chip
* Also works for the MCP3423 and MCP3224 (4 channel) chips
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
@@ -98,7 +99,7 @@ int myAnalogRead (struct wiringPiNodeStruct *node, int chan)
*********************************************************************************
*/
int mcp3422Setup (int pinBase, int i2cAddress, int channels, int sampleRate, int gain)
int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain)
{
int fd ;
struct wiringPiNodeStruct *node ;
@@ -106,7 +107,7 @@ int mcp3422Setup (int pinBase, int i2cAddress, int channels, int sampleRate, int
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
return fd ;
node = wiringPiNewNode (pinBase, channels) ;
node = wiringPiNewNode (pinBase, 4) ;
node->data0 = sampleRate ;
node->data1 = gain ;

View File

@@ -36,7 +36,7 @@
extern "C" {
#endif
extern int mcp3422Setup (int pinBase, int i2cAddress, int channels, int sampleRate, int gain) ;
extern int mcp3422Setup (int pinBase, int i2cAddress, int sampleRate, int gain) ;
#ifdef __cplusplus
}