30#define MODNAME "PS2 USB camera driver"
34#define BIND_RPC_ID 0x00FD000 +2
35#define DRIVER_VERSON_MAJOR 1
36#define DRIVER_VERSON_MINOR 0
38#define MAX_CAM_DEVICE 2
39#define MAX_CAM_DEVICE_HANDLE 2
46static int maintain_thread;
53 0, 0, 0, 0, 0, NULL };
58char irx_initialized = 0;
69int _start(
int argc,
char *argv[])
82 param.thread = rpcMainThread;
84 param.stacksize = 0x800;
88 th = CreateThread(¶m);
93 return MODULE_RESIDENT_END;
97 return MODULE_NO_RESIDENT_END;
114 printf(
"PS2 USB Camera Driver v.%d.%d ((C) www.ps2dev.org)\n",DRIVER_VERSON_MAJOR,DRIVER_VERSON_MINOR);
117 memset(&Camera[0], 0,
sizeof(Camera));
118 memset(&CamHandle[0], 0,
sizeof(CamHandle));
120 for(i=0;i<MAX_CAM_DEVICE_HANDLE;i++)
122 CamHandle[i].fd = i+1;
132 ps2cam_sema = CreateSema(&sema);
136 return sceUsbdRegisterLdd(&cam_driver);
152 dev = sceUsbdScanStaticDescriptor(devId, NULL, USB_DT_DEVICE);
153 conf = sceUsbdScanStaticDescriptor(devId, dev, USB_DT_CONFIG);
162 for(i=0;i<MAX_CAM_DEVICE;i++)
164 if(Camera[i].status==0)
count++;
167 if(
count <= 0)
return 0;
170 if(intf->bInterfaceClass == USB_CLASS_VENDOR_SPEC)
225 printf(
"camera was connected\n");
229 dev = sceUsbdScanStaticDescriptor(devId, NULL, USB_DT_DEVICE);
231 intf0 = sceUsbdScanStaticDescriptor(devId, dev, USB_DT_INTERFACE);
232 intf1 = sceUsbdScanStaticDescriptor(devId, intf0, USB_DT_INTERFACE);
240 for(i=0;i<MAX_CAM_DEVICE;i++)
242 if(Camera[i].status == 0)
257 cam->device_id = devId;
259 cam->
controll = sceUsbdOpenPipe(devId, NULL);
260 cam->
stream = sceUsbdOpenPipe(devId, endp1);
261 cam->stream_pocket_size = (endp1->wMaxPacketSizeHB * 256 + endp1->wMaxPacketSizeLB);
280 param.stacksize = 0x800;
283 maintain_thread = CreateThread(¶m);
286 StartThread(maintain_thread, cam);
302 printf(
"camera was unplugged\n");
305 for(i=0;i<MAX_CAM_DEVICE;i++)
307 if(Camera[i].device_id == devId)
321 for(i=0;i<MAX_CAM_DEVICE_HANDLE;i++)
323 if(CamHandle[i].cam == cam)
325 CamHandle[i].status = -1;
333 sceUsbdClosePipe(cam->
stream );
362void rpcMainThread(
void* param)
371 sceSifSetRpcQueue(&rpc_queue, tid);
372 sceSifRegisterRpc(&rpc_server, BIND_RPC_ID, (
void *) rpcCommandHandler, (u8 *) &_rpc_buffer, 0, 0, &rpc_queue);
373 sceSifRpcLoop(&rpc_queue);
384 unsigned char *temp_str;
409 d = sceUsbdScanStaticDescriptor(cam->device_id, NULL, USB_DT_DEVICE);
410 temp_str = AllocSysMemory(0, 128, 0);
413 printf(
"cam initialized(%s)\n",temp_str);
414 FreeSysMemory(temp_str);
418 DeleteThread(maintain_thread);
434 WaitSema(ps2cam_sema);
440 printf(
"Usb: Error sending set_configuration\n");
444 WaitSema(ps2cam_sema);
447 SignalSema(ps2cam_sema);
456 static int width,height;
467 setReg8(dev,EYETOY_GPIO_IO_CTRL0, 0xee);
485 setReg8(dev, EYETOY_CREG_PWDN, 0x03);
486 setReg8(dev, EYETOY_CREG_EN_CLK0, 0x9f);
487 setReg8(dev, EYETOY_CREG_EN_CLK1, 0x0f);
494 setReg8(dev, EYETOY_CREG_AUDIO_CLK, 0x02);
495 setReg8(dev, EYETOY_IREG_FRAR, 0x1f);
501 setReg8(dev, EYETOY_CREG_CAMERA_CLK,0x04);
528 setReg8(dev, EYETOY_IREG_H_SIZE, width>>4);
529 setReg8(dev, EYETOY_IREG_V_SIZE, height>>3);
531 setReg8(dev, EYETOY_IREG_X_OFFSETL, 0x00);
532 setReg8(dev, EYETOY_IREG_X_OFFSETH, 0x00);
533 setReg8(dev, EYETOY_IREG_Y_OFFSETL, 0x00);
534 setReg8(dev, EYETOY_IREG_Y_OFFSETH, 0x00);
537 camSetDIVIDER(dev, 1, 0, 1, 0);
538 setReg8(dev, EYETOY_IREG_FORMAT, 0x03);
573 printf(
"callback: result= %d, bytes= %d, arg= %p \n", resultCode, bytes, arg);
575 SignalSema(ps2cam_sema);
584 WaitSema(ps2cam_sema);
586 ret = sceUsbdControlTransfer(dev->
controll, USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, 0, (
unsigned short)reg_id, 1, &value,
PS2CamCallback, (
void*)ps2cam_sema);
590 printf(
"sceUsbdControlTransfer failed in 'setReg8'.\n");
595 WaitSema(ps2cam_sema);
598 SignalSema(ps2cam_sema);
610 WaitSema(ps2cam_sema);
612 ret = sceUsbdControlTransfer(dev->
controll,USB_DIR_IN|USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, 0,(
unsigned short)reg_id, 1, value,
PS2CamCallback, (
void*)ps2cam_sema);
616 printf(
"sceUsbdControlTransfer failed in 'getRegValue'.\n");
621 WaitSema(ps2cam_sema);
625 SignalSema(ps2cam_sema);
636 unsigned char current,
final;
638 ret =
getReg8(dev, reg_id, ¤t);
640 if (ret < 0)
return -1;
644 final = current | value;
646 ret =
setReg8(dev, reg_id,
final);
650int setReg16(
CAMERA_DEVICE *dev,
unsigned char reg_id,
unsigned short value)
654 WaitSema(ps2cam_sema);
656 ret = sceUsbdControlTransfer(dev->
controll,USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, 0, (
unsigned short)reg_id, 2, &value,
PS2CamCallback, (
void*)ps2cam_sema);
661 printf(
"Usb: setReg16 Error (%d)\n",ret);
664 WaitSema(ps2cam_sema);
667 SignalSema(ps2cam_sema);
676 static char buff[50];
681 WaitSema(ps2cam_sema);
684 ret = sceUsbdControlTransfer(dev->
controll, 0x80, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) | index, 0,
sizeof(buff), (
char *)&buff[0],
PS2CamCallback, (
void*)ps2cam_sema);
688 printf(
"Usb: Error getting string (%d)\n",ret);
695 WaitSema(ps2cam_sema);
698 for(i=0;(i<(sd->bLength-4)/2 && i<strmax-1);i++)
700 str[i] = sd->wData[i] & 0xFF;
706 SignalSema(ps2cam_sema);
719 WaitSema(ps2cam_sema);
726 printf(
"Usb: PS2CamSelectInterface Error...\n");
730 WaitSema(ps2cam_sema);
733 SignalSema(ps2cam_sema);
745 setReg8(dev,EYETOY_CREG_RESET1, 0x0f);
746 setReg8(dev,EYETOY_CREG_RESET1, 0x00);
752 setReg8(dev, EYETOY_CREG_SNAPSHOT, 23);
758 setReg8(dev, EYETOY_CREG_SNAPSHOT, 23);
825 setReg8Mask(dev, EYETOY_GPIO_DATA_OUT0, 0x01,0x01);
832 setReg8Mask(dev, EYETOY_GPIO_DATA_OUT0, 0x00,0x01);
840 setReg8(dev, EYETOY_CREG_RESET1, 0x00);
847 setReg8(dev, EYETOY_CREG_RESET1, 0x0f);
874void PS2CamReadDataCallback(
int resultCode,
int bytes,
void *arg)
880 read_rslt = resultCode;
882 SignalSema(ps2cam_sema);
892 WaitSema(ps2cam_sema);
894 ret = sceUsbdIsochronousTransfer(dev->
stream, addr, size, 0, PS2CamReadDataCallback, (
void*)ps2cam_sema);
898 printf(
"Usb: Error sending sceUsbdIsochronousTransfer\n");
903 WaitSema(ps2cam_sema);
906 SignalSema(ps2cam_sema);
941 static unsigned short ver[2];
944 ret = (
int *)&ver[0];
945 ver[0] =DRIVER_VERSON_MAJOR;
946 ver[1] =DRIVER_VERSON_MINOR;
971 if(! irx_initialized)
972 return CAM_ERROR_NOTINIT;
976 for(i=0;i<MAX_CAM_DEVICE;i++)
978 if(Camera[i].status > 0)
997 if(! irx_initialized)
998 return CAM_ERROR_NOTINIT;
1001 for(i=0,index=0;i<MAX_CAM_DEVICE;i++)
1003 if(Camera[i].status > 0)
1005 if(index == device_index)
1016 if((i+1) == (MAX_CAM_DEVICE))
1027 for(i=0;i<MAX_CAM_DEVICE_HANDLE;i++)
1029 if(CamHandle[i].status == 0)
1031 handle = &CamHandle[i];
1037 if((i+1)== MAX_CAM_DEVICE_HANDLE)
1063 if(! irx_initialized)
1064 return CAM_ERROR_NOTINIT;
1067 for(i=0;i<MAX_CAM_DEVICE_HANDLE;i++)
1069 if(CamHandle[i].fd == handle)
1071 CamHandle[i].status=0;
1077 if((i+1)== MAX_CAM_DEVICE_HANDLE)
1095 if(! irx_initialized)
1096 return CAM_ERROR_NOTINIT;
1098 if(handle > MAX_CAM_DEVICE_HANDLE || handle <= 0 || CamHandle[handle-1].status == 0)
1101 if(CamHandle[handle-1].status == -1)
1104 dev = CamHandle[handle-1].cam;
1115 static unsigned int size;
1121 if(! irx_initialized)
1122 return CAM_ERROR_NOTINIT;
1124 if(handle > MAX_CAM_DEVICE_HANDLE || handle <= 0 || CamHandle[handle-1].status == 0)
1127 if(CamHandle[handle-1].status == -1)
1142 cam = CamHandle[handle-1].cam;
1145 dev = sceUsbdScanStaticDescriptor(cam->device_id, NULL, USB_DT_DEVICE);
1159 strcpy((
char *)&inf.
model[0],
"SLEH-00030\0");
1163 strcpy((
char *)&inf.
model[0],
"SLEH-00031\0");
1167 strcpy((
char *)&inf.
model[0],
"UNKNOWN\0");
1170 memcpy(
info, &inf, size);
1187 if(! irx_initialized)
1188 return CAM_ERROR_NOTINIT;
1190 if(handle > MAX_CAM_DEVICE_HANDLE || handle <= 0 || CamHandle[handle-1].status == 0)
1193 if(CamHandle[handle-1].status == -1)
1197 cam = CamHandle[handle-1].cam;
1199 cam->bandwidth = bandwidth;
1204 dev = sceUsbdScanStaticDescriptor(cam->device_id, NULL, USB_DT_DEVICE);
1205 intf = sceUsbdScanStaticDescriptor(cam->device_id, dev, USB_DT_INTERFACE);
1207 for(i=0;i<cam->bandwidth;i++)
1209 intf = sceUsbdScanStaticDescriptor(cam->device_id, intf, USB_DT_INTERFACE);
1216 sceUsbdClosePipe(cam->
stream);
1217 cam->
stream = sceUsbdOpenPipe(cam->device_id, endp);
1219 cam->stream_pocket_size = (endp->wMaxPacketSizeHB * 256 + endp->wMaxPacketSizeLB);
1220 printf(
"bandwidth =%d\n",cam->stream_pocket_size);
1246 setReg8(cam, EYETOY_CREG_RESET1, 0x00);
1262 if(! irx_initialized)
1263 return CAM_ERROR_NOTINIT;
1265 if(handle > MAX_CAM_DEVICE_HANDLE || handle <= 0 || CamHandle[handle-1].status == 0)
1268 if(CamHandle[handle-1].status == -1)
1272 cam = CamHandle[handle-1].cam;
1274 if(cam == NULL)
return CAM_ERROR_INVALIDDEVICE;
1280 switch(cam->bandwidth)
1285 case EYETOY_ALTERNATE_SIZE_384:
1286 ret = PS2CamReadData(cam, &campacket[0], 384);
1288 case EYETOY_ALTERNATE_SIZE_512:
1289 ret = PS2CamReadData(cam, &campacket[0], 512);
1291 case EYETOY_ALTERNATE_SIZE_768:
1292 ret = PS2CamReadData(cam, &campacket[0], 768);
1294 case EYETOY_ALTERNATE_SIZE_896:
1295 ret = PS2CamReadData(cam, &campacket[0], 896);
1298 ret = PS2CamReadData(cam, &campacket[0], 384);
1312 if(! irx_initialized)
1313 return CAM_ERROR_NOTINIT;
1315 if(handle > MAX_CAM_DEVICE_HANDLE || handle <= 0 || CamHandle[handle-1].status == 0)
1318 if(CamHandle[handle-1].status == -1)
1322 cam = CamHandle[handle-1].cam;
1324 if(cam == NULL)
return CAM_ERROR_INVALIDDEVICE;
1358 if(! irx_initialized)
1359 return CAM_ERROR_NOTINIT;
1361 if(handle > MAX_CAM_DEVICE_HANDLE || handle <= 0 || CamHandle[handle-1].status == 0)
1364 if(CamHandle[handle-1].status == -1)
1368 cam = CamHandle[handle-1].cam;
1370 if(cam == NULL)
return CAM_ERROR_INVALIDDEVICE;
1382 if(cfg->
mask & CAM_CONFIG_MASK_DIMENSION)
1390 if(cfg->
mask & CAM_CONFIG_MASK_OFFSET)
1394 p = (
unsigned char *)&cfg->
x_offset;
1395 setReg8(cam, EYETOY_IREG_X_OFFSETL, p[0]);
1396 setReg8(cam, EYETOY_IREG_X_OFFSETH, p[1]);
1398 p = (
unsigned char *)&cfg->
y_offset;
1399 setReg8(cam, EYETOY_IREG_Y_OFFSETL, p[0]);
1400 setReg8(cam, EYETOY_IREG_Y_OFFSETH, p[1]);
1404 if(cfg->
mask & CAM_CONFIG_MASK_DIVIDER)
1413 if(cfg->
mask & CAM_CONFIG_MASK_FRAMERATE)
1453void *rpcCommandHandler(u32 command,
void *buffer,
int size)
1455 int* buf = (
int*) buffer;
1475 case PS2CAM_RPC_OPENDEVICE:
1479 case PS2CAM_RPC_CLOSEDEVICE:
1499 buf[1] = (int )&campacket[0];
1507 case PS2CAM_RPC_SETDEVCONFIG:
void PS2CamSetDeviceConfiguration(CAMERA_DEVICE *dev, int id)
void camResetDevice(CAMERA_DEVICE *dev)
void PS2CamCallback(int resultCode, int bytes, void *arg)
int PS2CamDisconnect(int devId)
int PS2CamReadPacket(int handle)
int getReg8(CAMERA_DEVICE *dev, unsigned char reg_id, unsigned char *value)
void camStartStream(CAMERA_DEVICE *dev)
int PS2CamGetDeviceCount(void)
int PS2CamSetLEDMode(int handle, int mode)
int PS2CamConnect(int devId)
int PS2CamGetDeviceInfo(int handle, int *info)
int setReg8Mask(CAMERA_DEVICE *dev, unsigned char reg_id, unsigned char value, unsigned char mask)
int PS2CamCloseDevice(int handle)
int PS2CamProbe(int devId)
void PS2CamSetDeviceDefaults(CAMERA_DEVICE *dev)
void camTurnOffRedLed(CAMERA_DEVICE *dev)
int PS2CamSetDeviceBandwidth(int handle, char bandwidth)
int PS2CamSelectInterface(CAMERA_DEVICE *dev, int interface, int altSetting)
void camResetUsb(CAMERA_DEVICE *dev)
int PS2CamGetIRXVersion(void)
void camDisableSystem(CAMERA_DEVICE *dev)
void camEnableSystem(CAMERA_DEVICE *dev)
void camTurnOnRedLed(CAMERA_DEVICE *dev)
void camSetUsbInit(CAMERA_DEVICE *dev)
int PS2CamSetDeviceConfig(int handle, void *config)
int PS2CamOpenDevice(int device_index)
void PS2CamGetDeviceSring(CAMERA_DEVICE *dev, int index, char *str, int strmax)
int PS2CamInitDriver(void)
void camSetUsbWork(CAMERA_DEVICE *dev)
int PS2CamGetDeviceStatus(int handle)
int setReg8(CAMERA_DEVICE *dev, unsigned char reg_id, unsigned char value)
void PS2CamInitializeNewDevice(CAMERA_DEVICE *cam)
#define PS2CAM_VEND_DLINK
unsigned char vendor_name[32]
#define EYETOY_ALTERNATE_SIZE_0
unsigned short product_id
unsigned char product_name[32]
#define PS2CAM_PROD_EYETOY4
#define PS2CAM_PROD_EYETOY
#define PS2CAM_PROD_VISUALSTREAM
#define PS2CAM_PROD_EYETOY2
#define PS2CAM_PROD_EYETOY3
#define CAM_STATUS_CONNECTED
#define CAM_ERROR_DISCONNECTED
#define CAM_ERROR_COMMUNKNOWN
#define PS2CAM_RPC_GETDEVSTATUS
#define CAM_ERROR_BADHANDLE
#define PS2CAM_RPC_SETDEVBANDWIDTH
#define CAM_ERROR_BADRANGE
#define PS2CAM_RPC_GETIRXVERSION
#define CAM_ERROR_UNKNOWN
#define CAM_ERROR_MAXHANDLE
#define PS2CAM_RPC_GETDEVCOUNT
#define PS2CAM_RPC_SETLEDMODE
#define PS2CAM_RPC_GETDEVINFO
#define PS2CAM_RPC_INITIALIZE
#define CAM_ERROR_DEVNOTREADY
#define CAM_STATUS_NOTCONNECTED
#define CAM_ERROR_NODEVICE
#define CAM_STATUS_CONNECTEDREADY
#define PS2CAM_RPC_READPACKET
u32 count
start sector of fragmented bd/file