Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
@@ -22,6 +22,7 @@
#include "error.h"
#include "bootloader.h"
#include "firmware.h"
#include "reinx_menu.h"
static pk11_offs *pk11Offs = NULL;
@@ -398,7 +399,7 @@ void launch() {
void firmware() {
display_init();
gfx_init_ctxt(&gfx_ctxt, display_init_framebuffer(), 720, 1280, 768);
gfx_clear_color(&gfx_ctxt, 0xFF000000);
gfx_clear_color(&gfx_ctxt, BLACK);
gfx_con_init(&gfx_con, &gfx_ctxt);
gfx_con_setcol(&gfx_con, DEFAULT_TEXT_COL, 0, 0);
@@ -424,7 +425,9 @@ void firmware() {
PMC(APBDEV_PMC_SCRATCH49) = 0;
if (btn_read() & BTN_VOL_DOWN) {
print("Booting verbosely\n");
print("Running in verbose mode!\n");
} else if (btn_read() & BTN_VOL_UP) {
init_reinx_menu();
} else if (drawSplash()) {
gfx_con.mute = 1;
}
View
@@ -26,6 +26,7 @@
#define YELLOW 0xFF00FFFF
#define ORANGE 0xFF3891FF
#define WHITE 0xFFFFFFFF
#define BLACK 0xFF000000
typedef struct _gfx_ctxt_t
{
View
@@ -11,6 +11,8 @@
#ifndef _MFD_MAX77620_H_
#define _MFD_MAX77620_H_
#define MAX77620_I2C_ADDR 0x3C
/* GLOBAL, PMIC, GPIO, FPS, ONOFFC, CID Registers */
#define MAX77620_REG_CNFGGLBL1 0x00
#define MAX77620_REG_CNFGGLBL2 0x01
View
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2018 Guillem96
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "menu.h"
#include "menu_pool.h"
menu_t *menu_create(const char *title)
{
menu_t *menu = (menu_t *)malloc(sizeof(menu_t));
strcpy(menu->title, title);
menu->next_entry = 0;
menu->selected_index = 0;
push_to_pool(menu);
return menu;
}
menu_t *create_yes_no_menu(const char *action,
int (*on_yes)(void *), void *on_yes_param,
int (*on_no)(void *), void *on_no_param)
{
char buffer[0x100];
strcpy(buffer, "Do you want to ");
strcat(buffer, action);
menu_t *menu = menu_create(buffer);
// Create yes entry
menu_entry_t *yes_entry = create_menu_entry("Yes", 0xFF, on_yes, on_yes_param);
// Create no entry
menu_entry_t *no_entry = create_menu_entry("No", 0xFF, on_no, on_no_param);
menu_append_entry(menu, yes_entry);
menu_append_entry(menu, no_entry);
push_to_pool(menu);
return menu;
}
void menu_append_entry(menu_t *menu, menu_entry_t *menu_entry)
{
if (menu->next_entry == MAX_ENTRIES)
return;
menu->entries[menu->next_entry] = menu_entry;
menu->next_entry++;
}
void menu_draw(menu_t *menu)
{
gfx_con_setpos(&gfx_con, 20, 50);
gfx_con.fntsz = 16;
gfx_printf(&gfx_con, "%k----- %s -----%k\n\n", 0xFFF45642, menu->title, WHITE);
for (size_t i = 0; i < menu->next_entry; i++)
{
if (i == menu->selected_index)
{
gfx_printf(&gfx_con, "%k-> %k%s%k\n", WHITE, menu->entries[i]->color, menu->entries[i]->text, WHITE);
}
else if (menu->entries[i]->handler == NULL)
{
gfx_printf(&gfx_con, "\n %k%s%k\n", menu->entries[i]->color, menu->entries[i]->text, WHITE);
}
else
{
gfx_printf(&gfx_con, "%k-> %k%s%k\n", BLACK, menu->entries[i]->color, menu->entries[i]->text, WHITE);
}
}
}
void skip_null_handlers(menu_t *menu, int direction)
{
while (menu->entries[menu->selected_index]->handler == NULL &&
((direction > 0 && menu->selected_index < menu->next_entry - 1) ||
(direction < 0 && menu->selected_index > 0)))
{
menu->selected_index += direction;
}
if (menu->entries[menu->selected_index]->handler == NULL)
menu->selected_index -= direction;
}
int menu_update(menu_t *menu)
{
menu_entry_t *entry = NULL;
u32 input;
menu_draw(menu);
input = btn_wait();
if ((input & BTN_VOL_UP) && menu->selected_index > 0)
{
menu->selected_index--;
skip_null_handlers(menu, -1);
}
else if ((input & BTN_VOL_DOWN) && menu->selected_index < menu->next_entry - 1)
{
menu->selected_index++;
skip_null_handlers(menu, 1);
}
else if (input & BTN_POWER)
{
entry = menu->entries[menu->selected_index];
if (entry->handler != NULL)
{
gfx_clear_color(&gfx_ctxt, BLACK);
gfx_con_setpos(&gfx_con, 20, 50);
if (entry->handler(entry->param) != 0)
return 0;
gfx_clear_color(&gfx_ctxt, BLACK);
menu_draw(menu);
}
}
return 1;
}
int menu_open(menu_t *menu)
{
skip_null_handlers(menu, 1);
while (menu_update(menu))
;
return 0;
}
void menu_destroy(menu_t *menu)
{
for (int i = 0; i < menu->next_entry; i++)
free(menu->entries[i]);
free(menu->entries);
free(menu);
}
View
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 Guillem96
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MENU_H_
#define _MENU_H_
#include "../hwinit.h"
#include "../hwinit/types.h"
#include "menu_entry.h"
#define MAX_ENTRIES 0x10
typedef struct
{
char title[0x100];
int next_entry;
int selected_index;
menu_entry_t *entries[MAX_ENTRIES];
} menu_t;
menu_t *menu_create(const char *title);
void menu_append_entry(menu_t *menu, menu_entry_t *menu_entry);
void menu_draw(menu_t *menu);
int menu_update(menu_t *menu);
int menu_open(menu_t *menu);
menu_t *create_yes_no_menu(const char *action,
int (*on_yes)(void *), void *on_yes_param,
int (*on_no)(void *), void *on_no_param);
void menu_destroy(menu_t *menu);
#endif
View
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2018 Guillem96
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "menu_entry.h"
menu_entry_t *create_menu_entry(const char *text, u32 color, int (*handler)(void *), void *param)
{
menu_entry_t *menu_entry = (menu_entry_t *)malloc(sizeof(menu_entry_t));
strcpy(menu_entry->text, text);
menu_entry->color = color;
menu_entry->handler = handler;
menu_entry->param = param;
return menu_entry;
}
int cancel(void *param)
{
return -1;
}
View
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018 Guillem96
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MENU_ENTRY_H
#define _MENU_ENTRY_H
#include <string.h>
#include "../hwinit.h"
#include "../hwinit/types.h"
typedef struct
{
char text[0x100];
u32 color;
void *param;
int (*handler)(void *);
} menu_entry_t;
menu_entry_t *create_menu_entry(const char *text, u32 color, int (*handler)(void *), void *param);
int cancel(void *param);
#endif
View
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018 Guillem96
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "menu_pool.h"
void pool_init()
{
menu_pool = (menu_pool_t *)malloc(sizeof(menu_pool_t));
menu_pool->max_items = 0x16;
menu_pool->current_items = 0;
menu_pool->menus = (menu_t **)malloc(sizeof(menu_t *) * menu_pool->max_items);
}
void push_to_pool(menu_t *menu)
{
if (menu != NULL)
{
if (menu_pool->current_items == menu_pool->max_items - 1)
{
// Resize the pool
menu_pool->max_items = menu_pool->max_items << 1;
menu_pool->menus = (menu_t **)realloc(menu_pool->menus, sizeof(menu_t *) * menu_pool->max_items);
}
menu_pool->menus[menu_pool->current_items] = menu;
menu_pool->current_items++;
}
}
void pool_cleanup()
{
for (int i = 0; i < menu_pool->current_items; ++i)
menu_destroy(menu_pool->menus[i]);
free(menu_pool->menus);
free(menu_pool);
}
View
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018 Guillem96
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MENU_POOL_H_
#define _MENU_POOL_H_
#include "menu.h"
typedef struct {
int max_items;
int current_items;
menu_t** menus;
} menu_pool_t;
menu_pool_t* menu_pool;
void pool_init();
void push_to_pool(menu_t * menu);
void pool_cleanup();
#endif
Oops, something went wrong.

No commit comments for this range