summaryrefslogtreecommitdiff
path: root/src/c/hardware/rasberrypi/gpio
diff options
context:
space:
mode:
authorsiddhu89902016-02-01 11:05:35 +0530
committersiddhu89902016-02-01 11:05:35 +0530
commit5df6d1cb2868abdc8df66755f76c997ee36c0b49 (patch)
tree8f6eef9f83437133b0b8d7f16f3b5dd470872aee /src/c/hardware/rasberrypi/gpio
parent1ff7f5293444b22b46ff7bd51d52a845dc20525c (diff)
downloadScilab2C_fossee_old-5df6d1cb2868abdc8df66755f76c997ee36c0b49.tar.gz
Scilab2C_fossee_old-5df6d1cb2868abdc8df66755f76c997ee36c0b49.tar.bz2
Scilab2C_fossee_old-5df6d1cb2868abdc8df66755f76c997ee36c0b49.zip
Support for RPi gpios added
Diffstat (limited to 'src/c/hardware/rasberrypi/gpio')
-rw-r--r--src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c30
-rw-r--r--src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c30
-rw-r--r--src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c38
3 files changed, 98 insertions, 0 deletions
diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c
new file mode 100644
index 0000000..6f06558
--- /dev/null
+++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalIns.c
@@ -0,0 +1,30 @@
+// 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
+//
+//
+// Authors
+// Siddhesh Wani
+//
+
+#include "types.h"
+#include "RPIPeripheralDigital.h"
+
+uint8 u8RPIDigitalIns(uint8 pin)
+{
+ uint8 state = 0;
+ state = bcm2835_gpio_lev(pin);
+ return (state);
+}
diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c
new file mode 100644
index 0000000..375ca89
--- /dev/null
+++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalOuts.c
@@ -0,0 +1,30 @@
+// 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
+//
+//
+// Authors
+// Siddhesh Wani
+//
+
+#include "types.h"
+#include "RPIPeripheralDigital.h"
+
+
+uint8 u8RPIDigitalOuts(uint8 pin, uint8 state)
+{
+ if (state == 0) //low output
+ bcm2835_gpio_clr(pin);
+ if (state == 1) //high output
+ bcm2835_gpio_set(pin);
+}
diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c
new file mode 100644
index 0000000..277c620
--- /dev/null
+++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c
@@ -0,0 +1,38 @@
+// 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
+//
+//
+// Authors
+// Siddhesh Wani
+//
+
+// This is curretly dummy function. It provides no functionality but is required
+// for providing support for generating C code for RPi.
+#include "types.h"
+#include "RPIPeripheralDigital.h"
+
+uint8 u8RPIDigitalSetups(uint8 pin, uint8 direction)
+{
+ if(direction == 1) //Pin to be used as output
+ {
+ bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP);
+ }
+ else
+ {
+ bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_INPT);
+ }
+}