From d7b4645f5c7274660c9a020f172ac54f546686b5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 15:11:29 +0000 Subject: Ludovic Lange's initial code for FM Recorder, edited and adjusted by me. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3110 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/adc.h | 4 ++++ firmware/drivers/button.c | 36 +++++++++++++++++++++++++++++++++--- firmware/drivers/power.c | 6 +++++- 3 files changed, 42 insertions(+), 4 deletions(-) (limited to 'firmware/drivers') diff --git a/firmware/drivers/adc.h b/firmware/drivers/adc.h index 0c05f4d0f8..9c90cb08a7 100644 --- a/firmware/drivers/adc.h +++ b/firmware/drivers/adc.h @@ -23,8 +23,12 @@ #define ADC_BATTERY 0 /* Battery voltage always reads 0x3FF due to silly scaling */ +#ifdef HAVE_FMADC +#define ADC_CHARGE_REGULATOR 0 /* Uh, we read the battery voltage? */ +#else #define ADC_CHARGE_REGULATOR 1 /* Regulator reference voltage, should read about 0x1c0 when charging, else 0x3FF */ +#endif #define ADC_USB_POWER 2 /* USB, reads 0x3FF when USB is inserted */ #define ADC_BUTTON_ROW1 4 /* Used for scanning the keys, different diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index ea3ffadffd..ebf606ac25 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -191,10 +191,19 @@ int button_get_w_tmo(int ticks) * DOWN, PLAY, LEFT, and RIGHT are likewise connected to AN5. */ /* Button analog voltage levels */ +#ifdef HAVE_FMADC +/* FM Recorder super-special levels */ +#define LEVEL1 150 +#define LEVEL2 385 +#define LEVEL3 545 +#define LEVEL4 700 +#else +/* plain bog standard Recorder levels */ #define LEVEL1 250 #define LEVEL2 500 #define LEVEL3 700 #define LEVEL4 900 +#endif /* *Initialize buttons @@ -219,11 +228,22 @@ static int button_read(void) int btn = BUTTON_NONE; /* Check port B pins for ON and OFF */ - int data = PBDR; + int data; + +#ifdef HAVE_FMADC + /* TODO: use proper defines here, and not the numerics in the + function argument */ + if ( adc_read(3) < 512 ) + btn |= BUTTON_ON; + if ( adc_read(2) > 512 ) + btn |= BUTTON_OFF; +#else + data = PBDR; if ((data & PBDR_BTN_ON) == 0) btn |= BUTTON_ON; else if ((data & PBDR_BTN_OFF) == 0) btn |= BUTTON_OFF; +#endif /* Check F1-3 and UP */ data = adc_read(ADC_BUTTON_ROW1); @@ -245,12 +265,22 @@ static int button_read(void) data = adc_read(ADC_BUTTON_ROW2); if (data >= LEVEL4) btn |= BUTTON_DOWN; - else if (data >= LEVEL3) + else if (data >= LEVEL3) { +#ifdef HAVE_FMADC + btn |= BUTTON_RIGHT; +#else btn |= BUTTON_PLAY; +#endif + } else if (data >= LEVEL2) btn |= BUTTON_LEFT; - else if (data >= LEVEL1) + else if (data >= LEVEL1) { +#ifdef HAVE_FMADC + btn |= BUTTON_PLAY; +#else btn |= BUTTON_RIGHT; +#endif + } } return btn; diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index b61090ff26..bb0ec80942 100644 --- a/firmware/drivers/power.c +++ b/firmware/drivers/power.c @@ -31,8 +31,12 @@ bool charger_enabled = 0; bool charger_inserted(void) { -#ifdef ARCHOS_RECORDER +#ifdef HAVE_CHARGE_CTRL +#ifdef HAVE_FMADC + return adc_read(ADC_CHARGE_REGULATOR) < 0x1FF; +#else return adc_read(ADC_EXT_POWER) > 0x100; +#endif #else return (PADR & 1) == 0; #endif -- cgit v1.2.3