button and naming

This commit is contained in:
Polprzewodnikowy 2022-08-20 21:30:55 +02:00
parent 3d3192b66a
commit 6de29251b5
11 changed files with 127 additions and 4 deletions

View File

@ -105,7 +105,7 @@ build_release () {
}
print_usage () {
echo "builder script for SummerCart64"
echo "builder script for SC64"
echo "usage: ./build.sh [bootloader] [controller] [fpga] [update] [release] [-c] [--help]"
echo "parameters:"
echo " bootloader - compile N64 bootloader software"

View File

@ -38,7 +38,7 @@ module n64_cfg (
end
always_ff @(posedge clk) begin
if (reset) begin
if (reset || n64_scb.n64_reset) begin
n64_scb.cfg_pending <= 1'b0;
n64_scb.cfg_cmd <= 8'h00;
irq <= 1'b0;

View File

@ -159,6 +159,8 @@ interface n64_scb ();
);
modport cfg (
input n64_reset,
output cfg_pending,
input cfg_done,
input cfg_error,

View File

@ -6,7 +6,7 @@
(paper "A4")
(title_block
(title "SummerCart64")
(title "SC64")
(date "2022-05-15")
(rev "2.0")
(company "Polprzewodnikowy")

View File

@ -5,7 +5,7 @@
(paper "A2")
(title_block
(title "SummerCart64")
(title "SC64")
(date "2022-05-15")
(rev "2.0")
(company "Polprzewodnikowy")

View File

@ -4,6 +4,7 @@ BUILD_DIR = build/app
SRC_FILES = \
app.S \
app.c \
button.c \
cfg.c \
cic.c \
dd.c \

View File

@ -0,0 +1,78 @@
#include <stdint.h>
#include "button.h"
#include "fpga.h"
#include "usb.h"
struct process {
uint32_t shift;
bool state;
button_mode_t mode;
bool trigger;
};
static struct process p;
bool button_get_state (void) {
return p.state;
}
button_mode_t button_get_mode (void) {
return p.mode;
}
void button_set_mode (button_mode_t mode) {
p.mode = mode;
if (p.mode == BUTTON_MODE_NONE) {
p.trigger = false;
}
}
void button_init (void) {
p.shift = 0x00000000UL;
p.state = false;
p.mode = BUTTON_MODE_NONE;
p.trigger = false;
}
void button_process (void) {
usb_tx_info_t packet_info;
uint32_t status = fpga_reg_get(REG_STATUS);
p.shift <<= 1;
if (!(status & STATUS_BUTTON)) {
p.shift |= (1 << 0);
}
if (!p.state && p.shift == 0xFFFFFFFFUL) {
p.state = true;
p.trigger = true;
}
if (p.state && p.shift == 0x00000000UL) {
p.state = false;
}
if (p.trigger) {
switch (p.mode) {
case BUTTON_MODE_N64_IRQ:
fpga_reg_set(REG_CFG_CMD, fpga_reg_get(REG_CFG_CMD) | CFG_CMD_IRQ);
p.trigger = false;
break;
case BUTTON_MODE_USB_PACKET:
usb_create_packet(&packet_info, PACKET_CMD_BUTTON_TRIGGER);
if (usb_enqueue_packet(&packet_info)) {
p.trigger = false;
}
break;
case BUTTON_MODE_DD_DISK_SWAP:
// TODO: implement 64DD disk swapping
p.trigger = false;
break;
default:
p.trigger = false;
break;
}
}
}

View File

@ -0,0 +1,23 @@
#ifndef BUTTON_H__
#define BUTTON_H__
#include <stdbool.h>
typedef enum {
BUTTON_MODE_NONE,
BUTTON_MODE_N64_IRQ,
BUTTON_MODE_USB_PACKET,
BUTTON_MODE_DD_DISK_SWAP,
} button_mode_t;
bool button_get_state (void);
button_mode_t button_get_mode (void);
void button_set_mode (button_mode_t mode);
void button_init (void);
void button_process (void);
#endif

View File

@ -1,3 +1,4 @@
#include "button.h"
#include "cfg.h"
#include "dd.h"
#include "flash.h"
@ -20,6 +21,8 @@ typedef enum {
CFG_ID_FLASH_ERASE_BLOCK,
CFG_ID_DD_DRIVE_TYPE,
CFG_ID_DD_DISK_STATE,
CFG_ID_BUTTON_STATE,
CFG_ID_BUTTON_MODE,
} cfg_id_t;
typedef enum {
@ -202,6 +205,12 @@ bool cfg_query (uint32_t *args) {
case CFG_ID_DD_DISK_STATE:
args[1] = dd_get_disk_state();
break;
case CFG_ID_BUTTON_STATE:
args[1] = button_get_state();
break;
case CFG_ID_BUTTON_MODE:
args[1] = button_get_mode();
break;
default:
return true;
}
@ -258,6 +267,12 @@ bool cfg_update (uint32_t *args) {
case CFG_ID_DD_DISK_STATE:
dd_set_disk_state(args[1]);
break;
case CFG_ID_BUTTON_STATE:
return true;
break;
case CFG_ID_BUTTON_MODE:
button_set_mode(args[1]);
break;
default:
return true;
}

View File

@ -1,3 +1,4 @@
#include "button.h"
#include "cfg.h"
#include "dd.h"
#include "flashram.h"
@ -10,6 +11,7 @@
void gvr_task (void) {
while (fpga_id_get() != FPGA_ID);
button_init();
cfg_init();
dd_init();
flashram_init();
@ -17,6 +19,7 @@ void gvr_task (void) {
usb_init();
while (1) {
button_process();
cfg_process();
dd_process();
flashram_process();

View File

@ -7,6 +7,7 @@
typedef enum packet_cmd {
PACKET_CMD_BUTTON_TRIGGER = 'B',
PACKET_CMD_DD_REQUEST = 'D',
PACKET_CMD_DEBUG_OUTPUT = 'U',
PACKET_CMD_ISV_OUTPUT = 'I',