Loading...
Searching...
No Matches
servo.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Freie Universität Berlin
3 * SPDX-FileCopyrightText: 2015 Eistec AB
4 * SPDX-FileCopyrightText: 2022 Otto-von-Guericke-Universität Magdeburg
5 * SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8#pragma once
9
40
41#include <stddef.h>
42#include <stdint.h>
43
44#include "periph/pwm.h"
45#include "periph/timer.h"
46#include "saul.h"
47#include "saul_reg.h"
48#include "time_units.h"
49
50#ifndef SERVO_TIMER_MAX_CHAN
62#define SERVO_TIMER_MAX_CHAN 4
63#endif
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
73
79typedef struct {
80 uint16_t res;
81 uint16_t freq;
84
88typedef struct servo servo_t;
89
102
112
116typedef struct {
117#if defined(MODULE_SERVO_PWM) || defined(DOXYGEN)
124#endif
125#if defined(MODULE_SERVO_TIMER) || defined(DOXYGEN)
137 gpio_t servo_pin;
138#endif
139 uint16_t min_us;
140 uint16_t max_us;
141#ifdef MODULE_SERVO_PWM
147 uint8_t pwm_chan;
148#endif
149#ifdef MODULE_SERVO_TIMER
161 uint8_t timer_chan;
162#endif
164
168struct servo {
178 uint16_t min;
187 uint16_t max;
188#ifdef MODULE_SERVO_TIMER
189 uint16_t current;
190#endif
191};
192
193#if defined(MODULE_SERVO_TIMER) || DOXYGEN
198#endif
199
209int servo_init(servo_t *dev, const servo_params_t *params);
210
225void servo_set(servo_t *dev, uint8_t pos);
226
227#ifdef __cplusplus
228}
229#endif
230
Low-level timer peripheral driver interface definitions.
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
uint_fast8_t pwm_t
Default PWM type definition.
Definition pwm.h:88
uint_fast8_t tim_t
Default timer type.
Definition timer.h:67
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:62
void servo_set(servo_t *dev, uint8_t pos)
Set the servo motor to a specified position.
struct servo servo_t
Servo device state.
Definition servo.h:88
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:286
Configuration parameters for a servo.
Definition servo.h:116
uint16_t max_us
Duration of high phase (in µs) for max extension.
Definition servo.h:140
const servo_pwm_params_t * pwm
Specification of the PWM device the servo is connected to.
Definition servo.h:123
gpio_t servo_pin
GPIO pin the servo is connected to.
Definition servo.h:137
uint16_t min_us
Duration of high phase (in µs) for min extension.
Definition servo.h:139
const servo_timer_params_t * timer
Specification of the timer to use.
Definition servo.h:131
PWM configuration parameters for a servos.
Definition servo.h:79
pwm_t pwm
PWM dev the servo is connected to.
Definition servo.h:82
uint16_t res
PWM resolution to use.
Definition servo.h:80
uint16_t freq
PWM frequency to use.
Definition servo.h:81
Memory needed for book keeping when using periph_timer_periodic based servo driver.
Definition servo.h:93
servo_t * servo_map[SERVO_TIMER_MAX_CHAN]
Look up table to get from channel.
Definition servo.h:100
Timer configuration parameters for a servos.
Definition servo.h:106
servo_timer_ctx_t * ctx
Per-timer state needed for book keeping.
Definition servo.h:110
tim_t timer
Timer to use.
Definition servo.h:107
uint16_t servo_freq
Servo frequency (typically 50 Hz or 100 Hz)
Definition servo.h:109
uint32_t timer_freq
Timer frequency to use.
Definition servo.h:108
Servo device state.
Definition servo.h:168
uint16_t min
Minimum PWM duty cycle / timer target matching servo_params_t::min_us.
Definition servo.h:178
uint16_t max
Maximum PWM duty cycle / timer target matching servo_params_t::min_us.
Definition servo.h:187
const servo_params_t * params
Parameters of this servo.
Definition servo.h:169
Utility header providing time unit defines.