summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/nwztools/plattools/Makefile12
-rw-r--r--utils/nwztools/plattools/all_tools.c132
-rw-r--r--utils/nwztools/plattools/dest_tool.c21
-rw-r--r--utils/nwztools/plattools/nwz_lib.c19
-rw-r--r--utils/nwztools/plattools/nwz_lib.h7
-rw-r--r--utils/nwztools/plattools/nwz_plattools.h37
-rw-r--r--utils/nwztools/plattools/nwz_power.h33
-rw-r--r--utils/nwztools/plattools/test_adc.c7
-rw-r--r--utils/nwztools/plattools/test_bl.c9
-rw-r--r--utils/nwztools/plattools/test_display.c3
-rw-r--r--utils/nwztools/plattools/test_keys.c46
-rw-r--r--utils/nwztools/plattools/test_power.c20
-rw-r--r--utils/nwztools/plattools/test_ts.c6
13 files changed, 325 insertions, 27 deletions
diff --git a/utils/nwztools/plattools/Makefile b/utils/nwztools/plattools/Makefile
index 31633294ee..8251afaf0a 100644
--- a/utils/nwztools/plattools/Makefile
+++ b/utils/nwztools/plattools/Makefile
@@ -5,13 +5,17 @@ CFLAGS=-std=gnu99 -Wall -O2
5INCLUDES=-I. 5INCLUDES=-I.
6 6
7LIB_FILES=nwz_lib.c nwz_lib_devlist.c 7LIB_FILES=nwz_lib.c nwz_lib_devlist.c
8ALL_BUT_LIB=$(patsubst %.c,%.elf,$(filter-out $(LIB_FILES),$(wildcard *.c))) 8TOOL_FILES=dest_tool.c test_adc.c test_adc.c test_bl.c test_display.c \
9 test_keys.c test_power.c test_ts.c
10ALL_ELF=$(patsubst %.c,%.elf,$(TOOL_FILES)) all_tools.elf
9 11
10all: $(ALL_BUT_LIB) 12all: $(ALL_ELF)
11 13
12%.elf: %.c $(LIB_FILES) 14%.elf: %.c $(LIB_FILES)
13 $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^ 15 $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^
14 16
15clean: 17all_tools.elf: all_tools.c $(TOOL_FILES) $(LIB_FILES)
16 rm -rf $(ALL_BUT_LIB) 18 $(CC) $(CFLAGS) -DNWZ_EMBED_TOOLS $(INCLUDES) -o $@ $^
17 19
20clean:
21 rm -rf $(ALL_ELF)
diff --git a/utils/nwztools/plattools/all_tools.c b/utils/nwztools/plattools/all_tools.c
new file mode 100644
index 0000000000..f3ecb51c05
--- /dev/null
+++ b/utils/nwztools/plattools/all_tools.c
@@ -0,0 +1,132 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
11 *
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24#include "nwz_lib.h"
25#include "nwz_plattools.h"
26
27#define TOOL_LIST \
28 TOOL(dest_tool) \
29 TOOL(test_adc) \
30 TOOL(test_bl) \
31 TOOL(test_display) \
32 TOOL(test_keys) \
33 TOOL(test_power) \
34 TOOL(test_ts)
35
36typedef int (*nwz_tool_main_t)(int argc, char **argv);
37
38struct nwz_tool_t
39{
40 const char *name;
41 nwz_tool_main_t main;
42};
43
44/* create list of extern definition */
45#define TOOL(name) extern int NWZ_TOOL_MAIN(name)(int argc, char **argv);
46TOOL_LIST
47#undef TOOL
48
49/* create actual list */
50#define TOOL(name) { #name, NWZ_TOOL_MAIN(name) },
51static struct nwz_tool_t g_tools[] =
52{
53 TOOL_LIST
54};
55#undef TOOL
56
57#define NR_TOOLS (sizeof(g_tools) / sizeof(g_tools[0]))
58
59static void hello(void)
60{
61 /* clear screen and display welcome message */
62 nwz_lcdmsg(true, 0, 0, "all_tools");
63 nwz_lcdmsg(false, 0, 2, "BACK: quit");
64 nwz_lcdmsg(false, 0, 2, "LEFT/RIGHT: change tool");
65 nwz_lcdmsg(false, 0, 3, "PLAY: run tool");
66}
67
68/* this tool itself can be embedded in the dualboot */
69#ifdef NWZ_DUALBOOT
70int NWZ_TOOL_MAIN(all_tools)(int argc, char **argv)
71#else
72int main(int argc, char **argv)
73#endif
74{
75 hello();
76 /* open input device */
77 int input_fd = nwz_key_open();
78 if(input_fd < 0)
79 {
80 nwz_lcdmsg(false, 3, 5, "Cannot open input device");
81 sleep(2);
82 return 1;
83 }
84 /* main loop */
85 int cur_tool = 0;
86 while(true)
87 {
88 /* print tools */
89 int line = 5;
90 for(size_t i = 0; i < NR_TOOLS; i++)
91 {
92 nwz_lcdmsgf(false, 0, line++, "%c %s", (i == cur_tool) ? '>' : ' ',
93 g_tools[i].name);
94 }
95 /* wait for event (1000ms) */
96 int ret = nwz_key_wait_event(input_fd, 1000000);
97 if(ret != 1)
98 continue;
99 struct input_event evt;
100 if(nwz_key_read_event(input_fd, &evt) != 1)
101 continue;
102 /* only act on key release */
103 if(nwz_key_event_is_press(&evt))
104 continue;
105 int keycode = nwz_key_event_get_keycode(&evt);
106 if(keycode == NWZ_KEY_LEFT)
107 {
108 cur_tool--;
109 if(cur_tool == -1)
110 cur_tool += NR_TOOLS;
111 }
112 else if(keycode == NWZ_KEY_RIGHT)
113 {
114 cur_tool++;
115 if(cur_tool == NR_TOOLS)
116 cur_tool = 0;
117 }
118 else if(keycode == NWZ_KEY_PLAY)
119 {
120 /* close input */
121 nwz_key_close(input_fd);
122 g_tools[cur_tool].main(argc, argv);
123 /* reopen input and clear the screen */
124 input_fd = nwz_key_open();
125 hello();
126 }
127 else if(keycode == NWZ_KEY_BACK)
128 break;
129 }
130 nwz_key_close(input_fd);
131 return 0;
132}
diff --git a/utils/nwztools/plattools/dest_tool.c b/utils/nwztools/plattools/dest_tool.c
index 7b6c0a4ff6..d137239f7f 100644
--- a/utils/nwztools/plattools/dest_tool.c
+++ b/utils/nwztools/plattools/dest_tool.c
@@ -21,10 +21,11 @@
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include <string.h> 22#include <string.h>
23#include <stdlib.h> 23#include <stdlib.h>
24#include "nwz_plattools.h"
24 25
25extern char **environ; 26extern char **environ;
26 27
27const char *white_list[] = 28static const char *white_list[] =
28{ 29{
29 "NWZ-E463", "NWZ-E464", "NWZ-E465", 30 "NWZ-E463", "NWZ-E464", "NWZ-E465",
30 "NWZ-A863", "NWZ-A864", "NWZ-A865", "NWZ-A866", "NWZ-A867", 31 "NWZ-A863", "NWZ-A864", "NWZ-A865", "NWZ-A866", "NWZ-A867",
@@ -32,7 +33,7 @@ const char *white_list[] =
32}; 33};
33 34
34/* get model id from ICX_MODEL_ID environment variable */ 35/* get model id from ICX_MODEL_ID environment variable */
35unsigned long find_model_id(void) 36static unsigned long find_model_id(void)
36{ 37{
37 const char *mid = getenv("ICX_MODEL_ID"); 38 const char *mid = getenv("ICX_MODEL_ID");
38 if(mid == NULL) 39 if(mid == NULL)
@@ -45,12 +46,12 @@ unsigned long find_model_id(void)
45 return v; 46 return v;
46} 47}
47 48
48unsigned long read32(unsigned char *buf) 49static unsigned long read32(unsigned char *buf)
49{ 50{
50 return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24; 51 return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
51} 52}
52 53
53void write32(unsigned char *buf, unsigned long value) 54static void write32(unsigned char *buf, unsigned long value)
54{ 55{
55 buf[0] = value & 0xff; 56 buf[0] = value & 0xff;
56 buf[1] = (value >> 8) & 0xff; 57 buf[1] = (value >> 8) & 0xff;
@@ -58,7 +59,7 @@ void write32(unsigned char *buf, unsigned long value)
58 buf[3] = (value >> 24) & 0xff; 59 buf[3] = (value >> 24) & 0xff;
59} 60}
60 61
61struct 62static struct
62{ 63{
63 unsigned long dest; 64 unsigned long dest;
64 const char *name; 65 const char *name;
@@ -84,7 +85,7 @@ struct
84 85
85#define NR_DEST (sizeof(g_dest_list) / sizeof(g_dest_list[0])) 86#define NR_DEST (sizeof(g_dest_list) / sizeof(g_dest_list[0]))
86 87
87int get_dest_index(unsigned long dest) 88static int get_dest_index(unsigned long dest)
88{ 89{
89 for(size_t i = 0; i < NR_DEST; i++) 90 for(size_t i = 0; i < NR_DEST; i++)
90 if(g_dest_list[i].dest == dest) 91 if(g_dest_list[i].dest == dest)
@@ -92,16 +93,16 @@ int get_dest_index(unsigned long dest)
92 return -1; 93 return -1;
93} 94}
94 95
95const char *get_dest_name(unsigned long dest) 96static const char *get_dest_name(unsigned long dest)
96{ 97{
97 int index = get_dest_index(dest); 98 int index = get_dest_index(dest);
98 return index < 0 ? "NG" : g_dest_list[index].name; 99 return index < 0 ? "NG" : g_dest_list[index].name;
99} 100}
100 101
101int main(int argc, char **argv) 102int NWZ_TOOL_MAIN(dest_tool)(int argc, char **argv)
102{ 103{
103 /* clear screen and display welcome message */ 104 /* clear screen and display welcome message */
104 nwz_lcdmsg(true, 0, 0, "destination tool"); 105 nwz_lcdmsg(true, 0, 0, "dest_tool");
105 /* open input device */ 106 /* open input device */
106 int input_fd = nwz_key_open(); 107 int input_fd = nwz_key_open();
107 if(input_fd < 0) 108 if(input_fd < 0)
@@ -113,6 +114,7 @@ int main(int argc, char **argv)
113 unsigned long model_id = find_model_id(); 114 unsigned long model_id = find_model_id();
114 if(model_id == 0) 115 if(model_id == 0)
115 { 116 {
117 nwz_key_close(input_fd);
116 nwz_lcdmsg(false, 3, 4, "Cannot get model ID"); 118 nwz_lcdmsg(false, 3, 4, "Cannot get model ID");
117 sleep(2); 119 sleep(2);
118 return 1; 120 return 1;
@@ -214,5 +216,6 @@ int main(int argc, char **argv)
214 } 216 }
215 } 217 }
216 /* finish nicely */ 218 /* finish nicely */
219 nwz_key_close(input_fd);
217 return 0; 220 return 0;
218} 221}
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c
index ebfe488a7d..4f49bec909 100644
--- a/utils/nwztools/plattools/nwz_lib.c
+++ b/utils/nwztools/plattools/nwz_lib.c
@@ -483,3 +483,22 @@ int nwz_power_is_fully_charged(int fd)
483 return -1; 483 return -1;
484 return status; 484 return status;
485} 485}
486
487int nwz_pminfo_open(void)
488{
489 return open(NWZ_PMINFO_DEV, O_RDONLY);
490}
491
492void nwz_pminfo_close(int fd)
493{
494 close(fd);
495}
496
497unsigned int nwz_pminfo_get_factor(int fd)
498{
499 unsigned int val;
500 if(ioctl(fd, NWZ_PMINFO_GET_FACTOR, &val) < 0)
501 return 0;
502 else
503 return val;
504}
diff --git a/utils/nwztools/plattools/nwz_lib.h b/utils/nwztools/plattools/nwz_lib.h
index 5e1640a70e..90d122003a 100644
--- a/utils/nwztools/plattools/nwz_lib.h
+++ b/utils/nwztools/plattools/nwz_lib.h
@@ -158,4 +158,11 @@ int nwz_power_get_acc_charge_mode(int fd);
158/* is battery fully charged? (or -1 on error) */ 158/* is battery fully charged? (or -1 on error) */
159int nwz_power_is_fully_charged(int fd); 159int nwz_power_is_fully_charged(int fd);
160 160
161/* open pminfo device */
162int nwz_pminfo_open(void);
163/* close pminfo device */
164void nwz_pminfo_close(int fd);
165/* get pminfo factor (or 0 on error) */
166unsigned int nwz_pminfo_get_factor(int fd);
167
161#endif /* _NWZLIB_H_ */ 168#endif /* _NWZLIB_H_ */
diff --git a/utils/nwztools/plattools/nwz_plattools.h b/utils/nwztools/plattools/nwz_plattools.h
new file mode 100644
index 0000000000..56d584ce30
--- /dev/null
+++ b/utils/nwztools/plattools/nwz_plattools.h
@@ -0,0 +1,37 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
11 *
12 * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
13 * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24#ifndef __NWZ_PLATTOOLS_H__
25#define __NWZ_PLATTOOLS_H__
26
27/** Platform tools can be either built individually, or be included in a
28 * single build (or even dualboot code) for easy testing. Thus, each tool must
29 * use the following macros to support all scenarios. */
30
31#ifdef NWZ_EMBED_TOOLS
32#define NWZ_TOOL_MAIN(tool) tool##_main
33#else
34#define NWZ_TOOL_MAIN(tool) main
35#endif
36
37#endif /* __NWZ_PLATTOOLS_H__ */
diff --git a/utils/nwztools/plattools/nwz_power.h b/utils/nwztools/plattools/nwz_power.h
index e8df47a3d6..7b325ce047 100644
--- a/utils/nwztools/plattools/nwz_power.h
+++ b/utils/nwztools/plattools/nwz_power.h
@@ -21,6 +21,8 @@
21#ifndef __NWZ_POWER_H__ 21#ifndef __NWZ_POWER_H__
22#define __NWZ_POWER_H__ 22#define __NWZ_POWER_H__
23 23
24/** power */
25
24#define NWZ_POWER_DEV "/dev/icx_power" 26#define NWZ_POWER_DEV "/dev/icx_power"
25 27
26#define NWZ_POWER_TYPE 'P' 28#define NWZ_POWER_TYPE 'P'
@@ -79,4 +81,35 @@
79#define NWZ_POWER_ACC_CHARGE_VBAT 1 81#define NWZ_POWER_ACC_CHARGE_VBAT 1
80#define NWZ_POWER_ACC_CHARGE_VSYS 2 82#define NWZ_POWER_ACC_CHARGE_VSYS 2
81 83
84/** pminfo
85 *
86 * This driver seems to collect the state of the device on boot. Thus one
87 * can know if a key was pressed when booting for example.
88 */
89
90#define NWZ_PMINFO_DEV "/dev/icx_pminfo"
91
92#define NWZ_PMINFO_TYPE 'b'
93
94/* ioctl request */
95
96#define NWZ_PMINFO_GET_FACTOR _IOR(NWZ_PMINFO_TYPE, 0, unsigned int *)
97#define NWZ_PMINFO_CLR_DETRSTFLG _IO(NWZ_PMINFO_TYPE, 1)
98
99/* NWZ_PMINFO_GET_FACTOR bitmap
100 * WARNING this information may not apply to all players and some bits do not
101 * exists on some players */
102#define ICX_PMINFO_FACTOR_RTC_WAL 0x20000000 /* RTC Weekly Alarm */
103#define ICX_PMINFO_FACTOR_RTC_DAL 0x10000000 /* RTC Daily Alarm */
104#define ICX_PMINFO_FACTOR_VBUS 0x08000000 /* VBUS in/out */
105#define ICX_PMINFO_FACTOR_DC_POWER 0x04000000 /* AC Adaptor in/out */
106#define ICX_PMINFO_FACTOR_USB_WAKE 0x01000000 /* USB Wake */
107#define ICX_PMINFO_FACTOR_CHARGE 0x00400000 /* Charge */
108#define ICX_PMINFO_FACTOR_CRADLE 0x00080000 /* Cradle in/out */
109#define ICX_PMINFO_FACTOR_AB_EV 0x00008000 /* ab event */
110#define ICX_PMINFO_FACTOR_NC_SW 0x00004000 /* nc switch */
111#define ICX_PMINFO_FACTOR_HOLD_SW 0x00002000 /* hold switch */
112#define ICX_PMINFO_FACTOR_KEY_PAD 0x00001000 /* keypad */
113#define ICX_PMINFO_FACTOR_KEY_CODE 0x00000FFF /* keycode */
114
82#endif /* __NWZ_POWER_H__ */ 115#endif /* __NWZ_POWER_H__ */
diff --git a/utils/nwztools/plattools/test_adc.c b/utils/nwztools/plattools/test_adc.c
index a0b12f55cc..31b685c43e 100644
--- a/utils/nwztools/plattools/test_adc.c
+++ b/utils/nwztools/plattools/test_adc.c
@@ -19,8 +19,9 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include "nwz_plattools.h"
22 23
23int main(int argc, char **argv) 24int NWZ_TOOL_MAIN(test_adc)(int argc, char **argv)
24{ 25{
25 /* clear screen and display welcome message */ 26 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_adc"); 27 nwz_lcdmsg(true, 0, 0, "test_adc");
@@ -37,6 +38,7 @@ int main(int argc, char **argv)
37 int adc_fd = nwz_adc_open(); 38 int adc_fd = nwz_adc_open();
38 if(adc_fd < 0) 39 if(adc_fd < 0)
39 { 40 {
41 nwz_key_close(input_fd);
40 nwz_lcdmsg(false, 3, 4, "Cannot open adc device"); 42 nwz_lcdmsg(false, 3, 4, "Cannot open adc device");
41 sleep(2); 43 sleep(2);
42 return 1; 44 return 1;
@@ -59,6 +61,7 @@ int main(int argc, char **argv)
59 break; 61 break;
60 } 62 }
61 /* finish nicely */ 63 /* finish nicely */
64 nwz_key_close(input_fd);
65 nwz_adc_close(adc_fd);
62 return 0; 66 return 0;
63} 67}
64
diff --git a/utils/nwztools/plattools/test_bl.c b/utils/nwztools/plattools/test_bl.c
index f97162fc4f..594cbbd377 100644
--- a/utils/nwztools/plattools/test_bl.c
+++ b/utils/nwztools/plattools/test_bl.c
@@ -19,8 +19,9 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include "nwz_plattools.h"
22 23
23int main(int argc, char **argv) 24int NWZ_TOOL_MAIN(test_bl)(int argc, char **argv)
24{ 25{
25 /* clear screen and display welcome message */ 26 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_bl"); 27 nwz_lcdmsg(true, 0, 0, "test_bl");
@@ -39,6 +40,7 @@ int main(int argc, char **argv)
39 int fb_fd = nwz_fb_open(true); 40 int fb_fd = nwz_fb_open(true);
40 if(fb_fd < 0) 41 if(fb_fd < 0)
41 { 42 {
43 nwz_key_close(input_fd);
42 nwz_lcdmsg(false, 3, 7, "Cannot open framebuffer device"); 44 nwz_lcdmsg(false, 3, 7, "Cannot open framebuffer device");
43 sleep(2); 45 sleep(2);
44 return 1; 46 return 1;
@@ -103,9 +105,8 @@ int main(int argc, char **argv)
103 nwz_fb_set_brightness(fb_fd, &bl); 105 nwz_fb_set_brightness(fb_fd, &bl);
104 } 106 }
105 /* close input device */ 107 /* close input device */
106 close(input_fd); 108 nwz_key_close(input_fd);
109 nwz_fb_close(fb_fd);
107 /* finish nicely */ 110 /* finish nicely */
108 return 0; 111 return 0;
109} 112}
110
111
diff --git a/utils/nwztools/plattools/test_display.c b/utils/nwztools/plattools/test_display.c
index a0dc706624..1ebf40e813 100644
--- a/utils/nwztools/plattools/test_display.c
+++ b/utils/nwztools/plattools/test_display.c
@@ -19,8 +19,9 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include "nwz_plattools.h"
22 23
23int main(int argc, char **argv) 24int NWZ_TOOL_MAIN(test_display)(int argc, char **argv)
24{ 25{
25 /* clear screen and display welcome message */ 26 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_display"); 27 nwz_lcdmsg(true, 0, 0, "test_display");
diff --git a/utils/nwztools/plattools/test_keys.c b/utils/nwztools/plattools/test_keys.c
index bfeadbb42b..353864d96f 100644
--- a/utils/nwztools/plattools/test_keys.c
+++ b/utils/nwztools/plattools/test_keys.c
@@ -19,12 +19,13 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include "nwz_plattools.h"
22 23
23int main(int argc, char **argv) 24int NWZ_TOOL_MAIN(test_keys)(int argc, char **argv)
24{ 25{
25 /* clear screen and display welcome message */ 26 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_keys"); 27 nwz_lcdmsg(true, 0, 0, "test_keys");
27 nwz_lcdmsg(false, 0, 2, "hold BACK for 3 seconds to quit"); 28 nwz_lcdmsg(false, 0, 2, "BACK: hold 3 seconds to quit");
28 /* open input device */ 29 /* open input device */
29 int input_fd = nwz_key_open(); 30 int input_fd = nwz_key_open();
30 if(input_fd < 0) 31 if(input_fd < 0)
@@ -35,6 +36,10 @@ int main(int argc, char **argv)
35 } 36 }
36 /* display input state in a loop */ 37 /* display input state in a loop */
37 int back_pressed = 0; /* 0 = no pressed, >0 = number of seconds pressed - 1 */ 38 int back_pressed = 0; /* 0 = no pressed, >0 = number of seconds pressed - 1 */
39#define FIRST_LINE 7
40#define LAST_LINE 17
41 int event_line = FIRST_LINE;
42 int prev_evt_line = -1;
38 while(1) 43 while(1)
39 { 44 {
40 /* display HOLD status */ 45 /* display HOLD status */
@@ -52,18 +57,49 @@ int main(int argc, char **argv)
52 struct input_event evt; 57 struct input_event evt;
53 if(nwz_key_read_event(input_fd, &evt) != 1) 58 if(nwz_key_read_event(input_fd, &evt) != 1)
54 continue; 59 continue;
55 nwz_lcdmsgf(false, 2, 6, "%s %s (HOLD=%d) ", 60 /* erase last '>' indicator */
61 if(prev_evt_line != -1)
62 nwz_lcdmsg(false, 0, prev_evt_line, " ");
63 prev_evt_line = event_line;
64 char buffer[32];
65 int len = sprintf(buffer, "> %s %s (HOLD=%d)",
56 nwz_key_get_name(nwz_key_event_get_keycode(&evt)), 66 nwz_key_get_name(nwz_key_event_get_keycode(&evt)),
57 nwz_key_event_is_press(&evt) ? "pressed" : "released", 67 nwz_key_event_is_press(&evt) ? "pressed" : "released",
58 nwz_key_event_get_hold_status(&evt)); 68 nwz_key_event_get_hold_status(&evt));
69 /* pad with spaces to erase old stuff */
70 while(len + 1 < sizeof(buffer))
71 buffer[len++] = ' ';
72 buffer[len] = 0;
73 /* print line */
74 nwz_lcdmsg(false, 0, event_line, buffer);
75 /* compute next line */
76 event_line++;
77 if(event_line == LAST_LINE)
78 event_line = FIRST_LINE;
79 /* handle quit */
59 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && nwz_key_event_is_press(&evt)) 80 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && nwz_key_event_is_press(&evt))
60 back_pressed = 1; 81 back_pressed = 1;
61 else 82 else
62 back_pressed = 0; 83 back_pressed = 0;
63 } 84 }
85 /* wait until back is released, to avoid messing with all_tools (if embedded) */
86 nwz_lcdmsg(true, 0, 0, "test_keys");
87 nwz_lcdmsg(false, 0, 2, "BACK: release to quit");
88 while(1)
89 {
90 /* wait for event */
91 int ret = nwz_key_wait_event(input_fd, 1000000);
92 if(ret != 1)
93 continue;
94 struct input_event evt;
95 if(nwz_key_read_event(input_fd, &evt) != 1)
96 continue;
97 /* handle quit */
98 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_BACK && !nwz_key_event_is_press(&evt))
99 break;
100 }
64 /* close input device */ 101 /* close input device */
65 close(input_fd); 102 nwz_key_close(input_fd);
66 /* finish nicely */ 103 /* finish nicely */
67 return 0; 104 return 0;
68} 105}
69
diff --git a/utils/nwztools/plattools/test_power.c b/utils/nwztools/plattools/test_power.c
index 9c429b989a..f0d374bf7b 100644
--- a/utils/nwztools/plattools/test_power.c
+++ b/utils/nwztools/plattools/test_power.c
@@ -19,6 +19,7 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include "nwz_plattools.h"
22 23
23static const char *charge_status_name(int chgstat) 24static const char *charge_status_name(int chgstat)
24{ 25{
@@ -59,7 +60,7 @@ static const char *acc_charge_mode_name(int mode)
59 } 60 }
60} 61}
61 62
62int main(int argc, char **argv) 63int NWZ_TOOL_MAIN(test_power)(int argc, char **argv)
63{ 64{
64 /* clear screen and display welcome message */ 65 /* clear screen and display welcome message */
65 nwz_lcdmsg(true, 0, 0, "test_power"); 66 nwz_lcdmsg(true, 0, 0, "test_power");
@@ -76,10 +77,21 @@ int main(int argc, char **argv)
76 int power_fd = nwz_power_open(); 77 int power_fd = nwz_power_open();
77 if(power_fd < 0) 78 if(power_fd < 0)
78 { 79 {
80 nwz_key_close(input_fd);
79 nwz_lcdmsg(false, 3, 4, "Cannot open power device"); 81 nwz_lcdmsg(false, 3, 4, "Cannot open power device");
80 sleep(2); 82 sleep(2);
81 return 1; 83 return 1;
82 } 84 }
85 /* open pminfo device */
86 int pminfo_fd = nwz_pminfo_open();
87 if(pminfo_fd < 0)
88 {
89 nwz_key_close(power_fd);
90 nwz_key_close(input_fd);
91 nwz_lcdmsg(false, 3, 4, "Cannot open pminfo device");
92 sleep(2);
93 return 1;
94 }
83 /* display input state in a loop */ 95 /* display input state in a loop */
84 while(1) 96 while(1)
85 { 97 {
@@ -119,6 +131,9 @@ int main(int argc, char **argv)
119 nwz_power_get_vbat_voltage(power_fd), nwz_power_get_vbat_adval(power_fd)); 131 nwz_power_get_vbat_voltage(power_fd), nwz_power_get_vbat_adval(power_fd));
120 nwz_lcdmsgf(false, 0, line++, "acc charge mode: %s (%d) ", 132 nwz_lcdmsgf(false, 0, line++, "acc charge mode: %s (%d) ",
121 acc_charge_mode_name(acc_chg_mode), acc_chg_mode); 133 acc_charge_mode_name(acc_chg_mode), acc_chg_mode);
134 /* pminfo */
135 line++;
136 nwz_lcdmsgf(false, 0, line++, "pminfo: %#x ", nwz_pminfo_get_factor(pminfo_fd));
122 /* wait for event (1s) */ 137 /* wait for event (1s) */
123 int ret = nwz_key_wait_event(input_fd, 1000000); 138 int ret = nwz_key_wait_event(input_fd, 1000000);
124 if(ret != 1) 139 if(ret != 1)
@@ -130,5 +145,8 @@ int main(int argc, char **argv)
130 break; 145 break;
131 } 146 }
132 /* finish nicely */ 147 /* finish nicely */
148 nwz_key_close(power_fd);
149 nwz_key_close(input_fd);
150 nwz_pminfo_close(pminfo_fd);
133 return 0; 151 return 0;
134} 152}
diff --git a/utils/nwztools/plattools/test_ts.c b/utils/nwztools/plattools/test_ts.c
index af6c741e00..b42d93bd09 100644
--- a/utils/nwztools/plattools/test_ts.c
+++ b/utils/nwztools/plattools/test_ts.c
@@ -19,8 +19,9 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "nwz_lib.h" 21#include "nwz_lib.h"
22#include "nwz_plattools.h"
22 23
23int main(int argc, char **argv) 24int NWZ_TOOL_MAIN(test_ts)(int argc, char **argv)
24{ 25{
25 /* clear screen and display welcome message */ 26 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_ts"); 27 nwz_lcdmsg(true, 0, 0, "test_ts");
@@ -36,6 +37,7 @@ int main(int argc, char **argv)
36 int ts_fd = nwz_ts_open(); 37 int ts_fd = nwz_ts_open();
37 if(ts_fd < 0) 38 if(ts_fd < 0)
38 { 39 {
40 nwz_key_close(key_fd);
39 nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device"); 41 nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device");
40 sleep(2); 42 sleep(2);
41 return 1; 43 return 1;
@@ -44,6 +46,8 @@ int main(int argc, char **argv)
44 struct nwz_ts_state_t ts_state; 46 struct nwz_ts_state_t ts_state;
45 if(nwz_ts_state_init(ts_fd, &ts_state) < 0) 47 if(nwz_ts_state_init(ts_fd, &ts_state) < 0)
46 { 48 {
49 nwz_key_close(key_fd);
50 nwz_ts_close(ts_fd);
47 nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device"); 51 nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device");
48 sleep(2); 52 sleep(2);
49 return 1; 53 return 1;