Mistake on this page?
Report an issue in GitHub or email us
i2c_api.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2019 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /** \addtogroup hal */
19 /** @{*/
20 
21 #ifndef MBED_I2C_API_H
22 #define MBED_I2C_API_H
23 
24 #include "device.h"
25 #include "pinmap.h"
26 #include "hal/buffer.h"
27 
28 #if DEVICE_I2C_ASYNCH
29 #include "hal/dma_api.h"
30 #endif
31 
32 #include <stdbool.h>
33 
34 #if DEVICE_I2C
35 
36 /**
37  * \defgroup hal_i2c I2C hal
38  *
39  * The I2C hal provides a low level interface to the I2C interface of a target.
40  *
41  * # Defined behavior
42  * * The function ::i2c_init initializes the peripheral pins specified in the input parameters,
43  * initializes the peripheral in master mode if `is_slave` is false,
44  * initializes the peripheral in slave mode if `is_slave` is true and `supports_slave_mode` is true - Verified by test ::fpga_i2c_test_init_free.
45  * * The function ::i2c_free resets the pins used to initialize the peripheral to their default state and
46  * disables the peripheral clock - Verified by test ::fpga_i2c_test_init_free.
47  * * The function ::i2c_get_capabilities fills the contents of the `i2c_capabilities_t` parameter - Verified by test ::fpga_i2c_test_get_capabilities.
48  * * The function ::i2c_frequency sets the frequency to use for the transfer, returns the actual frequency used and
49  * must leave all other configuration unchanged - Verified by test ::fpga_i2c_test_frequency.
50  * * The function ::i2c_timeout sets the transmision timeout to use for the following blocking transfers.
51  * If the timeout is not set, the default timeout is used.
52  * The default timeout value is based on I2C frequency. It's computed as triple the amount of time it would take to send data over I2C - Verified by test ::fpga_i2c_test_blocking_transmission_timeout.
53  * * The function ::i2c_write writes `length` number of symbols to the bus, returns the number of symbols sent to the bus,
54  * returns an error code if the transfer fails, generates a stop condition on the bus at the end of the transfer if `stop` parameter is true,
55  * and handles transfer collisions and loss of arbitration if the platform supports multimaster in hardware.
56  * The transfer times out and returns `I2C_ERROR_TIMEOUT ` if the transfer takes longer than the configured timeout duration - Verified by test ::fpga_i2c_test_blocking_write_read.
57  * * The function ::i2c_read reads `length` symbols from the bus, returns the number of symbols received from the bus,
58  * returns an error code if the transfer fails, generates a stop condition on the bus at the end of the transfer if `stop` parameter is true
59  * and handles transfer collisions and loss of arbitration if the platform supports multimaster in hardware.
60  * The transfer times out and returns `I2C_ERROR_TIMEOUT ` if the transfer takes longer than the configured timeout duration - Verified by test ::fpga_i2c_test_blocking_write_read.
61  * * The function ::i2c_start generates I2C START condition on the bus in master mode and does nothing if called when the peripheral is configured in slave mode.
62  * * The function ::i2c_stop generates I2C STOP condition on the bus in master mode and does nothing if called when the peripheral is configured in slave mode
63  * - Verified by test ::fpga_i2c_test_blocking_write_read ::fpga_i2c_test_async_write_read.
64  * * The function ::i2c_slave_status indicates which mode the peripheral has been addressed in and returns not addressed when called in master mode.
65  * * The function ::i2c_slave_address sets the address of the peripheral to the `address` parameter and does nothing if called in master mode.
66  * * The function ::i2c_transfer_async returns immediately with a `bool` indicating whether the transfer was successfully scheduled.
67  * The callback given to `i2c_transfer_async` is invoked when the transfer finishes or an error occurs and
68  * must save the handler and context pointers inside the `obj` pointer. The context pointer is passed to the callback on transfer completion.
69  * The callback must be invoked on completion unless the transfer is aborted and
70  * may handle transfer collisions and loss of arbitration if the platform supports multimaster in hardware and enabled in API.
71  * `i2c_async_event_t` must be filled with the number of symbols sent to the bus during transfer - Verified by test ::fpga_i2c_test_async_write_read.
72  * * The function ::i2c_abort_async aborts any ongoing async transfers - Verified by test ::fpga_i2c_test_async_abort.
73  *
74  * # Undefined behaviors
75  *
76  * * Use of a `null` pointer as an argument to any function.
77  * * Calling any `I2C` function before calling ::i2c_init or after calling ::i2c_free.
78  * * Initializing the `I2C` peripheral with invalid `SDA` and `SCL` pins.
79  * * Initializing the peripheral in slave mode if slave mode is not supported, indicated by ::i2c_get_capabilities.
80  * * Operating the peripheral in slave mode without first specifying an address using ::i2c_slave_address.
81  * * Setting an address using i2c_slave_address after initializing the peripheral in master mode.
82  * * Setting an address to an `I2C` reserved value.
83  * * Setting an address larger than the 7-bit supported maximum if 10-bit addressing is not supported.
84  * * Setting an address larger than the 10-bit supported maximum.
85  * * Setting a frequency outside the supported range given by ::i2c_get_capabilities.
86  * * Using the device in a multimaster configuration when `supports_multimaster_mode` is false.
87  * * Specifying an invalid address when calling any `read` or `write` functions.
88  * * Setting the length of the transfer or receive buffers to larger than the buffers are.
89  * * Passing an invalid pointer as `handler` to ::i2c_transfer_async.
90  * * Calling ::i2c_abort_async when no transfer is in progress.
91  *
92  * @{
93  */
94 
95 /**
96  * \defgroup hal_i2c_tests I2C hal tests
97  * The I2C test validate proper implementation of the I2C hal.
98  *
99  * To run the I2C hal tests, use the command:
100  *
101  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal_fpga_ci_test_shield-i2c
102  */
103 
104 
105 /**
106  * @defgroup hal_I2CEvents I2C Events Macros
107  *
108  * @{
109  */
110 #define I2C_EVENT_ERROR (1 << 1)
111 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
112 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
113 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
114 #define I2C_EVENT_ARBITRATION_LOST (1 << 5)
115 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | \
116  I2C_EVENT_TRANSFER_COMPLETE | \
117  I2C_EVENT_ERROR_NO_SLAVE | \
118  I2C_EVENT_TRANSFER_EARLY_NACK | \
119  I2C_EVENT_ARBITRATION_LOST)
120 
121 /**@}*/
122 
123 typedef struct i2c i2c_t;
124 
125 #if DEVICE_I2C_ASYNCH
126 /** Structure describing the status of async transfer */
127 typedef struct i2c_async_event {
128  uint32_t sent_bytes;
129  uint32_t received_bytes;
130  int32_t error_status; // error description I2C_ERROR_XXX
131  bool error;
133 
134 /** Asynchronous transfer callback.
135  *
136  * @param obj The I2C object
137  * @param event Pointer to the event holding async transfer status
138  * @param ctx The context pointer
139  *
140  * @note Callback is invoked when async transfer completes or when an error is detected.
141  */
142 typedef void (*i2c_async_handler_f)(i2c_t *obj, i2c_async_event_t *event, void *ctx);
143 #endif
144 
145 /** I2C HAL structure */
146 struct i2c {
147  struct i2c_s i2c; /**< Target specific I2C structure */
148 #if DEVICE_I2C_ASYNCH
149  struct buffer_s tx_buff; /**< Tx buffer */
150  struct buffer_s rx_buff; /**< Rx buffer */
151  i2c_async_handler_f handler;
152  void *ctx;
153 #endif
154 };
155 
156 /** Transmission error codes */
157 enum {
158  I2C_ERROR_NO_SLAVE = -1,
159  I2C_ERROR_BUS_BUSY = -2,
160  I2C_ERROR_TIMEOUT = -3,
161  I2C_ERROR_ARBITRATION_LOST = -4
162 };
163 
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167 
168 typedef struct {
169  /**< Minimum frequency supported must be set by target device */
171  /**< Maximum frequency supported must be set by target device */
173  /**< If true, the device can handle I2C slave mode. */
175  /**< If true, supports 10-bit addressing. */
177  /**< If true, the device handle multimaster collisions and arbitration safely*/
179  /**< If true, supports configuring clock stretching. */
180  bool supports_clock_stretching;
182 
183 /**
184  * \defgroup hal_GeneralI2C I2C Configuration Functions
185  *
186  * # Defined behavior
187  * * ::i2c_init initializes i2c_t control structure
188  * * ::i2c_init configures the pins used by I2C
189  * * ::i2c_free returns the pins owned by the I2C object to their reset state
190  * * ::i2c_frequency configure the I2C frequency
191  * * ::i2c_start sends START command
192  * * ::i2c_read reads `length` bytes from the I2C slave specified by `address` to the `data` buffer
193  * * ::i2c_read reads generates a stop condition on the bus at the end of the transfer if `stop` parameter is non-zero
194  * * ::i2c_read reads returns the number of symbols received from the bus
195  * * ::i2c_write writes `length` bytes to the I2C slave specified by `address` from the `data` buffer
196  * * ::i2c_write generates a stop condition on the bus at the end of the transfer if `stop` parameter is non-zero
197  * * ::i2c_write returns zero on success, error code otherwise
198  * * ::i2c_reset resets the I2C peripheral
199  * * ::i2c_byte_read reads and return one byte from the specfied I2C slave
200  * * ::i2c_byte_read uses `last` parameter to inform the slave that all bytes have been read
201  * * ::i2c_byte_write writes one byte to the specified I2C slave
202  * * ::i2c_byte_write returns 0 if NAK was received, 1 if ACK was received, 2 for timeout
203  * * ::i2c_slave_mode enables/disables I2S slave mode
204  * * ::i2c_slave_receive returns: 1 - read addresses, 2 - write to all slaves, 3 write addressed, 0 - the slave has not been addressed
205  * * ::i2c_slave_read reads `length` bytes from the I2C master to the `data` buffer
206  * * ::i2c_slave_read returns non-zero if a value is available, 0 otherwise
207  * * ::i2c_slave_write writes `length` bytes to the I2C master from the `data` buffer
208  * * ::i2c_slave_write returns non-zero if a value is available, 0 otherwise
209  * * ::i2c_slave_address configures I2C slave address
210  * * ::i2c_transfer_asynch starts I2C asynchronous transfer
211  * * ::i2c_transfer_asynch writes `tx_length` bytes to the I2C slave specified by `address` from the `tx` buffer
212  * * ::i2c_transfer_asynch reads `rx_length` bytes from the I2C slave specified by `address` to the `rx` buffer
213  * * ::i2c_transfer_asynch generates a stop condition on the bus at the end of the transfer if `stop` parameter is non-zero
214  * * The callback given to ::i2c_transfer_asynch is invoked when the transfer completes
215  * * ::i2c_transfer_asynch specifies the logical OR of events to be registered
216  * * The ::i2c_transfer_asynch function may use the `DMAUsage` hint to select the appropriate async algorithm
217  * * ::i2c_irq_handler_asynch returns event flags if a transfer termination condition was met, otherwise returns 0.
218  * * ::i2c_active returns non-zero if the I2C module is active or 0 if it is not
219  * * ::i2c_abort_asynch aborts an on-going async transfer
220  *
221  * # Undefined behavior
222  * * Calling ::i2c_init multiple times on the same `i2c_t`
223  * * Calling any function other than ::i2c_init on a non-initialized `i2c_t`
224  * * Initialising the `I2C` peripheral with invalid `SDA` and `SCL` pins.
225  * * Passing pins that cannot be on the same peripheral
226  * * Passing an invalid pointer as `obj` to any function
227  * * Use of a `null` pointer as an argument to any function.
228  * * Initialising the peripheral in slave mode if slave mode is not supported
229  * * Operating the peripheral in slave mode without first specifying and address using ::i2c_slave_address
230  * * Setting an address using i2c_slave_address after initialising the peripheral in master mode
231  * * Setting an address to an `I2C` reserved value
232  * * Specifying an invalid address when calling any `read` or `write` functions
233  * * Setting the length of the transfer or receive buffers to larger than the buffers are
234  * * Passing an invalid pointer as `handler`
235  * * Calling ::i2c_abort_async when no transfer is currently in progress
236  *
237  *
238  * @{
239  */
240 
241 /**
242  * \defgroup hal_GeneralI2C_tests I2C hal tests
243  * The I2C HAL tests ensure driver conformance to defined behaviour.
244  *
245  * To run the I2C hal tests use the command:
246  *
247  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal_fpga_ci_test_shield-i2c
248  *
249  */
250 
251 
252 /** Fills structure indicating supported features and frequencies on the current
253  * platform.
254  *
255  * @param[out] capabilities Capabilities structure filled with supported
256  * configurations.
257  */
258 void i2c_get_capabilities(i2c_capabilities_t *capabilities);
259 
260 /** Initialize the I2C peripheral. It sets the default parameters for the I2C
261  * peripheral and configures its pins.
262  *
263  * @param obj The I2C object
264  * @param sda The sda pin
265  * @param scl The scl pin
266  * @param is_slave Choose whether the peripheral is initialized as master or
267  * slave.
268  */
269 void i2c_init(i2c_t *obj, PinName sda, PinName scl, bool is_slave);
270 
271 /** Release the I2C object.
272  *
273  * @param obj The I2C object to deinitialize
274  */
275 void i2c_free(i2c_t *obj);
276 
277 /** Configure the frequency in Hz at which the I2C peripheral should operate.
278  *
279  * @param obj The I2C object
280  * @param frequency Frequency in Hz
281  *
282  * @returns The actual frequency that the peripheral generates to
283  * allow a user to adjust its strategy in case the target cannot be
284  * reached.
285  */
286 uint32_t i2c_frequency(i2c_t *obj, uint32_t frequency);
287 
288 /** Enable or disable clock stretching for the I2C peripheral.
289  *
290  * @param obj The I2C object
291  * @param enabled If 'true', enable clock stretching on the given I2C peripheral;
292  * otherwise, disable it.
293  */
294 void i2c_set_clock_stretching(i2c_t *obj, bool enabled);
295 
296 /** Configure the timeout duration in microseconds for blocking transmission
297  *
298  * @param obj The I2C object
299  * @param timeout Transmission timeout in microseconds.
300  *
301  * @note If no timeout is set, the default timeout is used.
302  * Default timeout value is based on I2C frequency.
303  * Byte timeout is computed as triple amount of time it would take
304  * to send 10 bit over I2C and is expressed by the formula:
305  * byte_timeout = 3 * (1/frequency * 10 * 1000000)
306  */
307 void i2c_timeout(i2c_t *obj, uint32_t timeout);
308 
309 /** Send START command
310  *
311  * @param obj The I2C object.
312  */
313 void i2c_start(i2c_t *obj);
314 
315 /** Send STOP command
316  *
317  * @param obj The I2C object
318  */
319 void i2c_stop(i2c_t *obj);
320 
321 /** Blocking sending data
322  *
323  * This function transmits data when the peripheral is configured as Master to
324  * the selected slave and when configured as Slave transmits data to the
325  * Master.
326  *
327  * This function is blocking; it returns when the transfer is complete or a
328  * timeout event is triggered. The number of bytes transmitted is returned by
329  * the function after the operation is completed. Transmit operation cannot be
330  * canceled or aborted.
331  *
332  * The data buffer must stay allocated during the duration of the transfer, and
333  * the contents must not be modified. The value of the specified `address` is
334  * ignored when configured in slave mode. In master mode, it contains the
335  * address of the target peripheral. This is a 7-bit value unless 10-bit
336  * addressing is configured, and the target supports it.
337  *
338  * When in master mode, the operation consists of:
339  * - Addressing the slave as a Master transmitter.
340  * - Transmitting data to the addressed slave.
341  * - Generating a STOP condition if the specified `stop` field is true.
342  *
343  * @param obj The I2C object
344  * @param address 7/10-bit address (last bit is 0)
345  * @param data The buffer for sending
346  * @param length Number of bytes to write
347  * @param stop If true, stop is generated after the transfer is done
348  *
349  * @note If the current platform supports multimaster operation, the peripheral
350  * performs arbitration automatically when detecting collisions and
351  * completes the transfer or returns I2C_ERROR_ARBITRATION_LOST
352  * when it loses arbitration.
353  *
354  * Additional time for arbitration or clock stretching should by count
355  * by setting appropriate timeout value.
356  *
357  * When no transmision timeout is set by the user, the default timeout value is
358  * used. It counts one additional byte for addressing stage:
359  * default_timeout = (length + 1) * byte_timeout.
360  *
361  * @return
362  * zero or nonzero - Number of written bytes
363  * negative - I2C_ERROR_XXX status
364  */
365 int32_t i2c_write(i2c_t *obj, uint16_t address, const uint8_t *data,
366  uint32_t length, bool stop);
367 
368 /** Blocking reading data
369  *
370  * This function receives data when the peripheral is configured as Master
371  * from the selected slave and when configured as Slave from the Master.
372  *
373  * This function is blocking; it returns when the transfer is complete or a
374  * timeout event is triggered. The number of bytes received is returned by
375  * the function after the operation is completed. Receive operation cannot be
376  * canceled or aborted.
377  *
378  * When in master mode, the operation consists of:
379  * - Addressing the slave as a Master receiver.
380  * - Receiving data from the addressed slave.
381  * - Generating a STOP condition if the specified `stop` field is true.
382  *
383  * @param obj The I2C object
384  * @param address 7/10-bit address (last bit is 1)
385  * @param data The buffer for receiving
386  * @param length Number of bytes to read
387  * @param stop If true, stop is generated after the transfer is done
388  *
389  * @note If the current platform supports multimaster operation, the peripheral
390  * performs arbitration automatically when detecting collisions and
391  * completes the transfer or returns I2C_ERROR_ARBITRATION_LOST
392  * when it loses arbitration.
393  *
394  * Additional time for arbitration or clock stretching should by count
395  * by setting appropriate timeout value.
396  *
397  * When no transmision timeout is set by the user, the default timeout value is
398  * used. It counts one additional byte for addressing stage:
399  * default_timeout = (length + 1) * byte_timeout.
400  *
401  * @return
402  * zero or nonzero - Number of written bytes
403  * negative - I2C_ERROR_XXX status
404  */
405 int32_t i2c_read(i2c_t *obj, uint16_t address, uint8_t *data, uint32_t length,
406  bool stop);
407 
408 /** Get the pins that support I2C SDA
409  *
410  * Return a PinMap array of pins that support I2C SDA in
411  * master mode. The array is terminated with {NC, NC, 0}.
412  *
413  * @return PinMap array
414  */
415 const PinMap *i2c_master_sda_pinmap(void);
416 
417 /** Get the pins that support I2C SCL
418  *
419  * Return a PinMap array of pins that support I2C SCL in
420  * master mode. The array is terminated with {NC, NC, 0}.
421  *
422  * @return PinMap array
423  */
424 const PinMap *i2c_master_scl_pinmap(void);
425 
426 /** Get the pins that support I2C SDA
427  *
428  * Return a PinMap array of pins that support I2C SDA in
429  * slave mode. The array is terminated with {NC, NC, 0}.
430  *
431  * @return PinMap array
432  */
433 const PinMap *i2c_slave_sda_pinmap(void);
434 
435 /** Get the pins that support I2C SCL
436  *
437  * Return a PinMap array of pins that support I2C SCL in
438  * slave mode. The array is terminated with {NC, NC, 0}.
439  *
440  * @return PinMap array
441  */
442 const PinMap *i2c_slave_scl_pinmap(void);
443 
444 /**@}*/
445 
446 #if DEVICE_I2CSLAVE
447 
448 /**
449  * \defgroup SynchI2C Synchronous I2C Hardware Abstraction Layer for slave
450  * @{
451  */
452 
453 /** Slave status
454  *
455  * @note Default status is Idle.
456  */
457 typedef enum {
458  Idle = 0, // Slave has not been addressed.
459  ReadAddressed = 1, // Master has requested a read from this slave.
460  WriteGeneral = 2, // Master is writing to all slaves.
461  WriteAddressed = 3 // Master is writing to this slave.
463 
464 /** Check to see if the I2C slave has been addressed.
465  *
466  * @param obj The I2C object
467  * @return The status - i2c_slave_status_t indicating what state the peripheral
468  * is configured in.
469  */
471 
472 /** Configure I2C address.
473  *
474  * @note This function does nothing when configured in master mode.
475  *
476  * @param obj The I2C object
477  * @param address The address to be set - 7 bit or 10 bit
478  */
479 void i2c_slave_address(i2c_t *obj, uint16_t address);
480 
481 #endif
482 
483 /**@}*/
484 
485 #if DEVICE_I2C_ASYNCH
486 
487 /**
488  * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer
489  * @{
490  */
491 
492 /** Start I2C asynchronous transfer
493  *
494  * @param obj The I2C object
495  * @param tx The transmit buffer
496  * @param tx_length The number of bytes to transmit
497  * @param rx The receive buffer
498  * @param rx_length The number of bytes to receive
499  * @param address The address to be set - 7 bit or 10 bit
500  * @param stop If true, stop is generated after the transfer is done
501  * @param handler The I2C IRQ handler to be set
502  * @param ctx The context pointer
503  * @return true if the transfer was successfully scheduled, false otherwise
504  */
505 bool i2c_transfer_async(i2c_t *obj, const uint8_t *tx, uint32_t tx_length,
506  uint8_t *rx, uint32_t rx_length, uint16_t address,
507  bool stop, i2c_async_handler_f handler, void *ctx);
508 
509 /** Abort asynchronous transfer
510  *
511  * This function does not perform any check - that should happen in upper
512  * layers.
513  *
514  * @param obj The I2C object
515  */
516 void i2c_abort_async(i2c_t *obj);
517 
518 #endif
519 
520 /**@}*/
521 
522 #ifdef __cplusplus
523 }
524 #endif
525 
526 #endif
527 
528 #endif
529 
530 /** @}*/
bool supports_slave_mode
If true, supports 10-bit addressing.
Definition: i2c_api.h:174
const PinMap * i2c_master_scl_pinmap(void)
Get the pins that support I2C SCL.
bool supports_multi_master
If true, supports configuring clock stretching.
Definition: i2c_api.h:178
const PinMap * i2c_master_sda_pinmap(void)
Get the pins that support I2C SDA.
Generic buffer structure.
Definition: buffer.h:27
bool supports_10bit_addressing
If true, the device handle multimaster collisions and arbitration safely.
Definition: i2c_api.h:176
I2C HAL structure.
Definition: i2c_api.h:146
void i2c_set_clock_stretching(i2c_t *obj, bool enabled)
Enable or disable clock stretching for the I2C peripheral.
uint32_t maximum_frequency
If true, the device can handle I2C slave mode.
Definition: i2c_api.h:172
void i2c_init(i2c_t *obj, PinName sda, PinName scl, bool is_slave)
Initialize the I2C peripheral.
bool i2c_transfer_async(i2c_t *obj, const uint8_t *tx, uint32_t tx_length, uint8_t *rx, uint32_t rx_length, uint16_t address, bool stop, i2c_async_handler_f handler, void *ctx)
Start I2C asynchronous transfer.
const PinMap * i2c_slave_sda_pinmap(void)
Get the pins that support I2C SDA.
const PinMap * i2c_slave_scl_pinmap(void)
Get the pins that support I2C SCL.
void i2c_get_capabilities(i2c_capabilities_t *capabilities)
Fills structure indicating supported features and frequencies on the current platform.
void i2c_slave_address(i2c_t *obj, uint16_t address)
Configure I2C address.
void i2c_stop(i2c_t *obj)
Send STOP command.
void(* i2c_async_handler_f)(i2c_t *obj, i2c_async_event_t *event, void *ctx)
Asynchronous transfer callback.
Definition: i2c_api.h:142
Structure describing the status of async transfer.
Definition: i2c_api.h:127
uint32_t i2c_frequency(i2c_t *obj, uint32_t frequency)
Configure the frequency in Hz at which the I2C peripheral should operate.
i2c_slave_status_t
Slave status.
Definition: i2c_api.h:457
void i2c_timeout(i2c_t *obj, uint32_t timeout)
Configure the timeout duration in microseconds for blocking transmission.
void i2c_abort_async(i2c_t *obj)
Abort asynchronous transfer.
struct i2c_async_event i2c_async_event_t
Structure describing the status of async transfer.
i2c_slave_status_t i2c_slave_status(i2c_t *obj)
Check to see if the I2C slave has been addressed.
Definition: pinmap.h:30
void i2c_free(i2c_t *obj)
Release the I2C object.
int32_t i2c_write(i2c_t *obj, uint16_t address, const uint8_t *data, uint32_t length, bool stop)
Blocking sending data.
int32_t i2c_read(i2c_t *obj, uint16_t address, uint8_t *data, uint32_t length, bool stop)
Blocking reading data.
void i2c_start(i2c_t *obj)
Send START command.
uint32_t minimum_frequency
< Minimum frequency supported must be set by target device
Definition: i2c_api.h:170
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.