Prepare new maemo release
[maemo-rb.git] / firmware / export / usb.h
blob13ef3983b2b9bfc198318405ef3632377737d5fb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _USB_H_
22 #define _USB_H_
24 #include "config.h"
25 #include "kernel.h"
26 #include "button.h"
28 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
29 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
30 #define USB_FIREWIRE_HANDLING
31 #endif
33 /* Messages from usb_tick and thread states */
34 enum
36 #ifdef HAVE_LCD_BITMAP
37 USB_SCREENDUMP = -1, /* State */
38 #endif
39 USB_EXTRACTED = 0, /* Event+State */
40 USB_INSERTED, /* Event+State */
41 USB_POWERED, /* State - transitional indicator if no power */
42 #if (CONFIG_STORAGE & STORAGE_MMC)
43 USB_REENABLE, /* Event */
44 #endif
45 #ifdef HAVE_USBSTACK
46 USB_TRANSFER_COMPLETION, /* Event */
47 USB_NOTIFY_SET_ADDR, /* Event */
48 USB_NOTIFY_SET_CONFIG, /* Event */
49 #endif
50 #ifdef USB_FIREWIRE_HANDLING
51 USB_REQUEST_REBOOT, /* Event */
52 #endif
53 USB_QUIT, /* Event */
54 #if defined(HAVE_USB_CHARGING_ENABLE) && defined(HAVE_USBSTACK)
55 USB_CHARGER_UPDATE, /* Event */
56 #endif
57 #ifdef HAVE_BOOTLOADER_USB_MODE
58 USB_HANDLED, /* Bootloader status code */
59 #endif
62 #ifdef HAVE_USB_POWER
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 /*allow people to define this in config-target.h if they need it*/
70 #elif !defined(USBPOWER_BTN_IGNORE)
71 #define USBPOWER_BTN_IGNORE 0
72 #endif
73 #endif
75 #ifdef HAVE_USBSTACK
76 /* USB class drivers */
77 enum {
78 #ifdef USB_ENABLE_STORAGE
79 USB_DRIVER_MASS_STORAGE,
80 #endif
81 #ifdef USB_ENABLE_SERIAL
82 USB_DRIVER_SERIAL,
83 #endif
84 #ifdef USB_ENABLE_CHARGING_ONLY
85 USB_DRIVER_CHARGING_ONLY,
86 #endif
87 #ifdef USB_ENABLE_HID
88 USB_DRIVER_HID,
89 #endif
90 USB_NUM_DRIVERS
93 struct usb_transfer_completion_event_data
95 unsigned char endpoint;
96 int dir;
97 int status;
98 int length;
99 void* data;
101 #endif /* HAVE_USBSTACK */
103 void usb_init(void) INIT_ATTR;
104 void usb_enable(bool on);
105 void usb_attach(void);
106 void usb_start_monitoring(void) INIT_ATTR;
107 void usb_close(void);
108 void usb_acknowledge(long id);
109 void usb_wait_for_disconnect(struct event_queue *q);
110 int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks);
111 bool usb_inserted(void); /* return the official value, what's been reported to the threads */
112 int usb_detect(void); /* return the raw hardware value - nothing/pc/charger */
113 /* For tick-less USB monitoring (USB_STATUS_BY_EVENT) */
114 void usb_status_event(int current_status);
115 #ifdef HAVE_USB_POWER
116 bool usb_powered(void);
117 #ifdef HAVE_USB_CHARGING_ENABLE
118 enum {
119 USB_CHARGING_DISABLE,
120 USB_CHARGING_ENABLE,
121 USB_CHARGING_FORCE
123 /* called by app, implemented by usb_core on targets with rockbox usb
124 * or target-specific code on others
126 void usb_charging_enable(int state);
127 #ifdef HAVE_USBSTACK
128 void usb_charger_update(void);
129 #endif /* HAVE_USBSTACK */
130 #endif /* HAVE_USB_CHARGING_ENABLE */
131 #endif /* HAVE_USB_POWER */
132 #ifdef HAVE_USBSTACK
133 void usb_signal_transfer_completion(
134 struct usb_transfer_completion_event_data *event_data);
135 void usb_signal_notify(long id, intptr_t data);
136 bool usb_driver_enabled(int driver);
137 bool usb_exclusive_storage(void); /* storage is available for usb */
138 #endif
139 int usb_release_exclusive_storage(void);
141 #ifdef USB_FIREWIRE_HANDLING
142 bool firewire_detect(void);
143 void usb_firewire_connect_event(void);
144 #endif
146 #ifdef USB_ENABLE_HID
147 void usb_set_hid(bool enable);
148 #endif
150 #if defined(USB_ENABLE_STORAGE) && defined(HAVE_MULTIDRIVE)
151 void usb_set_skip_first_drive(bool skip);
152 #endif
154 #if !defined(SIMULATOR) && !defined(USB_NONE)
155 void usb_init_device(void);
156 #endif
158 #endif