main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // (C) 2024 Victor Suarez Rovere <suarezvictor@gmail.com>
  2. // SPDX-License-Identifier: AGPL-3.0-only
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6. #include "sys.h"
  7. #include "driver_uart.h"
  8. #include "sw_accel_cores.h"
  9. #define LED_BUILTIN 22
  10. static const uint32_t led_mask = 1 << LED_BUILTIN;
  11. extern uintptr_t framebuffer_address;
  12. extern unsigned framebuffer_pitch;
  13. #if 0
  14. static void graphics_test(void)
  15. {
  16. int x0 = 100, x1 = 300;
  17. int y0 = 100, y1 = 300;
  18. accel_line32(framebuffer_address, 0, 100, 100, 0, 0xFF0000FF, framebuffer_pitch); //red
  19. accel_ellipse_fill32(framebuffer_address, x0, y0+300, x1, y0+350, 0xFFFF0000, framebuffer_pitch); //blue
  20. accel_rectangle_fill32(framebuffer_address, x0+400, y0+300, x1+300, y0+350, 0xFF00FF00, framebuffer_pitch); //green
  21. }
  22. #else
  23. unsigned FRAME_WIDTH, FRAME_HEIGHT, FRAME_PITCH;
  24. uintptr_t VIDEO_FRAMEBUFFER_BASE;
  25. #define highres_ticks_freq() (F_XTAL/24)
  26. #define highres_ticks() (cpu_count()/24)
  27. #include "../drawing_test.c"
  28. static void graphics_test(void)
  29. {
  30. VIDEO_FRAMEBUFFER_BASE = framebuffer_address;
  31. FRAME_WIDTH = 640 - 1; //FIXME: this correction is to make colors = 0 for analog VGA
  32. FRAME_HEIGHT = 480;
  33. FRAME_PITCH = framebuffer_pitch;
  34. for(;;)
  35. draw_clock(0xFFFF8000);
  36. }
  37. extern uint8_t jpeg_test_image_640x480_data[];
  38. extern unsigned jpeg_test_image_640x480_data_len;
  39. //#define TJPGD_DEMO
  40. #ifdef TJPGD_DEMO
  41. #include "../../tjpgd3/jpeg_demo.c"
  42. #include "../../tjpgd3/src/tjpgd.c"
  43. static void jpeg_decompress(void)
  44. {
  45. static uint8_t work[16384];
  46. static uint32_t fbdata[480][640];
  47. IODEV devid; // Session identifier
  48. devid.fp = jpeg_test_image_640x480_data;
  49. devid.fbuf = (uint8_t *) fbdata;
  50. devid.wfbuf = 640;
  51. JRESULT res = jpeg_demo(&devid, work, sizeof(work));
  52. if(res == JDR_OK)
  53. framebuffer_address = (uintptr_t) fbdata;
  54. }
  55. #else
  56. int ultraembedded_jpeg_decompress(const uint8_t *jpegdata, size_t jpegdata_size, uint8_t *dst);
  57. static void jpeg_decompress(void)
  58. {
  59. static uint32_t fbdata[480][640];
  60. if(ultraembedded_jpeg_decompress(jpeg_test_image_640x480_data, jpeg_test_image_640x480_data_len, (uint8_t *) fbdata) == 0)
  61. framebuffer_address = (uintptr_t) fbdata;
  62. }
  63. #endif
  64. #endif
  65. int main(void)
  66. {
  67. uart_probe(UART_COMM);
  68. printf("Decompressing JPEG...\r\n");
  69. jpeg_decompress();
  70. printf("Done\r\n");
  71. if(framebuffer_address)
  72. {
  73. void fb_probe(void);
  74. fb_probe();
  75. }
  76. #if 0
  77. uint64_t t0 = highres_ticks();
  78. size_t nbytes = 0;
  79. for(int i=0; ; ++i)
  80. {
  81. //printf("Hello from D1s bare %d!!\r\n", i);
  82. for(int y=0; y < 480; ++y)
  83. {
  84. memset((void*)(framebuffer_address+y*640*4), i, (640-1)*4);
  85. nbytes += (640-1)*4;
  86. }
  87. if((i & 0xFF) == 0)
  88. {
  89. uint64_t t1 = highres_ticks();
  90. printf("bytes %d, dt %d ms\r\n", nbytes, 1000*(t1-t0)/highres_ticks_freq());
  91. jpeg_decompress();
  92. t0 = highres_ticks();
  93. nbytes = 0;
  94. }
  95. io_write32(GPIO_pd_dat, i & 128 ? led_mask : 0);
  96. }
  97. #else
  98. for(;;);
  99. #endif
  100. return 0;
  101. }
  102. void __assert_fail(void)
  103. {
  104. printf("ASSERTION FAILED\r\n");
  105. for(;;);
  106. }