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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
* Copyright (c) 2007 Embedded Projects (http://www.embedded-projecs.net)
* Author: Benedikt Sauter <sauter@embedded-projects.net
* All rights reserved.
*
* Short descripton of file:
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the FH Augsburg nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef IO_H
#define IO_H
#include <avr/io.h>
#include <avr/pgmspace.h>
#define OX_PIN1 PINE
#define OX_PIN2 PINE
#define OX_PIN3 PINE
#define OX_PIN4 PINB
#define OX_PIN5 PINB
#define OX_PIN6 PINB
#define OX_PIN7 PINB
#define OX_PIN8 PINB
#define OX_PIN9 PINB
#define OX_PIN10 PINB
#define OX_PIN11 PINB
#define OX_PIN12 PIND
#define OX_PIN13 PIND
#define OX_PIN14 PIND
#define OX_PIN15 PIND
#define OX_PIN16 PIND
#define OX_PIN17 PIND
#define OX_PIN18 PIND
#define OX_PIN19 PIND
#define OX_PIN26 PINC
#define OX_PIN27 PINC
#define OX_PIN28 PINC
#define OX_PIN29 PINC
#define OX_PIN30 PINC
#define OX_PIN31 PINC
#define OX_PIN32 PINC
#define OX_PIN33 PINF
#define OX_PIN34 PINF
#define OX_PIN35 PINF
#define OX_PIN36 PINF
#define OX_PIN37 PINF
#define OX_PIN38 PINF
#define OX_PIN39 PINF
#define OX_PIN40 PINF
#define OX_PIN41 PINE
#define OX_PIN42 PINE
#define OX_PIN43 PINE
#define OX_PIN44 PINE
#define OX_PORT1 PORTE
#define OX_PORT2 PORTE
#define OX_PORT3 PORTE
#define OX_PORT4 PORTB
#define OX_PORT5 PORTB
#define OX_PORT6 PORTB
#define OX_PORT7 PORTB
#define OX_PORT8 PORTB
#define OX_PORT9 PORTB
#define OX_PORT10 PORTB
#define OX_PORT11 PORTB
#define OX_PORT12 PORTD
#define OX_PORT13 PORTD
#define OX_PORT14 PORTD
#define OX_PORT15 PORTD
#define OX_PORT16 PORTD
#define OX_PORT17 PORTD
#define OX_PORT18 PORTD
#define OX_PORT19 PORTD
#define OX_PORT26 PORTC
#define OX_PORT27 PORTC
#define OX_PORT28 PORTC
#define OX_PORT29 PORTC
#define OX_PORT30 PORTC
#define OX_PORT31 PORTC
#define OX_PORT32 PORTC
#define OX_PORT33 PORTF
#define OX_PORT34 PORTF
#define OX_PORT35 PORTF
#define OX_PORT36 PORTF
#define OX_PORT37 PORTF
#define OX_PORT38 PORTF
#define OX_PORT39 PORTF
#define OX_PORT40 PORTF
#define OX_PORT41 PORTE
#define OX_PORT42 PORTE
#define OX_PORT43 PORTE
#define OX_PORT44 PORTE
#define OX_DDR1 DDRE
#define OX_DDR2 DDRE
#define OX_DDR3 DDRE
#define OX_DDR4 DDRB
#define OX_DDR5 DDRB
#define OX_DDR6 DDRB
#define OX_DDR7 DDRB
#define OX_DDR8 DDRB
#define OX_DDR9 DDRB
#define OX_DDR10 DDRB
#define OX_DDR11 DDRB
#define OX_DDR12 DDRD
#define OX_DDR13 DDRD
#define OX_DDR14 DDRD
#define OX_DDR15 DDRD
#define OX_DDR16 DDRD
#define OX_DDR17 DDRD
#define OX_DDR18 DDRD
#define OX_DDR19 DDRD
#define OX_DDR26 DDRC
#define OX_DDR27 DDRC
#define OX_DDR28 DDRC
#define OX_DDR29 DDRC
#define OX_DDR30 DDRC
#define OX_DDR31 DDRC
#define OX_DDR32 DDRC
#define OX_DDR33 DDRF
#define OX_DDR34 DDRF
#define OX_DDR35 DDRF
#define OX_DDR36 DDRF
#define OX_DDR37 DDRF
#define OX_DDR38 DDRF
#define OX_DDR39 DDRF
#define OX_DDR40 DDRF
#define OX_DDR41 DDRE
#define OX_DDR42 DDRE
#define OX_DDR43 DDRE
#define OX_DDR44 DDRE
#define OX_P1 PE5
#define OX_P2 PE6
#define OX_P3 PE7
#define OX_P4 PB0
#define OX_P5 PB1
#define OX_P6 PB2
#define OX_P7 PB3
#define OX_P8 PB4
#define OX_P9 PB5
#define OX_P10 PB6
#define OX_P11 PB7
#define OX_P12 PD0
#define OX_P13 PD1
#define OX_P14 PD2
#define OX_P15 PD3
#define OX_P16 PD4
#define OX_P17 PD5
#define OX_P18 PD6
#define OX_P19 PD7
#define OX_P26 PC0
#define OX_P27 PC1
#define OX_P28 PC2
#define OX_P29 PC3
#define OX_P30 PC4
#define OX_P31 PC5
#define OX_P32 PC6
#define OX_P33 PF7
#define OX_P34 PF6
#define OX_P35 PF5
#define OX_P36 PF4
#define OX_P37 PF3
#define OX_P38 PF2
#define OX_P39 PF1
#define OX_P40 PF0
#define OX_P41 PE0
#define OX_P42 PE1
#define OX_P43 PE2
#define OX_P44 PE3
void io_parser(char *buf);
uint8_t io_init(uint8_t pin);
void io_init_usb(uint8_t pin);
uint8_t io_init_port(uint8_t port);
void io_init_port_usb(uint8_t port);
uint8_t io_set_port_direction_out(uint8_t port,uint8_t mask);
uint8_t io_set_port_direction_in(uint8_t port, uint8_t mask);
uint8_t io_set_port_direction_tri(uint8_t port, uint8_t mask);
void io_set_port_direction_out_usb (uint8_t port, uint8_t mask);
void io_set_port_direction_in_usb(uint8_t port, uint8_t mask);
void io_set_port_direction_tri_usb(uint8_t port, uint8_t mask);
uint8_t io_set_pin_direction_out(uint8_t pin);
uint8_t io_set_pin_direction_in(uint8_t pin);
uint8_t io_set_pin_direction_tri(uint8_t pin);
void io_set_pin_direction_out_usb(uint8_t pin);
void io_set_pin_direction_in_usb(uint8_t pin);
void io_set_pin_direction_tri_usb(uint8_t pin);
uint8_t io_get_port (uint8_t port, uint8_t *pvalue);
void io_get_port_usb (uint8_t port);
uint8_t io_set_port(uint8_t port, uint8_t value);
void io_set_port_usb (uint8_t port, uint8_t value);
uint8_t io_set_pin(uint8_t pin, uint8_t value);
void io_set_pin_usb(uint8_t pin, uint8_t value);
uint8_t io_get_pin(uint8_t pin, uint8_t *value);
void io_get_pin_usb(uint8_t pin);
#define PORT(port,pin) (PORT##port)
#define DDR(port,pin) (DDR##port)
#define PIN(port,pin) (PIN##port)
#define PIN_MASK(port,pin) (1<<(pin))
/* Set a pin */
#define SETPIN(pindef) PORT pindef |= PIN_MASK pindef
/* Clear a pin */
#define CLRPIN(pindef) PORT pindef &= ~PIN_MASK pindef
/* Get pin value */
#define GETPIN(pindef) (PIN pindef & PIN_MASK pindef)
/* Toggle a pin */
#define TOGGLEPIN(pindef) PIN pindef |= PIN_MASK pindef
/* Set a IO to output */
#define SET_DDR_OUT(pindef) DDR pindef |= PIN_MASK pindef
/* Set a IO to input */
#define SET_DDR_IN(pindef) DDR pindef &= ~PIN_MASK pindef
#endif /* IO_H */
|