From 1f645cf436b95d35279c930b8d2cb95577612288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Thu, 18 Feb 2016 06:21:14 +0100 Subject: [PATCH 1/4] drivers/saul: Fix typo in documentation --- drivers/include/saul.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/include/saul.h b/drivers/include/saul.h index e1a72e2e07..30c76807f9 100644 --- a/drivers/include/saul.h +++ b/drivers/include/saul.h @@ -76,7 +76,7 @@ enum { SAUL_ACT_MOTOR = 0x44, /**< actuator: motor */ SAUL_ACT_SWITCH = 0x45, /**< actuator: simple on/off switch */ SAUL_ACT_DIMMER = 0x46, /**< actuator: dimmable switch */ - SAUL_SENSE_ANY = 0x80, /**< any sensor - wildcart */ + SAUL_SENSE_ANY = 0x80, /**< any sensor - wildcard */ SAUL_SENSE_BTN = 0x81, /**< sensor: simple button */ SAUL_SENSE_TEMP = 0x82, /**< sensor: temperature */ SAUL_SENSE_HUM = 0x83, /**< sensor: humidity */ From 734892dbaa1c016fbec313c2a9d1c5943cee39fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 29 Mar 2016 19:02:45 +0200 Subject: [PATCH 2/4] Makefile.pseudomodules: Sort pseudomodule list --- Makefile.pseudomodules | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile.pseudomodules b/Makefile.pseudomodules index 1a45bacc10..6963794764 100644 --- a/Makefile.pseudomodules +++ b/Makefile.pseudomodules @@ -5,18 +5,18 @@ PSEUDOMODULES += conn_udp PSEUDOMODULES += core_msg PSEUDOMODULES += core_thread_flags PSEUDOMODULES += emb6_router -PSEUDOMODULES += gnrc_netdev_default PSEUDOMODULES += gnrc_ipv6_default PSEUDOMODULES += gnrc_ipv6_router PSEUDOMODULES += gnrc_ipv6_router_default +PSEUDOMODULES += gnrc_netdev_default PSEUDOMODULES += gnrc_neterr -PSEUDOMODULES += gnrc_sixlowpan_default +PSEUDOMODULES += gnrc_pktbuf PSEUDOMODULES += gnrc_sixlowpan_border_router_default +PSEUDOMODULES += gnrc_sixlowpan_default +PSEUDOMODULES += gnrc_sixlowpan_iphc_nhc PSEUDOMODULES += gnrc_sixlowpan_nd_border_router PSEUDOMODULES += gnrc_sixlowpan_router PSEUDOMODULES += gnrc_sixlowpan_router_default -PSEUDOMODULES += gnrc_sixlowpan_iphc_nhc -PSEUDOMODULES += gnrc_pktbuf PSEUDOMODULES += log PSEUDOMODULES += log_printfnoformat PSEUDOMODULES += lwip_arp @@ -32,15 +32,15 @@ PSEUDOMODULES += lwip_tcp PSEUDOMODULES += lwip_udp PSEUDOMODULES += lwip_udplite PSEUDOMODULES += netdev_default +PSEUDOMODULES += netif PSEUDOMODULES += netstats_l2 PSEUDOMODULES += newlib PSEUDOMODULES += newlib_nano PSEUDOMODULES += pktqueue -PSEUDOMODULES += schedstatistics -PSEUDOMODULES += netif +PSEUDOMODULES += printf_float PSEUDOMODULES += saul_default PSEUDOMODULES += saul_gpio -PSEUDOMODULES += printf_float +PSEUDOMODULES += schedstatistics # include variants of the AT86RF2xx drivers as pseudo modules PSEUDOMODULES += at86rf23% From 50b48c28ebf0d93d50090e6ddf8384cbc0515a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Thu, 18 Feb 2016 06:22:07 +0100 Subject: [PATCH 3/4] sys/saul: Add analog inputs to SAUL via periph/adc --- Makefile.pseudomodules | 1 + drivers/include/saul/periph.h | 19 ++++++++ drivers/saul/Makefile | 3 ++ drivers/saul/adc_saul.c | 44 ++++++++++++++++++ drivers/saul/saul_str.c | 1 + sys/auto_init/auto_init.c | 4 ++ sys/auto_init/saul/auto_init_adc.c | 75 ++++++++++++++++++++++++++++++ 7 files changed, 147 insertions(+) create mode 100644 drivers/saul/adc_saul.c create mode 100644 sys/auto_init/saul/auto_init_adc.c diff --git a/Makefile.pseudomodules b/Makefile.pseudomodules index 6963794764..2bc202a645 100644 --- a/Makefile.pseudomodules +++ b/Makefile.pseudomodules @@ -38,6 +38,7 @@ PSEUDOMODULES += newlib PSEUDOMODULES += newlib_nano PSEUDOMODULES += pktqueue PSEUDOMODULES += printf_float +PSEUDOMODULES += saul_adc PSEUDOMODULES += saul_default PSEUDOMODULES += saul_gpio PSEUDOMODULES += schedstatistics diff --git a/drivers/include/saul/periph.h b/drivers/include/saul/periph.h index 4f49cdf83d..00a148538f 100644 --- a/drivers/include/saul/periph.h +++ b/drivers/include/saul/periph.h @@ -19,12 +19,19 @@ #ifndef SAUL_PERIPH_H #define SAUL_PERIPH_H +#ifdef MODULE_SAUL_GPIO #include "periph/gpio.h" +#endif /* MODULE_SAUL_GPIO */ + +#ifdef MODULE_SAUL_ADC +#include "periph/adc.h" +#endif /* MODULE_SAUL_ADC */ #ifdef __cplusplus extern "C" { #endif +#ifdef MODULE_SAUL_GPIO /** * @brief Direct mapped GPIO configuration values */ @@ -33,6 +40,18 @@ typedef struct { gpio_t pin; /**< GPIO pin to initialize and expose */ gpio_mode_t mode; /**< pin mode to use */ } saul_gpio_params_t; +#endif /* MODULE_SAUL_GPIO */ + +#ifdef MODULE_SAUL_ADC +/** + * @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 */ +} saul_adc_params_t; +#endif /* MODULE_SAUL_ADC */ #ifdef __cplusplus } diff --git a/drivers/saul/Makefile b/drivers/saul/Makefile index cc5ba7234e..39dc655787 100644 --- a/drivers/saul/Makefile +++ b/drivers/saul/Makefile @@ -3,5 +3,8 @@ SRC = saul.c saul_str.c ifneq (,$(filter saul_gpio,$(USEMODULE))) SRC += gpio_saul.c endif +ifneq (,$(filter saul_adc,$(USEMODULE))) + SRC += adc_saul.c +endif include $(RIOTBASE)/Makefile.base diff --git a/drivers/saul/adc_saul.c b/drivers/saul/adc_saul.c new file mode 100644 index 0000000000..a7c81f2799 --- /dev/null +++ b/drivers/saul/adc_saul.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 Eistec AB + * + * 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_saul + * @{ + * + * @file + * @brief SAUL wrapper for direct access to analog pins + * + * @author Joakim Nohlgård + * + * @} + */ + +#include + +#include "saul.h" +#include "saul/periph.h" +#include "phydat.h" +#include "periph/adc.h" + + +static int read_adc(void *dev, phydat_t *res) +{ + const saul_adc_params_t *params = *((const saul_adc_params_t **)dev); + res->val[0] = adc_sample(params->line, params->res); + memset(&(res->val[1]), 0, 2 * sizeof(res->val[1])); + /* Raw ADC reading has no unit */ + res->unit = UNIT_NONE; + res->scale = 0; + return 1; +} + +const saul_driver_t adc_saul_driver = { + .read = read_adc, + .write = saul_notsup, + .type = SAUL_SENSE_ANALOG, +}; diff --git a/drivers/saul/saul_str.c b/drivers/saul/saul_str.c index fb9b5d9ce7..3e688563d8 100644 --- a/drivers/saul/saul_str.c +++ b/drivers/saul/saul_str.c @@ -46,6 +46,7 @@ const char *saul_class_to_str(uint8_t class_id) case SAUL_SENSE_GYRO: return "SENSE_GYRO"; case SAUL_SENSE_COLOR: return "SENSE_COLOR"; case SAUL_SENSE_PRESS: return "SENSE_PRESS"; + case SAUL_SENSE_ANALOG: return "SENSE_ANALOG"; case SAUL_CLASS_ANY: return "CLASS_ANY"; default: return "CLASS_UNKNOWN"; } diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 4488675a0f..9981271385 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -221,6 +221,10 @@ void auto_init(void) extern void auto_init_gpio(void); auto_init_gpio(); #endif +#ifdef MODULE_SAUL_ADC + extern void auto_init_adc(void); + auto_init_adc(); +#endif #ifdef MODULE_LSM303DLHC extern void auto_init_lsm303dlhc(void); auto_init_lsm303dlhc(); diff --git a/sys/auto_init/saul/auto_init_adc.c b/sys/auto_init/saul/auto_init_adc.c new file mode 100644 index 0000000000..16b020d434 --- /dev/null +++ b/sys/auto_init/saul/auto_init_adc.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2016 Eistec AB + * + * 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 auto_init_saul + * @{ + * + * @file + * @brief Auto initialization of ADC lines directly mapped to SAUL reg + * + * @author Joakim Nohlgård + * + * @} + */ + +#ifdef MODULE_SAUL_ADC + +#include "saul_reg.h" +#include "saul/periph.h" +#include "adc_params.h" +#include "periph/gpio.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +/** + * @brief Define the number of configured sensors + */ +#define SAUL_ADC_NUMOF (sizeof(saul_adc_params)/sizeof(saul_adc_params[0])) + +/** + * @brief Allocate memory for pointers to the ADC parameter structs + * + * We use this extra level of indirection to be able to keep the saul_adc_params + * array const and residing in ROM. + */ +static const saul_adc_params_t *saul_adcs[SAUL_ADC_NUMOF]; + +/** + * @brief Memory for the registry entries + */ +static saul_reg_t saul_reg_entries[SAUL_ADC_NUMOF]; + +/** + * @brief Reference the driver struct + */ +extern saul_driver_t adc_saul_driver; + +void auto_init_adc(void) +{ + DEBUG("auto init SAUL ADC\n"); + for (int i = 0; i < SAUL_ADC_NUMOF; i++) { + const saul_adc_params_t *p = &saul_adc_params[i]; + saul_adcs[i] = p; + + DEBUG("[auto_init_saul] initializing direct ADC\n"); + saul_reg_entries[i].dev = &saul_adcs[i]; + saul_reg_entries[i].name = p->name; + saul_reg_entries[i].driver = &adc_saul_driver; + /* initialize the ADC line */ + adc_init(p->line); + /* add to registry */ + saul_reg_add(&(saul_reg_entries[i])); + } +} + +#else +typedef int dont_be_pedantic; +#endif /* MODULE_SAUL_ADC */ From 99deb32911788f74e63996fdff4c5ac62018c577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Thu, 18 Feb 2016 06:17:45 +0100 Subject: [PATCH 4/4] boards/mulle: Add SAUL ADC parameters --- boards/mulle/Makefile.dep | 1 + boards/mulle/include/adc_params.h | 126 ++++++++++++++++++++++++++++++ boards/mulle/include/board.h | 8 ++ 3 files changed, 135 insertions(+) create mode 100644 boards/mulle/include/adc_params.h diff --git a/boards/mulle/Makefile.dep b/boards/mulle/Makefile.dep index d2c93c70bc..96549169fd 100644 --- a/boards/mulle/Makefile.dep +++ b/boards/mulle/Makefile.dep @@ -15,4 +15,5 @@ FEATURES_REQUIRED += periph_spi ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += saul_gpio + USEMODULE += saul_adc endif diff --git a/boards/mulle/include/adc_params.h b/boards/mulle/include/adc_params.h new file mode 100644 index 0000000000..36f6842cca --- /dev/null +++ b/boards/mulle/include/adc_params.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2016 Eistec AB + * + * 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 boards_mulle + * @{ + * + * @file + * @brief Board specific configuration of direct mapped ADC + * + * @author Joakim Nohlgård + */ + +#ifndef ADC_PARAMS_H +#define ADC_PARAMS_H + +#include "board.h" +#include "saul/periph.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief ADC configuration + */ +static const saul_adc_params_t saul_adc_params[] = +{ + { + .name = "k60temp", + .line = ADC_LINE(0), + .res = ADC_RES_16BIT, + }, + { + .name = "k60vrefsh", + .line = ADC_LINE(2), + .res = ADC_RES_16BIT, + }, + { + .name = "k60vrefsl", + .line = ADC_LINE(3), + .res = ADC_RES_16BIT, + }, + { + .name = "k60bandgap", + .line = ADC_LINE(1), + .res = ADC_RES_16BIT, + }, + { + .name = "DAC0feedback", + .line = ADC_LINE(4), + .res = ADC_RES_16BIT, + }, + { + .name = "VREFfeedback", + .line = ADC_LINE(5), + .res = ADC_RES_16BIT, + }, + { + .name = "Vbat", + .line = MULLE_VBAT_ADC_LINE, + .res = ADC_RES_16BIT, + }, + { + .name = "Vchr", + .line = MULLE_VCHR_ADC_LINE, + .res = ADC_RES_16BIT, + }, + { + .name = "PGA0_DP", + .line = ADC_LINE(8), + .res = ADC_RES_16BIT, + }, + { + .name = "PGA0_DM", + .line = ADC_LINE(9), + .res = ADC_RES_16BIT, + }, + { + .name = "PTA17", + .line = ADC_LINE(10), + .res = ADC_RES_16BIT, + }, + { + .name = "PTB0", + .line = ADC_LINE(11), + .res = ADC_RES_16BIT, + }, + { + .name = "PTC0", + .line = ADC_LINE(12), + .res = ADC_RES_16BIT, + }, + { + .name = "PTC8", + .line = ADC_LINE(13), + .res = ADC_RES_16BIT, + }, + { + .name = "PTC9", + .line = ADC_LINE(14), + .res = ADC_RES_16BIT, + }, + { + .name = "PTC10", + .line = ADC_LINE(15), + .res = ADC_RES_16BIT, + }, + { + .name = "PTC11", + .line = ADC_LINE(16), + .res = ADC_RES_16BIT, + }, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ADC_PARAMS_H */ +/** @} */ diff --git a/boards/mulle/include/board.h b/boards/mulle/include/board.h index c62e310bc3..e769b8e43b 100644 --- a/boards/mulle/include/board.h +++ b/boards/mulle/include/board.h @@ -119,6 +119,14 @@ void board_init(void); #define MULLE_NVRAM_SPI_ADDRESS_COUNT 1 /**< FRAM addressing size, in bytes */ /** @} */ +/** + * @name Mulle Vchr, Vbat ADC lines + */ +/** @{ */ +#define MULLE_VBAT_ADC_LINE ADC_LINE(6) +#define MULLE_VCHR_ADC_LINE ADC_LINE(7) +/** @} */ + /** * @name K60 clock dividers */