1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Implementation of a expo, a collection of scenes providing menu options
*
* Copyright 2022 Google LLC
* Written by Simon Glass <sjg@chromium.org>
*/
#include <common.h>
#include <dm.h>
#include <expo.h>
#include <malloc.h>
#include <video.h>
#include "scene_internal.h"
int expo_new(const char *name, void *priv, struct expo **expp)
{
struct expo *exp;
exp = calloc(1, sizeof(struct expo));
if (!exp)
return log_msg_ret("expo", -ENOMEM);
exp->name = strdup(name);
if (!exp->name) {
free(exp);
return log_msg_ret("name", -ENOMEM);
}
exp->priv = priv;
INIT_LIST_HEAD(&exp->scene_head);
INIT_LIST_HEAD(&exp->str_head);
*expp = exp;
return 0;
}
static void estr_destroy(struct expo_string *estr)
{
free(estr);
}
void expo_destroy(struct expo *exp)
{
struct scene *scn, *next;
struct expo_string *estr, *enext;
list_for_each_entry_safe(scn, next, &exp->scene_head, sibling)
scene_destroy(scn);
list_for_each_entry_safe(estr, enext, &exp->str_head, sibling)
estr_destroy(estr);
free(exp->name);
free(exp);
}
int expo_str(struct expo *exp, const char *name, uint id, const char *str)
{
struct expo_string *estr;
estr = calloc(1, sizeof(struct expo_string));
if (!estr)
return log_msg_ret("obj", -ENOMEM);
estr->id = resolve_id(exp, id);
estr->str = str;
list_add_tail(&estr->sibling, &exp->str_head);
return estr->id;
}
const char *expo_get_str(struct expo *exp, uint id)
{
struct expo_string *estr;
list_for_each_entry(estr, &exp->str_head, sibling) {
if (estr->id == id)
return estr->str;
}
return NULL;
}
int expo_set_display(struct expo *exp, struct udevice *dev)
{
exp->display = dev;
return 0;
}
void exp_set_text_mode(struct expo *exp, bool text_mode)
{
exp->text_mode = text_mode;
}
struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id)
{
struct scene *scn;
list_for_each_entry(scn, &exp->scene_head, sibling) {
if (scn->id == scene_id)
return scn;
}
return NULL;
}
int expo_set_scene_id(struct expo *exp, uint scene_id)
{
if (!expo_lookup_scene_id(exp, scene_id))
return log_msg_ret("id", -ENOENT);
exp->scene_id = scene_id;
return 0;
}
int expo_render(struct expo *exp)
{
struct udevice *dev = exp->display;
struct video_priv *vid_priv = dev_get_uclass_priv(dev);
struct scene *scn = NULL;
u32 colour;
int ret;
colour = video_index_to_colour(vid_priv, VID_WHITE);
ret = video_fill(dev, colour);
if (ret)
return log_msg_ret("fill", ret);
if (exp->scene_id) {
scn = expo_lookup_scene_id(exp, exp->scene_id);
if (!scn)
return log_msg_ret("scn", -ENOENT);
ret = scene_render(scn);
if (ret)
return log_msg_ret("ren", ret);
}
video_sync(dev, true);
return scn ? 0 : -ECHILD;
}
int expo_send_key(struct expo *exp, int key)
{
struct scene *scn = NULL;
if (exp->scene_id) {
int ret;
scn = expo_lookup_scene_id(exp, exp->scene_id);
if (!scn)
return log_msg_ret("scn", -ENOENT);
ret = scene_send_key(scn, key, &exp->action);
if (ret)
return log_msg_ret("key", ret);
}
return scn ? 0 : -ECHILD;
}
int expo_action_get(struct expo *exp, struct expo_action *act)
{
*act = exp->action;
exp->action.type = EXPOACT_NONE;
return act->type == EXPOACT_NONE ? -EAGAIN : 0;
}
|