libwebsockets
Lightweight C library for HTML5 websockets
lws-display.h
Go to the documentation of this file.
1 /*
2  * lws abstract display
3  *
4  * Copyright (C) 2019 - 2022 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 typedef int16_t lws_display_list_coord_t;
33 
34 typedef struct lws_box {
40 
41 struct lws_display_state;
42 struct lws_display;
43 
44 typedef enum {
50 
51 typedef struct lws_surface_info {
55  size_t palette_depth;
57  uint8_t greyscale:1; /* line: 0 = RGBA, 1 = YA */
58  uint8_t partial:1; /* can handle partial */
59  uint8_t render_to_rgba:1; /* render to 32-bit RGBA, not 24-bit RGB */
61 
62 typedef struct lws_greyscale_error {
63  int16_t rgb[1];
65 
66 typedef struct lws_colour_error {
67  int16_t rgb[3];
69 
70 typedef union {
71  lws_greyscale_error_t grey; /* when ic->greyscale set */
72  lws_colour_error_t colour; /* when ic->greyscale == 0 */
74 
77  const lws_display_colour_t *c);
78 
81  const lws_display_colour_t *palette, size_t pdepth,
83 
86  const lws_display_colour_t *palette, size_t pdepth,
88 
89 /*
90  * This is embedded in the actual display implementation object at the top,
91  * so a pointer to this can be cast to a pointer to the implementation object
92  * by any code that is specific to how it was implemented.
93  *
94  * Notice for the backlight / display intensity we contain pwm_ops... these can
95  * be some other pwm_ops like existing gpio pwm ops, or handled in a customized
96  * way like set oled contrast. Either way, the pwm level is arrived at via a
97  * full set of lws_led_sequences capable of generic lws transitions
98  */
99 
100 typedef struct lws_display {
101  int (*init)(struct lws_display_state *lds);
104  int (*blit)(struct lws_display_state *lds, const uint8_t *src,
105  lws_box_t *box, lws_dll2_owner_t *ids);
106  int (*power)(struct lws_display_state *lds, int state);
107 
111 
112  const char *name;
113  void *variant;
114 
115  int bl_index;
116 
118 
126 
127 /*
128  * This contains dynamic data related to display state
129  */
130 
133  LWSDISPS_AUTODIMMED, /* is in pre- blanking static dim mode */
134  LWSDISPS_BECOMING_ACTIVE, /* waiting for wake latency before active */
135  LWSDISPS_ACTIVE, /* is active */
136  LWSDISPS_GOING_OFF /* dimming then off */
137 };
138 
139 typedef struct lws_display_state {
140 
142 
143  char current_url[96];
144 
146  struct lws_context *ctx;
147 
148  void *priv; /* subclass driver alloc'd priv */
149 
151  int off_ms;
152 
153  struct lws_led_state *bl_lcs;
154 
156  /* set of sequencer transition channels */
157 
159 
161 
163 
164 /* Used for async display driver events, eg, EPD refresh completion */
165 typedef int (*lws_display_completion_t)(lws_display_state_t *lds, int a);
166 
186 lws_display_state_init(lws_display_state_t *lds, struct lws_context *ctx,
187  int autodim_ms, int off_ms, struct lws_led_state *bl_lcs,
188  const lws_display_t *disp);
189 
200  const lws_led_sequence_def_t *pwmseq);
201 
202 /*
203  * lws_display_state_active() - inform the system the display is active
204  *
205  * \param lds: the display state we are marking as active
206  *
207  * Resets the auto-dim and auto-off timers and makes sure the display is on and
208  * at the active brightness level
209  */
212 
213 /*
214  * lws_display_state_off() - turns off the related display
215  *
216  * \param lds: the display state we are turning off
217  *
218  * Turns the display to least power mode or completely off if possible.
219  * Disables the timers related to dimming and blanking.
220  */
223 
224 #endif
unsigned short uint16_t
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
lws_fx_t w
Definition: lws-display.h:37
LWS_VISIBLE LWS_EXTERN lws_display_palette_idx_t lws_display_palettize_col(const lws_surface_info_t *ic, const lws_display_colour_t *palette, size_t pdepth, lws_display_colour_t c, lws_colour_error_t *ectx)
struct lws_colour_error lws_colour_error_t
LWS_VISIBLE LWS_EXTERN void lws_surface_set_px(const lws_surface_info_t *ic, uint8_t *line, int x, const lws_display_colour_t *c)
const lws_display_colour_t * palette
Definition: lws-display.h:54
enum lws_display_controller_state state
Definition: lws-display.h:158
LWS_VISIBLE LWS_EXTERN void lws_display_state_off(lws_display_state_t *lds)
int(* lws_display_completion_t)(lws_display_state_t *lds, int a)
Definition: lws-display.h:165
const lws_display_t * disp
Definition: lws-display.h:145
lws_led_state_chs_t chs
Definition: lws-display.h:155
lws_fx_t h
Definition: lws-display.h:38
LWS_VISIBLE LWS_EXTERN void lws_display_state_active(lws_display_state_t *lds)
lws_surface_type_t type
Definition: lws-display.h:56
LWS_VISIBLE LWS_EXTERN lws_display_palette_idx_t lws_display_palettize_grey(const lws_surface_info_t *ic, const lws_display_colour_t *palette, size_t pdepth, lws_display_colour_t c, lws_greyscale_error_t *ectx)
uint16_t lws_display_palette_idx_t
Definition: lws-display.h:32
struct lws_display_state lws_display_state_t
struct lws_context * ctx
Definition: lws-display.h:146
uint16_t lws_display_rotation_t
Definition: lws-display.h:30
lws_colour_error_t colour
Definition: lws-display.h:72
uint32_t lws_display_colour_t
Definition: lws-display.h:31
struct lws_surface_info lws_surface_info_t
lws_fx_t x
Definition: lws-display.h:35
int16_t lws_display_list_coord_t
Definition: lws-display.h:28
struct lws_greyscale_error lws_greyscale_error_t
lws_fx_t wh_mm[2]
Definition: lws-display.h:53
uint8_t render_to_rgba
Definition: lws-display.h:59
lws_display_controller_state
Definition: lws-display.h:131
@ LWSDISPS_AUTODIMMED
Definition: lws-display.h:133
@ LWSDISPS_ACTIVE
Definition: lws-display.h:135
@ LWSDISPS_OFF
Definition: lws-display.h:132
@ LWSDISPS_BECOMING_ACTIVE
Definition: lws-display.h:134
@ LWSDISPS_GOING_OFF
Definition: lws-display.h:136
LWS_VISIBLE LWS_EXTERN void lws_display_state_set_brightness(lws_display_state_t *lds, const lws_led_sequence_def_t *pwmseq)
lws_sorted_usec_list_t sul_autodim
Definition: lws-display.h:141
struct lws_display lws_display_t
lws_fx_t y
Definition: lws-display.h:36
uint16_t lws_display_scalar
Definition: lws-display.h:29
lws_greyscale_error_t grey
Definition: lws-display.h:71
char current_url[96]
Definition: lws-display.h:143
int16_t rgb[3]
Definition: lws-display.h:67
struct lws_box lws_box_t
lws_fx_t wh_px[2]
Definition: lws-display.h:52
size_t palette_depth
Definition: lws-display.h:55
LWS_VISIBLE LWS_EXTERN void lws_display_state_init(lws_display_state_t *lds, struct lws_context *ctx, int autodim_ms, int off_ms, struct lws_led_state *bl_lcs, const lws_display_t *disp)
uint8_t greyscale
Definition: lws-display.h:57
struct lws_led_state * bl_lcs
Definition: lws-display.h:153
lws_surface_type_t
Definition: lws-display.h:44
@ LWSSURF_QUANTIZED_4BPP
Definition: lws-display.h:48
@ LWSSURF_565
Definition: lws-display.h:46
@ LWSSURF_TRUECOLOR32
Definition: lws-display.h:45
@ LWSSURF_PALETTE
Definition: lws-display.h:47
int(* contrast)(struct lws_display_state *lds, uint8_t contrast)
Definition: lws-display.h:103
uint16_t latency_wake_ms
Definition: lws-display.h:119
const lws_led_sequence_def_t * bl_active
Definition: lws-display.h:108
lws_surface_info_t ic
Definition: lws-display.h:117
const char * name
Definition: lws-display.h:112
int(* blit)(struct lws_display_state *lds, const uint8_t *src, lws_box_t *box, lws_dll2_owner_t *ids)
Definition: lws-display.h:104
const lws_pwm_ops_t * bl_pwm_ops
Definition: lws-display.h:102
void * variant
Definition: lws-display.h:113
const lws_led_sequence_def_t * bl_dim
Definition: lws-display.h:109
const lws_led_sequence_def_t * bl_transition
Definition: lws-display.h:110
uint16_t latency_update_ms
Definition: lws-display.h:123
int(* init)(struct lws_display_state *lds)
Definition: lws-display.h:101
int(* power)(struct lws_display_state *lds, int state)
Definition: lws-display.h:106