Skip to content

Commit

Permalink
sys/auto_init: Added auto initialization for pH OEM driver
Browse files Browse the repository at this point in the history
  • Loading branch information
skullbox305 committed Sep 5, 2019
1 parent 61d0970 commit 89082a3
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ void auto_init(void)
extern void auto_init_mpu9150(void);
auto_init_mpu9150();
#endif
#ifdef MODULE_PH_OEM
extern void auto_init_ph_oem(void);
auto_init_ph_oem();
#endif
#ifdef MODULE_PIR
extern void auto_init_pir(void);
auto_init_pir();
Expand Down
76 changes: 76 additions & 0 deletions sys/auto_init/saul/auto_init_ph_oem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2019 University of Applied Sciences Emden / Leer
*
* 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 sys_auto_init_saul
* @{
*
* @file
* @brief Auto initialization of Atlas Scientific pH OEM sensor
*
* @author igor.knippenberg@gmail.com
*
* @}
*/

#ifdef MODULE_PH_OEM

#include "assert.h"
#include "log.h"

#include "saul_reg.h"
#include "ph_oem.h"
#include "ph_oem_params.h"

/**
* @brief Define the number of configured sensors
*/
#define PH_OEM_NUM (sizeof(ph_oem_params) / sizeof(ph_oem_params[0]))

/**
* @brief Allocate memory for the device descriptors
*/
static ph_oem_t ph_oem_devs[PH_OEM_NUM];

/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[PH_OEM_NUM];

/**
* @brief Define the number of saul info
*/
#define PH_OEM_INFO_NUM (sizeof(ph_oem_saul_info) / sizeof(ph_oem_saul_info[0]))

/**
* @brief Reference the driver struct
*/
extern saul_driver_t ph_oem_saul_driver;

void auto_init_ph_oem(void)
{
assert(PH_OEM_INFO_NUM == PH_OEM_NUM);

for (unsigned i = 0; i < PH_OEM_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing ph_oem #%d\n", i);
if (ph_oem_init(&ph_oem_devs[i], &ph_oem_params[i]) < 0) {
LOG_ERROR("[auto_init_saul] error initializing ph_oem #%d\n", i);
continue;
}

saul_entries[i].dev = &(ph_oem_devs[i]);
saul_entries[i].name = ph_oem_saul_info[i].name;
saul_entries[i].driver = &ph_oem_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}

#else
typedef int dont_be_pedantic;
#endif /* MODULE_PH_OEM */

0 comments on commit 89082a3

Please sign in to comment.