Skip to content

Commit 68ea8c2

Browse files
committed
Implementation of #622. Change operating frequency.
1 parent b119764 commit 68ea8c2

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Diff for: libs/network/esp8266/jswrap_esp8266.c

+26
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,32 @@ JsVar *jswrap_ESP8266WiFi_getRstInfo() {
437437
return restartInfo;
438438
}
439439

440+
/*JSON{
441+
"type" : "staticmethod",
442+
"class" : "ESP8266WiFi",
443+
"name" : "updateCPUFreq",
444+
"generate" : "jswrap_ESP8266WiFi_updateCPUFreq",
445+
"params" : [
446+
["freq","JsVar","Desired frequency - either 80 or 160."]
447+
]
448+
}
449+
* Update the operating frequency of the ESP8266 processor.
450+
*/
451+
void jswrap_ESP8266WiFi_updateCPUFreq(
452+
JsVar *jsFreq //!< Operating frequency of the processor. Either 80 or 160.
453+
) {
454+
if (!jsvIsInt(jsFreq)) {
455+
jsExceptionHere(JSET_ERROR, "Invalid frequency.");
456+
return;
457+
}
458+
int newFreq = jsvGetInteger(jsFreq);
459+
if (newFreq != 80 && newFreq != 160) {
460+
jsExceptionHere(JSET_ERROR, "Invalid frequency value, must be 80 or 160.");
461+
return;
462+
}
463+
system_update_cpu_freq(newFreq);
464+
}
465+
440466

441467
/**
442468
* Return an object that contains details about the state of the ESP8266.

Diff for: libs/network/esp8266/jswrap_esp8266.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ JsVar *jswrap_ESP8266WiFi_getConnectedStations();
3030
JsVar *jswrap_ESP8266WiFi_getRSSI();
3131
JsVar *jswrap_ESP8266WiFi_getState();
3232
void jswrap_ESP8266WiFi_dumpSocket(JsVar *socketId);
33+
void jswrap_ESP8266WiFi_updateCPUFreq(JsVar *jsFreq);
3334

3435
#endif /* LIBS_NETWORK_ESP8266_JSWRAP_ESP8266_H_ */

Diff for: targets/esp8266/docs/05-User_Guide.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,14 @@ The returned object contains the following fields:
343343

344344
* `sdkVersion` - The version of the ESP8266 SDK used to build this release.
345345
* `cpuFrequency` - The CPU operating frequency in MHz.
346-
* `freeHeap` - The amount of free heap in bytes.
346+
* `freeHeap` - The amount of free heap in bytes.
347+
348+
----
349+
350+
##ESP8266WiFi.updateCPUFreq
351+
352+
Set the operating frequency of the ESP8266 processor.
353+
354+
`ESP8266WiFi.updateCPUFreq(newFreq)`
355+
356+
* `newFreq` - The new operating frequency of the CPU. Either 80 (80MHz) or 160 (160MHz).

0 commit comments

Comments
 (0)