diff options
Diffstat (limited to '2.3-1/src/c/hardware/rasberrypi')
19 files changed, 230 insertions, 61 deletions
diff --git a/2.3-1/src/c/hardware/rasberrypi/ISR/i16RPIPinISRs.c b/2.3-1/src/c/hardware/rasberrypi/ISR/i16RPIPinISRs.c index 425fc979..6e398a17 100644 --- a/2.3-1/src/c/hardware/rasberrypi/ISR/i16RPIPinISRs.c +++ b/2.3-1/src/c/hardware/rasberrypi/ISR/i16RPIPinISRs.c @@ -16,7 +16,7 @@ #include "RPIPeripheralPinISR.h" #include "RPIPeripheralDigital.h" -int16 i16RPIPinISRs(uint8 pin, uint8 edgetype, void (*ISRFunction)) +int16 i16RPIPinISRs(uint8 pin, uint8 edgetype, void (*ISRFunction)(void)) { int status; status = wiringPiISR((int)phy_pin[pin-1], (int) edgetype, ISRFunction); diff --git a/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c b/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c index d40263f2..a5f80e5d 100644 --- a/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c +++ b/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c @@ -19,8 +19,10 @@ /*pin is reduced by one as array index starts from 0 and pin no starts from 1*/ uint8 u8RPIDigitalOuts(uint8 pin, uint8 state) { - if (state == 0) //low output + if (state == 0) /*low output*/ digitalWrite(phy_pin[pin-1], LOW); - if (state == 1) //high output + if (state == 1) /*high output*/ digitalWrite(phy_pin[pin-1], HIGH); + + return 0; } diff --git a/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c b/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c index 163f0c87..37cfc037 100644 --- a/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c +++ b/2.3-1/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c @@ -28,14 +28,13 @@ int phy_pin[] = {17, 17, 8, 17, 9, 17, 7, 15, 17, 16, /*Pin 1 to 10*/ /*pin is reduced by one as arrayiindex starts from 0 and pin no starts from 1*/ uint8 u8RPIDigitalSetups(uint8 pin, uint8 direction) { - if(direction == 1) //Pin to be used as output - { - pinMode(phy_pin[pin-1], OUTPUT); - } + if(direction == 1) /*Pin to be used as output*/ + pinMode(phy_pin[pin-1], OUTPUT); + else if(direction == 2) + pinMode(phy_pin[pin-1], PWM_OUTPUT); else - { pinMode(phy_pin[pin-1], INPUT); - } + return 0; } diff --git a/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPWM.h b/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPWM.h new file mode 100644 index 00000000..47634d05 --- /dev/null +++ b/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPWM.h @@ -0,0 +1,31 @@ + /* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __RPIPERIPHERALPWM_H__ +#define __RPIPERIPHERALPWM_H__ + +#include "types.h" +#include "wiringPi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +uint8 u8RPIHardPWMWrites(uint8 pin, uint16 value); +uint8 u8RPIHardPWMSetRanges(uint16 value); +uint8 u8RPIHardPWMSetModes(uint8 mode); +uint8 u8RPIHardPWMSetClocks(uint16 clk_divisor); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__RPIPERIPHERALPWM_H__*/ diff --git a/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPinISR.h b/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPinISR.h index de05f908..fc5a8d04 100644 --- a/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPinISR.h +++ b/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralPinISR.h @@ -17,7 +17,7 @@ extern "C" { #endif -int16 i16RPIPinISRs(uint8 pin, uint8 edgetype, void (*ISRFunction)); +int16 i16RPIPinISRs(uint8 pin, uint8 edgetype, void (*ISRFunction)(void)); #ifdef __cplusplus } /* extern "C" */ diff --git a/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralThreading.h b/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralThreading.h index 4c5d3a55..23045677 100644 --- a/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralThreading.h +++ b/2.3-1/src/c/hardware/rasberrypi/includes/RPIPeripheralThreading.h @@ -19,7 +19,7 @@ extern "C" { #endif -uint16 RPIThreadCreate(void (*threadFunction)); +uint16 RPIThreadCreate(void *(*threadFunction)(void)); #ifdef __cplusplus } /* extern "C" */ diff --git a/2.3-1/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralPWM.h b/2.3-1/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralPWM.h new file mode 100644 index 00000000..8c8f4c62 --- /dev/null +++ b/2.3-1/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralPWM.h @@ -0,0 +1,30 @@ + /* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_RPIPERIPHERALPWM_H__ +#define __INT_RPIPERIPHERALPWM_H__ + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define RPI_HardPWMWrite(pin,value) u8RPIHardPWMWrites((uint8)pin,(uint16)value) +#define RPI_HardPWMSetRange(value) u8RPIHardPWMSetRanges((uint16)value) +#define RPI_HardPWMSetMode(mode) u8RPIHardPWMSetModes((uint8)mode) +#define RPI_HardPWMSetClock(clk_divisor) u8RPIHardPWMSetClocks((uint16)clk_divisor) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__INT_RPIPERIPHERALPWM_H__*/ diff --git a/2.3-1/src/c/hardware/rasberrypi/libraries/wiringPi/wiringPi.h b/2.3-1/src/c/hardware/rasberrypi/libraries/wiringPi/wiringPi.h index e11a0bef..a5eea873 100644 --- a/2.3-1/src/c/hardware/rasberrypi/libraries/wiringPi/wiringPi.h +++ b/2.3-1/src/c/hardware/rasberrypi/libraries/wiringPi/wiringPi.h @@ -24,17 +24,17 @@ #ifndef __WIRING_PI_H__ #define __WIRING_PI_H__ -// C doesn't have true/false by default and I can never remember which -// way round they are, so ... - +/* C doesn't have true/false by default and I can never remember which + way round they are, so ... +*/ #ifndef TRUE # define TRUE (1==1) # define FALSE (!TRUE) #endif -// Handy defines +/* Handy defines*/ -// wiringPi modes +/* wiringPi modes*/ #define WPI_MODE_PINS 0 #define WPI_MODE_GPIO 1 @@ -43,7 +43,7 @@ #define WPI_MODE_PIFACE 4 #define WPI_MODE_UNINITIALISED -1 -// Pin modes +/* Pin modes*/ #define INPUT 0 #define OUTPUT 1 @@ -56,27 +56,27 @@ #define LOW 0 #define HIGH 1 -// Pull up/down/none +/* Pull up/down/none*/ #define PUD_OFF 0 #define PUD_DOWN 1 #define PUD_UP 2 -// PWM +/* PWM*/ #define PWM_MODE_MS 0 #define PWM_MODE_BAL 1 -// Interrupt levels +/*Interrupt levels*/ #define INT_EDGE_SETUP 0 #define INT_EDGE_FALLING 1 #define INT_EDGE_RISING 2 #define INT_EDGE_BOTH 3 -// Pi model types and version numbers -// Intended for the GPIO program Use at your own risk. - +/*Pi model types and version numbers + Intended for the GPIO program Use at your own risk. +*/ #define PI_MODEL_A 0 #define PI_MODEL_B 1 #define PI_MODEL_AP 2 @@ -104,36 +104,36 @@ extern const char *piMakerNames [16] ; extern const int piMemorySize [ 8] ; -// Intended for the GPIO program Use at your own risk. +/* Intended for the GPIO program Use at your own risk.*/ -// Threads +/* Threads*/ #define PI_THREAD(X) void *X (void *dummy) -// Failure modes +/* Failure modes*/ #define WPI_FATAL (1==1) #define WPI_ALMOST (1==2) -// wiringPiNodeStruct: -// This describes additional device nodes in the extended wiringPi -// 2.0 scheme of things. -// It's a simple linked list for now, but will hopefully migrate to -// a binary tree for efficiency reasons - but then again, the chances -// of more than 1 or 2 devices being added are fairly slim, so who -// knows.... - +/*wiringPiNodeStruct: + This describes additional device nodes in the extended wiringPi + 2.0 scheme of things. + It's a simple linked list for now, but will hopefully migrate to + a binary tree for efficiency reasons - but then again, the chances + of more than 1 or 2 devices being added are fairly slim, so who + knows.... +*/ struct wiringPiNodeStruct { int pinBase ; int pinMax ; - int fd ; // Node specific - unsigned int data0 ; // ditto - unsigned int data1 ; // ditto - unsigned int data2 ; // ditto - unsigned int data3 ; // ditto + int fd ; /* Node specific*/ + unsigned int data0 ; /* ditto*/ + unsigned int data1 ; /* ditto*/ + unsigned int data2 ; /* ditto*/ + unsigned int data3 ; /* ditto*/ void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ; void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ; @@ -149,21 +149,21 @@ struct wiringPiNodeStruct extern struct wiringPiNodeStruct *wiringPiNodes ; -// Function prototypes -// c++ wrappers thanks to a comment by Nick Lott -// (and others on the Raspberry Pi forums) - +/*Function prototypes + c++ wrappers thanks to a comment by Nick Lott + (and others on the Raspberry Pi forums) +*/ #ifdef __cplusplus extern "C" { #endif -// Data +/* Data*/ -// Internal +/* Internal*/ extern int wiringPiFailure (int fatal, const char *message, ...) ; -// Core wiringPi functions +/* Core wiringPi functions*/ extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ; extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ; @@ -182,13 +182,13 @@ extern void pwmWrite (int pin, int value) ; extern int analogRead (int pin) ; extern void analogWrite (int pin, int value) ; -// PiFace specifics -// (Deprecated) +/* PiFace specifics + (Deprecated)*/ extern int wiringPiSetupPiFace (void) ; -extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only +extern int wiringPiSetupPiFaceForGpioProg (void) ; /* Don't use this - for gpio program only*/ -// On-Board Raspberry Pi hardware specific stuff +/* On-Board Raspberry Pi hardware specific stuff*/ extern int piBoardRev (void) ; extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ; @@ -204,23 +204,23 @@ extern void pwmSetRange (unsigned int range) ; extern void pwmSetClock (int divisor) ; extern void gpioClockSet (int pin, int freq) ; -// Interrupts -// (Also Pi hardware specific) +/* Interrupts + (Also Pi hardware specific)*/ extern int waitForInterrupt (int pin, int mS) ; extern int wiringPiISR (int pin, int mode, void (*function)(void)) ; -// Threads +/* Threads*/ extern int piThreadCreate (void *(*fn)(void *)) ; extern void piLock (int key) ; extern void piUnlock (int key) ; -// Schedulling priority +/* Schedulling priority*/ extern int piHiPri (const int pri) ; -// Extras from arduino land +/* Extras from arduino land*/ extern void delay (unsigned int howLong) ; extern void delayMicroseconds (unsigned int howLong) ; diff --git a/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetClocks.c b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetClocks.c new file mode 100644 index 00000000..883f3faf --- /dev/null +++ b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetClocks.c @@ -0,0 +1,27 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + +/*Function to set clock for pwm channel. Default clock is 19.2 MHz. 'clk_divisor' + along with range decides frequency for PWM + PWM frequency = 19.2 MHz / clk_divisor/ range + Range for clk_divisor = 1-2048 + */ + +#include "types.h" +#include "RPIPeripheralPWM.h" + +uint8 u8RPIHardPWMSetClocks(uint16 clk_divisor) +{ + pwmSetClock(clk_divisor); + + return 0; +} diff --git a/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetModes.c b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetModes.c new file mode 100644 index 00000000..5a7ccd15 --- /dev/null +++ b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetModes.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + +/*Function to set mode for PWM channel. Two modes are available + 0 --> balanced mode + 1 --> mark/space mode + */ + +#include "types.h" +#include "RPIPeripheralPWM.h" + +uint8 u8RPIHardPWMSetModes(uint8 mode) +{ + if (mode == 1) /*mark/space mode*/ + pwmSetMode(PWM_MODE_MS); + else + pwmSetMode(PWM_MODE_BAL); + return 0; +} diff --git a/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetRanges.c b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetRanges.c new file mode 100644 index 00000000..e3cda77e --- /dev/null +++ b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMSetRanges.c @@ -0,0 +1,25 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + +/*Function to assigne pwm duty to specified pin. PWM duty is decided by 'value' + and 'range' specified using corresponding function. + PWM duty = value/range + */ + +#include "types.h" +#include "RPIPeripheralPWM.h" + +uint8 u8RPIHardPWMSetRanges(uint16 value) +{ + pwmSetRange(value); + return 0; +} diff --git a/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMWrites.c b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMWrites.c new file mode 100644 index 00000000..546cfd5f --- /dev/null +++ b/2.3-1/src/c/hardware/rasberrypi/pwm/u8RPIHardPWMWrites.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + +/*Function to set range for pwm channel. PWM duty is decided by 'range' + and 'value' specified using corresponding function. + PWM duty = value/range + */ + +#include "types.h" +#include "RPIPeripheralPWM.h" +#include "RPIPeripheralDigital.h" + +uint8 u8RPIHardPWMWrites(uint8 pin, uint16 value) +{ + pwmWrite((int)phy_pin[pin-1], value); + return 0; +} diff --git a/2.3-1/src/c/hardware/rasberrypi/serial/dRPISerialSendDatas.c b/2.3-1/src/c/hardware/rasberrypi/serial/dRPISerialSendDatas.c index 163e9c7d..c1553f79 100644 --- a/2.3-1/src/c/hardware/rasberrypi/serial/dRPISerialSendDatas.c +++ b/2.3-1/src/c/hardware/rasberrypi/serial/dRPISerialSendDatas.c @@ -28,7 +28,7 @@ uint8 dRPISerialSendDatas(int fd, double data) for(count=0; count<sizeof(double); count++) { - //Send lsb first + /*Send lsb first*/ serialPutchar(fd, (uint8) in_data.bytes[count]); } diff --git a/2.3-1/src/c/hardware/rasberrypi/serial/i16RPISerialSendDatas.c b/2.3-1/src/c/hardware/rasberrypi/serial/i16RPISerialSendDatas.c index 861d7d89..ff6edfff 100644 --- a/2.3-1/src/c/hardware/rasberrypi/serial/i16RPISerialSendDatas.c +++ b/2.3-1/src/c/hardware/rasberrypi/serial/i16RPISerialSendDatas.c @@ -17,7 +17,7 @@ uint8 i16RPISerialSendDatas(int fd, int16 data) { - //Send lsb first + /*Send lsb first*/ serialPutchar(fd, (uint8) data); serialPutchar(fd, (uint8) (data>>8)); diff --git a/2.3-1/src/c/hardware/rasberrypi/serial/sRPISerialSendDatas.c b/2.3-1/src/c/hardware/rasberrypi/serial/sRPISerialSendDatas.c index a8c34d0e..bd0cd949 100644 --- a/2.3-1/src/c/hardware/rasberrypi/serial/sRPISerialSendDatas.c +++ b/2.3-1/src/c/hardware/rasberrypi/serial/sRPISerialSendDatas.c @@ -27,7 +27,7 @@ uint8 sRPISerialSendDatas(int fd, float data) for(count=0; count<sizeof(float); count++) { - //Send lsb first + /*Send lsb first*/ serialPutchar(fd, (uint8) in_data.bytes[count]); } diff --git a/2.3-1/src/c/hardware/rasberrypi/serial/u16RPISerialSendDatas.c b/2.3-1/src/c/hardware/rasberrypi/serial/u16RPISerialSendDatas.c index 5b2d0568..2f0536c3 100644 --- a/2.3-1/src/c/hardware/rasberrypi/serial/u16RPISerialSendDatas.c +++ b/2.3-1/src/c/hardware/rasberrypi/serial/u16RPISerialSendDatas.c @@ -17,7 +17,7 @@ uint8 u16RPISerialSendDatas(int fd, uint16 data) { - //Send lsb first + /*Send lsb first*/ serialPutchar(fd, (uint8) data); serialPutchar(fd, (uint8) (data>>8)); diff --git a/2.3-1/src/c/hardware/rasberrypi/threading/u16RPIThreadCreates.c b/2.3-1/src/c/hardware/rasberrypi/threading/u16RPIThreadCreates.c index d94beff4..d0a063ac 100644 --- a/2.3-1/src/c/hardware/rasberrypi/threading/u16RPIThreadCreates.c +++ b/2.3-1/src/c/hardware/rasberrypi/threading/u16RPIThreadCreates.c @@ -15,7 +15,7 @@ #include "types.h" #include "RPIPeripheralThreading.h" -uint16 RPIThreadCreate(void (*threadFunction)) +uint16 RPIThreadCreate(void *(*threadFunction)(void)) { int status; status = piThreadCreate (threadFunction); diff --git a/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMicros.c b/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMicros.c index 48418c09..fe756c96 100644 --- a/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMicros.c +++ b/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMicros.c @@ -18,5 +18,6 @@ uint8 u16RPIDelayMicros(uint16 time) { delayMicroseconds(time); + return 0; } diff --git a/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMillis.c b/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMillis.c index 2dc59bbf..d7be3f88 100644 --- a/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMillis.c +++ b/2.3-1/src/c/hardware/rasberrypi/timing/u16RPIDelayMillis.c @@ -20,6 +20,6 @@ uint8 u16RPIDelayMillis(uint16 time) { delay(time); - + return 0; } |