swd_probe_app.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef __ARHA_FLIPPERAPP_DEMO
  2. #define __ARHA_FLIPPERAPP_DEMO
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include <stdio.h>
  6. #include <furi.h>
  7. #include <furi_hal.h>
  8. #include <furi_hal_speaker.h>
  9. #include <gui/gui.h>
  10. #include <input/input.h>
  11. #include <lib/subghz/receiver.h>
  12. #include <lib/subghz/transmitter.h>
  13. #include <lib/subghz/subghz_file_encoder_worker.h>
  14. #include <notification/notification.h>
  15. #include <notification/notification_messages.h>
  16. #define TAG "SWD"
  17. #define SWD_DELAY_US 1
  18. #define TIMER_HZ 50
  19. #define TIMEOUT 3
  20. typedef enum {
  21. ModePageScan = 0,
  22. ModePageDPRegs = 1,
  23. ModePageDPID = 2,
  24. ModePageAPID = 3,
  25. ModePageCount = 4,
  26. ModePageHexDump = 0x100,
  27. } ModePages;
  28. #define CDBGPWRUPREQ (1 << 28)
  29. #define CDBGPWRUPACK (1 << 29)
  30. #define CSYSPWRUPREQ (1 << 30)
  31. #define CSYSPWRUPACK (1 << 31)
  32. #define WDATAERR (1 << 7)
  33. #define STICKYERR (1 << 5)
  34. #define STAT_ERROR_FLAGS (WDATAERR | STICKYERR)
  35. #define MEMAP_CSW 0x00
  36. #define MEMAP_TAR 0x04
  37. #define MEMAP_DRW 0x0C
  38. #define AP_IDR 0xFC
  39. #define AP_BASE 0xF8
  40. typedef enum { KeyNone, KeyUp, KeyRight, KeyDown, KeyLeft, KeyOK } KeyCode;
  41. typedef enum {
  42. EventTimerTick,
  43. EventKeyPress,
  44. } EventType;
  45. typedef struct {
  46. EventType type;
  47. InputEvent input;
  48. } AppEvent;
  49. typedef struct {
  50. uint32_t ctrlstat;
  51. bool ctrlstat_ok;
  52. uint32_t dlcr;
  53. bool dlcr_ok;
  54. uint32_t dlpidr;
  55. bool dlpidr_ok;
  56. uint32_t dpidr;
  57. bool dpidr_ok;
  58. uint32_t eventstat;
  59. bool eventstat_ok;
  60. uint32_t select;
  61. bool select_ok;
  62. uint32_t targetid;
  63. bool targetid_ok;
  64. } swd_dpreg_t;
  65. typedef struct {
  66. bool ok;
  67. bool tested;
  68. uint8_t revision;
  69. uint16_t designer;
  70. uint8_t class;
  71. uint8_t variant;
  72. uint8_t type;
  73. uint32_t base;
  74. } swd_apidr_info_t;
  75. typedef struct {
  76. uint8_t revision;
  77. uint8_t partno;
  78. uint8_t version;
  79. uint16_t designer;
  80. } swd_dpidr_info_t;
  81. typedef struct {
  82. uint8_t revision;
  83. uint16_t partno;
  84. uint16_t designer;
  85. } swd_targetid_info_t;
  86. typedef struct {
  87. KeyCode last_key;
  88. FuriTimer* _timer;
  89. FuriMessageQueue* _event_queue;
  90. NotificationApp* notification;
  91. swd_targetid_info_t targetid_info;
  92. swd_dpidr_info_t dpidr_info;
  93. swd_dpreg_t dp_regs;
  94. swd_apidr_info_t apidr_info[256];
  95. uint8_t current_mask_id;
  96. uint32_t current_mask;
  97. uint8_t io_swc;
  98. uint8_t io_swd;
  99. uint8_t io_num_swc;
  100. uint8_t io_num_swd;
  101. uint32_t detected_timeout;
  102. bool detected;
  103. bool detected_device;
  104. bool detected_notified;
  105. uint32_t mode_page;
  106. uint8_t ap_pos;
  107. uint8_t ap_scanned;
  108. uint32_t hex_addr;
  109. uint8_t hex_select;
  110. uint8_t hex_buffer[32];
  111. uint8_t hex_buffer_valid[8];
  112. uint8_t hex_read_delay;
  113. char state_string[32];
  114. } AppFSM;
  115. const NotificationSequence seq_c_minor = {
  116. &message_note_c4,
  117. &message_delay_100,
  118. &message_sound_off,
  119. &message_delay_10,
  120. &message_note_ds4,
  121. &message_delay_100,
  122. &message_sound_off,
  123. &message_delay_10,
  124. &message_note_g4,
  125. &message_delay_100,
  126. &message_sound_off,
  127. &message_delay_10,
  128. &message_vibro_on,
  129. &message_delay_50,
  130. &message_vibro_off,
  131. NULL,
  132. };
  133. #endif