libwebsockets
Lightweight C library for HTML5 websockets
lws-led.h
Go to the documentation of this file.
1 /*
2  * Generic LED 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  * This is like an abstract class for leds, a real implementation provides
25  * functions for the ops that use the underlying, eg, OS gpio arrangements.
26  */
27 
28 /* only b15 significant for GPIO */
31 
32 /* the normalized max intensity */
33 #define LWS_LED_MAX_INTENSITY (0xffff)
34 
35 /* the normalized 360 degree phase count for intensity functions */
36 #define LWS_LED_FUNC_PHASE 65536
37 /* used when the sequence doesn't stop by itself and goes around forever */
38 #define LWS_SEQ_LEDPHASE_TOTAL_ENDLESS (-1)
39 
40 #define LWS_LED_SEQUENCER_UPDATE_INTERVAL_MS 33
41 
42 struct lws_led_state; /* opaque */
43 struct lws_pwm_ops; /* forward ref */
44 
46 
47 typedef struct lws_led_sequence_def_t {
50  int ledphase_total; /* 65536= one cycle */
54 
55 enum {
59 };
60 
61 typedef struct lws_led_state_ch
62 {
63  const lws_led_sequence_def_t *seq; /* NULL = inactive */
72 
73 typedef struct lws_led_state_chs
74 {
77 
78 /* this should always be first in the subclassed implementation types */
79 
80 typedef struct lws_led_ops {
81  void (*intensity)(const struct lws_led_ops *lo, const char *name,
82  lws_led_intensity_t inten);
84  struct lws_led_state * (*create)(const struct lws_led_ops *led_ops);
85  void (*destroy)(struct lws_led_state *);
87 
88 typedef struct lws_led_gpio_map {
89  const char *name;
97  const struct lws_pwm_ops *pwm_ops;
102 
103 typedef struct lws_led_gpio_controller {
105 
110 
111 /* ops */
112 
113 LWS_VISIBLE LWS_EXTERN struct lws_led_state *
115 
117 lws_led_gpio_destroy(struct lws_led_state *lcs);
118 
131 lws_led_gpio_intensity(const struct lws_led_ops *lo, const char *name,
132  lws_led_intensity_t inten);
133 
135 lws_led_transition(struct lws_led_state *lcs, const char *name,
136  const lws_led_sequence_def_t *next,
137  const lws_led_sequence_def_t *trans);
138 
139 
140 #define lws_led_gpio_ops \
141  { \
142  .create = lws_led_gpio_create, \
143  .destroy = lws_led_gpio_destroy, \
144  .intensity = lws_led_gpio_intensity, \
145  }
146 
unsigned short uint16_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
int _lws_plat_gpio_t
Definition: lws-gpio.h:31
LWS_VISIBLE LWS_EXTERN struct lws_led_state * lws_led_gpio_create(const lws_led_ops_t *led_ops)
LWS_VISIBLE LWS_EXTERN void lws_led_gpio_destroy(struct lws_led_state *lcs)
const lws_led_ops_t led_ops
Definition: lws-led.h:104
lws_led_state_ch_t seqs[3]
Definition: lws-led.h:75
const lws_led_gpio_map_t * led_map
Definition: lws-led.h:107
uint8_t active_level
Definition: lws-led.h:100
const lws_led_sequence_def_t * seq
Definition: lws-led.h:63
lws_led_seq_phase_t step
Definition: lws-led.h:65
uint16_t lws_led_seq_phase_t
Definition: lws-led.h:30
const lws_gpio_ops_t * gpio_ops
Definition: lws-led.h:106
int phase_budget
Definition: lws-led.h:66
lws_led_lookup_t intensity_correction
Definition: lws-led.h:91
LWS_VISIBLE LWS_EXTERN void lws_led_gpio_intensity(const struct lws_led_ops *lo, const char *name, lws_led_intensity_t inten)
uint16_t lws_led_intensity_t
Definition: lws-led.h:29
struct lws_led_ops lws_led_ops_t
struct lws_led_gpio_map lws_led_gpio_map_t
struct lws_led_gpio_controller lws_led_gpio_controller_t
lws_led_seq_phase_t ledphase_offset
Definition: lws-led.h:49
lws_led_seq_phase_t ph
Definition: lws-led.h:64
struct lws_led_sequence_def_t lws_led_sequence_def_t
struct lws_led_state_ch lws_led_state_ch_t
lws_led_lookup_t func
Definition: lws-led.h:48
const char * name
Definition: lws-led.h:89
@ LLSI_CURR
Definition: lws-led.h:56
@ LLSI_NEXT
Definition: lws-led.h:57
@ LLSI_TRANS
Definition: lws-led.h:58
_lws_plat_gpio_t gpio
Definition: lws-led.h:90
lws_led_intensity_t last
Definition: lws-led.h:67
LWS_VISIBLE LWS_EXTERN int lws_led_transition(struct lws_led_state *lcs, const char *name, const lws_led_sequence_def_t *next, const lws_led_sequence_def_t *trans)
const struct lws_pwm_ops * pwm_ops
Definition: lws-led.h:97
struct lws_led_state_chs lws_led_state_chs_t
lws_led_intensity_t(* lws_led_lookup_t)(lws_led_seq_phase_t ph)
Definition: lws-led.h:45
void(* destroy)(struct lws_led_state *)
Definition: lws-led.h:85
void(* intensity)(const struct lws_led_ops *lo, const char *name, lws_led_intensity_t inten)
Definition: lws-led.h:81