|
ArduboyI2C Library
|
#include <ArduboyI2C.h>
Static Public Member Functions | |
| static void | init () |
| Initalizes I2C hardware. | |
| static void | setAddress (uint8_t address, bool generalCall=false) |
| Set the address of the device and enable/disable general calls on the I2C bus. | |
| static void | write (uint8_t address, const void *buffer, uint8_t size, bool wait) |
| Attempts to become the bus controller (master) and sends data over I2C to the specified address. | |
| template<typename T > | |
| static void | write (uint8_t address, const T *object, bool wait) |
| Attempts to become the bus controller (master) and sends data over I2C to the specified address. | |
| static void | read (uint8_t address, void *buffer, uint8_t size) |
| Attempts to become the bus controller (master) and reads data over I2C from the specified address. | |
| template<typename T > | |
| static void | read (uint8_t address, T *object) |
| Attempts to become the bus controller (master) and reads data over I2C from the specified address. | |
| static void | transmit (const void *buffer, uint8_t size) |
| Transmits data back to the controller (master). | |
| template<typename T > | |
| static void | transmit (const T *object) |
| Transmits data back to the controller (master). | |
| static void | onRequest (void(*function)()) |
| Sets up the callback to be called when data is requested from the device's address (a read). | |
| static void | onReceive (void(*function)()) |
| Sets up the callback to be called when data is sent to the device's address (a write) | |
| static uint8_t | getTWError () |
| Gets the hardware error which happened in a previous read or write. | |
| static uint8_t * | getBuffer () |
| Gets a pointer to the I2C buffer holding received data. | |
| static bool | detectEmulator () |
| Checks if an emulator without I2C support is being used to run the code. | |
| static uint8_t | getAddressFromId (uint8_t id) |
| Gets the address from a provided id. | |
| static uint8_t | handshake () |
| Handshakes with other devices and returns a unique id once complete. | |
Provides all I2C functionality.
|
static |
|
static |
Gets the address from a provided id.
| id | An id between 0 and I2C_MAX_ADDRESSES - 1 |
This function is provided to standardize addresses for each id. It is used by I2C::handshake.
|
static |
Gets a pointer to the I2C buffer holding received data.
Intended to be used inside the onReceive callback.
|
static |
Gets the hardware error which happened in a previous read or write.
|
static |
Handshakes with other devices and returns a unique id once complete.
I2C_MAX_PLAYERS must be defined to 1 or more before including the header file to the number of players in the handshake. This function will wait until every single player has joined.
|
static |
|
static |
Sets up the callback to be called when data is sent to the device's address (a write)
| function | The function to be called when data is received. |
Example Callback and Usage:
|
static |
Sets up the callback to be called when data is requested from the device's address (a read).
| function | The function to be called when data is requested. |
Example Callback and Usage:
transmit instead of write.
|
static |
Attempts to become the bus controller (master) and reads data over I2C from the specified address.
| T | The type of the data to read. |
| address | The 7-bit address which to receive the data from. Addresses 0-7 and 120-127 are reserved by the standard and should not be used. |
| buffer | A pointer to the buffer in which to store the data. |
Types with sizes larger than 255 should not be used with this function.
write function, this function is bufferless and is not limited to 32 bytes.
|
static |
Attempts to become the bus controller (master) and reads data over I2C from the specified address.
| address | The 7-bit address which to receive the data from. Addresses 0-7 and 120-127 are reserved by the standard and should not be used. |
| buffer | A pointer to the buffer in which to store the data. |
| size | The maximum amount of bytes to receive. This cannot be zero. |
write function, this function is bufferless and is not limited to 32 bytes.
|
static |
Set the address of the device and enable/disable general calls on the I2C bus.
| address | The 7-bit address which to respond to. Addresses 0-7 and 120-127 are reserved by the standard and should not be used. |
| generalCall | Whether to enable or disable general calls. Defaults to false. |
|
static |
Transmits data back to the controller (master).
| T | The type of data to transmit. |
| object | A pointer to the data to send. |
This function is intended to be called once inside the onRequest callback. It fills the transmitting buffer with data to then be send one byte at a time. If it is called multiple times, only the last call will be sent.
I2C_BUFFER_SIZE and defaults to 32. If the program needs to send more than 32 bytes at a time, I2C_BUFFER_SIZE must be defined before including to be larger.
|
static |
Transmits data back to the controller (master).
| buffer | A pointer to the data to send. |
| size | The amount of the data in bytes to send. |
This function is intended to be called once inside the onRequest callback. It fills the transmitting buffer with data to then be send one byte at a time. If it is called multiple times, only the last call will be sent.
I2C_BUFFER_SIZE and defaults to 32. If the program needs to send more than 32 bytes at a time, I2C_BUFFER_SIZE must be defined before including to be larger.
|
static |
Attempts to become the bus controller (master) and sends data over I2C to the specified address.
| T | The type of the data to write. |
| address | The 7-bit address which to send the data. To send a general call, use address 0. Addresses 1-7 and 120-127 are reserved by the standard and should not be used. |
| buffer | A pointer to the data to send. |
| wait | Whether or not to wait for the write to complete. If this is false, it will proceed with interrupts. |
generalCall argument of setAddress is true on every other device. I2C_BUFFER_SIZE and defaults to 32. If the program needs to send more than 32 bytes at a time, I2C_BUFFER_SIZE must be defined before including to be larger.
|
static |
Attempts to become the bus controller (master) and sends data over I2C to the specified address.
| address | The 7-bit address which to send the data. To send a general call, use address 0. Addresses 1-7 and 120-127 are reserved by the standard and should not be used. |
| buffer | A pointer to the data to send. |
| size | The amount of data in bytes to send. This cannot be zero. |
| wait | Whether or not to wait for the write to complete. If this is false, it will proceed with interrupts. |
generalCall argument of setAddress is true on every other device. I2C_BUFFER_SIZE and defaults to 32. If the program needs to send more than 32 bytes at a time, I2C_BUFFER_SIZE must be defined before including to be larger.