drv_spi.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**************************************************************************//**
  2. *
  3. * @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-2-7 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #ifndef __DRV_SPI_H__
  13. #define __DRV_SPI_H__
  14. #include <rtconfig.h>
  15. #include <rtdevice.h>
  16. #include "NuMicro.h"
  17. #include <nu_bitutil.h>
  18. #if defined(BSP_USING_SPI_PDMA)
  19. #include <drv_pdma.h>
  20. #endif
  21. struct nu_spi
  22. {
  23. struct rt_spi_bus dev;
  24. char *name;
  25. SPI_T *spi_base;
  26. uint32_t dummy;
  27. #if defined(BSP_USING_SPI_PDMA)
  28. int16_t pdma_perp_tx;
  29. int8_t pdma_chanid_tx;
  30. int16_t pdma_perp_rx;
  31. int8_t pdma_chanid_rx;
  32. rt_sem_t m_psSemBus;
  33. #endif
  34. struct rt_qspi_configuration configuration;
  35. };
  36. typedef struct nu_spi *nu_spi_t;
  37. void nu_spi_drain_rxfifo(SPI_T *spi_base);
  38. void nu_spi_transfer(struct nu_spi *spi_bus, uint8_t *tx, uint8_t *rx, int length, uint8_t bytes_per_word);
  39. #if defined(BSP_USING_SPI_PDMA)
  40. rt_err_t nu_hw_spi_pdma_allocate(struct nu_spi *spi_bus);
  41. #endif
  42. #endif // __DRV_SPI_H___