ChibiOS/HAL 9.0.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 */
65void i2c_lld_init(void) {
66
67#if PLATFORM_I2C_USE_I2C1 == TRUE
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 */
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 */
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 * @return The operation status.
123 * @retval MSG_OK if the function succeeded.
124 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
125 * be retrieved using @p i2cGetErrors().
126 * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a
127 * timeout the driver must be stopped and restarted
128 * because the bus is in an uncertain state</b>.
129 *
130 * @notapi
131 */
133 uint8_t *rxbuf, size_t rxbytes,
134 sysinterval_t timeout) {
135
136 (void)i2cp;
137 (void)addr;
138 (void)rxbuf;
139 (void)rxbytes;
140 (void)timeout;
141
142 return MSG_OK;
143}
144
145/**
146 * @brief Transmits data via the I2C bus as master.
147 *
148 * @param[in] i2cp pointer to the @p I2CDriver object
149 * @param[in] addr slave device address
150 * @param[in] txbuf pointer to the transmit buffer
151 * @param[in] txbytes number of bytes to be transmitted
152 * @param[out] rxbuf pointer to the receive buffer
153 * @param[in] rxbytes number of bytes to be received
154 * @param[in] timeout the number of ticks before the operation timeouts,
155 * the following special values are allowed:
156 * - @a TIME_INFINITE no timeout.
157 * @return The operation status.
158 * @retval MSG_OK if the function succeeded.
159 * @retval MSG_RESET if one or more I2C errors occurred, the errors can
160 * be retrieved using @p i2cGetErrors().
161 * @retval MSG_TIMEOUT if a timeout occurred before operation end. <b>After a
162 * timeout the driver must be stopped and restarted
163 * because the bus is in an uncertain state</b>.
164 *
165 * @notapi
166 */
168 const uint8_t *txbuf, size_t txbytes,
169 uint8_t *rxbuf, size_t rxbytes,
170 sysinterval_t timeout) {
171
172 (void)i2cp;
173 (void)addr;
174 (void)txbuf;
175 (void)txbytes;
176 (void)rxbuf;
177 (void)rxbytes;
178 (void)timeout;
179
180 return MSG_OK;
181}
182
183#endif /* HAL_USE_I2C == TRUE */
184
185/** @} */
void i2c_lld_stop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
Definition hal_i2c_lld.c:99
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.
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
uint16_t i2caddr_t
Type representing an I2C address.
Definition hal_i2c_lld.h:63
void i2c_lld_init(void)
Low level I2C driver initialization.
Definition hal_i2c_lld.c:65
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.
struct hal_i2c_driver I2CDriver
Type of a structure representing an I2C driver.
Definition hal_i2c_lld.h:88
@ I2C_STOP
Stopped.
Definition hal_i2c.h:86
int32_t msg_t
Type of a message.
Definition osal.h:159
uint32_t sysinterval_t
Type of system time interval.
Definition osal.h:169
#define MSG_OK
Definition osal.h:56
HAL subsystem header.
i2cstate_t state
Driver state.
Definition hal_i2c_lld.h:97