Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions boards/mega-xplained/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ extern "C" {
* @{
*/
/* LED0,2 currently unsupported due to lack of GPIO_OD support */
#define LED1_PIN GPIO_PIN(PORT_B, 3)
#define LED1_MODE GPIO_OUT
#define LED_PORT_PIN0 GPIO_PIN(PORT_B, 0)

#define LED1_PIN GPIO_PIN(PORT_B, 3)
#define LED1_MODE GPIO_OUT

#define LED3_PIN GPIO_PIN(PORT_B, 2)
#define LED3_MODE GPIO_OUT

#define LED3_PIN GPIO_PIN(PORT_B, 2)
#define LED3_MODE GPIO_OUT
/** @} */

/**
Expand All @@ -94,13 +97,15 @@ extern "C" {
* @name Button pin configuration
* @{
*/
#define BTN0_PIN GPIO_PIN(PORT_B, 0)
#define BTN0_MODE GPIO_IN

#define BTN1_PIN GPIO_PIN(PORT_B, 1)
#define BTN1_MODE GPIO_IN
#define BTN_PORT_PIN0 GPIO_PIN(PORT_B, 0)

/* BTN2 currently unsupported due to lack of GPIO_OD support */
#define BTN0_PIN GPIO_PIN(PORT_B, 0)
#define BTN0_MODE GPIO_IN

#define BTN1_PIN GPIO_PIN(PORT_B, 1)
#define BTN1_MODE GPIO_IN
/** @} */

/**
* @name ADC NTC, light sensor, and filter lines
Expand Down
24 changes: 8 additions & 16 deletions boards/mega-xplained/include/gpio_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,21 @@ extern "C" {
static const saul_gpio_params_t saul_gpio_params[] =
{
{
.name = "Button 0",
.pin = BTN0_PIN,
.name = "Button %u",
.pin = BTN_PORT_PIN0,
.pinlist = (1 << (BTN0_PIN - BTN_PORT_PIN0))
| (1 << (BTN1_PIN - BTN_PORT_PIN0)),
.mode = BTN0_MODE,
.flags = SAUL_GPIO_INVERTED,
},
{
.name = "Button 1",
.pin = BTN1_PIN,
.mode = BTN1_MODE,
.flags = SAUL_GPIO_INVERTED,
},
/* BTN2, LED0,2 currently unsupported due to lack of GPIO_OD support */
{
.name = "LED 1",
.pin = LED1_PIN,
.name = "LED %u",
.pin = LED_PORT_PIN0,
.pinlist = (1 << (LED1_PIN - LED_PORT_PIN0))
| (1 << (LED3_PIN - LED_PORT_PIN0)),
.mode = LED1_MODE,
.flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR),
},
{
.name = "LED 3",
.pin = LED3_PIN,
.mode = LED3_MODE,
.flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR),
}
};

Expand Down
4 changes: 3 additions & 1 deletion drivers/adcxx1c/adcxx1c_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
#include "saul.h"
#include "adcxx1c.h"

