My USB plugin doesn't work properly

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
nikocronaldo
Posts: 31
Joined: Sun Feb 24, 2008 7:19 am

My USB plugin doesn't work properly

Post by nikocronaldo »

Why my psp show the Sony error screen when I try this code :

Code: Select all


#include <pspkernel.h>
#include <pspiofilemgr.h>
#include <pspsdk.h>
#include <stdio.h>
#include <string.h>
#include <psploadexec_kernel.h>
#include <psploadcore.h>
#include <pspsysmem.h>
#include <pspsysmem_kernel.h>
#include <systemctrl.h>
#include <psppower.h>
#include <pspctrl.h>
#include <pspusb.h>
#include <pspusbstor.h>
#include <pspusbbus.h>
#include <pspdisplay_kernel.h>
#include <pspmodulemgr_kernel.h>
#include <kubridge.h>

#include <pspdisplay.h>


PSP_MODULE_INFO&#40;"Brightnes USB 1.0", 0x1000, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;   



static int curBrightness = 0;

int USB_GetState&#40;void&#41;
&#123;
    int k1 = pspSdkSetK1&#40;0&#41;;
           
    sceDisplayGetBrightness&#40;&curBrightness, 0&#41;;
	      sceDisplaySetBrightness&#40;0, 0&#41;;
         	 
   
    pspSdkSetK1&#40;k1&#41;;
	
    return 0;
	

&#125; 

int USB_Stop&#40;void&#41;
&#123;
   int k1 = pspSdkSetK1&#40;0&#41;;
                         
 sceDisplaySetBrightness&#40;curBrightness, 0&#41;;

 	 
   
    pspSdkSetK1&#40;k1&#41;;
	
    return 0;
	

&#125; 


int module_start&#40;SceSize args, void *argp&#41;
&#123;
    
       
       u32 x = sctrlHENFindFunction&#40;"sceThreadManager" ,"ThreadManForUser", 0xAA73C935&#41;; 
	x = sctrlHENFindFunction&#40;"sceUSB_Driver", "sceUsb", 0xC21645A4&#41;;
	sctrlHENPatchSyscall&#40;x, USB_GetState&#41;;
	x = sctrlHENFindFunction&#40;"sceUSB_Driver", "sceUsb", 0xC2464FA0&#41;;
	sctrlHENPatchSyscall&#40;x, USB_Stop&#41;;
    
        return 0;
&#125;          
    
      
                  
    

            
            
    
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

what type of error does PSP show?
nikocronaldo
Posts: 31
Joined: Sun Feb 24, 2008 7:19 am

Post by nikocronaldo »

blu_eye4 wrote:what type of error does PSP show?
PSP shows the following error when I connect again to the USB Mode:

Code: Select all

An internal error has ocurred &#40;80243101&#41;
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

You are not calling original functions, wo aht you would expect?
Your GetState and Stop functions should call original functions for this to work.
Mashphealh
Posts: 18
Joined: Wed Nov 28, 2007 4:18 am

Post by Mashphealh »

Yes, you don't call original function. Try using this code :

int USB_GetState(void)
{
int k1 = pspSdkSetK1(0);

sceDisplayGetBrightness(&curBrightness, 0);
sceDisplaySetBrightness(0, 0);


pspSdkSetK1(k1);

return sceUsbGetState();


}

int USB_Stop(const char* driverName, int size, void *args)
{
int k1 = pspSdkSetK1(0);

sceDisplaySetBrightness(curBrightness, 0);



pspSdkSetK1(k1);

return sceUsbStop(driverName, size, args);


}

M33's vshctrl patches sceUsbStop also, so I don't know if now usbdevice works for you.
nikocronaldo
Posts: 31
Joined: Sun Feb 24, 2008 7:19 am

Post by nikocronaldo »

moonlight wrote:You are not calling original functions, wo aht you would expect?
Your GetState and Stop functions should call original functions for this to work.
The PSP crashes with the original functions, with the same Mashphealt's code, why moonlight?
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

The usb stop function should be like this. The original function must be executed between the k1 stuff. This doesn't matter in the GetState one.
int USB_Stop(const char* driverName, int size, void *args)
{
int k1 = pspSdkSetK1(0);
sceDisplaySetBrightness(curBrightness, 0);
int ret = sceUsbStop(driverName, size, args)
pspSdkSetK1(k1);
return ret;
}
nikocronaldo
Posts: 31
Joined: Sun Feb 24, 2008 7:19 am

Post by nikocronaldo »

moonlight wrote:The psp stop function should be like this. The original function must be executed between the k1 stuff. This doesn't matter in the GetState one.
int USB_Stop(const char* driverName, int size, void *args)
{
int k1 = pspSdkSetK1(0);
sceDisplaySetBrightness(curBrightness, 0);
int ret = sceUsbStop(driverName, size, args)
pspSdkSetK1(k1);
return ret;
}

It crashes again, why?
int USB_GetState(void)
{
int k1 = pspSdkSetK1(0);

sceDisplayGetBrightness(&curBrightness, 0);
sceDisplaySetBrightness(0, 0);


pspSdkSetK1(k1);

return 0;


}

int USB_Stop(const char* driverName, int size, void *args)
{
int k1 = pspSdkSetK1(0);
sceDisplaySetBrightness(curBrightness, 0);
int ret = sceUsbStop(driverName, size, args);
pspSdkSetK1(k1);
return ret;
}
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

maybe, if you want make a prx you haven't to give 0x1000 at PSP_MODULE_INFO, maybe...
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Do a test commenting the calls to the display functions, to see if it crashes too or not.
nikocronaldo
Posts: 31
Joined: Sun Feb 24, 2008 7:19 am

Post by nikocronaldo »

moonlight wrote:Do a test commenting the calls to the display functions, to see if it crashes too or not.
Prx still crashes, any idea?
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

A suggestion, When you ask for something post the entire code, the makefile and give more infos, I can't see your actual code...
Anyway if I'm right you want to hook the usb load?
To do this use the m33 module handler, is better then hook some functions I think...
Sorry for my english...
Post Reply