Creates an I2C slave device with 32-byte registers that an I2C master device can write to and read from with a 7-bit device ID, 1-bit read/write, 8-bit register address, and 8 bits of data.
More...
#include "simpletools.h"
Go to the source code of this file.
|
i2cslave_t * | i2cslave_open (int pin_clock, int pin_data, int address) |
| Start an I2C slave processor in a new cog. More...
|
|
void | i2cslave_close (i2cslave_t *device) |
| Stop the I2C slave processor and make cog and memory resources available for other uses. More...
|
|
char * | i2cslave_regAddr (i2cslave_t *device) |
| Provides a pointer to the first of the I2C slave device's 32 byte registers. Applications can use this address to directly access the registers without making method calls. More...
|
|
int | i2cslave_checkForRegChange (i2cslave_t *device) |
| Check if any registers have changed. If a register has changed, return its number. If more than one register has changed, return the highest address that has changed. If no registers have changed, return -1. More...
|
|
int | i2cslave_checkReg (i2cslave_t *device, int index) |
| Get the register value if it has changed. More...
|
|
int | i2cslave_checkFlags (i2cslave_t *device) |
| Check the flags register. Bits 31 to 0 indicate if data has changed in registers 31 to 0. More...
|
|
int | i2cslave_checkFlag (i2cslave_t *device, int index) |
| Check a certain register's flag. More...
|
|
void | i2cslave_clearFlag (i2cslave_t *device, int index) |
| Clear a certain register's flag. More...
|
|
char | i2cslave_getReg (i2cslave_t *device, int index) |
| Get the value stored by a certain register. More...
|
|
void | i2cslave_putReg (i2cslave_t *device, int index, int value) |
| Set the value of a register. More...
|
|
void | i2cslave_flush (i2cslave_t *device) |
| Clear all register values and flags. More...
|
|
int | bitwiseEncode (int i) |
| Find out the highest bit with a 1 in a 32 bit register. More...
|
|
Creates an I2C slave device with 32-byte registers that an I2C master device can write to and read from with a 7-bit device ID, 1-bit read/write, 8-bit register address, and 8 bits of data.
- Author
- PASM Chris Gadd, Andy Lindsay Spin to C interface port.
- Copyright
- Parallax Inc. 2018, MIT License at end of file.
◆ bitwiseEncode()
int bitwiseEncode |
( |
int |
i | ) |
|
Find out the highest bit with a 1 in a 32 bit register.
- Returns
- index The number of the highest bit (31 to 0) that stores a 1 in a given 32 bit variable.
◆ i2cslave_checkFlag()
int i2cslave_checkFlag |
( |
i2cslave_t * |
device, |
|
|
int |
index |
|
) |
| |
Check a certain register's flag.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
index | The index of the flag to be checked. |
- Returns
- status 1 if the register has changed since the last time it was read of 0 if it has not.
◆ i2cslave_checkFlags()
int i2cslave_checkFlags |
( |
i2cslave_t * |
device | ) |
|
Check the flags register. Bits 31 to 0 indicate if data has changed in registers 31 to 0.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
- Returns
- flags Contents of the 32 bit flags register.
◆ i2cslave_checkForRegChange()
int i2cslave_checkForRegChange |
( |
i2cslave_t * |
device | ) |
|
Check if any registers have changed. If a register has changed, return its number. If more than one register has changed, return the highest address that has changed. If no registers have changed, return -1.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
- Returns
- number (0 to 31) of the highest value that has changed since the last checkForRegChange call.
◆ i2cslave_checkReg()
int i2cslave_checkReg |
( |
i2cslave_t * |
device, |
|
|
int |
index |
|
) |
| |
Get the register value if it has changed.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
index | The index (0 to 31) of the register to check. |
- Returns
- value The new register value, or -1 if the register has not changed.
◆ i2cslave_clearFlag()
void i2cslave_clearFlag |
( |
i2cslave_t * |
device, |
|
|
int |
index |
|
) |
| |
Clear a certain register's flag.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
index | The index of the flag to be cleared. |
◆ i2cslave_close()
void i2cslave_close |
( |
i2cslave_t * |
device | ) |
|
Stop the I2C slave processor and make cog and memory resources available for other uses.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
◆ i2cslave_flush()
void i2cslave_flush |
( |
i2cslave_t * |
device | ) |
|
Clear all register values and flags.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
◆ i2cslave_getReg()
char i2cslave_getReg |
( |
i2cslave_t * |
device, |
|
|
int |
index |
|
) |
| |
Get the value stored by a certain register.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
index | The index of the register (0 to 31). |
- Returns
- The value stored by the register.
◆ i2cslave_open()
i2cslave_t* i2cslave_open |
( |
int |
pin_clock, |
|
|
int |
pin_data, |
|
|
int |
address |
|
) |
| |
Start an I2C slave processor in a new cog.
- Parameters
-
pin_clock | I2C bus clock pin |
pin_data | I2C bus data pin |
address | 7-bit I2C address for slave device.
|
- Returns
- i2cslave process identifier for other i2cslave_* function calls.
◆ i2cslave_putReg()
void i2cslave_putReg |
( |
i2cslave_t * |
device, |
|
|
int |
index, |
|
|
int |
value |
|
) |
| |
Set the value of a register.
- Parameters
-
*device | The i2slave process identifier returned by i2cslave_start. |
index | The index of the register (0 to 31). |
value | The value stored by the register. |
◆ i2cslave_regAddr()
char* i2cslave_regAddr |
( |
i2cslave_t * |
device | ) |
|
Provides a pointer to the first of the I2C slave device's 32 byte registers. Applications can use this address to directly access the registers without making method calls.
- Returns
- char pointer to the first of 32 byte registers.