1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

saul: add support for grove ledbar

This commit is contained in:
smlng 2017-06-12 22:36:02 +02:00
parent 4fc150dfb9
commit ca0cc3956d
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2017 HAW Hamburg
*
* 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_grove_ledbar
* @{
*
* @file
* @brief Grove LED bar adaption to SAUL
*
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
#include <string.h>
#include <stdio.h>
#include "saul.h"
#include "grove_ledbar.h"
static int set_ledbar(const void *dev, phydat_t *res)
{
uint8_t lvl = (uint8_t)res->val[0];
grove_ledbar_set((grove_ledbar_t *)dev, lvl);
return 1;
}
const saul_driver_t grove_ledbar_saul_driver = {
.read = saul_notsup,
.write = set_ledbar,
.type = SAUL_ACT_LED_RGB,
};

View File

@ -20,6 +20,7 @@
#include "board.h"
#include "periph/gpio.h"
#include "saul_reg.h"
#include "grove_ledbar.h"
#include "my9221.h"
@ -72,6 +73,16 @@ static const grove_ledbar_params_t grove_ledbar_params[] =
#endif
};
/**
* @brief Additional meta information to keep in the SAUL registry
*/
static const saul_reg_info_t grove_ledbar_saul_info[] =
{
{
.name = "Grove LED bar"
}
};
#ifdef __cplusplus
}
#endif

View File

@ -291,6 +291,10 @@ void auto_init(void)
extern void auto_init_mpl3115a2(void);
auto_init_mpl3115a2();
#endif
#ifdef MODULE_GROVE_LEDBAR
extern void auto_init_grove_ledbar(void);
auto_init_grove_ledbar();
#endif
#ifdef MODULE_SI70XX
extern void auto_init_si70xx(void);
auto_init_si70xx();

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2017 HAW Hamburg
*
* 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 Grove LED bar
*
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
#ifdef MODULE_GROVE_LEDBAR
#include "log.h"
#include "saul_reg.h"
#include "grove_ledbar.h"
#include "grove_ledbar_params.h"
/**
* @brief Define the number of configured sensors
*/
#define GROVE_LEDBAR_NUM (sizeof(grove_ledbar_params) / sizeof(grove_ledbar_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static grove_ledbar_t grove_ledbar_devs[GROVE_LEDBAR_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[GROVE_LEDBAR_NUM];
/**
* @brief Reference the driver struct
*/
extern const saul_driver_t grove_ledbar_saul_driver;
void auto_init_grove_ledbar(void)
{
for (unsigned i = 0; i < GROVE_LEDBAR_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing Grove LED bar #%u: ", i);
if (my9221_init(&grove_ledbar_devs[i], &grove_ledbar_params[i]) != MY9221_OK) {
LOG_ERROR("ERROR\n");
continue;
}
LOG_DEBUG("SUCCESS\n");
saul_entries[i].dev = &(grove_ledbar_devs[i]);
saul_entries[i].name = grove_ledbar_saul_info[i].name;
saul_entries[i].driver = &grove_ledbar_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_GROVE_LEDBAR */