aboutsummaryrefslogtreecommitdiff
path: root/platform/atm2/ATM22xx-x1x/driver/keyboard/keyboard.h
blob: d2436025b3a5c9c56cd5970b6936d38093009b45 (plain)
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
/**
 *******************************************************************************
 *
 * @file keyboard.h
 *
 * @brief keyboard driver
 *
 * Copyright (C) Atmosic 2018-2021
 *
 *******************************************************************************
 */

#pragma once

/**
 * @defgroup KEYBOARD KEYBOARD
 * @ingroup DRIVERS
 * @brief User driver for KSM module.
 * @{
 */

#ifdef __cplusplus
extern "C" {
#endif

/// Key matrix event
typedef enum ksm_event_s {
    /// A key was released.
    KSM_RELEASE,
    /// A Key was pressed.
    KSM_PRESS,
    /// Hardware overflow error.
    KSM_ERR_HW_OVF
} ksm_event_t;

/**
 * @brief Callback function prototype
 * @param[in] event True if the key is pressed
 * @param[in] idx Key index which is used in KSM_RELEASE and KSM_PRESS event.
 * The index is Ri*Cn + Ci where Ci, Cn and Ri are column index, number of
 * columns and row index respectively.
 * @param[in] ctx Context from keyboard_run()
 */
typedef void (*keyboard_cb)(ksm_event_t event, uint32_t idx, void const *ctx);

/**
 * @brief Register callbacks and activate device.
 * The callback is called from SW event.
 * @param[in] callback Callback function. Called when a new keyboard
 * event occurred.
 * @param[in] ctx Context passed to callback
 */
__NONNULL(1)
void keyboard_run(keyboard_cb callback, void const *ctx);

#ifdef __cplusplus
}
#endif

/// @} KEYBOARD