mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #4863 from gebart/pr/saul-adc
SAUL: Add periph/adc support
This commit is contained in:
commit
7c02c616bd
@ -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,16 @@ 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_adc
|
||||
PSEUDOMODULES += saul_default
|
||||
PSEUDOMODULES += saul_gpio
|
||||
PSEUDOMODULES += printf_float
|
||||
PSEUDOMODULES += schedstatistics
|
||||
|
||||
# include variants of the AT86RF2xx drivers as pseudo modules
|
||||
PSEUDOMODULES += at86rf23%
|
||||
|
@ -15,4 +15,5 @@ FEATURES_REQUIRED += periph_spi
|
||||
|
||||
ifneq (,$(filter saul_default,$(USEMODULE)))
|
||||
USEMODULE += saul_gpio
|
||||
USEMODULE += saul_adc
|
||||
endif
|
||||
|
126
boards/mulle/include/adc_params.h
Normal file
126
boards/mulle/include/adc_params.h
Normal file
@ -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 <joakim.nohlgard@eistec.se>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
/** @} */
|
@ -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
|
||||
*/
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
44
drivers/saul/adc_saul.c
Normal file
44
drivers/saul/adc_saul.c
Normal file
@ -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 <joakim.nohlgard@eistec.se>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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,
|
||||
};
|
@ -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";
|
||||
}
|
||||
|
@ -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();
|
||||
|
75
sys/auto_init/saul/auto_init_adc.c
Normal file
75
sys/auto_init/saul/auto_init_adc.c
Normal file
@ -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 <joakim.nohlgard@eistec.se>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#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 */
|
Loading…
Reference in New Issue
Block a user