stm32f0xx_i2c_cpal_conf_template.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_i2c_cpal_conf.h
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 24-July-2014
  7. * @brief Library configuration file
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM32F0XX_I2C_CPAL_CONF_H
  29. #define __STM32F0XX_I2C_CPAL_CONF_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* Includes ------------------------------------------------------------------*/
  34. /* Exported types ------------------------------------------------------------*/
  35. /* Exported constants --------------------------------------------------------*/
  36. /*=======================================================================================================================================
  37. User NOTES
  38. =========================================================================================================================================
  39. -------------------------------
  40. 1. How To use the CPAL Library:
  41. -------------------------------
  42. ------- Refer to the user manual of the library and (eventually) the example to check if
  43. this firmware is appropriate for your hardware (device and (eventually) evaluation board)
  44. - Section 1 : Select the Device instances to be used and the total number of devices
  45. - Section 2 : Configure Transfer Options
  46. - Section 3 : Select and configure transfer and error user Callbacks
  47. - Section 4 : Configure Timeout mechanism and TimeoutCallback
  48. - Section 5 : Configure Interrupt Priority Offset
  49. - Section 6 : Configure CPAL_LOG Macro
  50. ------ After configuring CPAL firmware functionality , You should proceed by configuring hardware used with CPAL
  51. (please refer to stm32f0xx_i2c_cpal_hal.h file).
  52. ------ After configuring CPAL Firmware Library, you should follow these steps to use the Firmware correctly :
  53. -1- STRUCTURE INITIALIZATION
  54. Start by initializing the Device. To perform this action, the global variable PPPx_DevStructure declared
  55. in CPAL Firmware as CPAL_InitTypeDef (I2C1_DevStructure for I2C1, I2C2_DevStructure for I2C2 ...) must be used.
  56. There are two ways to proceed :
  57. ** Call the function CPAL_PPP_StructInit() using as parameter PPPx_DevStructure (where PPP = device type (ie. I2C...)
  58. and where x could be 1 for PPP1, 2 for PPP2 ...). This function sets the default values for all fields of this structure.
  59. Default values for I2C devices are :
  60. I2Cx_DevStructure.CPAL_Direction = CPAL_DIRECTION_TXRX
  61. I2Cx_DevStructure.CPAL_Mode = CPAL_MODE_MASTER
  62. I2Cx_DevStructure.CPAL_ProgModel = CPAL_PROGMODEL_DMA
  63. I2Cx_DevStructure.pCPAL_TransferTx = pNULL
  64. I2Cx_DevStructure.pCPAL_TransferRx = pNULL
  65. I2Cx_DevStructure.CPAL_State = CPAL_STATE_DISABLED
  66. I2Cx_DevStructure.wCPAL_DevError = CPAL_I2C_ERR_NONE
  67. I2Cx_DevStructure.wCPAL_Options = 0 (all options disabled)
  68. I2Cx_DevStructure.wCPAL_Timeout = CPAL_TIMEOUT_DEFAULT
  69. I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_Mode = I2C_Mode_I2C
  70. I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_AnalogFilter = I2C_AnalogFilter_Enable
  71. I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_DigitalFilter = 0x00
  72. I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_OwnAddress1 = 0
  73. I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_Ack = I2C_Ack_Enable
  74. I2Cx_DevStructure.pCPAL_I2C_Struct->I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit
  75. pCPAL_TransferTx and pCPAL_TransferRx fields have to be updated in order to point to valid structures
  76. (these structures should be local/global variables in the user application).
  77. ** Another way of configuration is without calling CPAL_PPP_StructInit() function.
  78. Declare the following structures:
  79. - A PPP_InitTypeDef structure for the device configuration (ie. I2C_InitTypeDef structure)
  80. - One or two CPAL_TransferTypeDef variables (one for Tx and one for Rx).
  81. - Use the extern structure provided by the CPAL library: PPPx_InitStructure (ie. I2C1_DevStructure).
  82. Fill in all the fields for these structures (one by one).
  83. Use the pointers to these structures to fill in the fields pCPAL_PPP_Struct and pCPAL_TransferTx and/or
  84. pCPAL_TransferRx of the PPPx_DevStructure.
  85. After that CPAL_State must be set to CPAL_STATE_DISABLED.
  86. Finally, call the CPAL_PPP_Init() with pointer to the PPPx_DevStructure as argument.
  87. Example:
  88. // Declare local structures
  89. I2C_InitTypeDef I2C1_InitStructure;
  90. CPAL_TransferTypeDef TX_Transfer, RX_Transfer;
  91. // Fill in all the fields of to these structures
  92. I2Cx_InitStructure.I2C_Timing = 0X50321312;
  93. I2Cx_InitStructure.I2C_Mode = I2C_Mode_I2C;
  94. I2Cx_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable;
  95. .....
  96. TX_Transfer.pbBuffer = 0;
  97. TX_Transfer.wNumData = 0;
  98. .....
  99. RX_Transfer.pbBuffer = 0;
  100. RX_Transfer.wNumData = 0;
  101. .....
  102. // Use these structures and fill all fields of I2C1_DevStructure.
  103. I2C1_DevStructure.CPAL_Dev = CPAL_I2C1;
  104. I2C1_DevStructure.CPAL_Direction = CPAL_DIRECTION_TXRX;
  105. I2C1_DevStructure.CPAL_Mode = CPAL_MODE_SLAVE;
  106. I2C1_DevStructure.wCPAL_Options = CPAL_OPT_DMATX_TCIT | CPAL_OPT_DMATX_HTIT ;
  107. .....
  108. I2C1_DevStructure.pCPAL_TransferTx = &TX_Transfer;
  109. I2C1_DevStructure.pCPAL_TransferRx = &RX_Transfer;
  110. I2C1_DevStructure.pCPAL_I2C_Struct = &I2C1_InitStructure;
  111. ...
  112. I2C1_DevStructure.wCPAL_State = CPAL_STATE_DISABLED;
  113. ....
  114. CPAL_I2C_Init(&I2C1_DevStructure);
  115. -2- DEVICE CONFIGURATION
  116. Call the function CPAL_PPP_Init() to configure the selected device with the selected configuration by calling
  117. CPAL_PPP_Init(). This function also enables device clock and initialize all related peripherals ( GPIO, DMA , IT and NVIC ).
  118. This function tests on CPAL_State, if it is equal to CPAL_STATE_BUSY it exit, otherwise device initialization is
  119. performed and CPAL_State is set to CPAL_STATE_READY.
  120. This function returns CPAL_PASS state when the operation is correctly performed, or CPAL_FAIL when the current state of the
  121. device doesn't allow configuration (ie. state different from READY, DISABLED or ERROR).
  122. After calling this function, you may check on the new state of device, when it is equal to CPAL_STATE_READY, Transfer operations
  123. can be started, otherwise you can call CPAL_PPP_DeInit() to deinitialize device and call CPAL_PPP_Init() once again.
  124. -3- READ / WRITE OPERATIONS
  125. Call the function CPAL_PPP_Write() or CPAL_PPP_Read() to perform transfer operations.
  126. These functions handle communication events using device event interrupts (independently of programming model used: DMA,
  127. Interrupt). These functions start preparing communication (send start condition, send salve address in case of
  128. master mode ...) if connection is established between devices CPAL_State is set CPAL_STATE_BUSY_XX and data transfer starts.
  129. By default, Error interrupts are enabled to manage device errors (Error interrupts can be disabled by affecting
  130. CPAL_OPT_I2C_ERRIT_DISABLE to wCPAL_Options). When transfer is completed successfully, CPAL_State is set to CPAL_STATE_READY
  131. and another operation can be started.
  132. These functions return CPAL_PASS if the current state of the device allows starting a new operation and the operation is correctly
  133. started (but not finished). It returns CPAL_FAIL when the state of the device doesn't allow starting a new communication (ie.
  134. BUSY, DISABLED, ERROR) or when an error occurs during operation start.
  135. Once operation is started, user application may perform other tasks while CPAL is sending/receiving data on device through interrupt
  136. or DMA.
  137. -4- DEVICE DEINITIALIZATION
  138. When transfer operations are finished, you may call CPAL_PPP_DeInit() to disable PPPx device and related resources
  139. ( GPIO, DMA , IT and NVIC). CPAL_State is then set to CPAL_STATE_DISABLED by this function.
  140. ------ Callbacks are routines that let you insert your own code in different stages of communication and for handling
  141. device errors. Their prototypes are declared by the CPAL library (if the relative define in this stm32f0xx_i2c_cpal_conf.h is enabled)
  142. but their body is not implemented by CPAL library. It may be done by user when needed.
  143. There are three types of Callbacks: Transfer User Callbacks, Error User Callbacks and Timeout User Callbacks:
  144. -a- Transfer User Callbacks :
  145. ** CPAL_I2C_TX_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  146. This function is called before sending data when Interrupt Programming Model is selected.
  147. ** CPAL_I2C_RX_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  148. This function is called after receiving data when Interrupt Programming Model is selected.
  149. ** CPAL_I2C_TXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  150. ** CPAL_I2C_RXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  151. These functions are called when a transfer is complete when using Interrupt programming model or DMA
  152. programming model.
  153. ** CPAL_I2C_DMATXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  154. ** CPAL_I2C_DMATXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  155. These functions are called when Transfer complete Interrupt occurred in transmission/reception operation
  156. if DMA Programming Model is selected
  157. ** CPAL_I2C_DMATXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  158. ** CPAL_I2C_DMARXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  159. These functions are called when Half transfer Interrupt occurred in transmission/reception operation
  160. if DMA Programming Model is selected.
  161. ** CPAL_I2C_DMATXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  162. ** CPAL_I2C_DMARXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  163. These functions are called when a transfer error Interrupt occurred in transmission/reception operation
  164. if DMA Programming Model is selected.
  165. ** CPAL_I2C_GENCALL_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  166. This function is called when an Address Event interrupt occurred and General Call Address Flag is set
  167. (available in Slave mode only and when the option CPAL_OPT_I2C_GENCALL is enabled).
  168. ** CPAL_I2C_DUALF_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
  169. This function is called when an Address Event interrupt occurred and Dual Address Flag is set
  170. (available in Slave mode only and when the option CPAL_OPT_I2C_DUALADDR is enabled).
  171. -b- Error User Callbacks :
  172. ** CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t Device_Error)
  173. This function is called either when an Error Interrupt occurred (If Error Interrupts enabled) or after
  174. a read or write operations to handle device errors (If Error Interrupts disabled). This callback
  175. can be used to handle all device errors. It is available only when the define USE_SINGLE_ERROR_CALLBACK
  176. is enabled (Section 5).
  177. ** CPAL_I2C_BERR_UserCallback(CPAL_DevTypeDef pDevInstance)
  178. This function is called either when a Bus Error Interrupt occurred (If Error Interrupts enabled) or
  179. after a read or write operations to handle this error (If Error Interrupts disabled). This callback is
  180. available only when USE_MULTIPLE_ERROR_CALLBACK is enabled (Section 5).
  181. ** CPAL_I2C_ARLO_UserCallback(CPAL_DevTypeDef pDevInstance)
  182. This function is called either when an Arbitration Lost Interrupt occurred (If Error Interrupts
  183. enabled) or after a read or write operations to handle this error (If Error Interrupts disabled).
  184. ** CPAL_I2C_OVR_UserCallback(CPAL_DevTypeDef pDevInstance)
  185. This function is called either when an Overrun Interrupt occurred (If Error Interrupts enabled) or
  186. after a read or write operations to handle this error (If Error Interrupts disabled). This callback is
  187. available only when USE_MULTIPLE_ERROR_CALLBACK is enabled (Section 5).
  188. ** CPAL_I2C_AF_UserCallback(CPAL_DevTypeDef pDevInstance)
  189. This function is called either when an Acknowledge Failure Interrupt occurred (If Error Interrupts
  190. enabled) or after a read or write operations to handle this error (If Error Interrupts disabled).
  191. This callback is available only when USE_MULTIPLE_ERROR_CALLBACK is enabled (Section 5).
  192. -c- Timeout User Callbacks :
  193. ** CPAL_TIMEOUT_UserCallback(void)
  194. This function is called when a Timeout occurred in communication.
  195. ** CPAL_TIMEOUT_INIT()
  196. This function allows to configure and enable the counting peripheral/function (ie. SysTick Timer)
  197. It is called into all CPAL_PPP_Init() functions.
  198. ** CPAL_TIMEOUT_DEINIT()
  199. This function allow to free the resources of counting peripheral/function and stop the count.
  200. (ie. disable the SysTick timer and its interrupt).
  201. ** CPAL_PPP_TIMEOUT_Manager()
  202. WARNING: DO NOT IMPLEMENT THIS FUNCTION (already implemented in CPAL drivers)
  203. This function is already implemented in the CPAL drivers (stm32f0xx_i2c_cpal.c file). It should be called periodically
  204. (using the count mechanism interrupt for example). This function checks all PPP devices and
  205. manages timeout conditions. In case of timeout occurring, this function calls the
  206. CPAL_TIMEOUT_UserCallback() function that may be implemented by user to manage the cases of
  207. timeout errors (ie. reset the device/microcontroller...).
  208. In order to facilitate implementation, this function (instead to be called periodically by user
  209. application), may be mapped directly to a periodic event/interrupt:
  210. Example:
  211. #define CPAL_I2C_TIMEOUT_Manager SysTick_Handler
  212. ** Note ** : when mapping CPAL_I2C_TIMEOUT_Manager to a periodic event/interrupt, the prototype
  213. of this event/interrupt should be added. Here below an example when SysTick_Handler
  214. is used to handle timeout mechanism :
  215. #ifndef CPAL_I2C_TIMEOUT_Manager
  216. void CPAL_I2C_TIMEOUT_Manager(void);
  217. #else
  218. void SysTick_Handler(void);
  219. #endif
  220. To implement Transfer and Error Callbacks, you should comment relative defines in Section 4 and implement Callback function (body) into
  221. your application (their prototypes are declared in stm32f0xx_i2c_cpal.h file).
  222. Example: How to implement CPAL_I2C_TX_UserCallback() callback:
  223. -1- Comment the relative define in this file :
  224. //#define CPAL_I2C_TX_UserCallback (void)
  225. -2- Add CPAL_I2C_TX_UserCallback code source in application file ( example : main.c )
  226. void CPAL_I2C_TX_UserCallback (CPAL_InitTypeDef* pDevInitStruct)
  227. {
  228. //
  229. // user code
  230. //
  231. }
  232. There are two types of Error Callbacks :
  233. -1- Single Error Callback : Only one Callback is used to manage all device errors.
  234. -2- Multiple Error Callback : Each device error is managed by its own separate Callback.
  235. Example of using CPAL_I2C_BERR_UserCallback :
  236. -1- Select Multiple Error Callback type :
  237. //#define USE_SINGLE_ERROR_CALLBACK
  238. #define USE_MULTIPLE_ERROR_CALLBACK
  239. -2- Comment define relative to CPAL_I2C_BERR_UserCallback in stm32f0xx_i2c_cpal_conf.h.h file:
  240. //#define CPAL_I2C_BERR_UserCallback (void)
  241. -3- Add CPAL_I2C_BERR_UserCallback code source in application file ( example: main.c )
  242. void CPAL_I2C_BERR_UserCallback (CPAL_DevTypeDef pDevInstance)
  243. {
  244. //
  245. // user code
  246. //
  247. }
  248. ------ The driver API functions Prototypes are in stm32f0xx_i2c_cpal.h file.
  249. *********END OF User Notes***************************************************************************************************************/
  250. /*=======================================================================================================================================
  251. CPAL Firmware Functionality Configuration
  252. =========================================================================================================================================*/
  253. /*-----------------------------------------------------------------------------------------------------------------------*/
  254. /*-----------------------------------------------------------------------------------------------------------------------*/
  255. /* -- Section 1 : **** I2Cx Device Selection ****
  256. Description: This section provide an easy way to select I2Cx devices in user application.
  257. Choosing device allows to save memory resources.
  258. If you need I2C1 device, uncomment relative define: #define CPAL_USE_I2C1.
  259. All available I2Cx device can be used at the same time.
  260. At least one I2C device should be selected.*/
  261. #define CPAL_USE_I2C1 /*<! Uncomment to use I2C1 device */
  262. #define CPAL_USE_I2C2 /*<! Uncomment to use I2C2 device */
  263. /*-----------------------------------------------------------------------------------------------------------------------*/
  264. /*-----------------------------------------------------------------------------------------------------------------------*/
  265. /* -- Section 2 : **** Transfer Options Configuration ****
  266. Description: This section allows user to enable/disable some Transfer Options. The benefits of these
  267. defines is to minimize the size of the source code */
  268. /* Enable the use of Master Mode */
  269. #define CPAL_I2C_MASTER_MODE
  270. /* Enable the use of Slave Mode */
  271. #define CPAL_I2C_SLAVE_MODE
  272. /* Enable the use of DMA Programming Model */
  273. #define CPAL_I2C_DMA_PROGMODEL
  274. /* Enable the use of IT Programming Model */
  275. #define CPAL_I2C_IT_PROGMODEL
  276. /* !!!! These following defines are available only when CPAL_I2C_MASTER_MODE is enabled !!!! */
  277. /* Enable the use of 10Bit Addressing Mode */
  278. #define CPAL_I2C_10BIT_ADDR_MODE
  279. /* Enable the use of Memory Addressing Mode */
  280. #define CPAL_I2C_MEM_ADDR
  281. /* Enable the use of 16Bit Address memory register option */
  282. #define CPAL_16BIT_REG_OPTION
  283. /*------------------------------------------------------------------------------------------------------------------------------*/
  284. /*------------------------------------------------------------------------------------------------------------------------------*/
  285. /* -- Section 3 : **** UserCallbacks Selection and Configuration ****
  286. Description: This section provides an easy way to enable UserCallbacks and select type of Error UserCallbacks.
  287. By default, All UserCallbacks are disabled (UserCallbacks are defined as void functions).
  288. To implement a UserCallbacks in your application, comment the relative define and
  289. implement the callback body in your application file.*/
  290. /* Error UserCallbacks Type : Uncomment to select UserCallbacks type. One type must be selected */
  291. /* Note : if Error UserCallbacks are not used the two following defines must be commented
  292. WARNING: These two defines are EXCLUSIVE, only one define should be uncommented !
  293. */
  294. //#define USE_SINGLE_ERROR_CALLBACK /*<! select single UserCallbacks type */
  295. //#define USE_MULTIPLE_ERROR_CALLBACK /*<! select multiple UserCallbacks type */
  296. /* Error UserCallbacks : To use an Error UserCallback comment the relative define */
  297. /* Single Error Callback */
  298. #define CPAL_I2C_ERR_UserCallback (void)
  299. /* Multiple Error Callback */
  300. #define CPAL_I2C_BERR_UserCallback (void)
  301. #define CPAL_I2C_ARLO_UserCallback (void)
  302. #define CPAL_I2C_OVR_UserCallback (void)
  303. #define CPAL_I2C_AF_UserCallback (void)
  304. /* Transfer UserCallbacks : To use a Transfer callback comment the relative define */
  305. #define CPAL_I2C_TX_UserCallback (void)
  306. #define CPAL_I2C_RX_UserCallback (void)
  307. #define CPAL_I2C_TXTC_UserCallback (void)
  308. #define CPAL_I2C_RXTC_UserCallback (void)
  309. /* DMA Transfer UserCallbacks : To use a DMA Transfer UserCallbacks comment the relative define */
  310. #define CPAL_I2C_DMATXTC_UserCallback (void)
  311. #define CPAL_I2C_DMATXHT_UserCallback (void)
  312. #define CPAL_I2C_DMATXTE_UserCallback (void)
  313. #define CPAL_I2C_DMARXTC_UserCallback (void)
  314. #define CPAL_I2C_DMARXHT_UserCallback (void)
  315. #define CPAL_I2C_DMARXTE_UserCallback (void)
  316. /* Address Mode UserCallbacks : To use an Address Mode UserCallbacks comment the relative define */
  317. #define CPAL_I2C_GENCALL_UserCallback (void)
  318. #define CPAL_I2C_DUALF_UserCallback (void)
  319. /* CriticalSectionCallback : Call User callback for critical section (should typically disable interrupts) */
  320. #define CPAL_EnterCriticalSection_UserCallback __disable_irq
  321. #define CPAL_ExitCriticalSection_UserCallback __enable_irq
  322. /*------------------------------------------------------------------------------------------------------------------------------------------------*/
  323. /*------------------------------------------------------------------------------------------------------------------------------------------------*/
  324. /* -- Section 4 : **** Configure Timeout method, TimeoutCallback ****
  325. Description: This section allows you to implement your own Timeout Procedure.
  326. By default Timeout procedure is implemented with Systick timer and
  327. CPAL_I2C_TIMEOUT_Manager is defined as SysTick_Handler.
  328. */
  329. #define _CPAL_TIMEOUT_INIT() SysTick_Config((SystemCoreClock / 1000));\
  330. NVIC_SetPriority (SysTick_IRQn, 0)
  331. /*<! Configure and enable the systick timer
  332. to generate an interrupt when counter value
  333. reaches 0. In the Systick interrupt handler
  334. the Timeout Error function is called. Time base is 1 ms */
  335. #define _CPAL_TIMEOUT_DEINIT() SysTick->CTRL = 0 /*<! Disable the systick timer */
  336. #define CPAL_I2C_TIMEOUT_Manager SysTick_Handler /*<! This callback is used to handle Timeout error.
  337. When a timeout occurs CPAL_TIMEOUT_UserCallback
  338. is called to handle this error */
  339. #ifndef CPAL_I2C_TIMEOUT_Manager
  340. void CPAL_I2C_TIMEOUT_Manager(void);
  341. #else
  342. void SysTick_Handler(void);
  343. #endif /* CPAL_I2C_TIMEOUT_Manager */
  344. /*#define CPAL_TIMEOUT_UserCallback (void) */ /*<! Comment this line and implement the callback body in your
  345. application in order to use the Timeout Callback.
  346. It is strongly advised to implement this callback, since it
  347. is the only way to manage timeout errors.*/
  348. /* Maximum Timeout values for each communication operation (preferably, Time base should be 1 Millisecond).
  349. The exact maximum value is the sum of event timeout value and the CPAL_I2C_TIMEOUT_MIN value defined below */
  350. #define CPAL_I2C_TIMEOUT_TC 5
  351. #define CPAL_I2C_TIMEOUT_TCR 5
  352. #define CPAL_I2C_TIMEOUT_TXIS 2
  353. #define CPAL_I2C_TIMEOUT_BUSY 2
  354. /* DO NOT MODIFY THESE VALUES ---------------------------------------------------------*/
  355. #define CPAL_I2C_TIMEOUT_DEFAULT ((uint32_t)0xFFFFFFFF)
  356. #define CPAL_I2C_TIMEOUT_MIN ((uint32_t)0x00000001)
  357. #define CPAL_I2C_TIMEOUT_DETECTED ((uint32_t)0x00000000)
  358. /*-----------------------------------------------------------------------------------------------------------------------*/
  359. /*-----------------------------------------------------------------------------------------------------------------------*/
  360. /* -- Section 5 : **** Configure Interrupt Priority Offset ****
  361. Description: This section allows user to configure Interrupt Priority Offset.
  362. By default Priority Offset of I2Cx device (ERR, EVT, DMA) are set to 0 */
  363. /*-----------Interrupt Priority Offset-------------*/
  364. /* This defines can be used to decrease the Level of Interrupt Priority for I2Cx Device (ERR, EVT, DMA_TX, DMA_RX).
  365. The value of I2Cx_IT_OFFSET_SUBPRIO is added to I2Cx_IT_XXX_SUBPRIO and the value of I2Cx_IT_OFFSET_PREPRIO
  366. is added to I2Cx_IT_XXX_PREPRIO (XXX: ERR, EVT, DMATX, DMARX).
  367. I2Cx Interrupt Priority are defined in stm32f0xx_i2c_cpal_hal.h file in Section 3 */
  368. #define I2C1_IT_OFFSET_SUBPRIO 0 /* I2C1 SUB-PRIORITY Offset */
  369. #define I2C1_IT_OFFSET_PREPRIO 0 /* I2C1 PREEMPTION PRIORITY Offset */
  370. #define I2C2_IT_OFFSET_SUBPRIO 0 /* I2C2 SUB-PRIORITY Offset */
  371. #define I2C2_IT_OFFSET_PREPRIO 0 /* I2C2 PREEMPTION PRIORITY Offset */
  372. /*-----------------------------------------------------------------------------------------------------------------------*/
  373. /*-----------------------------------------------------------------------------------------------------------------------*/
  374. /* -- Section 6 : **** CPAL DEBUG Configuration ****
  375. Description: This section allow user to enable or disable CPAL Debug option. Enabling this option provide
  376. to user an easy way to debug the application code. This option use CPAL_LOG Macro that integrate
  377. printf function. User can retarget printf function to USART ( use hyperterminal), LCD Screen
  378. on ST Eval Board or development toolchain debugger.
  379. In this example, the log is managed through printf function routed to USART peripheral and allowing
  380. to display messages on Hyperterminal-like terminals. This is performed through redefining the
  381. function PUTCHAR_PROTOTYPE (depending on the compiler) as follows:
  382. #ifdef __GNUC__
  383. // With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  384. // set to 'Yes') calls __io_putchar()
  385. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  386. #else
  387. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  388. #endif
  389. WARNING Be aware that enabling this feature may slow down the communication process, increase the code size
  390. significantly, and may in some cases cause communication errors (when print/display mechanism is too slow)*/
  391. /* To Enable CPAL_DEBUG Option Uncomment the define below */
  392. //#define CPAL_DEBUG
  393. #ifdef CPAL_DEBUG
  394. #define CPAL_LOG(Str) printf(Str)
  395. #include <stdio.h> /* This header file must be included when using CPAL_DEBUG option */
  396. #else
  397. #define CPAL_LOG(Str) ((void)0)
  398. #endif /* CPAL_DEBUG */
  399. /*-----------------------------------------------------------------------------------------------------------------------*/
  400. /*-----------------------------------------------------------------------------------------------------------------------*/
  401. /*********END OF CPAL Firmware Functionality Configuration****************************************************************/
  402. /* Exported macro ------------------------------------------------------------*/
  403. /* Exported functions ------------------------------------------------------- */
  404. #ifdef __cplusplus
  405. }
  406. #endif
  407. #endif /* __STM32F0XX_I2C_CPAL_CONF_H */
  408. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/