@@ -33,32 +33,41 @@ being performed. For example, a game could send a full screen update out over I
3333processing the next frame without waiting for the first one to be sent over I2C. DMA is used to handle
3434the transfer to/from the I2C hardware freeing the CPU from bit-banging or busy waiting.
3535
36- Note that asynchronous operations can not be intersped with normal, synchronous ones. Fully complete an
37- asynchronous operation before attempting to do a normal ``Wire.beginTransaction() `` or ``Wire.requestFrom ``.
38- Also, all buffers need to be valid throughout the entire operation. Read data cannot be accessed until
39- the transaction is completed and can't be "peeked" at while the operation is ongoing.
40-
41-
42- bool writeAsync(uint8_t address, const void \* buffer, size_t bytes, bool sendStop)
43- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44- Begins an I2C asynchronous write transaction. Writes to ``address `` of ``bytes `` from ``buffer `` and
45- at the end will send an I2C stop if ``sendStop `` is ``true ``.
46- Check ``finishedAsync() `` to determine when the operation completes and conclude the transaction.
47- This operation needs to allocate a buffer from heap equal to 2x ``bytes `` in size.
48-
49- bool readAsync(uint8_t address, void \* buffer, size_t bytes, bool sendStop)
50- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51- Begins an I2C asynchronous read transaction. Reads from ``address `` for ``bytes `` into ``buffer `` and
52- at the end will send an I2C stop if ``sendStop `` is ``true ``.
53- Check ``finishedAsync() `` to determine when the operation completes and conclude the transaction.
54- This operation needs to allocate a buffer from heap equal to 4x ``bytes `` in size.
36+ Note that asynchronous operations can not be intersped with normal, synchronous ones. Fully complete or
37+ abort an asynchronous operation before attempting to do a normal ``Wire.beginTransaction() `` or
38+ ``Wire.requestFrom ``.
39+
40+
41+ bool writeReadAsync(uint8_t address, const void \* wbuffer, size_t wbytes, const void \* rbuffer, size_t rbytes, bool sendStop)
42+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+ Executes a master I2C asynchronous write/read transaction to I2C slave ``address ``. First ``wbytes `` from
44+ ``wbuffer `` are written to the I2C slave, followed by an I2C restart, then ``rbytes `` are read from the
45+ I2C slave into ``rbuffer ``. The buffers need to be valid throughout the entire asynchronous operation.
46+
47+ At the end of the transaction an I2C stop is sent if ``sendStop `` is ``true ``, and at the beginning of the
48+ transaction an I2C start is sent if the previous write/read had ``sendStop `` set to ``true ``.
49+
50+ Check ``finishedAsync() `` to determine when the operation completes, or use ``onFinishedAsync() `` to set a
51+ callback.
52+
53+ Set ``rbytes `` to 0 to do a write-only operation, set ``wbytes `` to 0 to do a read-only operation. Or use:
54+
55+ ``bool writeAsync(uint8_t address, const void \*buffer, size_t bytes, bool sendStop) ``
56+
57+ ``bool readAsync(uint8_t address, void \*buffer, size_t bytes, bool sendStop) ``
58+
59+ The first call to an asynchronous write/read operation allocates the required DMA channels and internal
60+ buffer. If desired, call ``end() `` to free these resources.
5561
5662bool finishedAsync()
5763~~~~~~~~~~~~~~~~~~~~
58- Call to check if the asynchronous operations is completed and the buffer passed in can be either read or
59- reused. Frees the allocated memory and completes the asynchronous transaction.
64+ Call to check if the asynchronous operations is completed.
65+
66+ void onFinishedAsync(void(*function)(void))
67+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+ Set a (optional) callback for async operation. The ``function`` will be called when the asynchronous
69+ operation finishes.
6070
6171void abortAsync()
6272~~~~~~~~~~~~~~~~~
63- Cancels the outstanding asynchronous transaction and frees any allocated memory.
64-
73+ Cancels any outstanding asynchronous transaction.
0 commit comments