static int read_adc(const void *dev, phydat_t *res)
static int read_adc(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

adcxx1c_read_raw((const adcxx1c_t *)dev, res->val);

res->unit = UNIT_NONE;
Expand Down
4 changes: 3 additions & 1 deletion drivers/ads101x/ads101x_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
* (5/8) * 2^16 = 40960 */
#define CONV_TO_B10 (40960L)

static int read_adc(const void *dev, phydat_t *res)
static int read_adc(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

/* Change the mux channel */
ads101x_set_mux_gain((const ads101x_t *)dev,
((ads101x_t *)dev)->params.mux_gain);
Expand Down
4 changes: 3 additions & 1 deletion drivers/adxl345/adxl345_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include "saul.h"
#include "adxl345.h"

static int read_acc(const void *dev, phydat_t *res)
static int read_acc(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

adxl345_read((const adxl345_t *)dev, (adxl345_data_t *)res->val);

res->unit = UNIT_G;
Expand Down
8 changes: 6 additions & 2 deletions drivers/bmp180/bmp180_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@
#include "bmp180.h"
#include "xtimer.h"

static int read_temperature(const void *dev, phydat_t *res)
static int read_temperature(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

res->val[0] = bmp180_read_temperature((const bmp180_t *)dev);
res->unit = UNIT_TEMP_C;
res->scale = -1;
return 1;
}

static int read_pressure(const void *dev, phydat_t *res)
static int read_pressure(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

res->val[0] = bmp180_read_pressure((const bmp180_t *)dev) / 100;
res->unit = UNIT_PA;
res->scale = 2;
Expand Down
12 changes: 9 additions & 3 deletions drivers/bmx055/bmx055_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#include "saul.h"
#include "bmx055.h"

static int read_mag(const void *dev, phydat_t *res)
static int read_mag(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (bmx055_mag_read((bmx055_t *)dev, (int16_t *)res) != BMX055_OK) {
return 0;
}
Expand All @@ -32,8 +34,10 @@ static int read_mag(const void *dev, phydat_t *res)
return 3;
}

static int read_acc(const void *dev, phydat_t *res)
static int read_acc(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (bmx055_acc_read((bmx055_t *)dev, (int16_t *)res) != BMX055_OK) {
return 0;
}
Expand All @@ -42,8 +46,10 @@ static int read_acc(const void *dev, phydat_t *res)
return 3;
}

static int read_gyro(const void *dev, phydat_t *res)
static int read_gyro(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (bmx055_gyro_read((bmx055_t *)dev, (int16_t *)res) != BMX055_OK) {
return 0;
}
Expand Down
12 changes: 9 additions & 3 deletions drivers/bmx280/bmx280_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@

#include "bmx280.h"

static int read_temperature(const void *dev, phydat_t *res)
static int read_temperature(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

res->val[0] = bmx280_read_temperature((const bmx280_t *)dev);
res->unit = UNIT_TEMP_C;
res->scale = -2;

return 1;
}

static int read_pressure(const void *dev, phydat_t *res)
static int read_pressure(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

res->val[0] = bmx280_read_pressure((const bmx280_t *)dev) / 100;
res->unit = UNIT_PA;
res->scale = 2;
Expand All @@ -43,8 +47,10 @@ static int read_pressure(const void *dev, phydat_t *res)
}

#ifdef MODULE_BME280
static int read_relative_humidity(const void *dev, phydat_t *res)
static int read_relative_humidity(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

res->val[0] = bme280_read_humidity((const bmx280_t *)dev);
res->unit = UNIT_PERCENT;
res->scale = -2;
Expand Down
8 changes: 6 additions & 2 deletions drivers/dht/dht_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ static int check_and_read(const void *dev, phydat_t *res, int16_t *val, uint8_t
return 1;
}

static int read_temp(const void *dev, phydat_t *res)
static int read_temp(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

return check_and_read(dev, res, &temp, UNIT_TEMP_C);
}

static int read_hum(const void *dev, phydat_t *res)
static int read_hum(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

return check_and_read(dev, res, &hum, UNIT_PERCENT);
}

Expand Down
8 changes: 6 additions & 2 deletions drivers/fxos8700/fxos8700_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include "saul.h"
#include "fxos8700.h"

static int read_mag(const void *dev, phydat_t *res)
static int read_mag(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (fxos8700_read_cached(dev, NULL, (fxos8700_measurement_t *)res)
!= FXOS8700_OK) {
/* Read failure */
Expand All @@ -35,8 +37,10 @@ static int read_mag(const void *dev, phydat_t *res)
return 3;
}

static int read_acc(const void *dev, phydat_t *res)
static int read_acc(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (fxos8700_read_cached(dev, (fxos8700_measurement_t *)res, NULL)
!= FXOS8700_OK) {
/* Read failure */
Expand Down
4 changes: 3 additions & 1 deletion drivers/grove_ledbar/grove_ledbar_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
#include "saul.h"
#include "grove_ledbar.h"

static int set_ledbar(const void *dev, phydat_t *res)
static int set_ledbar(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

uint8_t lvl = (uint8_t)res->val[0];
grove_ledbar_set((grove_ledbar_t *)dev, lvl);
return 1;
Expand Down
8 changes: 6 additions & 2 deletions drivers/hdc1000/hdc1000_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include "saul.h"
#include "hdc1000.h"

static int read_temp(const void *dev, phydat_t *res)
static int read_temp(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (hdc1000_read_cached((const hdc1000_t *)dev, &(res->val[0]), NULL) != HDC1000_OK) {
return -ECANCELED;
}
Expand All @@ -35,8 +37,10 @@ static int read_temp(const void *dev, phydat_t *res)
return 1;
}

static int read_hum(const void *dev, phydat_t *res)
static int read_hum(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (hdc1000_read_cached((const hdc1000_t *)dev, NULL, &(res->val[0])) != HDC1000_OK) {
return -ECANCELED;
}
Expand Down
8 changes: 6 additions & 2 deletions drivers/hts221/hts221_saul.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#include "saul.h"
#include "hts221.h"

static int read_temp(const void *dev, phydat_t *res)
static int read_temp(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (hts221_read_temperature((const hts221_t *)dev, &res->val[0]) != HTS221_OK) {
return -ECANCELED;
}
Expand All @@ -34,8 +36,10 @@ static int read_temp(const void *dev, phydat_t *res)
return 1;
}

static int read_hum(const void *dev, phydat_t *res)
static int read_hum(const void *dev, const uint8_t ctxt, phydat_t *res)
{
(void)ctxt;

if (hts221_read_humidity((const hts221_t *)dev, (uint16_t *)&res->val[0]) != HTS221_OK) {
return -ECANCELED;
}
Expand Down
16 changes: 9 additions & 7 deletions drivers/include/saul.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ enum {
* Actuators can chose to either just return -ENOTSUP or to return their current
* set value (e.g. useful for reading back the current state of a switch)
*
* @param[in] dev device descriptor of the target device
* @param[out] res data read from the device
* @param[in] dev device descriptor of the target device
* @param[in] ctxt context for target device
* @param[out] res data read from the device
*
* @return number of values written into to result data structure [1-3]
* @return -ENOTSUP if the device does not support this operation
* @return -ECANCELED on other errors
*/
typedef int(*saul_read_t)(const void *dev, phydat_t *res);
typedef int(*saul_read_t)(const void *dev, const uint8_t ctxt, phydat_t *res);

/**
* @brief Write a value (a set of values) to a device
Expand All @@ -131,14 +132,15 @@ typedef int(*saul_read_t)(const void *dev, phydat_t *res);
* For actuators this function is used to influence the actuators state, e.g.
* switching a switch or setting the speed of a motor.
*
* @param[in] dev device descriptor of the target device
* @param[in] data data to write to the device
* @param[in] dev device descriptor of the target device
* @param[in] ctxt context for target device
* @param[in] data data to write to the device
*
* @return number of values actually processed by the device [1-3]
* @return -ENOTSUP if the device does not support this operation
* @return -ECANCELED on other errors
*/
typedef int(*saul_write_t)(const void *dev, phydat_t *data);
typedef int(*saul_write_t)(const void *dev, const uint8_t ctxt, phydat_t *data);

/**
* @brief Definition of the RIOT actuator/sensor interface
Expand All @@ -152,7 +154,7 @@ typedef struct {
/**
* @brief Default not supported function
*/
int saul_notsup(const void *dev, phydat_t *dat);
int saul_notsup(const void *dev, const uint8_t ctxt, phydat_t *dat);

/**
* @brief Helper function converts a class ID to a string
Expand Down
18 changes: 11 additions & 7 deletions drivers/include/saul/periph.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef SAUL_PERIPH_H
#define SAUL_PERIPH_H

#include "saul_reg.h"

#if MODULE_SAUL_GPIO || DOXYGEN
#include "periph/gpio.h"
#endif /* MODULE_SAUL_GPIO */
Expand All @@ -45,10 +47,11 @@ typedef enum {
* @brief Direct mapped GPIO configuration values
*/
typedef struct {
const char *name; /**< name of the device connected to this pin */
gpio_t pin; /**< GPIO pin to initialize and expose */
gpio_mode_t mode; /**< pin mode to use */
saul_gpio_flags_t flags; /**< Configuration flags */
const char *name; /**< name of the device(s) on this pin */
gpio_t pin; /**< GPIO pin offset for ctxtlist */
saul_ctxt_list_t pinlist; /**< bit list of pins to map */
gpio_mode_t mode; /**< pin mode to use */
saul_gpio_flags_t flags; /**< Configuration flags */
} saul_gpio_params_t;
#endif /* MODULE_SAUL_GPIO */

Expand All @@ -57,9 +60,10 @@ typedef struct {
* @brief Direct mapped ADC configuration values
*/
typedef struct {
const char *name; /**< name of the device connected to this pin */
adc_t line; /**< ADC line to initialize and expose */
adc_res_t res; /**< ADC resolution */
const char *name; /**< name of the device(s) on this pin */
adc_t line; /**< ADC line offset for ctxtlist */
saul_ctxt_list_t linelist; /**< bit list of lines to expose */
adc_res_t res; /**< ADC resolution */
} saul_adc_params_t;
#endif /* MODULE_SAUL_ADC */

Expand Down
Loading