Synced to git.drogon.net

This commit is contained in:
Gordon Henderson
2013-03-24 20:04:07 +00:00
committed by Philip Howard
parent dda3305ce1
commit 3fbc564d00
41 changed files with 1829 additions and 425 deletions

View File

@@ -1,4 +1,4 @@
#
# ;
# Makefile:
# wiringPi - Wiring Compatable library for the Raspberry Pi
#
@@ -45,13 +45,19 @@ LIBS =
SRC = wiringPi.c wiringPiFace.c wiringSerial.c wiringShift.c \
gertboard.c \
piNes.c \
lcd.c piHiPri.c piThread.c wiringPiSPI.c \
lcd.c piHiPri.c piThread.c \
wiringPiSPI.c \
softPwm.c softServo.c softTone.c
SRC_I2C = wiringPiI2C.c
OBJ = $(SRC:.c=.o)
all: $(STATIC) $(DYNAMIC)
#all: $(DYNAMIC)
OBJ_I2C = $(SRC_I2C:.c=.o)
all: $(DYNAMIC)
static: $(STATIC)
$(STATIC): $(OBJ)
@echo "[Link (Static)]"
@@ -63,13 +69,17 @@ $(DYNAMIC): $(OBJ)
@echo "[Link (Dynamic)]"
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ)
i2c: $(OBJ) $(OBJ_I2C)
@echo "[Link (Dynamic + I2C)]"
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ) $(OBJ_I2C)
.c.o:
@echo [Compile] $<
@$(CC) -c $(CFLAGS) $< -o $@
.PHONEY: clean
clean:
rm -f $(OBJ) *~ core tags Makefile.bak libwiringPi.*
rm -f $(OBJ) $(OBJ_I2C) *~ core tags Makefile.bak libwiringPi.*
.PHONEY: tags
tags: $(SRC)
@@ -77,7 +87,7 @@ tags: $(SRC)
@ctags $(SRC)
.PHONEY: install
install: $(TARGET)
install: $(DYNAMIC)
@echo "[Install]"
@install -m 0755 -d $(DESTDIR)$(PREFIX)/lib
@install -m 0755 -d $(DESTDIR)$(PREFIX)/include
@@ -91,12 +101,17 @@ install: $(TARGET)
@install -m 0644 softTone.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 lcd.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 wiringPiSPI.h $(DESTDIR)$(PREFIX)/include
@install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
@install -m 0644 wiringPiI2C.h $(DESTDIR)$(PREFIX)/include
@install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so.1
@ldconfig
.PHONEY: install-static
install-static: $(STATIC)
@echo "[Install Static]"
@install -m 0755 libwiringPi.a $(DESTDIR)$(PREFIX)/lib
.PHONEY: uninstall
uninstall:
@echo "[UnInstall]"
@@ -110,13 +125,14 @@ uninstall:
@rm -f $(DESTDIR)$(PREFIX)/include/softTone.h
@rm -f $(DESTDIR)$(PREFIX)/include/lcd.h
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiSPI.h
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiI2C.h
@rm -f $(DESTDIR)$(PREFIX)/lib/libwiringPi.*
@ldconfig
.PHONEY: depend
depend:
makedepend -Y $(SRC)
makedepend -Y $(SRC) $(SRC_I2C)
# DO NOT DELETE
@@ -129,5 +145,8 @@ piNes.o: wiringPi.h piNes.h
lcd.o: wiringPi.h lcd.h
piHiPri.o: wiringPi.h
piThread.o: wiringPi.h
softPwm.o: wiringPi.h softPwm.h
wiringPiSPI.o: wiringPiSPI.h
softPwm.o: wiringPi.h softPwm.h
softServo.o: wiringPi.h softServo.h
softTone.o: wiringPi.h softTone.h
wiringPiI2C.o: wiringPi.h wiringPiI2C.h

View File

