Skip to content

Commit 92bbc87

Browse files
committed
lab-data: sysdev: add lab-data for imx93-frdm
Signed-off-by: Antoine Picard <antoine.picard@bootlin.com>
1 parent 548c32c commit 92bbc87

36 files changed

+3347
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/* nunchuk-mpd-client
2+
(c) 2022 Bootlin <michael.opdenacker@bootlin.com>
3+
4+
License: Public Domain
5+
*/
6+
7+
#include <dirent.h>
8+
#include <mpd/client.h>
9+
#include <assert.h>
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <linux/input.h>
13+
#include <unistd.h>
14+
#include <fcntl.h>
15+
#include <string.h>
16+
17+
static int handle_error(struct mpd_connection *c)
18+
{
19+
fprintf(stderr, "%s\n", mpd_connection_get_error_message(c));
20+
mpd_connection_free(c);
21+
return EXIT_FAILURE;
22+
}
23+
24+
static void change_volume(struct mpd_connection *c, int delta)
25+
{
26+
int volume;
27+
if (!mpd_run_change_volume(c, delta))
28+
exit(handle_error(c));
29+
30+
volume = mpd_run_get_volume(c);
31+
32+
if (volume == -1)
33+
exit(handle_error(c));
34+
35+
printf("%d\n", volume);
36+
}
37+
38+
static void print_current_song(struct mpd_connection *c)
39+
{
40+
struct mpd_song *song;
41+
song = mpd_run_current_song(c);
42+
43+
if (song) {
44+
printf("%s (%u s)\n", mpd_song_get_uri(song), mpd_song_get_duration(song));
45+
mpd_song_free(song);
46+
}
47+
}
48+
49+
static int is_event_device(const struct dirent *dir) {
50+
return (strncmp("event", dir->d_name, 5) == 0);
51+
}
52+
53+
int main(int argc, char ** argv)
54+
{
55+
struct mpd_connection *conn;
56+
int i, ndev, ret, fd, quit = 0, num_events = 0;
57+
struct input_event event;
58+
struct dirent **namelist;
59+
60+
/* Find Nunchuk input device */
61+
62+
ndev = scandir("/dev/input", &namelist, is_event_device, alphasort);
63+
64+
if (ndev <= 0) {
65+
fprintf(stderr, "ERROR: no input event device found\n");
66+
exit(EXIT_FAILURE);
67+
}
68+
69+
for (i = 0; i < ndev; i++)
70+
{
71+
char fname[256];
72+
char name[256];
73+
74+
snprintf(fname, sizeof(fname), "/dev/%s", namelist[i]->d_name);
75+
free(namelist[i]);
76+
77+
fd = open(fname, O_RDONLY);
78+
79+
if (fd < 0)
80+
continue;
81+
82+
ioctl(fd, EVIOCGNAME(sizeof(name)), name);
83+
84+
if (strcmp("Wii Nunchuck", name) == 0)
85+
break;
86+
else
87+
close(fd);
88+
89+
}
90+
91+
if (i == ndev) {
92+
fprintf(stderr, "ERROR: didn't manage to find the Nunchuk device in /dev/input. Is the Nunchuk driver loaded?\n");
93+
exit(EXIT_FAILURE);
94+
}
95+
96+
/* Connection to MPD on localhost, default port */
97+
98+
conn = mpd_connection_new(0, 0, 30000);
99+
100+
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
101+
return handle_error(conn);
102+
103+
printf("Connection successful\n");
104+
105+
/* Main loop */
106+
107+
while (!quit) {
108+
ret = read(fd, &event, sizeof(struct input_event));
109+
num_events++;
110+
111+
switch (event.type) {
112+
case EV_KEY:
113+
switch (event.code) {
114+
case BTN_Z:
115+
if (event.value == 1) {
116+
printf("Play/Pause\n");
117+
if (!mpd_run_toggle_pause(conn))
118+
return handle_error(conn);
119+
}
120+
break;
121+
case BTN_C:
122+
if (event.value == 1) {
123+
printf("Quit\n");
124+
quit = 1;
125+
free(conn);
126+
}
127+
break;
128+
}
129+
break;
130+
case EV_ABS:
131+
switch (event.code) {
132+
case ABS_Y:
133+
if (event.value > 250) {
134+
printf("Volume up: ");
135+
change_volume(conn, 5);
136+
} else if (event.value < 5) {
137+
printf("Volume down: ");
138+
change_volume(conn, -5);
139+
}
140+
break;
141+
case ABS_X:
142+
if (event.value > 250) {
143+
if (!mpd_run_next(conn)) {
144+
printf("No next song. Aborting\n");
145+
exit(handle_error(conn));
146+
} else {
147+
printf("Next song: ");
148+
print_current_song(conn);
149+
}
150+
}
151+
else if (event.value < 5) {
152+
if (!mpd_run_previous(conn)) {
153+
printf("No previous song. Aborting\n");
154+
exit(handle_error(conn));
155+
} else {
156+
printf("Previous song: ");
157+
print_current_song(conn);
158+
}
159+
}
160+
break;
161+
}
162+
break;
163+
}
164+
}
165+
166+
/* Close connection */
167+
mpd_connection_free(conn);
168+
printf("Connection terminated\n");
169+
return 0;
170+
}
1.12 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
here we must add patch for imx93-frdm for u-boot
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# MPD configuration
2+
3+
# For ALSA output:
4+
audio_output {
5+
type "alsa"
6+
name "My ALSA Device"
7+
mixer_type "software"
8+
}
9+
10+
# Directory where the music is stored
11+
music_directory "/var/lib/mpd/music"
12+
13+
# Directory where user-made playlists are stored (RW)
14+
playlist_directory "/var/lib/mpd/playlists"
15+
16+
# Database file (RW)
17+
db_file "/var/lib/mpd/database"
18+
19+
# Log file (RW)
20+
log_file "/var/log/mpd.log"
21+
22+
# Process ID file (RW)
23+
pid_file "/var/run/mpd.pid"
24+
25+
# State file (RW)
26+
state_file "/var/lib/mpd/state"
27+
28+
# User id to run the daemon as
29+
#user "nobody"
30+
31+
# TCP socket binding
32+
#bind_to_address "any"
33+
bind_to_address "localhost"
34+
35+
# Unix socket to listen on
36+
bind_to_address "/var/lib/mpd/socket"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)