Subversion Repositories idreammicro-avr

Rev

Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 jlesech 1
/**************************************************************************//**
2
 * \brief MCP23008 library
3
 * \author Copyright (C) 2012  Julien Le Sech - www.idreammicro.com
4
 * \version 1.0
5
 * \date 20121025
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 mcp23008.h
25
 ******************************************************************************/
26
 
27
#ifndef H__IDREAMMICRO__MCP23008__H
28
#define H__IDREAMMICRO__MCP23008__H
29
 
30
#ifdef _cplusplus
31
extern "C"{
32
#endif
33
 
34
/******************************************************************************
35
 * Header file inclusions.
36
 ******************************************************************************/
37
 
38
#include <stdint.h>
39
 
40
/******************************************************************************
41
 * Public macro definitions.
42
 ******************************************************************************/
43
 
36 jlesech 44
/**************************************************************************//**
45
 * \def     MCP23008__CLOCK_RATE
46
 * \brief   MCP23008 frequency in Hertz.
47
 * On ATmega, can be 100 kHz or 400 Khz.
48
 ******************************************************************************/
49
#define MCP23008__CLOCK_RATE    400000
50
 
31 jlesech 51
/******************************************************************************
52
 * MCP23008 GPIOs.
53
 ******************************************************************************/
30 jlesech 54
 
31 jlesech 55
/**************************************************************************//**
56
 * \def     MCP23008__GP0
57
 * \brief   I/O pin 0.
58
 ******************************************************************************/
59
#define MCP23008__GP0   0
60
 
61
/**************************************************************************//**
62
 * \def     MCP23008__GP1
63
 * \brief   I/O pin 1.
64
 ******************************************************************************/
65
#define MCP23008__GP1   1
66
 
67
/**************************************************************************//**
68
 * \def     MCP23008__GP2
69
 * \brief   I/O iin 2.
70
 ******************************************************************************/
71
#define MCP23008__GP2   2
72
 
73
/**************************************************************************//**
74
 * \def     MCP23008__GP3
75
 * \brief   I/O pin 3.
76
 ******************************************************************************/
77
#define MCP23008__GP3   3
78
 
79
/**************************************************************************//**
80
 * \def     MCP23008__GP4
81
 * \brief   I/O pin 4.
82
 ******************************************************************************/
83
#define MCP23008__GP4   4
84
 
85
/**************************************************************************//**
86
 * \def     MCP23008__GP5
87
 * \brief   I/O pin 5.
88
 ******************************************************************************/
89
#define MCP23008__GP5   5
90
 
91
/**************************************************************************//**
92
 * \def     MCP23008__GP6
93
 * \brief   I/O pin 6.
94
 ******************************************************************************/
95
#define MCP23008__GP6   6
96
 
97
/**************************************************************************//**
98
 * \def     MCP23008__GP7
99
 * \brief   I/O pin 7.
100
 ******************************************************************************/
101
#define MCP23008__GP7   7
102
 
30 jlesech 103
/******************************************************************************
104
 * Public type definitions.
105
 ******************************************************************************/
106
 
107
/**************************************************************************//**
108
 * \enum mcp23008__directions
109
 * \brief MCP23008 pin/port directions.
110
 *
111
 * \typedef mcp23008__direction_t
112
 * \brief MCP23008 pin/port direction.
113
 ******************************************************************************/
114
typedef enum mcp23008__directions
115
{
31 jlesech 116
    MCP23008__DIRECTION__INPUT, /*!<  Input. */
117
    MCP23008__DIRECTION__OUTPUT /*!<  Output. */
30 jlesech 118
} mcp23008__direction_t;
119
 
120
/**************************************************************************//**
121
 * \enum mcp23008__levels
122
 * \brief MCP23008 GPIO levels.
123
 *
124
 * \typedef mcp23008__level_t
125
 * \brief MCP23008 GPIO level.
126
 ******************************************************************************/
127
typedef enum mcp23008__levels
128
{
31 jlesech 129
    MCP23008__LEVEL__LOW,   /*!<  Low level. */
130
    MCP23008__LEVEL__HIGH   /*!<  High level. */
30 jlesech 131
} mcp23008__level_t;
132
 
133
/**************************************************************************//**
134
 * \typedef mcp23008__gpio_t
135
 * \brief
136
 ******************************************************************************/
137
typedef uint8_t mcp23008__gpio_t;
138
 
139
/******************************************************************************
140
 * Public function prototypes.
141
 ******************************************************************************/
142
 
143
/**************************************************************************//**
144
 * \fn void mcp23008__initialize(uint8_t hardware_address)
145
 *
146
 * \brief Initialize MCP23008.
147
 *
31 jlesech 148
 * \param hardware_address  Hardware address defined by pins A0 to A2.
30 jlesech 149
 ******************************************************************************/
150
void
151
mcp23008__initialize
152
(
153
    uint8_t hardware_address
154
);
155
 
156
/**************************************************************************//**
31 jlesech 157
 * \fn void mcp23008__configure pin(
158
 * mcp23008__gpio_t         pin,
159
 * mcp23008__direction_t    direction)
30 jlesech 160
 *
31 jlesech 161
 * \brief Configure pin direction.
162
 *
163
 * \param pin       Pin to configure.
164
 * \param direction Pin direction.
30 jlesech 165
 ******************************************************************************/
166
void
167
mcp23008__configure_pin
168
(
169
    mcp23008__gpio_t        pin,
170
    mcp23008__direction_t   direction
171
);
172
 
173
/**************************************************************************//**
31 jlesech 174
 * \fn void mcp23008__configure_port(mcp23008__direction_t direction)
30 jlesech 175
 *
31 jlesech 176
 * \brief Configure port direction.
177
 *
178
 * \param direction Port direction.
30 jlesech 179
 ******************************************************************************/
180
void
181
mcp23008__configure_port
182
(
183
    mcp23008__direction_t direction
184
);
185
 
186
/**************************************************************************//**
31 jlesech 187
 * \fn mcp23008__level_t mcp23008__get_pin_level(mcp23008__gpio_t pin)
30 jlesech 188
 *
31 jlesech 189
 * \brief Get pin level.
190
 *
191
 * \param pin   Pin to get level.
192
 *
193
 * \return Pin level.
30 jlesech 194
 ******************************************************************************/
195
mcp23008__level_t
196
mcp23008__get_pin_level
197
(
198
    mcp23008__gpio_t pin
199
);
200
 
201
/**************************************************************************//**
31 jlesech 202
 * \fn void mcp23008__set_pin_level(
203
 * mcp23008__gpio_t     pin,
204
 * mcp23008__level_t    level)
30 jlesech 205
 *
31 jlesech 206
 * \brief Set pin level.
207
 *
208
 * \param pin   Pin to set level.
209
 * \param level Level to set.
30 jlesech 210
 ******************************************************************************/
211
void
212
mcp23008__set_pin_level
213
(
31 jlesech 214
    mcp23008__gpio_t    pin,
215
    mcp23008__level_t   level
30 jlesech 216
);
217
 
218
/**************************************************************************//**
31 jlesech 219
 * \fn uin8_t mcp23008__get_port_value(void)
30 jlesech 220
 *
31 jlesech 221
 * \brief Get port value.
222
 *
223
 * \return Port value.
30 jlesech 224
 ******************************************************************************/
225
uint8_t
226
mcp23008__get_port_value
227
(
228
    void
229
);
230
 
231
/**************************************************************************//**
31 jlesech 232
 * \fn void mcp23008__set_port_value(uint8_t value)
30 jlesech 233
 *
31 jlesech 234
 * \brief Set port value.
235
 *
236
 * \param value Value to set.
30 jlesech 237
 ******************************************************************************/
238
void
239
mcp23008__set_port_value
240
(
241
    uint8_t value
242
);
243
 
244
#ifdef _cplusplus
245
}
246
#endif
247
 
248
#endif /* H__IDREAMMICRO__MCP23008__H */