Skip to content

Commit ddafcea

Browse files
committed
doc/input: Add documention to MPR121 Capacitive Keypad
This commit adds the Documentation to MPR121 Keypad and the board profile documentation to STM32F4Discovery board. Signed-off-by: Alan C. Assis <acassis@gmail.com>
1 parent 71f832b commit ddafcea

4 files changed

Lines changed: 121 additions & 0 deletions

File tree

285 KB
Loading

Documentation/components/drivers/character/input/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Input Devices
77

88
keypad-keyboard.rst
99
keypad.rst
10+
mpr121.rst
1011
sbutton.rst
1112

1213
See ``include/nuttx/input/*.h`` for registration information.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
========================
2+
MPR121 Capacitive Keypad
3+
========================
4+
5+
**What is the MPR121 Keypad**
6+
The MPR Capacitive Keypad is a small keyboard with 12 keys, similar
7+
to a telephone keypad, however the keys are numered from 0 to 11.
8+
9+
This is the picture of the MPR121 Capacitive Keypad:
10+
11+
.. image:: images/mpr121.png
12+
:alt: MPR121 Capacitive Keypad
13+
:align: center
14+
:width: 200px
15+
16+
**Purpose**. The MPR121 driver provides a generic keypad
17+
implementation for this capacitive keypad. The MPR121 uses the I2C
18+
bus to setup and read the touched/released key and uses an IRQ pin
19+
(open drain) to indicate when a key is pressed/released or when some
20+
unnexpected issue happens (currently not used).
21+
22+
The driver also enables debounce, and emits keyboard events through
23+
the common keyboard upper-half. This makes the device available as a
24+
character driver (e.g., ``/dev/keypad0``) using the standard keyboard
25+
interfaces.
26+
27+
**Driver Overview**. The MPR121 lower-half scans the matrix and calls
28+
``keyboard_event()`` when it detects a press or release. The keyboard
29+
upper-half registers the character device at the requested ``devpath``
30+
and stores events in a circular buffer. Applications read
31+
``struct keyboard_event_s`` from the device or use the optional
32+
kbd-codec layer.
33+
34+
**Board Support**. To support the MPR121, a board must provide:
35+
36+
#. **IRQ Definition**
37+
38+
- Define the GPIO Input pin with pull-up enabled (since the
39+
IRQ pin is open-drain) to be used to detect the interrupts.
40+
41+
#. **Registration Hook**
42+
43+
- Define a ``struct xxx_mpr121config_s`` that will wrap the
44+
``struct mpr121_config_s config`` as first member and the irq
45+
argument and ISR handler (xcpt_t isr). The ``config`` needs to
46+
have its ``.irq_attach`` and ``keymap`` initialized with the
47+
board IRQ ISR function and the key mapping array.
48+
- Implement ``board_mpr121_initialize(int devno, int busno)`` to
49+
call ``mpr121_register(&config, devpath)``. It needs to initialize
50+
the I2C Master port/channel that will be used to communicate with
51+
the MPR121 and an instance of that ``xxx_mpr121config_s`` structure.
52+
- Invoke the board hook during bring-up (for example,
53+
``board_mpr121_initialize(0, 1)`` for ``/dev/keymap0`` and ``i2c1``).
54+
55+
**Reference Implementation (STM32F4Discovery)**. The current reference
56+
is in ``boards/arm/stm32/common/src/stm32_mpr121.c``:
57+
58+
- Keymap: 4x3 keypad layout
59+
- Registration: ``board_mpr121_initialize()`` calls
60+
``mpr121_register()``
61+
62+
**Data Path Summary**.
63+
64+
- Board calls ``board_mpr121_initialize(0, 1)``
65+
- ``mpr121_register()`` initializes and configure the MPR121 chip
66+
and calls ``keyboard_register(&lower, devpath, buflen)``
67+
- The upper-half registers the device node at ``devpath``
68+
- Every time an interruption is generated on IRQ pin it will call the
69+
``mpr121_worker()`` and it is calls ``keyboard_event()`` on
70+
press/release of keys.
71+
- Applications read events from the device node (``/dev/keypad0``).
72+

Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/index.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,54 @@ because code cannot be executed from CCM memory.
14751475
STATUS:
14761476
2018-06-02: Configuration added by Alan Carvalho de Assis.
14771477

1478+
mpr121_keypad
1479+
-------------
1480+
1481+
This board config enables the usage of an external MPR121 Capacitive
1482+
Keypad connected to STM32F4Discovery board this way:
1483+
1484+
================ =============
1485+
STM32F4Discovery MPR121 Keypad
1486+
================ =============
1487+
GND GND
1488+
3V [1] 3V3
1489+
I2C1 SDA (PB9) SDA
1490+
I2C1 SCL (PB6) SCL
1491+
PB0 IRQ
1492+
================ =============
1493+
1494+
1: You need to remove the diode D3 and short-circuit the PADs in the
1495+
board to get 3.3V. Be aware: although my board works fine, it could
1496+
damage something that expects 3V in our board (double check).
1497+
1498+
After compiling and flashing the firmware in our board, run kbd command.
1499+
1500+
.. code:: console
1501+
1502+
NuttShell (NSH) NuttX-12.13.0
1503+
nsh> ls /dev
1504+
/dev:
1505+
console
1506+
keypad0
1507+
null
1508+
ttyS0
1509+
zero
1510+
nsh> kbd
1511+
kbd_main: nsamples: 0
1512+
kbd_main: Opening /dev/keypad0
1513+
Sample :
1514+
code : 48
1515+
type : 0
1516+
Sample :
1517+
code : 48
1518+
type : 1
1519+
Sample :
1520+
code : 49
1521+
type : 0
1522+
Sample :
1523+
code : 49
1524+
type : 1
1525+
14781526
netnsh
14791527
------
14801528

0 commit comments

Comments
 (0)