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:
parent
d5ec78f917
commit
be3029d890
@ -23,12 +23,13 @@
|
||||
#include "saul.h"
|
||||
#include "phydat.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "saul/periph.h"
|
||||
|
||||
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
gpio_t pin = *((const gpio_t *)dev);
|
||||
res->val[0] = (gpio_read(pin)) ? 1 : 0;
|
||||
const saul_gpio_params_t *p = (const saul_gpio_params_t *)dev;
|
||||
res->val[0] = (gpio_read(p->pin)) ? 1: 0;
|
||||
memset(&(res->val[1]), 0, 2 * sizeof(int16_t));
|
||||
res->unit = UNIT_BOOL;
|
||||
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)
|
||||
{
|
||||
gpio_t pin = *((const gpio_t *)dev);
|
||||
gpio_write(pin, state->val[0]);
|
||||
const saul_gpio_params_t *p = (const saul_gpio_params_t *)dev;
|
||||
gpio_write(p->pin, state->val[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -32,11 +32,6 @@
|
||||
*/
|
||||
#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
|
||||
*/
|
||||
@ -60,8 +55,7 @@ void auto_init_gpio(void)
|
||||
|
||||
LOG_DEBUG("[auto_init_saul] initializing GPIO #%u\n", i);
|
||||
|
||||
saul_gpios[i] = p->pin;
|
||||
saul_reg_entries[i].dev = &(saul_gpios[i]);
|
||||
saul_reg_entries[i].dev = p;
|
||||
saul_reg_entries[i].name = p->name;
|
||||
if ((p->mode == GPIO_IN) || (p->mode == GPIO_IN_PD) ||
|
||||
(p->mode == GPIO_IN_PU)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user