This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 51cd4a548f8d53509568e634ad3417db39537746 Author: Alan Carvalho de Assis <[email protected]> AuthorDate: Sat Apr 25 18:45:52 2026 -0300 doc: Improved QE Documentation and add mt6816 board profile doc This commit explain that the QE encoder driver can be used to internal QE from microcontroller or external magnetic encoder. Also explains how to use the mt6816 board profile to STM32F4Discovery Signed-off-by: Alan C. Assis <[email protected]> --- .../components/drivers/character/quadrature.rst | 50 +++++++++++++++++++ .../arm/stm32f4/boards/stm32f4discovery/index.rst | 55 +++++++++++++++++++++ .../arm/stm32f4/boards/stm32f4discovery/mt6816.png | Bin 0 -> 183700 bytes 3 files changed, 105 insertions(+) diff --git a/Documentation/components/drivers/character/quadrature.rst b/Documentation/components/drivers/character/quadrature.rst index d19886e244d..af4e926253d 100644 --- a/Documentation/components/drivers/character/quadrature.rst +++ b/Documentation/components/drivers/character/quadrature.rst @@ -2,6 +2,16 @@ Quadrature Encoder Drivers ========================== +A Quadrature Encoder (QE) is a kind of sensor normally used to read +angular rotation of a motor or other turning device. + +NuttX supports internal QE peripheral that exists in some microcontrollers +like ESP32, iMXRT, STM32, nRF5x, TIVA, and others, and also supports +Magnetic Rotary Encoders like AS5048, MT6816, etc. + +Internal Peripheral Quadrature Encoder +====================================== + NuttX supports a low-level, two-part Quadrature Encoder driver. #. An "upper half", generic driver that provides the common @@ -28,6 +38,46 @@ following locations: for the specific processor ``<architecture>`` and for the specific ``<chip>`` Quadrature Encoder peripheral devices. +Magnetic Rotary Encoder +======================= + +Although technically a Magnetic Rotary Encoder is not a Quadrature Encoder, +usually uses the QE Lower Half driver to export a device compatible with +quadrature encoder. This way an application using an ordinary QE encoder +could use a Magnetic Rotary Encoder with any modification, just need to +enable and initialize the Magnetic Rotary Encoder on their board. + +This is how a board powered by STM32 will initialize a MT6816 Magnetic +Rotary Encoder: + +.. code-block:: c + + /* Initialize the SPI bus connected to MT6816 */ + + spi = stm32_spibus_initialize(spi_busno); + if (spi == NULL) + { + return -ENODEV; + } + + /* Initialize MT6816 using `spi` and a `device number` starting from 0 */ + + dev = mt6816_initialize(spi, (uint16_t) devno); + if (dev == NULL) + { + return -ENODEV; + } + + /* Use the returned qe lower half to register /dev/qe# (# => devno) */ + + ret = qe_register(qe_path, dev); + if (ret < 0) + { + snerr("ERROR: Failed to register MT6816 qe%d driver: %d\n", + devno, ret); + ret = -ENODEV; + } + Application Programming Interface ================================= diff --git a/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/index.rst b/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/index.rst index 31e724c4ba7..65a7eaf7831 100644 --- a/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/index.rst +++ b/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/index.rst @@ -1523,6 +1523,61 @@ After compiling and flashing the firmware in our board, run kbd command. code : 49 type : 1 +mt6816 +------ + +This board config enables the MagTek MT6816 Magnetic Rotary Encoder connected +to STM32F4Discovery board SPI1 this way: + +================ ====== +STM32F4Discovery MT6816 +================ ====== +3V [1] VCC +GND GND +PE3 CSN +SPI1 MOSI (PA7) MOSI +SPI1 MISO (PA6) MISO +SPI1 SCK (PA5) SCK +================ ====== + +1: You need to remove the diode D3 and short-circuit the PADs in the +board to get 3.3V. Be aware: although my board works fine, it could +damage something that expects 3V in our board (double check). + +IMPORTANT: You need to connect the HVPP (pin 2) to VCC in order to get +MT6816 working in SPI mode. Just short-circuit R3 pads will work: + +.. figure:: mt6816.png + :align: center + +After compiling and flashing the firmware in our board, run qe command: + +.. code:: console + + NuttShell (NSH) NuttX-12.13.0 + nsh> ls /dev + /dev: + console + null + qe0 + ttyS0 + zero + nsh> qe + qe_main: Hardware initialized. Opening the encoder device: /dev/qe0 + qe_main: Number of samples: 0 + qe_main: 1. 6546 + qe_main: 2. 6620 + qe_main: 3. 7384 + qe_main: 4. 7808 + qe_main: 5. 7900 + qe_main: 6. 7984 + qe_main: 7. 7989 + qe_main: 8. 7993 + qe_main: 9. 7998 + qe_main: 10. 8008 + qe_main: 11. 8052 + qe_main: 12. 8064 + netnsh ------ diff --git a/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/mt6816.png b/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/mt6816.png new file mode 100644 index 00000000000..3a937cf7dff Binary files /dev/null and b/Documentation/platforms/arm/stm32f4/boards/stm32f4discovery/mt6816.png differ
