1/*
2 * Generic PWM controller ops
3 *
4 * Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25typedef struct lws_pwm_map {
26 _lws_plat_gpio_t gpio;
27 uint8_t index;
28 uint8_t active_level;
29} lws_pwm_map_t;
30
31typedef struct lws_pwm_ops {
32 int (*init)(const struct lws_pwm_ops *lo);
33 void (*intensity)(const struct lws_pwm_ops *lo, _lws_plat_gpio_t gpio,
34 lws_led_intensity_t inten);
35 const lws_pwm_map_t *pwm_map;
36 uint8_t count_pwm_map;
37} lws_pwm_ops_t;
38
39LWS_VISIBLE LWS_EXTERN int
40lws_pwm_plat_init(const struct lws_pwm_ops *lo);
41
42LWS_VISIBLE LWS_EXTERN void
43lws_pwm_plat_intensity(const struct lws_pwm_ops *lo, _lws_plat_gpio_t gpio,
44 lws_led_intensity_t inten);
45
46#define lws_pwm_plat_ops \
47 .init = lws_pwm_plat_init, \
48 .intensity = lws_pwm_plat_intensity
49
50/*
51 * May be useful for making your own transitions or sequences
52 */
53
54LWS_VISIBLE LWS_EXTERN lws_led_intensity_t
55lws_led_func_linear(lws_led_seq_phase_t n);
56LWS_VISIBLE LWS_EXTERN lws_led_intensity_t
57lws_led_func_sine(lws_led_seq_phase_t n);
58
59/* canned sequences that can work out of the box */
60
61extern const lws_led_sequence_def_t lws_pwmseq_sine_endless_slow,
62 lws_pwmseq_sine_endless_fast,
63 lws_pwmseq_linear_wipe,
64 lws_pwmseq_sine_up, lws_pwmseq_sine_down,
65 lws_pwmseq_static_on,
66 lws_pwmseq_static_half,
67 lws_pwmseq_static_off;
68