Loading...
Searching...
No Matches
servo.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Freie Universität Berlin
3 * Copyright (C) 2015 Eistec AB
4 * Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg
5 *
6 * This file is subject to the terms and conditions of the GNU Lesser General
7 * Public License v2.1. See the file LICENSE in the top level directory for more
8 * details.
9 */
10
42#ifndef SERVO_H
43#define SERVO_H
44
45#include <stddef.h>
46#include <stdint.h>
47
48#include "periph/pwm.h"
49#include "periph/timer.h"
50#include "saul.h"
51#include "saul_reg.h"
52#include "time_units.h"
53
54#ifndef SERVO_TIMER_MAX_CHAN
66#define SERVO_TIMER_MAX_CHAN 4
67#endif
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
77
83typedef struct {
84 uint16_t res;
85 uint16_t freq;
88
92typedef struct servo servo_t;
93
97typedef struct {
106
116
120typedef struct {
121#if defined(MODULE_SERVO_PWM) || defined(DOXYGEN)
128#endif
129#if defined(MODULE_SERVO_TIMER) || defined(DOXYGEN)
141 gpio_t servo_pin;
142#endif
143 uint16_t min_us;
144 uint16_t max_us;
145#ifdef MODULE_SERVO_PWM
151 uint8_t pwm_chan;
152#endif
153#ifdef MODULE_SERVO_TIMER
165 uint8_t timer_chan;
166#endif
168
172struct servo {
182 uint16_t min;
191 uint16_t max;
192#ifdef MODULE_SERVO_TIMER
193 uint16_t current;
194#endif
195};
196
197#if defined(MODULE_SERVO_TIMER) || DOXYGEN
202#endif
203
213int servo_init(servo_t *dev, const servo_params_t *params);
214
229void servo_set(servo_t *dev, uint8_t pos);
230
231#ifdef __cplusplus
232}
233#endif
234
235#endif /* SERVO_H */
Low-level timer peripheral driver interface definitions.
uint_fast8_t pwm_t
Default PWM type definition.
Definition pwm.h:92
uint_fast8_t tim_t
Default timer type.
Definition timer.h:71
servo_timer_ctx_t servo_timer_default_ctx
Default timer context.
int servo_init(servo_t *dev, const servo_params_t *params)
Initialize servo.
#define SERVO_TIMER_MAX_CHAN
In case the servo_timer backend is used to driver the servo, this is the highest channel number usabl...
Definition servo.h:66
void servo_set(servo_t *dev, uint8_t pos)
Set the servo motor to a specified position.
const saul_driver_t servo_saul_driver
The SAUL adaption driver for servos.
Low-level PWM peripheral driver interface definitions.
SAUL registry interface definition.
Definition of the RIOT actuator/sensor interface.
Definition saul.h:284
Configuration parameters for a servo.
Definition servo.h:120
uint16_t max_us
Duration of high phase (in µs) for max extension.
Definition servo.h:144
const servo_pwm_params_t * pwm
Specification of the PWM device the servo is connected to.
Definition servo.h:127
gpio_t servo_pin
GPIO pin the servo is connected to.
Definition servo.h:141
uint16_t min_us
Duration of high phase (in µs) for min extension.
Definition servo.h:143
const servo_timer_params_t * timer
Specification of the timer to use.
Definition servo.h:135
PWM configuration parameters for a servos.
Definition servo.h:83
pwm_t pwm
PWM dev the servo is connected to.
Definition servo.h:86
uint16_t res
PWM resolution to use.
Definition servo.h:84
uint16_t freq
PWM frequency to use.
Definition servo.h:85
Memory needed for book keeping when using periph_timer_periodic based servo driver.
Definition servo.h:97
Timer configuration parameters for a servos.
Definition servo.h:110
servo_timer_ctx_t * ctx
Per-timer state needed for book keeping.
Definition servo.h:114
tim_t timer
Timer to use.
Definition servo.h:111
uint16_t servo_freq
Servo frequency (typically 50 Hz or 100 Hz)
Definition servo.h:113
uint32_t timer_freq
Timer frequency to use.
Definition servo.h:112
Servo device state.
Definition servo.h:172
uint16_t min
Minimum PWM duty cycle / timer target matching servo_params_t::min_us.
Definition servo.h:182
uint16_t max
Maximum PWM duty cycle / timer target matching servo_params_t::min_us.
Definition servo.h:191
const servo_params_t * params
Parameters of this servo.
Definition servo.h:173
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.
Utility header providing time unit defines.