summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/nwztools/plattools/nwz_adc.h42
-rw-r--r--utils/nwztools/plattools/nwz_fb.h56
-rw-r--r--utils/nwztools/plattools/nwz_keys.h2
-rw-r--r--utils/nwztools/plattools/nwz_lib.c40
-rw-r--r--utils/nwztools/plattools/nwz_lib.h11
-rw-r--r--utils/nwztools/plattools/test_adc.c64
6 files changed, 213 insertions, 2 deletions
diff --git a/utils/nwztools/plattools/nwz_adc.h b/utils/nwztools/plattools/nwz_adc.h
new file mode 100644
index 0000000000..86b2dc7595
--- /dev/null
+++ b/utils/nwztools/plattools/nwz_adc.h
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
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#ifndef __NWZ_ADC_H__
22#define __NWZ_ADC_H__
23
24#define NWZ_ADC_DEV "/dev/icx_adc"
25
26#define NWZ_ADC_TYPE 'm'
27
28#define NWZ_ADC_MIN_CHAN 0
29#define NWZ_ADC_MAX_CHAN 7
30
31#define NWZ_ADC_VCCBAT 0
32#define NWZ_ADC_VCCVBUS 1
33#define NWZ_ADC_ADIN3 2
34#define NWZ_ADC_ADIN4 3
35#define NWZ_ADC_ADIN5 4
36#define NWZ_ADC_ADIN6 5
37#define NWZ_ADC_ADIN7 6
38#define NWZ_ADC_ADIN8 7
39
40#define NWZ_ADC_GET_VAL(chan) _IOR(NWZ_ADC_TYPE, chan, unsigned char)
41
42#endif /* __NWZ_ADC_H__ */
diff --git a/utils/nwztools/plattools/nwz_fb.h b/utils/nwztools/plattools/nwz_fb.h
new file mode 100644
index 0000000000..c857c5eb8a
--- /dev/null
+++ b/utils/nwztools/plattools/nwz_fb.h
@@ -0,0 +1,56 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
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#ifndef __NWZ_FB_H__
22#define __NWZ_FB_H__
23
24#define NWZ_FB_LCD_DEV "/dev/fb/0"
25#define NWZ_FB_TV_DEV "/dev/fb/1"
26
27#define NWZ_FB_TYPE 'N'
28
29/* How backlight works:
30 *
31 * The brightness interface is a bit strange. There 6 levels: 0 throught 5.
32 * Level 0 means backlight off. When changing brightness, one sets level to the
33 * target brightness. The driver is gradually change the brightness to reach the
34 * target level. The step parameters control how many hardware steps will be done.
35 * For example, setting step to 1 will brutally change the level in one step.
36 * Setting step to 2 will change brightness in two steps: one intermediate and
37 * finally the target one. The more steps, the more gradual the transition. The
38 * period parameters controls the speed to changes between steps. Using this
39 * interface, one can achieve fade in/out at various speeds. */
40#define NWZ_FB_BL_MIN_LEVEL 0
41#define NWZ_FB_BL_MAX_LEVEL 5
42#define NWZ_FB_BL_MIN_STEP 1
43#define NWZ_FB_BL_MAX_STEP 100
44#define NWZ_FB_BL_MIN_PERIOD 10
45
46struct nwz_fb_brightness
47{
48 int level; /* brightness level: 0-5 */
49 int step; /* number of hardware steps to do when changing: 1-100 */
50 int period; /* period in ms between steps when changing: >=10 */
51};
52
53#define NWZ_FB_SET_BRIGHTNESS _IOW(NWZ_FB_TYPE, 0x07, struct nwz_fb_brightness)
54#define NWZ_FB_GET_BRIGHTNESS _IOR(NWZ_FB_TYPE, 0x08, struct nwz_fb_brightness)
55
56#endif /* __NWZ_FB_H__ */
diff --git a/utils/nwztools/plattools/nwz_keys.h b/utils/nwztools/plattools/nwz_keys.h
index 8228e5b620..4a8c28737f 100644
--- a/utils/nwztools/plattools/nwz_keys.h
+++ b/utils/nwztools/plattools/nwz_keys.h
@@ -21,6 +21,8 @@
21#ifndef __NWZ_KEYS_H__ 21#ifndef __NWZ_KEYS_H__
22#define __NWZ_KEYS_H__ 22#define __NWZ_KEYS_H__
23 23
24#define NWZ_KEY_DEV "/dev/input/event0"
25
24/* The Sony icx_key driver reports keys via the /dev/input/event0 device and 26/* The Sony icx_key driver reports keys via the /dev/input/event0 device and
25 * abuses the standard struct input_event. The input_event.code is split into 27 * abuses the standard struct input_event. The input_event.code is split into
26 * two parts: 28 * two parts:
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c
index 6316217902..b654855bb8 100644
--- a/utils/nwztools/plattools/nwz_lib.c
+++ b/utils/nwztools/plattools/nwz_lib.c
@@ -71,7 +71,7 @@ void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...)
71 71
72int nwz_key_open(void) 72int nwz_key_open(void)
73{ 73{
74 return open("/dev/input/event0", O_RDONLY); 74 return open(NWZ_KEY_DEV, O_RDONLY);
75} 75}
76 76
77void nwz_key_close(int fd) 77void nwz_key_close(int fd)
@@ -160,7 +160,7 @@ const char *nwz_key_get_name(int keycode)
160 160
161int nwz_fb_open(bool lcd) 161int nwz_fb_open(bool lcd)
162{ 162{
163 return open(lcd ? "/dev/fb/0" : "/dev/fb/1", O_RDWR); 163 return open(lcd ? NWZ_FB_LCD_DEV : NWZ_FB_TV_DEV, O_RDWR);
164} 164}
165 165
166void nwz_fb_close(int fd) 166void nwz_fb_close(int fd)
@@ -183,3 +183,39 @@ int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl)
183 else 183 else
184 return 1; 184 return 1;
185} 185}
186
187int nwz_adc_open(void)
188{
189 return open(NWZ_ADC_DEV, O_RDONLY);
190}
191
192void nwz_adc_close(int fd)
193{
194 close(fd);
195}
196
197static const char *nwz_adc_name[] =
198{
199 [NWZ_ADC_VCCBAT] = "VCCBAT",
200 [NWZ_ADC_VCCVBUS] = "VCCVBUS",
201 [NWZ_ADC_ADIN3] = "ADIN3",
202 [NWZ_ADC_ADIN4] = "ADIN4",
203 [NWZ_ADC_ADIN5] = "ADIN5",
204 [NWZ_ADC_ADIN6] = "ADIN6",
205 [NWZ_ADC_ADIN7] = "ADIN7",
206 [NWZ_ADC_ADIN8] = "ADIN8",
207};
208
209const char *nwz_adc_get_name(int ch)
210{
211 return nwz_adc_name[ch];
212}
213
214int nwz_adc_get_val(int fd, int ch)
215{
216 unsigned char val;
217 if(ioctl(fd, NWZ_ADC_GET_VAL(ch), &val) < 0)
218 return -1;
219 else
220 return val;
221}
diff --git a/utils/nwztools/plattools/nwz_lib.h b/utils/nwztools/plattools/nwz_lib.h
index 86f11ac346..5c8ad3e50c 100644
--- a/utils/nwztools/plattools/nwz_lib.h
+++ b/utils/nwztools/plattools/nwz_lib.h
@@ -32,6 +32,7 @@
32 32
33#include "nwz_keys.h" 33#include "nwz_keys.h"
34#include "nwz_fb.h" 34#include "nwz_fb.h"
35#include "nwz_adc.h"
35 36
36/* run a program and exit with nonzero status in case of error 37/* run a program and exit with nonzero status in case of error
37 * argument list must be NULL terminated */ 38 * argument list must be NULL terminated */
@@ -61,6 +62,7 @@ bool nwz_key_event_is_press(struct input_event *evt);
61bool nwz_key_event_get_hold_status(struct input_event *evt); 62bool nwz_key_event_get_hold_status(struct input_event *evt);
62/* get keycode name */ 63/* get keycode name */
63const char *nwz_key_get_name(int keycode); 64const char *nwz_key_get_name(int keycode);
65
64/* open framebuffer device */ 66/* open framebuffer device */
65int nwz_fb_open(bool lcd); 67int nwz_fb_open(bool lcd);
66/* close framebuffer device */ 68/* close framebuffer device */
@@ -70,4 +72,13 @@ int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl);
70/* set backlight brightness (return -1 on error, 1 on success) */ 72/* set backlight brightness (return -1 on error, 1 on success) */
71int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl); 73int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl);
72 74
75/* open adc device */
76int nwz_adc_open(void);
77/* close adc device */
78void nwz_adc_close(int fd);
79/* get channel name */
80const char *nwz_adc_get_name(int ch);
81/* read channel value, return -1 on error */
82int nwz_adc_get_val(int fd, int ch);
83
73#endif /* _NWZLIB_H_ */ 84#endif /* _NWZLIB_H_ */
diff --git a/utils/nwztools/plattools/test_adc.c b/utils/nwztools/plattools/test_adc.c
new file mode 100644
index 0000000000..52eafd042d
--- /dev/null
+++ b/utils/nwztools/plattools/test_adc.c
@@ -0,0 +1,64 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
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#include "nwz_lib.h"
22
23int main(int argc, char **argv)
24{
25 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_adc");
27 nwz_lcdmsg(false, 0, 2, "PWR OFF: quit");
28 /* open input device */
29 int input_fd = nwz_key_open();
30 if(input_fd < 0)
31 {
32 nwz_lcdmsg(false, 3, 7, "Cannot open input device");
33 sleep(2);
34 return 1;
35 }
36 /* open adc device */
37 int adc_fd = nwz_adc_open();
38 if(adc_fd < 0)
39 {
40 nwz_lcdmsg(false, 3, 4, "Cannot open adc device");
41 sleep(2);
42 return 1;
43 }
44 /* display input state in a loop */
45 while(1)
46 {
47 /* print channels */
48 for(int i = NWZ_ADC_MIN_CHAN; i <= NWZ_ADC_MAX_CHAN; i++)
49 nwz_lcdmsgf(false, 1, 4 + i, "%s: %d ", nwz_adc_get_name(i),
50 nwz_adc_get_val(adc_fd, i));
51 /* wait for event (10ms) */
52 int ret = nwz_key_wait_event(input_fd, 10000);
53 if(ret != 1)
54 continue;
55 struct input_event evt;
56 if(nwz_key_read_event(input_fd, &evt) != 1)
57 continue;
58 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && !nwz_key_event_is_press(&evt))
59 break;
60 }
61 /* finish nicely */
62 return 0;
63}
64