[bsp][Infineon][psoc6-evk-062s2]Adapt to RTduino

This commit is contained in:
LZerro 2024-08-22 17:00:51 +08:00 committed by Meco Man
parent 9a84c13b2e
commit e5382cb733
10 changed files with 311 additions and 50 deletions

View File

@ -31,35 +31,51 @@ struct ifx_pwm
static struct ifx_pwm ifx_pwm_obj[] =
{
#ifdef BSP_USING_PWM0_PORT0
#ifdef BSP_USING_PWM0_CH0_PORT0
PWM0_CH0_PORT0_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT2
#ifdef BSP_USING_PWM0_CH2_PORT11_COMPL
PWM0_CH2_PORT11_COMPL_CONFIG,
#endif
#ifdef BSP_USING_PWM0_CH3_PORT11
PWM0_CH3_PORT11_CONFIG,
#endif
#ifdef BSP_USING_PWM0_CH4_PORT5_COMPL
PWM0_CH4_PORT5_COMPL_CONFIG,
#endif
#ifdef BSP_USING_PWM0_CH7_PORT2
PWM0_CH7_PORT2_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT5
#ifdef BSP_USING_PWM0_CH7_PORT5
PWM0_CH7_PORT5_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT7
#ifdef BSP_USING_PWM0_CH7_PORT5_COMPL
PWM0_CH7_PORT5_COMPL_CONFIG,
#endif
#ifdef BSP_USING_PWM0_CH7_PORT7
PWM0_CH7_PORT7_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT9
#ifdef BSP_USING_PWM0_CH7_PORT9
PWM0_CH7_PORT9_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT10
#ifdef BSP_USING_PWM0_CH7_PORT10
PWM0_CH7_PORT10_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT12
#ifdef BSP_USING_PWM0_CH7_PORT12
PWM0_CH7_PORT12_CONFIG,
#endif
#ifdef BSP_USING_PWM0_PORT13
#ifdef BSP_USING_PWM0_CH7_PORT13
PWM0_CH3_PORT13_CONFIG,
#endif
};
@ -73,26 +89,12 @@ static rt_err_t drv_pwm_enable(cyhal_pwm_t *htim, struct rt_pwm_configuration *c
{
if (!enable)
{
if (channel == 3)
{
htim->tcpwm.resource.channel_num = channel;
}
else if (channel == 7)
{
htim->tcpwm.resource.channel_num = channel;
}
htim->tcpwm.resource.channel_num = channel;
cyhal_pwm_stop(htim);
}
else
{
if (channel == 3)
{
htim->tcpwm.resource.channel_num = channel;
}
else if (channel == 7)
{
htim->tcpwm.resource.channel_num = channel;
}
htim->tcpwm.resource.channel_num = channel;
cyhal_pwm_start(htim);
}
}
@ -217,7 +219,7 @@ __exit:
INIT_BOARD_EXPORT(rt_hw_pwm_init);
#define PWM_DEV_NAME "pwm0"
#define PWM_DEV_CHANNEL 7
#define PWM_DEV_CHANNEL 4
struct rt_device_pwm *pwm_dev;

View File

@ -29,7 +29,34 @@ extern "C"
.channel = 0, \
.gpio = GET_PIN(0, 0), \
}
#endif /* PWM0_CH7_PORT2_CONFIG */
#endif /* PWM0_CH0_PORT2_CONFIG */
#ifndef PWM0_CH2_PORT11_COMPL_CONFIG
#define PWM0_CH2_PORT11_COMPL_CONFIG \
{ \
.name = "pwm0", \
.channel = 2, \
.gpio = GET_PIN(11, 3), \
}
#endif /*PWM0_CH2_PORT11_COMPL_CONFIG*/
#ifndef PWM0_CH3_PORT11_CONFIG
#define PWM0_CH3_PORT11_CONFIG \
{ \
.name = "pwm0", \
.channel = 3, \
.gpio = GET_PIN(11, 4), \
}
#endif /*PWM0_CH3_PORT11_CONFIG*/
#ifndef PWM0_CH4_PORT5_COMPL_CONFIG
#define PWM0_CH4_PORT5_COMPL_CONFIG \
{ \
.name = "pwm0", \
.channel = 4, \
.gpio = GET_PIN(5, 1), \
}
#endif /*PWM0_CH4_PORT5_COMPL_CONFIG*/
#ifndef PWM0_CH7_PORT2_CONFIG
#define PWM0_CH7_PORT2_CONFIG \
@ -49,6 +76,15 @@ extern "C"
}
#endif /* PWM0_CH7_PORT5_CONFIG */
#ifndef PWM0_CH7_PORT5_COMPL_CONFIG
#define PWM0_CH7_PORT5_COMPL_CONFIG \
{ \
.name = "pwm0", \
.channel = 7, \
.gpio = GET_PIN(5, 7), \
}
#endif /*PWM0_CH7_PORT5_COMPL_CONFIG*/
#ifndef PWM0_CH7_PORT7_CONFIG
#define PWM0_CH7_PORT7_CONFIG \
{ \

View File

@ -1,16 +1,18 @@
import rtconfig
from building import *
import os
cwd = GetCurrentDir()
path = [cwd]
src = Glob('*.c')
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = path)
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
src += ['arduino_main.cpp']
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')
Return('group')

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-08-16 LZerro first version
*/
#include <Arduino.h>
void setup(void)
{
/* put your setup code here, to run once: */
Serial.begin();
}
void loop(void)
{
/* put your main code here, to run repeatedly: */
Serial.println("Hello Arduino!");
delay(800);
}

