diff --git a/main/main.ino b/main/main.ino index 3c3312a..115d1fc 100644 --- a/main/main.ino +++ b/main/main.ino @@ -2,18 +2,15 @@ #include #include -#define WAKEUP_PIN 4 // Solder to side of cap on guide - // -= NOTE: THIS MUST BE PIN 4!!! =- +#define SOFT_RESET_PIN 4 // Goes to Grounding side of power switch #define RCM_STRAP_PIN 3 // Solder to pin 10 on joycon rail -#define RCM_STRAP_TIME_us 1000000 // Amount of time to hold RCM_STRAP low and then launch payload -#define VOLUP_PIN 0 +#define VOLUP_PIN 0 // Goes to Vol+ ground signal pin +#define HOLD_STRAPS_LOW_TIME_uS 1000000 // Amount of time to hold straps low #define ONBOARD_LED 13 #define LED_CONFIRM_TIME_us 500000 // How long to show red or green light for success or fail // Contains fuseeBin and FUSEE_BIN_LENGTH -// Include only one payload here -// Use tools/binConverter.py to convert any payload bin you wish to load -#include "hekate_ctcaer_3.0.h" +#include "hekate_.h" #define INTERMEZZO_SIZE 92 const byte intermezzo[INTERMEZZO_SIZE] = @@ -61,11 +58,9 @@ void serialPrintHex(const byte *data, byte length) DEBUG_PRINTLN(); } +//Setup Dotstar Adafruit_DotStar strip = Adafruit_DotStar(1, INTERNAL_DS_DATA, INTERNAL_DS_CLK, DOTSTAR_BGR); -// From what I can tell, usb.outTransfer is completely broken for transfers larger than 64 bytes (even if maxPktSize is -// adjusted for that endpoint). This is a minimal and simplified reimplementation specific to our use cases that fixes -// that bug and is based on the code of USBHost::outTransfer, USBHost::SetPipeAddress and USBHost::OutTransfer. void usbOutTransferChunk(uint32_t addr, uint32_t ep, uint32_t nbytes, uint8_t* data) { @@ -209,13 +204,14 @@ void sleep(int errorCode) { digitalWrite(PIN_LED_TXL, HIGH); digitalWrite(ONBOARD_LED, LOW); if (errorCode == 1) { - setLedColor("green"); //led to red + setLedColor("green"); //led to green - success delayMicroseconds(LED_CONFIRM_TIME_us); - setLedColor("black"); //led to off + setLedColor("black"); //led to off - success } else { - setLedColor("red"); //led to red + setLedColor("red"); //led to red - fail delayMicroseconds(LED_CONFIRM_TIME_us); - setLedColor("black"); //led to off + setLedColor("white"); //led to white - Are you in RCM??? + foundTegra = false; } SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; /* Enable deepsleep */ @@ -233,11 +229,13 @@ void sleep(int errorCode) { void setLedColor(const char color[]) { if (color == "red") { - strip.setPixelColor(0, 64, 0, 0); + strip.setPixelColor(0, 255, 0, 0); } else if (color == "green") { - strip.setPixelColor(0, 0, 64, 0); - } else if (color == "orange") { - strip.setPixelColor(0, 64, 32, 0); + strip.setPixelColor(0, 0, 255, 0); + } else if (color == "white") { + strip.setPixelColor(0, 255, 255, 255); + } else if (color == "purple") { + strip.setPixelColor(0, 255, 32, 255); } else if (color == "blue") { strip.setPixelColor(0, 0, 0, 64); } else if (color == "black") { @@ -248,31 +246,37 @@ void setLedColor(const char color[]) { strip.show(); } +//This is disabled. Not required at present. +void firstbootRCM(){ + // Straps low + pinMode(RCM_STRAP_PIN, OUTPUT); + pinMode(VOLUP_PIN, OUTPUT); + digitalWrite(RCM_STRAP_PIN, LOW); + digitalWrite(VOLUP_PIN, LOW); + setLedColor("blue"); + delayMicroseconds(HOLD_STRAPS_LOW_TIME_uS); +} void wakeup(){ - // First, we set the RCM_STRAP low pinMode(RCM_STRAP_PIN, OUTPUT); pinMode(VOLUP_PIN, OUTPUT); digitalWrite(RCM_STRAP_PIN, LOW); digitalWrite(VOLUP_PIN, LOW); setLedColor("blue"); - // Wait a second (I tried to reduce this but 1 second is good) - delayMicroseconds(RCM_STRAP_TIME_us); + delayMicroseconds(HOLD_STRAPS_LOW_TIME_uS); SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk); //full software reset } void setup() { - // This continues after the reset after a wakeup - // Set RCM_STRAP as an input to "stealth" any funny business on the RCM_STRAP + // Set RCM_STRAP as an input to "stealth" any funny business on the RCM_STRAP after soft reset pinMode(RCM_STRAP_PIN, INPUT); pinMode(VOLUP_PIN, INPUT); - pinMode(WAKEUP_PIN, INPUT); + pinMode(SOFT_RESET_PIN, INPUT_PULLUP); // Before sleeping, make sure that we can wake up again when the switch turns on // by attaching an interrupt to the wakeup pin - attachInterrupt(WAKEUP_PIN, wakeup, RISING); - // Allow pin 4 to trigger wakeups. I'm not sure how to generalize this so that's - // why pin 4 must be the wakeup pin. + attachInterrupt(SOFT_RESET_PIN, wakeup, LOW); + // Allow pin 4 to trigger wakeups. Ground the pin to soft reset EIC->WAKEUP.vec.WAKEUPEN |= (1<<6); strip.begin(); @@ -296,7 +300,7 @@ void setup() if (currentTime > lastCheckTime + 100) { usb.ForEachUsbDevice(&findTegraDevice); if (blink && !foundTegra) { - setLedColor("orange"); //led to orange + setLedColor("purple"); //led to purple } else { setLedColor("black"); //led to black } @@ -333,12 +337,12 @@ void setup() 0x00, 0x00, 0x00, 0x00, 0x7000, 0x7000, usbWriteBuffer, NULL); DEBUG_PRINTLN("Done!"); - sleep(1); + foundTegra = false; } void loop() { - sleep(1); + foundTegra = false; }