@@ -174,6 +174,18 @@ void lcdClear (int fd)
}
/*
* lcdSendCommand:
* Send any arbitary command to the display
*********************************************************************************
*/
void lcdSendCommand (int fd, uint8_t command)
{
struct lcdDataStruct *lcd = lcds [fd] ;
putCommand (lcd, command) ;
}
/*
* lcdPosition:
* Update the position of the cursor on the display

View File

@@ -30,12 +30,13 @@
extern "C" {
#endif
extern void lcdHome (int fd) ;
extern void lcdClear (int fd) ;
extern void lcdPosition (int fd, int x, int y) ;
extern void lcdPutchar (int fd, uint8_t data) ;
extern void lcdPuts (int fd, char *string) ;
extern void lcdPrintf (int fd, char *message, ...) ;
extern void lcdHome (int fd) ;
extern void lcdClear (int fd) ;
extern void lcdSendCommand (int fd, uint8_t command) ;
extern void lcdPosition (int fd, int x, int y) ;
extern void lcdPutchar (int fd, uint8_t data) ;
extern void lcdPuts (int fd, char *string) ;
extern void lcdPrintf (int fd, char *message, ...) ;
extern int lcdInit (int rows, int cols, int bits, int rs, int strb,
int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) ;

BIN
wiringPi/libwiringPi.so.1.0 Executable file

Binary file not shown.

89
wiringPi/q2w.c Normal file
View File

@@ -0,0 +1,89 @@
/*
* q2w.c:
***********************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
// MCP23S17 Registers
#define IOCON 0x0A
#define IODIRA 0x00
#define IPOLA 0x02
#define GPINTENA 0x04
#define DEFVALA 0x06
#define INTCONA 0x08
#define GPPUA 0x0C
#define INTFA 0x0E
#define INTCAPA 0x10
#define GPIOA 0x12
#define OLATA 0x14
#define IODIRB 0x01
#define IPOLB 0x03
#define GPINTENB 0x05
#define DEFVALB 0x07
#define INTCONB 0x09
#define GPPUB 0x0D
#define INTFB 0x0F
#define INTCAPB 0x11
#define GPIOB 0x13
#define OLATB 0x15
// Bits in the IOCON register
#define IOCON_BANK_MODE 0x80
#define IOCON_MIRROR 0x40
#define IOCON_SEQOP 0x20
#define IOCON_DISSLW 0x10
#define IOCON_HAEN 0x08
#define IOCON_ODR 0x04
#define IOCON_INTPOL 0x02
#define IOCON_UNUSED 0x01
// Default initialisation mode
#define IOCON_INIT (IOCON_SEQOP)
/*
*********************************************************************************
* The works
*********************************************************************************
*/
int main (int argc, char *argv [])
{
int q2w ;
// if (wiringPiSetup () == -1)
// { fprintf (stderr, "q2w: Unable to initialise wiringPi: %s\n", strerror (errno)) ; return 1 ; }
if ((q2w = wiringPiI2CSetup (0x20)) == -1)
{ fprintf (stderr, "q2w: Unable to initialise I2C: %s\n", strerror (errno)) ; return 1 ; }
// Very simple direct control of the MCP23017:
wiringPiI2CWriteReg8 (q2w, IOCON, IOCON_INIT) ;
wiringPiI2CWriteReg8 (q2w, IODIRA, 0x00) ; // Port A -> Outputs
wiringPiI2CWriteReg8 (q2w, IODIRB, 0x00) ; // Port B -> Outputs
for (;;)
{
wiringPiI2CWriteReg8 (q2w, GPIOA, 0x00) ; // All Off
delay (500) ;
wiringPiI2CWriteReg8 (q2w, GPIOA, 0xFF) ; // All On
delay (500) ;
}
return 0 ;
}

View File

@@ -54,6 +54,15 @@
// the multipexing, but it does need to be at least 10mS, and preferably 16
// from what I've been able to determine.
// WARNING:
// This code is really experimental. It was written in response to some people
// asking for a servo driver, however while it works, there is too much
// jitter to successfully drive a small servo - I have tried it with a micro
// servo and it worked, but the servo ran hot due to the jitter in the signal
// being sent to it.
//
// If you want servo control for the Pi, then use the servoblaster kernel
// module.
#define MAX_SERVOS 8

View File

