Fix comments.
[bertos.git] / bertos / drv / i2c.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2005 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief I2C generic driver functions.
34  *
35  * \version $Id$
36  * \author Francesco Sacchi <batt@develer.com>
37  *
38  * $WIZARD_MODULE = {
39  * "name" : "i2c",
40  * "depends" : [],
41  * "configuration" : "bertos/cfg/cfg_i2c.h"
42  * }
43  */
44 #ifndef DRV_I2C_H
45 #define DRV_I2C_H
46
47 #include "cfg/cfg_i2c.h"
48 #include <cfg/compiler.h>
49
50 #define I2C_READBIT BV(0)
51
52 /**
53  * I2C Backends.
54  * Sometimes your cpu does not have a builtin
55  * i2c driver or you don't want, for some reason, to
56  * use that.
57  * With this you can choose, at compile time, which backend to use.
58  *
59  * $WIZARD_LIST = {
60  * "i2c_backend" : ["I2C_BACKEND_BUILTIN", "I2C_BACKEND_BITBANG"]
61  * }
62  */
63 #define I2C_BACKEND_BUILTIN 0 ///< Uses cpu builtin i2c driver
64 #define I2C_BACKEND_BITBANG 1 ///< Uses emulated bitbang driver
65
66
67 /**
68  * I2c builtin prototypes.
69  * Do NOT use these function directly, instead,
70  * you can call the ones named without "_builtin_"
71  * and specify in cfg_i2c.h ( \see CONFIG_I2C_BACKEND)
72  * that you want the builtin backend.
73  * \{
74  */
75 void i2c_builtin_init(void);
76 bool i2c_builtin_start_w(uint8_t id);
77 bool i2c_builtin_start_r(uint8_t id);
78 void i2c_builtin_stop(void);
79 bool i2c_builtin_put(uint8_t _data);
80 int i2c_builtin_get(bool ack);
81 /*\}*/
82
83 /**
84  * I2c bitbang prototypes.
85  * Same thing here: do NOT use these function directly, instead,
86  * you can call the ones named without "_bitbang_"
87  * and specify in cfg_i2c.h ( \see CONFIG_I2C_BACKEND)
88  * that you want the bitbang backend.
89  * \{
90  */
91 void i2c_bitbang_init(void);
92 bool i2c_bitbang_start_w(uint8_t id);
93 bool i2c_bitbang_start_r(uint8_t id);
94 void i2c_bitbang_stop(void);
95 bool i2c_bitbang_put(uint8_t _data);
96 int i2c_bitbang_get(bool ack);
97 /*\}*/
98
99 #if CONFIG_I2C_BACKEND == I2C_BACKEND_BUILTIN
100         #define i2c_init    i2c_builtin_init
101         #define i2c_start_w i2c_builtin_start_w
102         #define i2c_start_r i2c_builtin_start_r
103         #define i2c_stop    i2c_builtin_stop
104         #define i2c_put     i2c_builtin_put
105         #define i2c_get     i2c_builtin_get
106 #elif CONFIG_I2C_BACKEND == I2C_BACKEND_BITBANG
107         #define i2c_init    i2c_bitbang_init
108         #define i2c_start_w i2c_bitbang_start_w
109         #define i2c_start_r i2c_bitbang_start_r
110         #define i2c_stop    i2c_bitbang_stop
111         #define i2c_put     i2c_bitbang_put
112         #define i2c_get     i2c_bitbang_get
113 #else
114         #error Unsupported i2c backend.
115 #endif
116
117 bool i2c_send(const void *_buf, size_t count);
118 bool i2c_recv(void *_buf, size_t count);
119
120 #endif