saul/gpio: use saul_gpio_params_t structure as saul device

This provides the whole structure to read and write.
This commit is contained in:
Gaëtan Harter 2017-09-08 12:32:37 +02:00
parent d5ec78f917
commit be3029d890
2 changed files with 6 additions and 11 deletions

View File

@ -23,12 +23,13 @@
#include "saul.h" #include "saul.h"
#include "phydat.h" #include "phydat.h"
#include "periph/gpio.h" #include "periph/gpio.h"
#include "saul/periph.h"
static int read(const void *dev, phydat_t *res) static int read(const void *dev, phydat_t *res)
{ {
gpio_t pin = *((const gpio_t *)dev); const saul_gpio_params_t *p = (const saul_gpio_params_t *)dev;
res->val[0] = (gpio_read(pin)) ? 1 : 0; res->val[0] = (gpio_read(p->pin)) ? 1: 0;
memset(&(res->val[1]), 0, 2 * sizeof(int16_t)); memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
res->unit = UNIT_BOOL; res->unit = UNIT_BOOL;
res->scale = 0; res->scale = 0;
@ -37,8 +38,8 @@ static int read(const void *dev, phydat_t *res)
static int write(const void *dev, phydat_t *state) static int write(const void *dev, phydat_t *state)
{ {
gpio_t pin = *((const gpio_t *)dev); const saul_gpio_params_t *p = (const saul_gpio_params_t *)dev;
gpio_write(pin, state->val[0]); gpio_write(p->pin, state->val[0]);
return 1; return 1;
} }

View File

@ -32,11 +32,6 @@
*/ */
#define SAUL_GPIO_NUMOF (sizeof(saul_gpio_params)/sizeof(saul_gpio_params[0])) #define SAUL_GPIO_NUMOF (sizeof(saul_gpio_params)/sizeof(saul_gpio_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static gpio_t saul_gpios[SAUL_GPIO_NUMOF];
/** /**
* @brief Memory for the registry entries * @brief Memory for the registry entries
*/ */
@ -60,8 +55,7 @@ void auto_init_gpio(void)
LOG_DEBUG("[auto_init_saul] initializing GPIO #%u\n", i); LOG_DEBUG("[auto_init_saul] initializing GPIO #%u\n", i);
saul_gpios[i] = p->pin; saul_reg_entries[i].dev = p;
saul_reg_entries[i].dev = &(saul_gpios[i]);
saul_reg_entries[i].name = p->name; saul_reg_entries[i].name = p->name;
if ((p->mode == GPIO_IN) || (p->mode == GPIO_IN_PD) || if ((p->mode == GPIO_IN) || (p->mode == GPIO_IN_PD) ||
(p->mode == GPIO_IN_PU)) { (p->mode == GPIO_IN_PU)) {