qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

debounce_test_common.h (2429B)


      1 /* Copyright 2021 Simon Arlott
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #include "gtest/gtest.h"
     18 
     19 #include <initializer_list>
     20 #include <list>
     21 #include <string>
     22 
     23 extern "C" {
     24 #include "matrix.h"
     25 #include "timer.h"
     26 }
     27 
     28 enum Direction {
     29     DOWN,
     30     UP,
     31 };
     32 
     33 class MatrixTestEvent {
     34    public:
     35     MatrixTestEvent(int row, int col, Direction direction);
     36 
     37     const int       row_;
     38     const int       col_;
     39     const Direction direction_;
     40 };
     41 
     42 class DebounceTestEvent {
     43    public:
     44     // 0, {{0, 1, DOWN}}, {{0, 1, DOWN}})
     45     DebounceTestEvent(fast_timer_t time, std::initializer_list<MatrixTestEvent> inputs, std::initializer_list<MatrixTestEvent> outputs);
     46 
     47     const fast_timer_t               time_;
     48     const std::list<MatrixTestEvent> inputs_;
     49     const std::list<MatrixTestEvent> outputs_;
     50 };
     51 
     52 class DebounceTest : public ::testing::Test {
     53    protected:
     54     void addEvents(std::initializer_list<DebounceTestEvent> events);
     55     void runEvents();
     56 
     57     fast_timer_t time_offset_      = 7777;
     58     bool         time_jumps_       = false;
     59     fast_timer_t async_time_jumps_ = 0;
     60 
     61    private:
     62     static bool        directionValue(Direction direction);
     63     static std::string directionLabel(Direction direction);
     64 
     65     void runEventsInternal();
     66     void runDebounce(bool changed);
     67     void checkCookedMatrix(bool changed, const std::string &error_message);
     68     void matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event);
     69 
     70     std::string strTime();
     71     std::string strMatrix(matrix_row_t matrix[]);
     72 
     73     std::list<DebounceTestEvent> events_;
     74 
     75     matrix_row_t input_matrix_[MATRIX_ROWS];
     76     matrix_row_t raw_matrix_[MATRIX_ROWS];
     77     matrix_row_t cooked_matrix_[MATRIX_ROWS];
     78     matrix_row_t output_matrix_[MATRIX_ROWS];
     79 
     80     int  extra_iterations_;
     81     bool auto_advance_time_;
     82 };