KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gpio.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : gpio.c
11  * Created : 5 mrt. 2013
12  * Author : Vincent van Beveren
13  */
14 
15 
16 #include "drv/wb/gpio.h"
17 #include "lm32soc/dev_soc.h"
18 
19 #define GPIO_ALL_INPUT 0xffffffff
20 
21 void gpioInit()
22 {
23  GPIO->DIR = GPIO_ALL_INPUT;
24 }
25 
26 void gpioPinConf(int pin, GpioPinDir dir)
27 {
28  switch (dir)
29  {
30  case gpioOutput : GPIO->DIR &= ~ ( 1 << pin ); break;
31  case gpioInput : GPIO->DIR |= 1 << pin; break;
32  }
33 }
34 
35 void gpioPinSet(int pin, bool high)
36 {
37  if (high)
38  {
39  GPIO->SET = 1 << pin;
40  } else {
41  GPIO->CLR = 1 << pin;
42  }
43 }
44 
45 bool gpioPinGet(int pin)
46 {
47  return ((GPIO->GET >> pin) & 1) != 0;
48 }
49 
50 void gpioSetValue(uint32_t mask)
51 {
52  GPIO->CLR = ~mask;
53  GPIO->SET = mask;
54 }
55 
56 uint32_t gpioGetValue()
57 {
58  return GPIO->GET;
59 }
GPIO Driver.
void gpioPinConf(int pin, GpioPinDir dir)
Configure PIN directionality.
Definition: gpio.c:26
uint32_t gpioGetValue()
Read all gpio pins at once.
Definition: gpio.c:56
GpioPinDir
Defines direction of GPIO.
Definition: gpio.h:33
void gpioPinSet(int pin, bool high)
Sets the pin state.
Definition: gpio.c:35
GPIO is output.
Definition: gpio.h:36
void gpioInit()
Initializes the GPIO.
Definition: gpio.c:21
GPIO is input.
Definition: gpio.h:35
This file assigns all device structures to memory mapped structures.
bool gpioPinGet(int pin)
Gets the PIN value, if set as input.
Definition: gpio.c:45
#define GPIO
GPIO base pointer.
Definition: dev_soc.h:62
void gpioSetValue(uint32_t mask)
Set the complete bitmask on the gpio pins.
Definition: gpio.c:50