pwm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 Freie Universität Berlin
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 
61 #ifndef PERIPH_PWM_H
62 #define PERIPH_PWM_H
63 
64 #include <stdint.h>
65 #include <limits.h>
66 
67 #include "periph_cpu.h"
68 #include "periph_conf.h"
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
77 #ifndef PWM_DEV
78 #define PWM_DEV(x) (x)
79 #endif
80 
84 #ifndef PWM_UNDEF
85 #define PWM_UNDEF (UINT_FAST8_MAX)
86 #endif
87 
91 #ifndef HAVE_PWM_T
92 typedef uint_fast8_t pwm_t;
93 #endif
94 
98 #ifndef HAVE_PWM_MODE_T
99 typedef enum {
100  PWM_LEFT, /*< use left aligned PWM */
101  PWM_RIGHT, /*< use right aligned PWM */
102  PWM_CENTER /*< use center aligned PWM */
103 } pwm_mode_t;
104 #endif
105 
106 #ifdef MODULE_ARDUINO
111 typedef struct {
112  pwm_t dev;
113  uint8_t chan;
114  uint8_t pin;
115 } arduino_pwm_t;
116 #endif
117 
139 uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res);
140 
148 uint8_t pwm_channels(pwm_t dev);
149 
160 void pwm_set(pwm_t dev, uint8_t channel, uint16_t value);
161 
173 void pwm_poweron(pwm_t dev);
174 
183 void pwm_poweroff(pwm_t dev);
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* PERIPH_PWM_H */
pwm_mode_t
Definition: periph_conf.h:220
void pwm_poweron(pwm_t dev)
Resume PWM generation on the given device.
uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res)
Initialize a PWM device.
uint8_t pwm_channels(pwm_t dev)
Get the number of available channels.
pwm_mode_t
Default PWM mode definition.
Definition: pwm.h:99
void pwm_set(pwm_t dev, uint8_t channel, uint16_t value)
Set the duty-cycle for a given channel of the given PWM device.
void pwm_poweroff(pwm_t dev)
Stop PWM generation on the given device.
uint_fast8_t pwm_t
Default PWM type definition.
Definition: pwm.h:92
@ PWM_CENTER
center aligned
Definition: periph_conf.h:223
@ PWM_LEFT
left aligned
Definition: periph_conf.h:221
@ PWM_RIGHT
right aligned
Definition: periph_conf.h:222