static int setupHIDManager(yContextSt *ctx, OSX_HID_REF *hid, char *errmsg) { int c_vendorid = YOCTO_VENDORID; CFMutableDictionaryRef dictionary; CFNumberRef Vendorid; IOReturn tIOReturn; yInitializeCriticalSection(&hid->hidMCS); // Initialize HID Manager hid->manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); // create dictionary to match Yocto devices dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault,1,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks); Vendorid = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &c_vendorid ); CFDictionarySetValue( dictionary, CFSTR( kIOHIDVendorIDKey ), Vendorid ); CFRelease(Vendorid); // register the dictionary IOHIDManagerSetDeviceMatching(hid->manager, dictionary ); // now we can release the dictionary CFRelease(dictionary); // sechedulle the HID Manager with our global run loop IOHIDManagerScheduleWithRunLoop(hid->manager, ctx->usb_run_loop, kCFRunLoopDefaultMode); // Now open the IO HID Manager reference tIOReturn = IOHIDManagerOpen(hid->manager, kIOHIDOptionsTypeNone ); if(kIOReturnSuccess != tIOReturn ||CFGetTypeID(hid->manager) != IOHIDManagerGetTypeID()){ HALLOG("Unable to Open HID Manager"); return YERRMSG(YAPI_NOT_SUPPORTED,"Unable to Open HID Manager"); } return YAPI_SUCCESS; }
int yyySetup(yInterfaceSt *iface,char *errmsg) { char str[32]; yyyInitPktQueue(iface); yInitializeCriticalSection(&iface->yyyCS); if(iface->devref==NULL){ return YERR(YAPI_DEVICE_NOT_FOUND); } IOReturn ret = IOHIDDeviceOpen(iface->devref, kIOHIDOptionsTypeNone); if (ret != kIOReturnSuccess) { YSPRINTF(str,32,"Unable to open device (0x%x)",ret); return YERRMSG(YAPI_IO_ERROR,str); } /* Create the Run Loop Mode for this device. printing the reference seems to work. */ sprintf(str, "yocto_%p", iface->devref); iface->run_loop_mode = CFStringCreateWithCString(NULL, str, kCFStringEncodingASCII); /* Attach the device to a Run Loop */ IOHIDDeviceScheduleWithRunLoop(iface->devref, yContext->usb_run_loop, iface->run_loop_mode); IOHIDDeviceRegisterInputReportCallback( iface->devref, // IOHIDDeviceRef for the HID device (u8*) &iface->tmprxpkt, // pointer to the report data USB_PKT_SIZE, // number of bytes in the report (CFIndex) &Handle_IOHIDDeviceIOHIDReportCallback, // the callback routine iface); // context passed to callback return 0; }
void ySafeMemoryInit(u32 nbentry) { YASSERT(yMap==NULL && yMapSize==0); yInitializeCriticalSection(&yMapCS); yEnterCriticalSection(&yMapCS); yMap = malloc(nbentry *sizeof(YMEM_ENTRY)); if(yMap){ yMapSize = nbentry; memset(yMap,0,nbentry *sizeof(YMEM_ENTRY)); yMapUsed=0; } yLeaveCriticalSection(&yMapCS); }
void yFifoInitEx( #ifdef DEBUG_FIFO const char* fileid, int line, #endif yFifoBuf *buf, u8 *buffer, u16 bufflen) { memset(buf,0,sizeof(yFifoBuf)); buf->buff = buffer; buf->buffsize = bufflen; buf->head = buf->tail = buffer; #ifdef DEBUG_FIFO buf->line = line; buf->fileid = fileid; #endif #ifdef YFIFO_USE_MUTEX yInitializeCriticalSection(&(buf->cs)); #endif }
int yUSB_init(yContextSt *ctx,char *errmsg) { int c_vendorid = YOCTO_VENDORID; IOReturn tIOReturn; CFMutableDictionaryRef dictionary; CFNumberRef Vendorid; if(!yReserveGlobalAccess(ctx)){ return YERRMSG(YAPI_DOUBLE_ACCES,"Another process is already using yAPI"); } ctx->usb_thread_state = USB_THREAD_NOT_STARTED; pthread_create(&ctx->usb_thread, NULL, event_thread, ctx); yInitializeCriticalSection(&ctx->hidMCS); // Initialize HID Manager ctx->hidM = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); // create dictionary to match Yocto devices dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault,1,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks); Vendorid = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &c_vendorid ); CFDictionarySetValue( dictionary, CFSTR( kIOHIDVendorIDKey ), Vendorid ); // register the dictionary IOHIDManagerSetDeviceMatching( ctx->hidM, dictionary ); // now we can release the dictionary CFRelease(dictionary); IOHIDManagerRegisterDeviceRemovalCallback(ctx->hidM,hid_device_removal_callback,ctx); //register hid into read_thead's RunnLoop while(ctx->usb_thread_state != USB_THREAD_RUNNING){ usleep(50000); } IOHIDManagerScheduleWithRunLoop(ctx->hidM, ctx->usb_run_loop, kCFRunLoopDefaultMode); // Now open the IO HID Manager reference tIOReturn = IOHIDManagerOpen( ctx->hidM, kIOHIDOptionsTypeNone ); CFRelease(Vendorid); if(kIOReturnSuccess != tIOReturn ||CFGetTypeID(ctx->hidM) != IOHIDManagerGetTypeID()){ HALLOG("Unable to Open HID Manager"); return YERRMSG(YAPI_NOT_SUPPORTED,"Unable to Open HID Manager"); } return YAPI_SUCCESS; }
int yyyUSB_init(yContextSt *ctx,char *errmsg) { int res; if(!yReserveGlobalAccess(ctx)){ return YERRMSG(YAPI_DOUBLE_ACCES,"Another process is already using yAPI"); } memset(stringCache, 0, sizeof(stringCache)); yInitializeCriticalSection(&ctx->string_cache_cs); res = libusb_init(&ctx->libusb); if(res !=0){ return yLinSetErr("Unable to start lib USB", res,errmsg); } ctx->usb_thread_state = USB_THREAD_NOT_STARTED; pthread_create(&ctx->usb_thread, NULL, event_thread, ctx); //wait thead start while(ctx->usb_thread_state != USB_THREAD_RUNNING){ usleep(50000); } return YAPI_SUCCESS; }