reflow-oven-control-sw/stm-firmware/include/reflow-controller/ui/button.h

82 lines
2.0 KiB
C
Raw Permalink Normal View History

/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BUTTON_H__
#define __BUTTON_H__
2020-05-05 18:19:49 +02:00
/**
* @brief GPIO Port the button is connected to
*/
2020-02-23 21:48:52 +01:00
#define BUTTON_PORT GPIOD
2020-05-05 18:19:49 +02:00
/**
* @brief The RCC clock mask for @ref BUTTON_PORT
*/
2020-02-23 21:48:52 +01:00
#define BUTTON_RCC_MASK RCC_AHB1ENR_GPIODEN
2020-05-05 18:19:49 +02:00
/**
* @brief The GPIO pin number the button is connected to
*/
2020-02-23 21:48:52 +01:00
#define BUTTON_PIN 4
2020-05-05 18:19:49 +02:00
/**
* @brief The time in ms the button has to stay pressed to be detected as a short press
*/
#define BUTTON_SHORT_ON_TIME_MS 50UL
2020-05-05 18:19:49 +02:00
/**
* @brief Time in ms the button has to be pressed to be counted as a long press
*/
#define BUTTON_LONG_ON_TIME_MS 400UL
2020-02-23 21:48:52 +01:00
2020-05-05 18:19:49 +02:00
#if BUTTON_LONG_ON_TIME_MS <= BUTTON_SHORT_ON_TIME_MS
#error "Button BUTTON_SHORT_ON_TIME_MS time has to be shorter than BUTTON_LONG_ON_TIME_MS"
#endif
/**
* @brief States the puhsbutton of the rotary encoder can be in
*/
2020-02-25 21:01:34 +01:00
enum button_state {BUTTON_IDLE = 0, BUTTON_SHORT_RELEASED, BUTTON_LONG_RELEASED, BUTTON_SHORT, BUTTON_LONG};
2020-02-23 21:48:52 +01:00
2020-05-05 18:19:49 +02:00
/**
* @brief Init the push button
*/
2020-02-23 21:48:52 +01:00
void button_init();
2020-05-05 18:19:49 +02:00
/**
* @brief read if a push button event occured
* @return Button event
*/
2020-02-23 21:48:52 +01:00
enum button_state button_read_event();
2020-05-05 18:19:49 +02:00
/**
* @brief button_deinit
*/
2020-02-23 21:48:52 +01:00
void button_deinit();
/**
* @brief This function overrides the button event.
* @param state State to set
*/
void button_override_event(enum button_state state);
2020-02-23 21:48:52 +01:00
#endif /* __BUTTON_H__ */