libwebsockets
Lightweight C library for HTML5 websockets
lws-display.h
1 /*
2  * lws abstract display
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 
25 #if !defined(__LWS_DISPLAY_H__)
26 #define __LWS_DISPLAY_H__
27 
28 #include <stdint.h>
29 
30 typedef uint16_t lws_display_scalar;
31 
32 /*
33  * This is embedded in the actual display implementation object at the top,
34  * so a pointer to this can be cast to a pointer to the implementation object
35  * by any code that is specific to how it was implemented.
36  *
37  * Notice for the backlight / display intensity we contain pwm_ops... these can
38  * be some other pwm_ops like existing gpio pwm ops, or handled in a customized
39  * way like set oled contrast. Either way, the pwm level is arrived at via a
40  * full set of lws_led_sequences capable of generic lws transitions
41  */
42 
43 typedef struct lws_display {
44  int (*init)(const struct lws_display *disp);
45  const lws_pwm_ops_t *bl_pwm_ops;
46  int (*contrast)(const struct lws_display *disp, uint8_t contrast);
47  int (*blit)(const struct lws_display *disp, const uint8_t *src,
48  lws_display_scalar x, lws_display_scalar y,
49  lws_display_scalar w, lws_display_scalar h);
50  int (*power)(const struct lws_display *disp, int state);
51 
52  const lws_led_sequence_def_t *bl_active;
53  const lws_led_sequence_def_t *bl_dim;
54  const lws_led_sequence_def_t *bl_transition;
55 
56  void *variant;
57 
58  int bl_index;
59 
60  lws_display_scalar w;
62  lws_display_scalar h;
65  uint8_t latency_wake_ms;
70 
71 /*
72  * This contains dynamic data related to display state
73  */
74 
75 enum lws_display_controller_state {
76  LWSDISPS_OFF,
77  LWSDISPS_AUTODIMMED, /* is in pre- blanking static dim mode */
78  LWSDISPS_BECOMING_ACTIVE, /* waiting for wake latency before active */
79  LWSDISPS_ACTIVE, /* is active */
80  LWSDISPS_GOING_OFF /* dimming then off */
81 };
82 
83 typedef struct lws_display_state {
84 
85  lws_sorted_usec_list_t sul_autodim;
86  const lws_display_t *disp;
87  struct lws_context *ctx;
88 
89  int autodim_ms;
90  int off_ms;
91 
92  struct lws_led_state *bl_lcs;
93 
95  /* set of sequencer transition channels */
96 
97  enum lws_display_controller_state state;
98 
100 
119 LWS_VISIBLE LWS_EXTERN void
120 lws_display_state_init(lws_display_state_t *lds, struct lws_context *ctx,
121  int autodim_ms, int off_ms, struct lws_led_state *bl_lcs,
122  const lws_display_t *disp);
123 
132 LWS_VISIBLE LWS_EXTERN void
133 lws_display_state_set_brightness(lws_display_state_t *lds,
134  const lws_led_sequence_def_t *pwmseq);
135 
136 /*
137  * lws_display_state_active() - inform the system the display is active
138  *
139  * \param lds: the display state we are marking as active
140  *
141  * Resets the auto-dim and auto-off timers and makes sure the display is on and
142  * at the active brightness level
143  */
144 LWS_VISIBLE LWS_EXTERN void
145 lws_display_state_active(lws_display_state_t *lds);
146 
147 /*
148  * lws_display_state_off() - turns off the related display
149  *
150  * \param lds: the display state we are turning off
151  *
152  * Turns the display to least power mode or completely off if possible.
153  * Disables the timers related to dimming and blanking.
154  */
155 LWS_VISIBLE LWS_EXTERN void
156 lws_display_state_off(lws_display_state_t *lds);
157 
158 #endif
Definition: lws-display.h:83
Definition: lws-display.h:43
lws_display_scalar h
Definition: lws-display.h:62
uint8_t latency_wake_ms
Definition: lws-display.h:65
lws_display_scalar w
Definition: lws-display.h:60
Definition: lws-led.h:47
Definition: lws-led.h:74
Definition: lws-pwm.h:31
Definition: lws-timeout-timer.h:162