summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-09-04 08:03:07 +0000
committerDave Chapman <dave@dchapman.com>2007-09-04 08:03:07 +0000
commit1672350378c1eb218db319e35e7bf8fa457b1142 (patch)
treeccffc78a046ce73aa8f49784d5b2a2d26a2bc4d6 /firmware
parent946a815cd4166f8761fac0c9cba0092b871cf900 (diff)
downloadrockbox-1672350378c1eb218db319e35e7bf8fa457b1142.tar.gz
rockbox-1672350378c1eb218db319e35e7bf8fa457b1142.zip
FS #7691 - improved USB detection on PP devices. This patch modifies the target-tree function usb_detect() on all targets from bool to int, returning USB_INSERTED or USB_EXTRACTED instead of true or false. This was done to enable the PP usb_detect() to check for USB_POWER (either a connection to a USB wall charger, or the user holding "charge mode" button) and return that as a third value.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14600 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/usb.h37
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c4
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c8
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h1
-rw-r--r--firmware/target/arm/usb-fw-pp5002.c6
-rw-r--r--firmware/target/arm/usb-fw-pp502x.c88
-rw-r--r--firmware/target/coldfire/iaudio/usb-iaudio.c5
-rw-r--r--firmware/target/coldfire/iriver/h100/usb-h100.c5
-rw-r--r--firmware/target/coldfire/iriver/h300/usb-h300.c5
-rw-r--r--firmware/target/sh/archos/fm_v2/usb-fm_v2.c5
-rw-r--r--firmware/target/sh/archos/ondio/usb-ondio.c5
-rw-r--r--firmware/target/sh/archos/player/usb-player.c5
-rw-r--r--firmware/target/sh/archos/recorder/usb-recorder.c5
-rw-r--r--firmware/usb.c51
14 files changed, 145 insertions, 85 deletions
diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index 622db35543..82b9d36d4a 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -20,6 +20,41 @@
20#define _USB_H_ 20#define _USB_H_
21 21
22#include "kernel.h" 22#include "kernel.h"
23#include "button.h"
24
25/* Messages from usb_tick and thread states */
26#define USB_INSERTED 1
27#define USB_EXTRACTED 2
28#ifdef HAVE_MMC
29#define USB_REENABLE 3
30#endif
31
32#ifdef HAVE_USB_POWER
33#define USB_POWERED 4
34
35#if CONFIG_KEYPAD == RECORDER_PAD
36#define USBPOWER_BUTTON BUTTON_F1
37#define USBPOWER_BTN_IGNORE BUTTON_ON
38#elif CONFIG_KEYPAD == ONDIO_PAD
39#define USBPOWER_BUTTON BUTTON_MENU
40#define USBPOWER_BTN_IGNORE BUTTON_OFF
41#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
42#define USBPOWER_BUTTON BUTTON_MENU
43#define USBPOWER_BTN_IGNORE BUTTON_PLAY
44#elif CONFIG_KEYPAD == IRIVER_H300_PAD
45#define USBPOWER_BUTTON BUTTON_REC
46#define USBPOWER_BTN_IGNORE BUTTON_ON
47#elif CONFIG_KEYPAD == GIGABEAT_PAD
48#define USBPOWER_BUTTON BUTTON_MENU
49#define USBPOWER_BTN_IGNORE BUTTON_POWER
50#elif CONFIG_KEYPAD == IRIVER_H10_PAD
51#define USBPOWER_BUTTON BUTTON_NONE
52#define USBPOWER_BTN_IGNORE BUTTON_POWER
53#elif CONFIG_KEYPAD == SANSA_E200_PAD
54#define USBPOWER_BUTTON BUTTON_SELECT
55#define USBPOWER_BTN_IGNORE BUTTON_POWER
56#endif
57#endif /* HAVE_USB_POWER */
23 58
24void usb_init(void); 59void usb_init(void);
25void usb_enable(bool on); 60void usb_enable(bool on);
@@ -28,7 +63,7 @@ void usb_acknowledge(long id);
28void usb_wait_for_disconnect(struct event_queue *q); 63void usb_wait_for_disconnect(struct event_queue *q);
29int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks); 64int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks);
30bool usb_inserted(void); /* return the official value, what's been reported to the threads */ 65bool usb_inserted(void); /* return the official value, what's been reported to the threads */
31bool usb_detect(void); /* return the raw hardware value */ 66int usb_detect(void); /* return the raw hardware value - nothing/pc/charger */
32#ifdef HAVE_USB_POWER 67#ifdef HAVE_USB_POWER
33bool usb_powered(void); 68bool usb_powered(void);
34#ifdef CONFIG_CHARGING 69#ifdef CONFIG_CHARGING
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
index a22a227b15..3761c84a50 100644
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
+++ b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
@@ -37,10 +37,10 @@ void usb_init_device(void)
37{ 37{
38} 38}
39 39
40bool usb_detect(void) 40int usb_detect(void)
41{ 41{
42 /* TODO: Implement USB_ISP1582 */ 42 /* TODO: Implement USB_ISP1582 */
43 return false; 43 return USB_EXTRACTED;
44} 44}
45 45
46void usb_enable(bool on) 46void usb_enable(bool on)
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
index 566d25eecb..217a7d3cef 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
@@ -21,6 +21,7 @@
21#include "system.h" 21#include "system.h"
22#include "kernel.h" 22#include "kernel.h"
23#include "ata.h" 23#include "ata.h"
24#include "usb.h"
24 25
25#define USB_RST_ASSERT GPBDAT &= ~(1 << 4) 26#define USB_RST_ASSERT GPBDAT &= ~(1 << 4)
26#define USB_RST_DEASSERT GPBDAT |= (1 << 4) 27#define USB_RST_DEASSERT GPBDAT |= (1 << 4)
@@ -35,9 +36,12 @@
35#define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8) 36#define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8)
36 37
37/* The usb detect is one pin to the cpu active low */ 38/* The usb detect is one pin to the cpu active low */
38inline bool usb_detect(void) 39int usb_detect(void)
39{ 40{
40 return USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT; 41 if (USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT)
42 return USB_INSERTED;
43 else
44 return USB_EXTRACTED;
41} 45}
42 46
43void usb_init_device(void) 47void usb_init_device(void)
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h b/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h
index baeb539b38..65690dc86b 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h
@@ -20,7 +20,6 @@
20#define USB_TARGET_H 20#define USB_TARGET_H
21 21
22bool usb_init_device(void); 22bool usb_init_device(void);
23bool usb_detect(void);
24void usb_enable(bool on); 23void usb_enable(bool on);
25 24
26#endif 25#endif
diff --git a/firmware/target/arm/usb-fw-pp5002.c b/firmware/target/arm/usb-fw-pp5002.c
index e64d4f8f81..2a216c4d9b 100644
--- a/firmware/target/arm/usb-fw-pp5002.c
+++ b/firmware/target/arm/usb-fw-pp5002.c
@@ -56,15 +56,15 @@ void usb_enable(bool on)
56 } 56 }
57} 57}
58 58
59bool usb_detect(void) 59int usb_detect(void)
60{ 60{
61#if defined(IPOD_1G2G) || defined(IPOD_3G) 61#if defined(IPOD_1G2G) || defined(IPOD_3G)
62 /* GPIO C bit 7 is firewire detect */ 62 /* GPIO C bit 7 is firewire detect */
63 if (!(GPIOC_INPUT_VAL & 0x80)) 63 if (!(GPIOC_INPUT_VAL & 0x80))
64 return true; 64 return USB_INSERTED;
65#endif 65#endif
66 66
67 /* TODO: add USB detection for iPod 3rd gen */ 67 /* TODO: add USB detection for iPod 3rd gen */
68 68
69 return false; 69 return USB_EXTRACTED;
70} 70}
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c
index 76bd7281f5..ad2a10599f 100644
--- a/firmware/target/arm/usb-fw-pp502x.c
+++ b/firmware/target/arm/usb-fw-pp502x.c
@@ -92,7 +92,7 @@ void usb_init_device(void)
92void usb_enable(bool on) 92void usb_enable(bool on)
93{ 93{
94#ifdef HAVE_USBSTACK 94#ifdef HAVE_USBSTACK
95 (void)on; 95 (void)on;
96#else 96#else
97 /* This device specific code will eventually give way to proper USB 97 /* This device specific code will eventually give way to proper USB
98 handling, which should be the same for all PP502x targets. */ 98 handling, which should be the same for all PP502x targets. */
@@ -124,18 +124,42 @@ void usb_enable(bool on)
124#endif /* !HAVE_USBSTACK */ 124#endif /* !HAVE_USBSTACK */
125} 125}
126 126
127bool usb_detect(void) 127int usb_detect(void)
128{ 128{
129 static int countdown = 0;
130 static int status = USB_EXTRACTED;
129 static bool prev_usbstatus1 = false; 131 static bool prev_usbstatus1 = false;
130 bool usbstatus1,usbstatus2; 132 bool usbstatus1, usbstatus2;
131 133
132#if defined(IPOD_COLOR) || defined(IPOD_4G) \ 134#if defined(IPOD_COLOR) || defined(IPOD_4G) \
133 || defined(IPOD_MINI) || defined(IPOD_MINI2G) 135 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
134 /* GPIO C bit 1 is firewire detect */ 136 /* GPIO C bit 1 is firewire detect */
135 if (!(GPIOC_INPUT_VAL & 0x02)) 137 if (!(GPIOC_INPUT_VAL & 0x02))
136 return true; 138 return USB_INSERTED;
137#endif 139#endif
138 140
141 if (countdown > 0)
142 {
143 countdown--;
144
145 usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false;
146 if ((countdown == 0) || usbstatus2)
147 {
148 countdown = 0;
149 status = usbstatus2 ? USB_INSERTED : USB_POWERED;
150 dr_controller_stop();
151
152#ifdef HAVE_USBSTACK
153 /* TODO: Move this call - it shouldn't be done in this function */
154 if (status == USB_INSERTED)
155 {
156 usb_stack_start();
157 }
158#endif
159 }
160 return status;
161 }
162
139 /* UDC_ID should have the bit format: 163 /* UDC_ID should have the bit format:
140 [31:24] = 0x0 164 [31:24] = 0x0
141 [23:16] = 0x22 (Revision number) 165 [23:16] = 0x22 (Revision number)
@@ -144,29 +168,51 @@ bool usb_detect(void)
144 [7:6] = 0x0 (Reserved) 168 [7:6] = 0x0 (Reserved)
145 [5:0] = 0x05 (ID) */ 169 [5:0] = 0x05 (ID) */
146 if (UDC_ID != 0x22FA05) { 170 if (UDC_ID != 0x22FA05) {
147 return false; 171 /* This should never occur - do we even need to test? */
172 return USB_EXTRACTED;
148 } 173 }
149 174
150 usbstatus1 = (UDC_OTGSC & 0x800) ? true : false; 175 usbstatus1 = (UDC_OTGSC & 0x800) ? true : false;
176
177 if (usbstatus1 == prev_usbstatus1)
178 {
179 /* Nothing has changed, so just return previous status */
180 return status;
181 }
182 prev_usbstatus1 = usbstatus1;
183
184 if (!usbstatus1)
185 { /* We have just been disconnected */
186 status = USB_EXTRACTED;
151#ifdef HAVE_USBSTACK 187#ifdef HAVE_USBSTACK
152 if ((usbstatus1 == true) && (prev_usbstatus1 == false)) { 188 /* TODO: Move this call - it shouldn't be done in this function */
153 usb_stack_start();
154 } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
155 usb_stack_stop(); 189 usb_stack_stop();
156 }
157#else
158 if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
159 dr_controller_run();
160 } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
161 dr_controller_stop();
162 }
163#endif 190#endif
164 prev_usbstatus1 = usbstatus1; 191 return status;
165 usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false; 192 }
193
194 /* We now know that we have just been connected to either a charger
195 or a computer */
166 196
167 if (usbstatus1 && usbstatus2) { 197 if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON)
168 return true; 198 {
169 } else { 199 /* The user wants to charge, so it doesn't matter what we are
170 return false; 200 connected to. */
201
202 status = USB_POWERED;
203 return status;
171 } 204 }
205
206 /* Run the USB controller for long enough to detect if we're connected
207 to a computer, then stop it again. */
208
209 dr_controller_run();
210
211 /* Wait for 50 ticks (500ms) before deciding there is no computer
212 attached. The required value varied a lot between different users
213 when this feature was being tested. */
214
215 countdown = 50;
216
217 return status;
172} 218}
diff --git a/firmware/target/coldfire/iaudio/usb-iaudio.c b/firmware/target/coldfire/iaudio/usb-iaudio.c
index 3bd1a7a458..21d69611b7 100644
--- a/firmware/target/coldfire/iaudio/usb-iaudio.c
+++ b/firmware/target/coldfire/iaudio/usb-iaudio.c
@@ -20,6 +20,7 @@
20#include <stdbool.h> 20#include <stdbool.h>
21#include "cpu.h" 21#include "cpu.h"
22#include "system.h" 22#include "system.h"
23#include "usb.h"
23 24
24void usb_init_device(void) 25void usb_init_device(void)
25{ 26{
@@ -30,9 +31,9 @@ void usb_init_device(void)
30 or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */ 31 or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */
31} 32}
32 33
33bool usb_detect(void) 34int usb_detect(void)
34{ 35{
35 return (GPIO1_READ & 0x00800000)?true:false; 36 return (GPIO1_READ & 0x00800000) ? USB_INSERTED : USB_EXTRACTED;
36} 37}
37 38
38void usb_enable(bool on) 39void usb_enable(bool on)
diff --git a/firmware/target/coldfire/iriver/h100/usb-h100.c b/firmware/target/coldfire/iriver/h100/usb-h100.c
index 3b00e967da..5a2f7f500b 100644
--- a/firmware/target/coldfire/iriver/h100/usb-h100.c
+++ b/firmware/target/coldfire/iriver/h100/usb-h100.c
@@ -21,6 +21,7 @@
21#include "cpu.h" 21#include "cpu.h"
22#include "system.h" 22#include "system.h"
23#include "kernel.h" 23#include "kernel.h"
24#include "usb.h"
24 25
25void usb_init_device(void) 26void usb_init_device(void)
26{ 27{
@@ -30,9 +31,9 @@ void usb_init_device(void)
30 or_l(0x01000040, &GPIO_FUNCTION); 31 or_l(0x01000040, &GPIO_FUNCTION);
31} 32}
32 33
33bool usb_detect(void) 34int usb_detect(void)
34{ 35{
35 return (GPIO1_READ & 0x80)?true:false; 36 return (GPIO1_READ & 0x80) ? USB_INSERTED : USB_EXTRACTED;
36} 37}
37 38
38void usb_enable(bool on) 39void usb_enable(bool on)
diff --git a/firmware/target/coldfire/iriver/h300/usb-h300.c b/firmware/target/coldfire/iriver/h300/usb-h300.c
index d08cc24dba..d50b7bc808 100644
--- a/firmware/target/coldfire/iriver/h300/usb-h300.c
+++ b/firmware/target/coldfire/iriver/h300/usb-h300.c
@@ -21,6 +21,7 @@
21#include "cpu.h" 21#include "cpu.h"
22#include "system.h" 22#include "system.h"
23#include "kernel.h" 23#include "kernel.h"
24#include "usb.h"
24 25
25void usb_init_device(void) 26void usb_init_device(void)
26{ 27{
@@ -35,9 +36,9 @@ void usb_init_device(void)
35 or_l(0x03000000, &GPIO_FUNCTION); 36 or_l(0x03000000, &GPIO_FUNCTION);
36} 37}
37 38
38bool usb_detect(void) 39int usb_detect(void)
39{ 40{
40 return (GPIO1_READ & 0x80)?true:false; 41 return (GPIO1_READ & 0x80) ? USB_INSERTED : USB_EXTRACTED;
41} 42}
42 43
43void usb_enable(bool on) 44void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
index 3dcc3559a3..9c641b925a 100644
--- a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
+++ b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
@@ -22,10 +22,11 @@
22#include "cpu.h" 22#include "cpu.h"
23#include "hwcompat.h" 23#include "hwcompat.h"
24#include "system.h" 24#include "system.h"
25#include "usb.h"
25 26
26bool usb_detect(void) 27int usb_detect(void)
27{ 28{
28 return (adc_read(ADC_USB_POWER) <= 512) ? true : false; 29 return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED;
29} 30}
30 31
31void usb_enable(bool on) 32void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/ondio/usb-ondio.c b/firmware/target/sh/archos/ondio/usb-ondio.c
index c856f3ae2c..b370fec3d9 100644
--- a/firmware/target/sh/archos/ondio/usb-ondio.c
+++ b/firmware/target/sh/archos/ondio/usb-ondio.c
@@ -23,10 +23,11 @@
23#include "cpu.h" 23#include "cpu.h"
24#include "hwcompat.h" 24#include "hwcompat.h"
25#include "system.h" 25#include "system.h"
26#include "usb.h"
26 27
27bool usb_detect(void) 28int usb_detect(void)
28{ 29{
29 return (adc_read(ADC_USB_POWER) <= 512) ? true : false; 30 return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED;
30} 31}
31 32
32void usb_enable(bool on) 33void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/player/usb-player.c b/firmware/target/sh/archos/player/usb-player.c
index c10e222f0a..e86003f2c2 100644
--- a/firmware/target/sh/archos/player/usb-player.c
+++ b/firmware/target/sh/archos/player/usb-player.c
@@ -20,10 +20,11 @@
20#include <stdbool.h> 20#include <stdbool.h>
21#include "cpu.h" 21#include "cpu.h"
22#include "system.h" 22#include "system.h"
23#include "usb.h"
23 24
24bool usb_detect(void) 25int usb_detect(void)
25{ 26{
26 return (PADR & 0x8000) ? false : true; 27 return (PADR & 0x8000) ? USB_INSERTED : USB_EXTRACTED;
27} 28}
28 29
29void usb_enable(bool on) 30void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/recorder/usb-recorder.c b/firmware/target/sh/archos/recorder/usb-recorder.c
index 7ed237068e..dfa8462203 100644
--- a/firmware/target/sh/archos/recorder/usb-recorder.c
+++ b/firmware/target/sh/archos/recorder/usb-recorder.c
@@ -22,10 +22,11 @@
22#include "cpu.h" 22#include "cpu.h"
23#include "hwcompat.h" 23#include "hwcompat.h"
24#include "system.h" 24#include "system.h"
25#include "usb.h"
25 26
26bool usb_detect(void) 27int usb_detect(void)
27{ 28{
28 return (adc_read(ADC_USB_POWER) > 500) ? true : false; 29 return (adc_read(ADC_USB_POWER) > 500) ? USB_INSERTED : USB_EXTRACTED;
29} 30}
30 31
31void usb_enable(bool on) 32void usb_enable(bool on)
diff --git a/firmware/usb.c b/firmware/usb.c
index 9e9cb77919..876a5e4ec2 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -51,39 +51,6 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */
51 51
52#if !defined(SIMULATOR) && !defined(USB_NONE) 52#if !defined(SIMULATOR) && !defined(USB_NONE)
53 53
54/* Messages from usb_tick and thread states */
55#define USB_INSERTED 1
56#define USB_EXTRACTED 2
57#ifdef HAVE_MMC
58#define USB_REENABLE 3
59#endif
60#ifdef HAVE_USB_POWER
61#define USB_POWERED 4
62
63#if CONFIG_KEYPAD == RECORDER_PAD
64#define USBPOWER_BUTTON BUTTON_F1
65#define USBPOWER_BTN_IGNORE BUTTON_ON
66#elif CONFIG_KEYPAD == ONDIO_PAD
67#define USBPOWER_BUTTON BUTTON_MENU
68#define USBPOWER_BTN_IGNORE BUTTON_OFF
69#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
70#define USBPOWER_BUTTON BUTTON_MENU
71#define USBPOWER_BTN_IGNORE BUTTON_PLAY
72#elif CONFIG_KEYPAD == IRIVER_H300_PAD
73#define USBPOWER_BUTTON BUTTON_REC
74#define USBPOWER_BTN_IGNORE BUTTON_ON
75#elif CONFIG_KEYPAD == GIGABEAT_PAD
76#define USBPOWER_BUTTON BUTTON_MENU
77#define USBPOWER_BTN_IGNORE BUTTON_POWER
78#elif CONFIG_KEYPAD == IRIVER_H10_PAD
79#define USBPOWER_BUTTON BUTTON_NONE
80#define USBPOWER_BTN_IGNORE BUTTON_POWER
81#elif CONFIG_KEYPAD == SANSA_E200_PAD
82#define USBPOWER_BUTTON BUTTON_SELECT
83#define USBPOWER_BTN_IGNORE BUTTON_POWER
84#endif
85#endif /* HAVE_USB_POWER */
86
87#define NUM_POLL_READINGS (HZ/5) 54#define NUM_POLL_READINGS (HZ/5)
88static int countdown; 55static int countdown;
89 56
@@ -100,7 +67,7 @@ static long usb_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)];
100static const char usb_thread_name[] = "usb"; 67static const char usb_thread_name[] = "usb";
101#endif 68#endif
102static struct event_queue usb_queue; 69static struct event_queue usb_queue;
103static bool last_usb_status; 70static int last_usb_status;
104static bool usb_monitor_enabled; 71static bool usb_monitor_enabled;
105 72
106 73
@@ -161,6 +128,11 @@ static void usb_thread(void)
161 queue_wait(&usb_queue, &ev); 128 queue_wait(&usb_queue, &ev);
162 switch(ev.id) 129 switch(ev.id)
163 { 130 {
131#ifdef HAVE_USB_POWER
132 case USB_POWERED:
133 usb_state = USB_POWERED;
134 break;
135#endif
164 case USB_INSERTED: 136 case USB_INSERTED:
165#ifdef HAVE_LCD_BITMAP 137#ifdef HAVE_LCD_BITMAP
166 if(do_screendump_instead_of_usb) 138 if(do_screendump_instead_of_usb)
@@ -278,7 +250,7 @@ static void usb_thread(void)
278#ifndef BOOTLOADER 250#ifndef BOOTLOADER
279static void usb_tick(void) 251static void usb_tick(void)
280{ 252{
281 bool current_status; 253 int current_status;
282 254
283 if(usb_monitor_enabled) 255 if(usb_monitor_enabled)
284 { 256 {
@@ -300,10 +272,7 @@ static void usb_tick(void)
300 readings in a row */ 272 readings in a row */
301 if(countdown == 0) 273 if(countdown == 0)
302 { 274 {
303 if(current_status) 275 queue_post(&usb_queue, current_status, 0);
304 queue_post(&usb_queue, USB_INSERTED, 0);
305 else
306 queue_post(&usb_queue, USB_EXTRACTED, 0);
307 } 276 }
308 } 277 }
309 } 278 }
@@ -463,9 +432,9 @@ void usb_start_monitoring(void)
463{ 432{
464} 433}
465 434
466bool usb_detect(void) 435int usb_detect(void)
467{ 436{
468 return false; 437 return USB_EXTRACTED;
469} 438}
470 439
471void usb_wait_for_disconnect(struct event_queue *q) 440void usb_wait_for_disconnect(struct event_queue *q)