@@ -59,7 +59,9 @@ static PI_THREAD (softToneThread)
for (;;)
{
frewq = frewqs [pin] ;
if (frewq != 0)
if (frewq == 0)
delay (1) ;
else
{
halfPeriod = 500000 / frewq ;

File diff suppressed because it is too large Load Diff

View File

@@ -23,32 +23,50 @@
// Handy defines
// Deprecated
#define NUM_PINS 17
#define WPI_MODE_PINS 0
#define WPI_MODE_GPIO 1
#define WPI_MODE_GPIO_SYS 2
#define WPI_MODE_PIFACE 3
#define WPI_MODE_UNINITIALISED -1
#define INPUT 0
#define OUTPUT 1
#define PWM_OUTPUT 2
// Pin modes
#define LOW 0
#define HIGH 1
#define INPUT 0
#define OUTPUT 1
#define PWM_OUTPUT 2
#define GPIO_CLOCK 3
#define PUD_OFF 0
#define PUD_DOWN 1
#define PUD_UP 2
#define LOW 0
#define HIGH 1
// Pull up/down/none
#define PUD_OFF 0
#define PUD_DOWN 1
#define PUD_UP 2
// PWM
#define PWM_MODE_MS 0
#define PWM_MODE_BAL 1
#define PWM_MODE_MS 0
#define PWM_MODE_BAL 1
// Interrupt levels
#define INT_EDGE_SETUP 0
#define INT_EDGE_FALLING 1
#define INT_EDGE_RISING 2
#define INT_EDGE_BOTH 3
// Threads
#define PI_THREAD(X) void *X (void *dummy)
// Function prototypes
// c++ wrappers thanks to a commend by Nick Lott
// c++ wrappers thanks to a comment by Nick Lott
// (and others on the Raspberry Pi forums)
#ifdef __cplusplus
@@ -68,13 +86,14 @@ extern int wpiPinToGpio (int wpiPin) ;
extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
extern void (*pinMode) (int pin, int mode) ;
extern int (*getAlt) (int pin) ;
extern void (*pullUpDnControl) (int pin, int pud) ;
extern void (*digitalWrite) (int pin, int value) ;
extern void (*digitalWriteByte) (int value) ;
extern void (*gpioClockSet) (int pin, int freq) ;
extern void (*pwmWrite) (int pin, int value) ;
extern void (*setPadDrive) (int group, int value) ;
extern int (*digitalRead) (int pin) ;
extern void (*delayMicroseconds) (unsigned int howLong) ;
extern void (*pwmSetMode) (int mode) ;
extern void (*pwmSetRange) (unsigned int range) ;
extern void (*pwmSetClock) (int divisor) ;
@@ -82,11 +101,10 @@ extern void (*pwmSetClock) (int divisor) ;
// Interrupts
extern int (*waitForInterrupt) (int pin, int mS) ;
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
// Threads
#define PI_THREAD(X) void *X (void *dummy)
extern int piThreadCreate (void *(*fn)(void *)) ;
extern void piLock (int key) ;
extern void piUnlock (int key) ;
@@ -99,7 +117,9 @@ extern int piHiPri (int pri) ;
// Extras from arduino land
extern void delay (unsigned int howLong) ;
extern void delayMicroseconds (unsigned int howLong) ;
extern unsigned int millis (void) ;
extern unsigned int micros (void) ;
#ifdef __cplusplus
}

122
wiringPi/wiringPiI2C.c Normal file
View File

@@ -0,0 +1,122 @@
/*
* wiringPiI2C.c:
* Simplified I2C access routines
* 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 <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"
/*
* wiringPiI2CRead:
* Simple device read
*********************************************************************************
*/
int wiringPiI2CRead (int fd)
{
return i2c_smbus_read_byte (fd) ;
}
/*
* wiringPiI2CReadReg8: wiringPiI2CReadReg16:
* Read an 8 or 16-bit value from a regsiter on the device
*********************************************************************************
*/
int wiringPiI2CReadReg8 (int fd, int reg)
{
return i2c_smbus_read_byte_data (fd, reg) ;
}
int wiringPiI2CReadReg16 (int fd, int reg)
{
return i2c_smbus_read_word_data (fd, reg) ;
}
/*
* wiringPiI2CWrite:
* Simple device write
*********************************************************************************
*/
int wiringPiI2CWrite (int fd, int data)
{
return i2c_smbus_write_byte (fd, data) ;
}
/*
* wiringPiI2CWriteReg8: wiringPiI2CWriteReg16:
* Write an 8 or 16-bit value to the given register
*********************************************************************************
*/
int wiringPiI2CWriteReg8 (int fd, int reg, int data)
{
return i2c_smbus_write_byte_data (fd, reg, data) ;
}
int wiringPiI2CWriteReg16 (int fd, int reg, int data)
{
return i2c_smbus_write_word_data (fd, reg, data) ;
}
/*
* wiringPiI2CSetup:
* Open the I2C device, and regsiter the target device
*********************************************************************************
*/
int wiringPiI2CSetup (int devId)
{
int rev, fd ;
char *device ;
if ((rev = piBoardRev ()) < 0)
{
fprintf (stderr, "wiringPiI2CSetup: Unable to determine Pi board revision\n") ;
exit (1) ;
}
if (rev == 1)
device = "/dev/i2c-0" ;
else
device = "/dev/i2c-1" ;
if ((fd = open (device, O_RDWR)) < 0)
return -1 ;
if (ioctl (fd, I2C_SLAVE, devId) < 0)
return -1 ;
return fd ;
}

41
wiringPi/wiringPiI2C.h Normal file
View File

@@ -0,0 +1,41 @@
/*
* wiringPiI2C.h:
* Simplified I2C access routines
* 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
extern int wiringPiI2CRead (int fd) ;
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
extern int wiringPiI2CWrite (int fd, int data) ;
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
int wiringPiI2CSetup (int devId) ;
#ifdef __cplusplus
}
#endif