PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ps2cam.c File Reference
#include <stdio.h>
#include <sysclib.h>
#include <tamtypes.h>
#include <thbase.h>
#include <sifcmd.h>
#include <sifrpc.h>
#include <loadcore.h>
#include <ioman.h>
#include <usbd.h>
#include <usbd_macro.h>
#include <thsemap.h>
#include <sysmem.h>
#include "ps2cam.h"
+ Include dependency graph for ps2cam.c:

Go to the source code of this file.

Macros

#define MODNAME   "PS2 USB camera driver"
 
#define BIND_RPC_ID   0x00FD000 +2
 
#define DRIVER_VERSON_MAJOR   1
 
#define DRIVER_VERSON_MINOR   0
 
#define MAX_CAM_DEVICE   2
 
#define MAX_CAM_DEVICE_HANDLE   2
 

Functions

 IRX_ID (MODNAME, 1, 1)
 
static SifRpcDataQueue_t rpc_queue __attribute__ ((__aligned__(16)))
 
static int _rpc_buffer[1024] __attribute__ ((__aligned__(4)))
 
int _start (int argc, char *argv[])
 
int PS2CamInitDriver (void)
 
int PS2CamProbe (int devId)
 
int PS2CamConnect (int devId)
 
int PS2CamDisconnect (int devId)
 
void rpcMainThread (void *param)
 
void PS2CamInitializeNewDevice (CAMERA_DEVICE *cam)
 
void PS2CamSetDeviceConfiguration (CAMERA_DEVICE *dev, int id)
 
void PS2CamSetDeviceDefaults (CAMERA_DEVICE *dev)
 
void PS2CamCallback (int resultCode, int bytes, void *arg)
 
int setReg8 (CAMERA_DEVICE *dev, unsigned char reg_id, unsigned char value)
 
int getReg8 (CAMERA_DEVICE *dev, unsigned char reg_id, unsigned char *value)
 
int setReg8Mask (CAMERA_DEVICE *dev, unsigned char reg_id, unsigned char value, unsigned char mask)
 
int setReg16 (CAMERA_DEVICE *dev, unsigned char reg_id, unsigned short value)
 
void PS2CamGetDeviceSring (CAMERA_DEVICE *dev, int index, char *str, int strmax)
 
int PS2CamSelectInterface (CAMERA_DEVICE *dev, int interface, int altSetting)
 
void camResetDevice (CAMERA_DEVICE *dev)
 
void camEnableAutoLaunch (CAMERA_DEVICE *dev)
 
void camDisableAutoLaunch (CAMERA_DEVICE *dev)
 
void camClearSnapButton (CAMERA_DEVICE *dev)
 
int camCheckAutoLaunch (CAMERA_DEVICE *dev)
 
void camEnableSystem (CAMERA_DEVICE *dev)
 
void camDisableSystem (CAMERA_DEVICE *dev)
 
void camResetUsb (CAMERA_DEVICE *dev)
 
void camSetUsbInit (CAMERA_DEVICE *dev)
 
void camSetUsbWork (CAMERA_DEVICE *dev)
 
void camTurnOnRedLed (CAMERA_DEVICE *dev)
 
void camTurnOffRedLed (CAMERA_DEVICE *dev)
 
void camStartStream (CAMERA_DEVICE *dev)
 
void camStopStream (CAMERA_DEVICE *dev)
 
void PS2CamReadDataCallback (int resultCode, int bytes, void *arg)
 
int PS2CamReadData (CAMERA_DEVICE *dev, void *addr, int size)
 
int PS2CamGetIRXVersion (void)
 
int PS2CamInit (int mode)
 
int PS2CamGetDeviceCount (void)
 
int PS2CamOpenDevice (int device_index)
 
int PS2CamCloseDevice (int handle)
 
int PS2CamGetDeviceStatus (int handle)
 
int PS2CamGetDeviceInfo (int handle, int *info)
 
int PS2CamSetDeviceBandwidth (int handle, char bandwidth)
 
int PS2CamReadPacket (int handle)
 
int PS2CamSetLEDMode (int handle, int mode)
 
int PS2CamSetDeviceConfig (int handle, void *config)
 
void * rpcCommandHandler (u32 command, void *buffer, int size)
 

Variables

static int maintain_thread
 
sceUsbdLddOps cam_driver
 
char irx_initialized = 0
 
int ps2cam_sema =0
 
CAMERA_DEVICE Camera [MAX_CAM_DEVICE]
 
