diff --git a/source/Core/BSP/Magic/I2C_Wrapper.cpp b/source/Core/BSP/Magic/I2C_Wrapper.cpp index 34d1aac0..7472a5b0 100644 --- a/source/Core/BSP/Magic/I2C_Wrapper.cpp +++ b/source/Core/BSP/Magic/I2C_Wrapper.cpp @@ -43,7 +43,7 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b i2cCfg.subAddrSize = 1; // one byte address err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg); - // MSG((char *)"I2C Mem_Read %02X - %d - %d\r\n", DevAddress >> 1, err, number_of_byte); + MSG((char *)"I2C Mem_Read %02X - %d - %d\r\n", DevAddress >> 1, err, number_of_byte); bool res = err == SUCCESS; if (!res) { I2C_Unstick(); @@ -66,7 +66,7 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu i2cCfg.subAddrSize = 1; // one byte address err = I2C_MasterSendBlocking(I2C0_ID, &i2cCfg); - // MSG((char *)"I2C Mem_Write %02X - %d\r\n", DevAddress >> 1, err); + MSG((char *)"I2C Mem_Write %02X - %d\r\n", DevAddress >> 1, err); bool res = err == SUCCESS; if (!res) { I2C_Unstick(); @@ -107,17 +107,20 @@ bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *register bool FRToSI2C::wakePart(uint16_t DevAddress) { // wakepart is a special case where only the device address is sent - if (!lock()) - return false; + return false; // TODO - I2C_Transfer_Cfg i2cCfg = {0, DISABLE, 0, 0, 0, 0}; - BL_Err_Type err = ERROR; - i2cCfg.slaveAddr = DevAddress >> 1; - i2cCfg.stopEveryByte = DISABLE; - i2cCfg.subAddr = 0; - i2cCfg.dataSize = 0; - i2cCfg.data = 0; - i2cCfg.subAddrSize = 0; // one byte address + if (!lock()) { + return false; + } + uint8_t temp[1] = {0}; + I2C_Transfer_Cfg i2cCfg = {0, DISABLE, 0, 0, 0, 0}; + BL_Err_Type err = ERROR; + i2cCfg.slaveAddr = DevAddress >> 1; + i2cCfg.stopEveryByte = DISABLE; + i2cCfg.subAddr = 0; + i2cCfg.dataSize = 1; + i2cCfg.data = temp; + i2cCfg.subAddrSize = 0; err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg); MSG((char *)"I2C wakePart %02X - %d\r\n", DevAddress >> 1, err); @@ -126,5 +129,6 @@ bool FRToSI2C::wakePart(uint16_t DevAddress) { I2C_Unstick(); } unlock(); + MSG((char *)"I2C probe done \r\n"); return res; } diff --git a/source/Core/BSP/Magic/IRQ.cpp b/source/Core/BSP/Magic/IRQ.cpp index 15a21204..8a957087 100644 --- a/source/Core/BSP/Magic/IRQ.cpp +++ b/source/Core/BSP/Magic/IRQ.cpp @@ -177,22 +177,36 @@ void setTipPWM(const uint8_t pulse, const bool shouldUseFastModePWM) { } extern osThreadId POWTaskHandle; -// void EXTI5_9_IRQHandler(void) { -// // #if POW_PD -// // if (RESET != exti_interrupt_flag_get(EXTI_5)) { -// // exti_interrupt_flag_clear(EXTI_5); +void GPIO_IRQHandler(void) { + if (SET == GLB_Get_GPIO_IntStatus(FUSB302_IRQ_GLB_Pin)) { + GLB_GPIO_IntClear(FUSB302_IRQ_GLB_Pin, SET); + MSG((char *)"GPIO IRQ FUSB\r\n"); +#if POW_PD + if (POWTaskHandle != nullptr) { + MSG((char *)"Wake FUSB\r\n"); + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + xTaskNotifyFromISR(POWTaskHandle, 1, eSetBits, &xHigherPriorityTaskWoken); + /* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE. + The macro used to do this is dependent on the port and may be called + portEND_SWITCHING_ISR. */ + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } +#endif -// // if (POWTaskHandle != nullptr) { -// // BaseType_t xHigherPriorityTaskWoken = pdFALSE; -// // xTaskNotifyFromISR(POWTaskHandle, 1, eSetBits, &xHigherPriorityTaskWoken); -// // /* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE. -// // The macro used to do this is dependent on the port and may be called -// // portEND_SWITCHING_ISR. */ -// // portYIELD_FROM_ISR(xHigherPriorityTaskWoken); -// // } -// // } -// // #endif -// } + /* timeout check */ + uint32_t timeOut = 32; + + do { + timeOut--; + } while ((SET == GLB_Get_GPIO_IntStatus(FUSB302_IRQ_GLB_Pin)) && timeOut); + + if (!timeOut) { + // MSG("WARNING: Clear GPIO interrupt status fail.\r\n"); + } + + GLB_GPIO_IntClear(FUSB302_IRQ_GLB_Pin, RESET); + } +} bool getFUS302IRQLow() { // Return true if the IRQ line is still held low diff --git a/source/Core/BSP/Magic/IRQ.h b/source/Core/BSP/Magic/IRQ.h index 8139c88b..17f7e6f2 100644 --- a/source/Core/BSP/Magic/IRQ.h +++ b/source/Core/BSP/Magic/IRQ.h @@ -19,6 +19,7 @@ extern "C" { void timer0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state); void adc_fifo_irq(void); void start_adc_misc(void); +void GPIO_IRQHandler(void); #ifdef __cplusplus } #endif diff --git a/source/Core/BSP/Magic/Pins.h b/source/Core/BSP/Magic/Pins.h index 83445528..39f29ba5 100644 --- a/source/Core/BSP/Magic/Pins.h +++ b/source/Core/BSP/Magic/Pins.h @@ -31,7 +31,8 @@ #define QC_DM_LOW_Pin GPIO_PIN_4 #define QC_DM_HIGH_Pin GPIO_PIN_6 -#define FUSB302_IRQ_Pin GPIO_PIN_16 +#define FUSB302_IRQ_Pin GPIO_PIN_16 +#define FUSB302_IRQ_GLB_Pin GLB_GPIO_PIN_16 // uart #define UART_TX_Pin GPIO_PIN_22 diff --git a/source/Core/BSP/Magic/Setup.cpp b/source/Core/BSP/Magic/Setup.cpp index 616fa580..f1adf194 100644 --- a/source/Core/BSP/Magic/Setup.cpp +++ b/source/Core/BSP/Magic/Setup.cpp @@ -98,7 +98,19 @@ void setup_slow_PWM() { } void setupFUSBIRQ() { - // #TODO + return; // TODO + + MSG((char *)"Setting up FUSB IRQ\r\n"); + gpio_set_mode(FUSB302_IRQ_Pin, GPIO_SYNC_FALLING_TRIGER_INT_MODE); + MSG((char *)"Setting up FUSB IRQ1r\n"); + CPU_Interrupt_Disable(GPIO_INT0_IRQn); + MSG((char *)"Setting up FUSB IRQ2\r\n"); + Interrupt_Handler_Register(GPIO_INT0_IRQn, GPIO_IRQHandler); + MSG((char *)"Setting up FUSB IRQ3\r\n"); + CPU_Interrupt_Enable(GPIO_INT0_IRQn); + + MSG((char *)"Setting up FUSB IRQ4\r\n"); + gpio_irq_enable(FUSB302_IRQ_Pin, ENABLE); } void vAssertCalled(void) { diff --git a/source/Core/BSP/Magic/preRTOS.cpp b/source/Core/BSP/Magic/preRTOS.cpp index 26c592a0..1a949881 100644 --- a/source/Core/BSP/Magic/preRTOS.cpp +++ b/source/Core/BSP/Magic/preRTOS.cpp @@ -14,7 +14,6 @@ void preRToSInit() { // Normal system bringup -- GPIO etc - // #TODO bflb_platform_init(0); hardware_init(); diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 460f9b32..7f15cf45 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -800,15 +800,15 @@ void showDebugMenu(void) { } void showWarnings() { - // MSG((char *)"showWarningsshowWarnings\r\n"); + MSG((char *)"showWarningsshowWarnings\r\n"); return; // Display alert if settings were reset if (settingsWereReset) { - // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); - // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); - // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); - // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); - // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); + MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); + MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); + MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); + MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); + MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); warnUser(translatedString(Tr->SettingsResetMessage), 10 * TICKS_SECOND); } @@ -817,7 +817,7 @@ void showWarnings() { // In this case though, we dont want to nag the user _too_ much // So only show first 2 times while (DetectedAccelerometerVersion == AccelType::Scanning) { - // MSG((char *)"Accel Detect"); + MSG((char *)"Accel Detect"); osDelay(5); } // Display alert if accelerometer is not detected @@ -847,14 +847,14 @@ uint8_t disconnectedTipF[sizeof(disconnectedTip)]; /* StartGUITask function */ void startGUITask(void const *argument) { (void)argument; - // MSG((char *)"startGUITask\r\n"); + MSG((char *)"startGUITask\r\n"); prepareTranslations(); - // MSG((char *)"OLEDInit\r\n"); + MSG((char *)"OLEDInit\r\n"); OLED::initialize(); // start up the LCD - // MSG((char *)"setBrightness\r\n"); + MSG((char *)"setBrightness\r\n"); OLED::setBrightness(getSettingValue(SettingsOptions::OLEDBrightness)); - // MSG((char *)"setInverseDisplay\r\n"); + MSG((char *)"setInverseDisplay\r\n"); OLED::setInverseDisplay(getSettingValue(SettingsOptions::OLEDInversion)); uint8_t tempWarningState = 0; @@ -862,7 +862,7 @@ void startGUITask(void const *argument) { bool tempOnDisplay = false; bool tipDisconnectedDisplay = false; bool showExitMenuTransition = false; - // MSG((char *)"flip\r\n"); + MSG((char *)"flip\r\n"); { // Generate the flipped screen into ram for later use @@ -875,24 +875,24 @@ void startGUITask(void const *argument) { } } } - // MSG((char *)"tipTemp\r\n"); + MSG((char *)"tipTemp\r\n"); getTipRawTemp(1); // reset filter - // MSG((char *)"setRotation\r\n"); + MSG((char *)"setRotation\r\n"); OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1); - // MSG((char *)"Bootlogo\r\n"); + MSG((char *)"Bootlogo\r\n"); // BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR); - // MSG((char *)"showWarnings\r\n"); + MSG((char *)"showWarnings\r\n"); showWarnings(); - // MSG((char *)"AutoStartMode\r\n"); + MSG((char *)"AutoStartMode\r\n"); if (getSettingValue(SettingsOptions::AutoStartMode)) { // jump directly to the autostart mode gui_solderingMode(getSettingValue(SettingsOptions::AutoStartMode) - 1); buttonLockout = true; } - // MSG((char *)"GUI Thread Start\r\n"); + MSG((char *)"GUI Thread Start\r\n"); for (;;) { ButtonState buttons = getButtonState(); diff --git a/source/Core/Threads/POWThread.cpp b/source/Core/Threads/POWThread.cpp index 636a7b68..720fc716 100644 --- a/source/Core/Threads/POWThread.cpp +++ b/source/Core/Threads/POWThread.cpp @@ -34,6 +34,7 @@ void startPOWTask(void const *argument __unused) { #endif BaseType_t res; for (;;) { + MSG((char *)"POW Spin\r\n"); res = pdFALSE; // While the interrupt is low, dont delay /*This is due to a possible race condition, where: