[Add] First commit
This commit is contained in:
99
NSPE/Example/USBFS/usb_device/custom_hid/src/app.c
Normal file
99
NSPE/Example/USBFS/usb_device/custom_hid/src/app.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*!
|
||||
\file app.c
|
||||
\brief main routine
|
||||
|
||||
\version 2021-10-30, V1.0.0, firmware for GD32W51x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2021, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "drv_usb_hw.h"
|
||||
#include "custom_hid_core.h"
|
||||
|
||||
#define TZBMPC1_BLOCK_NUMBER 255 /* TZBMPC1 block number */
|
||||
|
||||
usb_core_driver custom_hid;
|
||||
|
||||
extern hid_fop_handler fop_handler;
|
||||
|
||||
void tzbmpc_config(void);
|
||||
|
||||
/*!
|
||||
\brief main routine will construct a USB custom HID device
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3)
|
||||
/* enable SecureFault handler */
|
||||
SCB->SHCSR |= SCB_SHCSR_SECUREFAULTENA_Msk;
|
||||
|
||||
/* configure TZBMPC */
|
||||
tzbmpc_config();
|
||||
|
||||
/* configure USBFS secure attributes */
|
||||
tzpcu_tzspc_peripheral_attributes_config(TZPCU_PERIPH_USBFS, TZPCU_SEC);
|
||||
#endif
|
||||
|
||||
usb_gpio_config();
|
||||
|
||||
usb_rcu_config();
|
||||
|
||||
usb_timer_init();
|
||||
|
||||
custom_hid_itfop_register(&custom_hid, &fop_handler);
|
||||
|
||||
usbd_init(&custom_hid, &custom_hid_desc, &usbd_custom_hid_cb);
|
||||
|
||||
usb_intr_config();
|
||||
|
||||
/* Main loop */
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief configure tzbmpc
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void tzbmpc_config(void)
|
||||
{
|
||||
uint16_t block_number = 0U;
|
||||
|
||||
/* enable TZPCU clock */
|
||||
rcu_periph_clock_enable(RCU_TZPCU);
|
||||
|
||||
/* SRAM1 is used to nonsecure code, so all blocks of SRAM1 should set to nonsecure */
|
||||
for(block_number = 0U; block_number <= TZBMPC1_BLOCK_NUMBER; block_number++){
|
||||
tzpcu_tzbmpc_block_secure_access_mode_config(TZBMPC1, block_number, BLOCK_SECURE_ACCESS_MODE_NSEC);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
/*!
|
||||
\file custom_hid_itf.c
|
||||
\brief custom HID interface driver
|
||||
|
||||
\version 2021-10-30, V1.0.0, firmware for GD32W51x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2021, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "custom_hid_core.h"
|
||||
|
||||
static void key_config(void);
|
||||
static void led_config(void);
|
||||
|
||||
hid_fop_handler fop_handler = {
|
||||
.periph_config = {key_config, led_config}
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief configure the keys
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
static void key_config(void)
|
||||
{
|
||||
/* keys configuration */
|
||||
gd_eval_key_init(KEY_TAMPER_WAKEUP, KEY_MODE_EXTI);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief configure the LEDs
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
static void led_config(void)
|
||||
{
|
||||
/* initialize LEDs */
|
||||
gd_eval_led_init(LED1);
|
||||
gd_eval_led_init(LED2);
|
||||
gd_eval_led_init(LED3);
|
||||
}
|
||||
217
NSPE/Example/USBFS/usb_device/custom_hid/src/gd32w51x_hw.c
Normal file
217
NSPE/Example/USBFS/usb_device/custom_hid/src/gd32w51x_hw.c
Normal file
@ -0,0 +1,217 @@
|
||||
/*!
|
||||
\file gd32w51x_hw.c
|
||||
\brief USB hardware configuration for GD32W51x
|
||||
|
||||
\version 2021-10-30, V1.0.0, firmware for GD32W51x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2021, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "drv_usb_hw.h"
|
||||
|
||||
#define TIM_MSEC_DELAY 0x01U
|
||||
#define TIM_USEC_DELAY 0x02U
|
||||
|
||||
__IO uint32_t delay_time = 0U;
|
||||
__IO uint16_t timer_prescaler = 5U;
|
||||
uint32_t usb_prescaler = 0U;
|
||||
|
||||
/* local function prototypes ('static') */
|
||||
static void hw_time_set (uint8_t unit);
|
||||
static void hw_delay (uint32_t ntime, uint8_t unit);
|
||||
|
||||
/*!
|
||||
\brief configure USB data line gpio
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_gpio_config(void)
|
||||
{
|
||||
rcu_periph_clock_enable(RCU_SYSCFG);
|
||||
rcu_periph_clock_enable(RCU_GPIOB);
|
||||
|
||||
/* USBFS_DM(PB12) and USBFS_DP(PB13) GPIO pin configuration */
|
||||
gpio_mode_set(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_12 | GPIO_PIN_13);
|
||||
gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_166MHZ, GPIO_PIN_12 | GPIO_PIN_13);
|
||||
|
||||
gpio_af_set(GPIOB, GPIO_AF_10, GPIO_PIN_12 | GPIO_PIN_13);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief configure USB clock
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_rcu_config(void)
|
||||
{
|
||||
rcu_usbfs_clock_config(RCU_USBFSSRC_PLL);
|
||||
|
||||
rcu_usbfs_div_config(RCU_USBFS_DIV7);
|
||||
|
||||
rcu_periph_clock_enable(RCU_USBFS);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief configure USB interrupt
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_intr_config(void)
|
||||
{
|
||||
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
|
||||
nvic_irq_enable((uint8_t)USBFS_IRQn, 2U, 0U);
|
||||
|
||||
/* enable the power module clock */
|
||||
rcu_periph_clock_enable(RCU_PMU);
|
||||
|
||||
/* USB wakeup EXTI line configuration */
|
||||
exti_interrupt_flag_clear(EXTI_18);
|
||||
exti_init(EXTI_18, EXTI_INTERRUPT, EXTI_TRIG_RISING);
|
||||
exti_interrupt_enable(EXTI_18);
|
||||
nvic_irq_enable((uint8_t)USBFS_WKUP_IRQn, 1U, 0U);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief initializes delay unit using Timer2
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_timer_init (void)
|
||||
{
|
||||
/* configure the priority group to 2 bits */
|
||||
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
|
||||
|
||||
/* enable the TIMER2 global interrupt */
|
||||
nvic_irq_enable((uint8_t)TIMER2_IRQn, 1U, 0U);
|
||||
|
||||
rcu_periph_clock_enable(RCU_TIMER2);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay in micro seconds
|
||||
\param[in] usec: value of delay required in micro seconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_udelay (const uint32_t usec)
|
||||
{
|
||||
hw_delay(usec, TIM_USEC_DELAY);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay in milliseconds
|
||||
\param[in] msec: value of delay required in milliseconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_mdelay (const uint32_t msec)
|
||||
{
|
||||
hw_delay(msec, TIM_MSEC_DELAY);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief time base IRQ
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void usb_timer_irq (void)
|
||||
{
|
||||
if (RESET != timer_interrupt_flag_get(TIMER2, TIMER_INT_UP)){
|
||||
timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP);
|
||||
|
||||
if (delay_time > 0x00U){
|
||||
delay_time--;
|
||||
} else {
|
||||
timer_disable(TIMER2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief delay routine based on TIMER2
|
||||
\param[in] nTime: delay Time
|
||||
\param[in] unit: delay Time unit = milliseconds / microseconds
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
static void hw_delay(uint32_t ntime, uint8_t unit)
|
||||
{
|
||||
delay_time = ntime;
|
||||
|
||||
hw_time_set(unit);
|
||||
|
||||
while (0U != delay_time) {
|
||||
}
|
||||
|
||||
timer_disable(TIMER2);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief configures TIMER2 for delay routine based on TIMER2
|
||||
\param[in] unit: msec /usec
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
static void hw_time_set(uint8_t unit)
|
||||
{
|
||||
timer_parameter_struct timer_basestructure;
|
||||
|
||||
timer_disable(TIMER2);
|
||||
timer_interrupt_disable(TIMER2, TIMER_INT_UP);
|
||||
|
||||
if (TIM_USEC_DELAY == unit) {
|
||||
timer_basestructure.period = 6U;
|
||||
} else if(TIM_MSEC_DELAY == unit) {
|
||||
timer_basestructure.period = 6999U;
|
||||
} else {
|
||||
/* no operation */
|
||||
}
|
||||
|
||||
timer_basestructure.prescaler = timer_prescaler;
|
||||
timer_basestructure.alignedmode = TIMER_COUNTER_EDGE;
|
||||
timer_basestructure.counterdirection = TIMER_COUNTER_UP;
|
||||
timer_basestructure.clockdivision = TIMER_CKDIV_DIV1;
|
||||
timer_basestructure.repetitioncounter = 0U;
|
||||
|
||||
timer_init(TIMER2, &timer_basestructure);
|
||||
|
||||
timer_interrupt_flag_clear(TIMER2, TIMER_INT_UP);
|
||||
|
||||
timer_auto_reload_shadow_enable(TIMER2);
|
||||
|
||||
/* TIMER interrupt enable */
|
||||
timer_interrupt_enable(TIMER2, TIMER_INT_UP);
|
||||
|
||||
/* TIMER2 enable counter */
|
||||
timer_enable(TIMER2);
|
||||
}
|
||||
261
NSPE/Example/USBFS/usb_device/custom_hid/src/gd32w51x_it.c
Normal file
261
NSPE/Example/USBFS/usb_device/custom_hid/src/gd32w51x_it.c
Normal file
@ -0,0 +1,261 @@
|
||||
/*!
|
||||
\file gd32w51x_it.c
|
||||
\brief main interrupt service routines
|
||||
|
||||
\version 2021-10-30, V1.0.0, firmware for GD32W51x
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2021, GigaDevice Semiconductor Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "gd32w51x_it.h"
|
||||
#include "drv_usbd_int.h"
|
||||
#include "custom_hid_core.h"
|
||||
|
||||
uint8_t send_buffer[4] = {0x00, 0x01, 0x00, 0x00};
|
||||
|
||||
extern usb_core_driver custom_hid;
|
||||
extern uint32_t usb_prescaler;
|
||||
|
||||
void usb_timer_irq (void);
|
||||
|
||||
/* local function prototypes ('static') */
|
||||
static void resume_mcu_clk(void);
|
||||
|
||||
/*!
|
||||
\brief this function handles NMI exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles HardFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* if Hard Fault exception occurs, go to infinite loop */
|
||||
while (1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles MemManage exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* if Memory Manage exception occurs, go to infinite loop */
|
||||
while (1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles BusFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* if Bus Fault exception occurs, go to infinite loop */
|
||||
while (1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles UsageFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* if Usage Fault exception occurs, go to infinite loop */
|
||||
while (1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles SVC exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles DebugMon exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles PendSV exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles SecureFault exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SecureFault_Handler(void)
|
||||
{
|
||||
/* if Secure Fault exception occurs, go to infinite loop */
|
||||
while(1){
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles SysTick exception
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles USBFS interrupt
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void USBFS_IRQHandler (void)
|
||||
{
|
||||
usbd_isr (&custom_hid);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles USBFS wakeup interrupt request.
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void USBFS_WKUP_IRQHandler(void)
|
||||
{
|
||||
if (custom_hid.bp.low_power) {
|
||||
resume_mcu_clk();
|
||||
|
||||
rcu_periph_clock_enable(RCU_USBFS);
|
||||
|
||||
usb_clock_active(&custom_hid);
|
||||
}
|
||||
|
||||
exti_interrupt_flag_clear(EXTI_18);
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles Timer0 updata interrupt request.
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void TIMER2_IRQHandler(void)
|
||||
{
|
||||
usb_timer_irq();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief this function handles EXTI0_IRQ Handler.
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void EXTI2_IRQHandler (void)
|
||||
{
|
||||
if (RESET != exti_interrupt_flag_get(TAMPER_WAKEUP_KEY_EXTI_LINE)) {
|
||||
if (USBD_CONFIGURED == custom_hid.dev.cur_status) {
|
||||
send_buffer[0] = 0x15U;
|
||||
|
||||
if (RESET == gd_eval_key_state_get(KEY_TAMPER_WAKEUP)) {
|
||||
if(send_buffer[1]) {
|
||||
send_buffer[1] = 0x00U;
|
||||
} else {
|
||||
send_buffer[1] = 0x01U;
|
||||
}
|
||||
}
|
||||
|
||||
custom_hid_report_send (&custom_hid, send_buffer, 2U);
|
||||
}
|
||||
|
||||
/* clear the EXTI line interrupt flag */
|
||||
exti_interrupt_flag_clear(TAMPER_WAKEUP_KEY_EXTI_LINE);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief resume mcu clock
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
static void resume_mcu_clk(void)
|
||||
{
|
||||
/* enable HSE */
|
||||
rcu_osci_on(RCU_HXTAL);
|
||||
|
||||
/* wait till HSE is ready */
|
||||
while(RESET == rcu_flag_get(RCU_FLAG_HXTALSTB)){
|
||||
}
|
||||
|
||||
/* enable PLL */
|
||||
rcu_osci_on(RCU_PLL_CK);
|
||||
|
||||
/* wait till PLL is ready */
|
||||
while(RESET == rcu_flag_get(RCU_FLAG_PLLSTB)){
|
||||
}
|
||||
|
||||
/* select PLL as system clock source */
|
||||
rcu_system_clock_source_config(RCU_CKSYSSRC_PLLP);
|
||||
|
||||
/* wait till PLL is used as system clock source */
|
||||
while(RCU_SCSS_PLLP != rcu_system_clock_source_get()){
|
||||
}
|
||||
}
|
||||
1078
NSPE/Example/USBFS/usb_device/custom_hid/src/system_gd32w51x.c
Normal file
1078
NSPE/Example/USBFS/usb_device/custom_hid/src/system_gd32w51x.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user