drv_spi.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @file drv_spi.h
  3. * @author 100ask development team
  4. * @brief
  5. * @version 0.1
  6. * @date 2022-06-16
  7. *
  8. * @copyright Copyright (c) 2022 Chongqing 100ASK Technology Co., LTD
  9. *
  10. */
  11. #ifndef __DRV_SPI_H_
  12. #define __DRV_SPI_H_
  13. #include <rtthread.h>
  14. #include "rtdevice.h"
  15. #include <rthw.h>
  16. #include "drv_common.h"
  17. #include "drv_dma.h"
  18. 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);
  19. struct mm32_hw_spi_cs
  20. {
  21. GPIO_Type* GPIOx;
  22. uint16_t GPIO_Pin;
  23. };
  24. struct mm32_spi_config
  25. {
  26. SPI_Type *Instance;
  27. char *bus_name;
  28. struct dma_config *dma_rx, *dma_tx;
  29. };
  30. struct stm32_spi_device
  31. {
  32. rt_uint32_t pin;
  33. char *bus_name;
  34. char *device_name;
  35. };
  36. #define SPI_USING_RX_DMA_FLAG (1<<0)
  37. #define SPI_USING_TX_DMA_FLAG (1<<1)
  38. /* stm32 spi dirver class */
  39. struct mm32_spi
  40. {
  41. SPI_Master_Init_Type handle;
  42. struct mm32_spi_config *config;
  43. struct rt_spi_configuration *cfg;
  44. struct
  45. {
  46. rt_uint16_t rx_buf_len;
  47. rt_uint8_t *rx_buf;
  48. DMA_Channel_Init_Type handle_rx;
  49. rt_uint16_t tx_buf_len;
  50. rt_uint8_t *tx_buf;
  51. DMA_Channel_Init_Type handle_tx;
  52. } dma;
  53. rt_uint8_t spi_dma_flag;
  54. struct rt_spi_bus spi_bus;
  55. };
  56. #endif /* __DRV_SPI_H_ */