Sensorian  1.0
C API Reference Guide Library
Utilities.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
29 #include "Utilities.h"
30 
34 
40 void delay_ms(unsigned int ms)
41 {
42  bcm2835_delay(ms);
43 }
44 
50 void pinModeOutput(PIN_t pin)
51 {
52  bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP);
53 }
54 
61 void digitalWrite(PIN_t pin, unsigned char level)
62 {
63  bcm2835_gpio_write(pin, level); // set to level
64 }
65 
72 {
73  bcm2835_gpio_fsel(pin,BCM2835_GPIO_FSEL_INPT); // Set the pin to be an input
74  bcm2835_gpio_set_pud(pin, BCM2835_GPIO_PUD_DOWN); // Enable pull up.
75  PinLevel_t pinLevel = (PinLevel_t)bcm2835_gpio_lev(pin); //read voltage level on MFP pin
76  return pinLevel;
77 }
78 
85 {
86  bcm2835_gpio_ren(pin); //enable rising edge detect on pin
87 }
88 
95 {
96  bcm2835_gpio_clr_ren(pin); //Disable rising edge detect on pin
97 }
98 
105 {
106  bcm2835_gpio_ren(pin); //enable rising edge detect on pin
107 }
108 
115 {
116  bcm2835_gpio_clr_ren(pin); //Disable rising edge detect on pin
117 }
118 
125 {
126  bcm2835_gpio_ren(pin); //enable rising edge detect on pin
127 }
128 
135 {
136  bcm2835_gpio_clr_ren(pin); //Disable rising edge detect on pin
137 }
138 
144 void EnableDetectLowLevel(PIN_t pin)
145 {
146  bcm2835_gpio_ren(pin); //enable rising edge detect on pin
147 }
148 
155 {
156  bcm2835_gpio_clr_ren(pin); //Disable rising edge detect on pin
157 }
158 
165 {
166  bcm2835_gpio_aren(pin); //enable rising edge detect on pin
167 }
168 
175 {
176  bcm2835_gpio_clr_aren(pin); //Disable rising edge detect on pin
177 }
178 
184 unsigned char CheckPinforEvent(PIN_t pin)
185 {
186  unsigned char event = bcm2835_gpio_eds(pin); //Check for event detection
187  bcm2835_gpio_set_eds(pin); //Clear even detection interrupt flags
188  return event;
189 }
190 
void pinModeOutput(PIN_t pin)
Configures the given pin as output.
Definition: Utilities.c:49
void DisableDetectRisingEdge(PIN_t pin)
Disables detection of rising edge.
Definition: Utilities.c:93
void EnableDetectFallingEdge(PIN_t pin)
Enables detection of falling edge.
Definition: Utilities.c:103
void DisableDetectFallinggEdge(PIN_t pin)
Dsiables detection of falling edge.
Definition: Utilities.c:113
void DisableDetectRisingInterrupt(PIN_t pin)
Disables detection of rising edge interrupt.
Definition: Utilities.c:173
void EnableDetectRisingEdge(PIN_t pin)
Enables detection of rising edge.
Definition: Utilities.c:83
unsigned char CheckPinforEvent(PIN_t pin)
Checks fro even on given pin.
Definition: Utilities.c:183
PinLevel_t ReadPinStatus(PIN_t pin)
Configures the pins as input and returns the pin status.
Definition: Utilities.c:70
void EnableDetectLowLevel(PIN_t pin)
Enables detection of low level.
Definition: Utilities.c:143
enum PinLev PinLevel_t
void DisableDetectHighLevel(PIN_t pin)
Disables detection of high level.
Definition: Utilities.c:133
uint8_t PIN_t
Definition: Utilities.h:37
void delay_ms(unsigned int ms)
Delay in ms.
Definition: Utilities.c:39
void digitalWrite(PIN_t pin, unsigned char level)
Write a logic level to the pin. The pin should be confgured as output.
Definition: Utilities.c:60
Utilities driver header.
void EnableDetectHighLevel(PIN_t pin)
Enables detection of high level on pin.
Definition: Utilities.c:123
void DisableDetectLowLevel(PIN_t pin)
Disables detection of low level.
Definition: Utilities.c:153
void EnableDetectRisingInterrupt(PIN_t pin)
Enables detection of rising edge interrupt.
Definition: Utilities.c:163