Академический Документы
Профессиональный Документы
Культура Документы
Class Objectives
1541 USB2
Slide
Agenda
1541 USB2
Slide
Agenda (Continued)
Obtaining a Handle
Handling Attach/Detach Events
1541 USB2
Slide
Performance
PIC32
High Performance, Pin Compatible to PIC24F
80 MHz, 1.53 DMIPS/MHz
Up to 80 MIPS
64- & 100-Pin Packages
Up to 512 KB Flash
Up to 32 KB RAM
USB 2.0 Device, Embedded Host, OTG
PIC24F
Mid-Range, Capacitive-Touch Capable
Up to 16 MIPS
64-, 80- & 100-Pin Packages
Up to 256 KB Flash
Up to 16 KB RAM
USB 2.0 Device, Embedded Host, OTG
PIC18F
32-bit
16-bit
8-bit
Migration
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
Class Folders
C:\Masters\1541
\Development Tools
\Lab1..Lab3
\Device
\Device Solution
\Host
\Host Solution
\Microchip
\Presentation and Handouts
\Users Guides & Data Sheets
1541 USB2
Slide
Application Overview
(Thermometer)
Outline
- Application Overview
Application Requirements
0 get Version
1 get Temperature
2 get Potentiometer
1541 USB2
Slide
On Board Debugger
(provides SYS CLK)
1541 USB2
Slide
PIC18F46J50
1541 USB2
Slide
10
1541 USB2
Slide
11
1541 USB2
Slide
12
1541 USB2
Slide
13
I/O Expansion
1541 USB2
Slide
14
S1 Menu Button
1541 USB2
Slide
15
1541 USB2
Slide
16
Potentiometer
1541 USB2
Slide
17
1541 USB2
Slide
18
PIC18F46J50 Features
1541 USB2
Slide
19
Mouse
Printer
1541 USB2
Speaker
Slide
21
Logical Device
Up to 16 bidirectional pipelines
End Points
Device
EP0
1541 USB2
Slide
22
Enumeration
Enumeration process
1541 USB2
Slide
23
Transfer types
Control
Interrupt
Bulk
Bus configuration
Guaranteed integrity
Isochronous
Guaranteed timeliness
1541 USB2
Slide
24
Transfer/
Endpoint Type
Polling Interval
% Reserved
BW/Frame for all
transfers of this
type
Max. # Data
Bytes/Frame/Endpoint (Max#
transactions per frame @ Max Ep
Size)*
Data
Integrity
Interrupt
Fixed, Periodic
90
64 (1 x 64)
Yes
Isochronous
Fixed, Periodic
90
1023 (1 x 1023)
No
Bulk
Yes
Control
Variable
10
Yes
1541 USB2
Slide
25
Data Glove
Ethernet
Adapter
Mouse
External
Hard Drive
PICkit 2
Starter Kit
Joystick
COM Port
MCP2200
Communication Device
Class (CDC)
Keyboard
ICD2
Custom Class
(Vendor Class)
1541 USB2
Slide
26
1541 USB2
Slide
27
HID
mchpusb.sys
CDC
WinUSB
LibUSB
(v1.0.0.6)
Driver support built
into Windows
Yes
Need .inf
No
Need .inf
No
64-bit PC Support
Yes
Yes
Yes
Yes
Yes
XP Ready
Yes
Yes
Yes
Yes
Yes
Vista/Win7 Ready
Yes
Yes
Yes
Yes
No**
Control
Yes
No
Yes
Yes
Yes
Interrupt
Yes
No
Yes
Yes
Yes
Bulk
No
Yes
Yes
Yes
Yes
64KB/s
~64kByte/s
~1.0 MB/s
~1.0MB/s
~1.0MB/s
Transfer Types
Max Speed
1541 USB2
Slide
28
Downloading the
Microchip Application Libraries
1541 USB2
Slide
30
1541 USB2
Slide
31
1541 USB2
Slide
32
MCHPFSUSB Framework
- Supported Platforms -
1541 USB2
Slide
33
General structure
./USB/Your application
main.c
usb_descriptors.c
Editable files
HardwareProfile.h
usb_config.h
./Microchip
/Include
/USB
/Common
/
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
34
MCHPFSUSB Framework
- Editable Files
usb_descriptors.c
/* Device Descriptor */
ROM USB_DEVICE_DESCRIPTOR device_dsc=
{
0x12,
// Size of this descriptor (byte)
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
0x0200,
// USB Spec Release Number
My_Class_code,
// Class code
My_Subclass_code,
// Subclass code
My_Protocol_code,
// Protocol code
EP0_BUFF_SIZE,
// Max packet size for EP0
0x0000,
// Vendor ID
0x0000,
// Product ID
1541 USB2
Slide
35
MCHPFSUSB Framework
- Editable Files
HardwareProfile.h
// #define USE_SELF_POWER_SENSE_IO
#define tris_self_power
TRISAbits.TRISA2
#if defined (USE_SELF_POWER_SENSE_IO)
#define self_power
PORTAbits.RA2
#else
#define self_power
1
#endif
//#define USE_USB_BUS_SENSE_IO
#define tris_usb_bus_sense
TRISAbits.TRISA1
#if defined (USE_USB_BUS_SENSE_IO)
#define USB_BUS_SENSE
PORTAbits.RA1
#else
#define USB_BUS_SENSE
1
#endif
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
// Input
// Input
Slide
36
MCHPFSUSB Framework
- Editable Files
usb_config.h
USB Definitions
Device Class Usage
Endpoint Allocation
MCHPFSUSB Framework
- Editable Files
main.c
Contains UserInit()
Main Loop
USBDeviceTasks()
Polled or Interrupt-driven
ProcessIO()
Callback function()
1541 USB2
Slide
38
MCHPFSUSB Framework
- Polled Program Flow -
Reset
main()
InitializeSystem()
while(1)
Cooperative
Multitasking!!
USBDeviceTasks()
USB Stack
ProcessIO()
Your application
code
Function
Services
CDCTxService()
MSDTasks()
Re-arm OUT Endpoint
(HID & Generic)
No blocking
functions.
Use state
machine.
1541 USB2
Slide
39
MCHPFSUSB Framework
- Interrupt Program Flow -
Reset
main()
USB Interrupt
Context
InitializeSystem()
You edit
UserInit()
USBDeviceAttach()
while(1)
USBDeviceTasks()
ProcessIO()
Function
Services
1541 USB2
Your application
code
CDCTxService()
MSDTasks()
Re-arm OUT Endpoint
(HID & Generic)
Slide
40
Cooperative Multitasking
State Machine
Main Loop
Task B - 100us
1541 USB2
Slide
41
Code Example
Main.c
#include ./USB/usb.h
#include ./USB/usb_function_cdc.h
#include HardwareProfile.h
void UserInit(void){
void ProcessIO(void){
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
CDCTxService();
}
static void InitializeSystem(void){
#if define
#endif
UserInit();
USBDeviceInit();
}
int main(void){
InitializeSystem();
while(1){
USBDeviceTasks();
ProcessIO();
}
}
Conditional compiling
(No need to change)
No need to change
1541 USB2
USBDeviceTasks()
is executed into an ISR
(High Priority PIC18,
_USB1Interrupt()
PIC24 & PIC32)
Slide
42
CALLBACK
FUNCTION
MAIN
PROGRAM
USB firmware
stack
LIBRARY
FUNCTION
1541 USB2
Slide
43
1541 USB2
Slide
45
1541 USB2
Slide
46
Beagle 480
(www.totalphase.com)
Non-obtrusive real-time
monitoring
Monitors USB 2.0 LS,
FS, HS
Protocol-level decoding
Real-time filtering
Data Center Software
runs on PC, Linux &
MAC
US $1200
1541 USB2
Slide
47
Capturing a transaction
1541 USB2
Slide
48
Outline
1541 USB2
Slide
50
1541 USB2
Slide
51
Microsoft Visual
Basic .NET
C++
C#
Linux
1541 USB2
Microsoft .NET
Framework
Novells Mono Project
Slide
52
A virtual machine
Microsoft Visual
Basic .NET
C++
C#
Loads .NET
assemblies,
Verifies that the IL
code is safe to
execute.
Linux
1541 USB2
Argument type
checking
Invokes a JIT
compiler to compile
the IL to native code
before execution
Garbage collection
Slide
53
Microsoft Visual
Basic .NET
C++
C#
A set of thousands of
classes that provide
system services
Wrap Win32 APIs &
more
Examples
System::IO
Windows
Linux
System::Windows::
Forms
1541 USB2
Classes for
File/Stream IO
54
1541 USB2
Slide
55
#using System.Windows.Forms.dll
using namespace System::Windows::Forms;
int main()
{
MessageBox::Show(Hello, World!);
// Fully-qualified name:
// System::Windows::Forms::MessageBox:Show(Hello, World!);
}
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
56
Microsoft Visual
Basic .NET
C++
C#
Linux
1541 USB2
58
Base Class
C#
C++/CLI
System::Byte
Visual Basic
2008
Byte
byte
unsigned char
System::SByte
SByte
sbyte
char
System::Int16
Short
short
short
System::Int32
Integer
int
int
System::Int64
Long
long
long long
System::Single
Single
float
float
System::Double
Double
double
double
System::String
String
string
String^
System::Decimal
Decimal
decimal
Decimal
1541 USB2
Slide
59
C#
VC++ .NET
vbc Compiler
csc Compiler
cpp Compiler
Unmanaged
Code
MSIL
CLR Services
1541 USB2
Slide
60
Managed
Unmanaged (Native)
1541 USB2
Slide
61
1541 USB2
Slide
62
1541 USB2
Slide
63
Free Download
http://www.microsoft.com/express/
1541 USB2
Slide
64
1541 USB2
Slide
65
/clr:pure
/clr:safe
Produces
Native mode executable. Compiles
classic C/C++ code+libraries (no
C++/CLI features)
Mixed mode assembly (contains native
and MSIL code). Compiles classic C/C++
& C++/CLI code
MSIL-only assembly (no native code).
Compiles classic C/C++ & C++/CLI code.
Can use classic types compiled to MSIL
MSIL-only verifiable assembly. Compiles
classic C/C++ & C++/CLI code. Can only
use .NET types.
1541 USB2
Slide
66
1541 USB2
Slide
67
1541 USB2
Slide
68
P/Invoke Example
Create a managed entry point for calling
Win32 API
RegisterDeviceNotification(..)
Step 1.
Set compilation mode to \clr, \clr:pure
1541 USB2
Slide
69
P/Invoke Example
Step 2.
From Visual Studio Help, search for & identify the
function signature, dll, and header file
HDEVNOTIFY WINAPI RegisterDeviceNotification(
HANDLE hRecipient,
LPVOID NotificationFilter,
DWORD Flags);
Header
Library
User32.lib
DLL
User32.dll
RegisterDeviceNotificationW
(Unicode) and
RegisterDeviceNotificationA
(ANSI)
1541 USB2
Slide
70
P/Invoke Example
Step 3.
#include the windows header file(s) & import
the namespace containing the DllImport
method
#include <Windows.h>
using namespace
System::Runtime::InteropServices;
1541 USB2
Slide
71
P/Invoke Example
Step 4.
Create a managed function declaration, and use
attributes to associate it to an existing native function
[DllImport(User32.dll" , CharSet = CharSet::Unicode,
EntryPoint="RegisterDeviceNotificationW")]
extern "C" HDEVNOTIFY WINAPI
RegisterDeviceNotificationUM(
HANDLE hRecipient,
// Input: The window that will receive the
// notification.
LPVOID NotificationFilter,
// Input: Pointer to a
// DEV_BROADCAST_DEVICEINTERFACE structure
DWORD Flags
// Input: Indicate whether the handle is for a
// window or service status
);
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
72
Summary
1541 USB2
Slide
73
Outline
1541 USB2
Slide
75
1541 USB2
Slide
76
HID limitations
1541 USB2
Slide
77
1541 USB2
Slide
78
1541 USB2
data
Slide
79
usb_config.h
/* HID */
#define HID_INTF_ID
#define HID_EP
#define HID_INT_OUT_EP_SIZE
#define HID_INT_IN_EP_SIZE
#define HID_NUM_OF_DSC
#define HID_RPT01_SIZE
0x00
1 Leave at 1
3
3
1
29
1541 USB2
Slide
80
HIDRxPacket(HID_EP,(BYTE*)
&ReceivedDataBuffer,64);
HIDRxHandleBusy(USBOutHandle)
1541 USB2
Slide
81
1541 USB2
Slide
82
HIDTxHandleBusy(USBInHandle
Is endpoint available?
HIDTxPacket(HID_EP,
(BYTE*)&ToSendDataBuffer,64);
1541 USB2
Slide
83
if(!HIDTxHandleBusy(USBInHandle))
USBInHandle =
HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer,64);
break;
1541 USB2
Slide
84
void
bool
bool
bool
1541 USB2
Slide
85
1541 USB2
Slide
86
1541 USB2
Slide
87
Writing A Report
bool HIDWriteReport (buffer,
len);
Buffer to transmit
len Length of valid data in buffer.
Remainder of buffer padded to actual
HID buffer length
Returns True or False indicating
transfer success/failure
The device firmware must implement a Generic HID
report descriptor as shown earlier!
1541 USB2
Slide
88
Reading a Report
bool HIDReadReport (buffer);
1541 USB2
Slide
89
Documentation
C:\Microchip Solutions\Microchip\Help\
HID Class DLL.chm
1541 USB2
Slide
90
Lab 1
HID Class Thermometer
Lab 1
Objective
1541 USB2
Slide
92
HID Summary
- Benefits/Drawbacks
Easy installation
no .inf file
driver built into OS
1541 USB2
Slide
93
Outline
WinUSB Conclusion
1541 USB2
Slide
95
Vendor Class
Firmware Structure
Reset
main()
InitializeSystem()
You Edit
UserInit()
main()
USB Interrupt
Context
ProcessIO()
USBDeviceTasks()
You edit in
main.c/user.c
Synchronous model
1541 USB2
Slide
96
USBGenWrite(ep,pSrc,len);
USBGenRead(ep,pSrc,len)
USBHandleBusy(USBGenericInHandle)
1541 USB2
Slide
97
Inbound data
USBGenRead(ep,pSrc,len)
USBHandleBusy(USBGenericOutHandle)
1541 USB2
Slide
98
1541 USB2
Slide
99
Outbound Data
USBGenWrite(ep,pSrc,len)
USBHandleBusy(USBGenericInHandle)
1541 USB2
Slide
100
if(!USBHandleBusy(USBGenericInHandle))
USBGenericInHandle =
USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket,USBGEN_
EP_SIZE);
break;
1541 USB2
Slide
101
1541 USB2
Slide
102
Endpoint Descriptors
File usb_descriptors.c
/* Endpoint Descriptor */
0x07,
USB_DESCRIPTOR_ENDPOINT,
_EP01_OUT,
_BULK,
USBGEN_EP_SIZE,0x00,
1,
/*sizeof(USB_EP_DSC)*/
//Endpoint Descriptor
//EndpointAddress
//Attributes
//size
//Interval
0x07,
USB_DESCRIPTOR_ENDPOINT,
_EP01_IN,
_BULK,
USBGEN_EP_SIZE,0x00,
1
/*sizeof(USB_EP_DSC)*/
//Endpoint Descriptor
//EndpointAddress
//Attributes
//size
//Interval
(Interrupt)
1541 USB2
Slide
103
WinUSB
1541 USB2
Slide
105
WinUSB Architecture
No need to write
your own driver
FULL speed
Works with XP and
Vista/7
One .inf file
Application
WinUSB
DLL
User mode
WinUSB.SYS
Vendor
Component
USB Stack
USB Device
(PIC18F14K50)
Kernel mode
Microsoft
Existing
Component
1541 USB2
Microsoft
New
Component
Device
Slide
106
WinUSB features
WinUSB supports:
1541 USB2
Slide
107
WinUsb_Initialize
WinUsb_WritePipe
WinUsb_ReadPipe
WinUSB_Free
*See http://msdn.microsoft.com/en-us/library/ff540046(v=VS.85).aspx#winusb
for the complete list of WinUsb routines.
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
108
WinUsb_Initialize
DeviceHandle [in]
The handle to the device that CreateFile returned.
InterfaceHandle [out]
The WinUSB handle for the device. All other WinUSB
routines require this handle as input.
1541 USB2
Slide
109
WinUsb_WritePipe
InterfaceHandle [in]
WinUSB handle, for the device, which is returned by WinUsb_Initialize.
PipeID [in]
An 8-bit value that consists of a 7-bit address and a direction bit.
Buffer [in]
A caller-allocated buffer that contains the data to write.
BufferLength [in]
The number of bytes to write. This number must be less than or equal to the size, in bytes, of Buffer.
LengthTransferred [out, optional]
A pointer to a ULONG variable that receives the actual number of bytes that were written to the pipe.
Overlapped [in, optional]
An optional pointer to an OVERLAPPED structure, which is used for asynchronous operations. If this parameter is
specified, WinUsb_WritePipe immediately returns, and the event is signaled when the operation is complete.
1541 USB2
Slide
110
WinUsb_ReadPipe
InterfaceHandle [in]
WinUSB handle, for the device, which is returned by WinUsb_Initialize.
PipeID [in]
An 8-bit value that consists of a 7-bit address and a direction bit.
Buffer [in]
A caller-allocated buffer that receives the data that is read.
BufferLength [in]
The maximum number of bytes to read. This number must be less than or equal to the size, in bytes, of Buffer.
LengthTransferred [out, optional]
A pointer to a ULONG variable that receives the actual number of bytes that were copied into Buffer.
Overlapped [in, optional]
An optional pointer to an OVERLAPPED structure, which is used for asynchronous operations. If this parameter is
specified, WinUsb_ReadPipe returns immediately rather than waiting synchronously for the operation to complete
before returning. An event is signaled when the operation is complete.
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
111
WinUsb_Free
InterfaceHandle [in]
WinUSB handle, for the device, which is returned by
WinUsb_Initialize
1541 USB2
Slide
112
http://connect.microsoft.com
See Appendix D for detailed instructions
http://msdn.microsoft.com/enus/subscriptions/default.aspx
Default folder:
C:\WinDDK\buildnumber
1541 USB2
Slide
114
Click
ProjectPropertiesConfigurat
ion PropertiesGeneralCommon
Language Runtime
Support/clr:pure
1541 USB2
Slide
115
C:\WinDDK\7600.16385.0\inc\ddk
C:\WinDDK\7600.16385.0\inc\api
1541 USB2
Slide
116
C:\WinDDK\7600.16385.0\inc\ddk
C:\WinDDK\7600.16385.0\inc\api
1541 USB2
Slide
117
#include <windows.h>
#include <setupapi.h>
#include <winusb.h>
1541 USB2
Slide
118
1541 USB2
Slide
119
4-Step Procedure:
1.
2.
3.
4.
1541 USB2
Slide
120
WinUSB - Sample
1
WinUsb_Initialize(deviceHandle, &interfaceHandle);
// pass the deviceHandle and you get the Interface Handle
WinUSB_WritePipe( interfaceHandle,
0x01,
// endpoint address for bulk out
output,
// output buffer
sizeof ( output ),
// output buffer length
&transferredBytes,
// bytes transferred
NULL);
// optional OVERLAPPED structure
1541 USB2
Slide
121
Create a package**:
WinUSBCoInstaller2.dll (Installs
WinUSB files on the target system)
WdfCoInstaller01009.dll* and
WUDFUpdate_01009.dll* (Kernel-mode coinstallers)
.inf file that installs winusb.sys as the
devices function driver
*The actual name might vary. The name is given for version 1.9
** XP Only. Windows Vista/7 already comes with the .dll & .sys - only requires the .inf
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
122
Sample .inf
C:\Masters\1541\Lab2\Host\Driver and
inf\MCHPWinUSBDevice_v2.inf
1541 USB2
Slide
123
Modifiable sections in
MCHPWinUSBDevice.inf
[Manufacturer]
%MFGNAME% = MyDevice_WinUSB,NTx86,NTamd64
[MyDevice_WinUSB.NTx86]
%DESCRIPTION% =USB_Install, USB\VID_04D8&PID_0053
[MyDevice_WinUSB.NTamd64]
%DESCRIPTION% =USB_Install, USB\VID_04D8&PID_0053
[Dev_AddReg]
HKR,,DeviceInterfaceGUIDs,0x10000,"{58D07
210-27C1-11DD-BD0B-0800200C9a66}"
1541 USB2
Slide
124
Modifiable sections in
MCHPWinUSBDevice.inf
[Strings]
1541 USB2
Slide
125
Lab 2
Custom Class Thermometer
Using WinUSB
Lab 2
1541 USB2
Slide
127
WinUSB - Conclusion
1541 USB2
Slide
128
Overview
instanceID
Format: USB\Vid_04d8&Pid_0053\1234
1541 USB2
Slide
130
1541 USB2
Slide
131
1541 USB2
Slide
132
A Devices deviceinstanceID
Before/After adding a Serial Number
1541 USB2
Slide
133
StartRunRegedit
\HKLM\SYSTEM\CurrentControlSet\Enum\USB\<VID_PID>
\<serial number/USB Port>
1541 USB2
Slide
134
Driver Key
\HKLM\SYSTEM\CurrentControlSet\Control\Class\<ClassGUID>\
<driver#>
1541 USB2
Slide
135
What is a GUID?
4D1E55B2-F16F-11CF-88CB-001111000030
1541 USB2
Slide
136
http://www.guidgen.com/
http://www.newguid.net/
1541 USB2
Slide
137
Defining a GUID
#include <Windows.h>
// declare/initialize a HID device
// interface class GUID
GUID InterfaceClassGuid = {0x4d1e55b2,
0xf16f, 0x11cf, 0x88, 0xcb, 0x00,
0x11, 0x11, 0x00, 0x00, 0x30};
1541 USB2
Slide
138
Detecting Devices
Obtaining a Handle
Handling Attach/Detach Events
1541 USB2
Slide
140
1541 USB2
Slide
141
1541 USB2
Slide
142
1541 USB2
Slide
143
1541 USB2
Slide
144
1541 USB2
Slide
145
SetupDiGetClassDevs
Usage
HDEVINFO hDevInfo = SetupDiGetClassDevs(
&InterfaceClassGUID,
0,
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE
);
1541 USB2
Slide
146
SetupDiEnumDeviceInfo
Usage
}
2011 Microchip Technology Incorporated. All Rights Reserved.
1541 USB2
Slide
147
SetupDiGetDeviceInstanceID
Usage
1541 USB2
Slide
148
SetupDiEnumDeviceInterfaces
BOOL SetupDiEnumDeviceInterfaces(
__in
HDEVINFO DeviceInfoSet,
__in_opt PSP_DEVINFO_DATA DeviceInfoData,
__in
const GUID *InterfaceClassGuid,
__in
DWORD MemberIndex,
__out
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData
);
1541 USB2
Slide
149
SetupDiGetDeviceInterfaceDetail
BOOL SetupDiGetDeviceInterfaceDetail(
__in
HDEVINFO DeviceInfoSet,
__in
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
__out_opt PSP_DEVICE_INTERFACE_DETAIL_DATA
DeviceInterfaceDetailData,
__in
DWORD DeviceInterfaceDetailDataSize,
__out_opt PDWORD RequiredSize,
__out_opt PSP_DEVINFO_DATA DeviceInfoData
);
1541 USB2
Slide
150
SetupDiEnumDeviceInfo
SetupDiGetDeviceInstanceID
Match?
SetupDiEnumDeviceInterfaces
SetupDiGetDeviceInterfaceDetail
1541 USB2
Slide
151
FindMyDevice
1541 USB2
Slide
152
Lab 3a
Objective
Device
Host
1541 USB2
Slide
153
Lab 3a
Solution (main.cpp)
#include <wchar.h>
#include <windows.h>
#include FindMyDevice.h
1541 USB2
Slide
154
Lab 3a
1541 USB2
Slide
155
Obtaining a Handle
CreateFile
1541 USB2
Slide
157
CreateFile
1541 USB2
Slide
158
Windows Messages
1541 USB2
Slide
160
WndProc(m) Method
1541 USB2
Slide
161
Handling Attach/Detach
Polling
Event-driven
1541 USB2
Slide
162
1541 USB2
Slide
163
Library
User32.lib
DLL
User32.dll
RegisterDeviceNotificationW
(Unicode) and
RegisterDeviceNotificationA
(ANSI)
1541 USB2
Slide
164
RegisterDeviceNotification()
Parameters
HANDLE hRecipient
LPVOID NotificationFilter
Pointer to a
DEV_BROADCAST_DEVICEINTERFACE
structure that holds information about the
request
DWORD Flags
1541 USB2
Slide
165
P/Invoke Signature
[DllImport(User32.dll" , CharSet = CharSet::Unicode,
EntryPoint="RegisterDeviceNotificationW")]
extern "C" HDEVNOTIFY WINAPI RegisterDeviceNotificationUM(
HANDLE hRecipient,
// Input: The window that will receive the notification.
LPVOID NotificationFilter,
// Input: Pointer to a DEV_BROADCAST_DEVICEINTERFACE structure
DWORD Flags
// Input: Indicate whether the handle is for a window or
// service status
);
1541 USB2
Slide
166
1541 USB2
Slide
167
BOOL FindMyDevice(...)
Call System::Windows::Forms::WndProc(m)
to process any other messages
1541 USB2
Slide
168
Lab 3b
Device
Host
1541 USB2
Slide
169
Lab 3b
Form Design
Event Triggers
WM_DEVICECHANGE
on/off
1541 USB2
Slide
170
System::Controls:Forms:Wndproc()
1541 USB2
Slide
171
Detecting Devices
- Summary -
Obtaining a Handle
SetupDixxx(..)
CreateFile(..)
RegisterDeviceNotification(..)
WndProc()
1541 USB2
Slide
172
Summary/Resources
1541 USB2
Slide
173
1541 USB2
Slide
174
Summary
Today we covered:
1541 USB2
Slide
175
Additional Resources
Books
Weblinks
www.usb.org/phpbb/
forum.microchip.com
www.microchip.com/usb
www.microsoft.com/whdc/connect/usb/winusb_howto.mspx
www.usb.org (USB Spec, class definitions)
www.lvr.com (USB Examples)
www.beyondlogic.org/usbnutshell/usb1.htm (Tutorial)
Forums
www.softwaretrainingacademy.com
App Notes
1541 USB2
Slide
176
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC, KeeLoq, KeeLoq
logo, MPLAB, PIC, PICmicro, PICSTART, PIC32 logo, rfPIC and UNI/O are
registered trademarks of Microchip Technology Incorporated in the U.S.A.
and other countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor, MXDEV,
MXLAB, SEEVAL and The Embedded Control Solutions Company are
registered trademarks of Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, chipKIT, chipKIT logo,
CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial Programming,
ICSP, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK,
mTouch, Omniscient Code Generation, PICC, PICC-18, PICDEM,
PICDEM.net, PICkit, PICtail, REAL ICE, rfLAB, Select Mode, Total
Endurance, TSHARC, UniWinDriver, WiperLock and ZENA are trademarks
of Microchip Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated in the
U.S.A.
All other trademarks mentioned herein are property of their respective
companies.
2011, Microchip Technology Incorporated, All Rights Reserved.
1541 USB2
Slide
177