malveke_gb_emulator.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // TODO
  2. // (DONE) Fix performance when not being charged
  3. // (DONE) Add UART command parsing to Esp32
  4. // (DONE) Prepare application and icon on github
  5. // (DONE) Write snapshots to SD card
  6. // 5. Set a constant refresh rate to the Flipper's display
  7. // 6. Emulate grayscale
  8. // 7. Photo browser app
  9. #include <furi.h>
  10. #include <furi_hal.h>
  11. #include <gui/gui.h>
  12. #include <gui/icon_i.h>
  13. #include <notification/notification.h>
  14. #include <notification/notification_messages.h>
  15. #include <gui/elements.h>
  16. #include <gui/view_dispatcher.h>
  17. #include <gui/modules/dialog_ex.h>
  18. #include <storage/filesystem_api_defines.h>
  19. #include <storage/storage.h>
  20. #include <expansion/expansion.h>
  21. #define THREAD_ALLOC 2048
  22. #define FRAME_WIDTH 128
  23. #define FRAME_HEIGTH 64
  24. #define FRAME_BIT_DEPTH 1
  25. #define FRAME_BUFFER_LENGTH \
  26. (FRAME_WIDTH * FRAME_HEIGTH * FRAME_BIT_DEPTH / 8) // 128*64*1 / 8 = 1024
  27. #define ROW_BUFFER_LENGTH (FRAME_WIDTH / 8) // 128/8 = 16
  28. #define LAST_ROW_INDEX (FRAME_BUFFER_LENGTH - ROW_BUFFER_LENGTH) // 1024 - 16 = 1008
  29. #define RING_BUFFER_LENGTH (ROW_BUFFER_LENGTH + 3) // ROW_BUFFER_LENGTH + Header => 16 + 3 = 19
  30. #define BITMAP_HEADER_LENGTH 62
  31. #define IMAGE_FILE_DIRECTORY_PATH EXT_PATH("DCIM")
  32. static const unsigned char bitmap_header[BITMAP_HEADER_LENGTH] = {
  33. 0x42, 0x4D, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
  34. 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
  35. 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00};
  37. const uint8_t _I_DolphinCommon_56x48_0[] = {
  38. 0x01, 0x00, 0xdf, 0x00, 0x00, 0x1f, 0xfe, 0x0e, 0x05, 0x3f, 0x04, 0x06, 0x78, 0x06, 0x30, 0x20,
  39. 0xf8, 0x00, 0xc6, 0x12, 0x1c, 0x04, 0x0c, 0x0a, 0x38, 0x08, 0x08, 0x0c, 0x60, 0xc0, 0x21, 0xe0,
  40. 0x04, 0x0a, 0x18, 0x02, 0x1b, 0x00, 0x18, 0xa3, 0x00, 0x21, 0x90, 0x01, 0x8a, 0x20, 0x02, 0x19,
  41. 0x80, 0x18, 0x80, 0x64, 0x09, 0x20, 0x89, 0x81, 0x8c, 0x3e, 0x41, 0xe2, 0x80, 0x50, 0x00, 0x43,
  42. 0x08, 0x01, 0x0c, 0xfc, 0x68, 0x40, 0x61, 0xc0, 0x50, 0x30, 0x00, 0x63, 0xa0, 0x7f, 0x80, 0xc4,
  43. 0x41, 0x19, 0x07, 0xff, 0x02, 0x06, 0x18, 0x24, 0x03, 0x41, 0xf3, 0x2b, 0x10, 0x19, 0x38, 0x10,
  44. 0x30, 0x31, 0x7f, 0xe0, 0x34, 0x08, 0x30, 0x19, 0x60, 0x80, 0x65, 0x86, 0x0a, 0x4c, 0x0c, 0x30,
  45. 0x81, 0xb9, 0x41, 0xa0, 0x54, 0x08, 0xc7, 0xe2, 0x06, 0x8a, 0x18, 0x25, 0x02, 0x21, 0x0f, 0x19,
  46. 0x88, 0xd8, 0x6e, 0x1b, 0x01, 0xd1, 0x1b, 0x86, 0x39, 0x66, 0x3a, 0xa4, 0x1a, 0x50, 0x06, 0x48,
  47. 0x18, 0x18, 0xd0, 0x03, 0x01, 0x41, 0x98, 0xcc, 0x60, 0x39, 0x01, 0x49, 0x2d, 0x06, 0x03, 0x50,
  48. 0xf8, 0x40, 0x3e, 0x02, 0xc1, 0x82, 0x86, 0xc7, 0xfe, 0x0f, 0x28, 0x2c, 0x91, 0xd2, 0x90, 0x9a,
  49. 0x18, 0x19, 0x3e, 0x6d, 0x73, 0x12, 0x16, 0x00, 0x32, 0x49, 0x72, 0xc0, 0x7e, 0x5d, 0x44, 0xba,
  50. 0x2c, 0x08, 0xa4, 0xc8, 0x82, 0x06, 0x17, 0xe0, 0x81, 0x90, 0x2a, 0x40, 0x61, 0xe1, 0xa2, 0x44,
  51. 0x0c, 0x76, 0x2b, 0xe8, 0x89, 0x26, 0x43, 0x83, 0x31, 0x8c, 0x78, 0x0c, 0xb0, 0x48, 0x10, 0x1a,
  52. 0xe0, 0x00, 0x63,
  53. };
  54. const uint8_t* const _I_DolphinCommon_56x48[] = {_I_DolphinCommon_56x48_0};
  55. const Icon I_DolphinCommon_56x48 = {
  56. .width = 56,
  57. .height = 48,
  58. .frame_count = 1,
  59. .frame_rate = 0,
  60. .frames = _I_DolphinCommon_56x48};
  61. typedef struct UartDumpModel UartDumpModel;
  62. typedef struct {
  63. Gui* gui;
  64. Storage* storage;
  65. NotificationApp* notification;
  66. ViewDispatcher* view_dispatcher;
  67. FuriHalSerialHandle* serial_handle_uart;
  68. FuriHalSerialHandle* serial_handle_lp_uart;
  69. View* view;
  70. FuriThread* worker_thread;
  71. FuriStreamBuffer* rx_stream;
  72. } UartEchoApp;
  73. struct UartDumpModel {
  74. uint8_t pixels[FRAME_BUFFER_LENGTH];
  75. File* cameraSav;
  76. bool initialized;
  77. int page;
  78. uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
  79. uint8_t ringbuffer_index;
  80. };
  81. typedef enum {
  82. WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
  83. WorkerEventStop = (1 << 1),
  84. WorkerEventRx = (1 << 2),
  85. } WorkerEventFlags;
  86. #define WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
  87. const NotificationSequence sequence_notification = {
  88. &message_display_backlight_on,
  89. &message_delay_10,
  90. NULL,
  91. };