summaryrefslogtreecommitdiff
path: root/utils/nwztools/plattools/nwz_lib.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-11-11 16:01:14 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2016-11-11 16:07:14 +0100
commitc95e30b75d75b674f0d645b7c41377bbd0511213 (patch)
tree3a0d6253a0a5cab8cbc14b1258f0b2d7b4f74e0d /utils/nwztools/plattools/nwz_lib.c
parent44bb2856a59be53ef5ede154a39c54a59b1cc6d0 (diff)
downloadrockbox-c95e30b75d75b674f0d645b7c41377bbd0511213.tar.gz
rockbox-c95e30b75d75b674f0d645b7c41377bbd0511213.zip
nwztools/plattools: use player database and rework stuff
Using the database, we can now safely read/write the NVP. I also add more support for Sony's "display" tool. Change-Id: I8439fe9bad391c7f29859d99f236781be7983625
Diffstat (limited to 'utils/nwztools/plattools/nwz_lib.c')
-rw-r--r--utils/nwztools/plattools/nwz_lib.c209
1 files changed, 198 insertions, 11 deletions
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c
index 43dc977d42..70dc070fc9 100644
--- a/utils/nwztools/plattools/nwz_lib.c
+++ b/utils/nwztools/plattools/nwz_lib.c
@@ -19,16 +19,7 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22 22#include "nwz_db.h"
23extern struct nwz_dev_info_t g_nwz_dev_list[];
24
25const char *nwz_get_model_name(unsigned long model_id)
26{
27 for(int i = 0; g_nwz_dev_list[i].name; i++)
28 if(g_nwz_dev_list[i].model_id == model_id)
29 return g_nwz_dev_list[i].name;
30 return NULL;
31}
32 23
33int nwz_run(const char *file, const char *args[], bool wait) 24int nwz_run(const char *file, const char *args[], bool wait)
34{ 25{
@@ -91,7 +82,7 @@ void nwz_lcdmsg(bool clear, int x, int y, const char *msg)
91 const char *args[16]; 82 const char *args[16];
92 int index = 0; 83 int index = 0;
93 char locate[32]; 84 char locate[32];
94 args[index++] = path_lcdmsg; 85 args[index++] = "lcdmsg";
95 if(clear) 86 if(clear)
96 args[index++] = "-c"; 87 args[index++] = "-c";
97 args[index++] = "-f"; 88 args[index++] = "-f";
@@ -116,6 +107,96 @@ void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...)
116 nwz_lcdmsg(clear, x, y, buffer); 107 nwz_lcdmsg(clear, x, y, buffer);
117} 108}
118 109
110#define NWZ_COLOR_RGB(col) \
111 NWZ_COLOR_RED(col), NWZ_COLOR_GREEN(col), NWZ_COLOR_BLUE(col)
112
113void nwz_display_clear(nwz_color_t color)
114{
115 const char *path_display = "/usr/local/bin/display";
116 const char *args[16];
117 int index = 0;
118 char col[32];
119 args[index++] = "display";
120 args[index++] = "lcd";
121 args[index++] = "clear";
122 sprintf(col, "%d,%d,%d", NWZ_COLOR_RGB(color));
123 args[index++] = col;
124 args[index++] = NULL;
125 /* wait for lcdmsg to finish to avoid any race conditions in framebuffer
126 * accesses */
127 nwz_run(path_display, args, true);
128}
129
130void nwz_display_text(int x, int y, bool big_font, nwz_color_t foreground_col,
131 nwz_color_t background_col, int alpha, const char *text)
132{
133 const char *path_display = "/usr/local/bin/display";
134 const char *args[16];
135 int index = 0;
136 char fg[32],bg[32], pos[32], transp[16];
137 args[index++] = "display";
138 args[index++] = "lcd";
139 args[index++] = "text";
140 sprintf(pos, "%d,%d", x, y);
141 args[index++] = pos;
142 if(big_font)
143 args[index++] = "/usr/local/bin/font_14x24.bmp";
144 else
145 args[index++] = "/usr/local/bin/font_08x12.bmp";
146 sprintf(fg, "%d,%d,%d", NWZ_COLOR_RGB(foreground_col));
147 args[index++] = fg;
148 sprintf(bg, "%d,%d,%d", NWZ_COLOR_RGB(background_col));
149 args[index++] = bg;
150 sprintf(transp, "%d", alpha);
151 args[index++] = transp;
152 args[index++] = text;
153 args[index++] = NULL;
154 /* wait for lcdmsg to finish to avoid any race conditions in framebuffer
155 * accesses */
156 nwz_run(path_display, args, true);
157}
158
159void nwz_display_textf(int x, int y, bool big_font, nwz_color_t foreground_col,
160 nwz_color_t background_col, int alpha, const char *fmt, ...)
161{
162 char buffer[1024];
163 va_list args;
164 va_start(args, fmt);
165 vsprintf(buffer, fmt, args);
166 va_end(args);
167 nwz_display_text(x, y, big_font, foreground_col, background_col, alpha, buffer);
168}
169
170void nwz_display_bitmap(int x, int y, const char *file, int left, int top,
171 int width, int height, nwz_color_t key_col, int bmp_alpha)
172{
173 const char *path_display = "/usr/local/bin/display";
174 const char *args[16];
175 int index = 0;
176 char pos[32], topleft[32], dim[32], key[32], transp[16];
177 args[index++] = "display";
178 args[index++] = "lcd";
179 args[index++] = "bitmap";
180 sprintf(pos, "%d,%d", x, y);
181 args[index++] = pos;
182 args[index++] = file;
183 sprintf(topleft, "%d,%d", left, top);
184 args[index++] = topleft;
185 sprintf(dim, "%d,%d", width, height);
186 args[index++] = dim;
187 if(key_col == NWZ_COLOR_NO_KEY)
188 sprintf(key, "no");
189 else
190 sprintf(key, "%d,%d,%d", NWZ_COLOR_RGB(key_col));
191 args[index++] = key;
192 sprintf(transp, "%d", bmp_alpha);
193 args[index++] = transp;
194 args[index++] = NULL;
195 /* wait for lcdmsg to finish to avoid any race conditions in framebuffer
196 * accesses */
197 nwz_run(path_display, args, true);
198}
199
119int nwz_input_open(const char *requested_name) 200int nwz_input_open(const char *requested_name)
120{ 201{
121 /* try all /dev/input/eventX, there can't a lot of them */ 202 /* try all /dev/input/eventX, there can't a lot of them */
@@ -259,6 +340,20 @@ int nwz_fb_set_standard_mode(int fd)
259 return 0; 340 return 0;
260} 341}
261 342
343int nwz_fb_get_resolution(int fd, int *x, int *y, int *bpp)
344{
345 struct fb_var_screeninfo vinfo;
346 if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
347 return -1;
348 if(x)
349 *x = vinfo.xres;
350 if(y)
351 *y = vinfo.yres;
352 if(bpp)
353 *bpp = vinfo.bits_per_pixel;
354 return 0;
355}
356
262int nwz_adc_open(void) 357int nwz_adc_open(void)
263{ 358{
264 return open(NWZ_ADC_DEV, O_RDONLY); 359 return open(NWZ_ADC_DEV, O_RDONLY);
@@ -560,3 +655,95 @@ unsigned int nwz_pminfo_get_factor(int fd)
560 else 655 else
561 return val; 656 return val;
562} 657}
658
659static unsigned long find_model_id(void)
660{
661 /* try with the environment variable */
662 const char *mid = getenv("ICX_MODEL_ID");
663 if(mid == NULL)
664 return 0;
665 char *end;
666 unsigned long v = strtoul(mid, &end, 0);
667 if(*end)
668 return 0;
669 else
670 return v;
671}
672
673unsigned long nwz_get_model_id(void)
674{
675 static unsigned long model_id = 0xffffffff;
676 if(model_id == 0xffffffff)
677 model_id = find_model_id();
678 return model_id;
679}
680
681const char *nwz_get_model_name()
682{
683 for(int i = 0; i < NWZ_MODEL_COUNT; i++)
684 if(nwz_model[i].mid == nwz_get_model_id())
685 return nwz_model[i].name;
686 return NULL;
687}
688
689static int find_series(void)
690{
691 for(int i = 0; i < NWZ_SERIES_COUNT; i++)
692 for(int j = 0; j < nwz_series[i].mid_count; j++)
693 if(nwz_series[i].mid[j] == nwz_get_model_id())
694 return i;
695 return -1;
696}
697
698int nwz_get_series(void)
699{
700 static int series = -2;
701 if(series == -2)
702 series = find_series();
703 return series;
704}
705
706static nwz_nvp_index_t *get_nvp_index(void)
707{
708 static nwz_nvp_index_t *index = 0;
709 if(index == 0)
710 {
711 int series = nwz_get_series();
712 index = series < 0 ? 0 : nwz_series[series].nvp_index;
713 }
714 return index;
715}
716
717int nwz_nvp_read(enum nwz_nvp_node_t node, void *data)
718{
719 int size = nwz_nvp[node].size;
720 if(data == 0)
721 return size;
722 nwz_nvp_index_t *index = get_nvp_index();
723 if(index == 0 || (*index)[node] == NWZ_NVP_INVALID)
724 return -1;
725 char nvp_path[32];
726 snprintf(nvp_path, sizeof(nvp_path), "/dev/icx_nvp/%03d", (*index)[node]);
727 int fd = open(nvp_path, O_RDONLY);
728 if(fd < 0)
729 return -1;
730 int cnt = read(fd, data, size);
731 close(fd);
732 return cnt == size ? size : -1;
733}
734
735int nwz_nvp_write(enum nwz_nvp_node_t node, void *data)
736{
737 int size = nwz_nvp[node].size;
738 nwz_nvp_index_t *index = get_nvp_index();
739 if(index == 0 || (*index)[node] == NWZ_NVP_INVALID)
740 return -1;
741 char nvp_path[32];
742 snprintf(nvp_path, sizeof(nvp_path), "/dev/icx_nvp/%03d", (*index)[node]);
743 int fd = open(nvp_path, O_WRONLY);
744 if(fd < 0)
745 return -1;
746 int cnt = write(fd, data, size);
747 close(fd);
748 return cnt == size ? 0 : -1;
749}