123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- #include "odroid/audio.h"
- #include "odroid/battery.h"
- #include "odroid/display.h"
- #include "odroid/input.h"
- #include "odroid/sdcard.h"
- #include "macros.h"
- #include "text.h"
- #include <esp_log.h>
- #include <freertos/FreeRTOS.h>
- #include <freertos/task.h>
- #include <string.h>
-
-
- static const char* LOG_TAG = "Main";
- static uint16_t gFramebuffer[LCD_WIDTH * LCD_HEIGHT];
-
-
- static const uint16_t palette[4] =
- {
- 0xFFFF,
- 0x55AD,
- 0xAA52,
- 0x0000,
- };
-
- static const uint8_t tiles[][16*16] =
- {
- // White
- {
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0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 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
- };
-
-
- void DrawTile(int index, int x, int y)
- {
- int startX = x * 16;
- int startY = y * 16;
-
- for (int row = 0; row < 16; ++row)
- {
- for (int col = 0; col < 16; ++col)
- {
- uint8_t paletteIndex = tiles[index][row * 16 + col];
-
- int screenY = startY + row;
- int screenX = startX + col;
-
- uint16_t color = palette[paletteIndex];
-
- gFramebuffer[screenY * LCD_WIDTH + screenX] = color;
- }
- }
- }
-
-
- void app_main(void)
- {
- Odroid_InitializeInput();
- Odroid_InitializeDisplay();
- Odroid_InitializeSdcard();
- Odroid_InitializeBatteryReader();
- Odroid_InitializeAudio();
-
- ESP_LOGI(LOG_TAG, "Odroid initialization complete - entering main loop");
-
-
- uint8_t frameIndex = 0;
- char snapFilename[20];
- int xLeft = 0;
-
- for (;;)
- {
- memset(gFramebuffer, 0xff, 320*240*2);
-
- Odroid_Input input = Odroid_PollInput();
-
- if (input.left)
- {
- xLeft -= 1;
-
- if (xLeft < 0)
- {
- xLeft = 39;
- }
- }
-
- else if (input.right)
- {
- xLeft += 1;
-
- if (xLeft > 39)
- {
- xLeft = 0;
- }
- }
-
- for (int tileY = 0; tileY < 15; ++tileY)
- {
- for (int tileX = xLeft; tileX < xLeft + 20; ++tileX)
- {
- int tile = tileX % 40;
-
- int tileIndex = tileBuffer[tileY][tile];
-
- DrawTile(tileIndex, tileX - xLeft, tileY);
- }
- }
-
-
- char string[5];
- snprintf(string, 5, "%02d", xLeft);
- DrawText(gFramebuffer, string, 2, 0, 0, palette[3]);
-
- int tileRight = (xLeft + 20) % 40;
- snprintf(string, 5, "%02d", tileRight);
- DrawText(gFramebuffer, string, 2, 18, 0, palette[3]);
-
- if (input.menu)
- {
- snprintf(snapFilename, 20, "/sdcard/frame%02d", frameIndex);
-
- ESP_LOGI(LOG_TAG, "Writing snapshot to %s", snapFilename);
-
- FILE* snapFile = fopen(snapFilename, "wb");
- assert(snapFile);
-
- fwrite(gFramebuffer, 1, LCD_WIDTH * LCD_HEIGHT * sizeof(gFramebuffer[0]), snapFile);
-
- fclose(snapFile);
-
- ++frameIndex;
- }
-
-
- Odroid_DrawFrame(gFramebuffer);
- }
-
- // Should never get here
- esp_restart();
- }
|