swd_probe_app.h 2.9 KB

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