PSPSDK 2024-10-31
Loading...
Searching...
No Matches
Controller Kernel Library

Data Structures

struct  SceCtrlData
 Controller data. More...
 
struct  SceCtrlLatch
 Controller latch data. More...
 

Typedefs

typedef struct SceCtrlData SceCtrlData
 Controller data.
 
typedef struct SceCtrlLatch SceCtrlLatch
 Controller latch data.
 

Enumerations

enum  PspCtrlButtons {
  PSP_CTRL_SELECT = 0x000001 , PSP_CTRL_START = 0x000008 , PSP_CTRL_UP = 0x000010 , PSP_CTRL_RIGHT = 0x000020 ,
  PSP_CTRL_DOWN = 0x000040 , PSP_CTRL_LEFT = 0x000080 , PSP_CTRL_LTRIGGER = 0x000100 , PSP_CTRL_RTRIGGER = 0x000200 ,
  PSP_CTRL_TRIANGLE = 0x001000 , PSP_CTRL_CIRCLE = 0x002000 , PSP_CTRL_CROSS = 0x004000 , PSP_CTRL_SQUARE = 0x008000 ,
  PSP_CTRL_HOME = 0x010000 , PSP_CTRL_HOLD = 0x020000 , PSP_CTRL_NOTE = 0x800000 , PSP_CTRL_SCREEN = 0x400000 ,
  PSP_CTRL_VOLUP = 0x100000 , PSP_CTRL_VOLDOWN = 0x200000 , PSP_CTRL_WLAN_UP = 0x040000 , PSP_CTRL_REMOTE = 0x080000 ,
  PSP_CTRL_DISC = 0x1000000 , PSP_CTRL_MS = 0x2000000
}
 Enumeration representing digital controller button flags. More...
 
enum  PspCtrlMode { PSP_CTRL_MODE_DIGITAL = 0 , PSP_CTRL_MODE_ANALOG = 1 }
 Controller mode. More...
 

Functions

int sceCtrlSetSamplingCycle (int cycle)
 Set the controller cycle setting.
 
int sceCtrlGetSamplingCycle (int *pcycle)
 Get the controller current cycle setting.
 
int sceCtrlSetSamplingMode (int mode)
 Set the controller mode.
 
int sceCtrlGetSamplingMode (int *pmode)
 Get the current controller mode.
 
int sceCtrlPeekBufferPositive (SceCtrlData *pad_data, int count)
 Read latest controller data from the controller service.
 
int sceCtrlPeekBufferNegative (SceCtrlData *pad_data, int count)
 
int sceCtrlReadBufferPositive (SceCtrlData *pad_data, int count)
 Read new controller data from the controller service.
 
int sceCtrlReadBufferNegative (SceCtrlData *pad_data, int count)
 
int sceCtrlPeekLatch (SceCtrlLatch *latch_data)
 Read latest latch data from the controller service.
 
int sceCtrlReadLatch (SceCtrlLatch *latch_data)
 Read new latch data from the controller service.
 
int sceCtrlSetIdleCancelThreshold (int idlereset, int idleback)
 Set analog threshold relating to the idle timer.
 
int sceCtrlGetIdleCancelThreshold (int *idlerest, int *idleback)
 Get the idle threshold values.
 

Detailed Description

Typedef Documentation

◆ SceCtrlData

Controller data.

Contains current button and axis state.

Note
Axis state is present only in PSP_CTRL_MODE_ANALOG controller mode.
See also
sceCtrlPeekBufferPositive()
sceCtrlPeekBufferNegative()
sceCtrlReadBufferPositive()
sceCtrlReadBufferNegative()
PspCtrlMode

◆ SceCtrlLatch

Controller latch data.

Contains information about button state changes between two controller service sampling cycles. With each sampling cycle, the controller service compares the new pressed & releasedbutton states with the previously collected pressed button states. This comparison will result in the following possible states for each button:

  • Make - The button has just been pressed with its prior state being the released state. Transition from 'released' state to 'pressed' state.
  • Press - The button is currently in the 'pressed' state.
  • Break - The button has just been released with its prior state being the 'pressed' state. Transition from 'pressed' state to 'release' state.
  • Release - The button is currently in the 'released' state.

It is possible for a button to (briefly) be in two states at the same time. Valid combinations are as follows:

  • Make & Press
  • Break & Release

In other words, if a button is in the Make state, then it is also in the Press state. However, this is not the case for the inverse. A button in the Press state does not need to be in the Make state.

Mask the values with one or more PspCtrlButtons flags to access specific buttons.

