2022-05-06 09:28:21 +08:00
|
|
|
/*
|
2024-01-09 21:56:37 +08:00
|
|
|
* Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
|
2022-05-06 09:28:21 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-04-28 CDT first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __DRV_SPI_H__
|
|
|
|
#define __DRV_SPI_H__
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Include files
|
|
|
|
******************************************************************************/
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "rtdevice.h"
|
|
|
|
#include "drv_dma.h"
|
|
|
|
#include "drv_irq.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
struct hc32_hw_spi_cs
|
|
|
|
{
|
|
|
|
rt_uint8_t port;
|
|
|
|
rt_uint16_t pin;
|
|
|
|
};
|
|
|
|
|
2024-01-09 21:56:37 +08:00
|
|
|
struct hc32_spi_irq_config
|
|
|
|
{
|
|
|
|
struct hc32_irq_config irq_config;
|
|
|
|
func_ptr_t irq_callback;
|
|
|
|
};
|
|
|
|
|
2022-05-06 09:28:21 +08:00
|
|
|
struct hc32_spi_config
|
|
|
|
{
|
2024-01-09 21:56:37 +08:00
|
|
|
CM_SPI_TypeDef *Instance;
|
|
|
|
char *bus_name;
|
|
|
|
rt_uint32_t clock;
|
|
|
|
rt_uint32_t timeout;
|
|
|
|
struct hc32_spi_irq_config err_irq;
|
|
|
|
#ifdef BSP_SPI_USING_DMA
|
|
|
|
struct dma_config *dma_rx;
|
|
|
|
struct dma_config *dma_tx;
|
|
|
|
#endif
|
2022-05-06 09:28:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hc32_spi
|
|
|
|
{
|
|
|
|
struct hc32_spi_config *config;
|
|
|
|
struct rt_spi_configuration *cfg;
|
|
|
|
struct rt_spi_bus spi_bus;
|
2024-01-09 21:56:37 +08:00
|
|
|
rt_uint16_t spi_dma_flag;
|
2022-05-06 09:28:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint8_t cs_gpio_port, uint16_t cs_gpio_pin);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __DRV_SPI_H__ */
|
|
|
|
|