2018-11-29 17:00:22 +08:00
|
|
|
/*
|
2023-01-09 10:20:16 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2018-11-29 17:00:22 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2019-01-08 11:58:57 +08:00
|
|
|
* 2018-11-5 SummerGift first version
|
2018-11-29 17:00:22 +08:00
|
|
|
*/
|
|
|
|
|
2020-09-03 14:59:18 +08:00
|
|
|
#ifndef __DRV_SPI_H__
|
|
|
|
#define __DRV_SPI_H__
|
2018-11-29 17:00:22 +08:00
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "rtdevice.h"
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <drv_common.h>
|
|
|
|
#include "drv_dma.h"
|
2022-10-18 03:52:03 +08:00
|
|
|
#include <ipc/completion.h>
|
2018-11-29 17:00:22 +08:00
|
|
|
|
2020-09-03 14:59:18 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2023-01-18 13:27:08 +08:00
|
|
|
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
|
2018-11-29 17:00:22 +08:00
|
|
|
|
2020-09-03 14:59:18 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
struct stm32_spi_config
|
|
|
|
{
|
|
|
|
SPI_TypeDef *Instance;
|
|
|
|
char *bus_name;
|
2021-04-23 09:52:17 +08:00
|
|
|
IRQn_Type irq_type;
|
2019-01-08 11:58:57 +08:00
|
|
|
struct dma_config *dma_rx, *dma_tx;
|
2018-11-29 17:00:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_spi_device
|
|
|
|
{
|
|
|
|
rt_uint32_t pin;
|
|
|
|
char *bus_name;
|
|
|
|
char *device_name;
|
|
|
|
};
|
|
|
|
|
2019-01-08 11:58:57 +08:00
|
|
|
#define SPI_USING_RX_DMA_FLAG (1<<0)
|
|
|
|
#define SPI_USING_TX_DMA_FLAG (1<<1)
|
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
/* stm32 spi dirver class */
|
|
|
|
struct stm32_spi
|
|
|
|
{
|
|
|
|
SPI_HandleTypeDef handle;
|
2019-01-08 11:58:57 +08:00
|
|
|
struct stm32_spi_config *config;
|
2018-11-29 17:00:22 +08:00
|
|
|
struct rt_spi_configuration *cfg;
|
2019-01-08 11:58:57 +08:00
|
|
|
|
2018-11-29 17:00:22 +08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
DMA_HandleTypeDef handle_rx;
|
|
|
|
DMA_HandleTypeDef handle_tx;
|
|
|
|
} dma;
|
2021-03-08 22:40:39 +08:00
|
|
|
|
2019-01-08 11:58:57 +08:00
|
|
|
rt_uint8_t spi_dma_flag;
|
2018-11-29 17:00:22 +08:00
|
|
|
struct rt_spi_bus spi_bus;
|
2022-10-18 03:52:03 +08:00
|
|
|
|
|
|
|
struct rt_completion cpt;
|
2018-11-29 17:00:22 +08:00
|
|
|
};
|
|
|
|
|
2020-09-04 07:59:37 +08:00
|
|
|
#endif /*__DRV_SPI_H__ */
|