These comparison results are stored internally as latch data and can be retrieved using the APIs sceCtrlPeekLatch() and sceCtrlReadLatch().

Remarks
The same can be accomplished by using the different sceCtrl[Read/Peek]Buffer[Positive/Negative]() APIs and comparing the currently collected button sampling data with the previously collected one.
See also
PspCtrlButtons
sceCtrlPeekLatch()
sceCtrlReadLatch()

Enumeration Type Documentation

◆ PspCtrlButtons

Enumeration representing digital controller button flags.

Each flag corresponds to a different button and can be used to extract button states from SceCtrlData and SceCtrlLatch structures. Flags can be combined using bitwise OR operation to check for mutliple key states at once.

Note
Some button states are available only in kernel mode.
See also
SceCtrlData
SceCtrlLatch
Enumerator
PSP_CTRL_SELECT 

Select button.

PSP_CTRL_START 

Start button.

PSP_CTRL_UP 

Up D-Pad button.

PSP_CTRL_RIGHT 

Right D-Pad button.

PSP_CTRL_DOWN 

Down D-Pad button.

PSP_CTRL_LEFT 

Left D-Pad button.

PSP_CTRL_LTRIGGER 

Left trigger.

PSP_CTRL_RTRIGGER 

Right trigger.

PSP_CTRL_TRIANGLE 

Triangle button.

PSP_CTRL_CIRCLE 

Circle button.

PSP_CTRL_CROSS 

Cross button.

PSP_CTRL_SQUARE 

Square button.

PSP_CTRL_HOME 

Kernel mode: Home button state.

User mode: Exit dialog visible.

PSP_CTRL_HOLD 

Hold button.

PSP_CTRL_NOTE 

Music note button - kernel mode only.

PSP_CTRL_SCREEN 

Screen button - kernel mode only.

PSP_CTRL_VOLUP 

Volume up button - kernel mode only.

PSP_CTRL_VOLDOWN 

Volume down button - kernel mode only.

PSP_CTRL_WLAN_UP 

Wlan switch up - kernel mode only.

PSP_CTRL_REMOTE 

Remote hold position - kernel mode only.

PSP_CTRL_DISC 

Disc present - kernel mode only.

PSP_CTRL_MS 

Memory stick present - kernel mode only.

◆ PspCtrlMode

Controller mode.

Specifies if analog data should be included in SceCtrlData.

See also
sceCtrlSetSamplingMode()
sceCtrlGetSamplingMode()
SceCtrlData
Enumerator
PSP_CTRL_MODE_DIGITAL 
PSP_CTRL_MODE_ANALOG 

Function Documentation

◆ sceCtrlGetIdleCancelThreshold()

int sceCtrlGetIdleCancelThreshold ( int idlerest,
int idleback 
)

Get the idle threshold values.

Parameters
idlerest- Movement needed by the analog to reset the idle timer.
idleback- Movement needed by the analog to bring the PSP back from an idle state.
Returns
< 0 on error.

◆ sceCtrlGetSamplingCycle()

int sceCtrlGetSamplingCycle ( int pcycle)

Get the controller current cycle setting.

Parameters
pcycle- Return value.
Returns
0.

◆ sceCtrlGetSamplingMode()

int sceCtrlGetSamplingMode ( int pmode)

Get the current controller mode.

Parameters
pmode- Return value.
Returns
0.

◆ sceCtrlPeekBufferNegative()

int sceCtrlPeekBufferNegative ( SceCtrlData pad_data,
int  count 
)

◆ sceCtrlPeekBufferPositive()

int sceCtrlPeekBufferPositive ( SceCtrlData pad_data,
int  count 
)

Read latest controller data from the controller service.

Controller data contains current button and axis state.

Note
Axis state is present only in PSP_CTRL_MODE_ANALOG controller mode.
Parameters
pad_data- A pointer to SceCtrlData structure that receives controller data.
count- Number of SceCtrlData structures to read.
See also
SceCtrlData
sceCtrlPeekBufferNegative()
sceCtrlReadBufferPositive()

◆ sceCtrlPeekLatch()

int sceCtrlPeekLatch ( SceCtrlLatch latch_data)

Read latest latch data from the controller service.

Latch data contains information about button state changes between two controller service sampling cycles.

Parameters
latch_dataA pointer to SceCtrlLatch structure that receives latch data.
Returns
On success, the number of times the controller service performed sampling since the last time sceCtrlReadLatch() was called.
< 0 on error.
See also
SceCtrlLatch
sceCtrlReadLatch()

