120 lines
3.1 KiB
C
120 lines
3.1 KiB
C
#include "led.h"
|
|
#include "dap_main.h"
|
|
#include "cdc_main.h"
|
|
|
|
static void TIM3_Init(u16 arr, u16 psc)
|
|
{
|
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
|
|
|
TIM_TimeBaseInitStructure.TIM_Period = arr;
|
|
TIM_TimeBaseInitStructure.TIM_Prescaler = psc;
|
|
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
|
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
|
|
|
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
|
|
|
|
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
|
|
TIM_Cmd(TIM3, ENABLE);
|
|
}
|
|
|
|
void LED_Init(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
|
AFIO->PCFR1 |= (1 << 26);
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_19;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_4, 0);
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_19, 0);
|
|
TIM3_Init(1000 - 1, 48 - 1);
|
|
}
|
|
|
|
static void LED_Task(void)
|
|
{
|
|
static uint32_t LED_Task_Cnt = 0;
|
|
|
|
// static uint32_t DAP_In_Active_Cnt = 0;
|
|
// static uint32_t CDC_In_Active_Cnt = 0;
|
|
|
|
// if (DAP_Is_Active == 1)
|
|
// DAP_In_Active_Cnt = 0;
|
|
// else if (DAP_In_Active_Cnt < 500)
|
|
// DAP_In_Active_Cnt++;
|
|
// DAP_Is_Active = 0;
|
|
//
|
|
// if (DAP_In_Active_Cnt >= 500)
|
|
// {
|
|
// GPIOA->BCR = 1 << 4; // LED1
|
|
// }
|
|
// else
|
|
// {
|
|
extern volatile unsigned char dap_status;
|
|
if (LED_Task_Cnt % 100 == 0)
|
|
{
|
|
if (dap_status == 1)
|
|
{
|
|
|
|
static char i = 0;
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_4, i);
|
|
// GPIO_WriteBit(GPIOC, GPIO_Pin_19, i);
|
|
i = !i;
|
|
}else{
|
|
GPIO_WriteBit(GPIOA, GPIO_Pin_4, 1);
|
|
}
|
|
}
|
|
if (LED_Task_Cnt % 1000 == 0)
|
|
{
|
|
static char i = 0;
|
|
GPIO_WriteBit(GPIOC, GPIO_Pin_19, i);
|
|
i = !i;
|
|
}
|
|
|
|
// }
|
|
|
|
// if (CDC_Is_Active == 1)
|
|
// CDC_In_Active_Cnt = 0;
|
|
// else if (CDC_In_Active_Cnt < 500)
|
|
// CDC_In_Active_Cnt++;
|
|
// CDC_Is_Active = 0;
|
|
|
|
// if (CDC_In_Active_Cnt >= 500)
|
|
// {
|
|
// GPIOC->BCR = 1 << 3; // LED2
|
|
// }
|
|
// else
|
|
// {
|
|
// if (LED_Task_Cnt % 100 == 0)
|
|
// {
|
|
// GPIO_WriteBit(GPIOA, GPIO_Pin_4, i);
|
|
// }
|
|
// }
|
|
|
|
LED_Task_Cnt++;
|
|
}
|
|
|
|
void TIM3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
|
void TIM3_IRQHandler(void)
|
|
{
|
|
if (TIM_GetITStatus(TIM3, TIM_IT_Update) == SET)
|
|
{
|
|
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
|
|
|
|
LED_Task();
|
|
}
|
|
}
|