Prusa MINI Firmware overview
|
#include <twibus.h>
Public Member Functions | |
TWIBus () | |
Class constructor. More... | |
void | reset () |
Reset the buffer. More... | |
void | send () |
Send the buffer data to the bus. More... | |
void | addbyte (const char c) |
Add one byte to the buffer. More... | |
void | addbytes (char src[], uint8_t bytes) |
Add some bytes to the buffer. More... | |
void | addstring (char str[]) |
Add a null-terminated string to the buffer. More... | |
void | address (const uint8_t adr) |
Set the target slave address. More... | |
void | echobuffer (const char prefix[], uint8_t adr) |
Echo data in the buffer to serial. More... | |
bool | request (const uint8_t bytes) |
Request data from the slave device and wait. More... | |
uint8_t | capture (char *dst, const uint8_t bytes) |
Capture data from the bus into the buffer. More... | |
void | relay (const uint8_t bytes) |
Request data from the slave device, echo to serial. More... | |
Static Public Member Functions | |
static void | echoprefix (uint8_t bytes, const char prefix[], uint8_t adr) |
Prefix for echo to serial. More... | |
static void | echodata (uint8_t bytes, const char prefix[], uint8_t adr) |
Echo data on the bus to serial. More... | |
static void | flush () |
Flush the i2c bus. More... | |
Public Attributes | |
uint8_t | addr = 0 |
Target device address @description The target device address. Persists until changed. More... | |
TWIBUS class
This class implements a wrapper around the two wire (I2C) bus, allowing Marlin to send and request data from any slave device on the bus.
The two main consumers of this class are M260 and M261. M260 provides a way to send an I2C packet to a device (no repeated starts) by caching up to 32 bytes in a buffer and then sending the buffer. M261 requests data from a device. The received data is relayed to serial out for the host to interpret.
For more information see
TWIBus::TWIBus | ( | ) |
Class constructor.
Initialize the TWI bus and clear the buffer
void TWIBus::reset | ( | ) |
Reset the buffer.
Set the buffer to a known-empty state
void TWIBus::send | ( | ) |
Send the buffer data to the bus.
Flush the buffer to the target address
Add one byte to the buffer.
Add a byte to the end of the buffer. Silently fails if the buffer is full.
c | a data byte |
Add some bytes to the buffer.
Add bytes to the end of the buffer. Concatenates at the buffer size.
src | source data address |
bytes | the number of bytes to add |
void TWIBus::addstring | ( | char | str[] | ) |
Add a null-terminated string to the buffer.
Add bytes to the end of the buffer up to a nul. Concatenates at the buffer size.
str | source string address |
Set the target slave address.
The target slave address for sending the full packet
adr | 7-bit integer address |
Prefix for echo to serial.
Echo a label, length, address, and "data:"
bytes | the number of bytes to request |
Echo data on the bus to serial.
Echo some number of bytes from the bus to serial in a parser-friendly format.
bytes | the number of bytes to request |
Echo data in the buffer to serial.
Echo the entire buffer to serial to serial in a parser-friendly format.
bytes | the number of bytes to request |
Request data from the slave device and wait.
Request a number of bytes from a slave device. Wait for the data to arrive, and return true on success.
bytes | the number of bytes to request |
Capture data from the bus into the buffer.
Capture data after a request has succeeded.
bytes | the number of bytes to request |
|
static |
Flush the i2c bus.
Get all bytes on the bus and throw them away.
Request data from the slave device, echo to serial.
Request a number of bytes from a slave device and output the returned data to serial in a parser-friendly format.
bytes | the number of bytes to request |
uint8_t TWIBus::addr = 0 |
Target device address @description The target device address. Persists until changed.