PS2CAM_DEVICE_HANDLE CamHandle [MAX_CAM_DEVICE_HANDLE]
 
int read_rslt
 
int read_byts
 

Detailed Description

PS2Camera driver irx

Definition in file ps2cam.c.

Macro Definition Documentation

◆ MODNAME

#define MODNAME   "PS2 USB camera driver"

Definition at line 30 of file ps2cam.c.

◆ BIND_RPC_ID

#define BIND_RPC_ID   0x00FD000 +2

Definition at line 34 of file ps2cam.c.

◆ DRIVER_VERSON_MAJOR

#define DRIVER_VERSON_MAJOR   1

Definition at line 35 of file ps2cam.c.

◆ DRIVER_VERSON_MINOR

#define DRIVER_VERSON_MINOR   0

Definition at line 36 of file ps2cam.c.

◆ MAX_CAM_DEVICE

#define MAX_CAM_DEVICE   2

Definition at line 38 of file ps2cam.c.

◆ MAX_CAM_DEVICE_HANDLE

#define MAX_CAM_DEVICE_HANDLE   2

Definition at line 39 of file ps2cam.c.

Function Documentation

◆ _start()

int _start ( int  argc,
char *  argv[] 
)

Definition at line 69 of file ps2cam.c.

◆ PS2CamInitDriver()

int PS2CamInitDriver ( void  )

Register This driver with usbd.irx

Definition at line 109 of file ps2cam.c.

◆ PS2CamProbe()

int PS2CamProbe ( int  devId)

◆ PS2CamConnect()

int PS2CamConnect ( int  devId)

this is executed when a compatible camera is detected

Definition at line 213 of file ps2cam.c.

References CAM_STATUS_CONNECTED, CAMERA_DEVICE::controll, PS2CamInitializeNewDevice(), and CAMERA_DEVICE::stream.

◆ PS2CamDisconnect()

int PS2CamDisconnect ( int  devId)

this is executed when a compatible camera is unplugged

Definition at line 297 of file ps2cam.c.

References CAM_STATUS_NOTCONNECTED, CAMERA_DEVICE::controll, and CAMERA_DEVICE::stream.

◆ rpcMainThread()

void rpcMainThread ( void *  param)

Definition at line 362 of file ps2cam.c.

◆ PS2CamInitializeNewDevice()

void PS2CamInitializeNewDevice ( CAMERA_DEVICE cam)

◆ PS2CamSetDeviceConfiguration()

void PS2CamSetDeviceConfiguration ( CAMERA_DEVICE dev,
int  id 
)

select the configuration for the device

Definition at line 429 of file ps2cam.c.

References CAMERA_DEVICE::controll, PS2CamCallback(), and USB_RC_OK.

Referenced by PS2CamInitializeNewDevice().

◆ PS2CamSetDeviceDefaults()

void PS2CamSetDeviceDefaults ( CAMERA_DEVICE dev)

set the defaults for the camera

Definition at line 453 of file ps2cam.c.

References camEnableSystem(), camResetDevice(), camSetUsbInit(), camStartStream(), camTurnOffRedLed(), setReg8(), and setReg8Mask().

Referenced by PS2CamInitializeNewDevice().

◆ PS2CamCallback()

void PS2CamCallback ( int  resultCode,
int  bytes,
void *  arg 
)

call back for most lowlevel usb funtions

Definition at line 570 of file ps2cam.c.

Referenced by getReg8(), PS2CamGetDeviceSring(), PS2CamSelectInterface(), PS2CamSetDeviceConfiguration(), and setReg8().

◆ setReg8()

int setReg8 ( CAMERA_DEVICE dev,
unsigned char  reg_id,
unsigned char  value 
)

◆ getReg8()

int getReg8 ( CAMERA_DEVICE dev,
unsigned char  reg_id,
unsigned char *  value 
)

Read the camera's 8bit register and return the value

Definition at line 606 of file ps2cam.c.

References CAMERA_DEVICE::controll, PS2CamCallback(), and USB_RC_OK.

Referenced by setReg8Mask().

◆ setReg8Mask()

int setReg8Mask ( CAMERA_DEVICE dev,
unsigned char  reg_id,
unsigned char  value,
unsigned char  mask 
)

Set the value in a 8bit register using a mask

Definition at line 633 of file ps2cam.c.

References getReg8(), and setReg8().

