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