swd_probe_app.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #define MODE_PAGES 4
  21. #define CDBGPWRUPREQ (1 << 28)
  22. #define CDBGPWRUPACK (1 << 29)
  23. #define CSYSPWRUPREQ (1 << 30)
  24. #define CSYSPWRUPACK (1 << 31)
  25. #define WDATAERR (1 << 7)
  26. #define STICKYERR (1 << 5)
  27. #define STAT_ERROR_FLAGS (WDATAERR | STICKYERR)
  28. #define MEMAP_CSW 0x00
  29. #define MEMAP_TAR 0x04
  30. #define MEMAP_DRW 0x0C
  31. #define AP_IDR 0xFC
  32. #define AP_BASE 0xF8
  33. typedef enum { KeyNone, KeyUp, KeyRight, KeyDown, KeyLeft, KeyOK } KeyCode;
  34. typedef enum {
  35. EventTimerTick,
  36. EventKeyPress,
  37. } EventType;
  38. typedef struct {
  39. EventType type;
  40. InputEvent input;
  41. } AppEvent;
  42. typedef struct {
  43. uint32_t ctrlstat;
  44. bool ctrlstat_ok;
  45. uint32_t dlcr;
  46. bool dlcr_ok;
  47. uint32_t dlpidr;
  48. bool dlpidr_ok;
  49. uint32_t dpidr;
  50. bool dpidr_ok;
  51. uint32_t eventstat;
  52. bool eventstat_ok;
  53. uint32_t select;
  54. bool select_ok;
  55. uint32_t targetid;
  56. bool targetid_ok;
  57. } swd_dpreg_t;
  58. typedef struct {
  59. bool ok;
  60. bool tested;
  61. uint8_t revision;
  62. uint16_t designer;
  63. uint8_t class;
  64. uint8_t variant;
  65. uint8_t type;
  66. uint32_t base;
  67. } swd_apidr_info_t;
  68. typedef struct {
  69. uint8_t revision;
  70. uint8_t partno;
  71. uint8_t version;
  72. uint16_t designer;
  73. } swd_dpidr_info_t;
  74. typedef struct {
  75. uint8_t revision;
  76. uint16_t partno;
  77. uint16_t designer;
  78. } swd_targetid_info_t;
  79. typedef struct {
  80. KeyCode last_key;
  81. FuriTimer* _timer;
  82. FuriMessageQueue* _event_queue;
  83. NotificationApp* notification;
  84. swd_targetid_info_t targetid_info;
  85. swd_dpidr_info_t dpidr_info;
  86. swd_dpreg_t dp_regs;
  87. swd_apidr_info_t apidr_info[256];
  88. uint8_t current_mask_id;
  89. uint32_t current_mask;
  90. uint8_t io_swc;
  91. uint8_t io_swd;
  92. uint8_t io_num_swc;
  93. uint8_t io_num_swd;
  94. uint32_t detected_timeout;
  95. bool detected;
  96. bool detected_device;
  97. bool detected_notified;
  98. uint8_t mode_page;
  99. uint8_t ap_pos;
  100. uint8_t ap_scanned;
  101. uint32_t hex_addr;
  102. uint8_t hex_select;
  103. uint8_t hex_buffer[32];
  104. uint8_t hex_buffer_valid[8];
  105. uint8_t hex_read_delay;
  106. char state_string[32];
  107. } AppFSM;
  108. const NotificationSequence seq_c_minor = {
  109. &message_note_c4,
  110. &message_delay_100,
  111. &message_sound_off,
  112. &message_delay_10,
  113. &message_note_ds4,
  114. &message_delay_100,
  115. &message_sound_off,
  116. &message_delay_10,
  117. &message_note_g4,
  118. &message_delay_100,
  119. &message_sound_off,
  120. &message_delay_10,
  121. &message_vibro_on,
  122. &message_delay_50,
  123. &message_vibro_off,
  124. NULL,
  125. };
  126. #endif