drv_spi.h 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date             Author          Notes
 * 2021-02-14       supperthomas    first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>

#include "spi.h"

#ifndef __DRV_SPI_H_
#define __DRV_SPI_H_

/**
 * @brief Attach the spi device to SPI bus, this function must be used after initialization.
 * @param bus_name     spi bus name  "spi0"/"spi1"/"spi2"
 * @param device_name  spi device name "spi0x"/"spi1x"/"spi2x"
 * @param ss_pin       spi ss pin number
 * @retval  RT_ERROR / RT_EOK
*/
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);

//SPI bus config
#ifdef BSP_USING_SPI0
#define MCU_SPI0_CONFIG          \
{                                \
    .bus_name = "spi0",          \
    .spi_instance = SPI0A,       \
}
#endif
#ifdef BSP_USING_SPI1
#ifdef BSP_USING_SPI1A  //The SPI1A is conflit with UART1 TX RX P0.10 P0.11
Thomas_Fly's avatar
Thomas_Fly 已提交
39
#define MCU_SPI1_CONFIG          \
40 41
{                                \
    .bus_name = "spi1",          \
Thomas_Fly's avatar
Thomas_Fly 已提交
42
    .spi_instance = SPI1A        \
43 44
}
#else
Thomas_Fly's avatar
Thomas_Fly 已提交
45
#define MCU_SPI1_CONFIG          \
46 47
{                                \
    .bus_name = "spi1",          \
Thomas_Fly's avatar
Thomas_Fly 已提交
48
    .spi_instance = SPI1B        \
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
}
#endif
#endif

struct mcu_drv_spi_config
{
    char *bus_name;
    spi_type spi_instance;
};

struct mcu_drv_spi
{
    spi_type spi_instance;
    spi_req_t spixfer_req;
    struct rt_spi_configuration *cfg;
    struct rt_spi_bus spi_bus;
};

#endif  /*__DRV_SPI_H_*/