-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAT91PIO.c
More file actions
87 lines (71 loc) · 1.87 KB
/
Copy pathAT91PIO.c
File metadata and controls
87 lines (71 loc) · 1.87 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* AT91PIO.c
*/
#include "config.h"
#include "AT91PIO.h"
/*
* Clear a port bit
*/
void OutputLow( unsigned long bit ){
__PIO_CODR = bit;
}
/*
* Set a port bit
*/
void OutputHigh( unsigned long bit ){
__PIO_SODR = bit;
}
/* No inputs in addition to keyboard column lines */
#define INPUTS 0x00000000
/* Outputs for LCD signals (P3, P4, P16, P17, P18, P19) and sounder (P6) */
#define OUTPUTS 0x000F0058
/* Four Outputs for row lines - P20, P21, P8, P23 */
#define ROWS 0x00B00100
/* Four inputs for column lines - P12, P9, P1, P2 */
#define COLUMNS 0x00001206
/* AT91InitialisePIO
*
* Initialise PIO register set for Powertip PG12864 LCD IO, Keyboard and Sounder
*
* I: Input
* O: Output
* x: Don't care
*
* x x x x x x x x O x O O O O O O x x x I x x I O x O x O O I I x
* 31 27 23 19 15 11 7 3 0
*/
void AT91InitialisePIO() {
__PIO_PER = INPUTS | OUTPUTS | ROWS | COLUMNS; // Enable PIO Controller for I/O bits
__PIO_OER = OUTPUTS | ROWS; // Output enable
__PIO_ODR = INPUTS | COLUMNS; // Output disable
__PIO_CODR = OUTPUTS; // Clear Outputs
__PIO_IDR = INPUTS | ROWS | COLUMNS; // Disable interrupts on Inputs
}
int getPortBit( unsigned long mask ) {
unsigned long port;
port = __PIO_PDSR;
return ( port & mask );
}
/* AT91GetInputBits
*
* Read all GPIO inputs
*
* WDH, June 22, 2006
*/
unsigned int AT91GetInputBits() {
unsigned long pa; // Port A value.
pa = ~__PIO_PDSR; /* Pin Data Status Register */
return (pa);
}
/* unsigned int GetButton( unsigned int button );
*
* Returns the state of a button
*/
unsigned int GetButton( unsigned int button ) {
unsigned int buttonMask;
buttonMask= AT91GetInputBits();
if ( button & buttonMask )
return 1;
else
return 0;
}