Skip to content

Commit 50fed85

Browse files
committed
input: add keyboard matrix driver
Add a generic kmatrix lower-half with polling/debounce, STM32 board adapters, Kconfig options, a public API header, and a test example/documentation. Signed-off-by: Felipe Moura <[email protected]>
1 parent fac7674 commit 50fed85

File tree

14 files changed

+1732
-0
lines changed

14 files changed

+1732
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/****************************************************************************
2+
* boards/arm/stm32/common/include/stm32_kmatrix_gpio.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_KMATRIX_GPIO_H
24+
#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_KMATRIX_GPIO_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
32+
/****************************************************************************
33+
* Pre-processor Definitions
34+
****************************************************************************/
35+
36+
/****************************************************************************
37+
* Type Definitions
38+
****************************************************************************/
39+
40+
/****************************************************************************
41+
* Public Types
42+
****************************************************************************/
43+
44+
/****************************************************************************
45+
* Public Data
46+
****************************************************************************/
47+
48+
#ifdef __cplusplus
49+
#define EXTERN extern "C"
50+
extern "C"
51+
{
52+
#else
53+
#define EXTERN extern
54+
#endif
55+
56+
/****************************************************************************
57+
* Inline Functions
58+
****************************************************************************/
59+
60+
/****************************************************************************
61+
* Public Function Prototypes
62+
****************************************************************************/
63+
64+
/****************************************************************************
65+
* Name: board_kmatrix_initialize
66+
*
67+
* Description:
68+
* This function is called by application-specific setup logic to
69+
* configure the keyboard matrix device.
70+
*
71+
* Input Parameters:
72+
* devpath - The device path, typically "/dev/kbd0"
73+
*
74+
* Returned Value:
75+
* Zero is returned on success. Otherwise, a negated errno value is
76+
* returned to indicate the nature of the failure.
77+
*
78+
****************************************************************************/
79+
80+
int board_kmatrix_initialize(const char *devpath);
81+
82+
#undef EXTERN
83+
#ifdef __cplusplus
84+
}
85+
#endif
86+
87+
#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_KMATRIX_GPIO_H */
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/****************************************************************************
2+
* boards/arm/stm32/common/include/stm32_kmatrix_i2c.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_KMATRIX_I2C_H
24+
#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_KMATRIX_I2C_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
32+
/****************************************************************************
33+
* Pre-processor Definitions
34+
****************************************************************************/
35+
36+
/****************************************************************************
37+
* Type Definitions
38+
****************************************************************************/
39+
40+
/****************************************************************************
41+
* Public Types
42+
****************************************************************************/
43+
44+
/****************************************************************************
45+
* Public Data
46+
****************************************************************************/
47+
48+
#ifdef __cplusplus
49+
#define EXTERN extern "C"
50+
extern "C"
51+
{
52+
#else
53+
#define EXTERN extern
54+
#endif
55+
56+
/****************************************************************************
57+
* Inline Functions
58+
****************************************************************************/
59+
60+
/****************************************************************************
61+
* Public Function Prototypes
62+
****************************************************************************/
63+
64+
/****************************************************************************
65+
* Name: board_kmatrix_i2c_initialize
66+
*
67+
* Description:
68+
* This function is called by application-specific setup logic to
69+
* configure the keyboard matrix device using an I2C GPIO expander.
70+
*
71+
* Input Parameters:
72+
* devpath - The device path, typically "/dev/kbd0"
73+
*
74+
* Returned Value:
75+
* Zero is returned on success. Otherwise, a negated errno value is
76+
* returned to indicate the nature of the failure.
77+
*
78+
****************************************************************************/
79+
80+
int board_kmatrix_i2c_initialize(const char *devpath);
81+
82+
#undef EXTERN
83+
#ifdef __cplusplus
84+
}
85+
#endif
86+
87+
#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_KMATRIX_I2C_H */

boards/arm/stm32/common/src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,12 @@ if(CONFIG_INPUT_SBUTTON)
158158
list(APPEND SRCS stm32_sbutton.c)
159159
endif()
160160

161+
if(CONFIG_INPUT_KMATRIX)
162+
list(APPEND SRCS stm32_kmatrix_gpio.c)
163+
endif()
164+
165+
if(CONFIG_INPUT_KMATRIX_I2C)
166+
list(APPEND SRCS stm32_kmatrix_i2c.c)
167+
endif()
168+
161169
target_sources(board PRIVATE ${SRCS})

boards/arm/stm32/common/src/Make.defs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ ifeq ($(CONFIG_INPUT_SBUTTON),y)
166166
CSRCS += stm32_sbutton.c
167167
endif
168168

169+
ifeq ($(CONFIG_INPUT_KMATRIX),y)
170+
CSRCS += stm32_kmatrix_gpio.c
171+
endif
172+
173+
ifeq ($(CONFIG_INPUT_KMATRIX_I2C),y)
174+
CSRCS += stm32_kmatrix_i2c.c
175+
endif
176+
169177
DEPPATH += --dep-path src
170178
VPATH += :src
171179
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src

0 commit comments

Comments
 (0)