View File

@ -0,0 +1,43 @@
# board_default 开发板的Arduino生态兼容说明
## 1 RTduino - RT-Thread的Arduino生态兼容层
board_default 开发板已经完整适配了[RTduino软件包](https://github.com/RTduino/RTduino)即RT-Thread的Arduino生态兼容层。用户可以按照Arduino的编程习惯来操作该BSP并且可以使用大量Arduino社区丰富的库是对RT-Thread生态的极大增强。更多信息请参见[RTduino软件包说明文档](https://github.com/RTduino/RTduino)。
### 1.1 如何开启针对本BSP的Arduino生态兼容层
Env 工具下敲入 menuconfig 命令,或者 RT-Thread Studio IDE 下选择 RT-Thread Settings
```Kconfig
Hardware Drivers Config --->
Onboard Peripheral Drivers --->
[*] Compatible with Arduino Ecosystem (RTduino)
```
## 2 Arduino引脚排布
更多引脚布局相关信息参见 [pins_arduino.c](pins_arduino.c) 和 [pins_arduino.h](pins_arduino.h)。
| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 |
| ------------------- | --------- | ---- | ------------------------------------------------------------------------- |
| 0 (D0) | BSP_IO_PORT_06_PIN_04 | 否 | Serial-RX,默认被RT-Thread的UART设备框架uart6接管 |
| 1 (D1) | BSP_IO_PORT_06_PIN_05 | 否 | Serial-TX,默认被RT-Thread的UART设备框架uart6接管 |
| 2 (D2) | BSP_IO_PORT_05_PIN_00 | 否 | |
| 3 (D3) | BSP_IO_PORT_05_PIN_01 | 否 | PWM0-CH0,默认被RT-Thread的PWM设备框架pwm0接管 |
| 4 (D4) | BSP_IO_PORT_11_PIN_02 | 否 | |
| 5 (D5) | BSP_IO_PORT_11_PIN_03 | 否 | PWM0-CH0,默认被RT-Thread的PWM设备框架pwm0接管 |
| 6 (D6) | BSP_IO_PORT_11_PIN_04 | 否 | PWM0-CH0,默认被RT-Thread的PWM设备框架pwm0接管 |
| 7 (D7) | BSP_IO_PORT_11_PIN_05 | 否 | |
| 8 (D8) | BSP_IO_PORT_11_PIN_06 | 否 | |
| 9 (D9) | BSP_IO_PORT_05_PIN_07 | 否 | PWM0-CH0,默认被RT-Thread的PWM设备框架pwm0接管 |
| 10 (D10) | BSP_IO_PORT_00_PIN_05 | 否 | |
| 11 (D11) | BSP_IO_PORT_00_PIN_02 | 否 | SPI0-MOSI,默认被RT-Thread的SPI设备框架spi0接管 |
| 12 (D12) | BSP_IO_PORT_00_PIN_03 | 否 | SPI0-MISO,默认被RT-Thread的SPI设备框架spi0接管 |
| 13 (D13) | BSP_IO_PORT_00_PIN_04 | 否 | SPI0-SCK,默认被RT-Thread的SPI设备框架spi0接管 |
| 14 (D14) | BSP_IO_PORT_08_PIN_01 | 否 | I2C0-SDA,默认被RT-Thread的I2C设备框架i2c0接管 |
| 15 (D15) | BSP_IO_PORT_08_PIN_00 | 否 | I2C0-SCL,默认被RT-Thread的I2C设备框架i2c0接管 |
> 注意:
>
> 1. xxxxxxxxx
> 2. xxxxxxxxx

View File

@ -0,0 +1,11 @@
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
inc = [cwd]
print(cwd)
group = DefineGroup('RTduino', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc)
Return('group')

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-08-16 LZerro first version
*/
#include <Arduino.h>
#include "drv_gpio.h"
#include "pins_arduino.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[]=
{
{D00, GET_PIN(6, 4), "uart6"}, /* Serial6-RX */
{D01, GET_PIN(6, 5), "uart6"}, /* Serial6-TX */
{D2, GET_PIN(5, 0)},
{D3, GET_PIN(5, 1), "pwm0", 4}, /* PWM */
{D4, GET_PIN(11, 2)},
{D5, GET_PIN(11, 3), "pwm0", 2}, /* PWM */
{D6, GET_PIN(11, 4), "pwm0", 3},
{D7, GET_PIN(11, 5)},
{D8, GET_PIN(5, 6)},
{D9, GET_PIN(5, 7), "pwm0", 7}, /* PWM */
{D10, GET_PIN(0, 5)}, /* SPI0_CS*/
{D11, GET_PIN(0, 2), "spi0"}, /* SPI0_MOSI */
{D12, GET_PIN(0, 3), "spi0"}, /* SPI0_MISO */
{D13, GET_PIN(0, 4), "spi0"}, /* SPI_SCK */
{D14, GET_PIN(8, 1), "i2c4"}, /* I2C-SDA (Soft Wire) */
{D15, GET_PIN(8, 0), "i2c4"}, /* I2C-SCL (Soft Wire) */
};

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-08-16 LZerro first version
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
/* pins alias. Must keep in sequence */
#define D00 (0)
#define D01 (1)
#define D2 (2)
#define D3 (3)
#define D4 (4)
#define D5 (5)
#define D6 (6)
#define D7 (7)
#define D8 (8)
#define D9 (9)
#define D10 (10)
#define D11 (11)
#define D12 (12)
#define D13 (13)
#define D14 (14)
#define D15 (15)
#define RTDUINO_PIN_MAX_LIMIT D15 /* pin number max limit check */
#define F_CPU 150000000L /* CPU:150MHz */
// #define LED_BUILTIN D0 /* Default Built-in LED */
/* i2c0 : P08.01-SDA P08.00-SCL */
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
/* spi0 : P0.04-SCK P00.03-MISO P00.02-MOSI */
#define SS D10 /* Chip select pin of default spi */
#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi0"
#endif /* Pins_Arduino_h */

View File

@ -15,6 +15,31 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_UART6
default y
config BSP_USING_ARDUINO
bool "Compatible with Arduino Ecosystem (RTduino)"
select PKG_USING_RTDUINO
select BSP_USING_STLINK_TO_USART
select BSP_USING_UART6
select BSP_USING_GPIO
select BSP_USING_PWM
select BSP_USING_PWM0
select BSP_USING_PWM0_CH2
select BSP_USING_PWM0_CH3
select BSP_USING_PWM0_CH4
select BSP_USING_PWM0_CH7
select BSP_USING_PWM0_CH2_PORT11_COMPL
select BSP_USING_PWM0_CH3_PORT11
select BSP_USING_PWM0_CH4_PORT5_COMPL
select BSP_USING_PWM0_CH7_PORT5_COMPL
select BSP_USING_HW_I2C
select BSP_USING_HW_I2C4
select BSP_USING_SPI
select BSP_USING_SPI0
imply RTDUINO_USING_SERVO
imply RTDUINO_USING_WIRE
imply RTDUINO_USING_SPI
default n
endmenu
menu "On-chip Peripheral Drivers"
@ -65,41 +90,74 @@ menu "On-chip Peripheral Drivers"
bool "Enable PWM0 channel0"
default n
if BSP_USING_PWM0_CH0
config BSP_USING_PWM0_PORT0
bool "Enable PWM0-PORT0 output pwm"
config BSP_USING_PWM0_CH0_PORT0
bool "Enable PWM0-CH0-PORT0 output pwm"
default n
endif
menuconfig BSP_USING_PWM0_CH2
bool "Enable PWM0 channel2"
default n
if BSP_USING_PWM0_CH2
config BSP_USING_PWM0_CH2_PORT11_COMPL
bool "Enable PWM0-CH2-PORT11-COMPL output pwm (Arduino PWM)"
default n
endif
menuconfig BSP_USING_PWM0_CH3
bool "Enable PWM0 channel3"
default n
if BSP_USING_PWM0_CH3
config BSP_USING_PWM0_CH3_PORT11
bool "Enable PWM0-CH3-PORT11 output pwm (Arduino PWM)"
default n
endif
menuconfig BSP_USING_PWM0_CH4
bool "Enable PWM0 channel4"
default n
if BSP_USING_PWM0_CH4
config BSP_USING_PWM0_CH4_PORT5_COMPL
bool "Enable PWM0-CH4-PORT5-CPMPL output pwm (Arduino PWM)"
default n
endif
menuconfig BSP_USING_PWM0_CH7
bool "Enable PWM0 channel7"
default n
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_PORT2
bool "Enable PWM0-PORT2 output pwm"
config BSP_USING_PWM0_CH7_PORT2
bool "Enable PWM0-CH7-PORT2 output pwm"
default n
endif
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_PORT5
bool "Enable PWM0-PORT5 output pwm"
config BSP_USING_PWM0_CH7_PORT5
bool "Enable PWM0-CH7-PORT5 output pwm"
default n
endif
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_PORT7
bool "Enable PWM0-PORT7 output pwm"
config BSP_USING_PWM0_CH7_PORT5_COMPL
bool "Enable PWM0-CH7-PORT5-COMPL output pwm (Arduino PWM)"
default n
endif
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_PORT9
bool "Enable PWM0-PORT9 output pwm"
config BSP_USING_PWM0_CH7_PORT7
bool "Enable PWM0-CH7-PORT7 output pwm"
default n
endif
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_PORT10
bool "Enable PWM0-PORT10 output pwm"
config BSP_USING_PWM0_CH7_PORT9
bool "Enable PWM0-CH7-PORT9 output pwm"
default n
endif
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_PORT12
bool "Enable PWM0-PORT12 output pwm"
config BSP_USING_PWM0_CH7_PORT10
bool "Enable PWM0-CH7-PORT10 output pwm"
default n
endif
if BSP_USING_PWM0_CH7
config BSP_USING_PWM0_CH7_PORT12
bool "Enable PWM0-CH7-PORT12 output pwm"
default n
endif
endif
@ -368,7 +426,7 @@ menu "Board extended module Drivers"
select BSP_USING_PWM
select BSP_USING_PWM0
select BSP_USING_PWM0_CH0
select BSP_USING_PWM0_PORT0
select BSP_USING_PWM0_CH0_PORT0
default n
endif
@ -429,4 +487,4 @@ menu "Board extended module Drivers"
default n
endmenu
endmenu
endmenu

View File

@ -300,7 +300,7 @@ void init_cycfg_pins(void)
Cy_GPIO_Pin_Init(CYBSP_SWDCK_PORT, CYBSP_SWDCK_PIN, &CYBSP_SWDCK_config);
Cy_GPIO_Pin_Init(CYBSP_CINA_PORT, CYBSP_CINA_PIN, &CYBSP_CINA_config);
Cy_GPIO_Pin_Init(CYBSP_CINB_PORT, CYBSP_CINB_PIN, &CYBSP_CINB_config);
Cy_GPIO_Pin_Init(CYBSP_CSD_BTN0_PORT, CYBSP_CSD_BTN0_PIN, &CYBSP_CSD_BTN0_config);
//Cy_GPIO_Pin_Init(CYBSP_CSD_BTN0_PORT, CYBSP_CSD_BTN0_PIN, &CYBSP_CSD_BTN0_config);
}
void reserve_cycfg_pins(void)
@ -312,7 +312,7 @@ void reserve_cycfg_pins(void)
cyhal_hwmgr_reserve(&CYBSP_CINB_obj);
cyhal_hwmgr_reserve(&CYBSP_LED_RGB_BLUE_obj);
cyhal_hwmgr_reserve(&CYBSP_CMOD_obj);
cyhal_hwmgr_reserve(&CYBSP_CSD_BTN0_obj);
//cyhal_hwmgr_reserve(&CYBSP_CSD_BTN0_obj);
cyhal_hwmgr_reserve(&CYBSP_A8_obj);
cyhal_hwmgr_reserve(&CYBSP_A9_obj);
cyhal_hwmgr_reserve(&CYBSP_A10_obj);