1
0
Fork 0
forked from len0rd/rockbox

Cleanup of new button reading code. Moved functions for enabling of scanning and the decision to scan or not to button_read_device.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11377 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2006-10-28 23:10:45 +00:00
parent 56e75bee23
commit c4a0d45d36
6 changed files with 31 additions and 47 deletions

View file

@ -1072,7 +1072,7 @@ bool dbg_ports(void)
#ifdef IAUDIO_X5 #ifdef IAUDIO_X5
snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x", snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x",
adc_get_button_scan_enabled() ? '+' : '-', adc_buttons); button_scan_enabled() ? '+' : '-', adc_buttons);
lcd_puts(0, line++, buf); lcd_puts(0, line++, buf);
snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x", snprintf(buf, sizeof(buf), "ADC_REMOTE (%c): %02x",
remote_detect() ? '+' : '-', adc_remote); remote_detect() ? '+' : '-', adc_remote);

View file

@ -28,7 +28,5 @@
/* Force a scan now */ /* Force a scan now */
unsigned short adc_scan(int channel); unsigned short adc_scan(int channel);
void adc_enable_button_scan(bool enable);
bool adc_get_button_scan_enabled(void);
#endif /* _ADC_TARGET_H_ */ #endif /* _ADC_TARGET_H_ */

View file

@ -33,37 +33,11 @@ static const int adcc2_parms[] =
[ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */
}; };
/* have buttons scan by default */
static volatile bool button_scan_on = true;
void adc_enable_button_scan(bool enable)
{
button_scan_on = enable;
}
bool adc_get_button_scan_enabled(void)
{
return button_scan_on;
}
unsigned short adc_scan(int channel) unsigned short adc_scan(int channel)
{ {
int level; int level;
unsigned char data; unsigned char data;
if (channel == ADC_BUTTONS)
{
/* no button scan if nothing pushed */
if (!button_scan_on)
return adcdata[channel] = 0xff;
}
else if (channel == ADC_REMOTE)
{
/* no remote scan if not plugged */
if (GPIO_READ & 0x01000000)
return adcdata[channel] = 0xff;
}
level = set_irq_level(HIGHEST_IRQ_LEVEL); level = set_irq_level(HIGHEST_IRQ_LEVEL);
pcf50606_write(0x2f, adcc2_parms[channel]); pcf50606_write(0x2f, adcc2_parms[channel]);

View file

@ -29,6 +29,8 @@ bool button_hold(void);
bool remote_button_hold(void); bool remote_button_hold(void);
void button_init_device(void); void button_init_device(void);
int button_read_device(void); int button_read_device(void);
void button_enable_scan(bool enable);
bool button_scan_enabled(void);
/* iaudio X5 specific button codes */ /* iaudio X5 specific button codes */

View file

@ -16,16 +16,17 @@
* KIND, either express or implied. * KIND, either express or implied.
* *
****************************************************************************/ ****************************************************************************/
#include <stdlib.h>
#include "config.h" #include "config.h"
#include "cpu.h"
#include "system.h" #include "system.h"
#include "button.h" #include "button.h"
#include "kernel.h"
#include "backlight.h" #include "backlight.h"
#include "adc.h" #include "adc.h"
#include "system.h" #include "lcd-remote-target.h"
/* have buttons scan by default */
static bool button_scan_on = true;
static bool hold_button = false;
static bool remote_hold_button = false;
void button_init_device(void) void button_init_device(void)
{ {
@ -34,24 +35,32 @@ void button_init_device(void)
GPIO_ENABLE &= ~0x0e000000; GPIO_ENABLE &= ~0x0e000000;
} }
void button_enable_scan(bool enable)
{
button_scan_on = enable;
}
bool button_scan_enabled(void)
{
return button_scan_on;
}
bool button_hold(void) bool button_hold(void)
{ {
return (GPIO_READ & 0x08000000)?false:true; return (GPIO_READ & 0x08000000) == 0;
} }
bool remote_button_hold(void) bool remote_button_hold(void)
{ {
return adc_scan(ADC_REMOTE) < 0x17; return remote_hold_button;
} }
int button_read_device(void) int button_read_device(void)
{ {
int data; int btn = BUTTON_NONE;
int btn = BUTTON_NONE;
static bool hold_button = false;
static bool remote_hold_button = false;
bool hold_button_old; bool hold_button_old;
bool remote_hold_button_old; bool remote_hold_button_old;
int data;
/* normal buttons */ /* normal buttons */
hold_button_old = hold_button; hold_button_old = hold_button;
@ -63,9 +72,10 @@ int button_read_device(void)
backlight_hold_changed(hold_button); backlight_hold_changed(hold_button);
#endif #endif
if (!hold_button) if (button_scan_on && !hold_button)
{ {
data = adc_scan(ADC_BUTTONS); data = adc_scan(ADC_BUTTONS);
if (data < 0xf0) if (data < 0xf0)
{ {
if(data < 0x7c) if(data < 0x7c)
@ -91,9 +101,9 @@ int button_read_device(void)
} }
/* remote buttons */ /* remote buttons */
remote_hold_button_old = remote_hold_button; data = remote_detect() ? adc_scan(ADC_REMOTE) : 0xff;
data = adc_scan(ADC_REMOTE); remote_hold_button_old = remote_hold_button;
remote_hold_button = data < 0x17; remote_hold_button = data < 0x17;
#ifndef BOOTLOADER #ifndef BOOTLOADER
@ -101,7 +111,7 @@ int button_read_device(void)
remote_backlight_hold_changed(remote_hold_button); remote_backlight_hold_changed(remote_hold_button);
#endif #endif
if(!remote_hold_button) if (!remote_hold_button)
{ {
if (data < 0xee) if (data < 0xee)
{ {

View file

@ -20,7 +20,7 @@
#include "system.h" #include "system.h"
#include "kernel.h" #include "kernel.h"
#include "pcf50606.h" #include "pcf50606.h"
#include "adc.h" #include "button-target.h"
#include "powermgmt.h" #include "powermgmt.h"
/* These voltages were determined by measuring the output of the PCF50606 /* These voltages were determined by measuring the output of the PCF50606
@ -130,7 +130,7 @@ void GPI0(void)
/* ACDINS/ACDREM */ /* ACDINS/ACDREM */
/* Check if adc_scan should actually scan main buttons or not - /* Check if adc_scan should actually scan main buttons or not -
bias towards "yes" out of paranoia. */ bias towards "yes" out of paranoia. */
adc_enable_button_scan((data[2] & 0x02) != 0 || button_enable_scan((data[2] & 0x02) != 0 ||
(pcf50606_read(0x33) & 0x01) != 0); (pcf50606_read(0x33) & 0x01) != 0);
} }
} }