![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
An I2C bus: the Arduino Wire API on one of the chip's I2C peripherals (the global Wire on this board). More...
#include <Wire.h>
Inherits Stream.
Public Types | |
| typedef std::function< void(int)> | cb_function_receive_t |
| What onReceive() takes: called with the number of bytes received. | |
| typedef std::function< void(void)> | cb_function_request_t |
| What onRequest() takes: called when the master asks for data. | |
Public Member Functions | |
| TwoWire () | |
An I2C bus on the variant's SDA and SCL (PC18 and PC19 on this board). | |
| TwoWire (uint32_t sda, uint32_t scl) | |
| An I2C bus on the given pins. | |
| void | setSCL (uint32_t scl) |
| Sets the SCL pin; call before begin(). | |
| void | setSDA (uint32_t sda) |
| Sets the SDA pin; call before begin(). | |
| void | setSCL (PinName scl) |
| Sets the SCL pin; call before begin(). | |
| void | setSDA (PinName sda) |
| Sets the SDA pin; call before begin(). | |
| void | begin (bool generalCall=false) |
| Joins the bus as the master, at 100 kHz. | |
| void | begin (uint32_t, uint32_t) |
| Joins the bus as the master on the given pins, at 100 kHz. | |
| void | begin (uint8_t, bool generalCall=false, bool NoStretchMode=false) |
| Joins the bus as a slave at a 7-bit address (1 means the master, as begin() does). | |
| void | begin (int, bool generalCall=false, bool NoStretchMode=false) |
Joins the bus as a slave at a 7-bit address (the int form). | |
| void | end () |
| Leaves the bus: turns the I2C interrupts off, resets I2C1 and frees the buffers. | |
| void | setClock (uint32_t) |
| Sets the bus clock; call after begin(). | |
| void | beginTransmission (uint8_t) |
| Starts collecting bytes for a slave; nothing goes on the bus until endTransmission(). | |
| void | beginTransmission (int) |
Starts collecting bytes for a slave (the int form). | |
| uint8_t | endTransmission (void) |
| Sends the bytes collected since beginTransmission(), then a STOP. | |
| uint8_t | endTransmission (uint8_t) |
| Sends the bytes collected since beginTransmission(), with or without a STOP. | |
| uint8_t | requestFrom (uint8_t, uint8_t) |
| Reads bytes from a slave into the receive buffer, for available() and read(). | |
| uint8_t | requestFrom (uint8_t, uint8_t, uint8_t) |
Reads bytes from a slave (Arduino's form with sendStop). | |
| uint8_t | requestFrom (uint8_t, size_t, bool) |
Reads bytes from a slave (Arduino's form with sendStop). | |
| uint8_t | requestFrom (uint8_t, uint8_t, uint32_t, uint8_t, uint8_t) |
| Writes a register address to a slave, then reads bytes from it with a repeated start. | |
| uint8_t | requestFrom (int, int) |
Reads bytes from a slave (the int form). | |
| uint8_t | requestFrom (int, int, int) |
Reads bytes from a slave (the int form with sendStop). | |
| virtual size_t | write (uint8_t) |
| Adds a byte to the transmission, or, in a slave's onRequest() callback, sends it to the master. | |
| virtual size_t | write (const uint8_t *, size_t) |
| Adds bytes to the transmission, or, in a slave's onRequest() callback, sends them to the master. | |
| virtual int | available (void) |
| How many received bytes are left to read (after requestFrom(), or in an onReceive() callback). | |
| virtual int | read (void) |
| Takes the next received byte. | |
| virtual int | peek (void) |
| The next received byte, left in the buffer. | |
| virtual void | flush (void) |
| Throws away the received bytes and the transmission's bytes. | |
| void | onReceive (cb_function_receive_t callback) |
| Sets what a slave does when the master has sent it a message. | |
| void | onRequest (cb_function_request_t callback) |
| Sets what a slave does when the master asks it for data. | |
| size_t | write (unsigned long n) |
Writes the low byte of n (see write(uint8_t)). | |
| size_t | write (long n) |
Writes the low byte of n (see write(uint8_t)). | |
| size_t | write (unsigned int n) |
Writes the low byte of n (see write(uint8_t)). | |
| size_t | write (int n) |
Writes the low byte of n (see write(uint8_t)). | |
| I2C_HandleTypeDef * | getHandle (void) |
| The WCH peripheral library's view of this bus: its instance and init structure, for mixing in WCH's own I2C functions. | |
An I2C bus: the Arduino Wire API on one of the chip's I2C peripherals (the global Wire on this board).
As a master: beginTransmission(), write() and endTransmission() to send; requestFrom(), then available() and read() to receive. As a slave: begin(address), with onReceive() and onRequest(). It is a Stream, so print() works inside a transmission too.
| typedef std::function<void(int)> TwoWire::cb_function_receive_t |
What onReceive() takes: called with the number of bytes received.
| typedef std::function<void(void)> TwoWire::cb_function_request_t |
What onRequest() takes: called when the master asks for data.
| TwoWire::TwoWire | ( | ) |
An I2C bus on the variant's SDA and SCL (PC18 and PC19 on this board).
| TwoWire::TwoWire | ( | uint32_t | sda, |
| uint32_t | scl | ||
| ) |
An I2C bus on the given pins.
| sda | the SDA pin (Arduino pin number). |
| scl | the SCL pin (Arduino pin number). |
|
inline |
Sets the SCL pin; call before begin().
| scl | the pin's Arduino number (PC19 on this board). |
|
inline |
Sets the SDA pin; call before begin().
| sda | the pin's Arduino number (PC18 on this board). |
|
inline |
Sets the SCL pin; call before begin().
| scl | the pin's name (PC_19). |
|
inline |
Sets the SDA pin; call before begin().
| sda | the pin's name (PC_18). |
| void TwoWire::begin | ( | bool | generalCall = false | ) |
Joins the bus as the master, at 100 kHz.
Sets the pins up and resets I2C1. If a device holds SDA low (stuck after a reset), clocks SCL 20 times first to free it. Call it once, or end() first: it forgets (and leaks) the buffers it had.
| generalCall | stored, but not used by this port. |
| void TwoWire::begin | ( | uint32_t | , |
| uint32_t | |||
| ) |
Joins the bus as the master on the given pins, at 100 kHz.
sda: the SDA pin (Arduino pin number).scl: the SCL pin (Arduino pin number). | void TwoWire::begin | ( | uint8_t | , |
| bool | generalCall = false, |
||
| bool | NoStretchMode = false |
||
| ) |
Joins the bus as a slave at a 7-bit address (1 means the master, as begin() does).
The I2C interrupt then answers the master: see onReceive() and onRequest(). A slave receives at most 32 bytes per message (I2C_TXRX_BUFFER_SIZE).
address: the slave's 7-bit address. | generalCall | stored, but not used by this port. |
| NoStretchMode | stored, but not used by this port. |
| void TwoWire::begin | ( | int | , |
| bool | generalCall = false, |
||
| bool | NoStretchMode = false |
||
| ) |
Joins the bus as a slave at a 7-bit address (the int form).
address: the slave's 7-bit address. | generalCall | stored, but not used by this port. |
| NoStretchMode | stored, but not used by this port. |
| void TwoWire::end | ( | ) |
Leaves the bus: turns the I2C interrupts off, resets I2C1 and frees the buffers.
| void TwoWire::setClock | ( | uint32_t | ) |
Sets the bus clock; call after begin().
frequency: in Hz: up to 100000 gives 100 kHz, up to 400000 gives 400 kHz, up to 1000000 gives 1 MHz. Higher values are not valid. | void TwoWire::beginTransmission | ( | uint8_t | ) |
Starts collecting bytes for a slave; nothing goes on the bus until endTransmission().
address: the slave's 7-bit address. | void TwoWire::beginTransmission | ( | int | ) |
Starts collecting bytes for a slave (the int form).
address: the slave's 7-bit address. | uint8_t TwoWire::endTransmission | ( | void | ) |
Sends the bytes collected since beginTransmission(), then a STOP.
Blocks until done. With no bytes it only addresses the slave, which is how an I2C scanner finds devices.
| uint8_t TwoWire::endTransmission | ( | uint8_t | ) |
Sends the bytes collected since beginTransmission(), with or without a STOP.
sendStop: true: end with a STOP; false: keep the bus, for a repeated start by the requestFrom() that follows. | uint8_t TwoWire::requestFrom | ( | uint8_t | , |
| uint8_t | |||
| ) |
Reads bytes from a slave into the receive buffer, for available() and read().
Blocks until done; the read always ends with a STOP.
address: the slave's 7-bit address.quantity: how many bytes, 1 to 255. quantity if they all arrived, 0 if the read failed. I2C_TIMEOUT_TICK): at 100 kHz that is about 30 bytes, at 400 kHz about 120. Raise the clock with setClock(), or read in smaller pieces, for more. | uint8_t TwoWire::requestFrom | ( | uint8_t | , |
| uint8_t | , | ||
| uint8_t | |||
| ) |
Reads bytes from a slave (Arduino's form with sendStop).
address: the slave's 7-bit address.quantity: how many bytes, 1 to 255.sendStop: ignored: this port always ends a read with a STOP. quantity if they all arrived, 0 if the read failed. | uint8_t TwoWire::requestFrom | ( | uint8_t | , |
| size_t | , | ||
| bool | |||
| ) |
Reads bytes from a slave (Arduino's form with sendStop).
address: the slave's 7-bit address.quantity: how many bytes, 1 to 255.sendStop: ignored: this port always ends a read with a STOP. quantity if they all arrived, 0 if the read failed. | uint8_t TwoWire::requestFrom | ( | uint8_t | , |
| uint8_t | , | ||
| uint32_t | , | ||
| uint8_t | , | ||
| uint8_t | |||
| ) |
Writes a register address to a slave, then reads bytes from it with a repeated start.
address: the slave's 7-bit address.quantity: how many bytes, 1 to 255.iaddress: the register (internal) address, sent first.isize: how many bytes of iaddress to send, most significant first: 0 (none, a plain read) to 3.sendStop: ignored: this port always ends a read with a STOP. quantity if they all arrived, 0 if the read failed. | uint8_t TwoWire::requestFrom | ( | int | , |
| int | |||
| ) |
Reads bytes from a slave (the int form).
address: the slave's 7-bit address.quantity: how many bytes, 1 to 255. quantity if they all arrived, 0 if the read failed. | uint8_t TwoWire::requestFrom | ( | int | , |
| int | , | ||
| int | |||
| ) |
Reads bytes from a slave (the int form with sendStop).
address: the slave's 7-bit address.quantity: how many bytes, 1 to 255.sendStop: ignored: this port always ends a read with a STOP. quantity if they all arrived, 0 if the read failed.
|
virtual |
Adds a byte to the transmission, or, in a slave's onRequest() callback, sends it to the master.
data: the byte.
|
virtual |
Adds bytes to the transmission, or, in a slave's onRequest() callback, sends them to the master.
data: the bytes.quantity: how many. quantity, or 0 if the transmission would pass WIRE_MAX_TX_BUFF_LENGTH bytes (none are added then).
|
virtual |
How many received bytes are left to read (after requestFrom(), or in an onReceive() callback).
|
virtual |
Takes the next received byte.
|
virtual |
The next received byte, left in the buffer.
|
virtual |
Throws away the received bytes and the transmission's bytes.
(Unlike Serial.flush(), it does not wait for anything.)
| void TwoWire::onReceive | ( | cb_function_receive_t | callback | ) |
Sets what a slave does when the master has sent it a message.
| callback | called from the I2C interrupt after the master's STOP, with the number of bytes received (1-32); it reads them with read(). |
| void TwoWire::onRequest | ( | cb_function_request_t | callback | ) |
Sets what a slave does when the master asks it for data.
| callback | called from the I2C interrupt; it answers with write(). |
|
inline |
Writes the low byte of n (see write(uint8_t)).
| n | the value; only its low 8 bits are sent. |
|
inline |
Writes the low byte of n (see write(uint8_t)).
| n | the value; only its low 8 bits are sent. |
|
inline |
Writes the low byte of n (see write(uint8_t)).
| n | the value; only its low 8 bits are sent. |
|
inline |
Writes the low byte of n (see write(uint8_t)).
| n | the value; only its low 8 bits are sent. |
|
inline |
The WCH peripheral library's view of this bus: its instance and init structure, for mixing in WCH's own I2C functions.
Use at your own risk.