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_servo.c
Marian Buschsieweke 6dc2a60597
drivers/servo: reimplement with high level interface
The previous servo driver didn't provide any benefit over using PWM
directly, as users controlled the servo in terms of PWM duty cycles.
This changes the interface to provide a high level interface that
abstracts the gory PWM details.

In addition, a SAUL layer and auto-initialization is provided.

Co-authored-by: benpicco <benpicco@googlemail.com>
2023-02-22 10:00:04 +01:00

59 lines
1.4 KiB
C

/*
* Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg
*
* 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
* @ingroup sys_auto_init_saul
* @{
*
* @file
* @brief Auto initialization for servo motors
*
* @author Marian Buschsieweke <marian.buschsieweke@ovgu.de>
*
* @}
*/
#include <string.h>
#include <stdint.h>
#include "assert.h"
#include "kernel_defines.h"
#include "log.h"
#include "phydat.h"
#include "saul.h"
#include "saul/periph.h"
#include "saul_reg.h"
#include "servo.h"
#include "servo_params.h"
#define SERVO_NUMOF ARRAY_SIZE(servo_params)
static servo_t servos[SERVO_NUMOF];
static saul_reg_t saul_entries[SERVO_NUMOF];
void auto_init_servo(void)
{
for (unsigned i = 0; i < SERVO_NUMOF; i++) {
LOG_DEBUG("[servo] auto-init servo #%u\n", i);
int retval = servo_init(&servos[i], &servo_params[i]);
if (retval != 0) {
LOG_WARNING("[servo] auto-init of servo #%u failed: %d\n",
i, retval);
continue;
}
saul_reg_t *e = &saul_entries[i];
e->dev = &servos[i];
e->name = servo_saul_info[i].name;
e->driver = &servo_saul_driver;
saul_reg_add(e);
}
}