Win HEC Download Win HEC presentations here http

  • Slides: 36
Download presentation
�点�以下�接下� Win. HEC的演�材料 Download Win. HEC presentations here: http: //channel 9. msdn. com/Events/Win. HEC/2015

�点�以下�接下� Win. HEC的演�材料 Download Win. HEC presentations here: http: //channel 9. msdn. com/Events/Win. HEC/2015

Driver. Entry(Driver. Object) { initialize driver_object_config with: Add. Device = On. Device. Add Unload

Driver. Entry(Driver. Object) { initialize driver_object_config with: Add. Device = On. Device. Add Unload = On. Driver. Unload return Wdf. Driver. Create( Driver. Object, driver_object_config ) // creates WDFDRIVER }

On. Device. Add(Driver. Object, Device. Info) { initialize obj_attributes with: Context. Type = My.

On. Device. Add(Driver. Object, Device. Info) { initialize obj_attributes with: Context. Type = My. Context wdf. Device = Wdf. Device. Create(&obj_attributes, Device. Info) // init context object allocated with device context = Get. Context(wdf. Device) context->Wdf. Device = wdf. Device return status } struct My. Context { WDFDEVICE Device; BYTE Reading. Buffer[6]; }; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(My. Context, Get. My. Context);

[Version] Signature = "$Windows NT$" Class = Sensor Class. Guid= {5175 D 334 -C

[Version] Signature = "$Windows NT$" Class = Sensor Class. Guid= {5175 D 334 -C 371 -4806 -B 3 BA-71 FD 53 C 9258 D} Provider=%Manufacturer. Name% Catalog. File=ADXL 345 Acc. cat Driver. Ver= [Manufacturer] %Manufacturer. Name%=Standard, NT$ARCH$ [Standard. NT$ARCH$] %Device. Name%=My. Device_Install, ACPIADXL 345 Acc … [Strings] Manufacturer. Name="Me" Device. Name="ADXL 345 Acc Device" MSDN

On. Prepare. Hardware(Device, Resource. List) { i 2 c_id = find i 2 c

On. Prepare. Hardware(Device, Resource. List) { i 2 c_id = find i 2 c resource in Resource. List // connect to I 2 C i 2 c_path = RESOURCE_HUB_CREATE_PATH_FROM_ID(i 2 c_id) device. Context->Io. Target = Wdf. Io. Target. Create(Device) Wdf. Io. Target. Open(context->Io. Target, i 2 c_path) }

On. D 0 Entry(Device) { Write. I 2 CRegister(ADXL 345_INT_ENABLE, 0); Write. I 2

On. D 0 Entry(Device) { Write. I 2 CRegister(ADXL 345_INT_ENABLE, 0); Write. I 2 CRegister(ADXL 345_POWER_CTL, ADXL 345_POWER_CTL_MEASURE); Read. I 2 CRegister(ADXL 345_DATA_X 0, 6 bytes); } On. D 0 Exit(Device, New. Power. State) { Write. I 2 CRegister(ADXL 345_INT_ENABLE, 0); Write. I 2 CRegister(ADXL 345_POWER_CTL, ADXL 345_POWER_CTL_STANDBY); }

DEFINE_GUID(GUID_Adxl 345_Interface, {c 2506459 -cded-40 ab-8 ead-0 b 9 ad 1 db 69 e

DEFINE_GUID(GUID_Adxl 345_Interface, {c 2506459 -cded-40 ab-8 ead-0 b 9 ad 1 db 69 e 4}) On. Device. Add(Driver. Object, Device. Info) { // create WDFDEVICE // … Wdf. Device. Create. Device. Interface( device, GUID_Adxl 345_Interface ) … }

On. Device. Add(Device) { // Create device object & context … initialize queue_config with:

On. Device. Add(Device) { // Create device object & context … initialize queue_config with: Dispatch. Type = Sequential Power Managed = true IO Read Callback = On. Read Wdf. Io. Queue. Create(Device, queue_config) … }

On. Read(Queue, Request, Length) { data_buffer = get Request output buffer if data_buffer too

On. Read(Queue, Request, Length) { data_buffer = get Request output buffer if data_buffer too small complete request with error & return initialize i 2 c_sequence buffer to read 6 bytes from ADXL 345_DATA_X 0 (data register index) into context->Reading. Buffer Reformat Request as I 2 C Sequence ioctl Wdf. Request. Set. Completion. Routine(Request, On. Data. Read. Complete) Wdf. Request. Send(Request, context->Io. Target) }

On. Data. Read. Complete(Request, Completion. Info) { if (Completion. Info->Status == success && Completion.

On. Data. Read. Complete(Request, Completion. Info) { if (Completion. Info->Status == success && Completion. Info->Bytes. Read == 6) define local tmp of type SENSOR_READING read_data_buffer = get Request output buffer convert context->Reading. Buffer into tmp copy tmp into read_data_buffer SENSOR_READING request. Status = success bytes. Returned = sizeof(SENSOR_READING) else request. Status = error code bytes. Returned = 0 Wdf. Request. Complete(Request, request. Status, bytes. Returned) }