Skip to content

Commit

Permalink
feat: 添加CDC的输出RTS和DTR功能
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfSweet committed Sep 22, 2024
1 parent 4de6611 commit 4a3b5bd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
4 changes: 3 additions & 1 deletion projects/HSLink-Pro/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ sdk_app_src(../../../DAP/Source/DAP.c)
sdk_app_src(../../../CherryRB/chry_ringbuffer.c)

sdk_app_src(main.c)
sdk_app_src(usb2uart.c)
sdk_app_src(dp_common.c)

if (CONFIG_BUILD_VERSION)
Expand All @@ -97,6 +96,9 @@ else ()
sdk_compile_definitions(-DDAP_FW_VER="Debug")
endif ()

sdk_app_src(USB2UART/usb2uart.c)
sdk_app_inc(USB2UART)

sdk_compile_definitions(-DPRODUCT_STRING="HSLink Pro")
#sdk_compile_definitions(-DCONFIG_USE_HID_CONFIG=1)
sdk_app_src(../common/HSLink_Pro_expansion.c)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include <stdio.h>
#include <hpm_gpiom_soc_drv.h>
#include <hpm_gpio_drv.h>
#include <hpm_gpiom_drv.h>
#include "board.h"
#include "hpm_uart_drv.h"
#include "hpm_debug_console.h"
#include "hpm_dma_mgr.h"
#include "hpm_sysctl_drv.h"
#include "dap_main.h"
#include "usb2uart.h"

#define UART_BASE HPM_UART2
#define UART_IRQ IRQn_UART2
Expand Down Expand Up @@ -110,8 +114,19 @@ void usb2uart_handler (void)
void uartx_preinit(void)
{
// board_init_uart(UART_BASE);
HPM_IOC->PAD[IOC_PAD_PA09].FUNC_CTL = IOC_PA09_FUNC_CTL_UART2_RXD;
HPM_IOC->PAD[IOC_PAD_PA08].FUNC_CTL = IOC_PA08_FUNC_CTL_UART2_TXD;
HPM_IOC->PAD[PIN_UART_RX].FUNC_CTL = IOC_PA09_FUNC_CTL_UART2_RXD;
HPM_IOC->PAD[PIN_UART_TX].FUNC_CTL = IOC_PA08_FUNC_CTL_UART2_TXD;

HPM_IOC->PAD[PIN_UART_DTR].FUNC_CTL = IOC_PAD_FUNC_CTL_ALT_SELECT_SET(0);
HPM_IOC->PAD[PIN_UART_RTS].FUNC_CTL = IOC_PAD_FUNC_CTL_ALT_SELECT_SET(0);

gpiom_set_pin_controller(HPM_GPIOM, GPIO_GET_PORT_INDEX(PIN_UART_DTR), GPIO_GET_PIN_INDEX(PIN_UART_DTR), gpiom_soc_gpio0);
gpio_set_pin_output(HPM_GPIO0, GPIO_GET_PORT_INDEX(PIN_UART_DTR), GPIO_GET_PIN_INDEX(PIN_UART_DTR));
gpio_write_pin(HPM_GPIO0, GPIO_GET_PORT_INDEX(PIN_UART_DTR), GPIO_GET_PIN_INDEX(PIN_UART_DTR), 1); // 默认输出高电平

gpiom_set_pin_controller(HPM_GPIOM, GPIO_GET_PORT_INDEX(PIN_UART_RTS), GPIO_GET_PIN_INDEX(PIN_UART_RTS), gpiom_soc_gpio0);
gpio_set_pin_output(HPM_GPIO0, GPIO_GET_PORT_INDEX(PIN_UART_RTS), GPIO_GET_PIN_INDEX(PIN_UART_RTS));
gpio_write_pin(HPM_GPIO0, GPIO_GET_PORT_INDEX(PIN_UART_RTS), GPIO_GET_PIN_INDEX(PIN_UART_RTS), 1); // 默认输出高电平

clock_set_source_divider(UART_CLK_NAME, clk_src_pll1_clk0, 8);
clock_add_to_group(UART_CLK_NAME, 0);
Expand Down Expand Up @@ -220,3 +235,17 @@ static hpm_stat_t board_uart_dma_config(void)
}
return status_success;
}

void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
{
(void)busid;
(void)intf;
gpio_write_pin(HPM_GPIO0, GPIO_GET_PORT_INDEX(PIN_UART_DTR), GPIO_GET_PIN_INDEX(PIN_UART_DTR), !dtr);
}

void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts)
{
(void)busid;
(void)intf;
gpio_write_pin(HPM_GPIO0, GPIO_GET_PORT_INDEX(PIN_UART_RTS), GPIO_GET_PIN_INDEX(PIN_UART_RTS), !rts);
}
13 changes: 13 additions & 0 deletions projects/HSLink-Pro/src/USB2UART/usb2uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef HSLINK_PRO_USB2UART_H
#define HSLINK_PRO_USB2UART_H

#define PIN_UART_TX IOC_PAD_PA08
#define PIN_UART_RX IOC_PAD_PA09
#define PIN_UART_RTS IOC_PAD_PA07
#define PIN_UART_DTR IOC_PAD_PA06

void uartx_preinit(void);

void usb2uart_handler(void);

#endif //HSLINK_PRO_USB2UART_H
4 changes: 1 addition & 3 deletions projects/HSLink-Pro/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include "dap_main.h"
#include "WS2812.h"
#include "projects/HSLink-Pro/common/HSLink_Pro_expansion.h"

extern void uartx_preinit(void);
extern void usb2uart_handler (void);
#include "usb2uart.h"

char serial_number[32];

Expand Down

0 comments on commit 4a3b5bd

Please sign in to comment.