RTOS enabled i2c-driver based on the official i2c-C-api.
Fork of mbed-RtosI2cDriver by
I2CSlaveRtos Class Reference
I2C slave interface to the RTOS-I2CDriver. More...
#include <I2CSlaveRtos.h>
Public Types | |
enum | RxStatus |
Status returned by the receiveSlave() function. More... | |
Public Member Functions | |
I2CSlaveRtos (PinName sda, PinName scl, int freq=100000, int address=42) | |
Create an I2C Slave interface, connected to the specified pins. | |
void | frequency (int hz) |
Set the frequency of the I2C interface. | |
int | receive (uint32_t timeout_ms=osWaitForever) |
Checks to see if this I2C Slave has been addressed. | |
int | read (char *data, int length) |
Read from an I2C master. | |
int | read (void) |
Read a single byte from an I2C master. | |
int | write (const char *data, int length) |
Write to an I2C master. | |
int | write (int data) |
Write a single byte to an I2C master. | |
void | address (int address) |
Sets the I2C slave address. | |
void | stop (void) |
Reset the I2C slave back into the known ready receiving state. | |
void | lock () |
Wait until the interface becomes available. | |
void | unlock () |
Unlock the interface that has previously been locked by the same thread. |
Detailed Description
I2C slave interface to the RTOS-I2CDriver.
The interface is compatible to the original mbed I2C class.
Definition at line 11 of file I2CSlaveRtos.h.
Member Enumeration Documentation
enum RxStatus |
Status returned by the receiveSlave() function.
Definition at line 17 of file I2CSlaveRtos.h.
Constructor & Destructor Documentation
I2CSlaveRtos | ( | PinName | sda, |
PinName | scl, | ||
int | freq = 100000 , |
||
int | address = 42 |
||
) |
Create an I2C Slave interface, connected to the specified pins.
- Parameters:
-
sda I2C data line pin scl I2C clock line pin
- Note:
- Has to be created in a thread context, i.e. within the main or some other function. A global delaration does not work
Definition at line 31 of file I2CSlaveRtos.h.
Member Function Documentation
void address | ( | int | address ) |
Sets the I2C slave address.
- Parameters:
-
address The address to set for the slave (ignoring the least signifcant bit). If set to 0, the slave will only respond to the general call address.
Definition at line 109 of file I2CSlaveRtos.h.
void frequency | ( | int | hz ) |
Set the frequency of the I2C interface.
- Parameters:
-
hz The bus frequency in hertz
Definition at line 38 of file I2CSlaveRtos.h.
void lock | ( | ) |
Wait until the interface becomes available.
Useful if you want to run a sequence of command without interrution by another thread. There's no need to call this function for running single request, because all driver functions will lock the device for exclusive access automatically.
Definition at line 126 of file I2CSlaveRtos.h.
int read | ( | void | ) |
Read a single byte from an I2C master.
- Returns:
- the byte read
Definition at line 74 of file I2CSlaveRtos.h.
int read | ( | char * | data, |
int | length | ||
) |
Read from an I2C master.
- Parameters:
-
data pointer to the byte array to read data in to length maximum number of bytes to read
- Returns:
- 0 on success, non-0 otherwise ... no! instead it returns number of bytes read minus one ... weird, guess its a bug in the official lib
Definition at line 65 of file I2CSlaveRtos.h.
int receive | ( | uint32_t | timeout_ms = osWaitForever ) |
Checks to see if this I2C Slave has been addressed.
- Returns:
- A status indicating if the device has been addressed, and how
- NoData - the slave has not been addressed
- ReadAddressed - the master has requested a read from this slave
- WriteAddressed - the master is writing to this slave
- WriteGeneral - the master is writing to all slave
Definition at line 51 of file I2CSlaveRtos.h.
void stop | ( | void | ) |
Reset the I2C slave back into the known ready receiving state.
Definition at line 116 of file I2CSlaveRtos.h.
void unlock | ( | ) |
Unlock the interface that has previously been locked by the same thread.
Definition at line 131 of file I2CSlaveRtos.h.
int write | ( | const char * | data, |
int | length | ||
) |
Write to an I2C master.
- Parameters:
-
data pointer to the byte array to be transmitted length the number of bytes to transmite
- Returns:
- 0 on success, non-0 otherwise
Definition at line 87 of file I2CSlaveRtos.h.
int write | ( | int | data ) |
Write a single byte to an I2C master.
the byte to write
- Returns:
- '1' if an ACK was received, '0' otherwise
Definition at line 99 of file I2CSlaveRtos.h.
Generated on Wed Jul 13 2022 17:20:05 by 1.7.2