drv_spi.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-5 SummerGift first version
  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 <drv_common.h>
  16. #include "drv_dma.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  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
  24. struct stm32_hw_spi_cs
  25. {
  26. GPIO_TypeDef* GPIOx;
  27. uint16_t GPIO_Pin;
  28. };
  29. struct stm32_spi_config
  30. {
  31. SPI_TypeDef *Instance;
  32. char *bus_name;
  33. struct dma_config *dma_rx, *dma_tx;
  34. };
  35. struct stm32_spi_device
  36. {
  37. rt_uint32_t pin;
  38. char *bus_name;
  39. char *device_name;
  40. };
  41. #define SPI_USING_RX_DMA_FLAG (1<<0)
  42. #define SPI_USING_TX_DMA_FLAG (1<<1)
  43. /* stm32 spi dirver class */
  44. struct stm32_spi
  45. {
  46. SPI_HandleTypeDef handle;
  47. struct stm32_spi_config *config;
  48. struct rt_spi_configuration *cfg;
  49. struct
  50. {
  51. DMA_HandleTypeDef handle_rx;
  52. DMA_HandleTypeDef handle_tx;
  53. } dma;
  54. rt_uint8_t spi_dma_flag;
  55. struct rt_spi_bus spi_bus;
  56. };
  57. #endif /*__DRV_SPI_H__ */