1 // SPDX-License-Identifier: GPL-2.0+
3 * Implementation of a expo, a collection of scenes providing menu options
5 * Copyright 2022 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
14 #include "scene_internal.h"
16 int expo_new(const char *name, void *priv, struct expo **expp)
20 exp = calloc(1, sizeof(struct expo));
22 return log_msg_ret("expo", -ENOMEM);
23 exp->name = strdup(name);
26 return log_msg_ret("name", -ENOMEM);
29 INIT_LIST_HEAD(&exp->scene_head);
30 INIT_LIST_HEAD(&exp->str_head);
37 static void estr_destroy(struct expo_string *estr)
42 void expo_destroy(struct expo *exp)
44 struct scene *scn, *next;
45 struct expo_string *estr, *enext;
47 list_for_each_entry_safe(scn, next, &exp->scene_head, sibling)
50 list_for_each_entry_safe(estr, enext, &exp->str_head, sibling)
57 int expo_str(struct expo *exp, const char *name, uint id, const char *str)
59 struct expo_string *estr;
61 estr = calloc(1, sizeof(struct expo_string));
63 return log_msg_ret("obj", -ENOMEM);
65 estr->id = resolve_id(exp, id);
67 list_add_tail(&estr->sibling, &exp->str_head);
72 const char *expo_get_str(struct expo *exp, uint id)
74 struct expo_string *estr;
76 list_for_each_entry(estr, &exp->str_head, sibling) {
84 int expo_set_display(struct expo *exp, struct udevice *dev)
91 void exp_set_text_mode(struct expo *exp, bool text_mode)
93 exp->text_mode = text_mode;
96 struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id)
100 list_for_each_entry(scn, &exp->scene_head, sibling) {
101 if (scn->id == scene_id)
108 int expo_set_scene_id(struct expo *exp, uint scene_id)
110 if (!expo_lookup_scene_id(exp, scene_id))
111 return log_msg_ret("id", -ENOENT);
112 exp->scene_id = scene_id;
117 int expo_render(struct expo *exp)
119 struct udevice *dev = exp->display;
120 struct video_priv *vid_priv = dev_get_uclass_priv(dev);
121 struct scene *scn = NULL;
125 colour = video_index_to_colour(vid_priv, VID_WHITE);
126 ret = video_fill(dev, colour);
128 return log_msg_ret("fill", ret);
131 scn = expo_lookup_scene_id(exp, exp->scene_id);
133 return log_msg_ret("scn", -ENOENT);
135 ret = scene_render(scn);
137 return log_msg_ret("ren", ret);
140 video_sync(dev, true);
142 return scn ? 0 : -ECHILD;
145 int expo_send_key(struct expo *exp, int key)
147 struct scene *scn = NULL;
152 scn = expo_lookup_scene_id(exp, exp->scene_id);
154 return log_msg_ret("scn", -ENOENT);
156 ret = scene_send_key(scn, key, &exp->action);
158 return log_msg_ret("key", ret);
161 return scn ? 0 : -ECHILD;
164 int expo_action_get(struct expo *exp, struct expo_action *act)
167 exp->action.type = EXPOACT_NONE;
169 return act->type == EXPOACT_NONE ? -EAGAIN : 0;