-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
17 changed files
with
957 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
MODULE = servo | ||
SUBMODULES := 1 | ||
|
||
include $(RIOTBASE)/Makefile.base |
Oops, something went wrong.