hpw422移植新的sdk

This commit is contained in:
xushaoxiang
2026-07-03 18:08:25 +08:00
commit 945a5a5b0b
2583 changed files with 713209 additions and 0 deletions
@@ -0,0 +1,216 @@
/*!
* \file main.c
*
* \brief Target main implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
*
* _ __ _ ________ _
* | |/ /(_)___ / ____/ /_ (_)___
* | // / __ \/ / / __ \/ / __ \
* / |/ / / / / /___/ / / / / /_/ /
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
* /_/
* (C) 2022-2025 XinChip
*
* \endcode
*
* \author ( XinChip ) Alex-J
*
* \author ( XinChip )
*/
/*-----------------------------------------------------------------------------------
INCLUDE HEADE FILES
------------------------------------------------------------------------------------*/
#include "xc6xxx.h"
#include "usbd_core.h"
#include "usb_device.h"
#include "usbd_hid_mouse.h"
#include "usbd_hid_keyboard.h"
#include "usbd_hid_custom.h"
/*------------------------------------------------------------------------------------
Macros
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Global Variables
-------------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------------
Functions
-------------------------------------------------------------------------------------*/
void SysTick_Callback(void)
{
}
void clock_init(void)
{
CLOCK_InitCfg_t clock_cfg;
clock_cfg.hfclk_src = CLOCK_HFCLK_SRC_XTAL;
clock_cfg.hfclk_in = CLOCK_HFCLK_IN_48M;
clock_cfg.lfclk_src = CLOCK_LFCLK_SRC_RC;
if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_XTAL) {
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32768;
} else if (clock_cfg.lfclk_src == CLOCK_LFCLK_SRC_RC) {
clock_cfg.lfclk_in = CLOCK_LFCLK_IN_32K;
}
xc_clock_init_cfg(&clock_cfg);
SysTick_Config(xc_clock_hfclk_in_get() / 100);
SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
}
void app_uart_init(void)
{
GPIO_InitCfg_t gpio_cfg = {0};
gpio_cfg.Mux = GPIO_Mux0;
gpio_cfg.Pull = GPIO_PULLUP;
gpio_cfg.Int = NOT_INT;
gpio_cfg.FunSel = UART0_TX;
gpio_cfg.Pin = GPIO_18;
gpio_cfg.Dir = GPIO_DIR_OUTPUT;
xc_gpio_init(&gpio_cfg);
gpio_cfg.FunSel = UART0_RX;
gpio_cfg.Pin = GPIO_19;
gpio_cfg.Dir = GPIO_DIR_INPUT;
xc_gpio_init(&gpio_cfg);
UART_InitCfg_t uart_cfg = {0};
uart_cfg.Parity = UART_PARITY_DISABLE;
uart_cfg.StopBits = UART_STOP_1_BITS;
uart_cfg.WordLength = UART_DATA_8_BITS;
uart_cfg.BaudRate = UART_BAUDRATE_115200;
uart_cfg.HardwareFlowControl = UART_HWFC_DISABLE;
xc_uart_init(UART0_IDX, &uart_cfg);
}
void GetPointerData(uint8_t *pbuf)
{
static int32_t move_cnt = 0;
static uint8_t step_x_y = 0;
static int8_t x = 0, y = 0;
static uint16_t cursor_step = 2;
static uint16_t cursor_width = 200;
move_cnt++;
if (move_cnt > cursor_width) {
step_x_y++;
step_x_y = step_x_y % 4;
move_cnt = 0;
}
switch (step_x_y) {
case 0: {
y = 0;
x = cursor_step;
} break;
case 1: {
x = 0;
y = cursor_step;
} break;
case 2: {
y = 0;
x = (int8_t)(-cursor_step);
} break;
case 3: {
x = 0;
y = (int8_t)(-cursor_step);
} break;
}
pbuf[0] = 0;
pbuf[1] = x;
pbuf[2] = y;
pbuf[3] = 0;
}
#ifdef APP_USB_MOUSE_FAST_SEND_DATA
void app_usb_mouse_fast_send_data(USBD_HandleTypeDef *pdev)
{
uint8_t data[4];
GLOBAL_INT_DISABLE();
GetPointerData(data);
(void)USBD_LL_Transmit(pdev, HID_MOUSE_EPIN_ADDR, data, HID_MOUSE_EPIN_SIZE);
GLOBAL_INT_RESTORE();
}
#endif
void app_usb_mouse_send_data(void)
{
uint8_t data[4];
GetPointerData(data);
GLOBAL_INT_DISABLE();
USBD_HID_Mouse_FirstSendReport(&hUsbDeviceFS, data, HID_MOUSE_EPIN_SIZE);
GLOBAL_INT_RESTORE();
}
void app_usb_keyboard_send_data(void)
{
const uint8_t key_codes[] = {0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26};
uint8_t key_data[HID_KEYBOARD_EPIN_SIZE] = {0};
for(int i=0;i<9;i++){
key_data[2] = key_codes[i];
GLOBAL_INT_DISABLE();
USBD_HID_Keyboard_FirstSendReport(&hUsbDeviceFS, key_data, HID_KEYBOARD_EPIN_SIZE);
GLOBAL_INT_RESTORE();
delay_ms(50);
key_data[2] = 0x0;
GLOBAL_INT_DISABLE();
USBD_HID_Keyboard_FirstSendReport(&hUsbDeviceFS, key_data, HID_KEYBOARD_EPIN_SIZE);
GLOBAL_INT_RESTORE();
delay_ms(50);
}
}
void app_usb_custom_send_data(void)
{
uint8_t data[HID_CUSTOM_EPIN_SIZE];
for (int i = 0; i < HID_CUSTOM_EPIN_SIZE; i++) {
data[i] = i;
}
GLOBAL_INT_DISABLE();
USBD_HID_Custom_FirstSendReport(&hUsbDeviceFS, data, HID_CUSTOM_EPIN_SIZE);
GLOBAL_INT_RESTORE();
}
int main(void)
{
clock_init();
app_uart_init( );
DEBUG("__USB_HID_COMPOSITE_DEMO__\n");
/* USB Device Initialization */
USB_DEVICE_Init( );
while(1)
{
delay_ms(1);
app_usb_mouse_send_data();
app_usb_keyboard_send_data();
app_usb_custom_send_data();
}
}