Referenced by camDisableSystem(), camTurnOffRedLed(), camTurnOnRedLed(), and PS2CamSetDeviceDefaults().

◆ setReg16()

int setReg16 ( CAMERA_DEVICE dev,
unsigned char  reg_id,
unsigned short  value 
)

Definition at line 650 of file ps2cam.c.

◆ PS2CamGetDeviceSring()

void PS2CamGetDeviceSring ( CAMERA_DEVICE dev,
int  index,
char *  str,
int  strmax 
)

Get a string descriptor from device

Definition at line 674 of file ps2cam.c.

References CAMERA_DEVICE::controll, PS2CamCallback(), and USB_RC_OK.

Referenced by PS2CamGetDeviceInfo(), and PS2CamInitializeNewDevice().

◆ PS2CamSelectInterface()

int PS2CamSelectInterface ( CAMERA_DEVICE dev,
int  interface,
int  altSetting 
)

Select the interface and alternet settting to use

Definition at line 712 of file ps2cam.c.

References CAMERA_DEVICE::controll, PS2CamCallback(), and USB_RC_OK.

Referenced by PS2CamInitializeNewDevice(), and PS2CamSetDeviceBandwidth().

◆ camResetDevice()

void camResetDevice ( CAMERA_DEVICE dev)

Reset the eyetoy

Definition at line 743 of file ps2cam.c.

References setReg8().

Referenced by PS2CamSetDeviceDefaults().

◆ camEnableAutoLaunch()

void camEnableAutoLaunch ( CAMERA_DEVICE dev)

Definition at line 750 of file ps2cam.c.

◆ camDisableAutoLaunch()

void camDisableAutoLaunch ( CAMERA_DEVICE dev)

Definition at line 756 of file ps2cam.c.

◆ camClearSnapButton()

void camClearSnapButton ( CAMERA_DEVICE dev)

Definition at line 762 of file ps2cam.c.

◆ camCheckAutoLaunch()

int camCheckAutoLaunch ( CAMERA_DEVICE dev)

Definition at line 768 of file ps2cam.c.

◆ camEnableSystem()

void camEnableSystem ( CAMERA_DEVICE dev)

Enable some setting that make the cam capture

Definition at line 778 of file ps2cam.c.

References setReg8().

Referenced by PS2CamSetDeviceDefaults().

◆ camDisableSystem()

void camDisableSystem ( CAMERA_DEVICE dev)

Disable some stuff

Definition at line 790 of file ps2cam.c.

References setReg8Mask().

◆ camResetUsb()

void camResetUsb ( CAMERA_DEVICE dev)

This is just a reguler reset to jpeg stuff

Definition at line 797 of file ps2cam.c.

References setReg8().

◆ camSetUsbInit()

void camSetUsbInit ( CAMERA_DEVICE dev)

reset jpeg and clear the frame reg

Definition at line 805 of file ps2cam.c.

References setReg8().

Referenced by PS2CamSetDeviceDefaults().

◆ camSetUsbWork()

void camSetUsbWork ( CAMERA_DEVICE dev)

reset jpeg and set the frame default value

Definition at line 814 of file ps2cam.c.

References setReg8().

◆ camTurnOnRedLed()

void camTurnOnRedLed ( CAMERA_DEVICE dev)

turn on the red leg on the GPIO pin

Definition at line 823 of file ps2cam.c.

References setReg8Mask().

Referenced by PS2CamSetLEDMode().

◆ camTurnOffRedLed()

void camTurnOffRedLed ( CAMERA_DEVICE dev)

turn off the red leg on the GPIO pin

Definition at line 830 of file ps2cam.c.

References setReg8Mask().

Referenced by PS2CamSetDeviceDefaults(), and PS2CamSetLEDMode().

◆ camStartStream()

void camStartStream ( CAMERA_DEVICE dev)

restart stream

Definition at line 837 of file ps2cam.c.

References setReg8().

Referenced by PS2CamInitializeNewDevice(), PS2CamSetDeviceConfig(), and PS2CamSetDeviceDefaults().

◆ camStopStream()

void camStopStream ( CAMERA_DEVICE dev)

Definition at line 844 of file ps2cam.c.

◆ PS2CamReadDataCallback()

void PS2CamReadDataCallback ( int  resultCode,
int  bytes,
void *  arg 
)

Definition at line 874 of file ps2cam.c.

◆ PS2CamReadData()

int PS2CamReadData ( CAMERA_DEVICE dev,
void *  addr,
int  size 
)

