pihwm  r1
A lightweight C library for Raspberry Pi hardware modules.
pi_gpio.h
Go to the documentation of this file.
1 
28 #ifndef PI_GPIO_H
29 #define PI_GPIO_H
30 
31 // Useful constants
32 #define INPUT 1
33 #define OUTPUT 0
34 #define IN INPUT
35 #define OUT OUTPUT
36 
37 #define HIGH 1
38 #define LOW 0
39 #define ON HIGH
40 #define OFF LOW
41 
42 // Function prototypes
43 int gpio_init (unsigned int pin, unsigned int dir);
44 int gpio_set_int (unsigned int pin, void (*isr) (int), char *mode);
45 int gpio_clear_int (unsigned int pin);
46 int gpio_write (unsigned int pin, unsigned int val);
47 int gpio_read (unsigned int pin);
48 int gpio_release (unsigned int pin);
49 
50 // Aliases for pseudo-Arduino compatibility
51 #define pinMode(pin, dir) gpio_init(pin, dir);
52 #define digitalWrite(pin, val) gpio_write(pin, val);
53 #define digitalRead(pin) gpio_read(pin);
54 #define attachInterrupt(pin, isr, mode) gpio_set_int(pin, isr, mode);
55 #define detachInterrupt(pin) gpio_clear_int(pin);
56 
57 #endif
58 
int gpio_init(unsigned int pin, unsigned int dir)
Initialize the GPIO interface for the pin numbered pin on the Raspberry Pi P1 header in the direction...
Definition: pi_gpio.c:124
int gpio_release(unsigned int pin)
The inverse of gpio_init. Frees the pin numbered pin on the Raspberry Pi P1 header, so it can be used for other purposes.
Definition: pi_gpio.c:397
int gpio_write(unsigned int pin, unsigned int val)
Set the pin numbered pin on the Raspberry Pi P1 header to the value specified by val. dir should be either "0" or "1". The defined constants LOW or OFF may be used instead of 0 and HIGH or ON instead of 1/.
Definition: pi_gpio.c:321
int gpio_read(unsigned int pin)
Read the value on the pin numbered pin on the Raspberry Pi P1 header.
Definition: pi_gpio.c:365
int gpio_set_int(unsigned int pin, void(*isr)(int), char *mode)
Set isr as the interrupt service routine (ISR) for pin numbered pin on the Raspberry Pi P1 header...
Definition: pi_gpio.c:274
int gpio_clear_int(unsigned int pin)
Clears any interrupt service routine (ISR) set on the pin numbered pin on the Raspberry Pi P1 header...
Definition: pi_gpio.c:303