blob: bcda92e691de200f4c6d57444e0318f0786ed675 (
plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include "dio.h"
void DIO_Init(char port, unsigned int dir, unsigned int pur) {
unsigned int off = port - 'A';
SYSCTL_RCGCGPIO_R |= 1 << off;
while(SYSCTL_RCGCGPIO_R && (1 << off) == 0) {};
unsigned int* address = (unsigned int*)(0x40004000 + (off * 0x1000));
if (off >= 4) {
address = (unsigned int*)(0x40024000 + ((off - 4) * 0x1000));
}
*(address + LOCKOFF) = 0x4C4F434B; // LOCK
*(address + COMMITOFF) = 0x1F;
*(address + PUROFF) = pur;
*(address + DENOFF) = 0x1F;
*(address + DIROFF) = dir;
}
void DIO_WritePin(volatile uint32_t* port, unsigned int pin, unsigned int value) {
if(value) {
SET(port, pin);
} else {
RESET(port, pin);
}
}
void DIO_WritePort(volatile uint32_t* port, unsigned int value) {
*port = value;
}
int DIO_ReadPin(volatile uint32_t* port, unsigned int pin) {
int x = GET_BIT(port, pin);
return x;
}
uint32_t DIO_ReadPort(volatile uint32_t port) {
return port;
}
void delay(int value) {
while(value--) {}
}
|