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

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

为ch32v307适配rt-duino,支持pwm、gpio、uart、iic,暂不支持 spi。
已在ch32v307评估板测试。
测试内容包括串口打印、呼吸灯、AHT10温湿度读取等。
上级 b1763e69
from building import *
import os
cwd = GetCurrentDir()
src = Glob('*.c')
cwd = GetCurrentDir()
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);
}
}
......@@ -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.
先完成此消息的编辑!
想要评论请 注册