feat: 增加CH32V307开发板支持
This commit is contained in:
32
platform/Makefile
Normal file
32
platform/Makefile
Normal file
@@ -0,0 +1,32 @@
|
||||
###################################################################
|
||||
#automatic detection QTOP and LOCALDIR
|
||||
CUR_DIR := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
|
||||
TRYQTOP := $(shell if [ -n "$$QTOP" ] ; then\
|
||||
echo $$QTOP;\
|
||||
else\
|
||||
cd $(CUR_DIR); while /usr/bin/test ! -e qmk ; do \
|
||||
dir=`cd ../;pwd`; \
|
||||
if [ "$$dir" = "/" ] ; then \
|
||||
echo Cannot find QTOP in $(firstword $(MAKEFILE_LIST)) 1>&2; \
|
||||
exit 1; \
|
||||
fi ; \
|
||||
cd $$dir; \
|
||||
done ; \
|
||||
pwd; \
|
||||
fi)
|
||||
QTOP ?= $(realpath ${TRYQTOP})
|
||||
|
||||
ifeq ($(QTOP),)
|
||||
$(error Please run this in a tree)
|
||||
endif
|
||||
LOCALDIR = $(patsubst %/,%,$(subst $(realpath $(QTOP))/,,$(CUR_DIR)))
|
||||
####################################################################
|
||||
|
||||
|
||||
TREE_LIB_ENABLE=0
|
||||
lib=
|
||||
subdirs=
|
||||
|
||||
|
||||
include ${QTOP}/qmk/generic/Make.tpl
|
||||
|
47
platform/hal/Makefile
Normal file
47
platform/hal/Makefile
Normal file
@@ -0,0 +1,47 @@
|
||||
###################################################################
|
||||
#automatic detection QTOP and LOCALDIR
|
||||
CUR_DIR := $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
|
||||
TRYQTOP := $(shell if [ -n "$$QTOP" ] ; then\
|
||||
echo $$QTOP;\
|
||||
else\
|
||||
cd $(CUR_DIR); while /usr/bin/test ! -d qmk ; do \
|
||||
dir=`cd ../;pwd`; \
|
||||
if [ "$$dir" = "/" ] ; then \
|
||||
echo Cannot find QTOP in $(firstword $(MAKEFILE_LIST)) 1>&2; \
|
||||
exit 1; \
|
||||
fi ; \
|
||||
cd $$dir; \
|
||||
done ; \
|
||||
pwd; \
|
||||
fi)
|
||||
QTOP ?= $(realpath ${TRYQTOP})
|
||||
|
||||
ifeq ($(QTOP),)
|
||||
$(error Please run this in a tree)
|
||||
endif
|
||||
LOCALDIR = $(patsubst %/,%,$(subst $(realpath $(QTOP))/,,$(CUR_DIR)))
|
||||
|
||||
####################################################################
|
||||
|
||||
|
||||
TREE_LIB_ENABLE=0
|
||||
lib=
|
||||
subdirs=
|
||||
ifneq (help,$(findstring help,$(MAKECMDGOALS)))
|
||||
|
||||
ifeq (, $(strip ${BP}))
|
||||
$(error when compile platform/, must specify BP obviously , see `make help`)
|
||||
endif
|
||||
|
||||
include ${QTOP}/qmk/board-pack/bp.${BP}
|
||||
|
||||
ifeq (,$(strip ${PLATFORM_HAL_LSRCS}))
|
||||
$(error when compile platform/, must specify PLATFORM_HAL_LSRCS on your bp.${BP} , see `make help`)
|
||||
endif
|
||||
endif
|
||||
|
||||
# arch src should be specify by bp
|
||||
LSRCS := $(subst $(QTOP)/$(LOCALDIR)/,, ${PLATFORM_HAL_LSRCS})
|
||||
include ${QTOP}/qmk/generic/Make.tpl
|
||||
|
||||
|
126
platform/hal/wch/ch32v30xx/src/tos_hal_sd.c
Normal file
126
platform/hal/wch/ch32v30xx/src/tos_hal_sd.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "tos_k.h"
|
||||
#include "tos_hal.h"
|
||||
#include "ch32v30x.h"
|
||||
#include "sdio.h"
|
||||
|
||||
__API__ int tos_hal_sd_init(hal_sd_t *sd)
|
||||
{
|
||||
(void)sd;
|
||||
|
||||
return SD_Init() == SD_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_read(hal_sd_t *sd, uint8_t *buf, uint32_t blk_addr, uint32_t blk_num, uint32_t timeout)
|
||||
{
|
||||
uint8_t err;
|
||||
|
||||
(void)sd;
|
||||
|
||||
if (!buf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = SD_ReadDisk(buf, blk_addr, blk_num);
|
||||
|
||||
return err == SD_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_write(hal_sd_t *sd, const uint8_t *buf, uint32_t blk_addr, uint32_t blk_num, uint32_t timeout)
|
||||
{
|
||||
uint8_t err;
|
||||
|
||||
(void)sd;
|
||||
|
||||
if (!buf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = SD_WriteDisk((uint8_t *)buf, blk_addr, blk_num);
|
||||
|
||||
return err == SD_OK ? 0 : -1;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_read_dma(hal_sd_t *sd, uint8_t *buf, uint32_t blk_addr, uint32_t blk_num)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_write_dma(hal_sd_t *sd, const uint8_t *buf, uint32_t blk_addr, uint32_t blk_num)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_erase(hal_sd_t *sd, uint32_t blk_add_start, uint32_t blk_addr_end)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_info_get(hal_sd_t *sd, hal_sd_info_t *info)
|
||||
{
|
||||
SD_Error err;
|
||||
SD_CardInfo card_info;
|
||||
|
||||
(void)sd;
|
||||
|
||||
if (!sd || !info) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = SD_GetCardInfo(&card_info);
|
||||
if (err != SD_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
info->card_type = card_info.CardType;
|
||||
info->blk_num = card_info.CardCapacity / card_info.CardBlockSize;
|
||||
info->blk_size = card_info.CardBlockSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_state_get(hal_sd_t *sd, hal_sd_state_t *state)
|
||||
{
|
||||
int ret = 0;
|
||||
SDCardState sd_state;
|
||||
|
||||
(void)sd;
|
||||
|
||||
if (!sd || !state) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sd_state = SD_GetState();
|
||||
switch (sd_state) {
|
||||
case SD_CARD_READY:
|
||||
*state = HAL_SD_STAT_READY;
|
||||
break;
|
||||
|
||||
case SD_CARD_SENDING:
|
||||
*state = HAL_SD_STAT_PROGRAMMING;
|
||||
break;
|
||||
|
||||
case SD_CARD_RECEIVING:
|
||||
*state = HAL_SD_STAT_RECEIVING;
|
||||
break;
|
||||
|
||||
case SD_CARD_TRANSFER:
|
||||
*state = HAL_SD_STAT_TRANSFER;
|
||||
break;
|
||||
|
||||
case SD_CARD_ERROR:
|
||||
*state = HAL_SD_STAT_ERROR;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_sd_deinit(hal_sd_t *sd)
|
||||
{
|
||||
(void)sd;
|
||||
return 0;
|
||||
}
|
||||
|
75
platform/hal/wch/ch32v30xx/src/tos_hal_uart.c
Normal file
75
platform/hal/wch/ch32v30xx/src/tos_hal_uart.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "tos_k.h"
|
||||
#include "tos_hal.h"
|
||||
#include "ch32v30x.h"
|
||||
#include "usart.h"
|
||||
|
||||
__API__ int tos_hal_uart_init(hal_uart_t *uart, hal_uart_port_t port)
|
||||
{
|
||||
if (!uart) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (port == HAL_UART_PORT_0) {
|
||||
uart->private_uart = UART7;
|
||||
uart7_init(115200);
|
||||
} else if (port == HAL_UART_PORT_2) {
|
||||
uart->private_uart = USART2;
|
||||
usart2_init(115200);
|
||||
} else if (port == HAL_UART_PORT_6) {
|
||||
uart->private_uart = UART6;
|
||||
uart6_init(115200);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_uart_write(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout)
|
||||
{
|
||||
USART_TypeDef *base;
|
||||
|
||||
if (!uart || !buf) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!uart->private_uart) {
|
||||
return -1;
|
||||
}
|
||||
base = (USART_TypeDef *)uart->private_uart;
|
||||
|
||||
for(size_t i=0; i<size; i++) {
|
||||
USART_SendData(base, buf[i]);
|
||||
while (USART_GetFlagStatus(base, USART_FLAG_TC) != SET);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_uart_read(hal_uart_t *uart, const uint8_t *buf, size_t size, uint32_t timeout)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__API__ int tos_hal_uart_deinit(hal_uart_t *uart)
|
||||
{
|
||||
//USART_TypeDef *base;
|
||||
|
||||
if (!uart) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!uart->private_uart) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//base = (USART_TypeDef *)uart->private_uart;
|
||||
|
||||
|
||||
|
||||
//usart_deinit(base);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user