-
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
14 changed files
with
909 additions
and
207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
MODULE = servo | ||
SUBMODULES := 1 | ||
|
||
include $(RIOTBASE)/Makefile.base |
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 +1,22 @@ | ||
FEATURES_REQUIRED += periph_pwm | ||
ifneq (,$(filter saul,$(USEMODULE))) | ||
DEFAULT_MODULE += servo_saul | ||
endif | ||
|
||
# if no servo driver implementation is chosen, we pick one | ||
ifeq (,$(filter servo_pwm servo_timer,$(USEMODULE))) | ||
# choose servo_pwm except for MCUs known to be incompatible | ||
ifneq (,$(filter nrf5%, $(CPU_FAM))) | ||
USEMODULE += servo_timer | ||
else | ||
USEMODULE += servo_pwm | ||
endif | ||
endif | ||
|
||
ifneq (,$(filter servo_pwm,$(USEMODULE))) | ||
FEATURES_REQUIRED += periph_pwm | ||
endif | ||
|
||
ifneq (,$(filter servo_timer,$(USEMODULE))) | ||
FEATURES_REQUIRED += periph_timer_periodic | ||
FEATURES_REQUIRED += periph_gpio | ||
endif |
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,2 @@ | ||
USEMODULE_INCLUDES_servo := $(LAST_MAKEFILEDIR)/include | ||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_servo) |
Oops, something went wrong.