1 /* 2 * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2022-04-28 CDT first version 9 */ 10 11 12 #ifndef __DRV_SPI_H__ 13 #define __DRV_SPI_H__ 14 15 /******************************************************************************* 16 * Include files 17 ******************************************************************************/ 18 #include <rtthread.h> 19 #include "rtdevice.h" 20 #include "drv_dma.h" 21 #include "drv_irq.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 struct hc32_spi_irq_config 28 { 29 struct hc32_irq_config irq_config; 30 func_ptr_t irq_callback; 31 }; 32 33 struct hc32_spi_config 34 { 35 CM_SPI_TypeDef *Instance; 36 char *bus_name; 37 rt_uint32_t clock; 38 rt_uint32_t timeout; 39 struct hc32_spi_irq_config err_irq; 40 #ifdef BSP_SPI_USING_DMA 41 struct dma_config *dma_rx; 42 struct dma_config *dma_tx; 43 #endif 44 }; 45 46 struct hc32_spi 47 { 48 struct hc32_spi_config *config; 49 struct rt_spi_configuration *cfg; 50 struct rt_spi_bus spi_bus; 51 rt_uint16_t spi_dma_flag; 52 }; 53 54 rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin); 55 56 57 #ifdef __cplusplus 58 } 59 #endif 60 61 #endif /* __DRV_SPI_H__ */ 62 63