2021-02-10 08:56:05 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "input.h"
|
2021-04-18 19:32:57 +00:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <timers.h>
|
2021-02-10 08:56:05 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <furi.h>
|
2021-03-04 12:30:20 +00:00
|
|
|
#include <cli/cli.h>
|
2021-04-18 19:32:57 +00:00
|
|
|
#include <m-string.h>
|
2021-04-29 08:51:48 +00:00
|
|
|
#include <api-hal-gpio.h>
|
2021-02-10 08:56:05 +00:00
|
|
|
|
|
|
|
#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
|
2021-04-18 19:32:57 +00:00
|
|
|
#define INPUT_PRESS_TICKS 200
|
|
|
|
#define INPUT_LONG_PRESS_COUNTS 4
|
2021-02-10 08:56:05 +00:00
|
|
|
#define INPUT_THREAD_FLAG_ISR 0x00000001
|
|
|
|
|
|
|
|
/* Input pin state */
|
|
|
|
typedef struct {
|
|
|
|
const InputPin* pin;
|
|
|
|
// State
|
|
|
|
volatile bool state;
|
|
|
|
volatile uint8_t debounce;
|
|
|
|
volatile osTimerId_t press_timer;
|
2021-04-18 19:32:57 +00:00
|
|
|
volatile uint8_t press_counter;
|
2021-02-10 08:56:05 +00:00
|
|
|
} InputPinState;
|
|
|
|
|
|
|
|
/* Input state */
|
|
|
|
typedef struct {
|
|
|
|
osThreadId_t thread;
|
|
|
|
PubSub event_pubsub;
|
|
|
|
InputPinState* pin_states;
|
2021-03-04 12:30:20 +00:00
|
|
|
Cli* cli;
|
2021-02-10 08:56:05 +00:00
|
|
|
} Input;
|
|
|
|
|
|
|
|
/* Input press timer callback */
|
|
|
|
void input_press_timer_callback(void* arg);
|
|
|
|
|
|
|
|
/* Input interrupt handler */
|
2021-04-29 08:51:48 +00:00
|
|
|
void input_isr(void* _ctx);
|