CryptoAuthLib
Microchip CryptoAuthentication Library
i2c_bitbang_samd21.h
Go to the documentation of this file.
1 
28 #ifndef I2C_BITBANG_SAMD21_H_
29 #define I2C_BITBANG_SAMD21_H_
30 
31 #include "atca_status.h"
32 #include <delay.h>
33 
34 
35 #define MAX_I2C_BUSES 18 //The MAX_I2C_BUSES is the number of free pins in samd21 xplained pro
36 
37 
38 typedef struct
39 {
42 } I2CBuses;
43 
45 
46 extern uint8_t pin_sda;
47 extern uint8_t pin_scl;
48 
49 # define I2C_ENABLE() { struct port_config pin_conf; \
50  port_get_config_defaults(&pin_conf); \
51  pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK; \
52  port_pin_set_config(pin_sda, &pin_conf); \
53  pin_conf.direction = PORT_PIN_DIR_OUTPUT; \
54  port_pin_set_config(pin_scl, &pin_conf); }
55 # define I2C_DISABLE() { struct port_config pin_conf; \
56  port_get_config_defaults(&pin_conf); \
57  pin_conf.direction = PORT_PIN_DIR_INPUT; \
58  pin_conf.input_pull = PORT_PIN_PULL_UP; \
59  port_pin_set_config(pin_sda, &pin_conf); \
60  port_pin_set_config(pin_scl, &pin_conf); }
61 # define I2C_CLOCK_LOW() port_pin_set_output_level(pin_scl, false)
62 # define I2C_CLOCK_HIGH() port_pin_set_output_level(pin_scl, true)
63 # define I2C_DATA_LOW() port_pin_set_output_level(pin_sda, false)
64 # define I2C_DATA_HIGH() port_pin_set_output_level(pin_sda, true)
65 # define I2C_DATA_IN() port_pin_get_input_level(pin_sda)
66 # define I2C_SET_OUTPUT() { struct port_config pin_conf; \
67  port_get_config_defaults(&pin_conf); \
68  pin_conf.direction = PORT_PIN_DIR_OUTPUT_WTH_READBACK; \
69  port_pin_set_config(pin_sda, &pin_conf); }
70 # define I2C_SET_OUTPUT_HIGH() { I2C_SET_OUTPUT(); I2C_DATA_HIGH(); }
71 # define I2C_SET_OUTPUT_LOW() { I2C_SET_OUTPUT(); I2C_DATA_LOW(); }
72 # define I2C_SET_INPUT() { struct port_config pin_conf; \
73  port_get_config_defaults(&pin_conf); \
74  pin_conf.direction = PORT_PIN_DIR_INPUT; \
75  port_pin_set_config(pin_sda, &pin_conf); }
76 # define DISABLE_INTERRUPT() cpu_irq_disable()
77 # define ENABLE_INTERRUPT() cpu_irq_enable()
78 
79 
80 #define I2C_CLOCK_DELAY_WRITE_LOW() delay_us(1)
81 #define I2C_CLOCK_DELAY_WRITE_HIGH() delay_us(1)
82 #define I2C_CLOCK_DELAY_READ_LOW() delay_us(1)
83 #define I2C_CLOCK_DELAY_READ_HIGH() delay_us(1)
84 #define I2C_CLOCK_DELAY_SEND_ACK() delay_us(1)
85 #define I2C_HOLD_DELAY() delay_us(1)
87 
88 
89 
90 
92 #define I2C_ACK_TIMEOUT (4)
93 
94 
102 void i2c_set_pin(uint8_t sda, uint8_t scl);
103 
104 
113 void i2c_discover_buses(int i2c_bitbang_buses[], int max_buses);
114 
118 void i2c_enable(void);
119 
123 void i2c_disable(void);
124 
125 
129 void i2c_send_start(void);
130 
136 void i2c_send_ack(uint8_t ack);
137 
141 void i2c_send_stop(void);
142 
146 void i2c_send_wake_token(void);
147 
155 ATCA_STATUS i2c_send_byte(uint8_t i2c_byte);
156 
165 ATCA_STATUS i2c_send_bytes(uint8_t count, uint8_t *data);
166 
174 uint8_t i2c_receive_one_byte(uint8_t ack);
175 
181 void i2c_receive_byte(uint8_t *data);
182 
189 void i2c_receive_bytes(uint8_t count, uint8_t *data);
190 
191 #endif /* I2C_BITBANG_SAMD21_H_ */
void i2c_send_ack(uint8_t ack)
Send an ACK or NACK (after receive).
Definition: i2c_bitbang_samd21.c:78
uint8_t i2c_receive_one_byte(uint8_t ack)
Receive one byte (MSB first).
Definition: i2c_bitbang_samd21.c:212
void i2c_enable(void)
Configure GPIO pins for I2C clock and data as output.
Definition: i2c_bitbang_samd21.c:55
ATCA_STATUS i2c_send_byte(uint8_t i2c_byte)
Send one byte.
Definition: i2c_bitbang_samd21.c:120
ATCA_STATUS
Definition: atca_status.h:41
I2CBuses i2c_buses_default
Definition: i2c_bitbang_samd21.c:34
uint8_t pin_scl
Definition: i2c_bitbang_samd21.c:40
uint8_t pin_sda
Definition: i2c_bitbang_samd21.c:40
void i2c_receive_bytes(uint8_t count, uint8_t *data)
Receive a number of bytes.
Definition: i2c_bitbang_samd21.c:248
void i2c_discover_buses(int i2c_bitbang_buses[], int max_buses)
Assigns the logical bus number for discovering the devices.
Definition: i2c_bitbang_samd21.c:42
void i2c_receive_byte(uint8_t *data)
Receive one byte and send ACK.
Definition: i2c_bitbang_samd21.c:243
void i2c_send_wake_token(void)
Send a Wake Token.
Definition: i2c_bitbang_samd21.c:113
ATCA_STATUS i2c_send_bytes(uint8_t count, uint8_t *data)
Send a number of bytes.
Definition: i2c_bitbang_samd21.c:190
void i2c_send_stop(void)
Send a STOP condition.
Definition: i2c_bitbang_samd21.c:103
Definition: i2c_bitbang_samd21.h:38
void i2c_disable(void)
Configure GPIO pins for I2C clock and data as input.
Definition: i2c_bitbang_samd21.c:62
void i2c_set_pin(uint8_t sda, uint8_t scl)
Set I2C data and clock pin. Other functions will use these pins.
Definition: i2c_bitbang_samd21.c:49
Microchip Crypto Auth status codes.
void i2c_send_start(void)
Send a START condition.
Definition: i2c_bitbang_samd21.c:68
#define MAX_I2C_BUSES
Definition: i2c_bitbang_samd21.h:35