First implementation of i2c module for stm32.
[bertos.git] / bertos / cpu / cortex-m3 / drv / i2c_stm32.c
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 2003, 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief STM32F103xx I2C driver.
34  *
35  * \author Daniele Basile <asterix@develer.com>
36  */
37
38 #include "cfg/cfg_i2c.h"
39
40 #define LOG_LEVEL  I2C_LOG_LEVEL
41 #define LOG_FORMAT I2C_LOG_FORMAT
42 #include <cfg/log.h>
43
44 #include <cfg/debug.h>
45 #include <cfg/macros.h> // BV()
46 #include <cfg/module.h>
47
48 #include <drv/i2c.h>
49
50 /**
51  * Send START condition on the bus.
52  *
53  * \return true on success, false otherwise.
54  */
55 static bool i2c_builtin_start(void)
56 {
57
58         return false;
59 }
60
61
62 /**
63  * Send START condition and select slave for write.
64  * \c id is the device id comprehensive of address left shifted by 1.
65  * The LSB of \c id is ignored and reset to 0 for write operation.
66  *
67  * \return true on success, false otherwise.
68  */
69 bool i2c_builtin_start_w(uint8_t id)
70 {
71         return false;
72 }
73
74
75 /**
76  * Send START condition and select slave for read.
77  * \c id is the device id comprehensive of address left shifted by 1.
78  * The LSB of \c id is ignored and set to 1 for read operation.
79  *
80  * \return true on success, false otherwise.
81  */
82 bool i2c_builtin_start_r(uint8_t id)
83 {
84
85         return false;
86 }
87
88
89 /**
90  * Send STOP condition.
91  */
92 void i2c_builtin_stop(void)
93 {
94
95 }
96
97
98 /**
99  * Put a single byte in master transmitter mode
100  * to the selected slave device through the TWI bus.
101  *
102  * \return true on success, false on error.
103  */
104 bool i2c_builtin_put(const uint8_t data)
105 {
106
107         return true;
108 }
109
110 /**
111  * Get 1 byte from slave in master transmitter mode
112  * to the selected slave device through the TWI bus.
113  * If \a ack is true issue a ACK after getting the byte,
114  * otherwise a NACK is issued.
115  *
116  * \return the byte read if ok, EOF on errors.
117  */
118 int i2c_builtin_get(bool ack)
119 {
120
121         return 0;
122 }
123
124 MOD_DEFINE(i2c);
125
126 /**
127  * Initialize TWI module.
128  */
129 void i2c_builtin_init(void)
130 {
131         MOD_INIT(i2c);
132 }