20#include "platform/platform.h"
21#include "hal/gpio_api.h"
23#if DEVICE_I2C || defined(DOXYGEN_ONLY)
25#include "hal/i2c_api.h"
26#include "platform/SingletonPtr.h"
27#include "rtos/Mutex.h"
28#include "platform/NonCopyable.h"
31#include "platform/CThunk.h"
33#include "platform/Callback.h"
239 I2C(PinName sda, PinName scl);
273 Result read(
int address,
char *data,
int length,
bool repeated =
false);
288 Result write(
int address,
const char *data,
int length,
bool repeated =
false);
363 MBED_DEPRECATED_SINCE(
"mbed-os-7.0",
"Use I2C::write_byte() instead for better readability and return codes")
451#if !defined(DOXYGEN_ONLY)
454 void lock_deep_sleep();
457 void unlock_deep_sleep();
459 void irq_handler_asynch(
void);
463 bool _deep_sleep_locked;
464 bool _async_transfer_is_repeated;
468#if !defined(DOXYGEN_ONLY)
489 int recover(PinName sda, PinName scl);
Class for created a pointer with data bound to it.
An I2C Master, used for communicating with I2C slave devices.
Result read(int address, char *data, int length, bool repeated=false)
Read from an I2C slave.
Result transfer_and_wait(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, rtos::Kernel::Clock::duration_u32 timeout=rtos::Kernel::wait_for_u32_forever, bool repeated=false)
Start I2C transfer and wait until it is complete.
int transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event=I2C_EVENT_TRANSFER_COMPLETE, bool repeated=false)
Start nonblocking I2C transfer.
Result write_byte(int data)
Write a single byte out on the I2C bus.
int read(int ack)
Read a single byte from the I2C bus.
int read_byte(bool ack)
Read a single byte from the I2C bus.
I2C(const i2c_pinmap_t &static_pinmap)
Create an I2C Master interface, connected to the specified pins.
Result write(int address, const char *data, int length, bool repeated=false)
Write to an I2C slave.
void abort_transfer()
Abort the ongoing I2C transfer.
void frequency(int hz)
Set the frequency of the I2C interface.
int start()
Creates a start condition on the I2C bus.
I2C(PinName sda, PinName scl)
Create an I2C Master interface, connected to the specified pins.
virtual void lock()
Acquire exclusive access to this I2C bus.
int stop()
Creates a stop condition on the I2C bus.
virtual void unlock()
Release exclusive access to this I2C bus.
Result
Result code for I2C operations.
@ INVALID_STATE
You tried to do something while in the wrong state (e.g. calling stop() before start())
@ NOT_SUPPORTED
Operation not supported (check i2c_get_capabilities())
@ TIMEOUT
Timeout waiting for I2C hardware.
@ OTHER_ERROR
Other error in I2C operation (e.g. wrong sequence of single byte calls)
Prevents generation of copy constructor and copy assignment operator in derived classes.
#define I2C_EVENT_TRANSFER_COMPLETE
Indicates that the transfer completed successfully.
DMAUsage
Enumeration of possible DMA usage hints.
constexpr Clock::duration_u32 wait_for_u32_forever
Magic "wait forever" constant for Kernel::Clock::duration_u32-based APIs.
Utility class for creating and using a singleton.