CryptoAuthLib
Microchip CryptoAuthentication Library
|
Hardware Interface Functions - I2C bit-bang for SAMD21. More...
Macros | |
#define | DEFAULT_I2C_BUS 2 |
Functions | |
void | i2c_discover_buses (int i2c_bitbang_buses[], int max_buses) |
Assigns the logical bus number for discovering the devices. More... | |
void | i2c_set_pin (uint8_t sda, uint8_t scl) |
Set I2C data and clock pin. Other functions will use these pins. More... | |
void | i2c_enable (void) |
Configure GPIO pins for I2C clock and data as output. More... | |
void | i2c_disable (void) |
Configure GPIO pins for I2C clock and data as input. More... | |
void | i2c_send_start (void) |
Send a START condition. More... | |
void | i2c_send_ack (uint8_t ack) |
Send an ACK or NACK (after receive). More... | |
void | i2c_send_stop (void) |
Send a STOP condition. More... | |
void | i2c_send_wake_token (void) |
Send a Wake Token. More... | |
ATCA_STATUS | i2c_send_byte (uint8_t i2c_byte) |
Send one byte. More... | |
ATCA_STATUS | i2c_send_bytes (uint8_t count, uint8_t *data) |
Send a number of bytes. More... | |
uint8_t | i2c_receive_one_byte (uint8_t ack) |
Receive one byte (MSB first). More... | |
void | i2c_receive_byte (uint8_t *data) |
Receive one byte and send ACK. More... | |
void | i2c_receive_bytes (uint8_t count, uint8_t *data) |
Receive a number of bytes. More... | |
Variables | |
I2CBuses | i2c_buses_default |
uint8_t | pin_sda |
uint8_t | pin_scl |
Hardware Interface Functions - I2C bit-bang for SAMD21.
#define DEFAULT_I2C_BUS 2 |
void i2c_disable | ( | void | ) |
Configure GPIO pins for I2C clock and data as input.
void i2c_discover_buses | ( | int | i2c_bitbang_buses[], |
int | max_buses | ||
) |
Assigns the logical bus number for discovering the devices.
[in] | i2c_bitbang_buses | The logical bus numbers are assigned to the variables. |
[in] | max_buses | Maximum number of bus used for discovering. |
void i2c_enable | ( | void | ) |
Configure GPIO pins for I2C clock and data as output.
void i2c_receive_byte | ( | uint8_t * | data | ) |
Receive one byte and send ACK.
[out] | data | pointer to received byte |
void i2c_receive_bytes | ( | uint8_t | count, |
uint8_t * | data | ||
) |
Receive a number of bytes.
[out] | data | pointer to receive buffer |
[in] | count | number of bytes to receive |
uint8_t i2c_receive_one_byte | ( | uint8_t | ack | ) |
Receive one byte (MSB first).
[in] | ack | 0:NACK, else:ACK |
We don't need to delay after the last bit because it takes time to switch the pin to output for acknowledging.
void i2c_send_ack | ( | uint8_t | ack | ) |
Send an ACK or NACK (after receive).
[in] | ack | 0: NACK, else: ACK |
< Low data line indicates an ACK.
< High data line indicates a NACK.
Clock out acknowledgment.
ATCA_STATUS i2c_send_byte | ( | uint8_t | i2c_byte | ) |
Send one byte.
[in] | i2c_byte | byte to write |
This avoids spikes but adds an if condition. We could parametrize the call to I2C_SET_OUTPUT and translate the msb to OUTSET or OUTCLR, but then the code would become target specific.
Send 8 bits of data.
Clock out the data bit.
Shifting while clock is high compensates for the time it takes to evaluate the bit while clock is low. That way, the low and high time of the clock pin is almost equal.
Clock in last data bit.
Set data line to be an input.
Wait for the ack.
ATCA_STATUS i2c_send_bytes | ( | uint8_t | count, |
uint8_t * | data | ||
) |
Send a number of bytes.
[in] | count | number of bytes to send |
[in] | data | pointer to buffer containing bytes to send |
void i2c_send_start | ( | void | ) |
Send a START condition.
Set clock high in case we re-start.
void i2c_send_stop | ( | void | ) |
Send a STOP condition.
void i2c_send_wake_token | ( | void | ) |
Send a Wake Token.
void i2c_set_pin | ( | uint8_t | sda, |
uint8_t | scl | ||
) |
Set I2C data and clock pin. Other functions will use these pins.
[in] | sda | definition of GPIO pin to be used as data pin |
[in] | scl | definition of GPIO pin to be used as clock pin |
I2CBuses i2c_buses_default |
uint8_t pin_scl |
uint8_t pin_sda |