Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB: Cleanup eyetoy code a bit. #12009

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pcsx2/USB/usb-eyetoy/cam-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@

HRESULT DirectShow::CallbackHandler::SampleCB(double time, IMediaSample* sample)
{
HRESULT hr;
unsigned char* buffer;

hr = sample->GetPointer((BYTE**)&buffer);
const HRESULT hr = sample->GetPointer((BYTE**)&buffer);

Check notice on line 39 in pcsx2/USB/usb-eyetoy/cam-windows.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/USB/usb-eyetoy/cam-windows.cpp#L39

C-style pointer casting
if (hr != S_OK)
return S_OK;

Expand Down Expand Up @@ -588,7 +587,7 @@
{
mpeg_mutex.lock();
int len2 = mpeg_buffer.length;
if ((unsigned int)len < mpeg_buffer.length)
if (static_cast<size_t>(len) < mpeg_buffer.length)
len2 = len;
memcpy(buf, mpeg_buffer.start, len2);
mpeg_buffer.length = 0;
Expand Down
34 changes: 17 additions & 17 deletions pcsx2/USB/usb-eyetoy/usb-eyetoy-webcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace usb_eyetoy

std::unique_ptr<VideoDevice> videodev;
USBDevice* mic;
uint8_t regs[0xFF]; //OV519
uint8_t i2c_regs[0xFF]; //OV764x
u8 regs[0xFF]; //OV519
u8 i2c_regs[0xFF]; //OV764x

int hw_camera_running;
int frame_step;
Expand Down Expand Up @@ -81,10 +81,10 @@ namespace usb_eyetoy
}
else if (s->hw_camera_running && s->subtype == TYPE_OV511P)
{
const int width = 320;
const int height = 240;
constexpr int width = 320;
constexpr int height = 240;
const FrameFormat format = format_yuv400;
const int mirror = 0;
constexpr int mirror = 0;
Console.WriteLn(
"EyeToy : eyetoy_open(); hw=%d, w=%d, h=%d, fmt=%d, mirr=%d", s->hw_camera_running, width, height, format, mirror);
if (s->videodev->Open(width, height, format, mirror) != 0)
Expand All @@ -111,7 +111,7 @@ namespace usb_eyetoy
s->mic->klass.handle_reset(s->mic);
}

static void webcam_handle_control_eyetoy(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, uint8_t* data)
static void webcam_handle_control_eyetoy(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, u8* data)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
int ret = 0;
Expand Down Expand Up @@ -172,9 +172,9 @@ namespace usb_eyetoy
case R518_I2C_CTL:
if (data[0] == 1) // Commit I2C write
{
//uint8_t reg = s->regs[s->regs[R51x_I2C_W_SID]];
uint8_t reg = s->regs[R51x_I2C_SADDR_3];
uint8_t val = s->regs[R51x_I2C_DATA];
//u8 reg = s->regs[s->regs[R51x_I2C_W_SID]];
const u8 reg = s->regs[R51x_I2C_SADDR_3];
const u8 val = s->regs[R51x_I2C_DATA];
if ((reg == 0x12) && (val & 0x80))
{
s->i2c_regs[0x12] = val & ~0x80; //or skip?
Expand All @@ -194,7 +194,7 @@ namespace usb_eyetoy
else if (s->regs[R518_I2C_CTL] == 0x03 && data[0] == 0x05)
{
//s->regs[s->regs[R51x_I2C_R_SID]] but seems to default to 0x43 (R51x_I2C_SADDR_2)
uint8_t i2c_reg = s->regs[R51x_I2C_SADDR_2];
const u8 i2c_reg = s->regs[R51x_I2C_SADDR_2];
s->regs[R51x_I2C_DATA] = 0;

if (i2c_reg < sizeof(s->i2c_regs))
Expand All @@ -218,7 +218,7 @@ namespace usb_eyetoy
}
}

static void webcam_handle_control_ov511p(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, uint8_t* data)
static void webcam_handle_control_ov511p(USBDevice* dev, USBPacket* p, int request, int value, int index, int length, u8* data)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
int ret = 0;
Expand All @@ -242,16 +242,16 @@ namespace usb_eyetoy
case R511_I2C_CTL:
if (data[0] == 1)
{
uint8_t reg = s->regs[R51x_I2C_SADDR_3];
uint8_t val = s->regs[R51x_I2C_DATA];
u8 reg = s->regs[R51x_I2C_SADDR_3];
const u8 val = s->regs[R51x_I2C_DATA];
if (reg < sizeof(s->i2c_regs))
{
s->i2c_regs[reg] = val;
}
}
else if (s->regs[R511_I2C_CTL] == 0x03 && data[0] == 0x05)
{
uint8_t i2c_reg = s->regs[R51x_I2C_SADDR_2];
const u8 i2c_reg = s->regs[R51x_I2C_SADDR_2];
s->regs[R51x_I2C_DATA] = 0;

if (i2c_reg < sizeof(s->i2c_regs))
Expand All @@ -277,8 +277,8 @@ namespace usb_eyetoy
static void webcam_handle_data_eyetoy(USBDevice* dev, USBPacket* p)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
static const unsigned int max_ep_size = 896;
uint8_t devep = p->ep->nr;
static constexpr unsigned int max_ep_size = 896;
const u8 devep = p->ep->nr;

if (!s->hw_camera_running)
{
Expand Down Expand Up @@ -346,7 +346,7 @@ namespace usb_eyetoy
static void webcam_handle_data_ov511p(USBDevice* dev, USBPacket* p)
{
EYETOYState* s = USB_CONTAINER_OF(dev, EYETOYState, dev);
uint8_t devep = p->ep->nr;
const u8 devep = p->ep->nr;

if (!s->hw_camera_running)
{
Expand Down
16 changes: 8 additions & 8 deletions pcsx2/USB/usb-eyetoy/usb-eyetoy-webcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace usb_eyetoy
{
static const uint8_t eyetoy_dev_descriptor[] = {
static const u8 eyetoy_dev_descriptor[] = {
0x12, /* bLength */
0x01, /* bDescriptorType */
WBVAL(0x0110), /* bcdUSB */
Expand All @@ -28,7 +28,7 @@ namespace usb_eyetoy
0x01, /* bNumConfigurations */
};

static const uint8_t eyetoy_config_descriptor[] = {
static const u8 eyetoy_config_descriptor[] = {
0x09, // bLength
0x02, // bDescriptorType (Configuration)
0xB4, 0x00, // wTotalLength 180
Expand Down Expand Up @@ -215,7 +215,7 @@ namespace usb_eyetoy
0x00, 0x00, // wLockDelay 0
};

static const uint8_t ov511p_dev_descriptor[] = {
static const u8 ov511p_dev_descriptor[] = {
0x12, // bLength
0x01, // bDescriptorType (Device)
0x00, 0x01, // bcdUSB 1.00
Expand All @@ -232,7 +232,7 @@ namespace usb_eyetoy
0x01, // bNumConfigurations 1
};

static const uint8_t ov511p_config_descriptor[] = {
static const u8 ov511p_config_descriptor[] = {
0x09, // bLength
0x02, // bDescriptorType (Configuration)
0x89, 0x00, // wTotalLength 137
Expand Down Expand Up @@ -379,7 +379,7 @@ namespace usb_eyetoy
0x01, // bInterval 1 (unit depends on device speed)
};

static const uint8_t ov519_defaults[] = {
static const u8 ov519_defaults[] = {
0xc0, 0x00, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x14, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x98, 0xff, 0x00, 0x03, 0x00, 0x00, 0x1e, 0x01, 0xf1, 0x00, 0x01, 0x00, 0x00, 0x00,
Expand All @@ -398,7 +398,7 @@ namespace usb_eyetoy
0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

static const uint8_t ov7648_defaults[] = {
static const u8 ov7648_defaults[] = {
0x00, 0x84, 0x84, 0x84, 0x34, 0x3e, 0x80, 0x8c, 0x00, 0x00, 0x76, 0x48, 0x7b, 0x5b, 0x00, 0x98,
0x57, 0x00, 0x14, 0xa3, 0x04, 0x00, 0x00, 0x1a, 0xba, 0x03, 0xf3, 0x00, 0x7f, 0xa2, 0x00, 0x01,
0xc0, 0x80, 0x80, 0xde, 0x10, 0x8a, 0xa2, 0xe2, 0x20, 0x00, 0x00, 0x00, 0x88, 0x81, 0x00, 0x94,
Expand All @@ -417,7 +417,7 @@ namespace usb_eyetoy
0x75, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

static const uint8_t ov511p_defaults[] = {
static const u8 ov511p_defaults[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x27, 0x1d, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x4f, 0x1d, 0x00, 0x01, 0x01, 0x04,
0x01, 0x01, 0x01, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -436,7 +436,7 @@ namespace usb_eyetoy
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

static const uint8_t ov7620_defaults[] = {
static const u8 ov7620_defaults[] = {
0x00, 0x84, 0x84, 0x84, 0x34, 0x3e, 0x80, 0x8c, 0x00, 0x00, 0x76, 0x48, 0x7b, 0x5b, 0x00, 0x98,
0x57, 0x00, 0x14, 0xa3, 0x04, 0x00, 0x00, 0x1a, 0xba, 0x03, 0xf3, 0x00, 0x7f, 0xa2, 0x00, 0x01,
0xc0, 0x80, 0x80, 0xde, 0x10, 0x8a, 0xa2, 0xe2, 0x20, 0x00, 0x00, 0x00, 0x88, 0x81, 0x00, 0x94,
Expand Down