Subversion Repositories idreammicro-avr

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 jlesech 1
/**************************************************************************//**
2
 * \brief Digital I/O library - API
3
 * \author Copyright (C) 2009  Julien Le Sech - www.idreammicro.com
4
 * \version 1.0
5
 * \date 20090314
6
 *
7
 * This file is part of the iDreamMicro library.
8
 *
9
 * This library is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * This library is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program. If not, see http://www.gnu.org/licenses/
21
 ******************************************************************************/
22
 
23
/**************************************************************************//**
24
 * \headerfile digital_io.h
25
 *
26
 * \brief
27
 *
28
 * \see
29
 ******************************************************************************/
30
 
31
#ifndef H__IDREAMMICRO__DIGITAL_IO__H
32
#define H__IDREAMMICRO__DIGITAL_IO__H
33
 
34
#ifdef _cplusplus
35
extern "C"{
36
#endif
37
 
38
/******************************************************************************
39
 * Header file inclusions.
40
 ******************************************************************************/
41
 
42
#include <avr/io.h>
43
 
44
#include <stdint.h>
45
 
46
/******************************************************************************
47
 * Public macro definitions.
48
 ******************************************************************************/
49
 
50
/**************************************************************************//**
51
 * \def digital_io__get_port(pin_position)
52
 * \brief Get port from pin position.
53
 ******************************************************************************/
54
#define digital_io__get_port(pin_position)  ((pin_position) >> 4)
55
 
56
/**************************************************************************//**
57
 * \def digital_io__get_pin(pin_position)
58
 * \brief Get pin form pin position.
59
 ******************************************************************************/
60
#define digital_io__get_pin(pin_position)   ((pin_position) & 0x0F)
61
 
62
/**************************************************************************//**
63
 * \def DIGITAL_IO__PORT_A
64
 * \brief Port A.
65
 ******************************************************************************/
66
#define DIGITAL_IO__PORT_A  0x00
67
 
68
/**************************************************************************//**
69
 * \def DIGITAL_IO__PORT_B
70
 * \brief Port B.
71
 ******************************************************************************/
72
#define DIGITAL_IO__PORT_B  0x10
73
 
74
/**************************************************************************//**
75
 * \def DIGITAL_IO__PORT_C
76
 * \brief Port C.
77
 ******************************************************************************/
78
#define DIGITAL_IO__PORT_C  0x20
79
 
80
/**************************************************************************//**
81
 * \def DIGITAL_IO__PORT_D
82
 * \brief Port D.
83
 ******************************************************************************/
84
#define DIGITAL_IO__PORT_D  0x30
85
 
86
/**************************************************************************//**
87
 * \def DIGITAL_IO__PORT_E
88
 * \brief Port E.
89
 ******************************************************************************/
90
#define DIGITAL_IO__PORT_E  0x40
91
 
92
/**************************************************************************//**
93
 * \def DIGITAL_IO__PORT_F
94
 * \brief Port F.
95
 ******************************************************************************/
96
#define DIGITAL_IO__PORT_F  0x50
97
 
98
/**************************************************************************//**
99
 * \def DIGITAL_IO__PORT_G
100
 * \brief Port G.
101
 ******************************************************************************/
102
#define DIGITAL_IO__PORT_G  0x60
103
 
104
/**************************************************************************//**
105
 * \def DIGITAL_IO__PORT_H
106
 * \brief port H.
107
 ******************************************************************************/
108
#define DIGITAL_IO__PORT_H  0x70 
109
 
110
/**************************************************************************//**
111
 * \def DIGITAL_IO__PORT_J
112
 * \brief Port J.
113
 ******************************************************************************/
114
#define DIGITAL_IO__PORT_J  0x80
115
 
116
/**************************************************************************//**
117
 * \def DIGITAL_IO__PORT_K
118
 * \brief Port K.
119
 ******************************************************************************/
120
#define DIGITAL_IO__PORT_K  0x90
121
 
122
/**************************************************************************//**
123
 * \def DIGITAL_IO__PORT_L
124
 * \brief Port L.
125
 ******************************************************************************/
126
#define DIGITAL_IO__PORT_L  0xA0
127
 
128
/**************************************************************************//**
129
 * \def DIGITAL_IO__PIN_0
130
 * \brief Pin 0.
131
 ******************************************************************************/
132
#define DIGITAL_IO__PIN_0   0
133
 
134
/**************************************************************************//**
135
 * \def DIGITAL_IO__PIN_1
136
 * \brief Pin 1.
137
 ******************************************************************************/
138
#define DIGITAL_IO__PIN_1   1
139
 
140
/**************************************************************************//**
141
 * \def DIGITAL_IO__PIN_2
142
 * \brief Pin 2.
143
 ******************************************************************************/
144
#define DIGITAL_IO__PIN_2   2
145
 
146
/**************************************************************************//**
147
 * \def DIGITAL_IO__PIN_3
148
 * \brief Pin 3.
149
 ******************************************************************************/
150
#define DIGITAL_IO__PIN_3   3
151
 
152
/**************************************************************************//**
153
 * \def DIGITAL_IO__PIN_4
154
 * \brief Pin 4.
155
 ******************************************************************************/
156
#define DIGITAL_IO__PIN_4   4
157
 
158
/**************************************************************************//**
159
 * \def DIGITAL_IO__PIN_5
160
 * \brief Pin 5.
161
 ******************************************************************************/
162
#define DIGITAL_IO__PIN_5   5
163
 
164
/**************************************************************************//**
165
 * \def DIGITAL_IO__PIN_6
166
 * \brief Pin 6.
167
 ******************************************************************************/
168
#define DIGITAL_IO__PIN_6   6
169
 
170
/**************************************************************************//**
171
 * \def DIGITAL_IO__PIN_7
172
 * \brief Pin 7.
173
 ******************************************************************************/
174
#define DIGITAL_IO__PIN_7   7
175
 
176
/******************************************************************************
177
 * Public types.
178
 ******************************************************************************/
179
 
180
/**************************************************************************//**
181
 * \typedef digital_io__port_t
182
 * \brief
183
 ******************************************************************************/
184
typedef uint8_t digital_io__port_t;
185
 
186
/**************************************************************************//**
187
 * \typedef digital_io__pin_t
188
 * \brief
189
 ******************************************************************************/
190
typedef uint8_t digital_io__pin_t;
191
 
192
/**************************************************************************//**
193
 * \typedef digital_io__pin_position_t
194
 * \brief Digital IO pin position.
195
 * High nibble is used for the port, low nibble is used for the pin.
196
 * digital_io__pin_position_t pin = DIGITAL_IO__PORT_B | DIGITAL_IO__PIN_5;
197
 ******************************************************************************/
198
typedef uint8_t digital_io__pin_position_t;
199
 
200
/**************************************************************************//**
201
 * \enum digital_io__directions
202
 * \brief Digital IO directions.
203
 *
204
 * \typedef digital_io__direction_t
205
 * \brief Digital IO direction.
206
 ******************************************************************************/
207
typedef enum digital_io__directions
208
{
209
    DIGITAL_IO__DIRECTION__INPUT,       /*!<  Input. */
210
    DIGITAL_IO__DIRECTION__OUTPUT       /*!<  Output. */
211
} digital_io__direction_t;
212
 
213
/**************************************************************************//**
214
 * \enum digital_io__levels
215
 * \brief Digital IO levels.
216
 *
217
 * \typedef digital_io__level_t
218
 * \brief Digital IO level.
219
 ******************************************************************************/
220
typedef enum digital_io__levels
221
{
222
    DIGITAL_IO__LEVEL__LOW, /*!<  Low level. */
223
    DIGITAL_IO__LEVEL__HIGH /*!<  High level. */
224
} digital_io__level_t;
225
 
226
/**************************************************************************//**
227
 * \typedef digital_io__port_value_t
228
 * \brief Port value.
229
 ******************************************************************************/
230
typedef uint8_t digital_io__port_value_t;
231
 
232
/******************************************************************************
233
 * Public function prototypes.
234
 ******************************************************************************/
235
 
236
/**************************************************************************//**
237
 * \fn void digital_io__configure_pin(
238
 * digital_io__pin_position_t   pin_position,
239
 * digital_io__direction_t      direction)
240
 *
241
 * \brief Configure a pin.
242
 *
243
 * \param   pin_position    pin position to configure
244
 * \param   direction       pin direction to set
245
 ******************************************************************************/
246
void
247
digital_io__configure_pin
248
(
249
    digital_io__pin_position_t  pin_position,
250
    digital_io__direction_t     direction
251
);
252
 
253
/**************************************************************************//**
254
 * \fn digital_io__level_t digital_io__get_pin_level(
255
 * digital_io__pin_position_t   pin_position)
256
 *
257
 * \brief Get the level of a pin.
258
 *
259
 * \param   pin_position    pin position to get level
260
 *
261
 * \return digital io level
262
 ******************************************************************************/
263
digital_io__level_t
264
digital_io__get_pin_level
265
(
266
    digital_io__pin_position_t  pin_position
267
);
268
 
269
/**************************************************************************//**
270
 * \fn void digital_io__set_pin_level(
271
 * digital_io__pin_position_t   pin_position,
272
 * digital_io__level_t          level)
273
 *
274
 * \brief Set the level of a pin.
275
 *
276
 * \param   pin_position    pin position to set level
277
 * \param   level           level to set
278
 ******************************************************************************/
279
void
280
digital_io__set_pin_level
281
(
282
    digital_io__pin_position_t  pin_position,
283
    digital_io__level_t         level
284
);
285
 
286
/**************************************************************************//**
287
 * \fn void digital_io__toggle_pin_level(
288
 * digital_io__pin_position_t   pin_position)
289
 *
290
 * \brief Toggle the level of a pin.
291
 *
292
 * \param   pin_position    pin position to toggle level
293
 ******************************************************************************/
294
void
295
digital_io__toggle_pin_level
296
(
297
    digital_io__pin_position_t  pin_position
298
);
299
 
300
/**************************************************************************//**
301
 * \fn void digital_io__configure_port(
302
 * digital_io__port_t       port,
303
 * digital_io__direction_t  direction)
304
 *
305
 * \brief Configure a port.
306
 *
307
 * \param   port        port to configure
308
 * \param   direction   port direction to configure
309
 ******************************************************************************/
310
void
311
digital_io__configure_port
312
(
313
    digital_io__port_t      port,
314
    digital_io__direction_t direction
315
);
316
 
317
/**************************************************************************//**
318
 * \fn uint8_t digital_io__get_port_value(digital_io__port_t port)
319
 *
320
 * \brief Get the value of a port.
321
 *
322
 * \param   port    port to get value
323
 *
324
 * \return Port value
325
 ******************************************************************************/
326
digital_io__port_value_t
327
digital_io__get_port_value
328
(
329
    digital_io__port_t  port
330
);
331
 
332
/**************************************************************************//**
333
 * \fn void digital_io__set_port_value(
334
 * digital_io__port_t       port,
335
 * digital_io__port_value_t value)
336
 *
337
 * \brief Set the value of a port.
338
 *
339
 * \param port  port to set value
340
 * \param value port value to set
341
 ******************************************************************************/
342
void
343
digital_io__set_port_value
344
(
345
    digital_io__port_t          port,
346
    digital_io__port_value_t    value
347
);
348
 
349
#ifdef _cplusplus
350
}
351
#endif
352
 
353
#endif /* H__IDREAMMICRO__DIGITAL_IO__H */
354