pins_arduino.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-09-21 Meco Man first version
  9. */
  10. #include <Arduino.h>
  11. #include "pins_arduino.h"
  12. #include <drv_gpio.h>
  13. #define DBG_TAG "RTduino.pins_arduino"
  14. #define DBG_LVL DBG_INFO
  15. #include <rtdbg.h>
  16. /*
  17. * {Arduino Pin, RT-Thread Pin [, Device Name, Channel]}
  18. * [] means optional
  19. * Digital pins must NOT give the device name and channel.
  20. * Analog pins MUST give the device name and channel(ADC, PWM or DAC).
  21. * Arduino Pin must keep in sequence.
  22. */
  23. const pin_map_t pin_map_table[]=
  24. {
  25. {D0, GET_PIN(G,9), "uart3"}, /* Serial-xx */
  26. {D1, GET_PIN(G,14), "uart3"}, /* Serial-xx */
  27. {D2, GET_PIN(F,15)},
  28. {D3, GET_PIN(E,13), "pwm1", 3}, /* PWM */
  29. {D4, GET_PIN(F,14)},
  30. {D5, GET_PIN(E,11), "pwm1", 2}, /* PWM */
  31. {D6, GET_PIN(E,9), "pwm1", 1}, /* PWM */
  32. {D7, GET_PIN(F,13)},
  33. {D8, GET_PIN(F,12)},
  34. {D9, GET_PIN(D,15), "pwm4", 4}, /* PWM */
  35. {D10, GET_PIN(D,14), "pwm4", 3}, /* PWM */
  36. {D11, GET_PIN(A,7), "pwm14", 1}, /* PWM */
  37. {D12, GET_PIN(A,6)},
  38. {D13, GET_PIN(A,5)},
  39. {D14, GET_PIN(B,9), "i2c1"}, /* I2C-SDA (Wire) */
  40. {D15, GET_PIN(B,8), "i2c1"}, /* I2C-SCL (Wire) */
  41. {D16, GET_PIN(C,13)}, /* USER KEY */
  42. {D17, GET_PIN(B,0)}, /* LED_BUILTIN, USER LED1 */
  43. {D18, GET_PIN(B,7)}, /* USER LED2 */
  44. {D19, GET_PIN(B,14)}, /* USER LED3 */
  45. {A0, GET_PIN(A,3), "adc1", 3}, /* ADC */
  46. {A1, GET_PIN(C,0), "adc1", 10}, /* ADC */
  47. {A2, GET_PIN(C,3), "adc1", 13}, /* ADC */
  48. {A3, GET_PIN(C,1), "adc1", 11}, /* ADC */
  49. {A4, GET_PIN(C,4), "adc1", 14}, /* ADC */
  50. {A5, GET_PIN(C,5), "adc1", 15}, /* ADC */
  51. {A6, RT_NULL, "adc1", RT_ADC_INTERN_CH_VREF}, /* ADC, On-Chip: internal reference voltage */
  52. {A7, RT_NULL, "adc1", RT_ADC_INTERN_CH_TEMPER}, /* ADC, On-Chip: internal temperature sensor */
  53. };
  54. #ifdef RTDUINO_USING_SPI
  55. void switchToSPI(const char *bus_name)
  56. {
  57. GPIO_InitTypeDef GPIO_InitStruct = {0};
  58. if(!rt_strcmp(bus_name, "spi1"))
  59. {
  60. __HAL_RCC_SPI1_CLK_ENABLE();
  61. __HAL_RCC_GPIOA_CLK_ENABLE();
  62. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
  63. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
  64. HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
  65. /**SPI1 GPIO Configuration
  66. PA5 ------> SPI1_SCK
  67. PA6 ------> SPI1_MISO
  68. PA7 ------> SPI1_MOSI
  69. */
  70. GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
  71. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  72. GPIO_InitStruct.Pull = GPIO_NOPULL;
  73. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  74. GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  75. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  76. LOG_W("D11, D12 and D13 will switch from PWM to SPI");
  77. }
  78. }
  79. #endif /* RTDUINO_USING_SPI */