Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /******************************************************************************* |
2 | |||
3 | USB Host Charger Client Driver (Header File) |
||
4 | |||
5 | Description: |
||
6 | This is the Charger client driver file for a USB Embedded Host device. This |
||
7 | driver should be used in a project with usb_host.c to provided the USB |
||
8 | hardware interface. |
||
9 | |||
10 | To interface with USB Embedded Host layer, the routine USBHostChargerInit() |
||
11 | should be specified as the Initialize() function, and |
||
12 | USBHostChargerEventHandler() should be specified as the EventHandler() |
||
13 | function in the usbClientDrvTable[] array declared in usb_config.c. |
||
14 | |||
15 | This driver can be used in either the event driven or polling mechanism. |
||
16 | |||
17 | Summary: |
||
18 | This is the Charger client driver file for a USB Embedded Host device. |
||
19 | |||
20 | *******************************************************************************/ |
||
21 | //DOM-IGNORE-BEGIN |
||
22 | /****************************************************************************** |
||
23 | |||
24 | * FileName: usb_client_charger.h |
||
25 | * Dependencies: None |
||
26 | * Processor: PIC24/dsPIC30/dsPIC33/PIC32MX |
||
27 | * Compiler: C30 v2.01/C32 v0.00.18 |
||
28 | * Company: Microchip Technology, Inc. |
||
29 | |||
30 | Software License Agreement |
||
31 | |||
32 | The software supplied herewith by Microchip Technology Incorporated |
||
33 | (the Company) for its PICmicro® Microcontroller is intended and |
||
34 | supplied to you, the Companys customer, for use solely and |
||
35 | exclusively on Microchip PICmicro Microcontroller products. The |
||
36 | software is owned by the Company and/or its supplier, and is |
||
37 | protected under applicable copyright laws. All rights are reserved. |
||
38 | Any use in violation of the foregoing restrictions may subject the |
||
39 | user to criminal sanctions under applicable laws, as well as to |
||
40 | civil liability for the breach of the terms and conditions of this |
||
41 | license. |
||
42 | |||
43 | THIS SOFTWARE IS PROVIDED IN AN AS IS CONDITION. NO WARRANTIES, |
||
44 | WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
||
45 | TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
46 | PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
||
47 | IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
||
48 | CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
||
49 | |||
50 | Change History: |
||
51 | Rev Description |
||
52 | ----- ---------------------------------- |
||
53 | 2.6a- No change |
||
54 | 2.7a |
||
55 | *******************************************************************************/ |
||
56 | #ifndef __USBHOSTCHARGER_H__ |
||
57 | #define __USBHOSTCHARGER_H__ |
||
58 | //DOM-IGNORE-END |
||
59 | |||
60 | // ***************************************************************************** |
||
61 | // ***************************************************************************** |
||
62 | // Section: Configuration |
||
63 | // ***************************************************************************** |
||
64 | // ***************************************************************************** |
||
65 | |||
66 | // ***************************************************************************** |
||
67 | /* Max Number of Supported Devices |
||
68 | |||
69 | This value represents the maximum number of attached devices this client driver |
||
70 | can support. If the user does not define a value, it will be set to 1. |
||
71 | */ |
||
72 | #ifndef USB_MAX_CHARGING_DEVICES |
||
73 | #define USB_MAX_CHARGING_DEVICES 1 |
||
74 | #endif |
||
75 | |||
76 | |||
77 | // ***************************************************************************** |
||
78 | // ***************************************************************************** |
||
79 | // Section: USB Charger Client Events |
||
80 | // ***************************************************************************** |
||
81 | // ***************************************************************************** |
||
82 | |||
83 | // This is an optional offset for the values of the generated events. |
||
84 | // If necessary, the application can use a non-zero offset for the |
||
85 | // generic events to resolve conflicts in event number. |
||
86 | #ifndef EVENT_CHARGER_OFFSET |
||
87 | #define EVENT_CHARGER_OFFSET 0 |
||
88 | #endif |
||
89 | |||
90 | // This event indicates that a device has been attached for charging. |
||
91 | // When USB_HOST_APP_EVENT_HANDLER is called with this event, *data |
||
92 | // points to a USB_CHARGING_DEVICE_ID structure, and size is the size of the |
||
93 | // USB_CHARGING_DEVICE_ID structure. |
||
94 | #define EVENT_CHARGER_ATTACH (EVENT_CHARGER_BASE+EVENT_CHARGER_OFFSET+0) |
||
95 | |||
96 | // This event indicates that the specified device has been detached |
||
97 | // from the USB. When USB_HOST_APP_EVENT_HANDLER is called with this |
||
98 | // event, *data points to a BYTE that contains the device address, and |
||
99 | // size is the size of a BYTE. |
||
100 | #define EVENT_CHARGER_DETACH (EVENT_CHARGER_BASE+EVENT_CHARGER_OFFSET+1) |
||
101 | |||
102 | |||
103 | // ***************************************************************************** |
||
104 | // ***************************************************************************** |
||
105 | // Section: USB Data Structures |
||
106 | // ***************************************************************************** |
||
107 | // ***************************************************************************** |
||
108 | |||
109 | // ***************************************************************************** |
||
110 | /* Charging Device ID Information |
||
111 | |||
112 | This structure contains identification information about an attached device. |
||
113 | */ |
||
114 | typedef struct |
||
115 | { |
||
116 | WORD vid; // Vendor ID of the device |
||
117 | WORD pid; // Product ID of the device |
||
118 | BYTE deviceAddress; // Address of the device on the USB |
||
119 | } USB_CHARGING_DEVICE_ID; |
||
120 | |||
121 | |||
122 | // ***************************************************************************** |
||
123 | /* Charging Device Information |
||
124 | |||
125 | This structure contains information about an attached device, including |
||
126 | status flags and device identification. |
||
127 | */ |
||
128 | typedef struct |
||
129 | { |
||
130 | USB_CHARGING_DEVICE_ID ID; // Identification information about the device |
||
131 | |||
132 | union |
||
133 | { |
||
134 | BYTE val; // BYTE representation of device status flags |
||
135 | struct |
||
136 | { |
||
137 | BYTE inUse : 1; // Record is being used. DO NOT MODIFY |
||
138 | }; |
||
139 | } flags; // Generic client driver status flags |
||
140 | |||
141 | } USB_CHARGING_DEVICE; |
||
142 | |||
143 | |||
144 | // ***************************************************************************** |
||
145 | // ***************************************************************************** |
||
146 | // Section: Global Variables |
||
147 | // ***************************************************************************** |
||
148 | // ***************************************************************************** |
||
149 | |||
150 | extern USB_CHARGING_DEVICE usbChargingDevices[USB_MAX_CHARGING_DEVICES]; // Information about the attached device. |
||
151 | |||
152 | // ***************************************************************************** |
||
153 | // ***************************************************************************** |
||
154 | // Section: Host Stack Interface Functions |
||
155 | // ***************************************************************************** |
||
156 | // ***************************************************************************** |
||
157 | |||
158 | /**************************************************************************** |
||
159 | Function: |
||
160 | BOOL USBHostChargerInitialize ( BYTE address, DWORD flags ) |
||
161 | |||
162 | Summary: |
||
163 | This function is called by the USB Embedded Host layer when a device |
||
164 | attaches for charging. |
||
165 | |||
166 | Description: |
||
167 | This routine is a call out from the USB Embedded Host layer to the USB |
||
168 | charger client driver. It is called when a device that is supported for |
||
169 | charging only has been connected to the host. Its purpose is to initialize |
||
170 | and activate the USB Charger client driver. |
||
171 | |||
172 | Preconditions: |
||
173 | The device has been configured. |
||
174 | |||
175 | Parameters: |
||
176 | BYTE address - Device's address on the bus |
||
177 | DWORD flags - Initialization flags |
||
178 | |||
179 | Return Values: |
||
180 | TRUE - Initialization was successful |
||
181 | FALSE - Initialization failed |
||
182 | |||
183 | Remarks: |
||
184 | Multiple client drivers may be used in a single application. The USB |
||
185 | Embedded Host layer will call the initialize routine required for the |
||
186 | attached device. |
||
187 | ***************************************************************************/ |
||
188 | |||
189 | BOOL USBHostChargerInitialize( BYTE address, DWORD flags ); |
||
190 | |||
191 | |||
192 | /**************************************************************************** |
||
193 | Function: |
||
194 | BOOL USBHostChargerEventHandler ( BYTE address, USB_EVENT event, |
||
195 | void *data, DWORD size ) |
||
196 | |||
197 | Summary: |
||
198 | This routine is called by the Host layer to notify the charger client of |
||
199 | events that occur. |
||
200 | |||
201 | Description: |
||
202 | This routine is called by the Host layer to notify the charger client of |
||
203 | events that occur. If the event is recognized, it is handled and the |
||
204 | routine returns TRUE. Otherwise, it is ignored and the routine returns |
||
205 | FALSE. |
||
206 | |||
207 | Preconditions: |
||
208 | None |
||
209 | |||
210 | Parameters: |
||
211 | BYTE address - Address of device with the event |
||
212 | USB_EVENT event - The bus event that occured |
||
213 | void *data - Pointer to event-specific data |
||
214 | DWORD size - Size of the event-specific data |
||
215 | |||
216 | Return Values: |
||
217 | TRUE - The event was handled |
||
218 | FALSE - The event was not handled |
||
219 | |||
220 | Remarks: |
||
221 | None |
||
222 | ***************************************************************************/ |
||
223 | |||
224 | BOOL USBHostChargerEventHandler( BYTE address, USB_EVENT event, void *data, DWORD size ); |
||
225 | |||
226 | |||
227 | // ***************************************************************************** |
||
228 | // ***************************************************************************** |
||
229 | // Section: Function Prototypes and Macro Functions |
||
230 | // ***************************************************************************** |
||
231 | // ***************************************************************************** |
||
232 | |||
233 | /**************************************************************************** |
||
234 | Function: |
||
235 | BOOL USBHostChargerDeviceDetached( BYTE deviceAddress ) |
||
236 | |||
237 | Description: |
||
238 | This interface is used to check if the devich has been detached from the |
||
239 | bus. |
||
240 | |||
241 | Preconditions: |
||
242 | None |
||
243 | |||
244 | Parameters: |
||
245 | deviceAddress - USB Address of the device. |
||
246 | |||
247 | Return Values: |
||
248 | TRUE - The device has been detached, or an invalid deviceAddress is given. |
||
249 | FALSE - The device is attached |
||
250 | |||
251 | Example: |
||
252 | <code> |
||
253 | if (USBHostChargerDeviceDetached( deviceAddress )) |
||
254 | { |
||
255 | // Handle detach |
||
256 | } |
||
257 | </code> |
||
258 | |||
259 | Remarks: |
||
260 | None |
||
261 | ***************************************************************************/ |
||
262 | |||
263 | BOOL USBHostChargerDeviceDetached( BYTE deviceAddress ); |
||
264 | |||
265 | |||
266 | /**************************************************************************** |
||
267 | Function: |
||
268 | BOOL USBHostChargerGetDeviceAddress(USB_CHARGING_DEVICE_ID *pDevID) |
||
269 | |||
270 | Description: |
||
271 | This interface is used get the address of a specific generic device on |
||
272 | the USB. |
||
273 | |||
274 | Preconditions: |
||
275 | The device must be connected and enumerated. |
||
276 | |||
277 | Parameters: |
||
278 | pDevID - Pointer to a structure containing the Device ID Info (VID, |
||
279 | PID, and device address). |
||
280 | |||
281 | Return Values: |
||
282 | TRUE - The device is connected |
||
283 | FALSE - The device is not connected. |
||
284 | |||
285 | Example: |
||
286 | <code> |
||
287 | USB_CHARGING_DEVICE_ID deviceID; |
||
288 | BYTE deviceAddress; |
||
289 | |||
290 | deviceID.vid = 0x1234; |
||
291 | deviceID.pid = 0x5678; |
||
292 | |||
293 | if (USBHostChargerGetDeviceAddress(&deviceID)) |
||
294 | { |
||
295 | deviceAddress = deviceID.deviceAddress; |
||
296 | } |
||
297 | </code> |
||
298 | |||
299 | Remarks: |
||
300 | None |
||
301 | ***************************************************************************/ |
||
302 | |||
303 | BOOL USBHostChargerGetDeviceAddress(USB_CHARGING_DEVICE_ID *pDevID); |
||
304 | |||
305 | |||
306 | /************************************************************************* |
||
307 | * EOF |
||
308 | */ |
||
309 | |||
310 | #endif |
Powered by WebSVN v2.8.3