how to get power from psp?

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

Moderators: cheriff, TyRaNiD

Post Reply
AvsDecode
Posts: 2
Joined: Sun Mar 15, 2009 1:12 am

how to get power from psp?

Post by AvsDecode »

As you know, Psp'camera use the two sheet metals beside the usb interface to supply power,and now i want to use them to supply power for
my own deivce,but i don't know if there is a function to control the power on or off, and what function i can call.
Sorry for my english.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

It's a bit old but I got someone to make a PRX Plugin to enable the power using L+R in the XMB way back.

Not sure if it works with current firmwares...

https://lan.st/showpost.php?p=5815&postcount=18
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

He asking for a command to activate his device power.
AvsDecode
Posts: 2
Joined: Sun Mar 15, 2009 1:12 am

Post by AvsDecode »

Thank you for your reply, and it must be useful.
It seems there still some problem when set usb power on as the author said.
If there is a system call such as 'sceSetUsbPower()' , it would be an easy way to set usb power with my own software.
Thanks for you help!
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

Dariusc123456 wrote:He asking for a command to activate his device power.

No really..? *rolls eyes* l beleive it's one click from the link I posted. The full source for the PRX. So don't be so quick to flame the help you idiot..

Code: Select all

#include <pspsdk.h>
#include <pspdisplay.h>
#include <pspuser.h>
#include <pspctrl.h>
#include <string.h>
#include <pspusb.h>
#include <stdio.h>
#include <sys/unistd.h>

#define PSP_USBGPS_PID 0x283
#define printf pspDebugScreenPrintf
#define PSP_USBGPS_DRIVERNAME "USBGps_Driver"
#define PSP_CTRL_COMBO PSP_CTRL_LTRIGGER | PSP_CTRL_RTRIGGER


PSP_MODULE_INFO&#40;"SoftSwitch", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;

u32 usbState = 0;
SceCtrlData newInput;
int err, kill_threads = 0;

/* Helper function for input_thread. */
int checkInput&#40;int PSP_CTRL_BUTTON&#41; &#123;
	return &#40;&#40;newInput.Buttons & &#40;PSP_CTRL_COMBO | PSP_CTRL_BUTTON&#41;&#41; == &#40;PSP_CTRL_COMBO | PSP_CTRL_BUTTON&#41;&#41;;
&#125;

void input_thread&#40;SceSize args, void *argp&#41; &#123;
	u32 oldInput = 0;
	while &#40;!kill_threads&#41; &#123;
		sceCtrlPeekBufferPositive&#40;&newInput, 1&#41;;
		if &#40;newInput.Buttons != oldInput&#41; &#123;
			if &#40;checkInput&#40;PSP_CTRL_TRIANGLE&#41;&#41; kill_threads = 1;
			if &#40;checkInput&#40;PSP_CTRL_SQUARE&#41;&#41; &#123;
				if &#40;usbState & PSP_USB_ACTIVATED&#41; sceUsbDeactivate&#40;PSP_USBGPS_PID&#41;; else sceUsbActivate&#40;PSP_USBGPS_PID&#41;;
				usbState = sceUsbGetState&#40;&#41;;
			&#125;
		&#125;
		oldInput = newInput.Buttons;
		sceKernelDelayThread&#40;1000&#41;;
	&#125;
	sceKernelExitDeleteThread&#40;0&#41;;
&#125;

u32 moduleLoadStart &#40;const char *path&#41; &#123;
	SceUID loadResult, startResult;
	int status;
	loadResult = sceKernelLoadModule&#40;path, 0, NULL&#41;;
	if &#40;loadResult & 0x80000000&#41; return 1;
	startResult = sceKernelStartModule&#40;loadResult, 0, NULL, &status, NULL&#41;;
	if &#40;loadResult != startResult&#41; return 2;
	return 0;
&#125;

