-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsp_gpio.c
175 lines (161 loc) · 4.57 KB
/
bsp_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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include <bsp_gpio.h>
/*
*********************************************************************************************************
* init_gpio()
*
* Description : This function initializes the Pin_1 GPIO module (P1_6, J1 Pin 23), the
* Pin_2 GPIO module (P2_0, J1 Pin 1 and P2_1, J1 Pin 2) and the push button
* GPIO module (P2_2, J1 Pin 3). On P2_1 a blue on-board LED is connected. On
* P2_2 on side of a GND-connected button is connected.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : Not re-entrant.
*********************************************************************************************************
*/
CPU_VOID init_gpio(CPU_VOID)
{
Pin_1_SetDriveMode(Pin_1_DM_STRONG);
Pin_2_SetDriveMode(Pin_2_DM_STRONG);
push_button_SetDriveMode(push_button_DM_STRONG);
push_button_Write(1);
}
/*
*********************************************************************************************************
* gpio_high()
*
* Description : This function set based on a chosen port (PORT1, PORT2) the digital level
* of a chosen pin (P1_6, P2_0, P2_1) on digital high (~ 5V).
*
* Argument(s) : port ... indicates which port should be addressed (PORT1, PORT2)
* pin ... indicates which pin of the chosen port is addressed (P1_6, P2_0, P2_1)
*
* Return(s) : 0 ... if no error occurred
* >1... if an error occurred
*
* Caller(s) : Application.
*
* Note(s) : Not re-entrant.
*********************************************************************************************************
*/
CPU_INT08U gpio_high(CPU_INT08U port, CPU_INT08U pin)
{
CPU_INT08U err = 0;
if(port == PORT1){
if(pin == P1_6){
Pin_1_Write(HIGH);
}
else{
err++;
}
}
else if(port == PORT2){
if(pin == P2_0){
Pin_2_Write(P2_0);
}
else if(pin == P2_1){
Pin_2_Write(P2_1);
}
else{
err++;
}
}
else{
err++;
}
return err;
}
/*
*********************************************************************************************************
* gpio_low()
*
* Description : This function resets based on a chosen port (PORT1, PORT2) the digital level
* of a chosen pin (P1_6, P2_0, P2_1) on digital low (0V).
*
* Argument(s) : port ... indicates which port should be addressed (PORT1, PORT2)
* pin ... indicates which pin of the chosen port is addressed (P1_6, P2_0, P2_1)
*
* Return(s) : 0 ... if no error occurred
* >1... if an error occurred
*
* Caller(s) : Application.
*
* Note(s) : Not re-entrant.
*********************************************************************************************************
*/
CPU_INT08U gpio_low(CPU_INT08U port, CPU_INT08U pin)
{
CPU_INT08U err = 0;
if(port == PORT1){
if(pin == P1_6){
Pin_1_Write(LOW);
}
else{
err++;
}
}
else if(port == PORT2){
if(pin == P2_0){
Pin_2_Write(!(P2_0));
}
else if(pin == P2_1){
Pin_2_Write(!(P2_1));
}
else{
err++;
}
}
else{
err++;
}
return err;
}
/*
*********************************************************************************************************
* gpio_read()
*
* Description : This function reads the digital level of a chosen port (PORT2) and pin (P2_2).
*
* Argument(s) : port ... indicates which port should be addressed (PORT2)
* pin ... indicates which pin of the chosen port is addressed (P2_2)
*
* Return(s) : 0 ... if no error occurred
* -1... if an error occurred
*
* Caller(s) : Application.
*
* Note(s) : Not re-entrant.
*********************************************************************************************************
*/
CPU_INT08S gpio_read(CPU_INT08U port, CPU_INT08U pin)
{
CPU_INT08S err = 0;
if(port == PORT2){
if(pin == P2_2){
err = push_button_Read();
}
else{
err = -1;
}
}
else{
err = -1;
}
return err;
}
/* [] END OF FILE */