1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <driver/qspi_types.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** 24 * @brief Init the QSPI driver 25 * 26 * This API init the resoure common: 27 * - Init QSPI driver control memory 28 * 29 * @attention 1. This API should be called before any other QSPI APIs. 30 * 31 * @return 32 * - BK_OK: succeed 33 * - others: other errors. 34 */ 35 bk_err_t bk_qspi_driver_init(void); 36 37 /** 38 * @brief Deinit the QSPI driver 39 * 40 * This API free all resource related to QSPI and disable QSPI. 41 * 42 * @return 43 * - BK_OK: succeed 44 * - others: other errors. 45 */ 46 bk_err_t bk_qspi_driver_deinit(void); 47 48 /** 49 * @brief Init the QSPI 50 * 51 * This API init the QSPI: 52 * - Power up the QSPI 53 * - Configure the QSPI clock 54 * - Map the QSPI to dedicated GPIO port 55 * - Enabel QSPI interrupt 56 * 57 * @param config QSPI parameter settings 58 * 59 * @return 60 * - BK_OK: succeed 61 * - BK_ERR_QSPI_NOT_INIT: QSPI driver not init 62 * - BK_ERR_NULL_PARAM: QSPI config parameter is NULL 63 * - others: other errors. 64 */ 65 bk_err_t bk_qspi_init(const qspi_config_t *config); 66 67 /** 68 * @brief Deinit the QSPI 69 * 70 * This API deinit the QSPI: 71 * - Disable the QSPI interrupt 72 * - Power down the QSPI 73 * 74 * @return 75 * - BK_OK: succeed 76 * - others: other errors. 77 */ 78 bk_err_t bk_qspi_deinit(void); 79 80 /** 81 * @brief Init the QSPI command 82 * 83 * @param cmd QSPI device command 84 * 85 * @return 86 * - BK_OK: succeed 87 * - others: other errors. 88 */ 89 bk_err_t bk_qspi_command(const qspi_cmd_t *cmd); 90 91 /** 92 * @brief QSPI indirect mode write 93 * 94 * @param base_addr QSPI write address 95 * @param data QSPI write data 96 * @param size the size of QSPI write data 97 * 98 * @return 99 * - BK_OK: succeed 100 * - others: other errors. 101 */ 102 bk_err_t bk_qspi_write(const void *data, uint32_t size); 103 104 /** 105 * @brief QSPI indirect mode read 106 * 107 * @param base_addr QSPI read address 108 * @param data QSPI read data 109 * @param size the size of QSPI read data 110 * 111 * @return 112 * - BK_OK: succeed 113 * - others: other errors. 114 */ 115 bk_err_t bk_qspi_read(void *data, uint32_t size); 116 117 /** 118 * @brief Register the TX interrupt service routine for QSPI 119 * 120 * @param isr QSPI TX callback 121 * @param param QSPI TX callback parameter 122 * 123 * @return 124 * - BK_OK: succeed 125 * - others: other errors. 126 */ 127 bk_err_t bk_qspi_register_tx_isr(qspi_isr_t isr, void *param); 128 129 /** 130 * @brief Register the RX interrupt service routine for QSPI 131 * 132 * @param isr QSPI RX callback 133 * @param param QSPI RX callback parameter 134 * 135 * @return 136 * - BK_OK: succeed 137 * - others: other errors. 138 */ 139 bk_err_t bk_qspi_register_rx_isr(qspi_isr_t isr, void *param); 140 141 #ifdef __cplusplus 142 } 143 #endif 144