[riot-notifications] [RIOT-OS/RIOT] periph/gpio: enable API usage for expanders (#9690)

Gunar Schorcht notifications at github.com
Wed Jan 9 15:59:35 CET 2019


As long as nothing has been changed, it should be easy as to

- rename `GPIO_PIN` definitions to `GPIO_CPU_PIN`  in all `cpu/*/periph/gpio` drivers as you suggested
- replace `gpio_t` by `gpio_cpu_t` in all `cpu/*/periph/gpio` drivers
- rename `gpio_*` cpu implementations to `gpio_cpu_*`
- declare the `gpio_t` struct in  `periph/gpio.h` similar to what you suggested
  ```
   #if MODULE_EXTEND_GPIO || DOXYGEN
   typedef struct {
       gpio_ext_dev_t *dev;
       union {
           unsigned ext_pin;
           gpio_cpu_t cpu_pin;
   } gpio_t;
   #else 
   typedef gpio_cpu_t gpio_t;
   #endif  
  ```
  This would ensure that an application which uses the `gpio_t` type for any reason will compile as long as it does't use expanders.
- define in `periph/gpio.h` a default macro
  ```
  #ifndef GPIO_EXT_0
  #define GPIO_EXT_0     0xff /* there shoul be no CPU with more than 255 ports ;-) */
  #endif
  ```
- define in `periph/gpio.h` a macro (unconditionally)
  ```
  #if MODULE_EXTEND_GPIO || DOXYGEN
  #define GPIO_PIN(x, y)      (x < GPIO_EXT_0 ? GPIO_CPU_PIN(x, y) \
                                              : GPIO_EXT_PIN(x, y))
  #else 
  #define GPIO_PIN(x, y)
  #endif      
  ```
- define a macro in `periph/gpio.h` a default macro as you suggested
  ```
  #if MODULE_EXTEND_GPIO
  #define GPIO_EXT_PIN(dev, pin)      (gpio_t) { .dev=dev, .pin=pin }
  #endif      
  ```
- change `gpio_*` function in `periph/gpio.h` to
   ```
    static inline int gpio_init(gpio_t pin, gpio_mode_t mode)
    {
    #ifdef MODULE_EXTEND_GPIO
        if (pin.device) {
            return pin.dev.gpio_ext_init(pin.ext_pin, mode);
        }
    #endif 
    
    #ifdef MODULE_PERIPH_GPIO
        return gpio_cpu_init(pin.cpu_pin, mode);
    #else
        return -1;
    #endif
    }
   ```

I would do it in the first step since it will become difficult to use `sed s/.../.../g` for renaming/replacing once some of changes have been added as first step.

-- 
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/issues/9690#issuecomment-452726247
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190109/b52a7407/attachment.html>


More information about the notifications mailing list