From 0282d5dc561ec8fb12f274fe45e6a7a145fc2774 Mon Sep 17 00:00:00 2001 From: Jim Parziale Date: Sun, 6 Feb 2022 14:08:24 -0500 Subject: [PATCH] Updates before trying to submit to the official WiringPi repo. --- examples/isr.c | 2 + examples/isr1.c | 2 + examples/pwm.c | 2 + examples/pwm1.c | 93 ------------- examples/servo.c | 31 +++-- gpio/newVersion | 26 ---- wiringPi/README | 2 +- wiringPi/wiringPiFace.c | 362 ------------------------------------------------ 8 files changed, 24 insertions(+), 496 deletions(-) delete mode 100644 examples/pwm1.c delete mode 100755 gpio/newVersion delete mode 100755 wiringPi/wiringPiFace.c diff --git a/examples/isr.c b/examples/isr.c index 3e2c178..e9256b7 100644 --- a/examples/isr.c +++ b/examples/isr.c @@ -29,6 +29,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with wiringPi. If not, see . *********************************************************************** + * Updates: 2021 J. Parziale + *********************************************************************** */ #include diff --git a/examples/isr1.c b/examples/isr1.c index 25e94e5..d504fd0 100644 --- a/examples/isr1.c +++ b/examples/isr1.c @@ -29,6 +29,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with wiringPi. If not, see . *********************************************************************** + * Updates: 2021 J. Parziale + *********************************************************************** */ #include diff --git a/examples/pwm.c b/examples/pwm.c index 6843ee3..a10e99b 100755 --- a/examples/pwm.c +++ b/examples/pwm.c @@ -20,6 +20,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with wiringPi. If not, see . *********************************************************************** + * Updates: 2021 J. Parziale + *********************************************************************** */ #include diff --git a/examples/pwm1.c b/examples/pwm1.c deleted file mode 100644 index c1fc331..0000000 --- a/examples/pwm1.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * pwm.c: - * Test of the software PWM driver. Needs 12 LEDs connected - * to the Pi. - * - * 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 . - *********************************************************************** - */ - -#include -#include -#include - -#include -#include - -#define RANGE 100 -#define NUM_LEDS 12 - -int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 } ; - -int values [NUM_LEDS] = { 0, 17, 32, 50, 67, 85, 100, 85, 67, 50, 32, 17 } ; - -int main () -{ - int i, j ; - char buf [80] ; - - if (wiringPiSetup () == -1) - { - fprintf (stdout, "oops: %s\n", strerror (errno)) ; - return 1 ; - } - - for (i = 0 ; i < NUM_LEDS ; ++i) - { - softPwmCreate (ledMap [i], 0, RANGE) ; - printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ; - } - - fgets (buf, 80, stdin) ; - -// Bring all up one by one: - - for (i = 0 ; i < NUM_LEDS ; ++i) - for (j = 0 ; j <= 100 ; ++j) - { - softPwmWrite (ledMap [i], j) ; - delay (10) ; - } - - fgets (buf, 80, stdin) ; - -// Down fast - - for (i = 100 ; i > 0 ; --i) - { - for (j = 0 ; j < NUM_LEDS ; ++j) - softPwmWrite (ledMap [j], i) ; - delay (10) ; - } - - fgets (buf, 80, stdin) ; - - for (;;) - { - for (i = 0 ; i < NUM_LEDS ; ++i) - softPwmWrite (ledMap [i], values [i]) ; - - delay (50) ; - - i = values [0] ; - for (j = 0 ; j < NUM_LEDS - 1 ; ++j) - values [j] = values [j + 1] ; - values [NUM_LEDS - 1] = i ; - } -} diff --git a/examples/servo.c b/examples/servo.c index b759572..f9e40a5 100755 --- a/examples/servo.c +++ b/examples/servo.c @@ -45,20 +45,23 @@ int main() softServoSetup(cPin, -1, -1, -1, -1, -1, -1, -1); -// softServoWrite(1, -250); -// delay(1000); -// softServoWrite(1, 0); -// delay(1000); -// softServoWrite(1, 50); -// delay(1000); -// softServoWrite(1, 150); -// delay(1000); -// softServoWrite(1, 200); -// delay(1000); -// softServoWrite(1, 250); -// delay(1000); -// softServoWrite(1, 1250); -// delay(1000); + /* + softServoWrite(1, -250); + delay(1000); + softServoWrite(1, 0); + delay(1000); + softServoWrite(1, 50); + delay(1000); + softServoWrite(1, 150); + delay(1000); + softServoWrite(1, 200); + delay(1000); + softServoWrite(1, 250); + delay(1000); + softServoWrite(1, 1250); + delay(1000); + */ + /* softServoWrite (1, 1000) ; delay(1000); softServoWrite (2, 1100) ; delay(1000); diff --git a/gpio/newVersion b/gpio/newVersion deleted file mode 100755 index b8728a5..0000000 --- a/gpio/newVersion +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# -# newVersion: -# Utility to create the version.h include file for the gpio command. -# -# Copyright (c) 2012-2015 Gordon Henderson -################################################################################# -# This file is part of wiringPi: -# Wiring Compatable library for the Raspberry Pi -# -# 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 . -################################################################################# - -rm -f version.h -echo "#define VERSION \"`cat ../VERSION`\"" > version.h diff --git a/wiringPi/README b/wiringPi/README index 8afde83..9c6abcc 100755 --- a/wiringPi/README +++ b/wiringPi/README @@ -4,5 +4,5 @@ An implementation of most of the Arduino Wiring functions for the Raspberry Pi, along with many more features and libraries to support hardware, etc. on the Raspberry Pi Full details at: -https://projects.drogon.net/raspberry-pi/wiringpi/ +https://github.com/WiringPi/WiringPi diff --git a/wiringPi/wiringPiFace.c b/wiringPi/wiringPiFace.c deleted file mode 100755 index ac3c6fa..0000000 --- a/wiringPi/wiringPiFace.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * wiringPiFace: - * Arduino compatable (ish) Wiring library for the Raspberry Pi - * Copyright (c) 2012 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://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 . - *********************************************************************** - */ - - -#include -#include -#include -#include -#include -#include - -#include "wiringPi.h" - - -// The SPI bus parameters -// Variables as they need to be passed as pointers later on - -static char *spiDevice = "/dev/spidev0.0" ; -static uint8_t spiMode = 0 ; -static uint8_t spiBPW = 8 ; -static uint32_t spiSpeed = 5000000 ; -static uint16_t spiDelay = 0; - -// Locals here to keep track of everything - -static int spiFd ; - -// The MCP23S17 doesn't have bit-set operations, so it's -// cheaper to keep a copy here than to read/modify/write it - -uint8_t dataOutRegister = 0 ; -uint8_t pudRegister = 0 ; - -// 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) - -// Command codes - -#define CMD_WRITE 0x40 -#define CMD_READ 0x41 - - -/* - * writeByte: - * Write a byte to a register on the MCP23S17 on the SPI bus. - * This is using the synchronous access mechanism. - ********************************************************************************* - */ - -static void writeByte (uint8_t reg, uint8_t data) -{ - uint8_t spiBufTx [3] ; - uint8_t spiBufRx [3] ; - struct spi_ioc_transfer spi ; - - spiBufTx [0] = CMD_WRITE ; - spiBufTx [1] = reg ; - spiBufTx [2] = data ; - - spi.tx_buf = (unsigned long)spiBufTx ; - spi.rx_buf = (unsigned long)spiBufRx ; - spi.len = 3 ; - spi.delay_usecs = spiDelay ; - spi.speed_hz = spiSpeed ; - spi.bits_per_word = spiBPW ; - - ioctl (spiFd, SPI_IOC_MESSAGE(1), &spi) ; -} - -/* - * readByte: - * Read a byte from a register on the MCP23S17 on the SPI bus. - * This is the synchronous access mechanism. - * What appears to happen is that the data returned is at - * the same offset as the number of bytes written to the device. So if we - * write 2 bytes (e.g. command then register number), then the data returned - * will by at the 3rd byte... - ********************************************************************************* - */ - -static uint8_t readByte (uint8_t reg) -{ - uint8_t tx [4] ; - uint8_t rx [4] ; - struct spi_ioc_transfer spi ; - - tx [0] = CMD_READ ; - tx [1] = reg ; - tx [2] = 0 ; - - spi.tx_buf = (unsigned long)tx ; - spi.rx_buf = (unsigned long)rx ; - spi.len = 3 ; - spi.delay_usecs = spiDelay ; - spi.speed_hz = spiSpeed ; - spi.bits_per_word = spiBPW ; - - ioctl (spiFd, SPI_IOC_MESSAGE(1), &spi) ; - - return rx [2] ; -} - - -/* - * digitalWritePiFace: - * Perform the digitalWrite function on the PiFace board - ********************************************************************************* - */ - -void digitalWritePiFace (int pin, int value) -{ - uint8_t mask = 1 << pin ; - - if (value == 0) - dataOutRegister &= (~mask) ; - else - dataOutRegister |= mask ; - - writeByte (GPIOA, dataOutRegister) ; -} - -void digitalWriteBytePiFace (int value) -{ - writeByte (GPIOA, value) ; -} - - -void digitalWritePiFaceSpecial (int pin, int value) -{ - uint8_t mask = 1 << pin ; - uint8_t old ; - - old = readByte (GPIOA) ; - - if (value == 0) - old &= (~mask) ; - else - old |= mask ; - - writeByte (GPIOA, old) ; -} - - -/* - * digitalReadPiFace: - * Perform the digitalRead function on the PiFace board - ********************************************************************************* - */ - -int digitalReadPiFace (int pin) -{ - uint8_t mask = 1 << pin ; - - if ((readByte (GPIOB) & mask) != 0) - return HIGH ; - else - return LOW ; -} - - -/* - * pullUpDnControlPiFace: - * Perform the pullUpDnControl function on the PiFace board - ********************************************************************************* - */ - -void pullUpDnControlPiFace (int pin, int pud) -{ - uint8_t mask = 1 << pin ; - - if (pud == PUD_UP) - pudRegister |= mask ; - else - pudRegister &= (~mask) ; - - writeByte (GPPUB, pudRegister) ; - -} - - -void pullUpDnControlPiFaceSpecial (int pin, int pud) -{ - uint8_t mask = 1 << pin ; - uint8_t old ; - - old = readByte (GPPUB) ; - - if (pud == PUD_UP) - old |= mask ; - else - old &= (~mask) ; - - writeByte (GPPUB, old) ; - -} - - - -/* - * Dummy functions that are not used in this mode - ********************************************************************************* - */ - -void pinModePiFace (int pin, int mode) {} -void pwmWritePiFace (int pin, int value) {} -int waitForInterruptPiFace (int pin, int mS) { return 0 ; } - - -/* - * wiringPiSetupPiFace - * Setup the SPI interface and initialise the MCP23S17 chip - ********************************************************************************* - */ - -static int _wiringPiSetupPiFace (void) -{ - if ((spiFd = open (spiDevice, O_RDWR)) < 0) - return -1 ; - -// Set SPI parameters -// Why are we doing a read after write? -// I don't know - just blindliy copying an example elsewhere... -GH- - - if (ioctl (spiFd, SPI_IOC_WR_MODE, &spiMode) < 0) - return -1 ; - - if (ioctl (spiFd, SPI_IOC_RD_MODE, &spiMode) < 0) - return -1 ; - - if (ioctl (spiFd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0) - return -1 ; - - if (ioctl (spiFd, SPI_IOC_RD_BITS_PER_WORD, &spiBPW) < 0) - return -1 ; - - if (ioctl (spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &spiSpeed) < 0) - return -1 ; - - if (ioctl (spiFd, SPI_IOC_RD_MAX_SPEED_HZ, &spiSpeed) < 0) - return -1 ; - -// Setup the MCP23S17 - - writeByte (IOCON, IOCON_INIT) ; - - writeByte (IODIRA, 0x00) ; // Port A -> Outputs - writeByte (IODIRB, 0xFF) ; // Port B -> Inputs - - return 0 ; -} - - -int wiringPiSetupPiFace (void) -{ - int x = _wiringPiSetupPiFace () ; - - if (x != 0) - return x ; - - writeByte (GPIOA, 0x00) ; // Set all outptus off - writeByte (GPPUB, 0x00) ; // Disable any pull-ups on port B - - pinMode = pinModePiFace ; - pullUpDnControl = pullUpDnControlPiFace ; - digitalWrite = digitalWritePiFace ; - digitalWriteByte = digitalWriteBytePiFace ; - pwmWrite = pwmWritePiFace ; - digitalRead = digitalReadPiFace ; - waitForInterrupt = waitForInterruptPiFace ; - - return 0 ; -} - - -/* - * wiringPiSetupPiFaceForGpioProg: - * Setup the SPI interface and initialise the MCP23S17 chip - * Special version for the gpio program - ********************************************************************************* - */ - - -int wiringPiSetupPiFaceForGpioProg (void) -{ - int x = _wiringPiSetupPiFace () ; - - if (x != 0) - return x ; - - pinMode = pinModePiFace ; - pullUpDnControl = pullUpDnControlPiFaceSpecial ; - digitalWrite = digitalWritePiFaceSpecial ; - digitalWriteByte = digitalWriteBytePiFace ; - pwmWrite = pwmWritePiFace ; - digitalRead = digitalReadPiFace ; - waitForInterrupt = waitForInterruptPiFace ; - - return 0 ; -}