ChibiOS/HAL 9.0.0
hal_i2c_lld.h
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.h
19 * @brief PLATFORM I2C subsystem low level driver header.
20 *
21 * @addtogroup I2C
22 * @{
23 */
24
25#ifndef HAL_I2C_LLD_H
26#define HAL_I2C_LLD_H
27
28#if (HAL_USE_I2C == TRUE) || defined(__DOXYGEN__)
29
30/*===========================================================================*/
31/* Driver constants. */
32/*===========================================================================*/
33
34/*===========================================================================*/
35/* Driver pre-compile time settings. */
36/*===========================================================================*/
37
38/**
39 * @name PLATFORM configuration options
40 * @{
41 */
42/**
43 * @brief I2C1 driver enable switch.
44 * @details If set to @p TRUE the support for I2C1 is included.
45 * @note The default is @p FALSE.
46 */
47#if !defined(PLATFORM_I2C_USE_I2C1) || defined(__DOXYGEN__)
48#define PLATFORM_I2C_USE_I2C1 FALSE
49#endif
50/** @} */
51
52/*===========================================================================*/
53/* Derived constants and error checks. */
54/*===========================================================================*/
55
56/*===========================================================================*/
57/* Driver data structures and types. */
58/*===========================================================================*/
59
60/**
61 * @brief Type representing an I2C address.
62 */
63typedef uint16_t i2caddr_t;
64
65/**
66 * @brief Type of I2C Driver condition flags.
67 */
68typedef uint32_t i2cflags_t;
69
70/**
71 * @brief I2C driver configuration structure.
72 * @note Implementations may extend this structure to contain more,
73 * architecture dependent, fields.
74 */
76 /* End of the mandatory fields.*/
77 uint32_t dummy;
78};
79
80/**
81 * @brief Type of a structure representing an I2C configuration.
82 */
84
85/**
86 * @brief Type of a structure representing an I2C driver.
87 */
89
90/**
91 * @brief Structure representing an I2C driver.
92 */
94 /**
95 * @brief Driver state.
96 */
98 /**
99 * @brief Current configuration data.
100 */
102 /**
103 * @brief Error flags.
104 */
106#if (I2C_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
108#endif
109#if defined(I2C_DRIVER_EXT_FIELDS)
110 I2C_DRIVER_EXT_FIELDS
111#endif
112 /* End of the mandatory fields.*/
113};
114
115/*===========================================================================*/
116/* Driver macros. */
117/*===========================================================================*/
118
119/**
120 * @brief Get errors from I2C driver.
121 *
122 * @param[in] i2cp pointer to the @p I2CDriver object
123 *
124 * @notapi
125 */
126#define i2c_lld_get_errors(i2cp) ((i2cp)->errors)
127
128/*===========================================================================*/
129/* External declarations. */
130/*===========================================================================*/
131
132#if (PLATFORM_I2C_USE_I2C1 == TRUE) && !defined(__DOXYGEN__)
133extern I2CDriver I2CD1;
134#endif
135
136#ifdef __cplusplus
137extern "C" {
138#endif
139 void i2c_lld_init(void);
140 void i2c_lld_start(I2CDriver *i2cp);
141 void i2c_lld_stop(I2CDriver *i2cp);
143 const uint8_t *txbuf, size_t txbytes,
144 uint8_t *rxbuf, size_t rxbytes,
145 sysinterval_t timeout);
147 uint8_t *rxbuf, size_t rxbytes,
148 sysinterval_t timeout);
149#ifdef __cplusplus
150}
151#endif
152
153#endif /* HAL_USE_I2C == TRUE */
154
155#endif /* HAL_I2C_LLD_H */
156
157/** @} */
void i2c_lld_stop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
Definition hal_i2c_lld.c:99
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
uint32_t i2cflags_t
Type of I2C Driver condition flags.
Definition hal_i2c_lld.h:68
struct hal_i2c_config I2CConfig
Type of a structure representing an I2C configuration.
Definition hal_i2c_lld.h:83
void i2c_lld_start(I2CDriver *i2cp)
Configures and activates the I2C peripheral.
Definition hal_i2c_lld.c:79
i2cstate_t
Driver state machine possible states.
Definition hal_i2c.h:84
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
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
uint32_t mutex_t
Type of a mutex.
Definition osal.h:229
I2C driver configuration structure.
Definition hal_i2c_lld.h:75
uint32_t dummy
Definition hal_i2c_lld.h:77
Structure representing an I2C driver.
Definition hal_i2c_lld.h:93
const I2CConfig * config
Current configuration data.
i2cflags_t errors
Error flags.
i2cstate_t state
Driver state.
Definition hal_i2c_lld.h:97