◆ sceCtrlReadBufferNegative()

int sceCtrlReadBufferNegative ( SceCtrlData pad_data,
int  count 
)

◆ sceCtrlReadBufferPositive()

int sceCtrlReadBufferPositive ( SceCtrlData pad_data,
int  count 
)

Read new controller data from the controller service.

Controller data contains current button and axis state.

Example:

// Do something with the read controller data
int sceCtrlSetSamplingCycle(int cycle)
Set the controller cycle setting.
int sceCtrlReadBufferPositive(SceCtrlData *pad_data, int count)
Read new controller data from the controller service.
int sceCtrlSetSamplingMode(int mode)
Set the controller mode.
Controller data.
Definition pspctrl.h:120
Note
Axis state is present only in PSP_CTRL_MODE_ANALOG controller mode.
Warning
Controller data is collected once every controller sampling cycle. If controller data was already read during a cycle, trying to read it again will block the execution until the next one.
Parameters
pad_data- A pointer to SceCtrlData structure that receives controller data.
count- Number of SceCtrlData structures to read.
See also
SceCtrlData
sceCtrlReadBufferNegative()
sceCtrlPeekBufferPositive()

Referenced by pspDebugKbInit().

◆ sceCtrlReadLatch()

int sceCtrlReadLatch ( SceCtrlLatch latch_data)

Read new latch data from the controller service.

Latch data contains information about button state changes between two controller service sampling cycles.

Example:

while (1) {
// Obtain latch data
if (latchData.uiMake & PSP_CTRL_CROSS)
{
// The Cross button has just been pressed (transition from 'released' state to 'pressed' state)
}
if (latchData.uiPress & PSP_CTRL_SQUARE)
{
// The Square button is currently in the 'pressed' state
}
{
// The Triangle button has just been released (transition from 'pressed' state to 'released' state)
}
if (latchData.uiRelease & PSP_CTRL_CIRCLE)
{
// The Circle button is currently in the 'released' state
}
// As we clear the internal latch data with the ReadLatch() call, we can explicitly wait for the VBLANK interval
// to give the controller service the time it needs to collect new latch data again. This guarantees the next call
// to sceCtrlReadLatch() will return collected data again.
//
// Note: The sceCtrlReadBuffer*() APIs are implicitly waiting for a VBLANK interval if necessary.
}
int sceCtrlReadLatch(SceCtrlLatch *latch_data)
Read new latch data from the controller service.
@ PSP_CTRL_SQUARE
Square button.
Definition pspctrl.h:64
@ PSP_CTRL_CROSS
Cross button.
Definition pspctrl.h:62
@ PSP_CTRL_CIRCLE
Circle button.
Definition pspctrl.h:60
@ PSP_CTRL_TRIANGLE
Triangle button.
Definition pspctrl.h:58
float x
Definition psptypes.h:0
Controller latch data.
Definition pspctrl.h:171
Warning
Latch data is produced once every controller sampling cycle. If latch data was already read during a cycle, trying to read it again will block the execution until the next one.
Parameters
latch_dataA pointer to SceCtrlLatch structure that receives latch data.
Returns
On success, the number of times the controller service performed sampling since the last time sceCtrlReadLatch() was called.
< 0 on error.
See also
SceCtrlLatch
sceCtrlPeekLatch()

◆ sceCtrlSetIdleCancelThreshold()

int sceCtrlSetIdleCancelThreshold ( int  idlereset,
int  idleback 
)

Set analog threshold relating to the idle timer.

Parameters
idlereset- Movement needed by the analog to reset the idle timer.
idleback- Movement needed by the analog to bring the PSP back from an idle state.

Set to -1 for analog to not cancel idle timer. Set to 0 for idle timer to be cancelled even if the analog is not moved. Set between 1 - 128 to specify the movement on either axis needed by the analog to fire the event.

Returns
< 0 on error.

◆ sceCtrlSetSamplingCycle()

int sceCtrlSetSamplingCycle ( int  cycle)

Set the controller cycle setting.

Parameters
cycle- Cycle. Normally set to 0.
Returns
The previous cycle setting.

Referenced by pspDebugKbInit().

◆ sceCtrlSetSamplingMode()

int sceCtrlSetSamplingMode ( int  mode)

Set the controller mode.

Parameters
mode- One of PspCtrlMode. If this is PSP_CTRL_MODE_DIGITAL, no data about the analog stick will be present in the SceCtrlData struct read by SceCtrlReadBuffer.
Returns
The previous mode.

Referenced by pspDebugKbInit().