commit 223d40ce8e4525cf28c2344e00b50384d29f9431 Author: cfif Date: Wed Dec 4 13:10:48 2024 +0300 Init diff --git a/Inc/UserInput.h b/Inc/UserInput.h new file mode 100644 index 0000000..76ef19d --- /dev/null +++ b/Inc/UserInput.h @@ -0,0 +1,46 @@ +/* + * UserInput.h + * + * Created on: Jun 3, 2021 + * Author: zemon + */ + +#ifndef USER_INPUT_INC_USERINPUT_H_ +#define USER_INPUT_INC_USERINPUT_H_ + +#include "UserInputButtonWatcher.h" + +typedef struct { + tGpioPin additional; + tGpioPin emergency; +} tUserInputPins; + +typedef enum { + UI_BUTTON_EMERGENCY, + UI_BUTTON_ADDITIONAL, +} eUserInputButtonIds; + +typedef struct { + struct { + tUserInputButtonWatch watches[2]; + } mem; + tUserInputButtonWatcher watcher; + tUserButtonsInterface buttonsInterface; + + struct { + osThreadId_t id; + uint32_t stack[512]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; +} tUserInput; + + +void UserInput_Init( + tUserInput *env, + tUserInputPins *userInputPins +); + +void UserInput_StartThread(tUserInput *env); + +#endif /* USER_INPUT_INC_USERINPUT_H_ */ diff --git a/Src/UserInput.c b/Src/UserInput.c new file mode 100644 index 0000000..fa4f6f9 --- /dev/null +++ b/Src/UserInput.c @@ -0,0 +1,44 @@ +/* + * UserInput.c + * + * Created on: Jun 3, 2021 + * Author: zemon + */ + +#include "UserInput.h" +#include +#include + +void UserInput_Init( + tUserInput *env, + tUserInputPins *pins +) { + UserInputButtonWatcher_InitStatic(&env->watcher, env->mem.watches, 128); + UserInputButtonWatcher_Add(&env->watcher, pins->emergency, UI_BUTTON_EMERGENCY); + UserInputButtonWatcher_Add(&env->watcher, pins->additional, UI_BUTTON_ADDITIONAL); + env->buttonsInterface = UserInputButtonWatcher_GetInterface(&env->watcher); + + InitThreadAtrStatic(&env->thread.attr, "UserInput", env->thread.controlBlock, env->thread.stack, osPriorityNormal); + env->thread.id = 0; +} + +static _Noreturn void UserInput_Thread(tUserInput *env) { + for (;;) { + UserInputButtonWatcher_Check(&env->watcher); + SystemDelayMs(5); + } +} + +void UserInput_StartThread(tUserInput *env) { + if (!env->thread.id) { + env->thread.id = osThreadNew((osThreadFunc_t) (UserInput_Thread), (void *) (env), &env->thread.attr); + } else { + osThreadResume(env->thread.id); + } +} + +void UserInput_Suspend(tUserInput *env) { + if (env->thread.id) { + osThreadSuspend(env->thread.id); + } +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..44ef617 --- /dev/null +++ b/modular.json @@ -0,0 +1,22 @@ +{ + "dep": [ + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "UserInputWatchButtons" + }, + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "GpioPinInterface" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file