ChibiOS/HAL  6.1.0
hal_i2c_lld.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_i2c_lld.c
19  * @brief PLATFORM I2C subsystem low level driver source.
20  *
21  * @addtogroup I2C
22  * @{
23  */
24 
25 #include "hal.h"
26 
27 #if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__)
28 
29 /*===========================================================================*/
30 /* Driver local definitions. */
31 /*===========================================================================*/
32 
33 /*===========================================================================*/
34 /* Driver exported variables. */
35 /*===========================================================================*/
36 
37 /**
38  * @brief I2C1 driver identifier.
39  */
40 #if (PLATFORM_I2C_USE_I2C1 == TRUE) || defined(__DOXYGEN__)
42 #endif
43 
44 /*===========================================================================*/
45 /* Driver local variables and types. */
46 /*===========================================================================*/
47 
48 /*===========================================================================*/
49 /* Driver local functions. */
50 /*===========================================================================*/
51 
52 /*===========================================================================*/
53 /* Driver interrupt handlers. */
54 /*===========================================================================*/
55 
56 /*===========================================================================*/
57 /* Driver exported functions. */
58 /*===========================================================================*/
59 
60 /**
61  * @brief Low level I2C driver initialization.
62  *
63  * @notapi
64  */
65 void i2c_lld_init(void) {
66 
67 #if PLATFORM_I2C_USE_I2C1 == TRUE
68  i2cObjectInit(&I2CD1);
69 #endif
70 }
71 
72 /**
73  * @brief Configures and activates the I2C peripheral.
74  *
75  * @param[in] i2cp pointer to the @p I2CDriver object
76  *
77  * @notapi
78  */
79 void i2c_lld_start(I2CDriver *i2cp) {
80 
81  if (i2cp->state == I2C_STOP) {
82  /* Enables the peripheral.*/
83 #if PLATFORM_I2C_USE_I2C1 == TRUE
84  if (&I2CD1 == i2cp) {
85 
86  }
87 #endif
88  }
89 
90 }
91 
92 /**
93  * @brief Deactivates the I2C peripheral.
94  *
95  * @param[in] i2cp pointer to the @p I2CDriver object
96  *
97  * @notapi
98  */
99 void i2c_lld_stop(I2CDriver *i2cp) {
100 
101  if (i2cp->state != I2C_STOP) {
102 
103  /* Disables the peripheral.*/
104 #if PLATFORM_I2C_USE_I2C1 == TRUE
105  if (&I2CD1 == i2cp) {
106 
107  }
108 #endif
109  }
110 }
111 
112 /**
113  * @brief Receives data via the I2C bus as master.
114  *
115  * @param[in] i2cp pointer to the @p I2CDriver object
116  * @param[in] addr slave device address
117  * @param[out] rxbuf pointer to the receive buffer
118  * @param[in] rxbytes number of bytes to be received
119  * @param[in] timeout the number of ticks before the operation timeouts,
120  * the following special values are allowed:
121  * - @a TIME_INFINITE no timeout.
122  * .
123  * @return The operation status.
124  * @retval MSG_OK if the function succeeded.
125  * @retval MSG_RESET if one or more I2C errors occurred, the errors can
126  * be retrieved using @p i2cGetErrors().
127  * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a
128  * timeout the driver must be stopped and restarted
129  * because the bus is in an uncertain state</b>.
130  *
131  * @notapi
132  */
134  uint8_t *rxbuf, size_t rxbytes,
135  sysinterval_t timeout) {
136 
137  (void)i2cp;
138  (void)addr;
139  (void)rxbuf;
140  (void)rxbytes;
141  (void)timeout;
142 
143  return MSG_OK;
144 }
145 
146 /**
147  * @brief Transmits data via the I2C bus as master.
148  *
149  * @param[in] i2cp pointer to the @p I2CDriver object
150  * @param[in] addr slave device address
151  * @param[in] txbuf pointer to the transmit buffer
152  * @param[in] txbytes number of bytes to be transmitted
153  * @param[out] rxbuf pointer to the receive buffer
154  * @param[in] rxbytes number of bytes to be received
155  * @param[in] timeout the number of ticks before the operation timeouts,
156  * the following special values are allowed:
157  * - @a TIME_INFINITE no timeout.
158  * .
159  * @return The operation status.
160  * @retval MSG_OK if the function succeeded.
161  * @retval MSG_RESET if one or more I2C errors occurred, the errors can
162  * be retrieved using @p i2cGetErrors().
163  * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a
164  * timeout the driver must be stopped and restarted
165  * because the bus is in an uncertain state</b>.
166  *
167  * @notapi
168  */
170  const uint8_t *txbuf, size_t txbytes,
171  uint8_t *rxbuf, size_t rxbytes,
172  sysinterval_t timeout) {
173 
174  (void)i2cp;
175  (void)addr;
176  (void)txbuf;
177  (void)txbytes;
178  (void)rxbuf;
179  (void)rxbytes;
180  (void)timeout;
181 
182  return MSG_OK;
183 }
184 
185 #endif /* HAL_USE_I2C == TRUE */
186 
187 /** @} */
void i2c_lld_stop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
Definition: hal_i2c_lld.c:99
msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr, const uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, sysinterval_t timeout)
Transmits data via the I2C bus as master.
Definition: hal_i2c_lld.c:169
HAL subsystem header.
void i2cObjectInit(I2CDriver *i2cp)
Initializes the standard part of a I2CDriver structure.
Definition: hal_i2c.c:71
msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr, uint8_t *rxbuf, size_t rxbytes, sysinterval_t timeout)
Receives data via the I2C bus as master.
Definition: hal_i2c_lld.c:133
int32_t msg_t
Type of a message.
Definition: osal.h:160
Structure representing an I2C driver.
Definition: hal_i2c_lld.h:88
I2CDriver I2CD1
I2C1 driver identifier.
Definition: hal_i2c_lld.c:41
void i2c_lld_start(I2CDriver *i2cp)
Configures and activates the I2C peripheral.
Definition: hal_i2c_lld.c:79
uint32_t sysinterval_t
Type of system time interval.
Definition: osal.h:170
void i2c_lld_init(void)
Low level I2C driver initialization.
Definition: hal_i2c_lld.c:65
uint16_t i2caddr_t
Type representing an I2C address.
Definition: hal_i2c_lld.h:63
i2cstate_t state
Driver state.
Definition: hal_i2c_lld.h:92