pins_arduino.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-01-25 ShichengChu first version
  9. */
  10. #include <Arduino.h>
  11. #include <board.h>
  12. #include "pins_arduino.h"
  13. #include <pico/stdlib.h>
  14. #include <hardware/spi.h>
  15. #include <hardware/gpio.h>
  16. #include <pico/binary_info.h>
  17. #define DBG_TAG "RTduino.pins_arduino"
  18. #define DBG_LVL DBG_INFO
  19. #include <rtdbg.h>
  20. /*
  21. * {Arduino Pin, RT-Thread Pin [, Device Name, Channel]}
  22. * [] means optional
  23. * Digital pins must NOT give the device name and channel.
  24. * Analog pins MUST give the device name and channel(ADC, PWM or DAC).
  25. * Arduino Pin must keep in sequence.
  26. */
  27. const pin_map_t pin_map_table[]=
  28. {
  29. {D0, 0, "uart0"}, /* Serial-TX */
  30. {D1, 1, "uart0"}, /* Serial-RX */
  31. {D2, 2},
  32. {D3, 3},
  33. {D4, 4, "i2c0"}, /* I2C-SDA (Wire) */
  34. {D5, 5, "i2c0"}, /* I2C-SCL (Wire) */
  35. {D6, 6},
  36. {D7, 7},
  37. {D8, 8, "uart1"}, /* Serial2-TX */
  38. {D9, 9, "uart1"}, /* Serial2-RX */
  39. {D10, 10, "pwm5", 0}, /* PWM */
  40. {D11, 11, "pwm5", 1}, /* PWM */
  41. {D12, 12, "pwm6", 0}, /* PWM */
  42. {D13, 13, "pwm6", 1}, /* PWM */
  43. {D14, 14, "pwm7", 0}, /* PWM */
  44. {D15, 15, "pwm7", 1}, /* PWM */
  45. {D16, 16, "pwm0", 0}, /* PWM */
  46. {D17, 17, "pwm0", 1}, /* PWM */
  47. {D18, 18, "pwm1", 0}, /* PWM */
  48. {D19, 19, "pwm1", 1}, /* PWM */
  49. {D20, 20, "pwm2", 0}, /* PWM */
  50. {D21, 21, "pwm2", 1}, /* PWM */
  51. {D22, 22, "pwm3", 0}, /* PWM */
  52. {D23, 23, "pwm3", 1}, /* PWM */
  53. {D24, 24, "pwm4", 0}, /* PWM */
  54. {D25, 25, "pwm4", 1}, /* LED_BUILTIN */
  55. {A0, 26, "adc0", 0}, /* ADC */
  56. {A1, 27, "adc1", 1}, /* ADC */
  57. {A2, 28, "adc2", 2}, /* ADC */
  58. };
  59. #ifdef RTDUINO_USING_SPI
  60. void switchToSPI(const char *bus_name)
  61. {
  62. if(!rt_strcmp(bus_name, "spi0"))
  63. {
  64. /**SPI0 GPIO Configuration
  65. 18u ------> SPI0_SCK
  66. 16u ------> SPI0_MISO
  67. 19u ------> SPI0_MOSI
  68. 17u ------> SPI0_CS
  69. */
  70. gpio_set_function(BSP_SPI0_SCK_PIN, GPIO_FUNC_SPI);
  71. gpio_set_function(BSP_SPI0_MISO_PIN, GPIO_FUNC_SPI);
  72. gpio_set_function(BSP_SPI0_MOSI_PIN, GPIO_FUNC_SPI);
  73. gpio_init(BSP_SPI0_CS_PIN);
  74. // Make the SPI pins available to picotool
  75. bi_decl(bi_3pins_with_func(BSP_SPI0_MISO_PIN, BSP_SPI0_MOSI_PIN, BSP_SPI0_SCK_PIN, GPIO_FUNC_SPI));
  76. // Make the CS pin available to picotool
  77. bi_decl(bi_1pin_with_name(BSP_SPI0_CS_PIN, "SPI CS"));
  78. LOG_I("D16, D17, D18 and D19 will switch from PWM to SPI");
  79. }
  80. }
  81. #endif /* RTDUINO_USING_SPI */