Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-pwm.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 
24 #include <sol-common-buildopts.h>
25 #include <sol-macros.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
60 struct sol_pwm;
61 typedef struct sol_pwm sol_pwm;
62 
72 };
73 
86 };
87 
95 typedef struct sol_pwm_config {
96 #ifndef SOL_NO_API_VERSION
97 #define SOL_PWM_CONFIG_API_VERSION (1)
98  uint16_t api_version;
99 #endif
100  int32_t period_ns;
101  int32_t duty_cycle_ns;
104  bool enabled;
106 
118 enum sol_pwm_alignment sol_pwm_alignment_from_str(const char *pwm_alignment)
119 #ifndef DOXYGEN_RUN
121 #endif
122  ;
123 
135 const char *sol_pwm_alignment_to_str(enum sol_pwm_alignment pwm_alignment)
136 #ifndef DOXYGEN_RUN
137  SOL_ATTR_WARN_UNUSED_RESULT
138 #endif
139  ;
140 
152 enum sol_pwm_polarity sol_pwm_polarity_from_str(const char *pwm_polarity)
153 #ifndef DOXYGEN_RUN
154  SOL_ATTR_WARN_UNUSED_RESULT
155 #endif
156  ;
157 
169 const char *sol_pwm_polarity_to_str(enum sol_pwm_polarity pwm_polarity)
170 #ifndef DOXYGEN_RUN
171  SOL_ATTR_WARN_UNUSED_RESULT
172 #endif
173  ;
174 
192 struct sol_pwm *sol_pwm_open_by_label(const char *label, const struct sol_pwm_config *config);
193 
212 struct sol_pwm *sol_pwm_open(int device, int channel, const struct sol_pwm_config *config);
213 
229 struct sol_pwm *sol_pwm_open_raw(int device, int channel, const struct sol_pwm_config *config);
230 
238 void sol_pwm_close(struct sol_pwm *pwm);
239 
249 int sol_pwm_set_enabled(struct sol_pwm *pwm, bool enable);
250 
258 bool sol_pwm_is_enabled(const struct sol_pwm *pwm);
259 
272 int sol_pwm_set_period(struct sol_pwm *pwm, uint32_t period_ns);
273 
283 int32_t sol_pwm_get_period(const struct sol_pwm *pwm);
284 
300 int sol_pwm_set_duty_cycle(struct sol_pwm *pwm, uint32_t duty_cycle_ns);
301 
311 int32_t sol_pwm_get_duty_cycle(const struct sol_pwm *pwm);
312 
317 #ifdef __cplusplus
318 }
319 #endif
struct sol_pwm * sol_pwm_open_by_label(const char *label, const struct sol_pwm_config *config)
Opens a given pin by its board label as pwm.
int32_t sol_pwm_get_duty_cycle(const struct sol_pwm *pwm)
Get PWM duty cycle in nanoseconds.
struct sol_pwm * sol_pwm_open_raw(int device, int channel, const struct sol_pwm_config *config)
Opens a given pin as pwm.
int sol_pwm_set_duty_cycle(struct sol_pwm *pwm, uint32_t duty_cycle_ns)
Set PWM duty cycle in nanoseconds.
int32_t duty_cycle_ns
The PWM duty cycle.
Definition: sol-pwm.h:101
void sol_pwm_close(struct sol_pwm *pwm)
Closes a given PWM pin.
int sol_pwm_set_enabled(struct sol_pwm *pwm, bool enable)
Enable or disable a given pwm pin.
struct sol_pwm * sol_pwm_open(int device, int channel, const struct sol_pwm_config *config)
Opens a given pin as pwm.
The pulse is aligned to the leading-edge (left) of the PWM period.
Definition: sol-pwm.h:69
sol_pwm_polarity
Polarity is whether the output is active-high or active-low.
Definition: sol-pwm.h:83
int sol_pwm_set_period(struct sol_pwm *pwm, uint32_t period_ns)
Set PWM period in nanoseconds.
These are common Soletta macros.
int32_t sol_pwm_get_period(const struct sol_pwm *pwm)
Get PWM period in nanoseconds.
const char * sol_pwm_polarity_to_str(enum sol_pwm_polarity pwm_polarity)
Converts sol_pwm_polarity to a string name.
enum sol_pwm_polarity polarity
The PWM polarity.
Definition: sol-pwm.h:103
#define SOL_ATTR_WARN_UNUSED_RESULT
Causes a warning to be emitted if a caller of the function with this attribute does not use its retur...
Definition: sol-macros.h:187
PWM configuration struct.
Definition: sol-pwm.h:95
const char * sol_pwm_alignment_to_str(enum sol_pwm_alignment pwm_alignment)
Converts sol_pwm_alignment to a string name.
Definition: sol-pwm.h:84
enum sol_pwm_polarity sol_pwm_polarity_from_str(const char *pwm_polarity)
Converts a string PWM polarity to sol_pwm_polarity.
enum sol_pwm_alignment alignment
The PWM alignment.
Definition: sol-pwm.h:102
sol_pwm_alignment
Alignment determines how the pulse is aligned within the PWM period.
Definition: sol-pwm.h:68
int32_t period_ns
The PWM period.
Definition: sol-pwm.h:100
uint16_t api_version
The API version.
Definition: sol-pwm.h:98
bool enabled
Set to true to for enabled false for disabled.
Definition: sol-pwm.h:104
struct sol_pwm_config sol_pwm_config
PWM configuration struct.
struct sol_pwm sol_pwm
A handle to a PWM.
Definition: sol-pwm.h:61
Definition: sol-pwm.h:85
The pulse is aligned to the trailing-edge (right) of the PWM period.
Definition: sol-pwm.h:70
bool sol_pwm_is_enabled(const struct sol_pwm *pwm)
Check wheter a pmw pin is enabled or disabled.
The pulse is aligned to the center of the PWM period.
Definition: sol-pwm.h:71
enum sol_pwm_alignment sol_pwm_alignment_from_str(const char *pwm_alignment)
Converts a string PWM alignment to sol_pwm_alignment.