-
Notifications
You must be signed in to change notification settings - Fork 8
/
gpio.c
30 lines (24 loc) · 848 Bytes
/
gpio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "gpio.h"
struct GpioRegisters *GpioRegisters_s;
/**********************************
Sets GPIO pin function
***********************************/
void SetGPIOFunction(int GPIO, int functionCode)
{
int registerIndex = GPIO / 10;
int bit = (GPIO % 10) * 3;
unsigned oldValue = GpioRegisters_s-> GPFSEL[registerIndex];
unsigned mask = 0b111 << bit;
printk("Changing function of GPIO%d from %x to %x\n",GPIO,(oldValue >> bit) & 0b111,functionCode);
GpioRegisters_s-> GPFSEL[registerIndex] = (oldValue & ~mask)|((functionCode << bit) & mask);
}
/******************************
Set GPIO pin level
******************************/
void SetGPIOOutputValue(int GPIO, bool outputValue)
{
if (outputValue)
GpioRegisters_s-> GPSET[GPIO / 32] = (1 << (GPIO % 32));
else
GpioRegisters_s-> GPCLR[GPIO / 32] = (1 << (GPIO % 32));
}