diff options
author | siddhu8990 | 2016-06-27 19:16:41 +0530 |
---|---|---|
committer | siddhu8990 | 2016-06-27 19:16:41 +0530 |
commit | 169db0082ebd07baea82d00213db6ffd4dee7cf6 (patch) | |
tree | c6644d701b64dd82a9d17aab12f5dccb10672126 /src/c/hardware/rasberrypi | |
parent | 396de3715ed2615f81325661c264341165f0edb2 (diff) | |
download | Scilab2C_fossee_old-169db0082ebd07baea82d00213db6ffd4dee7cf6.tar.gz Scilab2C_fossee_old-169db0082ebd07baea82d00213db6ffd4dee7cf6.tar.bz2 Scilab2C_fossee_old-169db0082ebd07baea82d00213db6ffd4dee7cf6.zip |
test commit
Diffstat (limited to 'src/c/hardware/rasberrypi')
5 files changed, 24 insertions, 53 deletions
diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c index 8ce0b3c..d9ff093 100644 --- a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c +++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c @@ -10,29 +10,15 @@ Email: toolbox@scilab.in */ -/* Function to read the state of the gpio pin - - Calling Sequence - u8RPI_DigitalIn(pin) - - Parameters - pin : pin of RPi to be read - - Returns - state: Current state of the specified gpio pin - - Description - There are few pins available on RPi as Gpio or digital i/o. These pins can be used as digital output or input. Using this function, current state (low/high) of any gpio pin can be read. 'pin' name must be provided from list provided. Please refer '' for complete list of pins. 'state' can be 0 or 1 depending upon state of the pin (Low/High). RPI_DigitalSetup with appropriate arguments must be called before using this function. - Examples - u8RPI_DigitalIn(RPI_GPIO_P1_03,1) //Returns the state of pin 3 of header P1 -*/ +/* Function to read the state of the gpio pin */ #include "types.h" #include "RPIPeripheralDigital.h" +/*pin is reduced by one as array index starts from 0 and pin no starts from 1*/ uint8 u8RPIDigitalIns(uint8 pin) { uint8 state = 0; - state = bcm2835_gpio_lev(pin); + state = bcm2835_gpio_lev(phy_pin[pin-1]); return (state); } diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c index d97f458..97c6a03 100644 --- a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c +++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c @@ -10,30 +10,17 @@ Email: toolbox@scilab.in */ -/* Function to change the output state of the gpio pin - - Calling Sequence - u8RPI_DigitalOuts(pin,state) - - Parameters - pin : pin of RPi to be used - state : desired output state for pin (0 -> LOW, 1 -> HIGH) - - Description - There are few pins available on RPi as Gpio or digital i/o. These pins can be used as digital output or input. 'Pin' name must be provided from list provided. Please refer '' for complete list of pins. 'state' can be 0 or 1 depending upon desired output (Low/High). RPI_DigitalSetup with appropriate arguments must be called before using this function. - Examples - u8RPI_DigitalOuts(RPI_GPIO_P1_03,1) //Sets pin 3 of header P1 as 'high' output -*/ +/* Function to change the output state of the gpio pin */ #include "types.h" #include "RPIPeripheralDigital.h" - +/*pin is reduced by one as arrayiindex starts from 0 and pin no starts from 1*/ uint8 u8RPIDigitalOuts(uint8 pin, uint8 state) { if (state == 0) //low output - bcm2835_gpio_clr(pin); + bcm2835_gpio_clr(phy_pin[pin-1]); if (state == 1) //high output - bcm2835_gpio_set(pin); + bcm2835_gpio_set(phy_pin[pin-1]); } diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c index 657df3a..79668b1 100644 --- a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c +++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c @@ -10,35 +10,31 @@ Email: toolbox@scilab.in */ -/* Function to setup digital pins. - - Calling Sequence - u8RPI_DigitalSetup(pin,direction) - - Parameters - pin : pin of RPi to be used - direction : direction to be set for pin (0 -> INPUT, 1 -> OUTPUT) - - Description - There are few pins available on RPi as Gpio or digital io. These pins can be used as digital output or input. Pin name must be provided from list provided. Please refer '' for complete list of pins. Direction can be 0 or 1 depending upon desired function (Input/output) - Examples - RPI_DigitalSetup(RPI_GPIO_P1_03,0) //Sets pin 3 of header P1 as input - - See also - RPI_DigitalIn RPI_DigitalOut +/* Function to setup digital pins + direction = 1 -> output */ #include "types.h" #include "RPIPeripheralDigital.h" + +/*This array maps pin numbers on RPi board, with actual physical pin numbers +on processor, required by BCM2835 library*/ +int phy_pin[] = {0, 0, 2, 0, 3, 0, 4, 14, 0, 15, /*Pin 1 to 10*/ + 17, 18, 27, 0, 22, 23, 0, 24, 10, 0, /*Pin 11 to 20*/ + 9, 25, 11, 8, 0, 7 }; /*Pin 21 to 26*/ + +/*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 { - bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP); + bcm2835_gpio_fsel(phy_pin[pin-1], BCM2835_GPIO_FSEL_OUTP); } else { - bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_INPT); + bcm2835_gpio_fsel(phy_pin[pin-1], BCM2835_GPIO_FSEL_INPT); } + + return 0; } diff --git a/src/c/hardware/rasberrypi/includes/RPIPeripheralDigital.h b/src/c/hardware/rasberrypi/includes/RPIPeripheralDigital.h index 87fe7dc..e56366c 100644 --- a/src/c/hardware/rasberrypi/includes/RPIPeripheralDigital.h +++ b/src/c/hardware/rasberrypi/includes/RPIPeripheralDigital.h @@ -23,6 +23,8 @@ extern "C" { #include "types.h" #include "bcm2835.h" +extern int phy_pin[]; + uint8 u8RPIDigitalSetups(uint8 pin, uint8 direction); uint8 u8RPIDigitalOuts(uint8 pin, uint8 state); uint8 u8RPIDigitalIns(uint8 pin); diff --git a/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralDigital.h b/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralDigital.h index 056f3cb..40a8e1a 100644 --- a/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralDigital.h +++ b/src/c/hardware/rasberrypi/interfaces/int_RPIPeripheralDigital.h @@ -22,7 +22,7 @@ extern "C" { #define RPI_DigitalSetup(in1,in2) u8RPIDigitalSetups((uint8) in1, (uint8) in2); -#define RPI_DigitalIn(in1,in2) u8RPIDigitalIns((uint8) in1); +#define RPI_DigitalIn(in1) u8RPIDigitalIns((uint8) in1); #define RPI_DigitalOut(in1,in2) u8RPIDigitalOuts((uint8) in1, (uint8) in2); |