psp/sys/power.rs
1use crate::sys::SceUid;
2
3bitflags::bitflags! {
4 /// Power callback flags
5 #[repr(transparent)]
6 pub struct PowerInfo: u32 {
7 /// Indicates the power switch is pushed, putting the unit into suspend
8 /// mode.
9 const POWER_SWITCH = 0x80000000;
10 /// Indicates the hold switch is on.
11 const HOLD_SWITCH = 0x40000000;
12 /// Indicates the screen is off.
13 const STANDBY = 0x00080000;
14 /// Indicates the resume process is complete. Only seems to be triggered
15 /// when another event happens.
16 const RESUME_COMPLETE = 0x00040000;
17 /// Indicates the unit is resuming from suspend mode.
18 const RESUMING = 0x00020000;
19 /// Indicates the unit is suspending, seems to occur due to inactivity.
20 const SUSPENDING = 0x00010000;
21 /// Indicates the unit is plugged into an AC outlet.
22 const AC_POWER = 0x00001000;
23 /// Indicates the battery charge level is low.
24 const BATTERY_LOW = 0x00000100;
25 /// Indicates there is a battery present in the unit.
26 const BATTERY_EXIST = 0x00000080;
27 /// Indicates that the system is running on battery power.
28 const BATTERY_POWER = 0x0000007;
29 }
30}
31
32/// Type of power tick to generate.
33#[repr(u32)]
34pub enum PowerTick {
35 /// A tick that prevents the PSP from suspending and the display from
36 /// turning off.
37 All = 0,
38 /// A power tick that prevents the PSP from suspending.
39 Suspend = 1,
40 /// A power tick that prevents the PSP display from turning off.
41 Display = 6,
42}
43
44/// Power callback function prototype
45///
46/// # Parameters
47///
48/// - `unknown`: Unknown function, appears to cycle between 1, 2, and 3.
49/// - `power_info`: Combination of `PowerInfo` flags.
50pub type PowerCallback = extern "C" fn(unknown: i32, power_info: PowerInfo);
51
52psp_extern! {
53 #![name = "scePower"]
54 #![flags = 0x4001]
55 #![version = (0x00, 0x00)]
56
57 #[psp(0x04B7766E)]
58 /// Register Power Callback Function
59 ///
60 /// # Parameters
61 ///
62 /// - `slot`: slot of the callback in the list, 0 to 15, pass -1 to get an
63 /// auto assignment.
64 /// - `cbid`: callback id from calling `sceKernelCreateCallback`
65 ///
66 /// # Return Value
67 ///
68 /// 0 on success, the slot number if -1 is passed, < 0 on error.
69 pub fn scePowerRegisterCallback(
70 slot: i32,
71 cbid: SceUid,
72 ) -> i32;
73
74 #[psp(0xDFA8BAF8)]
75 /// Unregister Power Callback Function
76 ///
77 /// # Parameters
78 ///
79 /// - `slot`: slot of the callback
80 ///
81 /// # Return Value
82 ///
83 /// 0 on success, < 0 on error.
84 pub fn scePowerUnregisterCallback(slot: i32) -> i32;
85
86 #[psp(0x87440F5E)]
87 /// Check if unit is plugged in
88 ///
89 /// # Return Value
90 ///
91 /// 1 if plugged in, 0 if not plugged in, < 0 on error.
92 pub fn scePowerIsPowerOnline() -> i32;
93
94 #[psp(0x0AFD0D8B)]
95 /// Check if a battery is present
96 ///
97 /// # Return Value
98 ///
99 /// 1 if battery present, 0 if battery not present, < 0 on error.
100 pub fn scePowerIsBatteryExist() -> i32;
101
102 #[psp(0x1E490401)]
103 /// Check if the battery is charging
104 ///
105 /// # Return Value
106 ///
107 /// 1 if battery charging, 0 if battery not charging, < 0 on error.
108 pub fn scePowerIsBatteryCharging() -> i32;
109
110 #[psp(0xB4432BC8)]
111 /// Get the status of the battery charging
112 pub fn scePowerGetBatteryChargingStatus() -> i32;
113
114 #[psp(0xD3075926)]
115 /// Check if the battery is low
116 ///
117 /// # Return Value
118 ///
119 /// 1 if the battery is low, 0 if the battery is not low, < 0 on error.
120 pub fn scePowerIsLowBattery() -> i32;
121
122 #[psp(0x2085D15D)]
123 /// Get battery life as integer percent
124 ///
125 /// # Return Value
126 ///
127 /// Battery charge percentage (0-100), < 0 on error.
128 pub fn scePowerGetBatteryLifePercent() -> i32;
129
130 #[psp(0x8EFB3FA2)]
131 /// Get battery life as time
132 ///
133 /// # Return Value
134 ///
135 /// Battery life in minutes, < 0 on error.
136 pub fn scePowerGetBatteryLifeTime() -> i32;
137
138 #[psp(0x28E12023)]
139 /// Get temperature of the battery
140 pub fn scePowerGetBatteryTemp() -> i32;
141
142 #[psp(0x862AE1A6)]
143 /// unknown? - crashes PSP in usermode
144 pub fn scePowerGetBatteryElec() -> i32;
145
146 #[psp(0x483CE86B)]
147 /// Get battery volt level
148 pub fn scePowerGetBatteryVolt() -> i32;
149
150 #[psp(0x843FBF43)]
151 /// Set CPU Frequency
152 ///
153 /// # Parameters
154 ///
155 /// - `cpufreq`: new CPU frequency, valid values are 1 - 333
156 pub fn scePowerSetCpuClockFrequency(cpufreq: i32) -> i32;
157
158 #[psp(0xB8D7B3FB)]
159 /// Set Bus Frequency
160 ///
161 /// # Parameters
162 ///
163 /// - `busfreq`: new BUS frequency, valid values are 1 - 166
164 pub fn scePowerSetBusClockFrequency(busfreq: i32) -> i32;
165
166 #[psp(0xFEE03A2F)]
167 /// Alias for scePowerGetCpuClockFrequencyInt
168 ///
169 /// # Return Value
170 ///
171 /// Frequency as integer
172 pub fn scePowerGetCpuClockFrequency() -> i32;
173
174 #[psp(0xFDB5BFE9)]
175 /// Get CPU Frequency as Integer
176 ///
177 /// # Return Value
178 ///
179 /// Frequency as an integer
180 pub fn scePowerGetCpuClockFrequencyInt() -> i32;
181
182 #[psp(0xB1A52C83)]
183 /// Get CPU Frequency as Float
184 ///
185 /// # Return Value
186 ///
187 /// Frequency as a float
188 pub fn scePowerGetCpuClockFrequencyFloat() -> f32;
189
190 #[psp(0x478FE6F5)]
191 /// Alias for scePowerGetBusClockFrequencyInt
192 ///
193 /// # Return Value
194 ///
195 /// Frequency as an integer
196 pub fn scePowerGetBusClockFrequency() -> i32;
197
198 #[psp(0xBD681969)]
199 /// Get Bus frequency as Integer
200 ///
201 /// # Return Value
202 ///
203 /// Frequency as an integer
204 pub fn scePowerGetBusClockFrequencyInt() -> i32;
205
206 #[psp(0x9BADB3EB)]
207 /// Get Bus frequency as Float
208 ///
209 /// # Return Value
210 ///
211 /// frequency as float
212 pub fn scePowerGetBusClockFrequencyFloat() -> f32;
213
214 #[psp(0x737486F2)]
215 /// Set Clock Frequencies
216 ///
217 /// # Parameters
218 ///
219 /// - `pllfreq`: pll frequency, valid from 19-333
220 /// - `cpufreq`: cpu frequency, valid from 1-333
221 /// - `busfreq`: bus frequency, valid from 1-166
222 ///
223 /// and:
224 ///
225 /// cpufreq <= pllfreq
226 /// busfreq*2 <= pllfreq
227 ///
228 pub fn scePowerSetClockFrequency(
229 pllfreq: i32,
230 cpufreq: i32,
231 busfreq: i32,
232 ) -> i32;
233
234 #[psp(0xD6D016EF)]
235 /// Lock power switch
236 ///
237 /// Note: if the power switch is toggled while locked it will fire
238 /// immediately after being unlocked.
239 ///
240 /// # Parameters
241 ///
242 /// - `unknown`: pass 0
243 ///
244 /// # Return Value
245 ///
246 /// 0 on success, < 0 on error.
247 pub fn scePowerLock(unknown: i32) -> i32;
248
249 #[psp(0xCA3D34C1)]
250 /// Unlock power switch
251 ///
252 /// # Parameters
253 ///
254 /// - `unknown`: pass 0
255 ///
256 /// # Return Value
257 ///
258 /// 0 on success, < 0 on error.
259 pub fn scePowerUnlock(unknown: i32) -> i32;
260
261 #[psp(0xEFD3C963)]
262 /// Generate a power tick, preventing unit from powering off and turning off
263 /// display.
264 ///
265 /// # Parameters
266 ///
267 /// - `type_`: type of power tick to generate
268 ///
269 /// # Return Value
270 ///
271 /// 0 on success, < 0 on error.
272 pub fn scePowerTick(type_: PowerTick) -> i32;
273
274 #[psp(0xEDC13FE5)]
275 /// Get Idle timer
276 pub fn scePowerGetIdleTimer() -> i32;
277
278 #[psp(0x7F30B3B1)]
279 /// Enable Idle timer
280 ///
281 /// # Parameters
282 ///
283 /// - `unknown`: pass 0
284 pub fn scePowerIdleTimerEnable(unknown: i32) -> i32;
285
286 #[psp(0x972CE941)]
287 /// Disable Idle timer
288 ///
289 /// # Parameters
290 ///
291 /// - `unknown`: pass 0
292 pub fn scePowerIdleTimerDisable(unknown: i32) -> i32;
293
294 #[psp(0x2B7C7CF4)]
295 /// Request the PSP to go into standby
296 ///
297 /// # Return Value
298 ///
299 /// 0 always
300 pub fn scePowerRequestStandby() -> i32;
301
302 #[psp(0xAC32C9CC)]
303 /// Request the PSP to go into suspend
304 ///
305 /// # Return Value
306 ///
307 /// 0 always
308 pub fn scePowerRequestSuspend() -> i32;
309}