diff options
Diffstat (limited to 'rbutil/jztool/src/device_info.c')
-rw-r--r-- | rbutil/jztool/src/device_info.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/rbutil/jztool/src/device_info.c b/rbutil/jztool/src/device_info.c new file mode 100644 index 0000000000..bc1477be32 --- /dev/null +++ b/rbutil/jztool/src/device_info.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "jztool.h" | ||
23 | #include <string.h> | ||
24 | |||
25 | static const char* const fiiom3k_action_names[] = { | ||
26 | "install", | ||
27 | "backup", | ||
28 | "restore", | ||
29 | }; | ||
30 | |||
31 | static const char* const fiiom3k_install_action_params[] = | ||
32 | {"spl", "bootloader", "backup", "without-backup", NULL}; | ||
33 | |||
34 | static const char* const fiiom3k_backuprestore_action_params[] = | ||
35 | {"spl", "image", NULL}; | ||
36 | |||
37 | static const char* const* fiiom3k_action_params[] = { | ||
38 | fiiom3k_install_action_params, | ||
39 | fiiom3k_backuprestore_action_params, | ||
40 | fiiom3k_backuprestore_action_params, | ||
41 | }; | ||
42 | |||
43 | static const jz_device_action_fn fiiom3k_action_funcs[] = { | ||
44 | jz_fiiom3k_install, | ||
45 | jz_fiiom3k_backup, | ||
46 | jz_fiiom3k_restore, | ||
47 | }; | ||
48 | |||
49 | static const jz_device_info infotable[] = { | ||
50 | { | ||
51 | .name = "fiiom3k", | ||
52 | .description = "FiiO M3K", | ||
53 | .device_type = JZ_DEVICE_FIIOM3K, | ||
54 | .cpu_type = JZ_CPU_X1000, | ||
55 | .vendor_id = 0xa108, | ||
56 | .product_id = 0x1000, | ||
57 | .num_actions = sizeof(fiiom3k_action_names)/sizeof(void*), | ||
58 | .action_names = fiiom3k_action_names, | ||
59 | .action_funcs = fiiom3k_action_funcs, | ||
60 | .action_params = fiiom3k_action_params, | ||
61 | }, | ||
62 | }; | ||
63 | |||
64 | static const int infotable_size = sizeof(infotable)/sizeof(struct jz_device_info); | ||
65 | |||
66 | /** \brief Get the number of entries in the device info list */ | ||
67 | int jz_get_num_device_info(void) | ||
68 | { | ||
69 | return infotable_size; | ||
70 | } | ||
71 | |||
72 | const jz_device_info* jz_get_device_info(jz_device_type type) | ||
73 | { | ||
74 | for(int i = 0; i < infotable_size; ++i) | ||
75 | if(infotable[i].device_type == type) | ||
76 | return &infotable[i]; | ||
77 | |||
78 | return NULL; | ||
79 | } | ||
80 | |||
81 | /** \brief Lookup info for a device by name, returns NULL if not found. */ | ||
82 | const jz_device_info* jz_get_device_info_named(const char* name) | ||
83 | { | ||
84 | for(int i = 0; i < infotable_size; ++i) | ||
85 | if(!strcmp(infotable[i].name, name)) | ||
86 | return &infotable[i]; | ||
87 | |||
88 | return NULL; | ||
89 | } | ||
90 | |||
91 | /** \brief Get a device info entry by index, returns NULL if out of range. */ | ||
92 | const jz_device_info* jz_get_device_info_indexed(int index) | ||
93 | { | ||
94 | if(index < infotable_size) | ||
95 | return &infotable[index]; | ||
96 | else | ||
97 | return NULL; | ||
98 | } | ||