未验证 提交 59f10fd7 编写于 作者: H hg0720 提交者: GitHub

[bsp][ch32v307]适配RT-duino框架 (#6669)

为ch32v307适配rt-duino,支持pwm、gpio、uart、iic,暂不支持 spi。
已在ch32v307评估板测试。
测试内容包括串口打印、呼吸灯、AHT10温湿度读取等。
上级 b1763e69
......@@ -2,8 +2,11 @@ from building import *
import os
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
src = ['main.c']
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
src += ['arduino_main.cpp']
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
......
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-11-29 hg0720 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);
}
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
inc = [cwd]
group = DefineGroup('RTduino', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc)
Return('group')
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-11-29 hg0720 first version
*/
#include <Arduino.h>
#include <board.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[]=
{
{D0, GET_PIN(A,10), "uart1"}, /* Serial-Rx */
{D1, GET_PIN(A,9), "uart1"}, /* Serial-Tx */
{D2, GET_PIN(A,8), "pwm1", 1}, /* PWM */
{D3, GET_PIN(A,7), "pwm3", 2}, /* PWM */
{D4, GET_PIN(A,6), "pwm3", 1}, /* PWM */
{D5, GET_PIN(B,5)}, /* LED_BUILTIN */
{D6, GET_PIN(B,8), "pwm4", 3}, /* PWM */
{D7, GET_PIN(B,9), "pwm4", 4}, /* PWM */
{D8, GET_PIN(B,1), "pwm3", 4}, /* PWM */
{D9, GET_PIN(B,0), "pwm3", 3}, /* PWM */
{D10, GET_PIN(B,12)},
{D11, GET_PIN(B,15)},
{D12, GET_PIN(B,14)},
{D13, GET_PIN(B,13)},
{D14, GET_PIN(B,11), "i2c1"}, /* I2C-SDA (Wire) */
{D15, GET_PIN(B,10), "i2c1"}, /* I2C-SCL (Wire) */
{A0, GET_PIN(A,0), "adc1", 0}, /* ADC */
{A1, GET_PIN(A,1), "adc1", 1}, /* ADC */
{A2, GET_PIN(A,2), "adc1", 2}, /* ADC */
{A3, GET_PIN(A,3), "adc1", 3}, /* ADC */
{A4, GET_PIN(A,4), "adc1", 4}, /* ADC */
{A5, GET_PIN(A,5), "adc1", 5}, /* ADC */
};
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-11-29 hg0720 first version
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
/* pins alias. Must keep in sequence */
#define D0 (0)
#define D1 (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 A0 (16)
#define A1 (17)
#define A2 (18)
#define A3 (19)
#define A4 (20)
#define A5 (21)
#define F_CPU 144000000L /* CPU:144MHz */
#define LED_BUILTIN D5 /* Default Built-in LED */
/* i2c1 : PB1-SDA PB10-SCL */
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1"
#endif /* Pins_Arduino_h */
......@@ -9,12 +9,21 @@
*/
#include <rtthread.h>
#include <rtdevice.h>
/* defined the LED0 pin: PB5 */
#define LED0_PIN rt_pin_get("PB.5")
int main(void)
{
/* set LED0 pin mode to output */
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
while (1)
{
rt_kprintf("Hello RT-Thread!\n");
rt_thread_mdelay(1000);
rt_pin_write(LED0_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(LED0_PIN, PIN_LOW);
rt_thread_mdelay(500);
}
}
......@@ -102,16 +102,16 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_I2C1
comment "Notice: PC7 --> 39; PC6 --> 38"
comment "Notice: PB10 --> 26; PB11 --> 27"
config BSP_I2C1_SCL_PIN
int "i2c1 SCL pin number"
range 0 79
default 38
default 26
config BSP_I2C1_SDA_PIN
int "i2c1 SDA pin number"
range 0 79
default 39
default 27
endif
config BSP_USING_I2C2
......@@ -153,6 +153,7 @@ menu "On-chip Peripheral Drivers"
bool "Enable SPI Flash"
default n
endif
endif
menuconfig BSP_USING_SOFT_SPI
......@@ -254,10 +255,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM1
choice
prompt "Using TIM1 as hwtimer or PWM mode"
default BSP_USING_TIM1_HWTIMER
config BSP_USING_TIM1_HWTIMER
bool "Using TIM1 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -265,7 +262,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM1_PWM
bool "Using TIM1 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM1_PWM
config BSP_USING_TIM1_PWM_CH1
......@@ -283,6 +279,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM1 channel 4"
endif
if BSP_USING_TIM1_HWTIMER && BSP_USING_TIM1_PWM
comment "BSP_USING_TIM1_HWTIMER and BSP_USING_TIM1_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM2
......@@ -290,10 +290,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM2
choice
prompt "Using TIM2 as hwtimer or PWM mode"
default BSP_USING_TIM2_HWTIMER
config BSP_USING_TIM2_HWTIMER
bool "Using TIM2 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -301,7 +297,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM2_PWM
bool "Using TIM2 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM2_PWM
config BSP_USING_TIM2_PWM_CH1
......@@ -319,6 +314,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM2 channel 4"
endif
if BSP_USING_TIM2_HWTIMER && BSP_USING_TIM2_PWM
comment "BSP_USING_TIM2_HWTIMER and BSP_USING_TIM2_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM3
......@@ -326,10 +325,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM3
choice
prompt "Using TIM3 as hwtimer or PWM mode"
default BSP_USING_TIM3_HWTIMER
config BSP_USING_TIM3_HWTIMER
bool "Using TIM3 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -337,7 +332,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM3_PWM
bool "Using TIM3 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM3_PWM
config BSP_USING_TIM3_PWM_CH1
......@@ -355,6 +349,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM3 channel 4"
endif
if BSP_USING_TIM3_HWTIMER && BSP_USING_TIM3_PWM
comment "BSP_USING_TIM3_HWTIMER and BSP_USING_TIM3_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM4
......@@ -362,10 +360,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM4
choice
prompt "Using TIM4 as hwtimer or PWM mode"
default BSP_USING_TIM4_HWTIMER
config BSP_USING_TIM4_HWTIMER
bool "Using TIM4 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -373,7 +367,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM4_PWM
bool "Using TIM4 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM4_PWM
config BSP_USING_TIM4_PWM_CH1
......@@ -391,6 +384,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM4 channel 4"
endif
if BSP_USING_TIM4_HWTIMER && BSP_USING_TIM4_PWM
comment "BSP_USING_TIM4_HWTIMER and BSP_USING_TIM4_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM5
......@@ -398,10 +395,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM5
choice
prompt "Using TIM5 as hwtimer or PWM mode"
default BSP_USING_TIM5_HWTIMER
config BSP_USING_TIM5_HWTIMER
bool "Using TIM5 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -409,7 +402,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM5_PWM
bool "Using TIM5 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM5_PWM
config BSP_USING_TIM5_PWM_CH1
......@@ -427,6 +419,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM5 channel 4"
endif
if BSP_USING_TIM5_HWTIMER && BSP_USING_TIM5_PWM
comment "BSP_USING_TIM5_HWTIMER and BSP_USING_TIM5_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM6
......@@ -434,15 +430,9 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM6
choice
prompt "Using TIM5 as hwtimer (PWM mode not supported)"
default BSP_USING_TIM6_HWTIMER
config BSP_USING_TIM6_HWTIMER
bool "Using TIM6 as hwtimer mode"
select BSP_USING_HWTIMER
endchoice
endif
config BSP_USING_TIM7
......@@ -450,15 +440,9 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM7
choice
prompt "Using TIM7 as hwtimer (PWM mode not supported)"
default BSP_USING_TIM7_HWTIMER
config BSP_USING_TIM7_HWTIMER
bool "Using TIM7 as hwtimer mode"
select BSP_USING_HWTIMER
endchoice
endif
config BSP_USING_TIM8
......@@ -466,10 +450,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM8
choice
prompt "Using TIM8 as hwtimer or PWM mode"
default BSP_USING_TIM8_HWTIMER
config BSP_USING_TIM8_HWTIMER
bool "Using TIM8 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -477,7 +457,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM8_PWM
bool "Using TIM8 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM8_PWM
config BSP_USING_TIM8_PWM_CH1
......@@ -495,6 +474,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM8 channel 4"
endif
if BSP_USING_TIM8_HWTIMER && BSP_USING_TIM8_PWM
comment "BSP_USING_TIM8_HWTIMER and BSP_USING_TIM8_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM9
......@@ -502,10 +485,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM9
choice
prompt "Using TIM9 as hwtimer or PWM mode"
default BSP_USING_TIM9_HWTIMER
config BSP_USING_TIM9_HWTIMER
bool "Using TIM9 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -513,7 +492,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM9_PWM
bool "Using TIM9 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM9_PWM
config BSP_USING_TIM9_PWM_CH1
......@@ -531,6 +509,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM9 channel 4"
endif
if BSP_USING_TIM9_HWTIMER && BSP_USING_TIM9_PWM
comment "BSP_USING_TIM9_HWTIMER and BSP_USING_TIM9_PWM can only be chosen for one!"
endif
endif
config BSP_USING_TIM10
......@@ -538,10 +520,6 @@ menu "On-chip Peripheral Drivers"
default n
if BSP_USING_TIM10
choice
prompt "Using TIM10 as hwtimer or PWM mode"
default BSP_USING_TIM10_HWTIMER
config BSP_USING_TIM10_HWTIMER
bool "Using TIM10 as hwtimer mode"
select BSP_USING_HWTIMER
......@@ -549,7 +527,6 @@ menu "On-chip Peripheral Drivers"
config BSP_USING_TIM10_PWM
bool "Using TIM10 as PWM mode"
select BSP_USING_PWM
endchoice
if BSP_USING_TIM10_PWM
config BSP_USING_TIM10_PWM_CH1
......@@ -567,6 +544,10 @@ menu "On-chip Peripheral Drivers"
bool "Using TIM10 channel 4"
endif
if BSP_USING_TIM10_HWTIMER && BSP_USING_TIM10_PWM
comment "BSP_USING_TIM10_HWTIMER and BSP_USING_TIM10_PWM can only be chosen for one!"
endif
endif
endif
......@@ -574,6 +555,34 @@ menu "On-chip Peripheral Drivers"
endmenu
menu "Onboard Peripheral Drivers"
config BSP_USING_ARDUINO
bool "Compatible with Arduino Ecosystem (RTduino)"
select PKG_USING_RTDUINO
select BSP_USING_GPIO
select BSP_USING_ADC
select BSP_USING_ADC1
select BSP_USING_TIM
select BSP_USING_PWM
select BSP_USING_TIM1
select BSP_USING_TIM1_PWM
select BSP_USING_TIM1_PWM_CH1
select BSP_USING_TIM3
select BSP_USING_TIM3_PWM
select BSP_USING_TIM3_PWM_CH1
select BSP_USING_TIM3_PWM_CH2
select BSP_USING_TIM3_PWM_CH3
select BSP_USING_TIM3_PWM_CH4
select BSP_USING_TIM4
select BSP_USING_TIM4_PWM
select BSP_USING_TIM4_PWM_CH3
select BSP_USING_TIM4_PWM_CH4
select BSP_USING_TIM6
select BSP_USING_TIM6_HWTIMER
select BSP_USING_SOFT_I2C
select BSP_USING_I2C1
imply RTDUINO_USING_SERVO
imply RTDUINO_USING_WIRE
default n
endmenu
......@@ -582,3 +591,4 @@ menu "Board extended module Drivers"
endmenu
endmenu
......@@ -12,7 +12,10 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#include <rtthread.h>
#include "ch32v30x.h"
#include "drv_gpio.h"
#include "drv_pwm.h"
/* board configuration */
#define SRAM_SIZE 96
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册