/* input - do getButtons() first, then getAnalogX() and/or getAnalogY() */ unsigned short getButtons(int pad) { // Read current controller status controller_scan(); gKeys = get_keys_pressed(); return (unsigned short)(gKeys.c[0].data >> 16); }
int do_menu() { unsigned char key = 0; int valid_opt[NUM_OPTS] = { 0 }; int x; int cursor = 0; u8 pwron = 0; lcd_console_setcolor(CONSOLE_COLOR_CYAN, CONSOLE_COLOR_BLACK); // lcd_clear (NULL, 1, 1, NULL); lcd_console_setpos(MENUTOP-5, INDENT); lcd_puts("_____________________________"); lcd_console_setpos(MENUTOP-3, INDENT); lcd_puts(" BOOT MENU "); lcd_console_setpos(MENUTOP-2, INDENT); lcd_puts("_____________________________"); gpio_write(COL0, 0);//drive COL0 LOW if (twl6030_hw_status(&pwron)) { lcd_console_setpos(MENUTOP, 2); lcd_puts("Error: Failed to read twl6030 hw_status\n"); } valid_opt[BOOT_FASTBOOT] = 1; valid_opt[BOOT_EMMC_NORMAL] = 1; valid_opt[BOOT_EMMC_RECOVERY] = 1; if (check_device_image(DEV_EMMC, "altboot.img")) valid_opt[BOOT_EMMC_ALTBOOT] = 1; if (check_device_image(DEV_SD, "recovery.img")) valid_opt[BOOT_SD_RECOVERY] = 1; if (check_device_image(DEV_SD, "cm7.img")) valid_opt[BOOT_SD_CM7] = 1; if (check_device_image(DEV_SD, "cm9.img")) valid_opt[BOOT_SD_CM9] = 1; if (check_device_image(DEV_SD, "altboot1.img")) valid_opt[BOOT_SD_ALTBOOT1] = 1; if (check_device_image(DEV_SD, "altboot2.img")) valid_opt[BOOT_SD_ALTBOOT2] = 1; if (check_device_image(DEV_SD, "altboot3.img")) valid_opt[BOOT_SD_ALTBOOT3] = 1; if (read_u_boot_file("u-boot.device") != 'X') // if that file is there valid_opt[CHANGE_BOOT_DEV] = 1; if (read_u_boot_file("u-boot.altboot") != 'X') // if that file is there valid_opt[CHANGE_BOOT_IMG] = 1; for (x = 0; x < NUM_OPTS; x++) { lcd_console_setpos(MENUTOP + x, INDENT); if ((!valid_opt[CHANGE_BOOT_DEV] && !valid_opt[CHANGE_BOOT_IMG]) && (x== DEFAULT_BOOT_STR || x == CHANGE_BOOT_DEV || x== CHANGE_BOOT_IMG)) continue; if (valid_opt[x]) highlight_boot_line(x, HIGHLIGHT_NONE); else highlight_boot_line(x, HIGHLIGHT_GRAY); } lcd_console_setpos(MENUTOP + NUM_OPTS + 4, INDENT - 7); lcd_puts(" PRESS VOL-UP/DN TO MOVE AND \"n\" TO SELECT"); lcd_console_setpos(59, 0); lcd_puts(" \n \n Menu by j4mm3r, HD.\n Credits: bauwks, fattire, mik_os, Rebellos, Denx, Ogilvy \n Cyanoboot for Nook Tablet (" __TIMESTAMP__ ") - ** NOT FOR SALE **"); cursor = 0; // highlight first option highlight_boot_line(cursor, HIGHLIGHT_CYAN); do { udelay(RESET_TICK); } while (get_keys_pressed(&key)); // wait for release do { get_keys_pressed(&key); lcd_console_setpos(5, 0); #if 0 //debugging purpose lcd_printf(" keycode: 0x%X, 0x%X, 0x%X, 0x%X", key, readl(CM_L4PER_GPIO6_CLKCTRL), readl(CM_L4PER_GPIO2_CLKCTRL), readl(CM_L4PER_CLKSTCTRL)); #endif if (key & VOLDOWN_KEY) // button is pressed { // unhighlight current option highlight_boot_line(cursor, HIGHLIGHT_NONE); while (!valid_opt[++cursor] || cursor >= NUM_OPTS) { if (cursor >= NUM_OPTS) cursor = -1; } // highlight new option highlight_boot_line(cursor, HIGHLIGHT_CYAN); do { udelay(RESET_TICK); } while (get_keys_pressed(&key)); //wait for release } if (key & VOLUP_KEY) // button is pressed { // unhighlight current option highlight_boot_line(cursor, HIGHLIGHT_NONE); while (!valid_opt[--cursor] || cursor < 0) { if (cursor < 0) cursor = NUM_OPTS; } // highlight new option highlight_boot_line(cursor, HIGHLIGHT_CYAN); do { udelay(RESET_TICK); } while (get_keys_pressed(&key)); //wait for release } if ((key & N_KEY) && (cursor == CHANGE_BOOT_DEV)) { //selected modify device const char* file = "u-boot.device"; if (read_u_boot_file(file) == '1') { write_u_boot_file(file, '0'); } else { write_u_boot_file(file, '1'); } udelay(RESET_TICK); highlight_boot_line(cursor, HIGHLIGHT_GREEN); do { udelay(RESET_TICK); } while (get_keys_pressed(&key)); //wait for release } if ((key & N_KEY) && (cursor == CHANGE_BOOT_IMG)) { //selected modify image const char* file = "u-boot.altboot"; if (read_u_boot_file(file) == '1') { write_u_boot_file(file, '0'); } else { write_u_boot_file(file, '1'); } udelay(RESET_TICK); highlight_boot_line(cursor, HIGHLIGHT_GREEN); do { udelay(RESET_TICK); } while (get_keys_pressed(&key)); //wait for release } udelay(RESET_TICK); } while (!(key & N_KEY) || (cursor == CHANGE_BOOT_DEV) || (cursor == CHANGE_BOOT_IMG)); highlight_boot_line(cursor, HIGHLIGHT_GREEN); lcd_console_setpos(MENUTOP + NUM_OPTS + 2, 25); lcd_console_setcolor(CONSOLE_COLOR_CYAN, CONSOLE_COLOR_BLACK); return cursor; }