• [单片机框架][bsp层][N32G4FR][framework][key_scan] 按键扫描


    按键扫描具备以下事件。
    按下,释放,长按保持,长按释放,长长按保持,长长按释放,单击,双击,三击。
    KEY_EVENT_NONE
    KEY_EVENT_PRESS
    KEY_EVENT_RELEASE
    KEY_EVENT_LONG_HOLD
    KEY_EVENT_LONG_RELEASE
    KEY_EVENT_LONG_LONG_HOLD
    KEY_EVENT_LONG_LONG_RELEASE
    KEY_EVENT_CLICK
    KEY_EVENT_DOUBLE_CLICK
    KEY_EVENT_TRIPLE_CLICK

    
    #include "bsp_gpio.h"
    
    #include 
    #include "sys_cmsis.h"
    #include "modules.h"
    #include "errorno.h"
    #include "string.h"
    #include "log.h"
    
    #include "key.h"
    
    #define KEY_LOG_EN 0
    #if KEY_LOG_EN
    #define KEY_LOG_D(str, ...)     LOG_D(str, ##__VA_ARGS__)
    #define KEY_LOG_I(str, ...)     LOG_I(str, ##__VA_ARGS__)
    #define KEY_LOG_N(str, ...)     LOG_N(str, ##__VA_ARGS__)
    #define KEY_LOG_W(str, ...)     LOG_W(str, ##__VA_ARGS__)
    #define KEY_LOG_E(str, ...)     LOG_E(str, ##__VA_ARGS__)
    #define KEY_LOG_C(str, ...)     LOG_C(str, ##__VA_ARGS__)
    #else
    #define KEY_LOG_D(str, ...)
    #define KEY_LOG_I(str, ...)
    #define KEY_LOG_N(str, ...)
    #define KEY_LOG_W(str, ...)
    #define KEY_LOG_E(str, ...)
    #define KEY_LOG_C(str, ...)
    #endif
    
    #define KEY_LPRESS_TIME         2000
    #define KEY_LLPRESS_TIME        8000
    #define KEY_REPEAT_TIME         1000
    #define KEY_DBLCLICK_TIME       200
    #define KEY_TPLCLICK_TIME       180
    
    typedef enum
    {
        KEY_STATUS_NONE             = 0,
        KEY_STATUS_DEBOUNCE         = (1 << 0),
        KEY_STATUS_FIRST_PRESS      = (1 << 1),
        KEY_STATUS_FIRST_RELEASE    = (1 << 2),
        KEY_STATUS_SECOND_PRESS     = (1 << 3),
        KEY_STATUS_SECOND_RELEASE   = (1 << 4),
        KEY_STATUS_THIRD_PRESS      = (1 << 5),
        KEY_STATUS_THIRD_RELEASE    = (1 << 6),
    } key_status_t;
    
    typedef struct
    {
        uint8_t status;
        uint32_t time;
        uint32_t event;
        uint32_t flag;
        uint32_t long_press_time;
        uint32_t long_long_press_time;
        key_num_t key_num;
        key_cfg_t *p_cfg;
        key_evt_cb_t evt_cbk;
    } key_hdl_t;
    
    static key_hdl_t g_key_hdl[KEY_NUM];
    static sys_timer_id_t g_key_judge_timer_id;
    
    static void key_state_change_handler(void *arg)
    {
        key_num_t key = *(key_num_t*)arg;
    
        if (g_key_hdl[key].p_cfg->trigger == KEY_TRIGGER_MODE_LEVEL)
        {
            if (g_key_hdl[key].time < (g_key_hdl[key].p_cfg->effective_interval / KEY_SAMPLE_INTERVAL_MS))
            {
                return;
            }
    
            if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                if (g_key_hdl[key].status == KEY_STATUS_NONE)
                {
                    g_key_hdl[key].status               = KEY_STATUS_DEBOUNCE;
                    g_key_hdl[key].time                 = 0;
                    g_key_hdl[key].long_press_time      = 0;
                    g_key_hdl[key].long_long_press_time = 0;
                }
            }
        }
        else if (g_key_hdl[key].p_cfg->trigger == KEY_TRIGGER_MODE_PULSE)
        {
            if (g_key_hdl[key].time < g_key_hdl[key].p_cfg->effective_interval / KEY_SAMPLE_INTERVAL_MS)
            {
                return;
            }
    
            if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].event |= KEY_EVENT_PRESS;
                if (g_key_hdl[key].evt_cbk != NULL)
                {
                    (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_PRESS);
                }
                KEY_LOG_D("[key][%d][press]\r\n", key);
            }
            else if (g_key_hdl[key].p_cfg->active_level != bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].time = 0;
                g_key_hdl[key].event |= KEY_EVENT_RELEASE;
                if (g_key_hdl[key].evt_cbk != NULL)
                {
                    (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_RELEASE);
                }
                KEY_LOG_D("[key][%d][release]\r\n", key);
            }
        }
    }
    
    void key_init(key_num_t key, key_cfg_t *cfg, key_evt_cb_t cbk)
    {
        memset(&g_key_hdl[key], 0, sizeof(key_hdl_t));
    
        g_key_hdl[key].p_cfg = cfg;
        g_key_hdl[key].key_num = key;
        g_key_hdl[key].evt_cbk = cbk;
    
        bsp_gpio_register_irq_callback(cfg->gpio_num, key_state_change_handler,
                                      (void *)&g_key_hdl[key].key_num);
    
        bsp_gpio_init(cfg->gpio_num, BSP_GPIO_EXTI_ENABLE);
    }
    
    static void key_normal_handle(key_num_t key)
    {
        if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
        {
            if (g_key_hdl[key].status == KEY_STATUS_NONE)
            {
                g_key_hdl[key].status               = KEY_STATUS_DEBOUNCE;
                g_key_hdl[key].time                 = 0;
                g_key_hdl[key].long_press_time      = 0;
                g_key_hdl[key].long_long_press_time = 0;
                KEY_LOG_D("[key][%d][normal_handle]\r\n", key);
            }
        }
    }
    
    static void key_debounce_handle(key_num_t key)
    {
        if (g_key_hdl[key].time >= g_key_hdl[key].p_cfg->debounce_time / KEY_SAMPLE_INTERVAL_MS)
        {
            g_key_hdl[key].time                  = 0;
            g_key_hdl[key].long_press_time       = 0;
            g_key_hdl[key].long_long_press_time  = 0;
            g_key_hdl[key].flag                  = 0;
            g_key_hdl[key].event                 = 0;
    
            if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].event |= KEY_EVENT_PRESS;
                if (g_key_hdl[key].evt_cbk != NULL)
                {
                    (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_PRESS);
                }
                KEY_LOG_D("[key][%d][press]\r\n", key);
                g_key_hdl[key].flag |= KEY_EVENT_PRESS;
                g_key_hdl[key].status = KEY_STATUS_FIRST_PRESS;
            }
            else
            {
                g_key_hdl[key].status = KEY_STATUS_NONE;
            }
        }
    }
    
    static void key_first_press_handle(key_num_t key)
    {
        if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
        {
            if (g_key_hdl[key].long_press_time >= KEY_LPRESS_TIME / KEY_SAMPLE_INTERVAL_MS)
            {
                g_key_hdl[key].long_press_time = 0;
    
                if ((g_key_hdl[key].event & KEY_EVENT_LONG_HOLD) == 0)
                {
                    g_key_hdl[key].event |= KEY_EVENT_LONG_HOLD;
                    g_key_hdl[key].flag |= KEY_EVENT_LONG_HOLD;
                    if (g_key_hdl[key].evt_cbk != NULL)
                    {
                        (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_LONG_HOLD);
                    }
                    KEY_LOG_D("[key][%d][long_hold]\r\n", key);
                }
            }
    
            if (g_key_hdl[key].long_long_press_time >= KEY_LLPRESS_TIME / KEY_SAMPLE_INTERVAL_MS)
            {
                g_key_hdl[key].long_long_press_time = 0;
    
                if ((g_key_hdl[key].event & KEY_EVENT_LONG_LONG_HOLD) == 0)
                {
                    g_key_hdl[key].event |= KEY_EVENT_LONG_LONG_HOLD;
                    g_key_hdl[key].flag |= KEY_EVENT_LONG_LONG_HOLD;
                    if (g_key_hdl[key].evt_cbk != NULL)
                    {
                        (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_LONG_LONG_HOLD);
                    }
                    KEY_LOG_D("[key][%d][long_long_hold]\r\n", key);
                }
            }
        }
        else
        {
            g_key_hdl[key].event |= KEY_EVENT_RELEASE;
            if (g_key_hdl[key].evt_cbk != NULL)
            {
                (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_RELEASE);
            }
            KEY_LOG_D("[key][%d][release]\r\n", key);
    
            if (g_key_hdl[key].flag & KEY_EVENT_LONG_LONG_HOLD)
            {
                g_key_hdl[key].flag &= (~KEY_EVENT_LONG_LONG_HOLD);
                g_key_hdl[key].event |= KEY_EVENT_LONG_LONG_RELEASE;
                if (g_key_hdl[key].evt_cbk != NULL)
                {
                    (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_LONG_LONG_RELEASE);
                }
                KEY_LOG_D("[key][%d][long_long_release]\r\n", key);
            }
            else
            {
                if (g_key_hdl[key].flag & KEY_EVENT_LONG_HOLD)
                {
                    g_key_hdl[key].flag &= (~KEY_EVENT_LONG_HOLD);
                    g_key_hdl[key].event |= KEY_EVENT_LONG_RELEASE;
                    if (g_key_hdl[key].evt_cbk != NULL)
                    {
                        (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_LONG_RELEASE);
                    }
                    KEY_LOG_D("[key][%d][long_release]\r\n", key);
                }
            }
    
            if (g_key_hdl[key].time >= KEY_DBLCLICK_TIME / KEY_SAMPLE_INTERVAL_MS)
            {
                if (((g_key_hdl[key].event & KEY_EVENT_LONG_LONG_HOLD) == 0) &&
                    ((g_key_hdl[key].event & KEY_EVENT_LONG_HOLD) == 0))
                {
                    g_key_hdl[key].event |= KEY_EVENT_CLICK;
                    if (g_key_hdl[key].evt_cbk != NULL)
                    {
                        (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_CLICK);
                    }
                    KEY_LOG_D("[key][%d][click_1]\r\n", key);
                }
                g_key_hdl[key].status = KEY_STATUS_NONE;
            }
            else
            {
                g_key_hdl[key].time      = 0;
                g_key_hdl[key].status    = KEY_STATUS_FIRST_RELEASE;
            }
        }
    }
    
    static void key_first_release_handle(key_num_t key)
    {
        if (g_key_hdl[key].time <= KEY_DBLCLICK_TIME / KEY_SAMPLE_INTERVAL_MS)
        {
            if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].time   = 0;
                g_key_hdl[key].status = KEY_STATUS_SECOND_PRESS;
            }
        }
        else
        {
            if (g_key_hdl[key].p_cfg->active_level != bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].event |= KEY_EVENT_CLICK;
                if (g_key_hdl[key].evt_cbk != NULL)
                {
                    (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_CLICK);
                }
                KEY_LOG_D("[key][%d][click_2]\r\n", key);
                g_key_hdl[key].status = KEY_STATUS_NONE;
            }
        }
    }
    
    static void key_second_press_handle(key_num_t key)
    {
        if (g_key_hdl[key].time <= KEY_DBLCLICK_TIME / KEY_SAMPLE_INTERVAL_MS)
        {
            if (g_key_hdl[key].p_cfg->active_level != bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].time   = 0;
                g_key_hdl[key].status = KEY_STATUS_SECOND_RELEASE;
            }
        }
        else
        {
            g_key_hdl[key].event |= KEY_EVENT_CLICK;
            if (g_key_hdl[key].evt_cbk != NULL)
            {
                (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_CLICK);
            }
            KEY_LOG_D("[key][%d][click_3]\r\n", key);
            g_key_hdl[key].time                  = 0;
            g_key_hdl[key].long_press_time       = 0;
            g_key_hdl[key].long_long_press_time  = 0;
            g_key_hdl[key].status                = KEY_STATUS_FIRST_PRESS;
        }
    }
    
    static void key_second_release_handle(key_num_t key)
    {
        if (g_key_hdl[key].time <= KEY_TPLCLICK_TIME / KEY_SAMPLE_INTERVAL_MS)
        {
            if (g_key_hdl[key].p_cfg->active_level == bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].time   = 0;
                g_key_hdl[key].status = KEY_STATUS_THIRD_PRESS;
            }
        }
        else
        {
            g_key_hdl[key].event |= KEY_EVENT_DOUBLE_CLICK;
            if (g_key_hdl[key].evt_cbk != NULL)
            {
                (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_DOUBLE_CLICK);
            }
            KEY_LOG_D("[key][%d][double_click_1]\r\n", key);
            g_key_hdl[key].status = KEY_STATUS_NONE;
        }
    }
    
    static void key_third_press_handle(key_num_t key)
    {
        if (g_key_hdl[key].time <= KEY_TPLCLICK_TIME / KEY_SAMPLE_INTERVAL_MS)
        {
            if (g_key_hdl[key].p_cfg->active_level != bsp_gpio_read(g_key_hdl[key].p_cfg->gpio_num))
            {
                g_key_hdl[key].time = 0;
                g_key_hdl[key].event |= KEY_EVENT_TRIPLE_CLICK;
                if (g_key_hdl[key].evt_cbk != NULL)
                {
                    (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_TRIPLE_CLICK);
                }
                KEY_LOG_D("[key][%d][triple_click]\r\n", key);
                g_key_hdl[key].status = KEY_STATUS_NONE;
            }
        }
        else
        {
            g_key_hdl[key].event |= KEY_EVENT_DOUBLE_CLICK;
            if (g_key_hdl[key].evt_cbk != NULL)
            {
                (*g_key_hdl[key].evt_cbk)(key, KEY_EVENT_DOUBLE_CLICK);
            }
            KEY_LOG_D("[key][%d][double_click_2]\r\n", key);
            g_key_hdl[key].time                  = 0;
            g_key_hdl[key].long_press_time       = 0;
            g_key_hdl[key].long_long_press_time  = 0;
            g_key_hdl[key].status                = KEY_STATUS_FIRST_PRESS;
        }
    }
    
    static void key_judge_timer_handle(void const *arg)
    {
        uint8_t i;
    
        for (i = 0; i < KEY_NUM; i++)
        {
            g_key_hdl[i].time ++;
            g_key_hdl[i].long_press_time ++;
            g_key_hdl[i].long_long_press_time ++;
        }
    
        for (i = 0; i < KEY_NUM; i++)
        {
            if (g_key_hdl[i].p_cfg->trigger == KEY_TRIGGER_MODE_PULSE)
            {
                continue;
            }
    
            switch (g_key_hdl[i].status)
            {
                case KEY_STATUS_NONE:
                {
                    key_normal_handle(i);
                }
                break;
                case KEY_STATUS_DEBOUNCE:
                {
                    key_debounce_handle(i);
                }
                break;
                case KEY_STATUS_FIRST_PRESS:
                {
                    key_first_press_handle(i);
                }
                break;
                case KEY_STATUS_FIRST_RELEASE:
                {
                    key_first_release_handle(i);
                }
                break;
                case KEY_STATUS_SECOND_PRESS:
                {
                    key_second_press_handle(i);
                }
                break;
                case KEY_STATUS_SECOND_RELEASE:
                {
                    key_second_release_handle(i);
                }
                break;
                case KEY_STATUS_THIRD_PRESS:
                {
                    key_third_press_handle(i);
                }
                break;
                case KEY_STATUS_THIRD_RELEASE:
                {
                    ;
                }
                break;
                default:
                break;
            }
        }
    }
    SYS_TIMER_DEF(key_judge_timer, key_judge_timer_handle);
    
    static void key_module_init(void)
    {
        sys_status status;
    
        g_key_judge_timer_id = sys_timer_create(SYS_TIMER(key_judge_timer), SYS_TIMER_PERIODIC, NULL);
        if (g_key_judge_timer_id)
        {
            status = sys_timer_start(g_key_judge_timer_id, KEY_SAMPLE_INTERVAL_MS);
            if (status != RETVAL(E_OK))
            {
                KEY_LOG_E("[key][key_module_init] failed %d\r\n", status);
            }
        }
    }
    
    APP_INITCALL("key_module", key_module_init);
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    #ifndef __KEY_H__
    #define __KEY_H__
    
    #include "typedefs.h"
    
    typedef enum
    {
        KEY0_POWER,
        KEY1_HALL,
        KEY2_USB,
        KEY_NUM,
    } key_num_t;
    
    #define KEY_SAMPLE_INTERVAL_MS          10
    
    typedef enum
    {
        KEY_EVENT_NONE              = 0,
        KEY_EVENT_PRESS             = (1 << 0),
        KEY_EVENT_RELEASE           = (1 << 1),
        KEY_EVENT_LONG_HOLD         = (1 << 2),
        KEY_EVENT_LONG_RELEASE      = (1 << 3),
        KEY_EVENT_LONG_LONG_HOLD    = (1 << 4),
        KEY_EVENT_LONG_LONG_RELEASE = (1 << 5),
        KEY_EVENT_CLICK             = (1 << 6),
        KEY_EVENT_DOUBLE_CLICK      = (1 << 7),
        KEY_EVENT_TRIPLE_CLICK      = (1 << 8),
    } key_event_t;
    
    typedef enum
    {
        KEY_ACTIVE_LEVEL_LOW = 0,
        KEY_ACTIVE_LEVEL_HIGH,
    } key_active_level_t;
    
    typedef enum
    {
        KEY_TRIGGER_MODE_PULSE,
        KEY_TRIGGER_MODE_LEVEL,
    } key_trigger_t;
    
    typedef struct
    {
        uint8_t gpio_num;
        uint8_t debounce_time;
        uint16_t effective_interval;
        key_trigger_t trigger;
        key_active_level_t active_level;
    } key_cfg_t;
    
    typedef void (*key_evt_cb_t)(key_num_t key, uint32_t event);
    
    void key_init(key_num_t key, key_cfg_t *cfg, key_evt_cb_t cbk);
    
    #endif //__KEY_H__
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    最新代码请去gitee获取:跳转

  • 相关阅读:
    Java学习——泛型通配符
    音视频项目—基于FFmpeg和SDL的音视频播放器解析(十一)
    xhadmin多应用Saas框架如何安装情侣飞行棋?
    Elasticsearch:在 ES|QL 中使用 DISSECT 和 GROK 进行数据处理
    C#实现的下拉多选框,下拉多选树,多级节点
    qt.qpa.xcb: could not connect to display 0
    springboot 如何获取URL请求参数呢?
    坚持与确定性:毒药还是良药?
    第2-1-5章 docker安装MinIO实现文件存储服务-springboot整合minio-minio全网最全的资料
    shell_74.Linux创建使用函数
  • 原文地址:https://blog.csdn.net/qq_29246181/article/details/126824508