diff --git a/diode_tester/Core/MyLibs/general_gpio.c b/diode_tester/Core/MyLibs/general_gpio.c new file mode 100644 index 0000000..f5799cd --- /dev/null +++ b/diode_tester/Core/MyLibs/general_gpio.c @@ -0,0 +1,128 @@ +/** + ************************************************************************** + * @file general_gpio.c + * @brief Модуль для инициализации портов. + ************************************************************************** + @verbatim + //-------------------Функции-------------------// + Functions: users + - GPIO_Clock_Enable Инициализация тактирования порта + @endverbatim +***************************************************************************/ +#include "general_gpio.h" + +//------------------------------------------------------------------- +//------------------------GPIO INIT FUNCTIONS------------------------ + +HAL_StatusTypeDef GPIO_Clock_Enable(GPIO_TypeDef *GPIOx) +{ + HAL_StatusTypeDef status = HAL_OK; + // choose port for enable clock + if (GPIOx==GPIOA) + __HAL_RCC_GPIOA_CLK_ENABLE(); + else if (GPIOx==GPIOB) + __HAL_RCC_GPIOB_CLK_ENABLE(); + else if (GPIOx==GPIOC) + __HAL_RCC_GPIOC_CLK_ENABLE(); +#ifdef GPIOD + else if (GPIOx==GPIOD) + __HAL_RCC_GPIOD_CLK_ENABLE(); +#endif +#ifdef GPIOE + else if (GPIOx==GPIOE) + __HAL_RCC_GPIOE_CLK_ENABLE(); +#endif + else + status = HAL_ERROR; + + return status; +} + +//------------------------GPIO INIT FUNCTIONS------------------------ +//------------------------------------------------------------------- + + +//------------------------------------------------------------------- +//------------------------GPIO LED FUNCTIONS------------------------- + +/** + * @brief Включить светодиод + */ +void GPIO_LED_On(GPIO_LEDTypeDef *led) +{ + led->state = LED_IS_ON; + HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, LED_ON); +} +/** + * @brief Выключить светодиод + */ +void GPIO_LED_Off(GPIO_LEDTypeDef *led) +{ + led->state = LED_IS_OFF; + HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, LED_OFF); +} + +/** + * @brief Активировать моргание светодиодом + */ +void GPIO_LED_Blink_Start(GPIO_LEDTypeDef *led, uint32_t period) +{ + led->state = LED_IS_BLINKING; + led->LED_Period = period; +} + +/** + * @brief Моргание светодиодом + */ +void GPIO_LED_Blink_Handle(GPIO_LEDTypeDef *led) +{ + if(led->state == LED_IS_BLINKING) + { + uint32_t tickcurrent = HAL_GetTick(); + if((tickcurrent - led->tickprev) > led->LED_Period) + { + HAL_GPIO_TogglePin(led->LED_Port, led->LED_Pin); + led->tickprev = tickcurrent; + } + } +} +//------------------------GPIO LED FUNCTIONS------------------------- +//------------------------------------------------------------------- + +//------------------------------------------------------------------- +//------------------------GPIO SW FUNCTIONS------------------------- + +/** + * @brief Считать состоянии кнопки запуска + */ +uint8_t GPIO_Read_Swich(GPIO_SwitchTypeDef *sw) +{ + + if(HAL_GPIO_ReadPin(sw->Sw_Port, sw->Sw_Pin) == SW_ON) + { + sw->Sw_PrevState = 1; + + if(sw->tickprev == 0) + sw->tickprev = HAL_GetTick(); + + if((HAL_GetTick() - sw->tickprev) > sw->Sw_FilterDelay) + { + if(HAL_GPIO_ReadPin(sw->Sw_Port, sw->Sw_Pin) == SW_ON) + { + return 1; + } + else + { + sw->tickprev = 0; + return 0; + } + } + } + else + { + sw->Sw_PrevState = 0; + } + return 0; +} +//------------------------GPIO SW FUNCTIONS------------------------- +//------------------------------------------------------------------- \ No newline at end of file diff --git a/diode_tester/Core/MyLibs/general_gpio.h b/diode_tester/Core/MyLibs/general_gpio.h new file mode 100644 index 0000000..e579fea --- /dev/null +++ b/diode_tester/Core/MyLibs/general_gpio.h @@ -0,0 +1,72 @@ +/** + ************************************************************************** + * @file general_gpio.h + * @brief Заголовочный файл для модуля инициализации портов. + *************************************************************************/ +#ifndef __GPIO_GENERAL_H_ +#define __GPIO_GENERAL_H_ + +#include "mylibs_defs.h" + + +#define SPI_Alternate_Mapping(INSTANCE) ((((INSTANCE) == TIM1) || ((INSTANCE) == TIM2))? GPIO_AF1_TIM1: \ + (((INSTANCE) == TIM3) || ((INSTANCE) == TIM4) || ((INSTANCE) == TIM5))? GPIO_AF2_TIM3: \ + (((INSTANCE) == TIM8) || ((INSTANCE) == TIM9) || ((INSTANCE) == TIM10) || ((INSTANCE) == TIM11))? GPIO_AF3_TIM8: \ + (((INSTANCE) == TIM12) || ((INSTANCE) == TIM13) || ((INSTANCE) == TIM14))? GPIO_AF9_TIM12: \ + (0)) + + +#define TIM_Alternate_Mapping(INSTANCE) ((((INSTANCE) == TIM1) || ((INSTANCE) == TIM2))? GPIO_AF1_TIM1: \ + (((INSTANCE) == TIM3) || ((INSTANCE) == TIM4) || ((INSTANCE) == TIM5))? GPIO_AF2_TIM3: \ + (((INSTANCE) == TIM8) || ((INSTANCE) == TIM9) || ((INSTANCE) == TIM10) || ((INSTANCE) == TIM11))? GPIO_AF3_TIM8: \ + (((INSTANCE) == TIM12) || ((INSTANCE) == TIM13) || ((INSTANCE) == TIM14))? GPIO_AF9_TIM12: \ + (0)) + + +typedef enum +{ + LED_IS_OFF = 0, + LED_IS_ON = 1, + LED_IS_BLINKING = 2, + LED_IS_FADING = 3, +}GPIO_LEDStateTypeDef; + +typedef struct +{ + GPIO_LEDStateTypeDef state; + + GPIO_TypeDef *LED_Port; + uint32_t LED_Pin; + + uint32_t LED_Period; + uint32_t tickprev; +}GPIO_LEDTypeDef; + +typedef struct +{ + GPIO_TypeDef *Sw_Port; + uint32_t Sw_Pin; + + uint32_t Sw_PrevState; + uint32_t Sw_FilterDelay; + uint32_t tickprev; +}GPIO_SwitchTypeDef; + +///////////////////////////////////////////////////////////////////// +///////////////////////////---FUNCTIONS---/////////////////////////// +HAL_StatusTypeDef GPIO_Clock_Enable(GPIO_TypeDef *GPIOx); + +/* Считать состоянии кнопки запуска */ +uint8_t GPIO_Read_Swich(GPIO_SwitchTypeDef *swstart); +/* Включить светодиод */ +void GPIO_LED_On(GPIO_LEDTypeDef *led); +/* Выключить светодиод */ +void GPIO_LED_Off(GPIO_LEDTypeDef *led); +/* Активировать моргание светодиодом */ +void GPIO_LED_Blink_Start(GPIO_LEDTypeDef *led, uint32_t period); +/* Моргание светодиодом */ +void GPIO_LED_Blink_Handle(GPIO_LEDTypeDef *led); +///////////////////////////---FUNCTIONS---/////////////////////////// + + +#endif // __GPIO_GENERAL_H_ diff --git a/diode_tester/Core/MyLibs/mylibs_include.h b/diode_tester/Core/MyLibs/mylibs_include.h index 4404540..4785078 100644 --- a/diode_tester/Core/MyLibs/mylibs_include.h +++ b/diode_tester/Core/MyLibs/mylibs_include.h @@ -64,6 +64,7 @@ #include "main.h" #include "modbus_data.h" +#include "general_gpio.h" /** @brief Struct for trackers for Measure */ /** @brief Struct for trackers for RS */ diff --git a/diode_tester/Core/Tester_main/tester_interface_func.c b/diode_tester/Core/Tester_main/tester_interface_func.c index da63284..2666d64 100644 --- a/diode_tester/Core/Tester_main/tester_interface_func.c +++ b/diode_tester/Core/Tester_main/tester_interface_func.c @@ -4,108 +4,37 @@ /** * @brief Инициализация структур интерфейса */ -void TESTER_InterfaceInit(TESTER_SwitchStartTypeDef *swstart, TESTER_LEDsTypeDef *leds) +void TESTER_InterfaceInit(GPIO_SwitchTypeDef *swstart, TESTER_LEDsTypeDef *leds) { } /** * @brief Включить индикацию таймаута старта при активации теста */ -void TESTER_LED_TimeoutForStartTest(TESTER_LEDTypeDef *led) +void TESTER_LED_TimeoutForStartTest(GPIO_LEDTypeDef *led) { - TESTER_LED_Off(led); + GPIO_LED_Off(led); } /** * @brief Включить индикацию прямого подключения диода */ -void TESTER_LED_TestingDiodeForward(TESTER_LEDTypeDef *led) +void TESTER_LED_TestingDiodeForward(GPIO_LEDTypeDef *led) { - led->state = LED_IS_BLINKING; - led->period = LED_FORWARD_DIODE_PERIOD; + GPIO_LED_Blink_Start(led, LED_FORWARD_DIODE_PERIOD); } /** * @brief Включить индикацию обратного подключения диода */ -void TESTER_LED_TestingDiodeReverse(TESTER_LEDTypeDef *led) +void TESTER_LED_TestingDiodeReverse(GPIO_LEDTypeDef *led) { - led->state = LED_IS_BLINKING; - led->period = LED_REVERSE_DIODE_PERIOD; + GPIO_LED_Blink_Start(led, LED_REVERSE_DIODE_PERIOD); } /** * @brief Выключить индикацию ожидания комманды * @details Сделано через моргание, чтобы понимать, что системные тики работают */ -void TESTER_LED_WaitForAction(TESTER_LEDTypeDef *led) +void TESTER_LED_WaitForAction(GPIO_LEDTypeDef *led) { - led->state = LED_IS_BLINKING; - led->period = LED_BLINK_AS_ON; -} - - -/** - * @brief Считать состоянии кнопки запуска - */ -uint8_t TESTER_ReadSwichStart(TESTER_SwitchStartTypeDef *swstart) -{ - - if(HAL_GPIO_ReadPin(swstart->Sw_Port, swstart->Sw_Pin) == SW_ON) - { - if(swstart->tickprev == 0) - swstart->tickprev = HAL_GetTick(); - - if((HAL_GetTick() - swstart->tickprev) > swstart->Sw_FilterDelay) - { - if(HAL_GPIO_ReadPin(swstart->Sw_Port, swstart->Sw_Pin) == SW_ON) - { - return 1; - } - else - { - swstart->tickprev = 0; - return 0; - } - } - } - return 0; -} -/** - * @brief Включить светодиод - */ -void TESTER_LED_On(TESTER_LEDTypeDef *led) -{ - led->state = LED_IS_ON; - HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, LED_ON); -} -/** - * @brief Выключить светодиод - */ -void TESTER_LED_Off(TESTER_LEDTypeDef *led) -{ - led->state = LED_IS_OFF; - HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, LED_OFF); -} - -/** - * @brief Активировать моргание светодиодом - */ -void TESTER_LED_Blink_Start(TESTER_LEDTypeDef *led) -{ - led->state = LED_IS_BLINKING; -} - -/** - * @brief Моргание светодиодом - */ -void TESTER_LEDBlink_Handle(TESTER_LEDTypeDef *led) -{ - if(led->state == LED_IS_BLINKING) - { - uint32_t tickcurrent = HAL_GetTick(); - if((tickcurrent - led->tickprev) > led->period) - { - HAL_GPIO_TogglePin(led->LED_Port, led->LED_Pin); - led->tickprev = tickcurrent; - } - } + GPIO_LED_Blink_Start(led, LED_BLINK_AS_ON); } diff --git a/diode_tester/Core/Tester_main/tester_interface_func.h b/diode_tester/Core/Tester_main/tester_interface_func.h index 37cfd72..1e70b8e 100644 --- a/diode_tester/Core/Tester_main/tester_interface_func.h +++ b/diode_tester/Core/Tester_main/tester_interface_func.h @@ -14,64 +14,26 @@ #include "mylibs_include.h" #include "rs_message.h" -typedef enum -{ - LED_IS_OFF = 0, - LED_IS_ON = 1, - LED_IS_BLINKING = 2, -}TESTER_LEDStateTypeDef; - -typedef struct -{ - TESTER_LEDStateTypeDef state; - - GPIO_TypeDef *LED_Port; - uint32_t LED_Pin; - - uint32_t tickprev; - uint32_t period; -}TESTER_LEDTypeDef; typedef struct { - TESTER_LEDTypeDef LED1; + GPIO_LEDTypeDef LED1; }TESTER_LEDsTypeDef; -typedef struct -{ - GPIO_TypeDef *Sw_Port; - uint32_t Sw_Pin; - - uint32_t Sw_PrevState; - uint32_t Sw_FilterDelay; - uint32_t tickprev; -}TESTER_SwitchStartTypeDef; - - /* Инициализация структур интерфейса */ -void TESTER_InterfaceInit(TESTER_SwitchStartTypeDef *swstart, TESTER_LEDsTypeDef *leds); +void TESTER_InterfaceInit(GPIO_SwitchTypeDef *swstart, TESTER_LEDsTypeDef *leds); /* Включить индикацию таймаута старта при активации теста */ -void TESTER_LED_TimeoutForStartTest(TESTER_LEDTypeDef *led); +void TESTER_LED_TimeoutForStartTest(GPIO_LEDTypeDef *led); /* Включить индикацию прямого подключения диода */ -void TESTER_LED_TestingDiodeForward(TESTER_LEDTypeDef *led); +void TESTER_LED_TestingDiodeForward(GPIO_LEDTypeDef *led); /* Включить индикацию обратного подключения диода */ -void TESTER_LED_TestingDiodeReverse(TESTER_LEDTypeDef *led); +void TESTER_LED_TestingDiodeReverse(GPIO_LEDTypeDef *led); /* Выключить индикацию активного теста диодов */ -void TESTER_LED_WaitForAction(TESTER_LEDTypeDef *led); +void TESTER_LED_WaitForAction(GPIO_LEDTypeDef *led); -/* Считать состоянии кнопки запуска */ -uint8_t TESTER_ReadSwichStart(TESTER_SwitchStartTypeDef *swstart); -/* Включить светодиод */ -void TESTER_LED_On(TESTER_LEDTypeDef *led); -/* Выключить светодиод */ -void TESTER_LED_Off(TESTER_LEDTypeDef *led); -/* Активировать моргание светодиодом */ -void TESTER_LED_Blink_Start(TESTER_LEDTypeDef *led); -/* Моргание светодиодом */ -void TESTER_LEDBlink_Handle(TESTER_LEDTypeDef *led); #endif //_TESTER_INTERFACE_FUNC_H_ diff --git a/diode_tester/Core/Tester_main/tester_main.c b/diode_tester/Core/Tester_main/tester_main.c index 407bba3..c9d857c 100644 --- a/diode_tester/Core/Tester_main/tester_main.c +++ b/diode_tester/Core/Tester_main/tester_main.c @@ -10,7 +10,7 @@ TESTER_ProjectTypeDef TESTER = {0}; void TESTER_Init(TESTER_ProjectTypeDef *tester) { TESTER_InterfaceInit(&tester->SwStart, &tester->leds); - tester->leds.LED1.period = 100; + GPIO_LED_Blink_Start(&tester->leds.LED1, 100); tester->delay = 250; tester->delay_en = 0; @@ -34,9 +34,11 @@ void TESTER_pre_while(TESTER_ProjectTypeDef *tester) TESTER_UpdateSettings(tester->htest, tester->mbdata); RS_Receive_IT(tester->hmodbus, &MODBUS_MSG); - tester->leds.LED1.period = LED_BLINK_AS_ON; - tester->f.flag_init_done = 1; HAL_TIM_Base_Start(&hmcstim); + + + tester->f.flag_init_done = 1; + GPIO_LED_Blink_Start(&tester->leds.LED1, LED_BLINK_AS_ON); } @@ -123,7 +125,7 @@ void TESTER_InterfaceHandle(TESTER_ProjectTypeDef *tester) tester->mode = *((TESTER_TestModeTypeDef *)&tester->mbdata->Coils) & 0x3; /* если кнопка нажата или пришла соответствующая комманда модбас */ - if(TESTER_ReadSwichStart(&tester->SwStart) || tester->mbdata->Coils.StartTest) + if(GPIO_Read_Swich(&tester->SwStart) || tester->mbdata->Coils.StartTest) { tester->mbdata->Coils.StartTest = 0; /* Обновление настроек тестера */ @@ -148,7 +150,7 @@ void TESTER_InterfaceHandle(TESTER_ProjectTypeDef *tester) } - TESTER_LEDBlink_Handle(&tester->leds.LED1); + GPIO_LED_Blink_Handle(&tester->leds.LED1); } @@ -199,9 +201,7 @@ void TESTER_Set_Default_Settings(TESTER_ProjectTypeDef *tester) /* Настройка пинов для светодиода*/ tester->leds.LED1.LED_Port = LED1_Port; - tester->leds.LED1.LED_Pin = LED1_Pin; - tester->leds.LED1.period = LED_BLINK_AS_ON; - + tester->leds.LED1.LED_Pin = LED1_Pin; /* Настройка таймингов по умолчанию для тестирования */ tester->mbdata->HoldRegs.TimeForForward = DEF_MS_TIME_FOR_POSITIVE; diff --git a/diode_tester/Core/Tester_main/tester_main.h b/diode_tester/Core/Tester_main/tester_main.h index 9aa0bea..79528ef 100644 --- a/diode_tester/Core/Tester_main/tester_main.h +++ b/diode_tester/Core/Tester_main/tester_main.h @@ -59,7 +59,7 @@ typedef struct MB_DataStructureTypeDef *mbdata; - TESTER_SwitchStartTypeDef SwStart; ///< структура кнопки старта + GPIO_SwitchTypeDef SwStart; ///< структура кнопки старта TESTER_LEDsTypeDef leds; ///< структура светодиодов diff --git a/diode_tester/MDK-ARM/diode_tester.uvoptx b/diode_tester/MDK-ARM/diode_tester.uvoptx index bff4e9a..31a4b0e 100644 --- a/diode_tester/MDK-ARM/diode_tester.uvoptx +++ b/diode_tester/MDK-ARM/diode_tester.uvoptx @@ -576,7 +576,7 @@ MyLibs - 0 + 1 0 0 0 @@ -628,6 +628,30 @@ 0 0 + + 4 + 24 + 1 + 0 + 0 + 0 + ..\Core\MyLibs\general_gpio.c + general_gpio.c + 0 + 0 + + + 4 + 25 + 5 + 0 + 0 + 0 + ..\Core\MyLibs\general_gpio.h + general_gpio.h + 0 + 0 + @@ -638,7 +662,7 @@ 0 5 - 24 + 26 2 0 0 @@ -658,7 +682,7 @@ 0 6 - 25 + 27 1 0 0 @@ -670,7 +694,7 @@ 6 - 26 + 28 1 0 0 @@ -682,7 +706,7 @@ 6 - 27 + 29 1 0 0 @@ -694,7 +718,7 @@ 6 - 28 + 30 1 0 0 @@ -706,7 +730,7 @@ 6 - 29 + 31 1 0 0 @@ -718,7 +742,7 @@ 6 - 30 + 32 1 0 0 @@ -730,7 +754,7 @@ 6 - 31 + 33 1 0 0 @@ -742,7 +766,7 @@ 6 - 32 + 34 1 0 0 @@ -762,7 +786,7 @@ 0 7 - 33 + 35 1 0 0 @@ -774,7 +798,7 @@ 7 - 34 + 36 1 0 0 @@ -786,7 +810,7 @@ 7 - 35 + 37 1 0 0 @@ -798,7 +822,7 @@ 7 - 36 + 38 1 0 0 @@ -810,7 +834,7 @@ 7 - 37 + 39 1 0 0 @@ -822,7 +846,7 @@ 7 - 38 + 40 1 0 0 @@ -834,7 +858,7 @@ 7 - 39 + 41 1 0 0 @@ -846,7 +870,7 @@ 7 - 40 + 42 1 0 0 @@ -858,7 +882,7 @@ 7 - 41 + 43 1 0 0 @@ -870,7 +894,7 @@ 7 - 42 + 44 1 0 0 @@ -882,7 +906,7 @@ 7 - 43 + 45 1 0 0 @@ -894,7 +918,7 @@ 7 - 44 + 46 1 0 0 @@ -906,7 +930,7 @@ 7 - 45 + 47 1 0 0 @@ -918,7 +942,7 @@ 7 - 46 + 48 1 0 0 @@ -930,7 +954,7 @@ 7 - 47 + 49 1 0 0 @@ -942,7 +966,7 @@ 7 - 48 + 50 1 0 0 @@ -962,7 +986,7 @@ 0 8 - 49 + 51 1 0 0 diff --git a/diode_tester/MDK-ARM/diode_tester.uvprojx b/diode_tester/MDK-ARM/diode_tester.uvprojx index 0d49905..21f3185 100644 --- a/diode_tester/MDK-ARM/diode_tester.uvprojx +++ b/diode_tester/MDK-ARM/diode_tester.uvprojx @@ -515,6 +515,16 @@ 5 ..\Core\MyLibs\trackers.h + + general_gpio.c + 1 + ..\Core\MyLibs\general_gpio.c + + + general_gpio.h + 5 + ..\Core\MyLibs\general_gpio.h + diff --git a/docs/mb_adr.xlsx b/docs/mb_adr.xlsx index 926cf96..2fc0eec 100644 Binary files a/docs/mb_adr.xlsx and b/docs/mb_adr.xlsx differ