Init
This commit is contained in:
commit
223d40ce8e
|
|
@ -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_ */
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* UserInput.c
|
||||
*
|
||||
* Created on: Jun 3, 2021
|
||||
* Author: zemon
|
||||
*/
|
||||
|
||||
#include "UserInput.h"
|
||||
#include <SystemDelayInterface.h>
|
||||
#include <CmsisRtosThreadUtils.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue