1
0
Fork 0
forked from len0rd/rockbox

nwztools/plattools: add adc test

Change-Id: Ic3ef964e8b5cc7b8ca3f02f141e9e4436a4d41db
This commit is contained in:
Amaury Pouly 2016-10-19 18:19:57 +02:00
parent 8d24b62912
commit 0b01ca69e0
6 changed files with 213 additions and 2 deletions

View file

@ -0,0 +1,42 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2016 Amaury Pouly
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __NWZ_ADC_H__
#define __NWZ_ADC_H__
#define NWZ_ADC_DEV "/dev/icx_adc"
#define NWZ_ADC_TYPE 'm'
#define NWZ_ADC_MIN_CHAN 0
#define NWZ_ADC_MAX_CHAN 7
#define NWZ_ADC_VCCBAT 0
#define NWZ_ADC_VCCVBUS 1
#define NWZ_ADC_ADIN3 2
#define NWZ_ADC_ADIN4 3
#define NWZ_ADC_ADIN5 4
#define NWZ_ADC_ADIN6 5
#define NWZ_ADC_ADIN7 6
#define NWZ_ADC_ADIN8 7
#define NWZ_ADC_GET_VAL(chan) _IOR(NWZ_ADC_TYPE, chan, unsigned char)
#endif /* __NWZ_ADC_H__ */

View file

@ -0,0 +1,56 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2016 Amaury Pouly
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef __NWZ_FB_H__
#define __NWZ_FB_H__
#define NWZ_FB_LCD_DEV "/dev/fb/0"
#define NWZ_FB_TV_DEV "/dev/fb/1"
#define NWZ_FB_TYPE 'N'
/* How backlight works:
*
* The brightness interface is a bit strange. There 6 levels: 0 throught 5.
* Level 0 means backlight off. When changing brightness, one sets level to the
* target brightness. The driver is gradually change the brightness to reach the
* target level. The step parameters control how many hardware steps will be done.
* For example, setting step to 1 will brutally change the level in one step.
* Setting step to 2 will change brightness in two steps: one intermediate and
* finally the target one. The more steps, the more gradual the transition. The
* period parameters controls the speed to changes between steps. Using this
* interface, one can achieve fade in/out at various speeds. */
#define NWZ_FB_BL_MIN_LEVEL 0
#define NWZ_FB_BL_MAX_LEVEL 5
#define NWZ_FB_BL_MIN_STEP 1
#define NWZ_FB_BL_MAX_STEP 100
#define NWZ_FB_BL_MIN_PERIOD 10
struct nwz_fb_brightness
{
int level; /* brightness level: 0-5 */
int step; /* number of hardware steps to do when changing: 1-100 */
int period; /* period in ms between steps when changing: >=10 */
};
#define NWZ_FB_SET_BRIGHTNESS _IOW(NWZ_FB_TYPE, 0x07, struct nwz_fb_brightness)
#define NWZ_FB_GET_BRIGHTNESS _IOR(NWZ_FB_TYPE, 0x08, struct nwz_fb_brightness)
#endif /* __NWZ_FB_H__ */

View file

@ -21,6 +21,8 @@
#ifndef __NWZ_KEYS_H__
#define __NWZ_KEYS_H__
#define NWZ_KEY_DEV "/dev/input/event0"
/* The Sony icx_key driver reports keys via the /dev/input/event0 device and
* abuses the standard struct input_event. The input_event.code is split into
* two parts:

View file

@ -71,7 +71,7 @@ void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...)
int nwz_key_open(void)
{
return open("/dev/input/event0", O_RDONLY);
return open(NWZ_KEY_DEV, O_RDONLY);
}
void nwz_key_close(int fd)
@ -160,7 +160,7 @@ const char *nwz_key_get_name(int keycode)
int nwz_fb_open(bool lcd)
{
return open(lcd ? "/dev/fb/0" : "/dev/fb/1", O_RDWR);
return open(lcd ? NWZ_FB_LCD_DEV : NWZ_FB_TV_DEV, O_RDWR);
}
void nwz_fb_close(int fd)
@ -183,3 +183,39 @@ int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl)
else
return 1;
}
int nwz_adc_open(void)
{
return open(NWZ_ADC_DEV, O_RDONLY);
}
void nwz_adc_close(int fd)
{
close(fd);
}
static const char *nwz_adc_name[] =
{
[NWZ_ADC_VCCBAT] = "VCCBAT",
[NWZ_ADC_VCCVBUS] = "VCCVBUS",
[NWZ_ADC_ADIN3] = "ADIN3",
[NWZ_ADC_ADIN4] = "ADIN4",
[NWZ_ADC_ADIN5] = "ADIN5",
[NWZ_ADC_ADIN6] = "ADIN6",
[NWZ_ADC_ADIN7] = "ADIN7",
[NWZ_ADC_ADIN8] = "ADIN8",
};
const char *nwz_adc_get_name(int ch)
{
return nwz_adc_name[ch];
}
int nwz_adc_get_val(int fd, int ch)
{
unsigned char val;
if(ioctl(fd, NWZ_ADC_GET_VAL(ch), &val) < 0)
return -1;
else
return val;
}

View file

@ -32,6 +32,7 @@
#include "nwz_keys.h"
#include "nwz_fb.h"
#include "nwz_adc.h"
/* run a program and exit with nonzero status in case of error
* argument list must be NULL terminated */
@ -61,6 +62,7 @@ bool nwz_key_event_is_press(struct input_event *evt);
bool nwz_key_event_get_hold_status(struct input_event *evt);
/* get keycode name */
const char *nwz_key_get_name(int keycode);
/* open framebuffer device */
int nwz_fb_open(bool lcd);
/* close framebuffer device */
@ -70,4 +72,13 @@ int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl);
/* set backlight brightness (return -1 on error, 1 on success) */
int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl);
/* open adc device */
int nwz_adc_open(void);
/* close adc device */
void nwz_adc_close(int fd);
/* get channel name */
const char *nwz_adc_get_name(int ch);
/* read channel value, return -1 on error */
int nwz_adc_get_val(int fd, int ch);
#endif /* _NWZLIB_H_ */

View file

@ -0,0 +1,64 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2016 Amaury Pouly
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "nwz_lib.h"
int main(int argc, char **argv)
{
/* clear screen and display welcome message */
nwz_lcdmsg(true, 0, 0, "test_adc");
nwz_lcdmsg(false, 0, 2, "PWR OFF: quit");
/* open input device */
int input_fd = nwz_key_open();
if(input_fd < 0)
{
nwz_lcdmsg(false, 3, 7, "Cannot open input device");
sleep(2);
return 1;
}
/* open adc device */
int adc_fd = nwz_adc_open();
if(adc_fd < 0)
{
nwz_lcdmsg(false, 3, 4, "Cannot open adc device");
sleep(2);
return 1;
}
/* display input state in a loop */
while(1)
{
/* print channels */
for(int i = NWZ_ADC_MIN_CHAN; i <= NWZ_ADC_MAX_CHAN; i++)
nwz_lcdmsgf(false, 1, 4 + i, "%s: %d ", nwz_adc_get_name(i),
nwz_adc_get_val(adc_fd, i));
/* wait for event (10ms) */
int ret = nwz_key_wait_event(input_fd, 10000);
if(ret != 1)
continue;
struct input_event evt;
if(nwz_key_read_event(input_fd, &evt) != 1)
continue;
if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && !nwz_key_event_is_press(&evt))
break;
}
/* finish nicely */
return 0;
}