Skip to content

Commit

Permalink
Merge pull request #18 from charcole/version4
Browse files Browse the repository at this point in the history
Firmware support for GunCon 2 cables
  • Loading branch information
charcole committed Jan 4, 2019
2 parents 1f1389b + ce0d1f0 commit c122f3a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 21 deletions.
24 changes: 12 additions & 12 deletions Firmware/main/images.h
Expand Up @@ -421,18 +421,18 @@ uint32_t ImageLogo[200][8] = {
{ 0x00568662, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568662, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568662, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568657, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568657, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x0061864c, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x0056864c, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00618642, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00618642, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568642, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568642, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x004b8642, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00408642, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x0036864c, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568657, 0x00158633, 0x001580ac, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568657, 0x00208628, 0x002080a2, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x0061864c, 0x00368613, 0x0036808c, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x0056864c, 0x0036861e, 0x0036808c, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00618642, 0x00158633, 0x001580ac, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00618642, 0x00158633, 0x001580ac, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568642, 0x00208633, 0x002080a2, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00568642, 0x00208633, 0x002080a2, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x004b8642, 0x0015863e, 0x001580ac, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x00408642, 0x00158649, 0x00208040, 0x0015804b, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x0036864c, 0x004b8628, 0x0020802b, 0x004b802b, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x004b8cab, 0x0015802b, 0x004b8036, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
{ 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000, 0x80008000 },
Expand Down
58 changes: 51 additions & 7 deletions Firmware/main/main.cpp
Expand Up @@ -13,6 +13,8 @@
// NonCommercial — You may not use the material for commercial purposes.
// Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

// Note to self: When updating releases update webpage and logo image

#include <stdio.h>
#include <string.h>
#include <math.h>
Expand Down Expand Up @@ -155,6 +157,7 @@ CableSetting CableSettings[]=
{ " +NES ", 35, 0, 13, 3 },
{ " +SMS ", 35, 0, 0, 1 },
{ " +SATURN ", 51, 0, 0, 0 },
{ " +GUNCON 2 ", 15, 8, 11, 5 },
};

EUIState UIState = kUIState_Syncing;
Expand Down Expand Up @@ -566,7 +569,7 @@ void RestoreMenuState()
CustomLineDelay = LineDelay = (State & 15); State >>= 4;
LoadedCableType = CableType = (State & 15); State >>= 4;

if (State != SAVESTATE_VERSION || IOType > 4 || CursorBrightness > 3 || WhiteLevelDecimal > 33 || DelayDecimal > 99 || CursorSize > 3 || CableType >= ARRAY_NUM(CableSettings))
if (State != SAVESTATE_VERSION || IOType > 5 || CursorBrightness > 3 || WhiteLevelDecimal > 33 || DelayDecimal > 99 || CursorSize > 3 || CableType >= ARRAY_NUM(CableSettings))
{
printf("Menu state seems corrupt: Version=%d Data=%d/%d/%d/%d/%d/%d\n", State, IOType, CursorBrightness, WhiteLevelDecimal, DelayDecimal, CursorSize, Coop);
SetDefaultMenuState();
Expand Down Expand Up @@ -668,7 +671,7 @@ void WiimoteTask(void *pvParameters)
WasPlayer1Button = Player1Buttons;
WasPlayer2Button = Player2Buttons;

if (IOType != 4)
if (IOType < 4)
{
bool bInvert = ((IOType & 2) != 0);
gpio_matrix_out(OUT_PLAYER1_TRIGGER1_PULLED, SIG_GPIO_OUT_IDX, bInvert, false);
Expand All @@ -691,7 +694,44 @@ void WiimoteTask(void *pvParameters)
gpio_set_level(OUT_PLAYER2_TRIGGER2_PULLED, Player2BButton);
}
}
else
else if (IOType == 5) // GunCon 2
{
if (UART1.status.txfifo_cnt == 0 && UART2.status.txfifo_cnt == 0)
{
for (int i = 0; i < 2; i++)
{
uint8_t ToTransmit[8];
PlayerInput *Player = i ? &Player2 : &Player1;
uint16_t SpotX = (ReticuleXPosition[i] + (40 + DelayDecimal) * 8) * 12 / 80; // GunCon 2 uses 12MHz clock from start of sync
uint16_t SpotY = ReticuleStartLineNum[i]; // GunCon 2 uses line numbers
uint16_t Buttons = Player->GetButtons();
if (SpotY >= 1000)
{
SpotX = SpotY = ~0;
}
else
{
SpotY += LineDelay - 8;
}
ToTransmit[0] = 0x80;
ToTransmit[1] = 0xCC; // GunCon 2 identifier
ToTransmit[2] = (SpotX >> 7) & 0x7F;
ToTransmit[3] = (SpotX & 0x7F);
ToTransmit[4] = (SpotY >> 7) & 0x7F;
ToTransmit[5] = (SpotY & 0x7F);
ToTransmit[6] = (Buttons >> 7) & 0x7F;
ToTransmit[7] = (Buttons & 0x7F);

uart_tx_chars((uart_port_t)(UART_NUM_1 + i), (char*)ToTransmit, sizeof(ToTransmit));
}

gpio_matrix_out(OUT_PLAYER1_TRIGGER1_PULLED, SIG_GPIO_OUT_IDX, true, false);
gpio_matrix_out(OUT_PLAYER1_TRIGGER2_PULLED, U1TXD_OUT_IDX, true, false);
gpio_matrix_out(OUT_PLAYER2_TRIGGER1_PULLED, SIG_GPIO_OUT_IDX, true, false);
gpio_matrix_out(OUT_PLAYER2_TRIGGER2_PULLED, U2TXD_OUT_IDX, true, false);
}
}
else // Serial
{
if (UART1.status.txfifo_cnt == 0) // UART FIFO is zero
{
Expand Down Expand Up @@ -1211,7 +1251,7 @@ void IRAM_ATTR SpotGeneratorInnerLoop()
bNTSC = (CurrentLine < 275); // PAL should be something like 300 and NTSC 250
}

if (IOType == 4) // Serial
if (IOType >= 4) // Serial
{
GPIO.out_w1ts = (1 << OUT_PLAYER1_TRIGGER1_PULLED) | (1 << OUT_PLAYER2_TRIGGER1_PULLED);
}
Expand All @@ -1229,7 +1269,7 @@ void IRAM_ATTR SpotGeneratorInnerLoop()
CompositeSyncPositiveEdge(Bank, Active);
bNeedSetup = true;

if (IOType == 4) // Serial
if (IOType >= 4) // Serial
{
GPIO.out_w1tc = (1 << OUT_PLAYER1_TRIGGER1_PULLED) | (1 << OUT_PLAYER2_TRIGGER1_PULLED);
}
Expand Down Expand Up @@ -1416,6 +1456,9 @@ void InitializeMiscGPIO()
};
uart_param_config(UART_NUM_1, &UARTConfig);
uart_driver_install(UART_NUM_1, UART_FIFO_LEN * 2, 0, 0, NULL, 0);

uart_param_config(UART_NUM_2, &UARTConfig);
uart_driver_install(UART_NUM_2, UART_FIFO_LEN * 2, 0, 0, NULL, 0);
}

