RTEMS  5.0.0
i2c.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2010
11  * embedded brains GmbH
12  * Obere Lagerstr. 30
13  * D-82178 Puchheim
14  * Germany
15  * <rtems@embedded-brains.de>
16  *
17  * The license and distribution terms for this file may be
18  * found in the file LICENSE in this distribution or at
19  * http://www.rtems.org/license/LICENSE.
20  */
21 
22 #ifndef LIBBSP_ARM_LPC32XX_I2C_H
23 #define LIBBSP_ARM_LPC32XX_I2C_H
24 
25 #include <rtems.h>
26 
27 #include <bsp/lpc32xx.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif /* __cplusplus */
32 
52 #define I2CCLK_1_EN BSP_BIT32(0)
53 #define I2CCLK_2_EN BSP_BIT32(1)
54 #define I2CCLK_1_HIGH_DRIVE BSP_BIT32(2)
55 #define I2CCLK_2_HIGH_DRIVE BSP_BIT32(3)
56 #define I2CCLK_USB_HIGH_DRIVE BSP_BIT32(4)
57 
66 #define I2C_TX_READ BSP_BIT32(0)
67 #define I2C_TX_ADDR(val) BSP_FLD32(val, 1, 7)
68 #define I2C_TX_START BSP_BIT32(8)
69 #define I2C_TX_STOP BSP_BIT32(9)
70 
79 #define I2C_STAT_TDI BSP_BIT32(0)
80 #define I2C_STAT_AFI BSP_BIT32(1)
81 #define I2C_STAT_NAI BSP_BIT32(2)
82 #define I2C_STAT_DRMI BSP_BIT32(3)
83 #define I2C_STAT_DRSI BSP_BIT32(4)
84 #define I2C_STAT_ACTIVE BSP_BIT32(5)
85 #define I2C_STAT_SCL BSP_BIT32(6)
86 #define I2C_STAT_SDA BSP_BIT32(7)
87 #define I2C_STAT_RFF BSP_BIT32(8)
88 #define I2C_STAT_RFE BSP_BIT32(9)
89 #define I2C_STAT_TFF BSP_BIT32(10)
90 #define I2C_STAT_TFE BSP_BIT32(11)
91 #define I2C_STAT_TFFS BSP_BIT32(12)
92 #define I2C_STAT_TFES BSP_BIT32(13)
93 
102 #define I2C_CTRL_TDIE BSP_BIT32(0)
103 #define I2C_CTRL_AFIE BSP_BIT32(1)
104 #define I2C_CTRL_NAIE BSP_BIT32(2)
105 #define I2C_CTRL_DRMIE BSP_BIT32(3)
106 #define I2C_CTRL_DRSIE BSP_BIT32(4)
107 #define I2C_CTRL_RFFIE BSP_BIT32(5)
108 #define I2C_CTRL_RFDAIE BSP_BIT32(6)
109 #define I2C_CTRL_TFFIO BSP_BIT32(7)
110 #define I2C_CTRL_RESET BSP_BIT32(8)
111 #define I2C_CTRL_SEVEN BSP_BIT32(9)
112 #define I2C_CTRL_TFFSIE BSP_BIT32(10)
113 
126  volatile lpc32xx_i2c *i2c,
127  unsigned clock_in_hz
128 );
129 
133 void lpc32xx_i2c_reset(volatile lpc32xx_i2c *i2c);
134 
144  volatile lpc32xx_i2c *i2c,
145  unsigned clock_in_hz
146 );
147 
160  volatile lpc32xx_i2c *i2c,
161  unsigned addr
162 );
163 
174  volatile lpc32xx_i2c *i2c,
175  const uint8_t *out,
176  size_t n,
177  bool stop
178 );
179 
192  volatile lpc32xx_i2c *i2c,
193  unsigned addr
194 );
195 
204  volatile lpc32xx_i2c *i2c,
205  uint8_t *in,
206  size_t n,
207  bool stop
208 );
209 
219  volatile lpc32xx_i2c *i2c,
220  unsigned addr,
221  const uint8_t *out,
222  size_t out_size,
223  uint8_t *in,
224  size_t in_size
225 );
226 
235 static inline rtems_status_code lpc32xx_i2c_write(
236  volatile lpc32xx_i2c *i2c,
237  unsigned addr,
238  const uint8_t *out,
239  size_t out_size
240 )
241 {
242  return lpc32xx_i2c_write_and_read(i2c, addr, out, out_size, NULL, 0);
243 }
244 
253 static inline rtems_status_code lpc32xx_i2c_read(
254  volatile lpc32xx_i2c *i2c,
255  unsigned addr,
256  uint8_t *in,
257  size_t in_size
258 )
259 {
260  return lpc32xx_i2c_write_and_read(i2c, addr, NULL, 0, in, in_size);
261 }
262 
265 #ifdef __cplusplus
266 }
267 #endif /* __cplusplus */
268 
269 #endif /* LIBBSP_ARM_LPC32XX_I2C_H */
rtems_status_code lpc32xx_i2c_read_start(volatile lpc32xx_i2c *i2c, unsigned addr)
Starts a read transaction on the I2C module i2c.
Definition: i2c.c:129
rtems_status_code lpc32xx_i2c_write_and_read(volatile lpc32xx_i2c *i2c, unsigned addr, const uint8_t *out, size_t out_size, uint8_t *in, size_t in_size)
Writes and reads data via the I2C module i2c.
Definition: i2c.c:216
Definition: 8xx_immap.h:216
rtems_status_code lpc32xx_i2c_read_with_optional_stop(volatile lpc32xx_i2c *i2c, uint8_t *in, size_t n, bool stop)
Reads data via the I2C module i2c with optional stop.
Definition: i2c.c:174
rtems_status_code lpc32xx_i2c_write_with_optional_stop(volatile lpc32xx_i2c *i2c, const uint8_t *out, size_t n, bool stop)
Writes data via the I2C module i2c with optional stop.
Definition: i2c.c:137
Register base addresses.
rtems_status_code
Classic API Status.
Definition: status.h:43
void lpc32xx_i2c_reset(volatile lpc32xx_i2c *i2c)
Resets the I2C module i2c.
Definition: i2c.c:28
rtems_status_code lpc32xx_i2c_write_start(volatile lpc32xx_i2c *i2c, unsigned addr)
Starts a write transaction on the I2C module i2c.
Definition: i2c.c:121
rtems_status_code lpc32xx_i2c_clock(volatile lpc32xx_i2c *i2c, unsigned clock_in_hz)
Sets the I2C module i2c clock.
Definition: i2c.c:55
rtems_status_code lpc32xx_i2c_init(volatile lpc32xx_i2c *i2c, unsigned clock_in_hz)
Initializes the I2C module i2c.
Definition: i2c.c:33
Definition: lpc32xx.h:475
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77