ArduboyI2C Library
Loading...
Searching...
No Matches
ArduboyI2C.h File Reference

An I2C library for Arduboy multiplayer games. More...

#include <avr/interrupt.h>
#include <avr/power.h>
#include <util/twi.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>

Go to the source code of this file.

Classes

class  I2C

Macros

#define I2C_FREQUENCY   100000
 The initial I2C frequency in Hz.
#define I2C_BUFFER_CAPACITY   32
 The capacity of the buffer used for writes/target (slave) operations.
#define I2C_HANDSHAKE_BUSY_CHECKS   128
 Number of times to check for a busy bus during a handshake.
#define I2C_CHECK_CABLE_FLIPPED_CHECKS   128
 The total number of checks to perform when checking for a flipped cable.
#define I2C_CHECK_CABLE_FLIPPED_DEBOUNCE_CHECKS   128
 The number of consecutive cable flip checks that pass before confirming the cable has been flipped back.
#define I2C_SDA_BIT   PIND1
 The bit of the pin on which the SDA line is connected.
#define I2C_SCL_BIT   PIND0
 The bit of the pin on which the SCL line is connected.
#define I2C_PIN   PIND
 The pin on which the SDA and SCL lines are connected.
#define I2C_PORT   PORTD
 The port on which the SDA and SCL lines are connected.
#define I2C_DDR   DDRD
 The data direction register for the SDA and SCL lines.
#define I2C_VERSION_MAJOR   3
 I2C library major version.
#define I2C_VERSION_MINOR   0
 I2C library minor version.
#define I2C_VERSION_PATCH   0
 I2C library patch version.
#define I2C_VERSION   (I2C_VERSION_MAJOR * 10000 + I2C_VERSION_MINOR * 100 + I2C_VERSION_PATCH)
 I2C library version.

Detailed Description

An I2C library for Arduboy multiplayer games.

Macro Definition Documentation

◆ I2C_FREQUENCY

#define I2C_FREQUENCY   100000

The initial I2C frequency in Hz.

Defaults to 100000 Hz, with a maximum of 200000 Hz. The Arduboy FX-C only has software pullups, so the I2C frequency must be < 200000 Hz to ensure reliability.

◆ I2C_BUFFER_CAPACITY

#define I2C_BUFFER_CAPACITY   32

The capacity of the buffer used for writes/target (slave) operations.

Defaults to 32. If more than 32 bytes are needed for writes/target (slave) operations, increase. If more RAM is needed, decrease. Maximum is 255.

◆ I2C_HANDSHAKE_BUSY_CHECKS

#define I2C_HANDSHAKE_BUSY_CHECKS   128

Number of times to check for a busy bus during a handshake.

Defaults to 128, with a maximum of 65535. Increase for a more accurate detection at the cost of a longer detection time, especially when a custom loop function is provided to the handshake function.

◆ I2C_CHECK_CABLE_FLIPPED_CHECKS

#define I2C_CHECK_CABLE_FLIPPED_CHECKS   128

The total number of checks to perform when checking for a flipped cable.

Defaults to 128, with a maximum of 65535. Increase for a more accurate detection at the cost of a longer detection time.

◆ I2C_CHECK_CABLE_FLIPPED_DEBOUNCE_CHECKS

#define I2C_CHECK_CABLE_FLIPPED_DEBOUNCE_CHECKS   128

The number of consecutive cable flip checks that pass before confirming the cable has been flipped back.

Defaults to 128, with a maximum of 65535. Increase for more accurate debouncing at the cost of a longer detection time.

◆ I2C_SDA_BIT

#define I2C_SDA_BIT   PIND1

The bit of the pin on which the SDA line is connected.

Defaults to PIND1.

◆ I2C_SCL_BIT

#define I2C_SCL_BIT   PIND0

The bit of the pin on which the SCL line is connected.

Defaults to PIND0.

◆ I2C_PIN

#define I2C_PIN   PIND

The pin on which the SDA and SCL lines are connected.

Defaults to PIND.

Note
There can be only one pin for the SDA and SCL lines to increase optimization.

◆ I2C_PORT

#define I2C_PORT   PORTD

The port on which the SDA and SCL lines are connected.

Defaults to PORTD.

Note
There can be only one port for the SDA and SCL lines to increase optimization.

◆ I2C_DDR

#define I2C_DDR   DDRD

The data direction register for the SDA and SCL lines.

Defaults to DDRD.

Note
There can be only one data direction register for the SDA and SCL lines to increase optimization.

◆ I2C_VERSION

#define I2C_VERSION   (I2C_VERSION_MAJOR * 10000 + I2C_VERSION_MINOR * 100 + I2C_VERSION_PATCH)

I2C library version.

For a given version x.y.z, the library version will be in the form x * 10000 + y * 100 + z.