rt-thread-official/bsp/stm32/stm32f401-st-nucleo/applications/arduino_pinout/pins_arduino.c

84 lines
2.8 KiB
C

/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-09-18 liYony first version
*/
#include <Arduino.h>
#include "pins_arduino.h"
#define DBG_TAG "RTduino.pins_arduino"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
/*
* {Arduino Pin, RT-Thread Pin [, Device Name, Channel]}
* [] means optional
* Digital pins must NOT give the device name and channel.
* Analog pins MUST give the device name and channel(ADC, PWM or DAC).
* Arduino Pin must keep in sequence.
*/
const pin_map_t pin_map_table[]=
{
{D0, GET_PIN(A,3), "uart2"}, /* Serial-Rx */
{D1, GET_PIN(A,2), "uart2"}, /* Serial-Tx */
{D2, GET_PIN(A,10)},
{D3, GET_PIN(B,3), "pwm2", 2}, /* PWM */
{D4, GET_PIN(B,5)},
{D5, GET_PIN(B,4), "pwm3", 1}, /* PWM */
{D6, GET_PIN(B,10), "pwm2", 3}, /* PWM */
{D7, GET_PIN(A,8)},
{D8, GET_PIN(A,9)},
{D9, GET_PIN(C,7), "pwm3", 2}, /* PWM */
{D10, GET_PIN(B,6), "pwm4", 1}, /* PWM */
{D11, GET_PIN(A,7), "pwm1", -1}, /* PWM */
{D12, GET_PIN(A,6)},
{D13, GET_PIN(A,5)}, /* LED_BUILTIN */
{D14, GET_PIN(B,9), "i2c1"}, /* I2C-SDA (Wire) */
{D15, GET_PIN(B,8), "i2c1"}, /* I2C-SCL (Wire) */
{D16, GET_PIN(C,13)}, /* USER KEY */
{A0, GET_PIN(A,0), "adc1", 0}, /* ADC */
{A1, GET_PIN(A,1), "adc1", 1}, /* ADC */
{A2, GET_PIN(A,4), "adc1", 4}, /* ADC */
{A3, GET_PIN(B,0), "adc1", 8}, /* ADC */
{A4, GET_PIN(C,1), "adc1", 11}, /* ADC */
{A5, GET_PIN(C,0), "adc1", 10}, /* ADC */
{A6, RT_NULL, "adc1", RT_ADC_INTERN_CH_VREF}, /* ADC, On-Chip: internal reference voltage */
{A7, RT_NULL, "adc1", RT_ADC_INTERN_CH_TEMPER}, /* ADC, On-Chip: internal temperature sensor */
};
#ifdef RTDUINO_USING_SPI
void switchToSPI(const char *bus_name)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(!rt_strcmp(bus_name, "spi1"))
{
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6);
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7);
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
LOG_W("D11, D12 and D13 will switch from PWM to SPI");
}
}
#endif /* RTDUINO_USING_SPI */