Definition at line 888 of file ps2cam.c.

◆ PS2CamGetIRXVersion()

int PS2CamGetIRXVersion ( void  )

Return the current version of the 'ps2cam.irx'

Definition at line 939 of file ps2cam.c.

References PS2CAM_RPC_GETIRXVERSION, and PS2CamGetIRXVersion().

Referenced by PS2CamGetIRXVersion().

◆ PS2CamInit()

int PS2CamInit ( int  mode)

initalize the camera driver. must be called 1st

Definition at line 954 of file ps2cam.c.

References PS2CAM_RPC_INITIALIZE, and PS2CamInit().

Referenced by PS2CamInit().

◆ PS2CamGetDeviceCount()

int PS2CamGetDeviceCount ( void  )

get the number of compatible camera connected

Definition at line 966 of file ps2cam.c.

References count, PS2CAM_RPC_GETDEVCOUNT, and PS2CamGetDeviceCount().

Referenced by PS2CamGetDeviceCount().

◆ PS2CamOpenDevice()

int PS2CamOpenDevice ( int  device_index)

open one of the compatible camera for reading

Definition at line 990 of file ps2cam.c.

References CAM_ERROR_BADRANGE, CAM_ERROR_MAXHANDLE, CAM_ERROR_NODEVICE, CAM_ERROR_UNKNOWN, and PS2CamOpenDevice().

Referenced by PS2CamOpenDevice().

◆ PS2CamCloseDevice()

int PS2CamCloseDevice ( int  handle)

close the device if it is no longer needed or disconnected

Definition at line 1059 of file ps2cam.c.

References CAM_ERROR_BADHANDLE, and PS2CamCloseDevice().

Referenced by PS2CamCloseDevice().

◆ PS2CamGetDeviceStatus()

int PS2CamGetDeviceStatus ( int  handle)

get the status of the compatible camera

Definition at line 1089 of file ps2cam.c.

References CAM_ERROR_BADHANDLE, CAM_ERROR_DISCONNECTED, PS2CAM_RPC_GETDEVSTATUS, and PS2CamGetDeviceStatus().

Referenced by PS2CamGetDeviceStatus().

◆ PS2CamGetDeviceInfo()

◆ PS2CamSetDeviceBandwidth()

int PS2CamSetDeviceBandwidth ( int  handle,
char  bandwidth 
)

◆ PS2CamReadPacket()

int PS2CamReadPacket ( int  handle)

read some data from the camera based on bandwidth

Definition at line 1254 of file ps2cam.c.

References CAM_ERROR_BADHANDLE, CAM_ERROR_DEVNOTREADY, CAM_ERROR_DISCONNECTED, EYETOY_ALTERNATE_SIZE_0, PS2CAM_RPC_READPACKET, and PS2CamReadPacket().

Referenced by PS2CamReadPacket().

◆ PS2CamSetLEDMode()

int PS2CamSetLEDMode ( int  handle,
int  mode 
)

◆ PS2CamSetDeviceConfig()

◆ rpcCommandHandler()

void * rpcCommandHandler ( u32  command,
void *  buffer,
int  size 
)

Definition at line 1453 of file ps2cam.c.

Variable Documentation

◆ maintain_thread

int maintain_thread
static

Definition at line 46 of file ps2cam.c.

◆ cam_driver

sceUsbdLddOps cam_driver
Initial value:
= {NULL,
NULL,
"ps2cam",
0, 0, 0, 0, 0, NULL }
int PS2CamDisconnect(int devId)
Definition ps2cam.c:297
int PS2CamConnect(int devId)
Definition ps2cam.c:213
int PS2CamProbe(int devId)
Definition ps2cam.c:143

Definition at line 47 of file ps2cam.c.

◆ irx_initialized

char irx_initialized = 0

Definition at line 58 of file ps2cam.c.

◆ ps2cam_sema

int ps2cam_sema =0

Definition at line 59 of file ps2cam.c.

◆ Camera

CAMERA_DEVICE Camera[MAX_CAM_DEVICE]

Definition at line 60 of file ps2cam.c.

◆ CamHandle

PS2CAM_DEVICE_HANDLE CamHandle[MAX_CAM_DEVICE_HANDLE]

Definition at line 61 of file ps2cam.c.

◆ read_rslt

int read_rslt

Definition at line 871 of file ps2cam.c.

◆ read_byts

int read_byts

Definition at line 872 of file ps2cam.c.