void initialize&#40;&#41; &#123;
	err = moduleLoadStart&#40;"ms0&#58;/prx/usbacc.prx"&#41;;
	if &#40;err&#41; printf&#40;"Error loading USB Accessory Module &#40;0x%08X&#41;/n", err&#41;;

	err = moduleLoadStart&#40;"ms0&#58;/prx/usbgps.prx"&#41;;
	if &#40;err&#41; printf&#40;"Error loading GPS Accessory Module &#40;0x%08X&#41;/n", err&#41;;

	err = sceUsbStart&#40;PSP_USBBUS_DRIVERNAME, 0, 0&#41;;
	if &#40;err&#41; printf&#40;"Error starting USB BUS Driver &#40;0x%08X&#41;/n", err&#41;;

	err = sceUsbStart&#40;"USBAccBaseDriver", 0, 0&#41;;
	if &#40;err&#41; printf&#40;"Error starting USB Accessory Driver &#40;0x%08X&#41;/n", err&#41;;

	err = sceUsbStart&#40;PSP_USBGPS_DRIVERNAME,0,0&#41;;
	if &#40;err&#41; printf&#40;"Error starting USB GPS Driver &#40;0x%08X&#41;/n", err&#41;;

	err = sceUsbActivate&#40;PSP_USBGPS_PID&#41;;
	if &#40;err&#41; printf&#40;"Error activating USB GPS &#40;0x%08X&#41;/n", err&#41;;
	usbState = sceUsbGetState&#40;&#41;;
	printf&#40;"USB&#58; %s/n", &#40;usbState & PSP_USB_ACTIVATED&#41; ? "On" &#58; "Off"&#41;;
&#125;

void exit_thread&#40;SceSize args, void *argp&#41; &#123;
	while &#40;!kill_threads&#41; &#123; sceKernelDelayThread&#40;10000&#41;; &#125;
	while &#40;kill_threads&#41; &#123;
		sceUsbDeactivate&#40;PSP_USBGPS_PID&#41;;

		err = sceUsbStop&#40;PSP_USBGPS_DRIVERNAME,0,0&#41;;
		if &#40;err&#41; printf&#40;"Error stopping USB Gps driver &#40;0x%08X&#41;/n", err&#41;;

		err = sceUsbStop&#40;"USBAccBaseDriver",0,0&#41;;
		if &#40;err&#41; printf&#40;"Error stopping USB Acc driver &#40;0x%08X&#41;/n", err&#41;;

		err = sceUsbStop&#40;PSP_USBBUS_DRIVERNAME,0,0&#41;;
		if &#40;err&#41; printf&#40;"Error stopping USB BUS driver &#40;0x%08X&#41;/n", err&#41;;
	&#125;
	sceKernelExitDeleteThread&#40;0&#41;;
&#125;

int main_thread &#40;SceSize args, void *argp&#41; &#123;
	SceUID input_thid, exit_thid;

	initialize&#40;&#41;;

	// Start input_thread to detect input conditions.
	input_thid = sceKernelCreateThread&#40;"input_thread", &#40;SceKernelThreadEntry&#41;input_thread, 0x20, 0x10000, 0, NULL&#41;;
	if &#40;input_thid >= 0&#41; sceKernelStartThread&#40;input_thid, 0, NULL&#41;;
	sceKernelDelayThread&#40;1000&#41;;

	// Start exit_thread to manage exit.
	exit_thid = sceKernelCreateThread&#40;"exit_thread", &#40;SceKernelThreadEntry&#41;exit_thread, 0x21, 0x10000, 0, NULL&#41;;
	if &#40;exit_thid >= 0&#41; sceKernelStartThread&#40;exit_thid, 0, NULL&#41;;
	sceKernelDelayThread&#40;1000&#41;;

	return 0;
&#125;

int module_start &#40;SceSize args, void *argp&#41; &#123;
	SceUID main_thid;
	main_thid = sceKernelCreateThread&#40;"main_thread", main_thread, 0x20, 0x10000, 0, NULL&#41;;
	if &#40;main_thid >= 0&#41; sceKernelStartThread&#40;main_thid, args, argp&#41;;
	return 0;
&#125;
Code By: califrag [lan.st]
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

Post Reply