Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

periph/gpio: support for extension API (part 2) #9958

Closed
wants to merge 13 commits into from
Closed
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ ifneq (,$(filter ethos,$(USEMODULE)))
USEMODULE += tsrb
endif

ifneq (,$(filter extend_gpio,$(USEMODULE)))
USEMODULE += extend
endif

ifneq (,$(filter feetech,$(USEMODULE)))
USEMODULE += uart_half_duplex
endif
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ ifneq (,$(filter encx24j600,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/encx24j600/include
endif

ifneq (,$(filter extend_,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/extend/include
endif

ifneq (,$(filter feetech,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/feetech/include
endif
Expand Down
1 change: 1 addition & 0 deletions drivers/extend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
128 changes: 128 additions & 0 deletions drivers/extend/gpio_notsup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (C) 2018 Acutam Automation, LLC
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_extend_gpio
*
* @{
*
* @file
* @brief GPIO extension not-supported functions
*
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
*
* @}
*/

ZetaR60 marked this conversation as resolved.
Show resolved Hide resolved
#if MODULE_EXTEND_GPIO

#include "periph/gpio.h"
#include "extend/gpio.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

int gpio_ext_init_notsup(void *dev, gpio_t pin, gpio_mode_t mode)
{
(void)dev;
(void)pin;
(void)mode;

DEBUG("[gpio_ext_init_notsup] call for dev %p\n", dev);

return -1;
}

int gpio_ext_init_int_notsup(void *dev, gpio_t pin, gpio_mode_t mode,
gpio_flank_t flank, gpio_cb_t cb, void *arg)
{
(void)dev;
(void)pin;
(void)mode;
(void)flank;
(void)cb;
(void)arg;

DEBUG("[gpio_ext_init_int_notsup] call for dev %p\n", dev);

return -1;
}

void gpio_ext_irq_enable_notsup(void *dev, gpio_t pin)
{
(void)dev;
(void)pin;

DEBUG("[gpio_ext_irq_enable_notsup] call for dev %p\n", dev);
}

void gpio_ext_irq_disable_notsup(void *dev, gpio_t pin)
{
(void)dev;
(void)pin;

DEBUG("[gpio_ext_irq_disable_notsup] call for dev %p\n", dev);
}

int gpio_ext_read_notsup(void *dev, gpio_t pin)
{
(void)dev;
(void)pin;

DEBUG("[gpio_ext_read_notsup] call for dev %p\n", dev);

return 0;
}

void gpio_ext_set_notsup(void *dev, gpio_t pin)
{
(void)dev;
(void)pin;

DEBUG("[gpio_ext_set_notsup] call for dev %p\n", dev);
}

void gpio_ext_clear_notsup(void *dev, gpio_t pin)
{
(void)dev;
(void)pin;

DEBUG("[gpio_ext_clear_notsup] call for dev %p\n", dev);
}

void gpio_ext_toggle_notsup(void *dev, gpio_t pin)
{
(void)dev;
(void)pin;

DEBUG("[gpio_ext_toggle_notsup] call for dev %p\n", dev);
}

void gpio_ext_write_notsup(void *dev, gpio_t pin, int value)
{
(void)dev;
(void)pin;
(void)value;

DEBUG("[gpio_ext_write_notsup] call for dev %p\n", dev);
}

/* not-supported driver */
const gpio_ext_driver_t gpio_ext_notsup_driver = {
.init = gpio_ext_init_notsup,
.init_int = gpio_ext_init_int_notsup,
.irq_enable = gpio_ext_irq_enable_notsup,
.irq_disable = gpio_ext_irq_disable_notsup,
.read = gpio_ext_read_notsup,
.set = gpio_ext_set_notsup,
.clear = gpio_ext_clear_notsup,
.toggle = gpio_ext_toggle_notsup,
.write = gpio_ext_write_notsup,
};

#endif /* MODULE_EXTEND_GPIO */
179 changes: 179 additions & 0 deletions drivers/extend/gpio_redir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* Copyright (C) 2018 Acutam Automation, LLC
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_extend_gpio
*
* @{
*
* @file
* @brief GPIO extension redirection functions
*
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
*
* @}
*/

gschorcht marked this conversation as resolved.
Show resolved Hide resolved
#if MODULE_EXTEND_GPIO

#include "periph/gpio.h"
#include "extend/gpio.h"
#include "gpio_ext_conf.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

gpio_ext_t *gpio_ext_entry(gpio_t gpio)
{
if (gpio == GPIO_UNDEF) {
return NULL;
}

gpio_t devnum = gpio_ext_dev(gpio);

DEBUG("[gpio_ext_entry] list entry is %u\n", devnum);

/* device is greater than number of listed entries */
if (devnum >= (sizeof(gpio_ext_list) / sizeof(gpio_ext_list[0]))) {
return NULL;
}

/* Cast to discard const */
return (gpio_ext_t *)&gpio_ext_list[devnum];
}

int gpio_init_redir(gpio_t pin, gpio_mode_t mode)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_init_redir] ext entry doesn't exist for %X\n", pin);
return -1;
}

pin = gpio_ext_pin(pin);

return entry->driver->init(entry->dev, pin, mode);
}

#ifdef MODULE_PERIPH_GPIO_IRQ
int gpio_init_int_redir(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
gpio_cb_t cb, void *arg)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_init_int_redir] ext entry doesn't exist for %X\n", pin);
return -1;
}

pin = gpio_ext_pin(pin);

return entry->driver->init_int(entry->dev, pin, mode, flank, cb, arg);
}
#endif /* MODULE_PERIPH_GPIO_IRQ */

