|
| 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 | + |
0 commit comments