You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.6 KiB
C

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
******************************************************************************
* @file driver_ST7735S.c
* @author <20>Ϻ<EFBFBD><CFBA><EFBFBD><EFBFBD><EFBFBD>
* @version V1.0.0
* @date 2023
* @brief ST7735S driver.
* This file provides firmware functions to manage gc9c01
* with SPI and DMA. User should set GPIO, dma channel, spi
* channel according actual resource allocation.
******************************************************************************
* @attention
*
* Copyright (c) 2023 Bixdo.
* All rights reserved.
******************************************************************************
*/
#include "ALLinclude.h"
TIM_HandleTypeDef TimHandle1;
TIM_OC_InitTypeDef sConfig1;
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_MasterConfigTypeDef sMasterConfig;
static void co_delay_100us(uint32_t timer)
{
uint32_t timerdelay =timer*100;
while(timerdelay)
{
timerdelay--;
}
}
void UVDriveInit(uint32_t PeriodValue,uint32_t DutyValue)
{
TimHandle1.Instance = TIM1; /* Select TIM1 */
TimHandle1.Init.Period = 100-1; /* Auto reload value */
TimHandle1.Init.Prescaler = (96000000/100/PeriodValue)-1; /* Prescaler800-1 */
TimHandle1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; /* Clock division: tDTS=tCK_INT */
TimHandle1.Init.CounterMode = TIM_COUNTERMODE_UP; /* CounterMode:Up */
TimHandle1.Init.RepetitionCounter = 1 - 1; /* repetition counter value:1-1 */
TimHandle1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; /* TIM1_ARR register is not buffered */
/* Initializes the TIM PWM Time Base */
if (HAL_TIM_PWM_Init(&TimHandle1) != HAL_OK)
{
APP_ErrorHandler();
}
// if (HAL_TIM_Base_Init(&TimHandle1) != HAL_OK)
// {
// APP_ErrorHandler();
// }
//PWM通道参数
sConfig1.OCMode = TIM_OCMODE_PWM1; /* Set as PWM1 mode */
sConfig1.OCPolarity = TIM_OCPOLARITY_HIGH; /* OC channel active high */
sConfig1.OCFastMode = TIM_OCFAST_DISABLE; /* Output Compare fast disable */
sConfig1.OCNPolarity = TIM_OCNPOLARITY_LOW; /* OCN channel active low */
sConfig1.OCNIdleState = TIM_OCNIDLESTATE_RESET; /* OC1N channel idle state is low level */
sConfig1.OCIdleState = TIM_OCIDLESTATE_RESET; /* OC1 channel idle state is low level */
sConfig1.Pulse = DutyValue; /* TIM1_CCR2 value:20,duty cycle:20/50=40% */
/* Initializes the TIM PWM channel 2 */
if (HAL_TIM_PWM_ConfigChannel(&TimHandle1, &sConfig1, TIM_CHANNEL_3) != HAL_OK)
{
APP_ErrorHandler();
}
}
void StartUV(uint32_t PeriodValue,uint32_t DutyValue)
{
EN_UV;
UVDriveInit(PeriodValue*2,DutyValue/2);
if(HAL_TIM_PWM_Start(&TimHandle1, TIM_CHANNEL_3) != HAL_OK)
{
APP_ErrorHandler();
}
}
void StopUV(void)
{
Dis_UV;
if(HAL_TIM_PWM_Stop(&TimHandle1, TIM_CHANNEL_3) != HAL_OK)
{
APP_ErrorHandler();
}
}
// /**
// * @brief update interrupt callback
// * @param None
// * @retval None
// */
// void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htinm)
// {
// __HAL_TIM_CLEAR_FLAG(&TimHandle1,TIM_IT_CC1);
// __HAL_TIM_ENABLE_IT(&TimHandle1,TIM_IT_CC1);
// HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
// }
/*********************************************END OF FILE*********************************************/