taler-xotp_fw

xOTP generator firmware
Log | Files | Refs | Submodules | README

inputInterface.h (4054B)


      1 /**
      2  * @file inputInterface.h
      3  * @author Adrian STEINER (steia19@bfh.ch)
      4  * @brief Interface to read out the keyboard from the current hardware
      5  * @version 0.1
      6  * @date 13-02-2025
      7  *
      8  * @copyright (C) 2025 Adrian STEINER
      9  * This program is free software: you can redistribute it and/or modify
     10  * it under the terms of the GNU General Public License as published by
     11  * the Free Software Foundation, either version 3 of the License, or
     12  * (at your option) any later version.
     13  *
     14  * This program is distributed in the hope that it will be useful,
     15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17  * GNU General Public License for more details.
     18  *
     19  * You should have received a copy of the GNU General Public License
     20  * along with this program.  If not, see <https: //www.gnu.org/licenses/>.
     21  *
     22  */
     23 
     24 #ifndef INPUT_INTERFACE_H
     25 #define INPUT_INTERFACE_H
     26 
     27 #ifdef __cplusplus
     28 extern "C" {
     29 #endif
     30 
     31 #include <stdbool.h>
     32 #include <stdint.h>
     33 
     34 /**
     35  * @brief Input level states
     36  *
     37  */
     38 typedef enum {
     39   INPUT_STATE_LOW = 0,      ///< Button not pressed
     40   INPUT_STATE_RISING_EDGE,  ///< Rising edge on the current button
     41   INPUT_STATE_FALLING_EDGE, ///< Falling edge on the current button
     42   INPUT_STATE_HIGH          ///< Button pressed
     43 } inputLevelState;
     44 
     45 /**
     46  * @brief Input positions
     47  *
     48  */
     49 typedef enum {
     50   INPUT_0 = 0,
     51   INPUT_1,
     52   INPUT_2,
     53   INPUT_3,
     54   INPUT_4,
     55   INPUT_5,
     56   INPUT_6,
     57   INPUT_7,
     58   INPUT_8,
     59   INPUT_9,
     60   INPUT_DEL,
     61   INPUT_ENTER,
     62   INPUT_NONE,
     63 } inputButtonPos;
     64 
     65 /**
     66  * @brief Callback type for powering on or off input hardware.
     67  */
     68 typedef void (*inputPwrCB)(void);
     69 
     70 /**
     71  * @brief Callback type for sampling input state.
     72  *
     73  * @param inputButton Pointer to the button position to be sampled.
     74  * @return inputLevelState The current level state of the input.
     75  */
     76 typedef inputLevelState (*inputSampleCB)(inputButtonPos *);
     77 
     78 /**
     79  * @brief Interface structure for input handling.
     80  */
     81 typedef struct {
     82   inputPwrCB powerOn;      /**< Callback to power on the input system. */
     83   inputPwrCB powerOff;     /**< Callback to power off the input system. */
     84   inputSampleCB readInput; /**< Callback to read the current input state. */
     85 } inputInterface;
     86 
     87 /**
     88  * @brief Initializes the input interface with provided callbacks.
     89  *
     90  * @param interfaceHandler Pointer to the input interface structure to
     91  * initialize.
     92  * @param powerOnCB Callback for powering on the input system.
     93  * @param powerOffCB Callback for powering off the input system.
     94  * @param readInputCB Callback for reading input state.
     95  * @return uint8_t Returns 0 on success, non-zero on failure.
     96  */
     97 uint8_t input_initInterface(inputInterface *interfaceHandler,
     98                             inputPwrCB powerOnCB,
     99                             inputPwrCB powerOffCB,
    100                             inputSampleCB readInputCB);
    101 
    102 /**
    103  * @brief Reads a numeric input from a button press.
    104  *
    105  * @param number Pointer to store the resulting number.
    106  * @param maxLength Maximum number of digits to read.
    107  * @param inputButton The button position to read from.
    108  * @return true if a valid number was read, false otherwise.
    109  */
    110 bool input_readNumber(uint64_t *number,
    111                       uint32_t maxLength,
    112                       const inputButtonPos inputButton);
    113 
    114 /**
    115  * @brief Reads a base-8 encoded input string from button presses.
    116  *
    117  * @param inputButton The button position to read from.
    118  * @param inputString Pointer to the buffer storing the input string.
    119  * @param inputLength Pointer to store the length of the input string.
    120  * @param stringMaxLength Maximum allowed length of the input string.
    121  * @param clearBuffer If true, clears the buffer before reading.
    122  * @return true if input was successfully read, false otherwise.
    123  */
    124 bool input_readBase8(const inputButtonPos inputButton,
    125                      uint8_t **inputString,
    126                      uint8_t *inputLength,
    127                      uint8_t stringMaxLength,
    128                      bool clearBuffer);
    129 
    130 #ifdef __cplusplus
    131 }
    132 #endif
    133 
    134 #endif /* INPUT_INTERFACE_H*/