drv_spi.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. struct ch32_hw_spi_cs
  21. {
  22. GPIO_TypeDef* GPIOx;
  23. rt_uint16_t GPIO_Pin;
  24. };
  25. struct ch32_spi_config
  26. {
  27. SPI_TypeDef *Instance;
  28. char *bus_name;
  29. IRQn_Type irq_type;
  30. };
  31. struct ch32_spi_device
  32. {
  33. rt_uint32_t pin;
  34. char *bus_name;
  35. char *device_name;
  36. };
  37. typedef struct __SPI_HandleTypeDef
  38. {
  39. SPI_TypeDef *Instance; /*!< SPI registers base address */
  40. SPI_InitTypeDef Init; /*!< SPI communication parameters */
  41. rt_uint8_t *pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */
  42. rt_uint16_t TxXferSize; /*!< SPI Tx Transfer size */
  43. volatile rt_uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */
  44. rt_uint8_t *pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */
  45. rt_uint16_t RxXferSize; /*!< SPI Rx Transfer size */
  46. volatile rt_uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */
  47. } SPI_HandleTypeDef;
  48. /* ch32 spi dirver class */
  49. struct ch32_spi
  50. {
  51. SPI_HandleTypeDef handle;
  52. struct ch32_spi_config *config;
  53. struct rt_spi_configuration *cfg;
  54. struct rt_spi_bus spi_bus;
  55. };
  56. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, GPIO_TypeDef* cs_gpiox, rt_uint16_t cs_gpio_pin);
  57. #ifdef __cplusplus
  58. }
  59. #endif /* ifdef __cplusplus */
  60. #endif /*__DRV_SPI_H__ */