mirror of
https://github.com/badgeteam/mch2022-template-app.git
synced 2024-12-22 23:26:36 +00:00
FPGA test
This commit is contained in:
parent
3f3cc1b328
commit
a694f1753f
4 changed files with 8788 additions and 39 deletions
|
@ -25,7 +25,6 @@ esp_err_t ice40_set_reset_wrapper(bool reset) {
|
||||||
void ili9341_set_lcd_mode(bool mode) {
|
void ili9341_set_lcd_mode(bool mode) {
|
||||||
ESP_LOGI(TAG, "LCD mode switch to %s", mode ? "FPGA" : "ESP32");
|
ESP_LOGI(TAG, "LCD mode switch to %s", mode ? "FPGA" : "ESP32");
|
||||||
rp2040_set_lcd_mode(&dev_rp2040, (lcd_mode_t) mode);
|
rp2040_set_lcd_mode(&dev_rp2040, (lcd_mode_t) mode);
|
||||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t _bus_init() {
|
static esp_err_t _bus_init() {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a5be12a6457cbce9a43e67b2e94f05169f1663c1
|
Subproject commit 7929cf7d34a60d5c8c91d06ac727f825aa310852
|
8678
main/fpga.h
Normal file
8678
main/fpga.h
Normal file
File diff suppressed because it is too large
Load diff
146
main/main.c
146
main/main.c
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "rp2040.h"
|
#include "rp2040.h"
|
||||||
|
|
||||||
|
#include "fpga.h"
|
||||||
|
|
||||||
static const char *TAG = "main";
|
static const char *TAG = "main";
|
||||||
|
|
||||||
bool calibrate = true;
|
bool calibrate = true;
|
||||||
|
@ -29,13 +31,17 @@ ICE40* ice40 = NULL;
|
||||||
BNO055* bno055 = NULL;
|
BNO055* bno055 = NULL;
|
||||||
RP2040* rp2040 = NULL;
|
RP2040* rp2040 = NULL;
|
||||||
|
|
||||||
|
uint8_t* framebuffer = NULL;
|
||||||
|
pax_buf_t* pax_buffer = NULL;
|
||||||
|
|
||||||
bno055_vector_t rotation_offset = {.x = 0, .y = 0, .z = 0};
|
bno055_vector_t rotation_offset = {.x = 0, .y = 0, .z = 0};
|
||||||
|
|
||||||
bno055_vector_t acceleration, magnetism, orientation, rotation, linear_acceleration, gravity;
|
bno055_vector_t acceleration, magnetism, orientation, rotation, linear_acceleration, gravity;
|
||||||
|
|
||||||
typedef enum action {
|
typedef enum action {
|
||||||
ACTION_NONE,
|
ACTION_NONE,
|
||||||
ACTION_INSTALLER
|
ACTION_INSTALLER,
|
||||||
|
ACTION_FPGA
|
||||||
} menu_action_t;
|
} menu_action_t;
|
||||||
|
|
||||||
typedef struct _menu_item {
|
typedef struct _menu_item {
|
||||||
|
@ -50,16 +56,29 @@ uint8_t amount_of_items = 0;
|
||||||
bool start_selected = false;
|
bool start_selected = false;
|
||||||
menu_item_t* first_menu_item = NULL;
|
menu_item_t* first_menu_item = NULL;
|
||||||
|
|
||||||
|
bool reset_to_menu = false;
|
||||||
|
bool reload_fpga = false;
|
||||||
|
|
||||||
const char installer_name[] = "Install app...";
|
const char installer_name[] = "Install app...";
|
||||||
|
const char fpga_name[] = "Test FPGA";
|
||||||
|
|
||||||
void button_handler(uint8_t pin, bool value) {
|
void button_handler(uint8_t pin, bool value) {
|
||||||
switch(pin) {
|
switch(pin) {
|
||||||
case PCA9555_PIN_BTN_JOY_LEFT:
|
case PCA9555_PIN_BTN_JOY_LEFT:
|
||||||
printf("Joystick horizontal %s\n", value ? "left" : "center");
|
printf("Joystick horizontal %s\n", value ? "left" : "center");
|
||||||
//ili9341_set_partial_scanning(ili9341, 60, ILI9341_WIDTH - 61);
|
if (value) {
|
||||||
|
for (uint8_t led = 0; led < 5; led++) {
|
||||||
|
rp2040_set_led_value(rp2040, led, 0, 255, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PCA9555_PIN_BTN_JOY_PRESS:
|
case PCA9555_PIN_BTN_JOY_PRESS:
|
||||||
printf("Joystick %s\n", value ? "pressed" : "released");
|
printf("Joystick %s\n", value ? "pressed" : "released");
|
||||||
|
if (value) {
|
||||||
|
for (uint8_t led = 0; led < 5; led++) {
|
||||||
|
rp2040_set_led_value(rp2040, led, 0, 0, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PCA9555_PIN_BTN_JOY_DOWN:
|
case PCA9555_PIN_BTN_JOY_DOWN:
|
||||||
printf("Joystick vertical %s\n", value ? "down" : "center");
|
printf("Joystick vertical %s\n", value ? "down" : "center");
|
||||||
|
@ -80,15 +99,22 @@ void button_handler(uint8_t pin, bool value) {
|
||||||
break;
|
break;
|
||||||
case PCA9555_PIN_BTN_JOY_RIGHT:
|
case PCA9555_PIN_BTN_JOY_RIGHT:
|
||||||
printf("Joy horizontal %s\n", value ? "right" : "center");
|
printf("Joy horizontal %s\n", value ? "right" : "center");
|
||||||
|
if (value) {
|
||||||
|
for (uint8_t led = 0; led < 5; led++) {
|
||||||
|
rp2040_set_led_value(rp2040, led, 255, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PCA9555_PIN_BTN_HOME:
|
case PCA9555_PIN_BTN_HOME:
|
||||||
printf("Home button %s\n", value ? "pressed" : "released");
|
printf("Home button %s\n", value ? "pressed" : "released");
|
||||||
break;
|
break;
|
||||||
case PCA9555_PIN_BTN_MENU:
|
case PCA9555_PIN_BTN_MENU:
|
||||||
printf("Menu button %s\n", value ? "pressed" : "released");
|
printf("Menu button %s\n", value ? "pressed" : "released");
|
||||||
|
if (value) reset_to_menu = true;
|
||||||
break;
|
break;
|
||||||
case PCA9555_PIN_BTN_START: {
|
case PCA9555_PIN_BTN_START: {
|
||||||
printf("Start button %s\n", value ? "pressed" : "released");
|
printf("Start button %s\n", value ? "pressed" : "released");
|
||||||
|
if (value) reload_fpga = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PCA9555_PIN_BTN_SELECT: {
|
case PCA9555_PIN_BTN_SELECT: {
|
||||||
|
@ -274,9 +300,9 @@ esp_err_t graphics_task(pax_buf_t* buffer, ILI9341* ili9341, uint8_t* framebuffe
|
||||||
return ili9341_write(ili9341, framebuffer);
|
return ili9341_write(ili9341, framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t draw_message(pax_buf_t* buffer, ILI9341* ili9341, uint8_t* framebuffer, char* message) {
|
esp_err_t draw_message(char* message) {
|
||||||
pax_background(buffer, 0xFFFFFF);
|
pax_background(pax_buffer, 0xFFFFFF);
|
||||||
pax_draw_text(buffer, pax_col_rgb(0,0,0), PAX_FONT_DEFAULT, 18, 0, 0, message);
|
pax_draw_text(pax_buffer, pax_col_rgb(0,0,0), PAX_FONT_DEFAULT, 18, 0, 0, message);
|
||||||
return ili9341_write(ili9341, framebuffer);
|
return ili9341_write(ili9341, framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,12 +436,14 @@ esp_err_t verify_file_in_psram(FILE* fd) {
|
||||||
|
|
||||||
void fpga_test(void) {
|
void fpga_test(void) {
|
||||||
esp_err_t res;
|
esp_err_t res;
|
||||||
|
/*draw_message("Loading passthrough...");
|
||||||
FILE* fpga_passthrough = fopen("/sd/pt.bin", "rb");
|
FILE* fpga_passthrough = fopen("/sd/pt.bin", "rb");
|
||||||
if (fpga_passthrough == NULL) {
|
if (fpga_passthrough == NULL) {
|
||||||
ESP_LOGE(TAG, "Failed to open passthrough firmware (pt.bin) from the SD card");
|
ESP_LOGE(TAG, "Failed to open passthrough firmware (pt.bin) from the SD card");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_message("Loading RAM...");
|
||||||
ESP_LOGI(TAG, "Loading passthrough bitstream into RAM buffer...");
|
ESP_LOGI(TAG, "Loading passthrough bitstream into RAM buffer...");
|
||||||
size_t fpga_passthrough_bitstream_length;
|
size_t fpga_passthrough_bitstream_length;
|
||||||
uint8_t* fpga_passthrough_bitstream = load_file_to_ram(fpga_passthrough, &fpga_passthrough_bitstream_length);
|
uint8_t* fpga_passthrough_bitstream = load_file_to_ram(fpga_passthrough, &fpga_passthrough_bitstream_length);
|
||||||
|
@ -446,9 +474,10 @@ void fpga_test(void) {
|
||||||
ESP_LOGE(TAG, "Failed to verify PSRAM contents (%d)", res);
|
ESP_LOGE(TAG, "Failed to verify PSRAM contents (%d)", res);
|
||||||
fclose(ram_contents);
|
fclose(ram_contents);
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
FILE* fpga_app = fopen("/sd/app.bin", "rb");
|
//draw_message("Loading app...");
|
||||||
|
/*FILE* fpga_app = fopen("/sd/app.bin", "rb");
|
||||||
if (fpga_app == NULL) {
|
if (fpga_app == NULL) {
|
||||||
ESP_LOGE(TAG, "Failed to open app.bin");
|
ESP_LOGE(TAG, "Failed to open app.bin");
|
||||||
return;
|
return;
|
||||||
|
@ -457,20 +486,35 @@ void fpga_test(void) {
|
||||||
ESP_LOGI(TAG, "Loading app bitstream into RAM buffer...");
|
ESP_LOGI(TAG, "Loading app bitstream into RAM buffer...");
|
||||||
size_t fpga_app_bitstream_length;
|
size_t fpga_app_bitstream_length;
|
||||||
uint8_t* fpga_app_bitstream = load_file_to_ram(fpga_app, &fpga_app_bitstream_length);
|
uint8_t* fpga_app_bitstream = load_file_to_ram(fpga_app, &fpga_app_bitstream_length);
|
||||||
fclose(fpga_app);
|
fclose(fpga_app);*/
|
||||||
|
|
||||||
ili9341_deinit(ili9341);
|
|
||||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
|
||||||
ili9341_select(ili9341, true);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Loading app bitstream into FPGA...");
|
|
||||||
res = ice40_load_bitstream(ice40, fpga_app_bitstream, fpga_app_bitstream_length);
|
|
||||||
if (res != ESP_OK) {
|
|
||||||
ESP_LOGE(TAG, "Failed to load app bitstream into FPGA (%d)", res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(fpga_app_bitstream);
|
do {
|
||||||
|
reload_fpga = false;
|
||||||
|
ili9341_deinit(ili9341);
|
||||||
|
ili9341_select(ili9341, false);
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
ili9341_select(ili9341, true);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Loading app bitstream into FPGA...");
|
||||||
|
//res = ice40_load_bitstream(ice40, fpga_app_bitstream, fpga_app_bitstream_length);
|
||||||
|
res = ice40_load_bitstream(ice40, proto2_bin, proto2_bin_len);
|
||||||
|
if (res != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to load app bitstream into FPGA (%d)", res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//free(fpga_app_bitstream);
|
||||||
|
|
||||||
|
reset_to_menu = false;
|
||||||
|
|
||||||
|
while (!reset_to_menu) {
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
if (reload_fpga) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ice40_disable(ice40);
|
||||||
|
ili9341_init(ili9341);
|
||||||
|
} while (reload_fpga);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t appfs_init(void) {
|
esp_err_t appfs_init(void) {
|
||||||
|
@ -540,15 +584,21 @@ void appfs_test(bool sdcard_ready) {
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
esp_err_t res;
|
esp_err_t res;
|
||||||
|
|
||||||
uint8_t* framebuffer = heap_caps_malloc(ILI9341_BUFFER_SIZE, MALLOC_CAP_8BIT);
|
framebuffer = heap_caps_malloc(ILI9341_BUFFER_SIZE, MALLOC_CAP_8BIT);
|
||||||
if (framebuffer == NULL) {
|
if (framebuffer == NULL) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate framebuffer");
|
ESP_LOGE(TAG, "Failed to allocate framebuffer");
|
||||||
restart();
|
restart();
|
||||||
}
|
}
|
||||||
memset(framebuffer, 0, ILI9341_BUFFER_SIZE);
|
memset(framebuffer, 0, ILI9341_BUFFER_SIZE);
|
||||||
|
|
||||||
pax_buf_t buffer;
|
pax_buffer = malloc(sizeof(pax_buf_t));
|
||||||
pax_buf_init(&buffer, framebuffer, ILI9341_WIDTH, ILI9341_HEIGHT, PAX_BUF_16_565RGB);
|
if (framebuffer == NULL) {
|
||||||
|
ESP_LOGE(TAG, "Failed to allocate pax buffer");
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
memset(pax_buffer, 0, sizeof(pax_buf_t));
|
||||||
|
|
||||||
|
pax_buf_init(pax_buffer, framebuffer, ILI9341_WIDTH, ILI9341_HEIGHT, PAX_BUF_16_565RGB);
|
||||||
driver_framebuffer_init(framebuffer);
|
driver_framebuffer_init(framebuffer);
|
||||||
|
|
||||||
res = board_init();
|
res = board_init();
|
||||||
|
@ -565,10 +615,12 @@ void app_main(void) {
|
||||||
|
|
||||||
//print_chip_info();
|
//print_chip_info();
|
||||||
|
|
||||||
draw_message(&buffer, ili9341, framebuffer, "Button init...");
|
draw_message("Button init...");
|
||||||
button_init();
|
button_init();
|
||||||
|
|
||||||
draw_message(&buffer, ili9341, framebuffer, "AppFS init...");
|
rp2040_set_led_mode(rp2040, true, true);
|
||||||
|
|
||||||
|
draw_message("AppFS init...");
|
||||||
res = appfs_init();
|
res = appfs_init();
|
||||||
if (res != ESP_OK) {
|
if (res != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "AppFS init failed: %d", res);
|
ESP_LOGE(TAG, "AppFS init failed: %d", res);
|
||||||
|
@ -576,18 +628,18 @@ void app_main(void) {
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "AppFS initialized");
|
ESP_LOGI(TAG, "AppFS initialized");
|
||||||
|
|
||||||
draw_message(&buffer, ili9341, framebuffer, "Mount SD card...");
|
draw_message("Mount SD card...");
|
||||||
res = mount_sd(SD_CMD, SD_CLK, SD_D0, SD_PWR, "/sd", false, 5);
|
res = mount_sd(SD_CMD, SD_CLK, SD_D0, SD_PWR, "/sd", false, 5);
|
||||||
bool sdcard_ready = (res == ESP_OK);
|
bool sdcard_ready = (res == ESP_OK);
|
||||||
|
|
||||||
/*if (sdcard_ready) {
|
/*if (sdcard_ready) {
|
||||||
ESP_LOGI(TAG, "SD card mounted");
|
ESP_LOGI(TAG, "SD card mounted");
|
||||||
draw_message(&buffer, ili9341, framebuffer, "AppFS test...");
|
//draw_message("AppFS test...");
|
||||||
appfs_test(sdcard_ready);
|
//appfs_test(sdcard_ready);
|
||||||
draw_message(&buffer, ili9341, framebuffer, "FPGA init...");
|
draw_message("FPGA init...");
|
||||||
fpga_test();
|
fpga_test();
|
||||||
} else {
|
ESP_LOGW(TAG, "End of main function, goodbye!");
|
||||||
draw_message(&buffer, ili9341, framebuffer, "No SD card?");
|
return;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -618,7 +670,9 @@ void app_main(void) {
|
||||||
} while (current_fd != APPFS_INVALID_FD);
|
} while (current_fd != APPFS_INVALID_FD);
|
||||||
printf("Building menu list done, %u items\r\n", amount_of_items);
|
printf("Building menu list done, %u items\r\n", amount_of_items);
|
||||||
|
|
||||||
menu_item_t* next_menu_item = malloc(sizeof(menu_item_t));
|
menu_item_t* next_menu_item;
|
||||||
|
|
||||||
|
/*next_menu_item = malloc(sizeof(menu_item_t));
|
||||||
if (current_menu_item != NULL) {
|
if (current_menu_item != NULL) {
|
||||||
current_menu_item->next = next_menu_item;
|
current_menu_item->next = next_menu_item;
|
||||||
} else {
|
} else {
|
||||||
|
@ -629,22 +683,40 @@ void app_main(void) {
|
||||||
current_menu_item->action = ACTION_INSTALLER;
|
current_menu_item->action = ACTION_INSTALLER;
|
||||||
current_menu_item->name = installer_name;
|
current_menu_item->name = installer_name;
|
||||||
current_menu_item->next = NULL;
|
current_menu_item->next = NULL;
|
||||||
|
amount_of_items++;*/
|
||||||
|
|
||||||
|
next_menu_item = malloc(sizeof(menu_item_t));
|
||||||
|
if (current_menu_item != NULL) {
|
||||||
|
current_menu_item->next = next_menu_item;
|
||||||
|
} else {
|
||||||
|
first_menu_item = next_menu_item;
|
||||||
|
}
|
||||||
|
current_menu_item = next_menu_item;
|
||||||
|
current_menu_item->fd = APPFS_INVALID_FD;
|
||||||
|
current_menu_item->action = ACTION_FPGA;
|
||||||
|
current_menu_item->name = fpga_name;
|
||||||
|
current_menu_item->next = NULL;
|
||||||
amount_of_items++;
|
amount_of_items++;
|
||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
//bno055_task(bno055);
|
//bno055_task(bno055);
|
||||||
graphics_task(&buffer, ili9341, framebuffer);
|
graphics_task(pax_buffer, ili9341, framebuffer);
|
||||||
printf("Selected: %u of %u\r\n", selected_item + 1, amount_of_items);
|
//printf("Selected: %u of %u\r\n", selected_item + 1, amount_of_items);
|
||||||
if (start_selected) {
|
if (start_selected) {
|
||||||
current_menu_item = first_menu_item;
|
current_menu_item = first_menu_item;
|
||||||
for (uint8_t index = 0; index < selected_item; index++) {
|
for (uint8_t index = 0; index < selected_item; index++) {
|
||||||
current_menu_item = current_menu_item->next;
|
current_menu_item = current_menu_item->next;
|
||||||
}
|
}
|
||||||
if (current_menu_item->action == ACTION_INSTALLER) {
|
if (current_menu_item->action == ACTION_INSTALLER) {
|
||||||
draw_message(&buffer, ili9341, framebuffer, "Starting installer...");
|
draw_message("Not yet implemented");
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
start_selected = false;
|
||||||
|
} else if (current_menu_item->action == ACTION_FPGA) {
|
||||||
|
fpga_test();
|
||||||
|
start_selected = false;
|
||||||
} else {
|
} else {
|
||||||
draw_message(&buffer, ili9341, framebuffer, "Starting app...");
|
draw_message("Starting app...");
|
||||||
appfs_boot_app(current_menu_item->fd);
|
appfs_boot_app(current_menu_item->fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -769,7 +841,7 @@ void app_main(void) {
|
||||||
printf("%u bytes in %lld microseconds = %llu kB/s\r\n", size_of_ram, rx_done_time - rx_start_time, result);*/
|
printf("%u bytes in %lld microseconds = %llu kB/s\r\n", size_of_ram, rx_done_time - rx_start_time, result);*/
|
||||||
|
|
||||||
free(framebuffer);
|
free(framebuffer);
|
||||||
ESP_LOGW(TAG, "End of main function, goodbye!");
|
//ESP_LOGW(TAG, "End of main function, goodbye!");
|
||||||
|
|
||||||
rp2040_set_led_mode(rp2040, true, true);
|
rp2040_set_led_mode(rp2040, true, true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue