diff --git a/devLib/Makefile b/devLib/Makefile index 304d75d..58903a3 100644 --- a/devLib/Makefile +++ b/devLib/Makefile @@ -43,16 +43,15 @@ LIBS = ############################################################################### -SRC = ds1302.c maxdetect.c piNes.c \ - gertboard.c piFace.c \ - lcd128x64.c lcd.c \ - scrollPhat.c \ +SRC = ds1302.c maxdetect.c \ + piNes.c piFace.c \ + lcd128x64.c lcd.c \ + scrollPhat.c \ piGlow.c OBJ = $(SRC:.c=.o) -HEADERS = ds1302.h gertboard.h lcd128x64.h lcd.h maxdetect.h piFace.h piGlow.h piNes.h\ - scrollPhat.h +HEADERS = ds1302.h lcd128x64.h lcd.h maxdetect.h piFace.h piGlow.h piNes.h scrollPhat.h ################################################################################# @@ -110,7 +109,6 @@ depend: ds1302.o: ds1302.h maxdetect.o: maxdetect.h piNes.o: piNes.h -gertboard.o: gertboard.h piFace.o: piFace.h lcd128x64.o: font.h lcd128x64.h lcd.o: lcd.h diff --git a/devLib/gertboard.c b/devLib/gertboard.c deleted file mode 100644 index f65bba3..0000000 --- a/devLib/gertboard.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * gertboard.c: - * Access routines for the SPI devices on the Gertboard - * Copyright (c) 2012 Gordon Henderson - * - * The Gertboard has: - * - * An MCP3002 dual-channel A to D convertor connected - * to the SPI bus, selected by chip-select A, and: - * - * An MCP4802 dual-channel D to A convertor connected - * to the SPI bus, selected via chip-select B. - * - *********************************************************************** - * This file is part of wiringPi: - * https://github.com/WiringPi/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 . - *********************************************************************** - */ - - -#include -#include -#include -#include -#include - -#include -#include - -#include "gertboard.h" - -// The A-D convertor won't run at more than 1MHz @ 3.3v - -#define SPI_ADC_SPEED 1000000 -#define SPI_DAC_SPEED 1000000 -#define SPI_A2D 0 -#define SPI_D2A 1 - - -/* - * gertboardAnalogWrite: - * Write an 8-bit data value to the MCP4802 Analog to digital - * convertor on the Gertboard. - ********************************************************************************* - */ - -void gertboardAnalogWrite (const int chan, const int value) -{ - uint8_t spiData [2] ; - uint8_t chanBits, dataBits ; - - if (chan == 0) - chanBits = 0x30 ; - else - chanBits = 0xB0 ; - - chanBits |= ((value >> 4) & 0x0F) ; - dataBits = ((value << 4) & 0xF0) ; - - spiData [0] = chanBits ; - spiData [1] = dataBits ; - - wiringPiSPIDataRW (SPI_D2A, spiData, 2) ; -} - - -/* - * gertboardAnalogRead: - * Return the analog value of the given channel (0/1). - * The A/D is a 10-bit device - ********************************************************************************* - */ - -int gertboardAnalogRead (const int chan) -{ - uint8_t spiData [2] ; - - uint8_t chanBits ; - - if (chan == 0) - chanBits = 0b11010000 ; - else - chanBits = 0b11110000 ; - - spiData [0] = chanBits ; - spiData [1] = 0 ; - - wiringPiSPIDataRW (SPI_A2D, spiData, 2) ; - - return ((spiData [0] << 8) | (spiData [1] >> 1)) & 0x3FF ; -} - - -/* - * gertboardSPISetup: - * Initialise the SPI bus, etc. - ********************************************************************************* - */ - -int gertboardSPISetup (void) -{ - if (wiringPiSPISetup (SPI_A2D, SPI_ADC_SPEED) < 0) - return -1 ; - - if (wiringPiSPISetup (SPI_D2A, SPI_DAC_SPEED) < 0) - return -1 ; - - return 0 ; -} - - -/* - * New wiringPi node extension methods. - ********************************************************************************* - */ - -static int myAnalogRead (struct wiringPiNodeStruct *node, const int chan) -{ - return gertboardAnalogRead (chan - node->pinBase) ; -} - -static void myAnalogWrite (struct wiringPiNodeStruct *node, const int chan, const int value) -{ - gertboardAnalogWrite (chan - node->pinBase, value) ; -} - - -/* - * gertboardAnalogSetup: - * Create a new wiringPi device node for the analog devices on the - * Gertboard. We create one node with 2 pins - each pin being read - * and write - although the operations actually go to different - * hardware devices. - ********************************************************************************* - */ - -int gertboardAnalogSetup (const int pinBase) -{ - struct wiringPiNodeStruct *node ; - int x ; - - if (( x = gertboardSPISetup ()) != 0) - return x; - - node = wiringPiNewNode (pinBase, 2) ; - node->analogRead = myAnalogRead ; - node->analogWrite = myAnalogWrite ; - - return 0 ; -} diff --git a/devLib/gertboard.h b/devLib/gertboard.h deleted file mode 100644 index 4107ade..0000000 --- a/devLib/gertboard.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * gertboard.h: - * Access routines for the SPI devices on the Gertboard - * Copyright (c) 2012 Gordon Henderson - * - * The Gertboard has an MCP4802 dual-channel D to A convertor - * connected to the SPI bus, selected via chip-select B. - * - *********************************************************************** - * This file is part of wiringPi: - * https://github.com/WiringPi/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 . - *********************************************************************** - */ - -#ifdef __cplusplus -extern "C" { -#endif - -// Old routines - -extern void gertboardAnalogWrite (const int chan, const int value) ; -extern int gertboardAnalogRead (const int chan) ; -extern int gertboardSPISetup (void) ; - -// New - -extern int gertboardAnalogSetup (const int pinBase) ; - -#ifdef __cplusplus -} -#endif diff --git a/devLib/piFaceOld.c b/devLib/piFaceOld.c deleted file mode 100644 index 51e157d..0000000 --- a/devLib/piFaceOld.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * piFace.: - * Copyright (c) 2012-2016 Gordon Henderson - * - * This file to interface with the PiFace peripheral device which - * has an MCP23S17 GPIO device connected via the SPI bus. - *********************************************************************** - * This file is part of wiringPi: - * https://github.com/WiringPi/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 . - *********************************************************************** - */ - - -#include -#include - -#include -#include - -#include "../wiringPi/mcp23x0817.h" - -#include "piFace.h" - -#define PIFACE_SPEED 4000000 -#define PIFACE_DEVNO 0 - - - -/* - * writeByte: - * Write a byte to a register on the MCP23S17 on the SPI bus. - ********************************************************************************* - */ - -static void writeByte (uint8_t reg, uint8_t data) -{ - uint8_t spiData [4] ; - - spiData [0] = CMD_WRITE ; - spiData [1] = reg ; - spiData [2] = data ; - - wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ; -} - -/* - * readByte: - * Read a byte from a register on the MCP23S17 on the SPI bus. - ********************************************************************************* - */ - -static uint8_t readByte (uint8_t reg) -{ - uint8_t spiData [4] ; - - spiData [0] = CMD_READ ; - spiData [1] = reg ; - - wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ; - - return spiData [2] ; -} - - -/* - * myDigitalWrite: - * Perform the digitalWrite function on the PiFace board - ********************************************************************************* - */ - -void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value) -{ - uint8_t mask, old ; - - pin -= node->pinBase ; - mask = 1 << pin ; - old = readByte (MCP23x17_GPIOA) ; - - if (value == 0) - old &= (~mask) ; - else - old |= mask ; - - writeByte (MCP23x17_GPIOA, old) ; -} - - -/* - * myDigitalRead: - * Perform the digitalRead function on the PiFace board - ********************************************************************************* - */ - -int myDigitalRead (struct wiringPiNodeStruct *node, int pin) -{ - uint8_t mask, reg ; - - mask = 1 << ((pin - node->pinBase) & 7) ; - - if (pin < 8) - reg = MCP23x17_GPIOB ; // Input regsiter - else - reg = MCP23x17_OLATA ; // Output latch regsiter - - if ((readByte (reg) & mask) != 0) - return HIGH ; - else - return LOW ; -} - - -/* - * myPullUpDnControl: - * Perform the pullUpDnControl function on the PiFace board - ********************************************************************************* - */ - -void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud) -{ - uint8_t mask, old ; - - mask = 1 << (pin - node->pinBase) ; - old = readByte (MCP23x17_GPPUB) ; - - if (pud == 0) - old &= (~mask) ; - else - old |= mask ; - - writeByte (MCP23x17_GPPUB, old) ; -} - - -/* - * piFaceSetup - * Setup the SPI interface and initialise the MCP23S17 chip - * We create one node with 16 pins - each if the first 8 pins being read - * and write - although the operations actually go to different - * hardware ports. The top 8 let you read the state of the output register. - ********************************************************************************* - */ - -int piFaceSetup (const int pinBase) -{ - int x ; - struct wiringPiNodeStruct *node ; - - if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0) - return x ; - -// Setup the MCP23S17 - - writeByte (MCP23x17_IOCON, IOCON_INIT) ; - writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs - writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs - - node = wiringPiNewNode (pinBase, 16) ; - node->digitalRead = myDigitalRead ; - node->digitalWrite = myDigitalWrite ; - node->pullUpDnControl = myPullUpDnControl ; - - return 0 ; -}