void gpio_irq_enable_redir(gpio_t pin)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_irq_enable_redir] ext entry doesn't exist for %X\n", pin);
return;
}

pin = gpio_ext_pin(pin);

entry->driver->irq_enable(entry->dev, pin);
}

void gpio_irq_disable_redir(gpio_t pin)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_irq_disable_redir] ext entry doesn't exist for %X\n", pin);
return;
}

pin = gpio_ext_pin(pin);

entry->driver->irq_disable(entry->dev, pin);
}

int gpio_read_redir(gpio_t pin)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_read_redir] ext entry doesn't exist for %X\n", pin);
return 0;
}

pin = gpio_ext_pin(pin);

return entry->driver->read(entry->dev, pin);
}

void gpio_set_redir(gpio_t pin)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_set_redir] ext entry doesn't exist for %X\n", pin);
return;
}

pin = gpio_ext_pin(pin);

entry->driver->set(entry->dev, pin);
}

void gpio_clear_redir(gpio_t pin)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_clear_redir] ext entry doesn't exist for %X\n", pin);
return;
}

pin = gpio_ext_pin(pin);

entry->driver->clear(entry->dev, pin);
}

void gpio_toggle_redir(gpio_t pin)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_toggle_redir] ext entry doesn't exist for %X\n", pin);
return;
}

pin = gpio_ext_pin(pin);

entry->driver->toggle(entry->dev, pin);
}

void gpio_write_redir(gpio_t pin, int value)
{
gpio_ext_t *entry = gpio_ext_entry(pin);

if (entry == NULL) {
DEBUG("[gpio_write_redir] ext entry doesn't exist for %X\n", pin);
return;
}

pin = gpio_ext_pin(pin);

entry->driver->write(entry->dev, pin, value);
}
ZetaR60 marked this conversation as resolved.
Show resolved Hide resolved

#endif /* MODULE_EXTEND_GPIO */
54 changes: 54 additions & 0 deletions drivers/extend/include/gpio_ext_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2018 Acutam Automation, LLC
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_extend_gpio
*
* @{
*
* @file
* @brief GPIO extension default / example list
*
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
*
* @}
*/

#ifndef GPIO_EXT_CONF_H
#define GPIO_EXT_CONF_H

#include <stddef.h>

#include "extend/gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Reference the driver struct
*/
extern gpio_ext_driver_t gpio_ext_notsup_driver;

/**
* @brief GPIO expansion default list if not defined
*/
static const gpio_ext_t gpio_ext_list[] =
{
{
.driver = &gpio_ext_notsup_driver,
.dev = NULL,
},
};

#ifdef __cplusplus
}
#endif

#endif /* GPIO_EXT_CONF_H */
/** @} */
Loading