[riot-notifications] [RIOT-OS/RIOT] drivers: add MCP23x17 I/O expander support (#10688)

Gunar Schorcht notifications at github.com
Wed Jan 2 03:22:10 CET 2019


### Contribution description

This PR adds a driver module for MCP23x17 serial I/O expander modules which extend the number of GPIOs over I2C or SPI. It is a complete rework of the driver provided in PR #7652 and written from scratch.

The following expander modules are supported:

- MCP23017 16-bit I2C I/O expander
- MCP23S17 16-bit I2C I/O expander

The driver interface
 - is compatible with the peripheral GPIO interface. The only difference is that the functions have the prefix `mcp23x17_` and require an additional parameter, the pointer to the expander device of type `mcp23x17_`
- supports the GPIO extension API as defined in PR #9582 and provided in PR #9860 and #9958.
- supports the following GPIO modes
  - `GPIO_IN`, `GPIO_IN_PU` and `GPIO_OUT` in hardware
  - `GPIO_OD` and `GPIO_OD_PU` are emulated.

Optionally, the driver can use the low-active push-pull INT signal of MCP23x17 expander modules to provide external interrupt capabilities for all expander pins. The driver interface is compatible to module `periph_gpio_irq`

The driver supports direct GPIO mapping to SAUL which is compatible to the peripheral GPIO SAUL interface. Thus MCP23x17 I/O expander pins can be used with SAUL in the same way as peripheral GPIOS.


## Benchmarks

MCP23x17 driver run-time performance benchmark over SPI using 10 MHz clock speed:
```
                 nop loop:       634us  ---   0.063us per call  ---   15772870 calls per sec
                 gpio_set:    540009us  ---  54.000us per call  ---      18518 calls per sec
               gpio_clear:    540000us  ---  54.000us per call  ---      18518 calls per sec
              gpio_toggle:    811005us  ---  81.100us per call  ---      12330 calls per sec
                gpio_read:    271001us  ---  27.100us per call  ---      36900 calls per sec
               gpio_write:    539005us  ---  53.900us per call  ---      18552 calls per sec
```
MCP23x17 driver run-time performance benchmark over SPI using 1 MHz clock speed:
```
                 nop loop:       634us  ---   0.063us per call  ---   15772870 calls per sec
                 gpio_set:   1429044us  ---  142.904us per call  ---       6997 calls per sec
               gpio_clear:   1429005us  ---  142.900us per call  ---       6997 calls per sec
              gpio_toggle:   2144009us  ---  214.400us per call  ---       4664 calls per sec
                gpio_read:    715000us  ---  71.500us per call  ---      13986 calls per sec
               gpio_write:   1428004us  ---  142.800us per call  ---       7002 calls per sec
```

Reference board was an `esp8266-esp-12x`.

### Testing procedure

The test application `tests/driver_mcp23x17` can be used to test each MCP23x17 expander I/O pin with shell commands. It bases on the test application for GPIO peripheral drivers.

To use the test application, just compile it with at least one of the pseudomodules `mcp23017` or `mcp23s17, e.g.:

     USEMODULE=mcp23017 make flash -C tests/driver_mcp23017 BOARD=...

Add module `periph_gpio_irq` and define the MCU interrupt pin by parameter  `PCF857X_PARAM_INT_PIN` to use the MCP23x17 interrupt signal, e.g.,

     CFLAGS="-DMCP23X17_PARAM_INT_PIN=\(GPIO\(0,6\)\)" \
     USEMODULE="mcp23017 periph_gpio_irq" make ...

### Issues/PRs references

The driver is compatible with the GPIO extension API, PRs #9582, #9860 and #9958, but it does not depend on it.
You can view, comment on, or merge this pull request online at:

  https://github.com/RIOT-OS/RIOT/pull/10688

-- Commit Summary --

  * drivers: support for MCP23x17 I/O expanders
  * makefiles: pseudomodules for MCP23x17 I/O expander
  * sys/autoinit: support for MCP23x17 I/O expander
  * tests: app for MCP23x17 I/O expanders

-- File Changes --

    M drivers/Makefile.dep (18)
    M drivers/Makefile.include (4)
    A drivers/include/mcp23x17.h (512)
    A drivers/mcp23x17/Makefile (1)
    A drivers/mcp23x17/include/mcp23x17_params.h (123)
    A drivers/mcp23x17/include/mcp23x17_regs.h (84)
    A drivers/mcp23x17/mcp23x17.c (578)
    A drivers/mcp23x17/mcp23x17_saul.c (57)
    M makefiles/pseudomodules.inc.mk (4)
    M sys/auto_init/auto_init.c (4)
    A sys/auto_init/saul/auto_init_mcp23x17.c (107)
    A tests/driver_mcp23x17/Makefile (13)
    A tests/driver_mcp23x17/README.md (32)
    A tests/driver_mcp23x17/include/gpio_ext_conf.h (59)
    A tests/driver_mcp23x17/main.c (459)

-- Patch Links --

https://github.com/RIOT-OS/RIOT/pull/10688.patch
https://github.com/RIOT-OS/RIOT/pull/10688.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/10688
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190101/0186e0a3/attachment.html>


More information about the notifications mailing list