Part 4: Storage
This commit is contained in:
parent
801a4e790d
commit
d86013c90c
|
@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.5)
|
||||||
set(EXTRA_COMPONENT_DIRS "src")
|
set(EXTRA_COMPONENT_DIRS "src")
|
||||||
set(COMPONENTS "esptool_py src")
|
set(COMPONENTS "esptool_py src")
|
||||||
|
|
||||||
|
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
project(game)
|
project(game)
|
||||||
|
|
12
README.md
12
README.md
|
@ -2,6 +2,18 @@
|
||||||
|
|
||||||
* Get the [ESP-IDF v4.0](https://github.com/espressif/esp-idf/releases/tag/v4.0)
|
* Get the [ESP-IDF v4.0](https://github.com/espressif/esp-idf/releases/tag/v4.0)
|
||||||
* Follow Steps 1 through 3 of the [Documentation](https://docs.espressif.com/projects/esp-idf/en/v4.0/get-started/index.html#step-1-install-prerequisites)
|
* Follow Steps 1 through 3 of the [Documentation](https://docs.espressif.com/projects/esp-idf/en/v4.0/get-started/index.html#step-1-install-prerequisites)
|
||||||
|
* Comment out line 303 of `esp-idf/components/driver/sdspi_host.c` to enable the shared SPI bus
|
||||||
|
|
||||||
|
```c
|
||||||
|
// Initialize SPI bus
|
||||||
|
esp_err_t ret = spi_bus_initialize((spi_host_device_t)slot, &buscfg,
|
||||||
|
slot_config->dma_channel);
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
ESP_LOGD(TAG, "spi_bus_initialize failed with rc=0x%x", ret);
|
||||||
|
//return ret;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
* Modify the `export.sh` script in this directory and fill out `IDF_PATH` and `IDF_TOOLS_PATH`
|
* Modify the `export.sh` script in this directory and fill out `IDF_PATH` and `IDF_TOOLS_PATH`
|
||||||
* `IDF_PATH` is the extracted ESP-IDF
|
* `IDF_PATH` is the extracted ESP-IDF
|
||||||
* `IDF_TOOLS_PATH` is the path to the toolchain
|
* `IDF_TOOLS_PATH` is the path to the toolchain
|
||||||
|
|
|
@ -3,10 +3,12 @@ idf_component_register(
|
||||||
"main.c"
|
"main.c"
|
||||||
"odroid/display.c"
|
"odroid/display.c"
|
||||||
"odroid/input.c"
|
"odroid/input.c"
|
||||||
|
"odroid/sdcard.c"
|
||||||
|
|
||||||
INCLUDE_DIRS
|
INCLUDE_DIRS
|
||||||
"."
|
"."
|
||||||
|
|
||||||
PRIV_REQUIRES
|
PRIV_REQUIRES
|
||||||
"esp_adc_cal")
|
"esp_adc_cal"
|
||||||
|
"fatfs")
|
||||||
|
|
||||||
|
|
54
src/main.c
54
src/main.c
|
@ -1,5 +1,6 @@
|
||||||
#include "odroid/display.h"
|
#include "odroid/display.h"
|
||||||
#include "odroid/input.h"
|
#include "odroid/input.h"
|
||||||
|
#include "odroid/sdcard.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
|
@ -14,6 +15,25 @@ void app_main(void)
|
||||||
{
|
{
|
||||||
Odroid_InitializeInput();
|
Odroid_InitializeInput();
|
||||||
Odroid_InitializeDisplay();
|
Odroid_InitializeDisplay();
|
||||||
|
Odroid_InitializeSdcard();
|
||||||
|
|
||||||
|
// Load sprite
|
||||||
|
uint16_t* sprite = (uint16_t*)malloc(64 * 64 * sizeof(uint16_t));
|
||||||
|
{
|
||||||
|
FILE* spriteFile = fopen("/sdcard/key", "r");
|
||||||
|
assert(spriteFile);
|
||||||
|
|
||||||
|
for (int i = 0; i < 64; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 64; ++j)
|
||||||
|
{
|
||||||
|
fread(sprite, sizeof(uint16_t), 64 * 64, spriteFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(spriteFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ESP_LOGI(LOG_TAG, "Odroid initialization complete - entering main loop");
|
ESP_LOGI(LOG_TAG, "Odroid initialization complete - entering main loop");
|
||||||
|
|
||||||
|
@ -39,12 +59,40 @@ void app_main(void)
|
||||||
else if (input.start) { color = SWAP_ENDIAN_16(RGB565(0, 0, 0xff)); }
|
else if (input.start) { color = SWAP_ENDIAN_16(RGB565(0, 0, 0xff)); }
|
||||||
else if (input.select) { color = SWAP_ENDIAN_16(RGB565(0xff, 0xff, 0xff)); }
|
else if (input.select) { color = SWAP_ENDIAN_16(RGB565(0xff, 0xff, 0xff)); }
|
||||||
|
|
||||||
for (int row = y; row < y + 50; ++row)
|
int spriteRow = 0;
|
||||||
|
int spriteCol = 0;
|
||||||
|
|
||||||
|
for (int row = y; row < y + 64; ++row)
|
||||||
{
|
{
|
||||||
for (int col = x; col < x + 50; ++col)
|
spriteCol = 0;
|
||||||
|
|
||||||
|
for (int col = x; col < x + 64; ++col)
|
||||||
{
|
{
|
||||||
gFramebuffer[LCD_WIDTH * row + col] = color;
|
uint16_t pixelColor = sprite[64 * spriteRow + spriteCol];
|
||||||
|
|
||||||
|
if (pixelColor != 0)
|
||||||
|
{
|
||||||
|
gFramebuffer[row * LCD_WIDTH + col] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
++spriteCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++spriteRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.menu)
|
||||||
|
{
|
||||||
|
const char* snapFilename = "/sdcard/framebuf";
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
Odroid_DrawFrame(gFramebuffer);
|
Odroid_DrawFrame(gFramebuffer);
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include "sdcard.h"
|
||||||
|
#include <esp_vfs_fat.h>
|
||||||
|
#include <driver/sdmmc_host.h>
|
||||||
|
#include <driver/sdspi_host.h>
|
||||||
|
#include <sdmmc_cmd.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const gpio_num_t SD_PIN_MISO = GPIO_NUM_19;
|
||||||
|
static const gpio_num_t SD_PIN_MOSI = GPIO_NUM_23;
|
||||||
|
static const gpio_num_t SD_PIN_SCLK = GPIO_NUM_18;
|
||||||
|
static const gpio_num_t SD_PIN_CS = GPIO_NUM_22;
|
||||||
|
|
||||||
|
|
||||||
|
void Odroid_InitializeSdcard()
|
||||||
|
{
|
||||||
|
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
|
||||||
|
host.slot = VSPI_HOST;
|
||||||
|
|
||||||
|
sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
|
||||||
|
slot_config.gpio_miso = SD_PIN_MISO;
|
||||||
|
slot_config.gpio_mosi = SD_PIN_MOSI;
|
||||||
|
slot_config.gpio_sck = SD_PIN_SCLK;
|
||||||
|
slot_config.gpio_cs = SD_PIN_CS;
|
||||||
|
|
||||||
|
esp_vfs_fat_sdmmc_mount_config_t mount_config = {};
|
||||||
|
mount_config.format_if_mount_failed = false;
|
||||||
|
mount_config.max_files = 5;
|
||||||
|
|
||||||
|
sdmmc_card_t* card;
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card));
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
void Odroid_InitializeSdcard(void);
|
||||||
|
|
Loading…
Reference in New Issue