Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
servo.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the Institute nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*
29
* This file is part of the Contiki operating system.
30
*
31
*/
32
/*---------------------------------------------------------------------------*/
33
/**
34
* \addtogroup zoul-sensors
35
* @{
36
*
37
* \defgroup zoul-servo Generic servo driver
38
*
39
* Driver for a Generic Servo actuator
40
*
41
* @{
42
*
43
* \file
44
* Header file for a Generic Servo driver
45
*
46
* \author
47
* Antonio Lignan <alinan@zolertia.com>
48
*/
49
/*---------------------------------------------------------------------------*/
50
#ifndef SERVO_H_
51
#define SERVO_H_
52
#include <stdio.h>
53
#include "
dev/pwm.h
"
54
/* -------------------------------------------------------------------------- */
55
/**
56
* \name Servo default settings
57
* @{
58
*/
59
/* -------------------------------------------------------------------------- */
60
#ifndef SERVO_CONF_FREQ
61
#define SERVO_DEFAULT_FREQ 50
/**< 50 Hz */
62
#else
63
#define SERVO_DEFAULT_FREQ SERVO_CONF_FREQ
64
#endif
65
66
#ifndef SERVO_CONF_MAX_DEGREES
67
#define SERVO_MAX_DEGREES 180
68
#else
69
#define SERVO_MAX_DEGREES SERVO_CONF_MAX_DEGREES
70
#endif
71
72
#ifndef SERVO_CONF_MIN_VAL
73
#define SERVO_MIN_VAL 9600
/**> roughly equals to 3% duty cycle */
74
#else
75
#define SERVO_MIN_VAL SERVO_CONF_MIN_VAL
76
#endif
77
78
#ifndef SERVO_CONF_MAX_VAL
79
#define SERVO_MAX_VAL 38400
/**> roughly equals to 12% duty cycle */
80
#else
81
#define SERVO_MAX_VAL SERVO_CONF_MAX_VAL
82
#endif
83
/** @} */
84
/* -------------------------------------------------------------------------- */
85
/**
86
* \name Servo general purpose timers mapping
87
* @{
88
*/
89
#define SERVO_CHANNEL_1 0x001
/**< GPT0-B */
90
#define SERVO_CHANNEL_2 0x100
/**< GPT1-A */
91
#define SERVO_CHANNEL_3 0x101
/**< GPT1-B */
92
#define SERVO_CHANNEL_4 0x200
/**< GPT2-A */
93
#define SERVO_CHANNEL_5 0x201
/**< GPT2-B */
94
#define SERVO_CHANNEL_6 0x300
/**< GPT3-A */
95
#define SERVO_CHANNEL_7 0x301
/**< GPT3-B */
96
/** @} */
97
/* -------------------------------------------------------------------------- */
98
/**
99
* \name Servo general constants
100
* @{
101
*/
102
#define SERVO_SUCCESS 0
103
#define SERVO_ERROR (-1)
104
/** @} */
105
/* -------------------------------------------------------------------------- */
106
/**
107
* \name Servo public funtions
108
* @{
109
*/
110
111
/** \brief Configures and positions a servo in a given position (by degrees)
112
* The servo will lock its position as long as it is not stopped
113
* \param gptab Servo channel (PWM GPT from 1-7)
114
* \param port Port number to use as PWM
115
* \param pin Pin number to use as PWM
116
* \param pos Position to map the servo to (0-360ยบ, integer)
117
* \return \c SERVO_SUCCESS if successful, else \c SERVO_ERROR
118
*/
119
int
servo_position
(uint16_t gptab, uint8_t port, uint8_t pin, uint16_t pos);
120
121
/** \brief Fully stop a servo and reconfigures back the pin/port as GPIO
122
* \param gptab Servo channel (PWM GPT from 1-7)
123
* \param port Port number to use as PWM
124
* \param pin Pin number to use as PWM
125
* \return \c SERVO_SUCCESS if successful, else \c SERVO_ERROR
126
*/
127
int
servo_stop
(uint16_t gptab, uint8_t port, uint8_t pin);
128
/** @} */
129
/* -------------------------------------------------------------------------- */
130
#endif
131
/* -------------------------------------------------------------------------- */
132
/**
133
* @}
134
* @}
135
*/
136
servo_position
int servo_position(uint16_t gptab, uint8_t port, uint8_t pin, uint16_t pos)
Configures and positions a servo in a given position (by degrees) The servo will lock its position as...
Definition
servo.c:55
servo_stop
int servo_stop(uint16_t gptab, uint8_t port, uint8_t pin)
Fully stop a servo and reconfigures back the pin/port as GPIO.
Definition
servo.c:105
pwm.h
Header file for the CC2538 PWM driver.
arch
platform
zoul
dev
servo.h
Generated on
for Contiki-NG by
1.17.0