Initial tests for building a launcher, very ugly code

This commit is contained in:
Renze Nicolai 2022-01-24 23:41:03 +01:00
parent 14d9695ff9
commit 3f3cc1b328
3 changed files with 98 additions and 30 deletions

View file

@ -23,7 +23,9 @@ 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");
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 0cf971f8cbf6ec7c8b018639479f91eef8066788 Subproject commit fc1f1f634420f0b5baffb07bdef422e2280d207f

View file

@ -33,7 +33,24 @@ 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 {
ACTION_NONE,
ACTION_INSTALLER
} menu_action_t;
typedef struct _menu_item {
const char* name;
appfs_handle_t fd;
menu_action_t action;
struct _menu_item* next;
} menu_item_t;
uint8_t selected_item = 0; uint8_t selected_item = 0;
uint8_t amount_of_items = 0;
bool start_selected = false;
menu_item_t* first_menu_item = NULL;
const char installer_name[] = "Install app...";
void button_handler(uint8_t pin, bool value) { void button_handler(uint8_t pin, bool value) {
switch(pin) { switch(pin) {
@ -47,42 +64,43 @@ void button_handler(uint8_t pin, bool value) {
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");
//ili9341_set_partial_scanning(ili9341, 0, ILI9341_WIDTH / 2 - 1); //ili9341_set_partial_scanning(ili9341, 0, ILI9341_WIDTH / 2 - 1);
if (value) selected_item += 1; if (value && (!start_selected)) {
if (selected_item < amount_of_items - 1) {
selected_item += 1;
}
}
break; break;
case PCA9555_PIN_BTN_JOY_UP: case PCA9555_PIN_BTN_JOY_UP:
printf("Joy vertical %s\n", value ? "up" : "center"); printf("Joy vertical %s\n", value ? "up" : "center");
//ili9341_set_partial_scanning(ili9341, ILI9341_WIDTH / 2, ILI9341_WIDTH - 1); if (value && (!start_selected)) {
if (value) selected_item -= 1; if (selected_item > 0) {
selected_item -= 1;
}
}
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");
//ili9341_set_partial_scanning(ili9341, 0, ILI9341_WIDTH - 1);
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");
//ili9341_set_tearing_effect_line(ili9341, true);
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");
//ili9341_set_tearing_effect_line(ili9341, false);
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");
//ili9341_set_idle_mode(ili9341, true);
break; break;
} }
case PCA9555_PIN_BTN_SELECT: { case PCA9555_PIN_BTN_SELECT: {
printf("Select button %s\n", value ? "pressed" : "released"); printf("Select button %s\n", value ? "pressed" : "released");
//ili9341_set_idle_mode(ili9341, false);
break; break;
} }
case PCA9555_PIN_BTN_BACK: case PCA9555_PIN_BTN_BACK:
printf("Back button %s\n", value ? "pressed" : "released"); printf("Back button %s\n", value ? "pressed" : "released");
display_bno_value = value;
break; break;
case PCA9555_PIN_BTN_ACCEPT: case PCA9555_PIN_BTN_ACCEPT:
printf("Accept button %s\n", value ? "pressed" : "released"); printf("Accept button %s\n", value ? "pressed" : "released");
if (value) calibrate = true; if (value) start_selected = true;
break; break;
default: default:
printf("Unknown button %d %s\n", pin, value ? "pressed" : "released"); printf("Unknown button %d %s\n", pin, value ? "pressed" : "released");
@ -203,13 +221,13 @@ esp_err_t draw_menu(pax_buf_t* buffer) {
//pax_apply_2d(buffer, matrix_2d_scale(1, 1)); //pax_apply_2d(buffer, matrix_2d_scale(1, 1));
pax_simple_line(buffer, pax_col_rgb(0,0,0), 0, 20, 320, 20); pax_simple_line(buffer, pax_col_rgb(0,0,0), 0, 20, 320, 20);
pax_draw_text(buffer, pax_col_rgb(0,0,0), PAX_FONT_DEFAULT, 18, 0, 0, "Launcher"); pax_draw_text(buffer, pax_col_rgb(0,0,0), PAX_FONT_DEFAULT, 18, 0, 0, "Launcher");
draw_menu_item(buffer, 0, (selected_item == 0), "Item 1"); menu_item_t* item = first_menu_item;
draw_menu_item(buffer, 1, (selected_item == 1), "Item 2"); for (uint8_t index = 0; index < amount_of_items; index++) {
draw_menu_item(buffer, 2, (selected_item == 2), "Item 3"); if (item != NULL) {
draw_menu_item(buffer, 3, (selected_item == 3), "Item 4"); draw_menu_item(buffer, index, (selected_item == index), item->name);
draw_menu_item(buffer, 4, (selected_item == 4), "Item 5"); }
draw_menu_item(buffer, 5, (selected_item == 5), "Item 6"); item = item->next;
draw_menu_item(buffer, 6, (selected_item == 6), "Item 7"); }
pax_pop_2d(buffer); pax_pop_2d(buffer);
return ESP_OK; return ESP_OK;
} }
@ -506,10 +524,6 @@ void appfs_boot_app(int fd) {
} }
void appfs_test(bool sdcard_ready) { void appfs_test(bool sdcard_ready) {
appfsDump();
// Try booting the app from appfs
appfs_handle_t fd = appfsOpen("gnuboy"); appfs_handle_t fd = appfsOpen("gnuboy");
if (fd < 0) { if (fd < 0) {
ESP_LOGW(TAG, "gnuboy not found in appfs"); ESP_LOGW(TAG, "gnuboy not found in appfs");
@ -566,23 +580,75 @@ void app_main(void) {
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...");
appfs_test(sdcard_ready);
draw_message(&buffer, ili9341, framebuffer, "FPGA init..."); draw_message(&buffer, ili9341, framebuffer, "FPGA init...");
fpga_test(); fpga_test();
} else { } else {
draw_message(&buffer, ili9341, framebuffer, "No SD card?"); draw_message(&buffer, ili9341, framebuffer, "No SD card?");
} }*/
//appfs_test(sdcard_ready);
// //
/*while (1) { menu_item_t* current_menu_item = NULL;
bno055_task(bno055); appfs_handle_t current_fd = APPFS_INVALID_FD;
amount_of_items = 0;
selected_item = 0;
do {
current_fd = appfsNextEntry(current_fd);
if (current_fd != APPFS_INVALID_FD) {
menu_item_t* 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;
appfsEntryInfo(current_fd, &current_menu_item->name, NULL);
current_menu_item->fd = current_fd;
current_menu_item->action = ACTION_NONE;
current_menu_item->next = NULL;
printf("Building menu list %u: %s\r\n", amount_of_items, current_menu_item->name);
amount_of_items++;
}
} while (current_fd != APPFS_INVALID_FD);
printf("Building menu list done, %u items\r\n", amount_of_items);
menu_item_t* 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_INSTALLER;
current_menu_item->name = installer_name;
current_menu_item->next = NULL;
amount_of_items++;
while (1) {
//bno055_task(bno055);
graphics_task(&buffer, ili9341, framebuffer); graphics_task(&buffer, ili9341, framebuffer);
}*/ printf("Selected: %u of %u\r\n", selected_item + 1, amount_of_items);
if (start_selected) {
current_menu_item = first_menu_item;
for (uint8_t index = 0; index < selected_item; index++) {
current_menu_item = current_menu_item->next;
}
if (current_menu_item->action == ACTION_INSTALLER) {
draw_message(&buffer, ili9341, framebuffer, "Starting installer...");
} else {
draw_message(&buffer, ili9341, framebuffer, "Starting app...");
appfs_boot_app(current_menu_item->fd);
}
}
}
/* /*
uint8_t data_out, data_in; uint8_t data_out, data_in;