2 **************************************************************************
3 * @file i2c_application.h
4 * @brief i2c application libray header file
5 **************************************************************************
6 * Copyright notice & Disclaimer
8 * The software Board Support Package (BSP) that is made available to
9 * download from Artery official website is the copyrighted work of Artery.
10 * Artery authorizes customers to use, copy, and distribute the BSP
11 * software and its related documentation for the purpose of design and
12 * development in conjunction with Artery microcontrollers. Use of the
13 * software is governed by this copyright notice and the following disclaimer.
15 * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
16 * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
17 * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
18 * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
19 * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
22 **************************************************************************
25 /*!< define to prevent recursive inclusion -------------------------------------*/
26 #ifndef __I2C_APPLICATION_H
27 #define __I2C_APPLICATION_H
33 /* includes ------------------------------------------------------------------*/
34 #include "at32f435_437.h"
36 /** @addtogroup AT32F435_437_middlewares_i2c_application_library
41 /** @defgroup I2C_library_event_check_flag
45 #define I2C_EVENT_CHECK_NONE ((uint32_t)0x00000000) /*!< check flag none */
46 #define I2C_EVENT_CHECK_ACKFAIL ((uint32_t)0x00000001) /*!< check flag ackfail */
47 #define I2C_EVENT_CHECK_STOP ((uint32_t)0x00000002) /*!< check flag stop */
53 /** @defgroup I2C_library_memory_address_width_mode
59 I2C_MEM_ADDR_WIDIH_8
= 0x01, /*!< memory address is 8 bit */
60 I2C_MEM_ADDR_WIDIH_16
= 0x02, /*!< memory address is 16 bit */
61 } i2c_mem_address_width_type
;
67 /** @defgroup I2C_library_transmission_mode
89 /** @defgroup I2C_library_status_code
95 I2C_OK
= 0, /*!< no error */
96 I2C_ERR_STEP_1
, /*!< step 1 error */
97 I2C_ERR_STEP_2
, /*!< step 2 error */
98 I2C_ERR_STEP_3
, /*!< step 3 error */
99 I2C_ERR_STEP_4
, /*!< step 4 error */
100 I2C_ERR_STEP_5
, /*!< step 5 error */
101 I2C_ERR_STEP_6
, /*!< step 6 error */
102 I2C_ERR_STEP_7
, /*!< step 7 error */
103 I2C_ERR_STEP_8
, /*!< step 8 error */
104 I2C_ERR_STEP_9
, /*!< step 9 error */
105 I2C_ERR_STEP_10
, /*!< step 10 error */
106 I2C_ERR_STEP_11
, /*!< step 11 error */
107 I2C_ERR_STEP_12
, /*!< step 12 error */
108 I2C_ERR_TCRLD
, /*!< tcrld error */
109 I2C_ERR_TDC
, /*!< tdc error */
110 I2C_ERR_ADDR
, /*!< addr error */
111 I2C_ERR_STOP
, /*!< stop error */
112 I2C_ERR_ACKFAIL
, /*!< ackfail error */
113 I2C_ERR_TIMEOUT
, /*!< timeout error */
114 I2C_ERR_INTERRUPT
, /*!< interrupt error */
121 /** @defgroup I2C_library_handler
126 * @brief i2c transmission status
134 I2C_STEP_REG
, // Preliminary transfer to write register address prior to a read
141 i2c_type
*i2cx
; /*!< i2c registers base address */
143 uint8_t *pbuff
[I2C_STEP_COUNT
]; /*!< pointer to i2c transfer buffer */
144 __IO
uint16_t psize
; /*!< i2c transfer size */
145 __IO
uint16_t pcount
[I2C_STEP_COUNT
]; /*!< i2c transfer counter */
146 __IO
uint32_t mode
; /*!< i2c communication mode */
147 __IO i2cStep_t step
; /*!< 0 based phased count */
148 __IO i2cState_t state
; /*!< i2c communication state */
149 __IO i2c_status_type error_code
; /*!< i2c error code */
150 dma_channel_type
*dma_tx_channel
; /*!< dma transmit channel */
151 dma_channel_type
*dma_rx_channel
; /*!< dma receive channel */
152 dma_init_type dma_init_struct
; /*!< dma init parameters */
159 /** @defgroup I2C_library_exported_functions
163 void i2c_config (i2c_handle_type
* hi2c
);
164 void i2c_lowlevel_init (i2c_handle_type
* hi2c
);
165 void i2c_reset_ctrl2_register (i2c_handle_type
* hi2c
);
166 i2c_status_type
i2c_wait_flag (i2c_handle_type
* hi2c
, uint32_t flag
, uint32_t event_check
, uint32_t timeout
);
168 i2c_status_type
i2c_master_transmit (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
169 i2c_status_type
i2c_master_receive (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
170 i2c_status_type
i2c_slave_transmit (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
171 i2c_status_type
i2c_slave_receive (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
173 i2c_status_type
i2c_master_transmit_int (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
174 i2c_status_type
i2c_master_receive_int (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
175 i2c_status_type
i2c_slave_transmit_int (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
176 i2c_status_type
i2c_slave_receive_int (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
178 i2c_status_type
i2c_master_transmit_dma (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
179 i2c_status_type
i2c_master_receive_dma (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
180 i2c_status_type
i2c_slave_transmit_dma (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
181 i2c_status_type
i2c_slave_receive_dma (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
183 i2c_status_type
i2c_smbus_master_transmit (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
184 i2c_status_type
i2c_smbus_master_receive (i2c_handle_type
* hi2c
, uint16_t address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
185 i2c_status_type
i2c_smbus_slave_transmit (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
186 i2c_status_type
i2c_smbus_slave_receive (i2c_handle_type
* hi2c
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
188 i2c_status_type
i2c_memory_write (i2c_handle_type
* hi2c
, i2c_mem_address_width_type mem_address_width
, uint16_t address
, uint16_t mem_address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
189 i2c_status_type
i2c_memory_write_int (i2c_handle_type
* hi2c
, i2c_mem_address_width_type mem_address_width
, uint16_t address
, uint16_t mem_address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
190 i2c_status_type
i2c_memory_write_dma (i2c_handle_type
* hi2c
, i2c_mem_address_width_type mem_address_width
, uint16_t address
, uint16_t mem_address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
191 i2c_status_type
i2c_memory_read (i2c_handle_type
* hi2c
, i2c_mem_address_width_type mem_address_width
, uint16_t address
, uint16_t mem_address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
192 i2c_status_type
i2c_memory_read_int (i2c_handle_type
* hi2c
, i2c_mem_address_width_type mem_address_width
, uint16_t address
, uint16_t mem_address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
193 i2c_status_type
i2c_memory_read_dma (i2c_handle_type
* hi2c
, i2c_mem_address_width_type mem_address_width
, uint16_t address
, uint16_t mem_address
, uint8_t* pdata
, uint16_t size
, uint32_t timeout
);
195 void i2c_evt_irq_handler (i2c_handle_type
* hi2c
);
196 void i2c_err_irq_handler (i2c_handle_type
* hi2c
);
197 void i2c_dma_tx_irq_handler (i2c_handle_type
* hi2c
);
198 void i2c_dma_rx_irq_handler (i2c_handle_type
* hi2c
);