• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ****************************************************************************************
3   * @file    gr55xx_hal_spi.c
4   * @author  BLE Driver Team
5   * @brief   SPI 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_SPI_MODULE_ENABLED) && (defined(GR5515_D) || defined(GR5515_E))
41 
42 /* Private variables ---------------------------------------------------------*/
43 
44 static hal_spi_callback_t spi_callback = {
45     .spi_msp_init               = hal_spi_msp_init,
46     .spi_msp_deinit             = hal_spi_msp_deinit,
47     .spi_error_callback         = hal_spi_error_callback,
48     .spi_abort_cplt_callback    = hal_spi_abort_cplt_callback,
49     .spi_rx_cplt_callback       = hal_spi_rx_cplt_callback,
50     .spi_tx_cplt_callback       = hal_spi_tx_cplt_callback,
51     .spi_tx_rx_cplt_callback    = hal_spi_tx_rx_cplt_callback
52 };
53 
54 /* Private function prototypes -----------------------------------------------*/
55 
hal_spi_init(spi_handle_t * p_spi)56 hal_status_t hal_spi_init(spi_handle_t *p_spi)
57 {
58     hal_spi_register_callback(&spi_callback);
59 
60     hal_status_t ret;
61     GLOBAL_EXCEPTION_DISABLE();
62     ret = hal_spi_init_ext(p_spi);
63     GLOBAL_EXCEPTION_ENABLE();
64 
65     return ret;
66 }
67 
hal_spi_deinit(spi_handle_t * p_spi)68 hal_status_t hal_spi_deinit(spi_handle_t *p_spi)
69 {
70     hal_spi_register_callback(&spi_callback);
71 
72     hal_status_t ret;
73     GLOBAL_EXCEPTION_DISABLE();
74     ret = hal_spi_deinit_ext(p_spi);
75     GLOBAL_EXCEPTION_ENABLE();
76 
77     return ret;
78 }
79 
hal_spi_msp_init(spi_handle_t * p_spi)80 __WEAK void hal_spi_msp_init(spi_handle_t *p_spi)
81 {
82     /* Prevent unused argument(s) compilation warning */
83     return;
84 
85     /* NOTE : This function should not be modified, when the callback is needed,
86               the hal_spi_msp_init can be implemented in the user file
87      */
88 }
89 
hal_spi_msp_deinit(spi_handle_t * p_spi)90 __WEAK void hal_spi_msp_deinit(spi_handle_t *p_spi)
91 {
92     /* Prevent unused argument(s) compilation warning */
93     return;
94 
95     /* NOTE : This function should not be modified, when the callback is needed,
96               the hal_spi_msp_deinit can be implemented in the user file
97      */
98 }
99 
hal_spi_error_callback(spi_handle_t * p_spi)100 __WEAK void hal_spi_error_callback(spi_handle_t *p_spi)
101 {
102     /* Prevent unused argument(s) compilation warning */
103     UNUSED(p_spi);
104 }
105 
hal_spi_abort_cplt_callback(spi_handle_t * p_spi)106 __WEAK void hal_spi_abort_cplt_callback(spi_handle_t *p_spi)
107 {
108     /* Prevent unused argument(s) compilation warning */
109     UNUSED(p_spi);
110 }
111 
hal_spi_rx_cplt_callback(spi_handle_t * p_spi)112 __WEAK void hal_spi_rx_cplt_callback(spi_handle_t *p_spi)
113 {
114     /* Prevent unused argument(s) compilation warning */
115     UNUSED(p_spi);
116 }
117 
hal_spi_tx_cplt_callback(spi_handle_t * p_spi)118 __WEAK void hal_spi_tx_cplt_callback(spi_handle_t *p_spi)
119 {
120     /* Prevent unused argument(s) compilation warning */
121     UNUSED(p_spi);
122 }
123 
hal_spi_tx_rx_cplt_callback(spi_handle_t * p_spi)124 __WEAK void hal_spi_tx_rx_cplt_callback(spi_handle_t *p_spi)
125 {
126     /* Prevent unused argument(s) compilation warning */
127     UNUSED(p_spi);
128 }
129 
130 #endif /* HAL_SPI_MODULE_ENABLED */
131