diff options
Diffstat (limited to 'utils/nwztools/plattools')
-rw-r--r-- | utils/nwztools/plattools/nwz_keys.h | 2 | ||||
-rw-r--r-- | utils/nwztools/plattools/nwz_lib.c | 284 | ||||
-rw-r--r-- | utils/nwztools/plattools/nwz_lib.h | 69 | ||||
-rw-r--r-- | utils/nwztools/plattools/nwz_power.h | 82 | ||||
-rw-r--r-- | utils/nwztools/plattools/nwz_ts.h | 35 | ||||
-rw-r--r-- | utils/nwztools/plattools/test_adc.c | 2 | ||||
-rw-r--r-- | utils/nwztools/plattools/test_power.c | 134 | ||||
-rw-r--r-- | utils/nwztools/plattools/test_ts.c | 94 |
8 files changed, 685 insertions, 17 deletions
diff --git a/utils/nwztools/plattools/nwz_keys.h b/utils/nwztools/plattools/nwz_keys.h index 4a8c28737f..9fc5b4c9fd 100644 --- a/utils/nwztools/plattools/nwz_keys.h +++ b/utils/nwztools/plattools/nwz_keys.h | |||
@@ -21,7 +21,7 @@ | |||
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" | 24 | #define NWZ_KEY_NAME "icx_key" |
25 | 25 | ||
26 | /* 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 |
27 | * 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 |
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c index b654855bb8..4ea1edee19 100644 --- a/utils/nwztools/plattools/nwz_lib.c +++ b/utils/nwztools/plattools/nwz_lib.c | |||
@@ -69,9 +69,29 @@ void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...) | |||
69 | nwz_lcdmsg(clear, x, y, buffer); | 69 | nwz_lcdmsg(clear, x, y, buffer); |
70 | } | 70 | } |
71 | 71 | ||
72 | int nwz_input_open(const char *requested_name) | ||
73 | { | ||
74 | /* try all /dev/input/eventX, there can't a lot of them */ | ||
75 | for(int index = 0; index < 8; index++) | ||
76 | { | ||
77 | char buffer[32]; | ||
78 | sprintf(buffer, "/dev/input/event%d", index); | ||
79 | int fd = open(buffer, O_RDWR); | ||
80 | if(fd < 0) | ||
81 | continue; /* try next one */ | ||
82 | /* query name */ | ||
83 | char name[256]; | ||
84 | if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) >= 0 && | ||
85 | strcmp(name, requested_name) == 0) | ||
86 | return fd; | ||
87 | close(fd); | ||
88 | } | ||
89 | return -1; | ||
90 | } | ||
91 | |||
72 | int nwz_key_open(void) | 92 | int nwz_key_open(void) |
73 | { | 93 | { |
74 | return open(NWZ_KEY_DEV, O_RDONLY); | 94 | return nwz_input_open(NWZ_KEY_NAME); |
75 | } | 95 | } |
76 | 96 | ||
77 | void nwz_key_close(int fd) | 97 | void nwz_key_close(int fd) |
@@ -89,20 +109,7 @@ int nwz_key_get_hold_status(int fd) | |||
89 | 109 | ||
90 | int nwz_key_wait_event(int fd, long tmo_us) | 110 | int nwz_key_wait_event(int fd, long tmo_us) |
91 | { | 111 | { |
92 | fd_set rfds; | 112 | return nwz_wait_fds(&fd, 1, tmo_us); |
93 | struct timeval tv; | ||
94 | struct timeval *tv_ptr = NULL; | ||
95 | /* watch the input device */ | ||
96 | FD_ZERO(&rfds); | ||
97 | FD_SET(fd, &rfds); | ||
98 | /* setup timeout */ | ||
99 | if(tmo_us >= 0) | ||
100 | { | ||
101 | tv.tv_sec = 0; | ||
102 | tv.tv_usec = tmo_us; | ||
103 | tv_ptr = &tv; | ||
104 | } | ||
105 | return select(fd + 1, &rfds, NULL, NULL, tv_ptr); | ||
106 | } | 113 | } |
107 | 114 | ||
108 | int nwz_key_read_event(int fd, struct input_event *evt) | 115 | int nwz_key_read_event(int fd, struct input_event *evt) |
@@ -219,3 +226,250 @@ int nwz_adc_get_val(int fd, int ch) | |||
219 | else | 226 | else |
220 | return val; | 227 | return val; |
221 | } | 228 | } |
229 | |||
230 | int nwz_ts_open(void) | ||
231 | { | ||
232 | return nwz_input_open(NWZ_TS_NAME); | ||
233 | } | ||
234 | |||
235 | void nwz_ts_close(int fd) | ||
236 | { | ||
237 | close(fd); | ||
238 | } | ||
239 | |||
240 | int nwz_ts_state_init(int fd, struct nwz_ts_state_t *state) | ||
241 | { | ||
242 | memset(state, 0, sizeof(struct nwz_ts_state_t)); | ||
243 | struct input_absinfo info; | ||
244 | if(ioctl(fd, EVIOCGABS(ABS_X), &info) < 0) | ||
245 | return -1; | ||
246 | state->max_x = info.maximum; | ||
247 | if(ioctl(fd, EVIOCGABS(ABS_Y), &info) < 0) | ||
248 | return -1; | ||
249 | state->max_y = info.maximum; | ||
250 | if(ioctl(fd, EVIOCGABS(ABS_PRESSURE), &info) < 0) | ||
251 | return -1; | ||
252 | state->max_pressure = info.maximum; | ||
253 | if(ioctl(fd, EVIOCGABS(ABS_TOOL_WIDTH), &info) < 0) | ||
254 | return -1; | ||
255 | state->max_tool_width = info.maximum; | ||
256 | return 1; | ||
257 | } | ||
258 | |||
259 | int nwz_ts_state_update(struct nwz_ts_state_t *state, struct input_event *evt) | ||
260 | { | ||
261 | switch(evt->type) | ||
262 | { | ||
263 | case EV_SYN: | ||
264 | return 1; | ||
265 | case EV_REL: | ||
266 | if(evt->code == REL_RX) | ||
267 | state->flick_x = evt->value; | ||
268 | else if(evt->code == REL_RY) | ||
269 | state->flick_y = evt->value; | ||
270 | else | ||
271 | return -1; | ||
272 | state->flick = true; | ||
273 | break; | ||
274 | case EV_ABS: | ||
275 | if(evt->code == ABS_X) | ||
276 | state->x = evt->value; | ||
277 | else if(evt->code == ABS_Y) | ||
278 | state->y = evt->value; | ||
279 | else if(evt->code == ABS_PRESSURE) | ||
280 | state->pressure = evt->value; | ||
281 | else if(evt->code == ABS_TOOL_WIDTH) | ||
282 | state->tool_width = evt->value; | ||
283 | else | ||
284 | return -1; | ||
285 | break; | ||
286 | case EV_KEY: | ||
287 | if(evt->code == BTN_TOUCH) | ||
288 | state->touch = evt->value; | ||
289 | else | ||
290 | return -1; | ||
291 | break; | ||
292 | default: | ||
293 | return -1; | ||
294 | } | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | int nwz_ts_state_post_syn(struct nwz_ts_state_t *state) | ||
299 | { | ||
300 | state->flick = false; | ||
301 | return 1; | ||
302 | } | ||
303 | |||
304 | int nwz_ts_read_events(int fd, struct input_event *evts, int nr_evts) | ||
305 | { | ||
306 | int ret = read(fd, evts, nr_evts * sizeof(struct input_event)); | ||
307 | if(ret < 0) | ||
308 | return -1; | ||
309 | return ret / sizeof(struct input_event); | ||
310 | } | ||
311 | |||
312 | long nwz_wait_fds(int *fds, int nr_fds, long tmo_us) | ||
313 | { | ||
314 | fd_set rfds; | ||
315 | struct timeval tv; | ||
316 | struct timeval *tv_ptr = NULL; | ||
317 | /* watch the input device */ | ||
318 | FD_ZERO(&rfds); | ||
319 | int max_fd = 0; | ||
320 | for(int i = 0; i < nr_fds; i++) | ||
321 | { | ||
322 | FD_SET(fds[i], &rfds); | ||
323 | if(fds[i] > max_fd) | ||
324 | max_fd = fds[i]; | ||
325 | } | ||
326 | /* setup timeout */ | ||
327 | if(tmo_us >= 0) | ||
328 | { | ||
329 | tv.tv_sec = 0; | ||
330 | tv.tv_usec = tmo_us; | ||
331 | tv_ptr = &tv; | ||
332 | } | ||
333 | int ret = select(max_fd + 1, &rfds, NULL, NULL, tv_ptr); | ||
334 | if(ret <= 0) | ||
335 | return ret; | ||
336 | long bitmap = 0; | ||
337 | for(int i = 0; i < nr_fds; i++) | ||
338 | if(FD_ISSET(fds[i], &rfds)) | ||
339 | bitmap |= 1 << i; | ||
340 | return bitmap; | ||
341 | } | ||
342 | |||
343 | int nwz_power_open(void) | ||
344 | { | ||
345 | return open(NWZ_POWER_DEV, O_RDWR); | ||
346 | } | ||
347 | |||
348 | void nwz_power_close(int fd) | ||
349 | { | ||
350 | close(fd); | ||
351 | } | ||
352 | |||
353 | int nwz_power_get_status(int fd) | ||
354 | { | ||
355 | int status; | ||
356 | if(ioctl(fd, NWZ_POWER_GET_STATUS, &status) < 0) | ||
357 | return -1; | ||
358 | return status; | ||
359 | } | ||
360 | |||
361 | static int nwz_power_adval_to_mv(int adval, int ad_base) | ||
362 | { | ||
363 | if(adval == -1) | ||
364 | return -1; | ||
365 | /* the AD base corresponds to the millivolt value if adval was 255 */ | ||
366 | return (adval * ad_base) / 255; | ||
367 | } | ||
368 | |||
369 | int nwz_power_get_vbus_adval(int fd) | ||
370 | { | ||
371 | int status; | ||
372 | if(ioctl(fd, NWZ_POWER_GET_VBUS_ADVAL, &status) < 0) | ||
373 | return -1; | ||
374 | return status; | ||
375 | } | ||
376 | |||
377 | int nwz_power_get_vbus_voltage(int fd) | ||
378 | { | ||
379 | return nwz_power_adval_to_mv(nwz_power_get_vbus_adval(fd), NWZ_POWER_AD_BASE_VBUS); | ||
380 | } | ||
381 | |||
382 | int nwz_power_get_vbus_limit(int fd) | ||
383 | { | ||
384 | int status; | ||
385 | if(ioctl(fd, NWZ_POWER_GET_VBUS_LIMIT, &status) < 0) | ||
386 | return -1; | ||
387 | return status; | ||
388 | } | ||
389 | |||
390 | int nwz_power_get_charge_switch(int fd) | ||
391 | { | ||
392 | int status; | ||
393 | if(ioctl(fd, NWZ_POWER_GET_CHARGE_SWITCH, &status) < 0) | ||
394 | return -1; | ||
395 | return status; | ||
396 | } | ||
397 | |||
398 | int nwz_power_get_charge_current(int fd) | ||
399 | { | ||
400 | int status; | ||
401 | if(ioctl(fd, NWZ_POWER_GET_CHARGE_CURRENT, &status) < 0) | ||
402 | return -1; | ||
403 | return status; | ||
404 | } | ||
405 | |||
406 | int nwz_power_get_battery_gauge(int fd) | ||
407 | { | ||
408 | int status; | ||
409 | if(ioctl(fd, NWZ_POWER_GET_BAT_GAUGE, &status) < 0) | ||
410 | return -1; | ||
411 | return status; | ||
412 | } | ||
413 | |||
414 | int nwz_power_get_battery_adval(int fd) | ||
415 | { | ||
416 | int status; | ||
417 | if(ioctl(fd, NWZ_POWER_GET_BAT_ADVAL, &status) < 0) | ||
418 | return -1; | ||
419 | return status; | ||
420 | } | ||
421 | |||
422 | int nwz_power_get_battery_voltage(int fd) | ||
423 | { | ||
424 | return nwz_power_adval_to_mv(nwz_power_get_battery_adval(fd), NWZ_POWER_AD_BASE_VBAT); | ||
425 | } | ||
426 | |||
427 | int nwz_power_get_vbat_adval(int fd) | ||
428 | { | ||
429 | int status; | ||
430 | if(ioctl(fd, NWZ_POWER_GET_VBAT_ADVAL, &status) < 0) | ||
431 | return -1; | ||
432 | return status; | ||
433 | } | ||
434 | |||
435 | int nwz_power_get_vbat_voltage(int fd) | ||
436 | { | ||
437 | return nwz_power_adval_to_mv(nwz_power_get_vbat_adval(fd), NWZ_POWER_AD_BASE_VBAT); | ||
438 | } | ||
439 | |||
440 | int nwz_power_get_sample_count(int fd) | ||
441 | { | ||
442 | int status; | ||
443 | if(ioctl(fd, NWZ_POWER_GET_SAMPLE_COUNT, &status) < 0) | ||
444 | return -1; | ||
445 | return status; | ||
446 | } | ||
447 | |||
448 | int nwz_power_get_vsys_adval(int fd) | ||
449 | { | ||
450 | int status; | ||
451 | if(ioctl(fd, NWZ_POWER_GET_VSYS_ADVAL, &status) < 0) | ||
452 | return -1; | ||
453 | return status; | ||
454 | } | ||
455 | |||
456 | int nwz_power_get_vsys_voltage(int fd) | ||
457 | { | ||
458 | return nwz_power_adval_to_mv(nwz_power_get_vsys_adval(fd), NWZ_POWER_AD_BASE_VSYS); | ||
459 | } | ||
460 | |||
461 | int nwz_power_get_acc_charge_mode(int fd) | ||
462 | { | ||
463 | int status; | ||
464 | if(ioctl(fd, NWZ_POWER_GET_ACCESSARY_CHARGE_MODE, &status) < 0) | ||
465 | return -1; | ||
466 | return status; | ||
467 | } | ||
468 | |||
469 | int nwz_power_is_fully_charged(int fd) | ||
470 | { | ||
471 | int status; | ||
472 | if(ioctl(fd, NWZ_POWER_IS_FULLY_CHARGED, &status) < 0) | ||
473 | return -1; | ||
474 | return status; | ||
475 | } | ||
diff --git a/utils/nwztools/plattools/nwz_lib.h b/utils/nwztools/plattools/nwz_lib.h index 5c8ad3e50c..1dd7b4c85b 100644 --- a/utils/nwztools/plattools/nwz_lib.h +++ b/utils/nwztools/plattools/nwz_lib.h | |||
@@ -29,10 +29,13 @@ | |||
29 | #include <sys/wait.h> | 29 | #include <sys/wait.h> |
30 | #include <linux/input.h> | 30 | #include <linux/input.h> |
31 | #include <fcntl.h> | 31 | #include <fcntl.h> |
32 | #include <string.h> | ||
32 | 33 | ||
33 | #include "nwz_keys.h" | 34 | #include "nwz_keys.h" |
34 | #include "nwz_fb.h" | 35 | #include "nwz_fb.h" |
35 | #include "nwz_adc.h" | 36 | #include "nwz_adc.h" |
37 | #include "nwz_ts.h" | ||
38 | #include "nwz_power.h" | ||
36 | 39 | ||
37 | /* run a program and exit with nonzero status in case of error | 40 | /* run a program and exit with nonzero status in case of error |
38 | * argument list must be NULL terminated */ | 41 | * argument list must be NULL terminated */ |
@@ -81,4 +84,70 @@ const char *nwz_adc_get_name(int ch); | |||
81 | /* read channel value, return -1 on error */ | 84 | /* read channel value, return -1 on error */ |
82 | int nwz_adc_get_val(int fd, int ch); | 85 | int nwz_adc_get_val(int fd, int ch); |
83 | 86 | ||
87 | /* open touchscreen device */ | ||
88 | int nwz_ts_open(void); | ||
89 | /* close touchscreen device */ | ||
90 | void nwz_ts_close(int fd); | ||
91 | /* structure to track touch state */ | ||
92 | struct nwz_ts_state_t | ||
93 | { | ||
94 | int x, y; /* current position (valid is touch is true) */ | ||
95 | int max_x, max_y; /* maximum possible values */ | ||
96 | int pressure, tool_width; /* current pressure and tool width */ | ||
97 | int max_pressure, max_tool_width; /* maximum possible values */ | ||
98 | bool touch; /* is the user touching the screen? */ | ||
99 | bool flick; /* was the action a flick? */ | ||
100 | int flick_x, flick_y; /* if so, this is the flick direction */ | ||
101 | }; | ||
102 | /* get touchscreen information and init state, return -1 on error, 1 on success */ | ||
103 | int nwz_ts_state_init(int fd, struct nwz_ts_state_t *state); | ||
104 | /* update state with an event, return -1 on unhandled event, >=0 on handled: | ||
105 | * 1 if sync event, 0 otherwise */ | ||
106 | int nwz_ts_state_update(struct nwz_ts_state_t *state, struct input_event *evt); | ||
107 | /* update state after a sync event to prepare for next round of events */ | ||
108 | int nwz_ts_state_post_syn(struct nwz_ts_state_t *state); | ||
109 | /* read at most N events from touch screen, and return the number of events */ | ||
110 | int nwz_ts_read_events(int fd, struct input_event *evts, int nr_evts); | ||
111 | |||
112 | /* wait for events on several file descriptors, return a bitmap of active ones | ||
113 | * or 0 on timeout, the timeout can be -1 to block */ | ||
114 | long nwz_wait_fds(int *fds, int nr_fds, long timeout_us); | ||
115 | |||
116 | /* open power device */ | ||
117 | int nwz_power_open(void); | ||
118 | /* close power device */ | ||
119 | void nwz_power_close(int fd); | ||
120 | /* get power status (return -1 on error, bitmap on success) */ | ||
121 | int nwz_power_get_status(int fd); | ||
122 | /* get vbus adval (or -1 on error) */ | ||
123 | int nwz_power_get_vbus_adval(int fd); | ||
124 | /* get vbus voltage in mV (or -1 on error) */ | ||
125 | int nwz_power_get_vbus_voltage(int fd); | ||
126 | /* get vbus current limit (or -1 on error) */ | ||
127 | int nwz_power_get_vbus_limit(int fd); | ||
128 | /* get charge switch (or -1 on error) */ | ||
129 | int nwz_power_get_charge_switch(int fd); | ||
130 | /* get charge current (or -1 on error) */ | ||
131 | int nwz_power_get_charge_current(int fd); | ||
132 | /* get battery gauge (or -1 on error) */ | ||
133 | int nwz_power_get_battery_gauge(int fd); | ||
134 | /* get battery adval (or -1 on error) */ | ||
135 | int nwz_power_get_battery_adval(int fd); | ||
136 | /* get battery voltage in mV (or -1 on error) */ | ||
137 | int nwz_power_get_battery_voltage(int fd); | ||
138 | /* get vbat adval (or -1 on error) */ | ||
139 | int nwz_power_get_vbat_adval(int fd); | ||
140 | /* get vbat voltage (or -1 on error) */ | ||
141 | int nwz_power_get_vbat_voltage(int fd); | ||
142 | /* get sample count (or -1 on error) */ | ||
143 | int nwz_power_get_sample_count(int fd); | ||
144 | /* get vsys adval (or -1 on error) */ | ||
145 | int nwz_power_get_vsys_adval(int fd); | ||
146 | /* get vsys voltage in mV (or -1 on error) */ | ||
147 | int nwz_power_get_vsys_voltage(int fd); | ||
148 | /* get accessory charge mode */ | ||
149 | int nwz_power_get_acc_charge_mode(int fd); | ||
150 | /* is battery fully charged? (or -1 on error) */ | ||
151 | int nwz_power_is_fully_charged(int fd); | ||
152 | |||
84 | #endif /* _NWZLIB_H_ */ | 153 | #endif /* _NWZLIB_H_ */ |
diff --git a/utils/nwztools/plattools/nwz_power.h b/utils/nwztools/plattools/nwz_power.h new file mode 100644 index 0000000000..e8df47a3d6 --- /dev/null +++ b/utils/nwztools/plattools/nwz_power.h | |||
@@ -0,0 +1,82 @@ | |||
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_POWER_H__ | ||
22 | #define __NWZ_POWER_H__ | ||
23 | |||
24 | #define NWZ_POWER_DEV "/dev/icx_power" | ||
25 | |||
26 | #define NWZ_POWER_TYPE 'P' | ||
27 | |||
28 | /* ioctl request */ | ||
29 | #define NWZ_POWER_GET_STATUS _IOR(NWZ_POWER_TYPE, 0, int *) | ||
30 | #define NWZ_POWER_SET_VBUS_LIMIT _IOW(NWZ_POWER_TYPE, 1, int *) | ||
31 | #define NWZ_POWER_GET_BAT_ADVAL _IOR(NWZ_POWER_TYPE, 2, int *) | ||
32 | #define NWZ_POWER_GET_BAT_GAUGE _IOR(NWZ_POWER_TYPE, 3, int *) | ||
33 | #define NWZ_POWER_ENABLE_CHARGER _IOW(NWZ_POWER_TYPE, 4, int *) | ||
34 | #define NWZ_POWER_ENABLE_DEBUG_PORT _IO (NWZ_POWER_TYPE, 5) | ||
35 | #define NWZ_POWER_IS_FULLY_CHARGED _IOR(NWZ_POWER_TYPE, 6, int *) | ||
36 | #define NWZ_POWER_AVG_VALUE _IO (NWZ_POWER_TYPE, 7) | ||
37 | #define NWZ_POWER_CONSIDERATION_CHARGE _IOW(NWZ_POWER_TYPE, 8, int) | ||
38 | #define NWZ_POWER_GET_VBUS_LIMIT _IOR(NWZ_POWER_TYPE, 9, int *) | ||
39 | #define NWZ_POWER_GET_CHARGE_SWITCH _IOR(NWZ_POWER_TYPE,10, int *) | ||
40 | #define NWZ_POWER_GET_SAMPLE_COUNT _IOR(NWZ_POWER_TYPE,11, int *) | ||
41 | #define NWZ_POWER_SET_CHARGE_CURRENT _IOW(NWZ_POWER_TYPE,12, int *) | ||
42 | #define NWZ_POWER_GET_CHARGE_CURRENT _IOR(NWZ_POWER_TYPE,13, int *) | ||
43 | #define NWZ_POWER_GET_VBUS_ADVAL _IOR(NWZ_POWER_TYPE,14, int *) | ||
44 | #define NWZ_POWER_GET_VSYS_ADVAL _IOR(NWZ_POWER_TYPE,15, int *) | ||
45 | #define NWZ_POWER_GET_VBAT_ADVAL _IOR(NWZ_POWER_TYPE,16, int *) | ||
46 | #define NWZ_POWER_CHG_VBUS_LIMIT _IOW(NWZ_POWER_TYPE,17, int *) | ||
47 | #define NWZ_POWER_SET_ACCESSARY_CHARGE_MODE _IOW(NWZ_POWER_TYPE,18, int *) | ||
48 | #define NWZ_POWER_GET_ACCESSARY_CHARGE_MODE _IOR(NWZ_POWER_TYPE,19, int *) | ||
49 | |||
50 | /* NWZ_POWER_GET_STATUS bitmap */ | ||
51 | #define NWZ_POWER_STATUS_CHARGE_INIT 0x100 /* initializing charging */ | ||
52 | #define NWZ_POWER_STATUS_CHARGE_STATUS 0x0c0 /* charging status mask */ | ||
53 | #define NWZ_POWER_STATUS_VBUS_DET 0x020 /* vbus detected */ | ||
54 | #define NWZ_POWER_STATUS_AC_DET 0x010 /* ac adapter detected */ | ||
55 | #define NWZ_POWER_STATUS_CHARGE_LOW 0x001 /* full voltage of 4.1 instead of 4.2 */ | ||
56 | /* NWZ_POWER_STATUS_CHARGING_MASK value */ | ||
57 | #define NWZ_POWER_STATUS_CHARGE_STATUS_CHARGING 0xc0 | ||
58 | #define NWZ_POWER_STATUS_CHARGE_STATUS_SUSPEND 0x80 | ||
59 | #define NWZ_POWER_STATUS_CHARGE_STATUS_TIMEOUT 0x40 | ||
60 | #define NWZ_POWER_STATUS_CHARGE_STATUS_NORMAL 0x00 | ||
61 | |||
62 | /* base values to convert from adval to mV (represents mV for adval of 255) */ | ||
63 | #define NWZ_POWER_AD_BASE_VBAT 4664 | ||
64 | #define NWZ_POWER_AD_BASE_VBUS 7254 | ||
65 | #define NWZ_POWER_AD_BASE_VSYS 5700 | ||
66 | |||
67 | /* battery gauge */ | ||
68 | #define NWZ_POWER_BAT_NOBAT -100 /* no battery */ | ||
69 | #define NWZ_POWER_BAT_VERYLOW -99 /* very low */ | ||
70 | #define NWZ_POWER_BAT_LOW 0 /* low */ | ||
71 | #define NWZ_POWER_BAT_GAUGE0 1 /* ____ */ | ||
72 | #define NWZ_POWER_BAT_GAUGE1 2 /* O___ */ | ||
73 | #define NWZ_POWER_BAT_GAUGE2 3 /* OO__ */ | ||
74 | #define NWZ_POWER_BAT_GAUGE3 4 /* OOO_ */ | ||
75 | #define NWZ_POWER_BAT_GAUGE4 5 /* OOOO */ | ||
76 | |||
77 | /* NWZ_POWER_GET_ACCESSARY_CHARGE_MODE */ | ||
78 | #define NWZ_POWER_ACC_CHARGE_NONE 0 | ||
79 | #define NWZ_POWER_ACC_CHARGE_VBAT 1 | ||
80 | #define NWZ_POWER_ACC_CHARGE_VSYS 2 | ||
81 | |||
82 | #endif /* __NWZ_POWER_H__ */ | ||
diff --git a/utils/nwztools/plattools/nwz_ts.h b/utils/nwztools/plattools/nwz_ts.h new file mode 100644 index 0000000000..4528609ddc --- /dev/null +++ b/utils/nwztools/plattools/nwz_ts.h | |||
@@ -0,0 +1,35 @@ | |||
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_TS_H__ | ||
22 | #define __NWZ_TS_H__ | ||
23 | |||
24 | #define NWZ_TS_NAME "icx_touch_screen" | ||
25 | |||
26 | /* How touchscreen works: | ||
27 | * | ||
28 | * The touchscreen uses mostly the standard linux protocol, reporting ABS_X, | ||
29 | * ABS_Y, ABS_PRESSURE, TOOL_WIDTH and BTN_TOUCH with SYN to synchronize. The | ||
30 | * only nonstandard part is the use of REL_RX and REL_RY to report "flick" | ||
31 | * detection by the hardware. */ | ||
32 | |||
33 | #endif /* __NWZ_TS_H__ */ | ||
34 | |||
35 | |||
diff --git a/utils/nwztools/plattools/test_adc.c b/utils/nwztools/plattools/test_adc.c index 52eafd042d..52c0bffe1b 100644 --- a/utils/nwztools/plattools/test_adc.c +++ b/utils/nwztools/plattools/test_adc.c | |||
@@ -29,7 +29,7 @@ int main(int argc, char **argv) | |||
29 | int input_fd = nwz_key_open(); | 29 | int input_fd = nwz_key_open(); |
30 | if(input_fd < 0) | 30 | if(input_fd < 0) |
31 | { | 31 | { |
32 | nwz_lcdmsg(false, 3, 7, "Cannot open input device"); | 32 | nwz_lcdmsg(false, 3, 4, "Cannot open input device"); |
33 | sleep(2); | 33 | sleep(2); |
34 | return 1; | 34 | return 1; |
35 | } | 35 | } |
diff --git a/utils/nwztools/plattools/test_power.c b/utils/nwztools/plattools/test_power.c new file mode 100644 index 0000000000..c02f689b17 --- /dev/null +++ b/utils/nwztools/plattools/test_power.c | |||
@@ -0,0 +1,134 @@ | |||
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 | |||
23 | static const char *charge_status_name(int chgstat) | ||
24 | { | ||
25 | switch(chgstat) | ||
26 | { | ||
27 | case NWZ_POWER_STATUS_CHARGE_STATUS_CHARGING: return "charging"; | ||
28 | case NWZ_POWER_STATUS_CHARGE_STATUS_SUSPEND: return "suspend"; | ||
29 | case NWZ_POWER_STATUS_CHARGE_STATUS_TIMEOUT: return "timeout"; | ||
30 | case NWZ_POWER_STATUS_CHARGE_STATUS_NORMAL: return "normal"; | ||
31 | default: return "unknown"; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | static const char *get_batt_gauge_name(int gauge) | ||
36 | { | ||
37 | switch(gauge) | ||
38 | { | ||
39 | case NWZ_POWER_BAT_NOBAT: return "no batt"; | ||
40 | case NWZ_POWER_BAT_VERYLOW: return "very low"; | ||
41 | case NWZ_POWER_BAT_LOW: return "low"; | ||
42 | case NWZ_POWER_BAT_GAUGE0: return "____"; | ||
43 | case NWZ_POWER_BAT_GAUGE1: return "O___"; | ||
44 | case NWZ_POWER_BAT_GAUGE2: return "OO__"; | ||
45 | case NWZ_POWER_BAT_GAUGE3: return "OOO_"; | ||
46 | case NWZ_POWER_BAT_GAUGE4: return "OOOO"; | ||
47 | default: return "unknown"; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | static const char *acc_charge_mode_name(int mode) | ||
52 | { | ||
53 | switch(mode) | ||
54 | { | ||
55 | case NWZ_POWER_ACC_CHARGE_NONE: return "none"; | ||
56 | case NWZ_POWER_ACC_CHARGE_VBAT: return "vbat"; | ||
57 | case NWZ_POWER_ACC_CHARGE_VSYS: return "vsys"; | ||
58 | default: return "unknown"; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | int main(int argc, char **argv) | ||
63 | { | ||
64 | /* clear screen and display welcome message */ | ||
65 | nwz_lcdmsg(true, 0, 0, "test_power"); | ||
66 | nwz_lcdmsg(false, 0, 2, "PWR OFF: quit"); | ||
67 | /* open input device */ | ||
68 | int input_fd = nwz_key_open(); | ||
69 | if(input_fd < 0) | ||
70 | { | ||
71 | nwz_lcdmsg(false, 3, 4, "Cannot open input device"); | ||
72 | sleep(2); | ||
73 | return 1; | ||
74 | } | ||
75 | /* open adc device */ | ||
76 | int power_fd = nwz_power_open(); | ||
77 | if(power_fd < 0) | ||
78 | { | ||
79 | nwz_lcdmsg(false, 3, 4, "Cannot open power device"); | ||
80 | sleep(2); | ||
81 | return 1; | ||
82 | } | ||
83 | /* display input state in a loop */ | ||
84 | while(1) | ||
85 | { | ||
86 | /* print status */ | ||
87 | int line = 4; | ||
88 | int status = nwz_power_get_status(power_fd); | ||
89 | int chgstat = status & NWZ_POWER_STATUS_CHARGE_STATUS; | ||
90 | int acc_chg_mode = nwz_power_get_acc_charge_mode(power_fd); | ||
91 | nwz_lcdmsgf(false, 0, line++, "ac detected: %s ", | ||
92 | (status & NWZ_POWER_STATUS_AC_DET) ? "yes" : "no"); | ||
93 | nwz_lcdmsgf(false, 0, line++, "vbus detected: %s ", | ||
94 | (status & NWZ_POWER_STATUS_VBUS_DET) ? "yes" : "no"); | ||
95 | nwz_lcdmsgf(false, 0, line++, "vbus voltage: %d mV (AD=%d) ", | ||
96 | nwz_power_get_vbus_voltage(power_fd), nwz_power_get_vbus_adval(power_fd)); | ||
97 | nwz_lcdmsgf(false, 0, line++, "vbus limit: %d mA ", | ||
98 | nwz_power_get_vbus_limit(power_fd)); | ||
99 | nwz_lcdmsgf(false, 0, line++, "vsys voltage: %d mV (AD=%d) ", | ||
100 | nwz_power_get_vsys_voltage(power_fd), nwz_power_get_vsys_adval(power_fd)); | ||
101 | nwz_lcdmsgf(false, 0, line++, "charge switch: %s ", | ||
102 | nwz_power_get_charge_switch(power_fd) ? "on" : "off"); | ||
103 | nwz_lcdmsgf(false, 0, line++, "full voltage: %s V ", | ||
104 | (status & NWZ_POWER_STATUS_CHARGE_LOW) ? "4.1" : "4.2"); | ||
105 | nwz_lcdmsgf(false, 0, line++, "current limit: %d mA ", | ||
106 | nwz_power_get_charge_current(power_fd)); | ||
107 | nwz_lcdmsgf(false, 0, line++, "charge status: %s (%x) ", | ||
108 | charge_status_name(chgstat), chgstat); | ||
109 | nwz_lcdmsgf(false, 0, line++, "battery full: %s ", | ||
110 | nwz_power_is_fully_charged(power_fd) ? "yes" : "no"); | ||
111 | nwz_lcdmsgf(false, 0, line++, "bat gauge: %s (%d) ", | ||
112 | get_batt_gauge_name(nwz_power_get_battery_gauge(power_fd)), | ||
113 | nwz_power_get_battery_gauge(power_fd)); | ||
114 | nwz_lcdmsgf(false, 0, line++, "avg voltage: %d mV (AD=%d) ", | ||
115 | nwz_power_get_battery_voltage(power_fd), nwz_power_get_battery_adval(power_fd)); | ||
116 | nwz_lcdmsgf(false, 0, line++, "sample count: %d ", | ||
117 | nwz_power_get_sample_count(power_fd)); | ||
118 | nwz_lcdmsgf(false, 0, line++, "raw voltage: %d mV (AD=%d) ", | ||
119 | 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) ", | ||
121 | acc_charge_mode_name(acc_chg_mode), acc_chg_mode); | ||
122 | /* wait for event (1s) */ | ||
123 | int ret = nwz_key_wait_event(input_fd, 1000000); | ||
124 | if(ret != 1) | ||
125 | continue; | ||
126 | struct input_event evt; | ||
127 | if(nwz_key_read_event(input_fd, &evt) != 1) | ||
128 | continue; | ||
129 | if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && !nwz_key_event_is_press(&evt)) | ||
130 | break; | ||
131 | } | ||
132 | /* finish nicely */ | ||
133 | return 0; | ||
134 | } | ||
diff --git a/utils/nwztools/plattools/test_ts.c b/utils/nwztools/plattools/test_ts.c new file mode 100644 index 0000000000..73e729a093 --- /dev/null +++ b/utils/nwztools/plattools/test_ts.c | |||
@@ -0,0 +1,94 @@ | |||
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 | |||
23 | int main(int argc, char **argv) | ||
24 | { | ||
25 | /* clear screen and display welcome message */ | ||
26 | nwz_lcdmsg(true, 0, 0, "test_ts"); | ||
27 | nwz_lcdmsg(false, 0, 2, "PWR OFF: quit"); | ||
28 | /* open input device */ | ||
29 | int key_fd = nwz_key_open(); | ||
30 | if(key_fd < 0) | ||
31 | { | ||
32 | nwz_lcdmsg(false, 3, 4, "Cannot open key device"); | ||
33 | sleep(2); | ||
34 | return 1; | ||
35 | } | ||
36 | int ts_fd = nwz_ts_open(); | ||
37 | if(ts_fd < 0) | ||
38 | { | ||
39 | nwz_lcdmsg(false, 3, 4, "Cannot open touch screen device"); | ||
40 | sleep(2); | ||
41 | return 1; | ||
42 | } | ||
43 | /* init state and print maximum information */ | ||
44 | struct nwz_ts_state_t ts_state; | ||
45 | if(nwz_ts_state_init(ts_fd, &ts_state) < 0) | ||
46 | { | ||
47 | nwz_lcdmsg(false, 3, 4, "Cannot init touch screen device"); | ||
48 | sleep(2); | ||
49 | return 1; | ||
50 | } | ||
51 | /* display static information */ | ||
52 | nwz_lcdmsgf(false, 1, 6, "size: %d, %d ", ts_state.max_x, ts_state.max_y); | ||
53 | /* display input state in a loop */ | ||
54 | while(1) | ||
55 | { | ||
56 | /* wait for event */ | ||
57 | int fds[2] = {key_fd, ts_fd}; | ||
58 | int ret = nwz_wait_fds(fds, 2, -1); | ||
59 | if(ret & 1) /* key_fd */ | ||
60 | { | ||
61 | struct input_event evt; | ||
62 | if(nwz_key_read_event(key_fd, &evt) == 1) | ||
63 | { | ||
64 | if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && | ||
65 | nwz_key_event_is_press(&evt)) | ||
66 | break; /* quit */ | ||
67 | } | ||
68 | } | ||
69 | if(ret & 2) /* ts_fd */ | ||
70 | { | ||
71 | #define NR_TS_EVTS 16 | ||
72 | struct input_event evts[NR_TS_EVTS]; | ||
73 | int nr = nwz_ts_read_events(ts_fd, evts, NR_TS_EVTS); | ||
74 | for(int i = 0; i < nr; i++) | ||
75 | if(nwz_ts_state_update(&ts_state, &evts[i]) == 1) | ||
76 | { | ||
77 | nwz_lcdmsgf(false, 1, 7, "touch: %s ", ts_state.touch ? "yes" : "no"); | ||
78 | nwz_lcdmsgf(false, 1, 8, "pos: %d, %d ", ts_state.x, ts_state.y); | ||
79 | nwz_lcdmsgf(false, 1, 9, "pressure: %d ", ts_state.pressure); | ||
80 | nwz_lcdmsgf(false, 1, 10, "width: %d ", ts_state.tool_width); | ||
81 | nwz_lcdmsgf(false, 1, 11, "flick: %s ", ts_state.flick ? "yes" : "no"); | ||
82 | nwz_lcdmsgf(false, 1, 12, "flick vec: %d, %d ", ts_state.flick_x, ts_state.flick_y); | ||
83 | /* process touch */ | ||
84 | nwz_ts_state_post_syn(&ts_state); | ||
85 | } | ||
86 | #undef NR_TS_EVTS | ||
87 | } | ||
88 | } | ||
89 | /* close input device */ | ||
90 | nwz_key_close(key_fd); | ||
91 | nwz_ts_close(ts_fd); | ||
92 | /* finish nicely */ | ||
93 | return 0; | ||
94 | } | ||