drv_spi.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. E_SYS_IPRST rstidx;
  27. E_SYS_IPCLK clkidx;
  28. uint32_t dummy;
  29. #if defined(BSP_USING_SPI_PDMA)
  30. int16_t pdma_perp_tx;
  31. int8_t pdma_chanid_tx;
  32. int16_t pdma_perp_rx;
  33. int8_t pdma_chanid_rx;
  34. rt_sem_t m_psSemBus;
  35. #endif
  36. struct rt_qspi_configuration configuration;
  37. };
  38. typedef struct nu_spi *nu_spi_t;
  39. void nu_spi_drain_rxfifo(SPI_T *spi_base);
  40. void nu_spi_transfer(struct nu_spi *spi_bus, uint8_t *tx, uint8_t *rx, int length, uint8_t bytes_per_word);
  41. #if defined(BSP_USING_SPI_PDMA)
  42. rt_err_t nu_hw_spi_pdma_allocate(struct nu_spi *spi_bus);
  43. #endif
  44. #endif // __DRV_SPI_H___