drv_spi.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-11-26 zhaohaisheng copy from sch and do some change
  9. */
  10. #ifndef __DRV_SPI_H__
  11. #define __DRV_SPI_H__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #include <rthw.h>
  15. #include "ch32v30x_rcc.h"
  16. #include "ch32v30x_gpio.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif /* ifdef __cplusplus */
  20. 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);
  21. #ifdef __cplusplus
  22. }
  23. #endif /* ifdef __cplusplus */
  24. struct ch32_hw_spi_cs
  25. {
  26. GPIO_TypeDef* GPIOx;
  27. uint16_t GPIO_Pin;
  28. };
  29. struct ch32_spi_config
  30. {
  31. SPI_TypeDef *Instance;
  32. char *bus_name;
  33. IRQn_Type irq_type;
  34. };
  35. struct ch32_spi_device
  36. {
  37. rt_uint32_t pin;
  38. char *bus_name;
  39. char *device_name;
  40. };
  41. typedef struct __SPI_HandleTypeDef
  42. {
  43. SPI_TypeDef *Instance; /*!< SPI registers base address */
  44. SPI_InitTypeDef Init; /*!< SPI communication parameters */
  45. uint8_t *pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */
  46. uint16_t TxXferSize; /*!< SPI Tx Transfer size */
  47. volatile uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */
  48. uint8_t *pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */
  49. uint16_t RxXferSize; /*!< SPI Rx Transfer size */
  50. volatile uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */
  51. } SPI_HandleTypeDef;
  52. /* ch32 spi dirver class */
  53. struct ch32_spi
  54. {
  55. SPI_HandleTypeDef handle;
  56. struct ch32_spi_config *config;
  57. struct rt_spi_configuration *cfg;
  58. struct rt_spi_bus spi_bus;
  59. };
  60. 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);
  61. #endif /*__DRV_SPI_H__ */