void ConvertText(const char *Text, int Row, int Column)
Expand Down Expand Up @@ -1484,6 +1527,7 @@ void UpdateMenu()
case 2: ConvertText("INV AB", 7, Tab); break;
case 3: ConvertText("INV BA", 7, Tab); break;
case 4: ConvertText("SERIAL", 7, Tab); break;
case 5: ConvertText("GUNCON", 7, Tab); break;
}
DrawWholeNumber(LineDelay, 8, Tab);
for (int i=2; i<=9; i++)
Expand Down Expand Up @@ -1546,7 +1590,7 @@ bool MenuInput(MenuControl Input, PlayerInput *MenuPlayer)
case 4: bDirty |= AdjustRange(Input, kMenu_Left, kMenu_Right, Coop, 0, 1); break;
case 5: bDirty |= AdjustRange(Input, kMenu_Left, kMenu_Right, DelayDecimal, 0, 99); break;
case 6: bDirty |= AdjustRange(Input, kMenu_Left, kMenu_Right, WhiteLevelDecimal, 0, 33); break;
case 7: bDirty |= AdjustRange(Input, kMenu_Left, kMenu_Right, IOType, 0, 4); break;
case 7: bDirty |= AdjustRange(Input, kMenu_Left, kMenu_Right, IOType, 0, 5); break;
case 8: bDirty |= AdjustRange(Input, kMenu_Left, kMenu_Right, LineDelay, 0, 15); break;
}
if (Input == kMenu_Select)
Expand Down Expand Up @@ -1806,7 +1850,7 @@ void WifiStartListening()
else
{
printf("Sending response\n");
const char* GoodResponse = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<!doctype html><title>LightGunVerter Firmware Update</title><style>*{box-sizing: border-box;}body{margin: 0;}#main{display: flex; min-height: calc(100vh - 40vh);}#main > article{flex: 1;}#main > nav, #main > aside{flex: 0 0 20vw;}#main > nav{order: -1;}header, footer, article, nav, aside{padding: 1em;}header, footer{height: 20vh;}</style><body> <header> <center><h1>LightGunVerter Firmware Update</h1></center> </header> <div id=\"main\"> <nav></nav> <article> <p> Upload new .bin file: <form id=\"uploadbanner\" enctype=\"multipart/form-data\" method=\"post\" action=\"#\"> <input id=\"fileupload\" name=\"myfile\" type=\"file\"/> <input type=\"submit\" value=\"Update\" id=\"submit\"/> </form> </p><p> <b>Do not remove power while updating</b> </p></article> <aside></aside> </div></body>";
const char* GoodResponse = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<!doctype html><title>LightGunVerter Firmware Update</title><style>*{box-sizing: border-box;}body{margin: 0;}#main{display: flex; min-height: calc(100vh - 40vh);}#main > article{flex: 1;}#main > nav, #main > aside{flex: 0 0 20vw;}#main > nav{order: -1;}header, footer, article, nav, aside{padding: 1em;}header, footer{height: 20vh;}</style><body> <header> <center><h1>LightGunVerter Firmware Update</h1></center> </header> <div id=\"main\"> <nav></nav> <article> <p> Current firmware version 1.1 (2019/1/4) </p> <p> Upload new .bin file: <form id=\"uploadbanner\" enctype=\"multipart/form-data\" method=\"post\" action=\"#\"> <input id=\"fileupload\" name=\"myfile\" type=\"file\"/> <input type=\"submit\" value=\"Update\" id=\"submit\"/> </form> </p><p> <b>Do not remove power while updating</b> </p></article> <aside></aside> </div></body>";
const char* BadResponse = "HTTP/1.0 404 NOT FOUND\r\nContent-Type: text/html\r\n\r\n<!doctype html><title>Not Found</title><body>Page not found :(</body>";
const char* Response = bReturnIndex ? GoodResponse : BadResponse;

Expand Down
8 changes: 6 additions & 2 deletions Firmware/sdkconfig
Expand Up @@ -28,6 +28,7 @@ CONFIG_BOOTLOADER_APP_TEST=
#
# Security features
#
CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT=
CONFIG_SECURE_BOOT_ENABLED=
CONFIG_FLASH_ENCRYPTION_ENABLED=

Expand Down Expand Up @@ -231,6 +232,7 @@ CONFIG_ESP32_WIFI_TX_BA_WIN=6
CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP32_WIFI_RX_BA_WIN=6
CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752

#
# PHY
Expand Down Expand Up @@ -366,6 +368,8 @@ CONFIG_LWIP_IP_FRAG=
CONFIG_LWIP_IP_REASSEMBLY=
CONFIG_LWIP_STATS=
CONFIG_LWIP_ETHARP_TRUST_IP_MAC=y
CONFIG_ESP_GRATUITOUS_ARP=y
CONFIG_GARP_TMR_INTERVAL=60
CONFIG_TCPIP_RECVMBOX_SIZE=32
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=

Expand Down Expand Up @@ -494,9 +498,9 @@ CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
CONFIG_MBEDTLS_ECP_NIST_OPTIM=y

#
# mDNS
# NVS
#
CONFIG_MDNS_MAX_SERVICES=10
CONFIG_MP_BLOB_SUPPORT=

#
# OpenSSL
Expand Down

0 comments on commit c122f3a

Please sign in to comment.