Moved archos USB handling to target tree. Minor simplification for coldfire (only one usb-target.h).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13110 a1c6a512-1295-4272-9138-f99709370657
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 9f90919..a053141 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -318,6 +318,7 @@
target/sh/archos/player/button-player.c
target/sh/archos/player/lcd-as-player.S
target/sh/archos/player/lcd-player.c
+target/sh/archos/player/usb-player.c
#endif /* SIMULATOR */
#endif /* ARCHOS_PLAYER */
@@ -328,6 +329,7 @@
target/sh/archos/lcd-archos-bitmap.c
target/sh/archos/lcd-as-archos-bitmap.S
target/sh/archos/recorder/button-recorder.c
+target/sh/archos/recorder/usb-recorder.c
#endif /* SIMULATOR */
#endif /* ARCHOS_RECORDER */
@@ -338,6 +340,7 @@
target/sh/archos/lcd-archos-bitmap.c
target/sh/archos/lcd-as-archos-bitmap.S
target/sh/archos/fm_v2/button-fm_v2.c
+target/sh/archos/fm_v2/usb-fm_v2.c
#endif /* SIMULATOR */
#endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */
@@ -346,6 +349,7 @@
target/sh/archos/lcd-archos-bitmap.c
target/sh/archos/lcd-as-archos-bitmap.S
target/sh/archos/ondio/button-ondio.c
+target/sh/archos/ondio/usb-ondio.c
#endif /* SIMULATOR */
#endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */
diff --git a/firmware/target/coldfire/iaudio/usb-target.h b/firmware/target/coldfire/usb-target.h
similarity index 100%
rename from firmware/target/coldfire/iaudio/usb-target.h
rename to firmware/target/coldfire/usb-target.h
diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
similarity index 61%
copy from firmware/target/coldfire/iriver/usb-target.h
copy to firmware/target/sh/archos/fm_v2/usb-fm_v2.c
index ab8cac6..2b4632e 100644
--- a/firmware/target/coldfire/iriver/usb-target.h
+++ b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Linus Nielsen Feltzing
+ * Copyright (C) 2007 by Jens Arnold
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@@ -16,9 +16,31 @@
* KIND, either express or implied.
*
****************************************************************************/
-#ifndef USB_TARGET_H
-#define USB_TARGET_H
+#include "config.h"
+#include <stdbool.h>
+#include "adc.h"
+#include "cpu.h"
+#include "hwcompat.h"
+#include "system.h"
-bool usb_init_device(void);
+bool usb_detect(void)
+{
+ return (adc_read(ADC_USB_POWER) <= 512) ? true : false;
+}
-#endif
+void usb_enable(bool on)
+{
+ if(read_hw_mask() & USB_ACTIVE_HIGH)
+ on = !on;
+
+ if(on)
+ and_b(~0x04, &PADRH); /* enable USB */
+ else
+ or_b(0x04, &PADRH);
+}
+
+void usb_init_device(void)
+{
+ usb_enable(false);
+ or_b(0x04, &PAIORH);
+}
diff --git a/firmware/target/sh/archos/ondio/usb-ondio.c b/firmware/target/sh/archos/ondio/usb-ondio.c
new file mode 100644
index 0000000..7c09bf3
--- /dev/null
+++ b/firmware/target/sh/archos/ondio/usb-ondio.c
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2007 by Jens Arnold
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include <stdbool.h>
+#include "adc.h"
+#include "ata_mmc.h"
+#include "cpu.h"
+#include "hwcompat.h"
+#include "system.h"
+
+bool usb_detect(void)
+{
+ return (adc_read(ADC_USB_POWER) <= 512) ? true : false;
+}
+
+void usb_enable(bool on)
+{
+ if (on)
+ {
+ mmc_enable_int_flash_clock(!mmc_detect());
+
+ if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
+ and_b(~0x20, &PBDRH); /* old circuit needs SCK1 = low while on USB */
+ or_b(0x20, &PADRL); /* enable USB */
+ and_b(~0x08, &PADRL); /* assert card detect */
+ }
+ else
+ {
+ if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
+ or_b(0x20, &PBDRH); /* reset SCK1 = high for old circuit */
+ and_b(~0x20, &PADRL); /* disable USB */
+ or_b(0x08, &PADRL); /* deassert card detect */
+ }
+}
+
+void usb_init_device(void)
+{
+ PACR2 &= ~0x04C0; /* use PA3 (card detect) and PA5 (USB enabled) as GPIO */
+ and_b(~0x20, &PADRL); /* disable USB */
+ or_b(0x08, &PADRL); /* deassert card detect */
+ or_b(0x28, &PAIORL); /* output for USB enable and card detect */
+}
diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/sh/archos/player/usb-player.c
similarity index 68%
copy from firmware/target/coldfire/iriver/usb-target.h
copy to firmware/target/sh/archos/player/usb-player.c
index ab8cac6..c10e222 100644
--- a/firmware/target/coldfire/iriver/usb-target.h
+++ b/firmware/target/sh/archos/player/usb-player.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Linus Nielsen Feltzing
+ * Copyright (C) 2007 by Jens Arnold
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@@ -16,9 +16,26 @@
* KIND, either express or implied.
*
****************************************************************************/
-#ifndef USB_TARGET_H
-#define USB_TARGET_H
+#include "config.h"
+#include <stdbool.h>
+#include "cpu.h"
+#include "system.h"
-bool usb_init_device(void);
+bool usb_detect(void)
+{
+ return (PADR & 0x8000) ? false : true;
+}
-#endif
+void usb_enable(bool on)
+{
+ if(on)
+ and_b(~0x04, &PADRH);
+ else
+ or_b(0x04, &PADRH);
+}
+
+void usb_init_device(void)
+{
+ or_b(0x04, &PADRH);
+ or_b(0x04, &PAIORH);
+}
diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/sh/archos/recorder/usb-recorder.c
similarity index 61%
copy from firmware/target/coldfire/iriver/usb-target.h
copy to firmware/target/sh/archos/recorder/usb-recorder.c
index ab8cac6..2934b32 100644
--- a/firmware/target/coldfire/iriver/usb-target.h
+++ b/firmware/target/sh/archos/recorder/usb-recorder.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Linus Nielsen Feltzing
+ * Copyright (C) 2007 by Jens Arnold
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@@ -16,9 +16,31 @@
* KIND, either express or implied.
*
****************************************************************************/
-#ifndef USB_TARGET_H
-#define USB_TARGET_H
+#include "config.h"
+#include <stdbool.h>
+#include "adc.h"
+#include "cpu.h"
+#include "hwcompat.h"
+#include "system.h"
-bool usb_init_device(void);
+bool usb_detect(void)
+{
+ return (adc_read(ADC_USB_POWER) > 500) ? true : false;
+}
-#endif
+void usb_enable(bool on)
+{
+ if(read_hw_mask() & USB_ACTIVE_HIGH)
+ on = !on;
+
+ if(on)
+ and_b(~0x04, &PADRH); /* enable USB */
+ else
+ or_b(0x04, &PADRH);
+}
+
+void usb_init_device(void)
+{
+ usb_enable(false);
+ or_b(0x04, &PAIORH);
+}
diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/sh/usb-target.h
similarity index 94%
rename from firmware/target/coldfire/iriver/usb-target.h
rename to firmware/target/sh/usb-target.h
index ab8cac6..65fa31f 100644
--- a/firmware/target/coldfire/iriver/usb-target.h
+++ b/firmware/target/sh/usb-target.h
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Linus Nielsen Feltzing
+ * Copyright (C) 2007 by Jens Arnold
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
diff --git a/firmware/usb.c b/firmware/usb.c
index 13adc3b..217aaf8 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -32,18 +32,11 @@
#include "disk.h"
#include "panic.h"
#include "lcd.h"
-#include "adc.h"
#include "usb.h"
#include "button.h"
#include "sprintf.h"
#include "string.h"
-#include "hwcompat.h"
-#ifdef HAVE_MMC
-#include "ata_mmc.h"
-#endif
-#ifdef TARGET_TREE
#include "usb-target.h"
-#endif
#ifdef IRIVER_H300_SERIES
#include "pcf50606.h" /* for pcf50606_usb_charging_... */
#endif
@@ -56,8 +49,6 @@
void screen_dump(void); /* Nasty again. Defined in apps/ too */
#endif
-#define USB_REALLY_BRAVE
-
#if !defined(SIMULATOR) && !defined(USB_NONE)
/* Messages from usb_tick and thread states */
@@ -93,10 +84,7 @@
#endif
#endif /* HAVE_USB_POWER */
-/* The ADC tick reads one channel per tick, and we want to check 3 successive
- readings on the USB voltage channel. This doesn't apply to the Player, but
- debouncing the USB detection port won't hurt us either. */
-#define NUM_POLL_READINGS (NUM_ADC_CHANNELS * 3)
+#define NUM_POLL_READINGS (HZ/5)
static int countdown;
static int usb_state;
@@ -115,46 +103,6 @@
static bool last_usb_status;
static bool usb_monitor_enabled;
-#ifndef TARGET_TREE
-void usb_enable(bool on)
-{
-#ifdef USB_ENABLE_ONDIOSTYLE
- PACR2 &= ~0x04C0; /* use PA3, PA5 as GPIO */
- if(on)
- {
-#ifdef HAVE_MMC
- mmc_enable_int_flash_clock(!mmc_detect());
-#endif
- if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
- and_b(~0x20, &PBDRH); /* old circuit needs SCK1 = low while on USB */
- or_b(0x20, &PADRL); /* enable USB */
- and_b(~0x08, &PADRL); /* assert card detect */
- }
- else
- {
- if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
- or_b(0x20, &PBDRH); /* reset SCK1 = high for old circuit */
- and_b(~0x20, &PADRL); /* disable USB */
- or_b(0x08, &PADRL); /* deassert card detect */
- }
- or_b(0x28, &PAIORL); /* output for USB enable and card detect */
-#else
-#ifdef HAVE_LCD_BITMAP
- if(read_hw_mask() & USB_ACTIVE_HIGH)
- on = !on;
-#endif
- if(on)
- {
- and_b(~0x04, &PADRH); /* enable USB */
- }
- else
- {
- or_b(0x04, &PADRH);
- }
- or_b(0x04, &PAIORH);
-#endif
-}
-#endif
#ifndef BOOTLOADER
static void usb_slave_mode(bool on)
@@ -246,13 +194,9 @@
if(num_acks_to_expect == 0)
{
DEBUGF("All threads have acknowledged the connect.\n");
-#ifdef USB_REALLY_BRAVE
usb_slave_mode(true);
usb_state = USB_INSERTED;
cpu_idle_mode(true);
-#else
- system_reboot();
-#endif
}
else
{
@@ -330,23 +274,6 @@
}
#endif
-#ifndef TARGET_TREE
-bool usb_detect(void)
-{
- bool current_status;
-
-#ifdef USB_RECORDERSTYLE
- current_status = (adc_read(ADC_USB_POWER) > 500)?true:false;
-#endif
-#ifdef USB_FMRECORDERSTYLE
- current_status = (adc_read(ADC_USB_POWER) <= 512)?true:false;
-#endif
-#ifdef USB_PLAYERSTYLE
- current_status = (PADR & 0x8000)?false:true;
-#endif
- return current_status;
-}
-#endif
#ifndef BOOTLOADER
static void usb_tick(void)
@@ -402,10 +329,7 @@
usb_monitor_enabled = false;
countdown = -1;
-#ifdef TARGET_TREE
usb_init_device();
-#endif
-
usb_enable(false);
/* We assume that the USB cable is extracted */