mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-03-25 01:43:49 +08:00
534
bsp/wch/risc-v/Libraries/ch32_drivers/drv_spi.c
Normal file
534
bsp/wch/risc-v/Libraries/ch32_drivers/drv_spi.c
Normal file
File diff suppressed because it is too large
Load Diff
87
bsp/wch/risc-v/Libraries/ch32_drivers/drv_spi.h
Normal file
87
bsp/wch/risc-v/Libraries/ch32_drivers/drv_spi.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-11-26 zhaohaisheng copy from sch and do some change
|
||||
*/
|
||||
|
||||
#ifndef __DRV_SPI_H__
|
||||
#define __DRV_SPI_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rthw.h>
|
||||
|
||||
#include "ch32v30x_rcc.h"
|
||||
#include "ch32v30x_gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* ifdef __cplusplus */
|
||||
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* ifdef __cplusplus */
|
||||
|
||||
struct ch32_hw_spi_cs
|
||||
{
|
||||
GPIO_TypeDef* GPIOx;
|
||||
uint16_t GPIO_Pin;
|
||||
};
|
||||
|
||||
struct ch32_spi_config
|
||||
{
|
||||
SPI_TypeDef *Instance;
|
||||
char *bus_name;
|
||||
IRQn_Type irq_type;
|
||||
|
||||
};
|
||||
|
||||
struct ch32_spi_device
|
||||
{
|
||||
rt_uint32_t pin;
|
||||
char *bus_name;
|
||||
char *device_name;
|
||||
};
|
||||
|
||||
typedef struct __SPI_HandleTypeDef
|
||||
{
|
||||
|
||||
SPI_TypeDef *Instance; /*!< SPI registers base address */
|
||||
|
||||
SPI_InitTypeDef Init; /*!< SPI communication parameters */
|
||||
|
||||
uint8_t *pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */
|
||||
|
||||
uint16_t TxXferSize; /*!< SPI Tx Transfer size */
|
||||
|
||||
volatile uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */
|
||||
|
||||
uint8_t *pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */
|
||||
|
||||
uint16_t RxXferSize; /*!< SPI Rx Transfer size */
|
||||
|
||||
volatile uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */
|
||||
|
||||
|
||||
} SPI_HandleTypeDef;
|
||||
|
||||
/* ch32 spi dirver class */
|
||||
struct ch32_spi
|
||||
{
|
||||
SPI_HandleTypeDef handle;
|
||||
|
||||
struct ch32_spi_config *config;
|
||||
struct rt_spi_configuration *cfg;
|
||||
struct rt_spi_bus spi_bus;
|
||||
|
||||
|
||||
};
|
||||
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);
|
||||
|
||||
#endif /*__DRV_SPI_H__ */
|
||||
@@ -133,7 +133,6 @@ menu "On-chip Peripheral Drivers"
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI"
|
||||
select RT_USING_SPI_BITOPS
|
||||
select RT_USING_SPI
|
||||
|
||||
if BSP_USING_SPI
|
||||
@@ -154,7 +153,13 @@ menu "On-chip Peripheral Drivers"
|
||||
bool "Enable SPI Flash"
|
||||
default n
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable SOFT SPI"
|
||||
select RT_USING_SPI_BITOPS
|
||||
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable SSPI1 Bus (User SPI)"
|
||||
default n
|
||||
@@ -173,7 +178,7 @@ menu "On-chip Peripheral Drivers"
|
||||
range 1 79
|
||||
default 23
|
||||
endif
|
||||
|
||||
|
||||
config BSP_USING_SOFT_SPI2
|
||||
bool "Enable SSPI2 Bus (soft SPI)"
|
||||
default n
|
||||
|
||||
Reference in New Issue
Block a user