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 
11 #pragma once
12 
44 #include <stddef.h>
45 #include <stdint.h>
46 
47 #include "periph/pwm.h"
48 #include "periph/timer.h"
49 #include "saul.h"
50 #include "saul_reg.h"
51 #include "time_units.h"
52 
53 #ifndef SERVO_TIMER_MAX_CHAN
65 #define SERVO_TIMER_MAX_CHAN 4
66 #endif
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
76 
82 typedef struct {
83  uint16_t res;
84  uint16_t freq;
87 
91 typedef struct servo servo_t;
92 
96 typedef struct {
105 
109 typedef struct {
111  uint32_t timer_freq;
112  uint16_t servo_freq;
115 
119 typedef struct {
120 #if defined(MODULE_SERVO_PWM) || defined(DOXYGEN)
127 #endif
128 #if defined(MODULE_SERVO_TIMER) || defined(DOXYGEN)
140  gpio_t servo_pin;
141 #endif
142  uint16_t min_us;
143  uint16_t max_us;
144 #ifdef MODULE_SERVO_PWM
150  uint8_t pwm_chan;
151 #endif
152 #ifdef MODULE_SERVO_TIMER
164  uint8_t timer_chan;
165 #endif
167 
171 struct servo {
181  uint16_t min;
190  uint16_t max;
191 #ifdef MODULE_SERVO_TIMER
192  uint16_t current;
193 #endif
194 };
195 
196 #if defined(MODULE_SERVO_TIMER) || DOXYGEN
201 #endif
202 
212 int servo_init(servo_t *dev, const servo_params_t *params);
213 
228 void servo_set(servo_t *dev, uint8_t pos);
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 
Low-level timer peripheral driver interface definitions.
uint_fast8_t pwm_t
Default PWM type definition.
Definition: pwm.h:91
uint_fast8_t tim_t
Default timer type.
Definition: timer.h:70
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:65
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:283
Configuration parameters for a servo.
Definition: servo.h:119
uint16_t max_us
Duration of high phase (in µs) for max extension.
Definition: servo.h:143
const servo_pwm_params_t * pwm
Specification of the PWM device the servo is connected to.
Definition: servo.h:126
gpio_t servo_pin
GPIO pin the servo is connected to.
Definition: servo.h:140
uint16_t min_us
Duration of high phase (in µs) for min extension.
Definition: servo.h:142
const servo_timer_params_t * timer
Specification of the timer to use.
Definition: servo.h:134
PWM configuration parameters for a servos.
Definition: servo.h:82
pwm_t pwm
PWM dev the servo is connected to.
Definition: servo.h:85
uint16_t res
PWM resolution to use.
Definition: servo.h:83
uint16_t freq
PWM frequency to use.
Definition: servo.h:84
Memory needed for book keeping when using periph_timer_periodic based servo driver.
Definition: servo.h:96
Timer configuration parameters for a servos.
Definition: servo.h:109
servo_timer_ctx_t * ctx
Per-timer state needed for book keeping.
Definition: servo.h:113
tim_t timer
Timer to use.
Definition: servo.h:110
uint16_t servo_freq
Servo frequency (typically 50 Hz or 100 Hz)
Definition: servo.h:112
uint32_t timer_freq
Timer frequency to use.
Definition: servo.h:111
Servo device state.
Definition: servo.h:171
uint16_t min
Minimum PWM duty cycle / timer target matching servo_params_t::min_us.
Definition: servo.h:181
uint16_t max
Maximum PWM duty cycle / timer target matching servo_params_t::min_us.
Definition: servo.h:190
const servo_params_t * params
Parameters of this servo.
Definition: servo.h:172
Functionality for reading [S]ensor [A]ctuator [U]ber [L]ayer sensors as SenML.
Utility header providing time unit defines.