@@ -1092,35 +1092,24 @@ int rg_system_get_log_level(void)
1092
1092
1093
1093
void rg_system_set_overclock (int level )
1094
1094
{
1095
- #if defined(ESP_PLATFORM ) && CONFIG_IDF_TARGET_ESP32
1096
- // None of this is documented by espressif but can be found in the file rtc_clk.c
1095
+ #if CONFIG_IDF_TARGET_ESP32
1096
+ // #include "driver/uart.h"
1097
+ // None of this is documented by espressif but there are comments to be found in the file `rtc_clk.c`
1097
1098
#define I2C_BBPLL 0x66
1098
- #define I2C_BBPLL_ENDIV5 11
1099
- #define I2C_BBPLL_BBADC_DSMP 9
1100
1099
#define I2C_BBPLL_HOSTID 4
1101
- #define I2C_BBPLL_OC_LREF 2
1102
- #define I2C_BBPLL_OC_DIV_7_0 3
1103
- #define I2C_BBPLL_OC_DCUR 5
1104
- #define BBPLL_ENDIV5_VAL_320M 0x43
1105
- #define BBPLL_BBADC_DSMP_VAL_320M 0x84
1100
+ #define I2C_BBPLL_ENDIV5 11 // This controls the BBPLL frequency. It should already be at 480Mhz
1101
+ #define I2C_BBPLL_BBADC_DSMP 9 // This controls the BBPLL frequency. It should already be at 480Mhz
1102
+ #define I2C_BBPLL_OC_LREF 2 // This is specific to the installed crystal (24/26/40), we don't care
1103
+ #define I2C_BBPLL_OC_DIV_7_0 3 // This is the PLL divider to get the CPU clock (our main concern)
1104
+ #define I2C_BBPLL_OC_DCUR 5 // This is specific to the installed crystal (24/26/40), we don't care
1106
1105
#define BBPLL_ENDIV5_VAL_480M 0xc3
1107
1106
#define BBPLL_BBADC_DSMP_VAL_480M 0x74
1108
1107
extern void rom_i2c_writeReg (uint8_t block , uint8_t host_id , uint8_t reg_add , uint8_t data );
1109
1108
extern uint8_t rom_i2c_readReg (uint8_t block , uint8_t host_id , uint8_t reg_add );
1109
+ extern int uart_set_baudrate (int uart_num , uint32_t baud_rate );
1110
1110
1111
- uint8_t div_ref = 0 ;
1112
- uint8_t div7_0 = (level + 4 ) * 8 ;
1113
- uint8_t div10_8 = 0 ;
1114
- uint8_t lref = 0 ;
1115
- uint8_t dcur = 6 ;
1116
- uint8_t bw = 3 ;
1117
- uint8_t ENDIV5 = BBPLL_ENDIV5_VAL_480M ;
1118
- uint8_t BBADC_DSMP = BBPLL_BBADC_DSMP_VAL_480M ;
1119
- uint8_t BBADC_OC_LREF = (lref << 7 ) | (div10_8 << 4 ) | (div_ref );
1120
- uint8_t BBADC_OC_DIV_7_0 = div7_0 ;
1121
- uint8_t BBADC_OC_DCUR = (bw << 6 ) | dcur ;
1122
-
1123
- static uint8_t BASE_ENDIV5 , BASE_BBADC_DSMP , BASE_BBADC_OC_LREF , BASE_BBADC_OC_DIV_7_0 , BASE_BBADC_OC_DCUR , BASE_SAVED ;
1111
+ static uint8_t BASE_ENDIV5 , BASE_BBADC_DSMP , BASE_BBADC_OC_LREF , BASE_BBADC_OC_DIV_7_0 , BASE_BBADC_OC_DCUR ;
1112
+ static bool BASE_SAVED = false;
1124
1113
if (!BASE_SAVED )
1125
1114
{
1126
1115
BASE_ENDIV5 = rom_i2c_readReg (I2C_BBPLL , I2C_BBPLL_HOSTID , I2C_BBPLL_ENDIV5 );
@@ -1131,48 +1120,56 @@ void rg_system_set_overclock(int level)
1131
1120
BASE_SAVED = true;
1132
1121
}
1133
1122
1134
- if (level == 0 )
1135
- {
1136
- ENDIV5 = BASE_ENDIV5 ;
1137
- BBADC_DSMP = BASE_BBADC_DSMP ;
1138
- BBADC_OC_LREF = BASE_BBADC_OC_LREF ;
1139
- BBADC_OC_DIV_7_0 = BASE_BBADC_OC_DIV_7_0 ;
1140
- BBADC_OC_DCUR = BASE_BBADC_OC_DCUR ;
1141
- }
1142
- else if (level < -4 || level > 3 )
1123
+ uint8_t ENDIV5 = BASE_ENDIV5 ;
1124
+ uint8_t BBADC_DSMP = BASE_BBADC_DSMP ;
1125
+ uint8_t BBADC_OC_LREF = BASE_BBADC_OC_LREF ;
1126
+ uint8_t BBADC_OC_DIV_7_0 = BASE_BBADC_OC_DIV_7_0 ;
1127
+ uint8_t BBADC_OC_DCUR = BASE_BBADC_OC_DCUR ;
1128
+
1129
+ if (level < -4 || level > 3 )
1143
1130
{
1144
1131
RG_LOGW ("Invalid level %d, min:-4 max:3" , level );
1145
1132
return ;
1146
1133
}
1134
+ else if (level != 0 )
1135
+ {
1136
+ uint8_t div_ref = 0 ;
1137
+ uint8_t div7_0 = (level + 4 ) * 8 ;
1138
+ uint8_t div10_8 = 0 ;
1139
+ uint8_t lref = 0 ;
1140
+ uint8_t dcur = 6 ;
1141
+ uint8_t bw = 3 ;
1142
+ ENDIV5 = BBPLL_ENDIV5_VAL_480M ;
1143
+ BBADC_DSMP = BBPLL_BBADC_DSMP_VAL_480M ;
1144
+ BBADC_OC_LREF = (lref << 7 ) | (div10_8 << 4 ) | (div_ref );
1145
+ BBADC_OC_DIV_7_0 = div7_0 ;
1146
+ BBADC_OC_DCUR = (bw << 6 ) | dcur ;
1147
+ }
1147
1148
1148
1149
RG_LOGW (" " );
1149
1150
RG_LOGW ("BASE: %d %d %d %d %d" , BASE_ENDIV5 , BASE_BBADC_DSMP , BASE_BBADC_OC_LREF , BASE_BBADC_OC_DIV_7_0 , BASE_BBADC_OC_DCUR );
1150
1151
RG_LOGW ("NEW : %d %d %d %d %d" , ENDIV5 , BBADC_DSMP , BBADC_OC_LREF , BBADC_OC_DIV_7_0 , BBADC_OC_DCUR );
1151
1152
RG_LOGW (" " );
1152
1153
1154
+ RG_LOGW ("Preparing peripherals for the speed change..." );
1155
+ rg_task_delay (10 ); // Wait for the log to be sent
1156
+
1157
+ float overclock_ratio = (240 + (level * 40 )) / 240.f ;
1158
+ rg_audio_set_sample_rate (app .sampleRate / overclock_ratio );
1159
+ uart_set_baudrate (0 , 115200 / overclock_ratio );
1160
+
1161
+ RG_LOGW ("Updating clock registers!" );
1153
1162
rom_i2c_writeReg (I2C_BBPLL , I2C_BBPLL_HOSTID , I2C_BBPLL_ENDIV5 , ENDIV5 );
1154
1163
rom_i2c_writeReg (I2C_BBPLL , I2C_BBPLL_HOSTID , I2C_BBPLL_BBADC_DSMP , BBADC_DSMP );
1155
- rom_i2c_writeReg (I2C_BBPLL , I2C_BBPLL_HOSTID , I2C_BBPLL_OC_LREF , BBADC_OC_LREF );
1164
+ // rom_i2c_writeReg(I2C_BBPLL, I2C_BBPLL_HOSTID, I2C_BBPLL_OC_LREF, BBADC_OC_LREF);
1156
1165
rom_i2c_writeReg (I2C_BBPLL , I2C_BBPLL_HOSTID , I2C_BBPLL_OC_DIV_7_0 , BBADC_OC_DIV_7_0 );
1157
- rom_i2c_writeReg (I2C_BBPLL , I2C_BBPLL_HOSTID , I2C_BBPLL_OC_DCUR , BBADC_OC_DCUR );
1158
-
1166
+ // rom_i2c_writeReg(I2C_BBPLL, I2C_BBPLL_HOSTID, I2C_BBPLL_OC_DCUR, BBADC_OC_DCUR);
1159
1167
RG_LOGW ("Overclock applied!" );
1160
- #if 0
1161
- extern uint64_t esp_rtc_get_time_us (void );
1162
- uint64_t start = esp_rtc_get_time_us ();
1163
- int64_t end = rg_system_timer () + 1000000 ;
1164
- while (rg_system_timer () < end )
1165
- continue ;
1166
- overclock_ratio = 1000000.f / (esp_rtc_get_time_us () - start );
1167
- #endif
1168
- // overclock_ratio = (240 + (app.overclock * 40)) / 240.f;
1169
1168
1170
- // rg_audio_set_sample_rate( app.sampleRate / overclock_ratio) ;
1169
+ app .overclock = level ;
1171
1170
#else
1172
1171
RG_LOGE ("Overclock not supported on this platform!" );
1173
1172
#endif
1174
-
1175
- app .overclock = level ;
1176
1173
}
1177
1174
1178
1175
int rg_system_get_overclock (void )
0 commit comments