summaryrefslogtreecommitdiff
path: root/firmware/usb.c
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-06-23 02:18:29 +0000
committerJens Arnold <amiconn@rockbox.org>2005-06-23 02:18:29 +0000
commit97a804938996d5bbc122128eb78a074491c4ad61 (patch)
tree8e5b58c663edc49bcbffd40c8237f259ca36309c /firmware/usb.c
parent6e0436f65cd461bb2b21c9a0178dfa6978213d27 (diff)
downloadrockbox-97a804938996d5bbc122128eb78a074491c4ad61.tar.gz
rockbox-97a804938996d5bbc122128eb78a074491c4ad61.zip
New feature for units that can be powered or charged from USB (Recorder fm/v2, Ondios): USB power mode, based on patch #1110332 by Pieter Bos. This way you can save battery power or even charge the battery (fm/v2) while using your unit near a PC. Hold MODE (Ondio) or F1 (fm/v2) while plugging USB to enter that mode. A tiny USB plug icon will be displayed is the status bar (overridden by the regular power plug icon in case of fm/v2 when the charger is connected).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6836 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usb.c')
-rw-r--r--firmware/usb.c79
1 files changed, 49 insertions, 30 deletions
diff --git a/firmware/usb.c b/firmware/usb.c
index a514f8f0b4..866ca5319c 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -47,18 +47,21 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */
47 47
48#if !defined(SIMULATOR) && !defined(USB_NONE) 48#if !defined(SIMULATOR) && !defined(USB_NONE)
49 49
50/* Messages from usb_tick */ 50/* Messages from usb_tick and thread states */
51#define USB_INSERTED 1 51#define USB_INSERTED 1
52#define USB_EXTRACTED 2 52#define USB_EXTRACTED 2
53#ifdef HAVE_MMC 53#ifdef HAVE_MMC
54#define USB_REENABLE 3 54#define USB_REENABLE 3
55#endif 55#endif
56#ifdef HAVE_USB_POWER
57#define USB_POWERED 4
56 58
57/* Thread states */ 59#if CONFIG_KEYPAD == RECORDER_PAD
58#define EXTRACTING 1 60#define USBPOWER_BUTTON BUTTON_F1
59#define EXTRACTED 2 61#elif CONFIG_KEYPAD == ONDIO_PAD
60#define INSERTED 3 62#define USBPOWER_BUTTON BUTTON_MENU
61#define INSERTING 4 63#endif
64#endif /* HAVE_USB_POWER */
62 65
63/* The ADC tick reads one channel per tick, and we want to check 3 successive 66/* The ADC tick reads one channel per tick, and we want to check 3 successive
64 readings on the USB voltage channel. This doesn't apply to the Player, but 67 readings on the USB voltage channel. This doesn't apply to the Player, but
@@ -221,8 +224,15 @@ static void usb_thread(void)
221 screen_dump(); 224 screen_dump();
222 } 225 }
223 else 226 else
227#endif
228#ifdef HAVE_USB_POWER
229 if(button_status() == USBPOWER_BUTTON)
224 { 230 {
231 usb_state = USB_POWERED;
232 }
233 else
225#endif 234#endif
235 {
226 /* Tell all threads that they have to back off the ATA. 236 /* Tell all threads that they have to back off the ATA.
227 We subtract one for our own thread. */ 237 We subtract one for our own thread. */
228 num_acks_to_expect = 238 num_acks_to_expect =
@@ -230,11 +240,9 @@ static void usb_thread(void)
230 waiting_for_ack = true; 240 waiting_for_ack = true;
231 DEBUGF("USB inserted. Waiting for ack from %d threads...\n", 241 DEBUGF("USB inserted. Waiting for ack from %d threads...\n",
232 num_acks_to_expect); 242 num_acks_to_expect);
233#ifdef HAVE_LCD_BITMAP
234 } 243 }
235#endif
236 break; 244 break;
237 245
238 case SYS_USB_CONNECTED_ACK: 246 case SYS_USB_CONNECTED_ACK:
239 if(waiting_for_ack) 247 if(waiting_for_ack)
240 { 248 {
@@ -259,33 +267,37 @@ static void usb_thread(void)
259 267
260 case USB_EXTRACTED: 268 case USB_EXTRACTED:
261#ifdef HAVE_LCD_BITMAP 269#ifdef HAVE_LCD_BITMAP
262 if(!do_screendump_instead_of_usb) 270 if(do_screendump_instead_of_usb)
263 { 271 break;
264#endif 272#endif
265 if(usb_state == USB_INSERTED) 273#ifdef HAVE_USB_POWER
266 { 274 if(usb_state == USB_POWERED)
267 /* Only disable the USB mode if we really have enabled it 275 {
268 some threads might not have acknowledged the
269 insertion */
270 usb_slave_mode(false);
271 }
272
273 usb_state = USB_EXTRACTED; 276 usb_state = USB_EXTRACTED;
274 277 break;
275 /* Tell all threads that we are back in business */ 278 }
276 num_acks_to_expect =
277 queue_broadcast(SYS_USB_DISCONNECTED, NULL) - 1;
278 waiting_for_ack = true;
279 DEBUGF("USB extracted. Waiting for ack from %d threads...\n",
280 num_acks_to_expect);
281#ifdef HAVE_LCD_CHARCELLS
282 lcd_icon(ICON_USB, false);
283#endif 279#endif
284#ifdef HAVE_LCD_BITMAP 280 if(usb_state == USB_INSERTED)
281 {
282 /* Only disable the USB mode if we really have enabled it
283 some threads might not have acknowledged the
284 insertion */
285 usb_slave_mode(false);
285 } 286 }
287
288 usb_state = USB_EXTRACTED;
289
290 /* Tell all threads that we are back in business */
291 num_acks_to_expect =
292 queue_broadcast(SYS_USB_DISCONNECTED, NULL) - 1;
293 waiting_for_ack = true;
294 DEBUGF("USB extracted. Waiting for ack from %d threads...\n",
295 num_acks_to_expect);
296#ifdef HAVE_LCD_CHARCELLS
297 lcd_icon(ICON_USB, false);
286#endif 298#endif
287 break; 299 break;
288 300
289 case SYS_USB_DISCONNECTED_ACK: 301 case SYS_USB_DISCONNECTED_ACK:
290 if(waiting_for_ack) 302 if(waiting_for_ack)
291 { 303 {
@@ -475,6 +487,13 @@ bool usb_inserted(void)
475 return usb_state == USB_INSERTED; 487 return usb_state == USB_INSERTED;
476} 488}
477 489
490#ifdef HAVE_USB_POWER
491bool usb_powered(void)
492{
493 return usb_state == USB_POWERED;
494}
495#endif
496
478#else 497#else
479 498
480#ifdef USB_NONE 499#ifdef USB_NONE