dap_scene_config.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "../dap_gui_i.h"
  2. static const char* swd_pins[] = {[DapSwdPinsPA7PA6] = "2,3", [DapSwdPinsPA14PA13] = "10,12"};
  3. static const char* uart_pins[] = {[DapUartTypeUSART1] = "13,14", [DapUartTypeLPUART1] = "15,16"};
  4. static const char* uart_swap[] = {[DapUartTXRXNormal] = "No", [DapUartTXRXSwap] = "Yes"};
  5. static void swd_pins_cb(VariableItem* item) {
  6. DapGuiApp* app = variable_item_get_context(item);
  7. uint8_t index = variable_item_get_current_value_index(item);
  8. variable_item_set_current_value_text(item, swd_pins[index]);
  9. DapConfig* config = dap_app_get_config(app->dap_app);
  10. config->swd_pins = index;
  11. dap_app_set_config(app->dap_app, config);
  12. }
  13. static void uart_pins_cb(VariableItem* item) {
  14. DapGuiApp* app = variable_item_get_context(item);
  15. uint8_t index = variable_item_get_current_value_index(item);
  16. variable_item_set_current_value_text(item, uart_pins[index]);
  17. DapConfig* config = dap_app_get_config(app->dap_app);
  18. config->uart_pins = index;
  19. dap_app_set_config(app->dap_app, config);
  20. }
  21. static void uart_swap_cb(VariableItem* item) {
  22. DapGuiApp* app = variable_item_get_context(item);
  23. uint8_t index = variable_item_get_current_value_index(item);
  24. variable_item_set_current_value_text(item, uart_swap[index]);
  25. DapConfig* config = dap_app_get_config(app->dap_app);
  26. config->uart_swap = index;
  27. dap_app_set_config(app->dap_app, config);
  28. }
  29. static void ok_cb(void* context, uint32_t index) {
  30. DapGuiApp* app = context;
  31. switch(index) {
  32. case 3:
  33. view_dispatcher_send_custom_event(app->view_dispatcher, DapAppCustomEventHelp);
  34. break;
  35. case 4:
  36. view_dispatcher_send_custom_event(app->view_dispatcher, DapAppCustomEventAbout);
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. void dap_scene_config_on_enter(void* context) {
  43. DapGuiApp* app = context;
  44. VariableItemList* var_item_list = app->var_item_list;
  45. VariableItem* item;
  46. DapConfig* config = dap_app_get_config(app->dap_app);
  47. item = variable_item_list_add(
  48. var_item_list, "SWC SWD Pins", COUNT_OF(swd_pins), swd_pins_cb, app);
  49. variable_item_set_current_value_index(item, config->swd_pins);
  50. variable_item_set_current_value_text(item, swd_pins[config->swd_pins]);
  51. item =
  52. variable_item_list_add(var_item_list, "UART Pins", COUNT_OF(uart_pins), uart_pins_cb, app);
  53. variable_item_set_current_value_index(item, config->uart_pins);
  54. variable_item_set_current_value_text(item, uart_pins[config->uart_pins]);
  55. item = variable_item_list_add(
  56. var_item_list, "Swap TX RX", COUNT_OF(uart_swap), uart_swap_cb, app);
  57. variable_item_set_current_value_index(item, config->uart_swap);
  58. variable_item_set_current_value_text(item, uart_swap[config->uart_swap]);
  59. variable_item_list_add(var_item_list, "Help and Pinout", 0, NULL, NULL);
  60. variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
  61. variable_item_list_set_selected_item(
  62. var_item_list, scene_manager_get_scene_state(app->scene_manager, DapSceneConfig));
  63. variable_item_list_set_enter_callback(var_item_list, ok_cb, app);
  64. view_dispatcher_switch_to_view(app->view_dispatcher, DapGuiAppViewVarItemList);
  65. }
  66. bool dap_scene_config_on_event(void* context, SceneManagerEvent event) {
  67. DapGuiApp* app = context;
  68. if(event.type == SceneManagerEventTypeCustom) {
  69. if(event.event == DapAppCustomEventHelp) {
  70. scene_manager_next_scene(app->scene_manager, DapSceneHelp);
  71. return true;
  72. } else if(event.event == DapAppCustomEventAbout) {
  73. scene_manager_next_scene(app->scene_manager, DapSceneAbout);
  74. return true;
  75. }
  76. }
  77. return false;
  78. }
  79. void dap_scene_config_on_exit(void* context) {
  80. DapGuiApp* app = context;
  81. scene_manager_set_scene_state(
  82. app->scene_manager,
  83. DapSceneConfig,
  84. variable_item_list_get_selected_item_index(app->var_item_list));
  85. variable_item_list_reset(app->var_item_list);
  86. }