drv_spi.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file drv_spi.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __DRV_SPI_H__
  35. #define __DRV_SPI_H__
  36. #include <rthw.h>
  37. #include <rtthread.h>
  38. #include <board.h>
  39. struct n32_spi_cs
  40. {
  41. GPIO_Module* GPIOx;
  42. uint32_t GPIO_Pin;
  43. };
  44. #ifdef BSP_USING_SPI1
  45. #define SPI1_SCK_PIN GPIO_PIN_5 /* PA.05 */
  46. #define SPI1_SCK_GPIO_PORT GPIOA /* GPIOA */
  47. #define SPI1_SCK_GPIO_CLK RCC_APB2_PERIPH_GPIOA
  48. #define SPI1_MISO_PIN GPIO_PIN_6 /* PA.06 */
  49. #define SPI1_MISO_GPIO_PORT GPIOA /* GPIOA */
  50. #define SPI1_MISO_GPIO_CLK RCC_APB2_PERIPH_GPIOA
  51. #define SPI1_MOSI_PIN GPIO_PIN_7 /* PA.07 */
  52. #define SPI1_MOSI_GPIO_PORT GPIOA /* GPIOA */
  53. #define SPI1_MOSI_GPIO_CLK RCC_APB2_PERIPH_GPIOA
  54. #endif /* RT_USING_SPI1 */
  55. #ifdef BSP_USING_SPI2
  56. #define SPI2_SCK_PIN GPIO_PIN_13 /* PB.13 */
  57. #define SPI2_SCK_GPIO_PORT GPIOB /* GPIOB */
  58. #define SPI2_SCK_GPIO_CLK RCC_APB2_PERIPH_GPIOB
  59. #define SPI2_MISO_PIN GPIO_PIN_14 /* PB.14 */
  60. #define SPI2_MISO_GPIO_PORT GPIOB /* GPIOB */
  61. #define SPI2_MISO_GPIO_CLK RCC_APB2_PERIPH_GPIOB
  62. #define SPI2_MOSI_PIN GPIO_PIN_15 /* PB.15 */
  63. #define SPI2_MOSI_GPIO_PORT GPIOB /* GPIOB */
  64. #define SPI2_MOSI_GPIO_CLK RCC_APB2_PERIPH_GPIOB
  65. #endif /* RT_USING_SPI2 */
  66. #ifdef BSP_USING_SPI3
  67. #define SPI3_SCK_PIN GPIO_PIN_3 /* PB.03 */
  68. #define SPI3_SCK_GPIO_PORT GPIOB /* GPIOB */
  69. #define SPI3_SCK_GPIO_CLK RCC_APB2_PERIPH_GPIOB
  70. #define SPI3_MISO_PIN GPIO_PIN_4 /* PB.04 */
  71. #define SPI3_MISO_GPIO_PORT GPIOB /* GPIOB */
  72. #define SPI3_MISO_GPIO_CLK RCC_APB2_PERIPH_GPIOB
  73. #define SPI3_MOSI_PIN GPIO_PIN_5 /* PB.05 */
  74. #define SPI3_MOSI_GPIO_PORT GPIOB /* GPIOB */
  75. #define SPI3_MOSI_GPIO_CLK RCC_APB2_PERIPH_GPIOB
  76. #endif /* RT_USING_SPI3 */
  77. int rt_hw_spi_init(void);
  78. #endif /* __DRV_SPI_H__ */