servo_params.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
21 #include "board.h"
22 #include "macros/units.h"
23 #include "periph/gpio.h"
24 #include "periph/pwm.h"
25 #include "periph/timer.h"
26 #include "saul_reg.h"
27 #include "servo.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
37 #ifndef SERVO_PWM_PARAM_DEV
43 #define SERVO_PWM_PARAM_DEV PWM_DEV(0)
44 #endif
45 
46 #ifndef SERVO_PWM_PARAM_RES
52 #define SERVO_PWM_PARAM_RES UINT16_MAX
53 #endif
54 
55 #ifndef SERVO_PWM_PARAM_FREQ
61 #define SERVO_PWM_PARAM_FREQ 50
62 #endif
63 
64 #ifndef SERVO_PWM_PARAMS
68 #define SERVO_PWM_PARAMS {\
69  .pwm = SERVO_PWM_PARAM_DEV, \
70  .freq = SERVO_PWM_PARAM_FREQ, \
71  .res = SERVO_PWM_PARAM_RES, \
72  }
73 #endif
80 {
82 };
83 
88 #ifndef SERVO_TIMER_PARAM_DEV
94 #define SERVO_TIMER_PARAM_DEV TIMER_DEV(1)
95 #endif
96 
97 #ifndef SERVO_TIMER_PARAM_TIMER_FREQ
103 #define SERVO_TIMER_PARAM_TIMER_FREQ MHZ(1)
104 #endif
105 
106 #ifndef SERVO_TIMER_PARAM_SERVO_FREQ
112 #define SERVO_TIMER_PARAM_SERVO_FREQ 50
113 #endif
114 
115 #ifndef SERVO_TIMER_PARAM_TIMER_CTX
129 #define SERVO_TIMER_PARAM_TIMER_CTX (&servo_timer_default_ctx)
130 #endif
131 
132 #ifndef SERVO_TIMER_PARAMS
136 #define SERVO_TIMER_PARAMS {\
137  .timer = SERVO_TIMER_PARAM_DEV, \
138  .timer_freq = SERVO_TIMER_PARAM_TIMER_FREQ, \
139  .servo_freq = SERVO_TIMER_PARAM_SERVO_FREQ, \
140  .ctx = SERVO_TIMER_PARAM_TIMER_CTX, \
141  }
142 #endif
149 {
151 };
152 
157 #ifndef SERVO_PARAM_PWM_PARAMS
163 #define SERVO_PARAM_PWM_PARAMS (&servo_pwm_params[0])
164 #endif
165 
166 #ifndef SERVO_PARAM_TIMER_PARAMS
172 #define SERVO_PARAM_TIMER_PARAMS (&servo_timer_params[0])
173 #endif
174 
175 #ifndef SERVO_PARAM_PWM_CHAN
181 #define SERVO_PARAM_PWM_CHAN 0
182 #endif
183 
184 #ifndef SERVO_PARAM_TIMER_CHAN
190 #define SERVO_PARAM_TIMER_CHAN 1
191 #endif
192 
193 #ifndef SERVO_PARAM_PIN
199 #define SERVO_PARAM_PIN GPIO_UNDEF
200 #endif
201 
202 #ifndef SERVO_PARAM_MIN_US
208 #define SERVO_PARAM_MIN_US 900UL
209 #endif
210 
211 #ifndef SERVO_PARAM_MAX_US
217 #define SERVO_PARAM_MAX_US 2100UL
218 #endif
219 
220 #ifndef SERVO_PARAMS
224 #ifdef MODULE_SERVO_PWM
225 #define SERVO_PARAMS {\
226  .pwm = SERVO_PARAM_PWM_PARAMS, \
227  .min_us = SERVO_PARAM_MIN_US, \
228  .max_us = SERVO_PARAM_MAX_US, \
229  .pwm_chan = SERVO_PARAM_PWM_CHAN, \
230  }
231 #endif
232 #ifdef MODULE_SERVO_TIMER
233 #define SERVO_PARAMS {\
234  .timer = SERVO_PARAM_TIMER_PARAMS, \
235  .servo_pin = SERVO_PARAM_PIN, \
236  .min_us = SERVO_PARAM_MIN_US, \
237  .max_us = SERVO_PARAM_MAX_US, \
238  .timer_chan = SERVO_PARAM_TIMER_CHAN, \
239  }
240 #endif
241 #endif
247 static const servo_params_t servo_params[] =
248 {
249  SERVO_PARAMS
250 };
251 
252 #ifndef SERVO_SAULINFO
256 #define SERVO_SAULINFO { .name = "servo" }
257 #endif
258 
263 {
265 };
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
Low-level timer peripheral driver interface definitions.
Low-level GPIO peripheral driver interface definitions.
Low-level PWM peripheral driver interface definitions.
SAUL registry interface definition.
High-level driver for easy handling of servo motors.
static const servo_params_t servo_params[]
Parameters for controlling a servo.
Definition: servo_params.h:247
#define SERVO_SAULINFO
Servo SAUL info.
Definition: servo_params.h:256
#define SERVO_TIMER_PARAMS
TIMER parameters for controlling a servo.
Definition: servo_params.h:136
servo_timer_ctx_t servo_timer_default_ctx
Default servo timer context.
static const servo_pwm_params_t servo_pwm_params[]
Servo PWM parameters.
Definition: servo_params.h:79
#define SERVO_PWM_PARAMS
PWM parameters for controlling a servo.
Definition: servo_params.h:68
static const servo_timer_params_t servo_timer_params[]
Servo timer parameters.
Definition: servo_params.h:148
static const saul_reg_info_t servo_saul_info[]
Allocate and configure entries to the SAUL registry.
Definition: servo_params.h:262
Additional data to collect for each entry.
Definition: saul_reg.h:48
Configuration parameters for a servo.
Definition: servo.h:119
PWM configuration parameters for a servos.
Definition: servo.h:82
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
Unit helper macros.