drv_spi.h 1.2 KB
Newer Older
1
/*
mysterywolf's avatar
mysterywolf 已提交
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
3 4 5 6 7
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
8
 * 2018-11-5      SummerGift   first version
9 10
 */

C
Chenxuan Zhao 已提交
11 12
#ifndef __DRV_SPI_H__
#define __DRV_SPI_H__
13 14 15 16 17 18 19

#include <rtthread.h>
#include "rtdevice.h"
#include <rthw.h>
#include <drv_common.h>
#include "drv_dma.h"

C
Chenxuan Zhao 已提交
20 21 22 23
#ifdef __cplusplus
extern "C" {
#endif

24 25
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, GPIO_TypeDef* cs_gpiox, uint16_t cs_gpio_pin);

C
Chenxuan Zhao 已提交
26 27 28 29
#ifdef __cplusplus
}
#endif

30 31 32 33 34 35 36 37 38 39
struct stm32_hw_spi_cs
{
    GPIO_TypeDef* GPIOx;
    uint16_t GPIO_Pin;
};

struct stm32_spi_config
{
    SPI_TypeDef *Instance;
    char *bus_name;
40
    struct dma_config *dma_rx, *dma_tx;
41 42 43 44 45 46 47 48 49
};

struct stm32_spi_device
{
    rt_uint32_t pin;
    char *bus_name;
    char *device_name;
};

50 51 52
#define SPI_USING_RX_DMA_FLAG   (1<<0)
#define SPI_USING_TX_DMA_FLAG   (1<<1)

53 54 55 56
/* stm32 spi dirver class */
struct stm32_spi
{
    SPI_HandleTypeDef handle;
57
    struct stm32_spi_config *config;
58
    struct rt_spi_configuration *cfg;
59

60 61 62 63 64
    struct
    {
        DMA_HandleTypeDef handle_rx;
        DMA_HandleTypeDef handle_tx;
    } dma;
mysterywolf's avatar
mysterywolf 已提交
65

66
    rt_uint8_t spi_dma_flag;
67 68 69
    struct rt_spi_bus spi_bus;
};

C
Chenxuan Zhao 已提交
70
#endif /*__DRV_SPI_H__ */