• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ****************************************************************************************
3   * @file    gr55xx_hal_i2c.c
4   * @author  BLE Driver Team
5   * @brief   I2C HAL module driver.
6   ****************************************************************************************
7   * @attention
8   #####Copyright (c) 2019 GOODIX
9    All rights reserved.
10 
11    Redistribution and use in source and binary forms, with or without
12    modification, are permitted provided that the following conditions are met:
13    * Redistributions of source code must retain the above copyright
14     notice, this list of conditions and the following disclaimer.
15    * Redistributions in binary form must reproduce the above copyright
16      notice, this list of conditions and the following disclaimer in the
17      documentation and/or other materials provided with the distribution.
18    * Neither the name of GOODIX nor the names of its contributors may be used
19      to endorse or promote products derived from this software without
20      specific prior written permission.
21 
22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25    ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32    POSSIBILITY OF SUCH DAMAGE.
33   ****************************************************************************************
34   */
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "gr55xx_hal.h"
38 #include "gr55xx_rom_symbol.h"
39 
40 #if defined(HAL_I2C_MODULE_ENABLED) && (defined(GR5515_D) || defined(GR5515_E))
41 
42 /* Private variables ---------------------------------------------------------*/
43 
44 static hal_i2c_callback_t i2c_callback = {
45     .i2c_msp_init                   = hal_i2c_msp_init,
46     .i2c_msp_deinit                 = hal_i2c_msp_deinit,
47     .i2c_master_tx_cplt_callback    = hal_i2c_master_tx_cplt_callback,
48     .i2c_master_rx_cplt_callback    = hal_i2c_master_rx_cplt_callback,
49     .i2c_slave_tx_cplt_callback     = hal_i2c_slave_tx_cplt_callback,
50     .i2c_slave_rx_cplt_callback     = hal_i2c_slave_rx_cplt_callback,
51     .i2c_listen_cplt_callback       = hal_i2c_listen_cplt_callback,
52     .i2c_mem_tx_cplt_callback       = hal_i2c_mem_tx_cplt_callback,
53     .i2c_mem_rx_cplt_callback       = hal_i2c_mem_rx_cplt_callback,
54     .i2c_error_callback             = hal_i2c_error_callback,
55     .i2c_abort_cplt_callback        = hal_i2c_abort_cplt_callback
56 };
57 
58 /* Private function prototypes -----------------------------------------------*/
59 
hal_i2c_init(i2c_handle_t * p_i2c)60 hal_status_t hal_i2c_init(i2c_handle_t *p_i2c)
61 {
62     hal_i2c_register_callback(&i2c_callback);
63 
64     hal_status_t ret;
65     GLOBAL_EXCEPTION_DISABLE();
66     ret = hal_i2c_init_ext(p_i2c);
67     GLOBAL_EXCEPTION_ENABLE();
68 
69     return ret;
70 }
71 
hal_i2c_deinit(i2c_handle_t * p_i2c)72 hal_status_t hal_i2c_deinit(i2c_handle_t *p_i2c)
73 {
74     hal_i2c_register_callback(&i2c_callback);
75 
76     hal_status_t ret;
77     GLOBAL_EXCEPTION_DISABLE();
78     ret = hal_i2c_deinit_ext(p_i2c);
79     GLOBAL_EXCEPTION_ENABLE();
80 
81     return ret;
82 }
83 
hal_i2c_msp_init(i2c_handle_t * p_i2c)84 __WEAK void hal_i2c_msp_init(i2c_handle_t *p_i2c)
85 {
86     /* Prevent unused argument(s) compilation warning */
87     UNUSED(p_i2c);
88 }
89 
hal_i2c_msp_deinit(i2c_handle_t * p_i2c)90 __WEAK void hal_i2c_msp_deinit(i2c_handle_t *p_i2c)
91 {
92     /* Prevent unused argument(s) compilation warning */
93     UNUSED(p_i2c);
94 }
95 
hal_i2c_master_tx_cplt_callback(i2c_handle_t * p_i2c)96 __WEAK void hal_i2c_master_tx_cplt_callback(i2c_handle_t *p_i2c)
97 {
98     /* Prevent unused argument(s) compilation warning */
99     UNUSED(p_i2c);
100 }
101 
hal_i2c_master_rx_cplt_callback(i2c_handle_t * p_i2c)102 __WEAK void hal_i2c_master_rx_cplt_callback(i2c_handle_t *p_i2c)
103 {
104     /* Prevent unused argument(s) compilation warning */
105     UNUSED(p_i2c);
106 }
107 
hal_i2c_slave_tx_cplt_callback(i2c_handle_t * p_i2c)108 __WEAK void hal_i2c_slave_tx_cplt_callback(i2c_handle_t *p_i2c)
109 {
110     /* Prevent unused argument(s) compilation warning */
111     UNUSED(p_i2c);
112 }
113 
hal_i2c_slave_rx_cplt_callback(i2c_handle_t * p_i2c)114 __WEAK void hal_i2c_slave_rx_cplt_callback(i2c_handle_t *p_i2c)
115 {
116     /* Prevent unused argument(s) compilation warning */
117     UNUSED(p_i2c);
118 }
119 
hal_i2c_listen_cplt_callback(i2c_handle_t * p_i2c)120 __WEAK void hal_i2c_listen_cplt_callback(i2c_handle_t *p_i2c)
121 {
122     /* Prevent unused argument(s) compilation warning */
123     UNUSED(p_i2c);
124 }
125 
hal_i2c_mem_tx_cplt_callback(i2c_handle_t * p_i2c)126 __WEAK void hal_i2c_mem_tx_cplt_callback(i2c_handle_t *p_i2c)
127 {
128     /* Prevent unused argument(s) compilation warning */
129     UNUSED(p_i2c);
130 }
131 
hal_i2c_mem_rx_cplt_callback(i2c_handle_t * p_i2c)132 __WEAK void hal_i2c_mem_rx_cplt_callback(i2c_handle_t *p_i2c)
133 {
134     /* Prevent unused argument(s) compilation warning */
135     UNUSED(p_i2c);
136 }
137 
hal_i2c_error_callback(i2c_handle_t * p_i2c)138 __WEAK void hal_i2c_error_callback(i2c_handle_t *p_i2c)
139 {
140     /* Prevent unused argument(s) compilation warning */
141     UNUSED(p_i2c);
142 }
143 
hal_i2c_abort_cplt_callback(i2c_handle_t * p_i2c)144 __WEAK void hal_i2c_abort_cplt_callback(i2c_handle_t *p_i2c)
145 {
146     /* Prevent unused argument(s) compilation warning */
147     UNUSED(p_i2c);
148 }
149 
150 #endif /* HAL_I2C_MODULE_ENABLED */
151