1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/saul/init_devs/auto_init_pca9685.c
Alexandre Abadie f585b53d03
drivers/saul/auto_init: remove useless preprocessor directives
The files are now built only when the corresponding module is used
2020-06-08 11:10:48 +02:00

91 lines
2.5 KiB
C

/*
* Copyright (C) 2017 Mesotic SAS
*
* 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_pca9685
* @ingroup sys_auto_init_saul
* @brief Auto initialization of PCA9685 I2C PWM controller
* @author Gunar Schorcht <gunar@schorcht.net>
* @file
*/
#include "assert.h"
#include "log.h"
#include "saul_reg.h"
#include "saul/periph.h"
#include "pca9685.h"
#include "pca9685_params.h"
/**
* @brief Number of configured PCA9685 DAC devices
*/
#define PCA9685_NUM (ARRAY_SIZE(pca9685_params))
/**
* @brief Number of configured SAUL PCA9685 DAC channels
*/
#define PCA9685_SAUL_DAC_NUMOF (ARRAY_SIZE(pca9685_saul_pwm_params))
/**
* @brief Number of saul info
*/
#define PCA9685_INFO_NUM (ARRAY_SIZE(pca9685_saul_info))
/**
* @brief Allocate the memory for the PCA9685 DAC device descriptors
*/
pca9685_t pca9685_devs[PCA9685_NUM];
/**
* @brief Allocate the memory for PCA9685 DAC SAUL registry entries
*/
static saul_reg_t pca9685_saul_reg_entries[PCA9685_SAUL_DAC_NUMOF];
/**
* @brief Reference the PCA9685 DAC input mode driver struct
*/
extern saul_driver_t pca9685_pwm_in_saul_driver;
/**
* @brief Reference to the PCA9685 DAC output mode driver struct
*/
extern saul_driver_t pca9685_pwm_saul_driver;
void auto_init_pca9685(void)
{
for (unsigned int i = 0; i < PCA9685_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing PCA9685 PWM dev #%u\n", i);
pca9685_init(&pca9685_devs[i], &pca9685_params[i]);
pca9685_pwm_init(&pca9685_devs[i], pca9685_params[i].mode,
pca9685_params[i].freq,
pca9685_params[i].res);
}
for (unsigned int i = 0; i < PCA9685_SAUL_DAC_NUMOF; i++) {
const pca9685_saul_pwm_params_t *p = &pca9685_saul_pwm_params[i];
LOG_DEBUG("[auto_init_saul] initializing PCA9685 channel #%u\n", i);
/* check the PCA9685 device index */
assert(p->dev < PCA9685_NUM);
pca9685_saul_reg_entries[i].dev = (void *)p;
pca9685_saul_reg_entries[i].name = p->name;
pca9685_saul_reg_entries[i].driver = &pca9685_pwm_saul_driver;
/* initialize the PCA9685 pin */
pca9685_pwm_set(&pca9685_devs[p->dev], p->channel, p->initial);
/* add to registry */
saul_reg_add(&(pca9685_saul_reg_entries[i]));
}
}