Merge pull request 'add tim and lamp bar source' (#57) from T6_O1L into master
Reviewed-on: https://gitea.yunhorn.com/sundp/WLE5CC_NODE_STS/pulls/57
This commit is contained in:
commit
38018f0943
|
@ -0,0 +1,125 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : sts_lamp_bar.h
|
||||
* @brief : Header for sts_lamp_bar.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STS_LAMP_BAR_H
|
||||
#define __STS_LAMP_BAR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define DEFAULT_SATURATION 50 // 0 - 100 S:Saturation, 0~100
|
||||
#define DEFAULT_BRIGHTNESS 50 // 0 - 100 V:Value of lightness, 0~100
|
||||
#define DEFAULT_LUMINANCE_LEVEL (30)
|
||||
#define STS_Status_Door_Close (0) //Normal Close NC:Open **2024-07-15 changed
|
||||
#define STS_Status_Door_Open (1) //Normal Close NC:Close **2024-07-15 changed
|
||||
#define STS_Status_SOS_Pushdown (0) //Normal Open NO:Open
|
||||
#define STS_Status_SOS_Release (1) //Normal Open NO:Close
|
||||
#define STS_Status_Alarm_Mute_Pushdown (0) //Normal Open NO:Open
|
||||
#define STS_Status_Alarm_Mute_Release (1) //Normal Open NO:Close#
|
||||
#define STS_Status_Alarm_Reset_Pushdown (0) //Normal Open NO:Open
|
||||
#define STS_Status_Alarm_Reset_Release (1) //Normal Open NO:Close#
|
||||
|
||||
enum sts_lamp_color {
|
||||
STS_DARK = 0, //灭:0, Code 0x00
|
||||
STS_GREEN, //绿:1 0 1 0 code 0x01 0b0000 0001
|
||||
STS_RED, //红:2 1 0 0 code 0x02 0b0000 0010
|
||||
STS_BLUE, //蓝:3 0 0 1 code 0x03 0b0000 0011
|
||||
STS_YELLOW, //黄:4 1 1 0 code 0x04 0b0000 0100
|
||||
STS_PINK, //紫:5 1 0 1 code 0x05 0b0000 0101
|
||||
STS_CYAN, //青:6 0 1 1 code 0x06 0b0000 0110
|
||||
STS_WHITE, //白:7 1 1 1 code 0x07 0b0000 0111
|
||||
STS_COLOR_MAX, //8: MAX NUM OF COLORS 0x08 0b0000 1000
|
||||
|
||||
STS_GREEN_DARK=0x10, //0b0001 0000 GREEN DARK
|
||||
STS_RED_DARK=0x20, //0b0010 0000,
|
||||
STS_RED_GREEN=0x21,
|
||||
STS_RED_BLUE=0x23, //0b0010 0011 RED BLUE FLASH
|
||||
STS_BLUE_DARK=0x30, //0b0011 0000 BLUE DARK
|
||||
STS_BLUE_GREEN=0x31,
|
||||
|
||||
STS_GREENDARK=0x41, // GREEN FLASH 'A'
|
||||
STS_REDDARK=0x42, // RED FLASH 'B'
|
||||
STS_REDBLUE=0x43, // RED/BLUE FLASH 'C'
|
||||
STS_BLUEDARK=0x44, // BLUE FLASH 'D'
|
||||
STS_REDGREEN=0x45, // RED/GREEN FLASH 'E'
|
||||
STS_BLUEGREEN=0x46 // BLUE/GREEN FLASH 'F'
|
||||
};
|
||||
|
||||
enum sts_oo_work_mode {
|
||||
STS_NETWORK_MODE = 0, // 0 NETWORK MODE
|
||||
STS_WIRED_MODE, // 1 WIRED MODE === WATER LEAKAGE, SOAP CAPACITY SENSOR MODE
|
||||
STS_REEDSWITCH_MODE, // 2 REED SWITCH ONLY
|
||||
STS_RSS_MODE, // 3 RSS ONLY
|
||||
STS_DUAL_MODE, // 4 RSS + REED SWITCH IN ONE UNIT
|
||||
STS_UNI_MODE, // 5 DUAL_MODE + FALL DETECTION
|
||||
STS_REMOTE_REED_RSS_MODE, // 6 REMOTE REED SWITCH + RSS MODE 2023-05-04
|
||||
STS_DUAL_RSS_MODE, // 7 RSS_1 + RSS_2 IN TWO UNITS
|
||||
STS_TOF_RSS_MODE, // 8 TOF + RSS MODE
|
||||
STS_TOF_DISTANCE_MODE, // 9 TOF DISTANCE
|
||||
STS_TOF_PRESENCE_MODE, // A TOF PRESENCE OCCUPANCY
|
||||
STS_TOF_IN_OUT_MODE, // B TOF IN OUT COUNT
|
||||
STS_FALL_DETECTION_MODE, // C FALL DETECTION
|
||||
|
||||
STS_OTHER_MODE // ? OTHER MODE
|
||||
};
|
||||
#if defined(STS_O7)||defined(STS_O6)
|
||||
#define STS_Reed_Hall_State HALL1_STATE
|
||||
#define STS_Emergency_Button_State HALL2_STATE
|
||||
#else
|
||||
#define STS_Reed_Hall_State HAL_GPIO_ReadPin(BUT1_GPIO_Port, BUT1_Pin)
|
||||
#endif
|
||||
//void STS_Lamp_Bar_All(uint8_t lamp_color, uint8_t luminance_level);
|
||||
void STS_Lamp_Bar_Set_Color(uint8_t red, uint8_t green, uint8_t blue );
|
||||
void STS_Lamp_Bar_Set_RGB(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void STS_Lamp_Bar_Set_RGB_Color(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void STS_Lamp_Bar_Init(void);
|
||||
void STS_Lamp_Bar_Full_Color_Gradient(void);
|
||||
void STS_WS2812B_Refresh(void);
|
||||
void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx);
|
||||
void STS_Reed_Hall_Working(void);
|
||||
void STS_Lamp_Bar_Self_Test_Simple(void);
|
||||
void STS_Lamp_Bar_Self_Test(void);
|
||||
void STS_Lamp_Bar_Set_Dark(void);
|
||||
void sts_rgb_unit_test(void);
|
||||
void STS_Reed_Hall_Presence_Detection(void);
|
||||
|
||||
void STS_RSS_Smart_Presence_Detection(void);
|
||||
void STS_RSS_Smart_Presence(void);
|
||||
|
||||
void STS_Combined_Status_Processing(void);
|
||||
|
||||
// Before Join LoRa-WAN Network
|
||||
void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t luminance_level);
|
||||
// Occupancy Status, Set Color to STS_RED
|
||||
// Vacant Status, Set Color to STS_GREEN
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t luminance_level);
|
||||
void STS_Lamp_Bar_Refresh(void);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _STS_LAMP_BAR_H */
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file tim.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the tim.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TIM_H__
|
||||
#define __TIM_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
void MX_TIM1_Init(void);
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TIM_H__ */
|
||||
|
|
@ -0,0 +1,284 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file yunhorn_sts_lamp_bar.c *
|
||||
* @author Yunhorn (r) Technology Limited Application Team *
|
||||
* @brief Yunhorn (r) SmarToilets (r) Product configuration file. *
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 Yunhorn Technology Limited.
|
||||
* Copyright (c) 2022 Shenzhen Yunhorn Technology Co., Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
#include "main.h"
|
||||
#include "dma.h"
|
||||
#include "tim.h"
|
||||
#include "string.h"
|
||||
#include "sys_app.h"
|
||||
#include "stm32_systime.h"
|
||||
#include "sts_lamp_bar.h"
|
||||
|
||||
#include "yunhorn_sts_sensors.h"
|
||||
|
||||
#define ONE_PULSE (40) //36
|
||||
#define ZERO_PULSE (20)
|
||||
|
||||
#define LED_DATA_LEN 24
|
||||
#define WS2812B_DATA_LEN (LED_DATA_LEN * (STS_LAMP_BAR_LED_NUM))
|
||||
#define RESET_PULSE (24) //(80) TO FIX DARK_COLOR AND SM2
|
||||
|
||||
|
||||
typedef struct ws2812b_e {
|
||||
//uint16_t head[3];
|
||||
uint16_t GRB[WS2812B_DATA_LEN];
|
||||
uint16_t tail;
|
||||
} WS2812B_FrameTypeDef;
|
||||
|
||||
volatile WS2812B_FrameTypeDef rgb_buf = {
|
||||
// .head[0] = 0,
|
||||
// .head[1] = 0,
|
||||
// .head[2] = 0,
|
||||
.tail = 0
|
||||
};
|
||||
|
||||
uint8_t color_rgb[8][3] = { //STS_COLOR R G B MAPPING TABLE
|
||||
{0,0,0},{0,1,0},{1,0,0},{0,0,1},{1,1,0},{1,0,1},{0,1,1},{1,1,1}
|
||||
};
|
||||
extern volatile uint8_t sts_service_mask;
|
||||
extern volatile uint8_t sts_work_mode;
|
||||
volatile uint8_t sts_reed_hall_ext_int = 0;
|
||||
volatile uint8_t sts_status_color = STS_GREEN;
|
||||
volatile uint8_t sts_lamp_bar_color = STS_GREEN; //puColor
|
||||
volatile uint8_t sts_lamp_bar_flashing_color = STS_RED_DARK; //0x23; RED_BLUE;
|
||||
volatile uint8_t sts_cloud_netcolor = STS_GREEN; //netColor
|
||||
extern volatile uint8_t sts_occupancy_status;
|
||||
|
||||
extern volatile uint8_t sts_reed_hall_result, sts_emergency_button_pushed; // inital 0 = close
|
||||
volatile uint8_t sts_hall1_read=STS_Status_Door_Open,sts_hall2_read=STS_Status_SOS_Release; // Above hall1_read == reed_hall_result, hall2_read == emergency_button
|
||||
volatile uint8_t sts_hall3_read=STS_Status_Alarm_Mute_Release,sts_hall4_read=STS_Status_Alarm_Reset_Release;
|
||||
extern volatile uint8_t sts_reed_hall_1_result, sts_reed_hall_2_result;
|
||||
extern volatile uint8_t sts_tof_result_changed_flag;
|
||||
|
||||
|
||||
|
||||
extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag;
|
||||
extern volatile uint8_t sts_rss_result;
|
||||
extern volatile uint8_t sts_rss_2nd_result; //2nd RSS sensor status
|
||||
extern volatile uint8_t sts_tof_result;
|
||||
|
||||
|
||||
volatile uint8_t last_lamp_bar_color=STS_GREEN;
|
||||
extern volatile uint8_t sts_presence_fall_detection;
|
||||
extern volatile uint8_t sts_fall_rising_detected_result;
|
||||
extern volatile float sts_presence_rss_distance;
|
||||
extern volatile uint8_t sensor_data_ready;
|
||||
extern SysTime_t mems_event_time;
|
||||
extern volatile uint32_t event_start_time, event_stop_time;
|
||||
extern volatile uint32_t event_door_lock_start_time, event_door_lock_stop_time;
|
||||
volatile uint8_t luminance_level = DEFAULT_LUMINANCE_LEVEL;
|
||||
|
||||
|
||||
void STS_Lamp_Bar_Set_Dark(void)
|
||||
{
|
||||
for (uint8_t i=0; i< STS_LAMP_BAR_LED_NUM; i++)
|
||||
{
|
||||
STS_WS2812B_Set_RGB(0x00,0x00,0x00,i);
|
||||
|
||||
}
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
|
||||
void STS_WS2812B_Refresh(void)
|
||||
{
|
||||
|
||||
HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)&rgb_buf, (WS2812B_DATA_LEN+RESET_PULSE));
|
||||
//HAL_TIM_PWM_Start_IT(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL);
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Init(void)
|
||||
{
|
||||
if (sts_service_mask == STS_SERVICE_MASK_L0)
|
||||
{
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(STS_GREEN, luminance_level);
|
||||
|
||||
HAL_Delay(200);
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(STS_RED, luminance_level);
|
||||
|
||||
HAL_Delay(200);
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(STS_BLUE, luminance_level);
|
||||
|
||||
HAL_Delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
//marquee scoller
|
||||
void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t lum_level)
|
||||
{
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
|
||||
for(uint8_t i = 0; i<STS_LAMP_BAR_LED_NUM; i++)
|
||||
{
|
||||
HAL_Delay(30); //MAKE THIS LESS THAN 10 NOT TO BLOCK JOIN THE LORAWAN
|
||||
STS_WS2812B_Set_RGB(color_rgb[color][0]*lum_level,color_rgb[color][1]*lum_level, color_rgb[color][2]*lum_level, i);
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void STS_WS2812B_Set_RGB(uint8_t red, uint8_t green, uint8_t blue, uint8_t idx)
|
||||
{
|
||||
for (uint8_t j = 0; j < 8; j ++)
|
||||
{
|
||||
rgb_buf.GRB[idx*24+j] = (uint16_t)(((green<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+8+j] = (uint16_t)(((red<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[idx*24+16+j] = (uint16_t)(((blue<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
}
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Set_RGB_Color(uint8_t red, uint8_t green, uint8_t blue )
|
||||
{
|
||||
uint8_t i =0;
|
||||
UTIL_MEM_set_8((void*)rgb_buf.GRB,0x00,(WS2812B_DATA_LEN+RESET_PULSE));
|
||||
|
||||
for(i = 0; i < STS_LAMP_BAR_LED_NUM; i++)
|
||||
{
|
||||
for (uint8_t j = 0; j < 8; j ++)
|
||||
{
|
||||
rgb_buf.GRB[i*24+j] = (uint16_t)(((green<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[i*24+8+j] = (uint16_t)(((red<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[i*24+16+j] = (uint16_t)(((blue<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
}
|
||||
}
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Refresh(void)
|
||||
{
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, luminance_level);
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum)
|
||||
{
|
||||
if (sts_lamp_color <=8)
|
||||
{
|
||||
switch (sts_lamp_color)
|
||||
{
|
||||
case STS_DARK:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0);
|
||||
break;
|
||||
case STS_GREEN:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, lum, 0x0);
|
||||
break;
|
||||
case STS_RED:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, 0x0, 0x0);
|
||||
break;
|
||||
case STS_BLUE:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, lum);
|
||||
break;
|
||||
case STS_YELLOW:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, lum, 0x0);
|
||||
break;
|
||||
case STS_PINK:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, 0x0, lum);
|
||||
break;
|
||||
case STS_CYAN:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, lum, lum);
|
||||
break;
|
||||
case STS_WHITE:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, lum, lum);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
__HAL_TIM_SetCompare(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL,0);
|
||||
HAL_TIM_PWM_Stop_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL);
|
||||
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Self_Test_Simple(void)
|
||||
{
|
||||
uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL;
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Lumianance Level Testing Start\r\n");
|
||||
for (color=STS_GREEN; color < STS_COLOR_MAX; color++)
|
||||
{
|
||||
lum_level = 10;
|
||||
do {
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(color, lum_level);
|
||||
HAL_Delay(50);
|
||||
lum_level += 20;
|
||||
} while (lum_level < 99);
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
}
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Lumianance Level Testing Finished\r\n");
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Self_Test(void)
|
||||
{
|
||||
uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL;
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n YunHorn STS Indicative Lamp Self Test\r\n");
|
||||
|
||||
//STS_Lamp_Bar_Self_Test_Simple();
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#2] Scoller Testing\r\n");
|
||||
lum_level=50;
|
||||
for (color = STS_GREEN; color < STS_COLOR_MAX; color++)
|
||||
{
|
||||
STS_Lamp_Bar_Scoller(color, lum_level);
|
||||
}
|
||||
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n [##] YunHorn STS Indicative Lamp Self Test Finished\r\n");
|
||||
if ((sts_work_mode == STS_WIRED_MODE) )
|
||||
{
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
} else
|
||||
{
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(STS_GREEN, lum_level);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void sts_rgb_unit_test(void)
|
||||
{
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n STS Lamp Bar Init...\r\n");
|
||||
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
|
||||
STS_Lamp_Bar_Full_Color_Gradient();
|
||||
|
||||
STS_Lamp_Bar_Self_Test();
|
||||
|
||||
do {
|
||||
for (uint8_t i=0; i<9; i++)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n STS Lamp Bar color = %d...\r\n", i);
|
||||
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(i, luminance_level);
|
||||
STS_Combined_Status_Processing();
|
||||
HAL_Delay(6000);
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
}
|
||||
} while(1);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file tim.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the TIM instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "tim.h"
|
||||
#include "main.h"
|
||||
/* USER CODE BEGIN 0 */
|
||||
TIM_HandleTypeDef htim1;
|
||||
|
||||
DMA_HandleTypeDef hdma_tim1_ch1; //PA8 WS2812B
|
||||
|
||||
//DMA_HandleTypeDef hdma_tim1_ch2; //PA9 WS2812B
|
||||
|
||||
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* TIM1 init function */
|
||||
void MX_TIM1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 1 */
|
||||
|
||||
/* USER CODE END TIM1_Init 1 */
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 0;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = STS_LAMP_BAR_PWM_TIM_PERIOD;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;//TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; //TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#if 1
|
||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||
sBreakDeadTimeConfig.DeadTime = 0;
|
||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.BreakFilter = 0;
|
||||
sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;
|
||||
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
|
||||
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.Break2Filter = 0;
|
||||
sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#endif
|
||||
/* USER CODE BEGIN TIM1_Init 2 */
|
||||
|
||||
/* USER CODE END TIM1_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim1);
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
{
|
||||
|
||||
if(tim_baseHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 0 */
|
||||
/* TIM1 clock enable */
|
||||
__HAL_RCC_TIM1_CLK_ENABLE();
|
||||
|
||||
/* TIM1 DMA Init */
|
||||
/* TIM1_CH1 Init */
|
||||
hdma_tim1_ch1.Instance = DMA1_Channel1;
|
||||
|
||||
hdma_tim1_ch1.Init.Request = DMA_REQUEST_TIM1_CH1;
|
||||
hdma_tim1_ch1.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||||
hdma_tim1_ch1.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_tim1_ch1.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_tim1_ch1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||||
hdma_tim1_ch1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; //DMA_MDATAALIGN_HALFWORD; //DMA_MDATAALIGN_HALFWORD;
|
||||
hdma_tim1_ch1.Init.Mode = DMA_CIRCULAR;
|
||||
hdma_tim1_ch1.Init.Priority = DMA_PRIORITY_HIGH; //was HIGH
|
||||
|
||||
if (HAL_DMA_Init(&hdma_tim1_ch1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#ifdef STM32WL55xx
|
||||
if (HAL_DMA_ConfigChannelAttributes(&hdma_tim1_ch1, DMA_CHANNEL_NPRIV) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
#endif
|
||||
__HAL_LINKDMA(tim_baseHandle,hdma[TIM_DMA_ID_CC1],hdma_tim1_ch1);
|
||||
|
||||
/* USER CODE BEGIN TIM1_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(timHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 0 */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM1 GPIO Configuration
|
||||
PA8 ------> TIM1_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP; //GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN TIM1_MspPostInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
{
|
||||
|
||||
if(tim_baseHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM1_CLK_DISABLE();
|
||||
|
||||
/* TIM1 DMA DeInit */
|
||||
HAL_DMA_DeInit(tim_baseHandle->hdma[TIM_DMA_ID_CC1]);
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
Loading…
Reference in New Issue