diff options
Diffstat (limited to 'firmware/target/arm/imx233/debug-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/debug-imx233.c | 134 |
1 files changed, 131 insertions, 3 deletions
diff --git a/firmware/target/arm/imx233/debug-imx233.c b/firmware/target/arm/imx233/debug-imx233.c index 808716916c..c5646a1c91 100644 --- a/firmware/target/arm/imx233/debug-imx233.c +++ b/firmware/target/arm/imx233/debug-imx233.c | |||
@@ -45,6 +45,7 @@ | |||
45 | #include "button.h" | 45 | #include "button.h" |
46 | #include "button-imx233.h" | 46 | #include "button-imx233.h" |
47 | #include "sdmmc-imx233.h" | 47 | #include "sdmmc-imx233.h" |
48 | #include "led-imx233.h" | ||
48 | #include "storage.h" | 49 | #include "storage.h" |
49 | 50 | ||
50 | #include "regs/usbphy.h" | 51 | #include "regs/usbphy.h" |
@@ -792,6 +793,13 @@ bool dbg_hw_info_ocotp(void) | |||
792 | } | 793 | } |
793 | } | 794 | } |
794 | 795 | ||
796 | static void get_pwm_freq_duty(int chan, int *freq, int *duty) | ||
797 | { | ||
798 | struct imx233_pwm_info_t info = imx233_pwm_get_info(chan); | ||
799 | *freq = imx233_clkctrl_get_freq(CLK_XTAL) * 1000 / info.cdiv / info.period; | ||
800 | *duty = (info.inactive - info.active) * 100 / info.period; | ||
801 | } | ||
802 | |||
795 | bool dbg_hw_info_pwm(void) | 803 | bool dbg_hw_info_pwm(void) |
796 | { | 804 | { |
797 | lcd_setfont(FONT_SYSFIXED); | 805 | lcd_setfont(FONT_SYSFIXED); |
@@ -833,14 +841,14 @@ bool dbg_hw_info_pwm(void) | |||
833 | } | 841 | } |
834 | else | 842 | else |
835 | { | 843 | { |
836 | char *prefix = ""; | 844 | int freq, duty; |
837 | int freq = imx233_clkctrl_get_freq(CLK_XTAL) * 1000 / info.cdiv / info.period; | 845 | get_pwm_freq_duty(i, &freq, &duty); |
846 | const char *prefix = ""; | ||
838 | if(freq > 1000) | 847 | if(freq > 1000) |
839 | { | 848 | { |
840 | prefix = "K"; | 849 | prefix = "K"; |
841 | freq /= 1000; | 850 | freq /= 1000; |
842 | } | 851 | } |
843 | int duty = (info.inactive - info.active) * 100 / info.period; | ||
844 | lcd_putsf(0, line++, "%d @%d %sHz, %d%% %c/%c", i, freq, prefix, | 852 | lcd_putsf(0, line++, "%d @%d %sHz, %d%% %c/%c", i, freq, prefix, |
845 | duty, info.active_state, info.inactive_state); | 853 | duty, info.active_state, info.inactive_state); |
846 | } | 854 | } |
@@ -1261,6 +1269,125 @@ bool dbg_hw_info_sdmmc(void) | |||
1261 | } | 1269 | } |
1262 | } | 1270 | } |
1263 | 1271 | ||
1272 | static const char *get_led_col(enum imx233_led_color_t col) | ||
1273 | { | ||
1274 | switch(col) | ||
1275 | { | ||
1276 | case LED_RED: return "red"; | ||
1277 | case LED_GREEN: return "green"; | ||
1278 | case LED_BLUE: return "blue"; | ||
1279 | default: return "unknown"; | ||
1280 | } | ||
1281 | } | ||
1282 | |||
1283 | bool dbg_hw_info_led(void) | ||
1284 | { | ||
1285 | lcd_setfont(FONT_SYSFIXED); | ||
1286 | int cur_led = 0, cur_chan = 0; | ||
1287 | bool nr_leds = imx233_led_get_count(); | ||
1288 | struct imx233_led_t *leds = imx233_led_get_info(); | ||
1289 | bool prev_pending = false; | ||
1290 | bool next_pending = false; | ||
1291 | bool editing = false; | ||
1292 | |||
1293 | while(1) | ||
1294 | { | ||
1295 | int button = my_get_action(HZ / 10); | ||
1296 | switch(button) | ||
1297 | { | ||
1298 | case ACT_NEXT: | ||
1299 | if(nr_leds > 0 && !editing) | ||
1300 | { | ||
1301 | cur_chan++; | ||
1302 | if(cur_chan == leds[cur_led].nr_chan) | ||
1303 | { | ||
1304 | cur_chan = 0; | ||
1305 | cur_led = (cur_led + 1) % nr_leds; | ||
1306 | } | ||
1307 | } | ||
1308 | else | ||
1309 | next_pending = true; | ||
1310 | break; | ||
1311 | case ACT_PREV: | ||
1312 | if(nr_leds > 0 && !editing) | ||
1313 | { | ||
1314 | cur_chan--; | ||
1315 | if(cur_chan == -1) | ||
1316 | { | ||
1317 | cur_led = (cur_led + nr_leds - 1) % nr_leds; | ||
1318 | cur_chan = leds[cur_led].nr_chan - 1; | ||
1319 | } | ||
1320 | } | ||
1321 | else | ||
1322 | prev_pending = true; | ||
1323 | break; | ||
1324 | case ACT_OK: | ||
1325 | editing = !editing; | ||
1326 | break; | ||
1327 | case ACT_CANCEL: | ||
1328 | lcd_setfont(FONT_UI); | ||
1329 | return false; | ||
1330 | } | ||
1331 | |||
1332 | lcd_clear_display(); | ||
1333 | int line = 0; | ||
1334 | if(nr_leds == 0) | ||
1335 | lcd_putsf(0, line++, "This device has no LED!"); | ||
1336 | for(int led = 0; led < imx233_led_get_count(); led++) | ||
1337 | { | ||
1338 | lcd_putsf(0, line++, "LED %d:", led); | ||
1339 | for(int chan = 0; chan < leds[led].nr_chan; chan++) | ||
1340 | { | ||
1341 | /* read current configuration */ | ||
1342 | char buffer[64]; | ||
1343 | bool use_pwm = false; | ||
1344 | int duty = 0, freq = 1; | ||
1345 | bool on = false; | ||
1346 | if(leds[led].chan[chan].has_pwm && | ||
1347 | imx233_pwm_is_enabled(leds[led].chan[chan].pwm_chan)) | ||
1348 | { | ||
1349 | get_pwm_freq_duty(leds[led].chan[chan].pwm_chan, &freq, &duty); | ||
1350 | /* assume active is high and inactive is low */ | ||
1351 | snprintf(buffer, sizeof(buffer), "%d Hz, %d%%", freq, duty); | ||
1352 | use_pwm = true; | ||
1353 | } | ||
1354 | else | ||
1355 | { | ||
1356 | on = imx233_pinctrl_get_gpio(leds[led].chan[chan].gpio_bank, | ||
1357 | leds[led].chan[chan].gpio_pin); | ||
1358 | snprintf(buffer, sizeof(buffer), "%s", on ? "on" : "off"); | ||
1359 | } | ||
1360 | if(cur_led == led && cur_chan == chan) | ||
1361 | lcd_set_foreground(editing ? LCD_RGBPACK(255, 0, 0) : LCD_RGBPACK(0, 0, 255)); | ||
1362 | lcd_putsf(0, line++, " %s: %s", | ||
1363 | get_led_col(leds[led].chan[chan].color), buffer); | ||
1364 | lcd_set_foreground(LCD_WHITE); | ||
1365 | /* do edit */ | ||
1366 | if(cur_led != led || cur_chan != chan || !editing) | ||
1367 | continue; | ||
1368 | if(!next_pending && !prev_pending) | ||
1369 | continue; | ||
1370 | bool inc = next_pending; | ||
1371 | next_pending = false; | ||
1372 | prev_pending = false; | ||
1373 | if(use_pwm) | ||
1374 | { | ||
1375 | duty += inc ? 10 : -10; | ||
1376 | if(duty < 0) | ||
1377 | duty = 0; | ||
1378 | if(duty > 100) | ||
1379 | duty = 100; | ||
1380 | imx233_led_set_pwm(cur_led, cur_chan, freq, duty); | ||
1381 | } | ||
1382 | else | ||
1383 | imx233_led_set(cur_led, cur_chan, !on); | ||
1384 | } | ||
1385 | } | ||
1386 | lcd_update(); | ||
1387 | yield(); | ||
1388 | } | ||
1389 | } | ||
1390 | |||
1264 | #ifdef HAVE_DUALBOOT_STUB | 1391 | #ifdef HAVE_DUALBOOT_STUB |
1265 | bool dbg_hw_info_dualboot(void) | 1392 | bool dbg_hw_info_dualboot(void) |
1266 | { | 1393 | { |
@@ -1341,6 +1468,7 @@ static struct | |||
1341 | {"timrot", dbg_hw_info_timrot}, | 1468 | {"timrot", dbg_hw_info_timrot}, |
1342 | {"button", dbg_hw_info_button}, | 1469 | {"button", dbg_hw_info_button}, |
1343 | {"sdmmc", dbg_hw_info_sdmmc}, | 1470 | {"sdmmc", dbg_hw_info_sdmmc}, |
1471 | {"led", dbg_hw_info_led}, | ||
1344 | #ifdef HAVE_DUALBOOT_STUB | 1472 | #ifdef HAVE_DUALBOOT_STUB |
1345 | {"dualboot", dbg_hw_info_dualboot}, | 1473 | {"dualboot", dbg_hw_info_dualboot}, |
1346 | #endif | 1474 | #endif |