@@ -177,26 +177,7 @@ uint32_t EspClass::getFlashChipSize(void)
177
177
uint8_t * bytes = (uint8_t *) &data;
178
178
// read first 4 byte (magic byte + flash config)
179
179
if (spi_flash_read (0x0000 , &data, 4 ) == SPI_FLASH_RESULT_OK) {
180
- switch ((bytes[3 ] & 0xf0 ) >> 4 ) {
181
- case 0x0 : // 4 Mbit (512KB)
182
- return (512_kB);
183
- case 0x1 : // 2 MBit (256KB)
184
- return (256_kB);
185
- case 0x2 : // 8 MBit (1MB)
186
- return (1_MB);
187
- case 0x3 : // 16 MBit (2MB)
188
- return (2_MB);
189
- case 0x4 : // 32 MBit (4MB)
190
- return (4_MB);
191
- case 0x5 : // 64 MBit (8MB)
192
- return (8_MB);
193
- case 0x6 : // 128 MBit (16MB)
194
- return (16_MB);
195
- case 0x7 : // 256 MBit (32MB)
196
- return (32_MB);
197
- default : // fail?
198
- return 0 ;
199
- }
180
+ return magicFlashChipSize ((bytes[3 ] & 0xf0 ) >> 4 );
200
181
}
201
182
return 0 ;
202
183
}
@@ -207,18 +188,7 @@ uint32_t EspClass::getFlashChipSpeed(void)
207
188
uint8_t * bytes = (uint8_t *) &data;
208
189
// read first 4 byte (magic byte + flash config)
209
190
if (spi_flash_read (0x0000 , &data, 4 ) == SPI_FLASH_RESULT_OK) {
210
- switch (bytes[3 ] & 0x0F ) {
211
- case 0x0 : // 40 MHz
212
- return (40_MHz);
213
- case 0x1 : // 26 MHz
214
- return (26_MHz);
215
- case 0x2 : // 20 MHz
216
- return (20_MHz);
217
- case 0xf : // 80 MHz
218
- return (80_MHz);
219
- default : // fail?
220
- return 0 ;
221
- }
191
+ return magicFlashChipSpeed (bytes[3 ] & 0x0F );
222
192
}
223
193
return 0 ;
224
194
}
@@ -230,10 +200,53 @@ FlashMode_t EspClass::getFlashChipMode(void)
230
200
uint8_t * bytes = (uint8_t *) &data;
231
201
// read first 4 byte (magic byte + flash config)
232
202
if (spi_flash_read (0x0000 , &data, 4 ) == SPI_FLASH_RESULT_OK) {
233
- mode = (FlashMode_t) bytes[2 ];
234
- if (mode > FM_DOUT) {
235
- mode = FM_UNKNOWN;
236
- }
203
+ mode = magicFlashChipMode (bytes[2 ]);
204
+ }
205
+ return mode;
206
+ }
207
+
208
+ uint32_t EspClass::magicFlashChipSize (uint8_t byte) {
209
+ switch (byte & 0x0F ) {
210
+ case 0x0 : // 4 Mbit (512KB)
211
+ return (512_kB);
212
+ case 0x1 : // 2 MBit (256KB)
213
+ return (256_kB);
214
+ case 0x2 : // 8 MBit (1MB)
215
+ return (1_MB);
216
+ case 0x3 : // 16 MBit (2MB)
217
+ return (2_MB);
218
+ case 0x4 : // 32 MBit (4MB)
219
+ return (4_MB);
220
+ case 0x5 : // 64 MBit (8MB)
221
+ return (8_MB);
222
+ case 0x6 : // 128 MBit (16MB)
223
+ return (16_MB);
224
+ case 0x7 : // 256 MBit (32MB)
225
+ return (32_MB);
226
+ default : // fail?
227
+ return 0 ;
228
+ }
229
+ }
230
+
231
+ uint32_t EspClass::magicFlashChipSpeed (uint8_t byte) {
232
+ switch (byte & 0x0F ) {
233
+ case 0x0 : // 40 MHz
234
+ return (40_MHz);
235
+ case 0x1 : // 26 MHz
236
+ return (26_MHz);
237
+ case 0x2 : // 20 MHz
238
+ return (20_MHz);
239
+ case 0xf : // 80 MHz
240
+ return (80_MHz);
241
+ default : // fail?
242
+ return 0 ;
243
+ }
244
+ }
245
+
246
+ FlashMode_t EspClass::magicFlashChipMode (uint8_t byte) {
247
+ FlashMode_t mode = (FlashMode_t) byte;
248
+ if (mode > FM_DOUT) {
249
+ mode = FM_UNKNOWN;
237
250
}
238
251
return mode;
239
252
}
0 commit comments