CryptoAuthLib
Microchip CryptoAuthentication Library
|
definitions for bit-banged I2C More...
Go to the source code of this file.
Data Structures | |
struct | I2CBuses |
Macros | |
#define | MAX_I2C_BUSES 18 |
#define | I2C_ENABLE() |
#define | I2C_DISABLE() |
#define | I2C_CLOCK_LOW() port_pin_set_output_level(pin_scl, false) |
#define | I2C_CLOCK_HIGH() port_pin_set_output_level(pin_scl, true) |
#define | I2C_DATA_LOW() port_pin_set_output_level(pin_sda, false) |
#define | I2C_DATA_HIGH() port_pin_set_output_level(pin_sda, true) |
#define | I2C_DATA_IN() port_pin_get_input_level(pin_sda) |
#define | I2C_SET_OUTPUT() |
#define | I2C_SET_OUTPUT_HIGH() { I2C_SET_OUTPUT(); I2C_DATA_HIGH(); } |
#define | I2C_SET_OUTPUT_LOW() { I2C_SET_OUTPUT(); I2C_DATA_LOW(); } |
#define | I2C_SET_INPUT() |
#define | DISABLE_INTERRUPT() cpu_irq_disable() |
#define | ENABLE_INTERRUPT() cpu_irq_enable() |
#define | I2C_CLOCK_DELAY_WRITE_LOW() delay_us(1) |
#define | I2C_CLOCK_DELAY_WRITE_HIGH() delay_us(1) |
#define | I2C_CLOCK_DELAY_READ_LOW() delay_us(1) |
#define | I2C_CLOCK_DELAY_READ_HIGH() delay_us(1) |
#define | I2C_CLOCK_DELAY_SEND_ACK() delay_us(1) |
#define | I2C_HOLD_DELAY() delay_us(1) |
This delay is inserted to make the Start and Stop hold time at least 250 ns. More... | |
#define | I2C_ACK_TIMEOUT (4) |
loop count when waiting for an acknowledgment More... | |
Functions | |
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_discover_buses (int i2c_bitbang_buses[], int max_buses) |
Assigns the logical bus number for discovering the devices. 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 |
definitions for bit-banged I2C
#define DISABLE_INTERRUPT | ( | ) | cpu_irq_disable() |
#define ENABLE_INTERRUPT | ( | ) | cpu_irq_enable() |
#define I2C_ACK_TIMEOUT (4) |
loop count when waiting for an acknowledgment
#define I2C_CLOCK_DELAY_READ_HIGH | ( | ) | delay_us(1) |
#define I2C_CLOCK_DELAY_READ_LOW | ( | ) | delay_us(1) |
#define I2C_CLOCK_DELAY_SEND_ACK | ( | ) | delay_us(1) |
#define I2C_CLOCK_DELAY_WRITE_HIGH | ( | ) | delay_us(1) |
#define I2C_CLOCK_DELAY_WRITE_LOW | ( | ) | delay_us(1) |
#define I2C_CLOCK_HIGH | ( | ) | port_pin_set_output_level(pin_scl, true) |
#define I2C_CLOCK_LOW | ( | ) | port_pin_set_output_level(pin_scl, false) |
#define I2C_DATA_HIGH | ( | ) | port_pin_set_output_level(pin_sda, true) |
#define I2C_DATA_IN | ( | ) | port_pin_get_input_level(pin_sda) |
#define I2C_DATA_LOW | ( | ) | port_pin_set_output_level(pin_sda, false) |
#define I2C_DISABLE | ( | ) |
#define I2C_ENABLE | ( | ) |
#define I2C_HOLD_DELAY | ( | ) | delay_us(1) |
This delay is inserted to make the Start and Stop hold time at least 250 ns.
#define I2C_SET_INPUT | ( | ) |
#define I2C_SET_OUTPUT | ( | ) |
#define I2C_SET_OUTPUT_HIGH | ( | ) | { I2C_SET_OUTPUT(); I2C_DATA_HIGH(); } |
#define I2C_SET_OUTPUT_LOW | ( | ) | { I2C_SET_OUTPUT(); I2C_DATA_LOW(); } |
#define MAX_I2C_BUSES 18 |
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 |