2021-10-03 13:36:05 +03:00
|
|
|
/**
|
|
|
|
* @file input_i.h
|
|
|
|
* Input: internal API
|
|
|
|
*/
|
|
|
|
|
2021-02-10 11:56:05 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <furi.h>
|
2021-03-04 15:30:20 +03:00
|
|
|
#include <cli/cli.h>
|
2021-04-18 22:32:57 +03:00
|
|
|
#include <m-string.h>
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal_gpio.h>
|
2021-02-10 11:56:05 +03:00
|
|
|
|
|
|
|
#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
|
2021-06-02 15:51:05 +03:00
|
|
|
#define INPUT_PRESS_TICKS 150
|
|
|
|
#define INPUT_LONG_PRESS_COUNTS 2
|
2021-02-10 11:56:05 +03:00
|
|
|
#define INPUT_THREAD_FLAG_ISR 0x00000001
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Input pin state */
|
2021-02-10 11:56:05 +03:00
|
|
|
typedef struct {
|
|
|
|
const InputPin* pin;
|
|
|
|
// State
|
|
|
|
volatile bool state;
|
|
|
|
volatile uint8_t debounce;
|
2022-07-20 13:56:33 +03:00
|
|
|
FuriTimer* press_timer;
|
2021-04-18 22:32:57 +03:00
|
|
|
volatile uint8_t press_counter;
|
2021-09-02 00:05:00 +03:00
|
|
|
volatile uint32_t counter;
|
2021-02-10 11:56:05 +03:00
|
|
|
} InputPinState;
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Input state */
|
2021-02-10 11:56:05 +03:00
|
|
|
typedef struct {
|
2022-06-20 17:54:48 +03:00
|
|
|
FuriThreadId thread_id;
|
2021-11-01 23:35:54 +03:00
|
|
|
FuriPubSub* event_pubsub;
|
2021-02-10 11:56:05 +03:00
|
|
|
InputPinState* pin_states;
|
2021-03-04 15:30:20 +03:00
|
|
|
Cli* cli;
|
2021-09-02 00:05:00 +03:00
|
|
|
volatile uint32_t counter;
|
2021-02-10 11:56:05 +03:00
|
|
|
} Input;
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Input press timer callback */
|
2021-02-10 11:56:05 +03:00
|
|
|
void input_press_timer_callback(void* arg);
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Input interrupt handler */
|
2021-04-29 11:51:48 +03:00
|
|
|
void input_isr(void* _ctx);
|
2022-02-16 14:15:40 +03:00
|
|
|
|
|
|
|
/** Input CLI command handler */
|
|
|
|
void input_cli(Cli* cli, string_t args, void* context);
|