ChibiOS/HAL  6.1.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  */
63 typedef uint16_t i2caddr_t;
64 
65 /**
66  * @brief Type of I2C Driver condition flags.
67  */
68 typedef uint32_t i2cflags_t;
69 
70 /**
71  * @brief Type of I2C driver configuration structure.
72  * @note Implementations may extend this structure to contain more,
73  * architecture dependent, fields.
74  */
75 typedef struct {
76  /* End of the mandatory fields.*/
77  uint32_t dummy;
78 } I2CConfig;
79 
80 /**
81  * @brief Type of a structure representing an I2C driver.
82  */
83 typedef struct I2CDriver I2CDriver;
84 
85 /**
86  * @brief Structure representing an I2C driver.
87  */
88 struct I2CDriver {
89  /**
90  * @brief Driver state.
91  */
93  /**
94  * @brief Current configuration data.
95  */
96  const I2CConfig *config;
97  /**
98  * @brief Error flags.
99  */
101 #if (I2C_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
102  mutex_t mutex;
103 #endif
104 #if defined(I2C_DRIVER_EXT_FIELDS)
105  I2C_DRIVER_EXT_FIELDS
106 #endif
107  /* End of the mandatory fields.*/
108 };
109 
110 /*===========================================================================*/
111 /* Driver macros. */
112 /*===========================================================================*/
113 
114 /**
115  * @brief Get errors from I2C driver.
116  *
117  * @param[in] i2cp pointer to the @p I2CDriver object
118  *
119  * @notapi
120  */
121 #define i2c_lld_get_errors(i2cp) ((i2cp)->errors)
122 
123 /*===========================================================================*/
124 /* External declarations. */
125 /*===========================================================================*/
126 
127 #if (PLATFORM_I2C_USE_I2C1 == TRUE) && !defined(__DOXYGEN__)
128 extern I2CDriver I2CD1;
129 #endif
130 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134  void i2c_lld_init(void);
135  void i2c_lld_start(I2CDriver *i2cp);
136  void i2c_lld_stop(I2CDriver *i2cp);
138  const uint8_t *txbuf, size_t txbytes,
139  uint8_t *rxbuf, size_t rxbytes,
140  sysinterval_t timeout);
142  uint8_t *rxbuf, size_t rxbytes,
143  sysinterval_t timeout);
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* HAL_USE_I2C == TRUE */
149 
150 #endif /* HAL_I2C_LLD_H */
151 
152 /** @} */
void i2c_lld_stop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
Definition: hal_i2c_lld.c:99
Type of I2C driver configuration structure.
Definition: hal_i2c_lld.h:75
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
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
uint32_t i2cflags_t
Type of I2C Driver condition flags.
Definition: hal_i2c_lld.h:68
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
i2cflags_t errors
Error flags.
Definition: hal_i2c_lld.h:100
const I2CConfig * config
Current configuration data.
Definition: hal_i2c_lld.h:96
i2cstate_t
Driver state machine possible states.
Definition: hal_i2c.h:77
uint32_t mutex_t
Type of a mutex.
Definition: osal.h:223
i2cstate_t state
Driver state.
Definition: hal_i2c_lld.h:92