From 9c4f663b67d6549954d06be35a8770943dffc5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Mon, 15 Feb 2021 11:19:40 +0100 Subject: [PATCH 01/40] Update German translation --- Translations/translation_DE.json | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Translations/translation_DE.json b/Translations/translation_DE.json index 60c9b4b9..34eeae44 100644 --- a/Translations/translation_DE.json +++ b/Translations/translation_DE.json @@ -14,7 +14,7 @@ "BadTipString": "Spitze Defekt", "SleepingSimpleString": "Zzz ", "SleepingAdvancedString": "Ruhemodus...", - "WarningSimpleString": "HEIß!", + "WarningSimpleString": "HEISS!", "WarningAdvancedString": "! Achtung Heiß !", "SleepingTipAdvancedString": "Temp:", "IdleTipString": "Ist:", @@ -99,14 +99,14 @@ "Ruhever-", "zögerung" ], - "desc": "System wechselt in Ruhemodus, wenn innerhalb dieser Dauer nicht bewegt " + "desc": "Dauer vor Übergang in den Ruhemodus " }, "ShutdownTimeout": { "text2": [ "Abschalt-", "zeit" ], - "desc": "System schaltet ab, wenn innerhalb dieser Dauer nicht bewegt " + "desc": "Dauer vor automatischer Abschaltung " }, "MotionSensitivity": { "text2": [ @@ -148,7 +148,7 @@ "Start im", "Lötmodus" ], - "desc": "Bestimmt das Heizverhalten beim Einschalten der Spannungsversorgung " + "desc": "Heizverhalten beim Einschalten der Spannungsversorgung " }, "CooldownBlink": { "text2": [ @@ -169,14 +169,14 @@ "Einstellungen", "zurücksetzen?" ], - "desc": "Werte werden auf Werkseinstellungen zurückgesetzt!" + "desc": "Werte auf Werkseinstellungen zurücksetzen" }, "VoltageCalibration": { "text2": [ "Eingangsspannung", "kalibrieren?" ], - "desc": "Kalibrierung der Eingangsspannung. Kurzer Tastendruck zum Einstellen, langer Tastendruck zum Verlassen." + "desc": "Kalibrierung der Eingangsspannung " }, "AdvancedSoldering": { "text2": [ @@ -204,14 +204,14 @@ "Einfache", "Kalibrierung" ], - "desc": "Einfache Kalibrierung mittels heißen Wassers" + "desc": "Einfache Kalibrierung mit heißem Wasser" }, "AdvancedCalibrationMode": { "text2": [ "Erweiterte", "Kalibrierung" ], - "desc": "Erweiterte Kalibrierung mittels eines Thermoelements an der Lötspitze" + "desc": "Erweiterte Kalibrierung mit Thermoelement an der Lötspitze" }, "QCMaxVoltage": { "text2": [ @@ -253,28 +253,28 @@ "Leistungs-", "impuls" ], - "desc": "Powerbank wird mittels eines Impulses wach gehalten " + "desc": "Powerbank mit einem Impuls wach halten " }, "TipGain": { "text2": [ "Ändere", - "Spitzen Faktor" + "Spitzen-Faktor" ], - "desc": "Spitzen Faktor" + "desc": "Spitzen-Faktor" }, "HallEffSensitivity": { "text2": [ - "Hall Sensor", + "Hall-Sonde", "Empfindlichkeit" ], - "desc": "Empfindlichkeit des Hall Effekt Sensors beim Erkennen des Ruhemodus " + "desc": "Empfindlichkeit der Hall-Sonde beim Erkennen des Ruhemodus " }, "LockingMode": { "text2": [ - "Knopf-", + "Tasten-", "sperre" ], - "desc": "Langes drücken beider Knöpfe im Lötmodus, sperrt diese " + "desc": "Langes drücken beider Tasten im Lötmodus sperrt diese " } } } From 8318b02baca3bbc97a0727d1a07f78b0e523d53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Mon, 15 Feb 2021 11:54:16 +0100 Subject: [PATCH 02/40] Fix docker build on Fedora --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 30ddcb88..31ded282 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,5 +7,5 @@ services: context: . command: /bin/bash volumes: - - ./ci:/build/ci - - ./:/build/source + - ./ci:/build/ci:Z + - ./:/build/source:Z From 1d8f83b5e9a55b8fe6284bc5274d768366a4a9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Mon, 15 Feb 2021 12:07:43 +0100 Subject: [PATCH 03/40] Change temperature steps for long step config Added two new steps in the long step config: short step (=1) and half long step (=5). This allows swapping of short and long press behavior. --- source/Core/Src/gui.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 20a9284c..9cecf546 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -822,9 +822,15 @@ static void settings_displayTempChangeShortStep(void) { } static bool settings_setTempChangeLongStep(void) { - systemSettings.TempChangeLongStep += TEMP_CHANGE_LONG_STEP; + if (systemSettings.TempChangeLongStep == TEMP_CHANGE_SHORT_STEP) { + systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP / 2; + } else if (systemSettings.TempChangeLongStep == TEMP_CHANGE_LONG_STEP / 2) { + systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; + } else { + systemSettings.TempChangeLongStep += TEMP_CHANGE_LONG_STEP; + } if (systemSettings.TempChangeLongStep > TEMP_CHANGE_LONG_STEP_MAX) { - systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; // loop back at TEMP_CHANGE_LONG_STEP_MAX + systemSettings.TempChangeLongStep = TEMP_CHANGE_SHORT_STEP; // loop back at TEMP_CHANGE_LONG_STEP_MAX } return systemSettings.TempChangeLongStep == TEMP_CHANGE_LONG_STEP_MAX; } From c53c28914ed0d9aa609a8f025cdc217da366726e Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 23 Feb 2021 22:11:50 +1100 Subject: [PATCH 04/40] Move mem_read to new state format --- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 911 ++++++++++++------------- 1 file changed, 450 insertions(+), 461 deletions(-) diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index c54380c0..874363e5 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -12,498 +12,487 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore = nullptr; StaticSemaphore_t FRToSI2C::xSemaphoreBuffer; #define I2C_TIME_OUT (uint16_t)(12000) void FRToSI2C::CpltCallback() { - // TODO + // TODO } -bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { return Mem_Write(address, reg, &data, 1); } +bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { + return Mem_Write(address, reg, &data, 1); +} uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) { - uint8_t temp = 0; - Mem_Read(add, reg, &temp, 1); - return temp; + uint8_t temp = 0; + Mem_Read(add, reg, &temp, 1); + return temp; } +enum i2c_step { +//Write+read steps + Write_start, //Sending start on bus + Write_device_address, //start sent, send device address + Write_device_memory_address, //device address sent, write the memory location + Write_device_data_start, // Write all of the remaining data using DMA + Write_device_data_wait, // Write all of the remaining data using DMA + + Read_start, //second read + Read_device_address, // Send device address again for the read + Read_device_data_start, //read device data via DMA + Read_device_data_finish, //read device data via DMA + Send_stop, // send the stop at the end of the transaction + Wait_stop, // Wait for stop to send and we are done + Done, //Finished + Error_occured, //Error occured on the bus + +}; +struct i2c_state { + i2c_step currentStep; + dma_parameter_struct dma_init_struct; + +}; +volatile i2c_state currentState; bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) { - if (!lock()) - return false; - i2c_interrupt_disable(I2C0, I2C_INT_ERR); - i2c_interrupt_disable(I2C0, I2C_INT_BUF); - i2c_interrupt_disable(I2C0, I2C_INT_EV); - dma_parameter_struct dma_init_struct; + if (!lock()) + return false; + i2c_interrupt_disable(I2C0, I2C_INT_ERR); + i2c_interrupt_disable(I2C0, I2C_INT_BUF); + i2c_interrupt_disable(I2C0, I2C_INT_EV); + //Setup DMA + dma_deinit(DMA0, DMA_CH6); + currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; + currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); - uint8_t state = I2C_START; - uint8_t in_rx_cycle = 0; - uint16_t timeout = 0; - uint8_t tries = 0; - uint8_t i2c_timeout_flag = 0; - while (!(i2c_timeout_flag)) { - switch (state) { - case I2C_START: - tries++; - if (tries > 64) { - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - unlock(); - return false; - } - if (0 == in_rx_cycle) { - /* disable I2C0 */ - i2c_disable(I2C0); - /* enable I2C0 */ - i2c_enable(I2C0); + i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); - /* enable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_ENABLE); - /* i2c master sends start signal only when the bus is idle */ - while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - /* send the start signal */ - i2c_start_on_bus(I2C0); - timeout = 0; - state = I2C_SEND_ADDRESS; - } else { - I2C_Unstick(); - timeout = 0; - state = I2C_START; - } - } else { - i2c_start_on_bus(I2C0); - timeout = 0; - state = I2C_SEND_ADDRESS; - } - break; - case I2C_SEND_ADDRESS: - /* i2c master sends START signal successfully */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - if (RESET == in_rx_cycle) { - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - state = I2C_CLEAR_ADDRESS_FLAG; - } else { - i2c_master_addressing(I2C0, DevAddress, I2C_RECEIVER); - state = I2C_CLEAR_ADDRESS_FLAG; - } - timeout = 0; - } else { - timeout = 0; - state = I2C_START; - in_rx_cycle = 0; - } - break; - case I2C_CLEAR_ADDRESS_FLAG: - /* address flag set means i2c slave sends ACK */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT)) { - timeout++; - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - // Address NACK'd - unlock(); - return false; - } - } - if (timeout < I2C_TIME_OUT) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - timeout = 0; - state = I2C_TRANSMIT_DATA; - } else { - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - // Address NACK'd - unlock(); - return false; - } - break; - case I2C_TRANSMIT_DATA: - if (0 == in_rx_cycle) { - /* wait until the transmit data buffer is empty */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_TBE)) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - // Write out the 8 byte address - i2c_data_transmit(I2C0, read_address); - timeout = 0; - } else { - timeout = 0; - state = I2C_START; - in_rx_cycle = 0; - } - /* wait until BTC bit is set */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_BTC)) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - timeout = 0; - state = I2C_START; - in_rx_cycle = 1; - } else { - timeout = 0; - state = I2C_START; - in_rx_cycle = 0; - } - } else { - /* one byte master reception procedure (polling) */ - if (number_of_byte < 2) { - /* disable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_DISABLE); - /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register - * (I2C_STAT0 has already been read) */ - i2c_flag_get(I2C0, I2C_FLAG_ADDSEND); - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - /* wait for the byte to be received */ - while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) - ; - /* read the byte received from the EEPROM */ - *p_buffer = i2c_data_receive(I2C0); - /* decrement the read bytes counter */ - number_of_byte--; - timeout = 0; - } else { /* more than one byte master reception procedure (DMA) */ - dma_deinit(DMA0, DMA_CH6); - dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; - dma_init_struct.memory_addr = (uint32_t)p_buffer; - dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - dma_init_struct.number = number_of_byte; - dma_init_struct.periph_addr = (uint32_t)&I2C_DATA(I2C0); - dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - dma_init(DMA0, DMA_CH6, &dma_init_struct); + currentState.currentStep = Write_start; + TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; + while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { + if (xTaskGetTickCount() > timeout) { + i2c_stop_on_bus(I2C0); + I2C_Unstick(); + unlock(); + return false; + } + switch (currentState.currentStep) { + case Error_occured: - i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH6); - /* wait until BTC bit is set */ - while (!dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) {} - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - } - timeout = 0; - state = I2C_STOP; - } - break; - case I2C_STOP: - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - timeout = 0; - state = I2C_END; - i2c_timeout_flag = I2C_OK; - } else { - timeout = 0; - state = I2C_START; - in_rx_cycle = 0; - } - break; - default: - state = I2C_START; - in_rx_cycle = 0; - i2c_timeout_flag = I2C_OK; - timeout = 0; - break; - } - } - unlock(); - return true; + i2c_stop_on_bus(I2C0); + I2C_Unstick(); + unlock(); + return false; + break; + case Write_start: + + /* disable I2C0 */ + i2c_disable(I2C0); + /* enable I2C0 */ + i2c_enable(I2C0); + + /* enable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_ENABLE); + /* i2c master sends start signal only when the bus is idle */ + if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { + /* send the start signal */ + i2c_start_on_bus(I2C0); + currentState.currentStep = Write_device_address; + } + break; + case Read_start: + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + i2c_start_on_bus(I2C0); + currentState.currentStep = Read_device_address; + } + break; + case Write_device_address: + /* i2c master sends START signal successfully */ + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); + currentState.currentStep = Write_device_memory_address; + } + break; + case Read_device_address: + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_master_addressing(I2C0, DevAddress, I2C_RECEIVER); + currentState.currentStep = Read_device_data_start; + } + break; + case Write_device_memory_address: + //Send the device memory location + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + //Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } + if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + // Write out the 8 byte address + i2c_data_transmit(I2C0, read_address); + currentState.currentStep = Read_start; + } + } + break; + case Read_device_data_start: + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + //Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); //TODO may not be able to do this + /* one byte master reception procedure (polling) */ + if (number_of_byte == 0) { + + currentState.currentStep = Send_stop; + } else if (number_of_byte == 1) { + /* disable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_DISABLE); + /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register + * (I2C_STAT0 has already been read) */ + i2c_flag_get(I2C0, I2C_FLAG_ADDSEND); //sat0 + i2c_flag_get(I2C0, I2C_FLAG_I2CBSY); //sat1 + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + /* wait for the byte to be received */ + while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) + ; + /* read the byte received from the EEPROM */ + *p_buffer = i2c_data_receive(I2C0); + currentState.currentStep = Wait_stop; + } else { /* more than one byte master reception procedure (DMA) */ + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH6); + currentState.currentStep = Read_device_data_finish; + } + } + break; + case Read_device_data_finish: //Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) { + currentState.currentStep = Send_stop; + } + + break; + case Send_stop: + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + currentState.currentStep = Wait_stop; + break; + case Wait_stop: + /* i2c master sends STOP signal successfully */ + if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { + currentState.currentStep = Done; + } + break; + default: + //If we get here something is amiss + unlock(); + return false; + } + } + unlock(); + return true; } bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) { - if (!lock()) - return false; + if (!lock()) + return false; - i2c_interrupt_disable(I2C0, I2C_INT_ERR); - i2c_interrupt_disable(I2C0, I2C_INT_EV); - i2c_interrupt_disable(I2C0, I2C_INT_BUF); - dma_parameter_struct dma_init_struct; + i2c_interrupt_disable(I2C0, I2C_INT_ERR); + i2c_interrupt_disable(I2C0, I2C_INT_EV); + i2c_interrupt_disable(I2C0, I2C_INT_BUF); + dma_parameter_struct dma_init_struct; - uint8_t state = I2C_START; - uint16_t timeout = 0; - bool done = false; - bool timedout = false; - while (!(done || timedout)) { - switch (state) { - case I2C_START: - /* i2c master sends start signal only when the bus is idle */ - while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_start_on_bus(I2C0); - timeout = 0; - state = I2C_SEND_ADDRESS; - } else { - I2C_Unstick(); - timeout = 0; - state = I2C_START; - } - break; - case I2C_SEND_ADDRESS: - /* i2c master sends START signal successfully */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - timeout = 0; - state = I2C_CLEAR_ADDRESS_FLAG; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - case I2C_CLEAR_ADDRESS_FLAG: - /* address flag set means i2c slave sends ACK */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT)) { - timeout++; - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - // Address NACK'd - unlock(); - return false; - } - } - timeout = 0; - if (timeout < I2C_TIME_OUT) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - state = I2C_TRANSMIT_DATA; - } else { - // Dont retry as this means a NAK - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - unlock(); - return false; - } - break; - case I2C_TRANSMIT_DATA: - /* wait until the transmit data buffer is empty */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_TBE)) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - /* send the EEPROM's internal address to write to : only one byte - * address */ - i2c_data_transmit(I2C0, MemAddress); - timeout = 0; - } else { - timedout = true; - timeout = 0; - state = I2C_START; - } - /* wait until BTC bit is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) - ; - dma_deinit(DMA0, DMA_CH5); - dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; - dma_init_struct.memory_addr = (uint32_t)p_buffer; - dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - dma_init_struct.number = number_of_byte; - dma_init_struct.periph_addr = (uint32_t)&I2C_DATA(I2C0); - dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - dma_init(DMA0, DMA_CH5, &dma_init_struct); - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH5); - /* wait until BTC bit is set */ - while (!dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) {} - /* wait until BTC bit is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) {} - state = I2C_STOP; - break; - case I2C_STOP: - /* send a stop condition to I2C bus */ - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - timeout = 0; - state = I2C_END; - done = true; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - default: - state = I2C_START; - timeout = 0; - break; - } - } - unlock(); - return timedout == false; + uint8_t state = I2C_START; + uint16_t timeout = 0; + bool done = false; + bool timedout = false; + while (!(done || timedout)) { + switch (state) { + case I2C_START: + /* i2c master sends start signal only when the bus is idle */ + while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + i2c_start_on_bus(I2C0); + timeout = 0; + state = I2C_SEND_ADDRESS; + } else { + I2C_Unstick(); + timeout = 0; + state = I2C_START; + } + break; + case I2C_SEND_ADDRESS: + /* i2c master sends START signal successfully */ + while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); + timeout = 0; + state = I2C_CLEAR_ADDRESS_FLAG; + } else { + timedout = true; + done = true; + timeout = 0; + state = I2C_START; + } + break; + case I2C_CLEAR_ADDRESS_FLAG: + /* address flag set means i2c slave sends ACK */ + while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT )) { + timeout++; + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); + i2c_stop_on_bus(I2C0); + /* i2c master sends STOP signal successfully */ + while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + // Address NACK'd + unlock(); + return false; + } + } + timeout = 0; + if (timeout < I2C_TIME_OUT) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + state = I2C_TRANSMIT_DATA; + } else { + // Dont retry as this means a NAK + i2c_stop_on_bus(I2C0); + /* i2c master sends STOP signal successfully */ + while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + unlock(); + return false; + } + break; + case I2C_TRANSMIT_DATA: + /* wait until the transmit data buffer is empty */ + while ((!i2c_flag_get(I2C0, I2C_FLAG_TBE)) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + /* send the EEPROM's internal address to write to : only one byte + * address */ + i2c_data_transmit(I2C0, MemAddress); + timeout = 0; + } else { + timedout = true; + timeout = 0; + state = I2C_START; + } + /* wait until BTC bit is set */ + while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) + ; + dma_deinit(DMA0, DMA_CH5); + dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; + dma_init_struct.memory_addr = (uint32_t) p_buffer; + dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + dma_init_struct.number = number_of_byte; + dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + dma_init(DMA0, DMA_CH5, &dma_init_struct); + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH5); + /* wait until BTC bit is set */ + while (!dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { + } + /* wait until BTC bit is set */ + while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + } + state = I2C_STOP; + break; + case I2C_STOP: + /* send a stop condition to I2C bus */ + i2c_stop_on_bus(I2C0); + /* i2c master sends STOP signal successfully */ + while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + timeout = 0; + state = I2C_END; + done = true; + } else { + timedout = true; + done = true; + timeout = 0; + state = I2C_START; + } + break; + default: + state = I2C_START; + timeout = 0; + break; + } + } + unlock(); + return timedout == false; } -bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); } +bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { + return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); +} bool FRToSI2C::probe(uint16_t DevAddress) { - uint8_t temp[1]; - return Mem_Read(DevAddress, 0x00, temp, sizeof(temp)); + uint8_t temp[1]; + return Mem_Read(DevAddress, 0x00, temp, sizeof(temp)); } -void FRToSI2C::I2C_Unstick() { unstick_I2C(); } +void FRToSI2C::I2C_Unstick() { + unstick_I2C(); +} bool FRToSI2C::lock() { - if (I2CSemaphore == nullptr) { - return false; - } - return xSemaphoreTake(I2CSemaphore, TICKS_SECOND) == pdTRUE; + if (I2CSemaphore == nullptr) { + return false; + } + return xSemaphoreTake(I2CSemaphore, TICKS_SECOND) == pdTRUE; } -void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); } +void FRToSI2C::unlock() { + xSemaphoreGive(I2CSemaphore); +} bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) { - for (int index = 0; index < registersLength; index++) { - if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) { - return false; - } - if (registers[index].pause_ms) { - delay_ms(registers[index].pause_ms); - } - } - return true; + for (int index = 0; index < registersLength; index++) { + if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) { + return false; + } + if (registers[index].pause_ms) { + delay_ms(registers[index].pause_ms); + } + } + return true; } bool FRToSI2C::wakePart(uint16_t DevAddress) { - // wakepart is a special case where only the device address is sent - if (!lock()) - return false; +// wakepart is a special case where only the device address is sent + if (!lock()) + return false; - i2c_interrupt_disable(I2C0, I2C_INT_ERR); - i2c_interrupt_disable(I2C0, I2C_INT_EV); - i2c_interrupt_disable(I2C0, I2C_INT_BUF); + i2c_interrupt_disable(I2C0, I2C_INT_ERR); + i2c_interrupt_disable(I2C0, I2C_INT_EV); + i2c_interrupt_disable(I2C0, I2C_INT_BUF); - uint8_t state = I2C_START; - uint16_t timeout = 0; - bool done = false; - bool timedout = false; - while (!(done || timedout)) { - switch (state) { - case I2C_START: - /* i2c master sends start signal only when the bus is idle */ - while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_start_on_bus(I2C0); - timeout = 0; - state = I2C_SEND_ADDRESS; - } else { - I2C_Unstick(); - timeout = 0; - state = I2C_START; - } - break; - case I2C_SEND_ADDRESS: - /* i2c master sends START signal successfully */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - timeout = 0; - state = I2C_CLEAR_ADDRESS_FLAG; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - case I2C_CLEAR_ADDRESS_FLAG: - /* address flag set means i2c slave sends ACK */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT)) { - timeout++; - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - // Address NACK'd - unlock(); - return false; - } - } - if (timeout < I2C_TIME_OUT) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - timeout = 0; - state = I2C_STOP; - } else { - // Dont retry as this means a NAK - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - unlock(); - return false; - } - break; + uint8_t state = I2C_START; + uint16_t timeout = 0; + bool done = false; + bool timedout = false; + while (!(done || timedout)) { + switch (state) { + case I2C_START: + /* i2c master sends start signal only when the bus is idle */ + while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + i2c_start_on_bus(I2C0); + timeout = 0; + state = I2C_SEND_ADDRESS; + } else { + I2C_Unstick(); + timeout = 0; + state = I2C_START; + } + break; + case I2C_SEND_ADDRESS: + /* i2c master sends START signal successfully */ + while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); + timeout = 0; + state = I2C_CLEAR_ADDRESS_FLAG; + } else { + timedout = true; + done = true; + timeout = 0; + state = I2C_START; + } + break; + case I2C_CLEAR_ADDRESS_FLAG: + /* address flag set means i2c slave sends ACK */ + while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT )) { + timeout++; + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); + i2c_stop_on_bus(I2C0); + /* i2c master sends STOP signal successfully */ + while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + // Address NACK'd + unlock(); + return false; + } + } + if (timeout < I2C_TIME_OUT) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + timeout = 0; + state = I2C_STOP; + } else { + // Dont retry as this means a NAK + i2c_stop_on_bus(I2C0); + /* i2c master sends STOP signal successfully */ + while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + unlock(); + return false; + } + break; + + case I2C_STOP: + /* send a stop condition to I2C bus */ + i2c_stop_on_bus(I2C0); + /* i2c master sends STOP signal successfully */ + while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { + timeout++; + } + if (timeout < I2C_TIME_OUT) { + timeout = 0; + state = I2C_END; + done = true; + } else { + timedout = true; + done = true; + timeout = 0; + state = I2C_START; + } + break; + default: + state = I2C_START; + timeout = 0; + break; + } + } + unlock(); + return timedout == false; +} + +void I2C_EV_IRQ() { + +} +void I2C_ER_IRQ() { +//Error callbacks - case I2C_STOP: - /* send a stop condition to I2C bus */ - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT)) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - timeout = 0; - state = I2C_END; - done = true; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - default: - state = I2C_START; - timeout = 0; - break; - } - } - unlock(); - return timedout == false; } From b18bc384cc53128c2fc0fc1c8dc5663892f05887 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 23 Feb 2021 22:24:27 +1100 Subject: [PATCH 05/40] Rework writes to use the new states --- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 232 +++++++++++-------------- 1 file changed, 102 insertions(+), 130 deletions(-) diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index 874363e5..aa0bbe7f 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -31,7 +31,7 @@ enum i2c_step { Write_device_address, //start sent, send device address Write_device_memory_address, //device address sent, write the memory location Write_device_data_start, // Write all of the remaining data using DMA - Write_device_data_wait, // Write all of the remaining data using DMA + Write_device_data_finish, // Write all of the remaining data using DMA Read_start, //second read Read_device_address, // Send device address again for the read @@ -208,143 +208,115 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu i2c_interrupt_disable(I2C0, I2C_INT_ERR); i2c_interrupt_disable(I2C0, I2C_INT_EV); i2c_interrupt_disable(I2C0, I2C_INT_BUF); - dma_parameter_struct dma_init_struct; - - uint8_t state = I2C_START; - uint16_t timeout = 0; - bool done = false; - bool timedout = false; - while (!(done || timedout)) { - switch (state) { - case I2C_START: - /* i2c master sends start signal only when the bus is idle */ - while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_start_on_bus(I2C0); - timeout = 0; - state = I2C_SEND_ADDRESS; - } else { - I2C_Unstick(); - timeout = 0; - state = I2C_START; - } - break; - case I2C_SEND_ADDRESS: - /* i2c master sends START signal successfully */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - timeout = 0; - state = I2C_CLEAR_ADDRESS_FLAG; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - case I2C_CLEAR_ADDRESS_FLAG: - /* address flag set means i2c slave sends ACK */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT )) { - timeout++; - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - // Address NACK'd - unlock(); - return false; - } - } - timeout = 0; - if (timeout < I2C_TIME_OUT) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - state = I2C_TRANSMIT_DATA; - } else { - // Dont retry as this means a NAK - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - unlock(); - return false; - } - break; - case I2C_TRANSMIT_DATA: - /* wait until the transmit data buffer is empty */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_TBE)) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - /* send the EEPROM's internal address to write to : only one byte - * address */ - i2c_data_transmit(I2C0, MemAddress); - timeout = 0; - } else { - timedout = true; - timeout = 0; - state = I2C_START; - } - /* wait until BTC bit is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) - ; - dma_deinit(DMA0, DMA_CH5); - dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; - dma_init_struct.memory_addr = (uint32_t) p_buffer; - dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - dma_init_struct.number = number_of_byte; - dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - dma_init(DMA0, DMA_CH5, &dma_init_struct); - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH5); - /* wait until BTC bit is set */ - while (!dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { - } - /* wait until BTC bit is set */ - while (!i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - } - state = I2C_STOP; - break; - case I2C_STOP: - /* send a stop condition to I2C bus */ + dma_deinit(DMA0, DMA_CH5); + currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; + currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); + currentState.currentStep = Write_start; + TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; + while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { + if (xTaskGetTickCount() > timeout) { i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { - timeout++; + I2C_Unstick(); + unlock(); + return false; + } + switch (currentState.currentStep) { + + case Error_occured: + + i2c_stop_on_bus(I2C0); + I2C_Unstick(); + unlock(); + return false; + break; + case Write_start: + + /* disable I2C0 */ + i2c_disable(I2C0); + /* enable I2C0 */ + i2c_enable(I2C0); + + /* enable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_ENABLE); + /* i2c master sends start signal only when the bus is idle */ + if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { + /* send the start signal */ + i2c_start_on_bus(I2C0); + currentState.currentStep = Write_device_address; } - if (timeout < I2C_TIME_OUT) { - timeout = 0; - state = I2C_END; - done = true; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; + break; + case Write_device_address: + /* i2c master sends START signal successfully */ + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); + currentState.currentStep = Write_device_memory_address; + } + break; + case Write_device_memory_address: + //Send the device memory location + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + //Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } + if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + // Write out the 8 byte address + i2c_data_transmit(I2C0, MemAddress); + currentState.currentStep = Write_device_data_start; + } + } + break; + case Write_device_data_start: + + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH5); + currentState.currentStep = Write_device_data_finish; + } + break; + + case Write_device_data_finish: //Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + currentState.currentStep = Send_stop; + } + } + + break; + case Send_stop: + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + currentState.currentStep = Wait_stop; + break; + case Wait_stop: + /* i2c master sends STOP signal successfully */ + if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { + currentState.currentStep = Done; } break; default: - state = I2C_START; - timeout = 0; - break; + //If we get here something is amiss + unlock(); + return false; } } unlock(); - return timedout == false; + return true; } bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { From 530002297beaba57242096e6fa686ed8c15deb7f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 17:49:16 +1100 Subject: [PATCH 06/40] merge I2C state machine --- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 226 +++++++++---------------- 1 file changed, 84 insertions(+), 142 deletions(-) diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index aa0bbe7f..55eb4919 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -45,55 +45,69 @@ enum i2c_step { }; struct i2c_state { i2c_step currentStep; + bool isMemoryWrite; dma_parameter_struct dma_init_struct; }; volatile i2c_state currentState; -bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) { - if (!lock()) - return false; + +bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8_t *p_buffer, uint16_t number_of_byte, bool isWrite) { + { + //TODO is this required + /* disable I2C0 */ + i2c_disable(I2C0); + /* enable I2C0 */ + i2c_enable(I2C0); + } i2c_interrupt_disable(I2C0, I2C_INT_ERR); i2c_interrupt_disable(I2C0, I2C_INT_BUF); i2c_interrupt_disable(I2C0, I2C_INT_EV); + currentState.isMemoryWrite = isWrite; //Setup DMA - dma_deinit(DMA0, DMA_CH6); - currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; - currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; - currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - currentState.dma_init_struct.number = number_of_byte; - currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); + if (currentState.isMemoryWrite) { + dma_deinit(DMA0, DMA_CH5); + currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; + currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); + } else { + dma_deinit(DMA0, DMA_CH6); + currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; + currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); + } - i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); - - currentState.currentStep = Write_start; + if (!currentState.isMemoryWrite) { + i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); + } + currentState.currentStep = Write_start; //Always start in write mode TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { if (xTaskGetTickCount() > timeout) { i2c_stop_on_bus(I2C0); - I2C_Unstick(); - unlock(); return false; } switch (currentState.currentStep) { case Error_occured: i2c_stop_on_bus(I2C0); - I2C_Unstick(); - unlock(); return false; break; case Write_start: - /* disable I2C0 */ - i2c_disable(I2C0); - /* enable I2C0 */ - i2c_enable(I2C0); - /* enable acknowledge */ i2c_ack_config(I2C0, I2C_ACK_ENABLE); /* i2c master sends start signal only when the bus is idle */ @@ -133,10 +147,36 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); // Write out the 8 byte address - i2c_data_transmit(I2C0, read_address); - currentState.currentStep = Read_start; + i2c_data_transmit(I2C0, memory_address); + if (currentState.isMemoryWrite) { + currentState.currentStep = Write_device_data_start; + } else { + currentState.currentStep = Read_start; + } } } + break; + case Write_device_data_start: + + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH5); + currentState.currentStep = Write_device_data_finish; + } + break; + + case Write_device_data_finish: //Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + currentState.currentStep = Send_stop; + } + } + break; case Read_device_data_start: if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent @@ -144,7 +184,7 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b //Arb error - we lost the bus / nacked currentState.currentStep = Error_occured; } - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); //TODO may not be able to do this + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); /* one byte master reception procedure (polling) */ if (number_of_byte == 0) { @@ -193,130 +233,32 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b break; default: //If we get here something is amiss - unlock(); return false; } } - unlock(); return true; } +bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) { + if (!lock()) + return false; + bool res = perform_i2c_transaction(DevAddress, read_address, p_buffer, number_of_byte, false); + if (!res) { + I2C_Unstick(); + } + unlock(); + return res; +} + bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) { if (!lock()) return false; - - i2c_interrupt_disable(I2C0, I2C_INT_ERR); - i2c_interrupt_disable(I2C0, I2C_INT_EV); - i2c_interrupt_disable(I2C0, I2C_INT_BUF); - dma_deinit(DMA0, DMA_CH5); - currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; - currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; - currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - currentState.dma_init_struct.number = number_of_byte; - currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); - currentState.currentStep = Write_start; - TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; - while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { - if (xTaskGetTickCount() > timeout) { - i2c_stop_on_bus(I2C0); - I2C_Unstick(); - unlock(); - return false; - } - switch (currentState.currentStep) { - - case Error_occured: - - i2c_stop_on_bus(I2C0); - I2C_Unstick(); - unlock(); - return false; - break; - case Write_start: - - /* disable I2C0 */ - i2c_disable(I2C0); - /* enable I2C0 */ - i2c_enable(I2C0); - - /* enable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_ENABLE); - /* i2c master sends start signal only when the bus is idle */ - if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { - /* send the start signal */ - i2c_start_on_bus(I2C0); - currentState.currentStep = Write_device_address; - } - break; - case Write_device_address: - /* i2c master sends START signal successfully */ - if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - currentState.currentStep = Write_device_memory_address; - } - break; - case Write_device_memory_address: - //Send the device memory location - if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - //Arb error - we lost the bus / nacked - currentState.currentStep = Error_occured; - } - if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - // Write out the 8 byte address - i2c_data_transmit(I2C0, MemAddress); - currentState.currentStep = Write_device_data_start; - } - } - break; - case Write_device_data_start: - - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH5); - currentState.currentStep = Write_device_data_finish; - } - break; - - case Write_device_data_finish: //Wait for complete then goto stop - /* wait until BTC bit is set */ - if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - currentState.currentStep = Send_stop; - } - } - - break; - case Send_stop: - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - currentState.currentStep = Wait_stop; - break; - case Wait_stop: - /* i2c master sends STOP signal successfully */ - if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { - currentState.currentStep = Done; - } - break; - default: - //If we get here something is amiss - unlock(); - return false; - } + bool res = perform_i2c_transaction(DevAddress, MemAddress, p_buffer, number_of_byte, true); + if (!res) { + I2C_Unstick(); } unlock(); - return true; + return res; } bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { From 296c2f9351b314436962e2d70f8aee817ec1687c Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 17:52:40 +1100 Subject: [PATCH 07/40] De-dupe --- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index 55eb4919..7a0c40fc 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -64,29 +64,21 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 i2c_interrupt_disable(I2C0, I2C_INT_EV); currentState.isMemoryWrite = isWrite; //Setup DMA + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; if (currentState.isMemoryWrite) { dma_deinit(DMA0, DMA_CH5); currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; - currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; - currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - currentState.dma_init_struct.number = number_of_byte; - currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); } else { dma_deinit(DMA0, DMA_CH6); currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; - currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; - currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - currentState.dma_init_struct.number = number_of_byte; - currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); } From 8d39ff1cbc91696449982ab8e6e86ec538e72b50 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 19:21:35 +1100 Subject: [PATCH 08/40] Move prob into the new state machine --- source/Core/BSP/Pine64/BSP.cpp | 165 +++++++++--------- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 231 ++++++++++--------------- 2 files changed, 176 insertions(+), 220 deletions(-) diff --git a/source/Core/BSP/Pine64/BSP.cpp b/source/Core/BSP/Pine64/BSP.cpp index 707f55ce..8bbcd495 100644 --- a/source/Core/BSP/Pine64/BSP.cpp +++ b/source/Core/BSP/Pine64/BSP.cpp @@ -9,112 +9,123 @@ #include "main.hpp" #include -const uint16_t powerPWM = 255; -const uint8_t holdoffTicks = 25; // delay of 7 ms -const uint8_t tempMeasureTicks = 25; +const uint16_t powerPWM = 255; +const uint8_t holdoffTicks = 25; // delay of 7 ms +const uint8_t tempMeasureTicks = 25; uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle // 2 second filter (ADC is PID_TIM_HZ Hz) -history rawTempFilter = {{0}, 0, 0}; -void resetWatchdog() { fwdgt_counter_reload(); } +history rawTempFilter = { { 0 }, 0, 0 }; +void resetWatchdog() { + fwdgt_counter_reload(); +} uint16_t getTipInstantTemperature() { - volatile uint16_t sum = 0; // 12 bit readings * 8*2 -> 16 bits + volatile uint16_t sum = 0; // 12 bit readings * 8*2 -> 16 bits - for (int i = 0; i < 4; i++) { - sum += adc_inserted_data_read(ADC0, i); - sum += adc_inserted_data_read(ADC1, i); - } - return sum; // 8x over sample + for (int i = 0; i < 4; i++) { + sum += adc_inserted_data_read(ADC0, i); + sum += adc_inserted_data_read(ADC1, i); + } + return sum; // 8x over sample } uint16_t getTipRawTemp(uint8_t refresh) { - if (refresh) { - uint16_t lastSample = getTipInstantTemperature(); - rawTempFilter.update(lastSample); - return lastSample; - } else { - return rawTempFilter.average(); - } + if (refresh) { + uint16_t lastSample = getTipInstantTemperature(); + rawTempFilter.update(lastSample); + return lastSample; + } else { + return rawTempFilter.average(); + } } uint16_t getHandleTemperature() { #ifdef TEMP_TMP36 - // We return the current handle temperature in X10 C - // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for - // example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) = - // 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125 - // mV per count So we need to subtract an offset of 0.5V to center on 0C - // (4964.8 counts) - // - int32_t result = getADC(0); - result -= 4965; // remove 0.5V offset - // 10mV per C - // 99.29 counts per Deg C above 0C - result *= 100; - result /= 993; - return result; + // We return the current handle temperature in X10 C + // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for + // example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) = + // 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125 + // mV per count So we need to subtract an offset of 0.5V to center on 0C + // (4964.8 counts) + // + int32_t result = getADC(0); + result -= 4965; // remove 0.5V offset + // 10mV per C + // 99.29 counts per Deg C above 0C + result *= 100; + result /= 993; + return result; #else #error #endif } uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) { - static uint8_t preFillneeded = 10; - static uint32_t samples[BATTFILTERDEPTH]; - static uint8_t index = 0; - if (preFillneeded) { - for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) - samples[i] = getADC(1); - preFillneeded--; - } - if (sample) { - samples[index] = getADC(1); - index = (index + 1) % BATTFILTERDEPTH; - } - uint32_t sum = 0; + static uint8_t preFillneeded = 10; + static uint32_t samples[BATTFILTERDEPTH]; + static uint8_t index = 0; + if (preFillneeded) { + for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) + samples[i] = getADC(1); + preFillneeded--; + } + if (sample) { + samples[index] = getADC(1); + index = (index + 1) % BATTFILTERDEPTH; + } + uint32_t sum = 0; - for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) - sum += samples[i]; + for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) + sum += samples[i]; - sum /= BATTFILTERDEPTH; - if (divisor == 0) { - divisor = 1; - } - return sum * 4 / divisor; + sum /= BATTFILTERDEPTH; + if (divisor == 0) { + divisor = 1; + } + return sum * 4 / divisor; } void unstick_I2C() { - /* configure SDA/SCL for GPIO */ - GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin; - gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - GPIO_BOP(GPIOB) |= SCL_Pin; - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - GPIO_BOP(GPIOB) |= SDA_Pin; - /* connect PB6 to I2C0_SCL */ - /* connect PB7 to I2C0_SDA */ - gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); + /* configure SDA/SCL for GPIO */ + GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin; + gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); + for (int i = 0; i < 8; i++) { + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + GPIO_BOP(GPIOB) |= SCL_Pin; + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + GPIO_BOP(GPIOB) &= SCL_Pin; + } + /* connect PB6 to I2C0_SCL */ + /* connect PB7 to I2C0_SDA */ + gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); } -uint8_t getButtonA() { return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; } -uint8_t getButtonB() { return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; } +uint8_t getButtonA() { + return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; +} +uint8_t getButtonB() { + return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; +} void reboot() { - // Spin for watchdog - for (;;) {} + // Spin for watchdog + for (;;) { + } } -void delay_ms(uint16_t count) { delay_1ms(count); } -uint32_t __get_IPSR(void) { - return 0; // To shut-up CMSIS +void delay_ms(uint16_t count) { + delay_1ms(count); +} +uint32_t __get_IPSR(void) { + return 0; // To shut-up CMSIS } diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index 7a0c40fc..f13bc3c1 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -46,12 +46,13 @@ enum i2c_step { struct i2c_state { i2c_step currentStep; bool isMemoryWrite; + bool wakePart; dma_parameter_struct dma_init_struct; }; volatile i2c_state currentState; -bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8_t *p_buffer, uint16_t number_of_byte, bool isWrite) { +bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8_t *p_buffer, uint16_t number_of_byte, bool isWrite, bool isWakeOnly) { { //TODO is this required /* disable I2C0 */ @@ -62,29 +63,38 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 i2c_interrupt_disable(I2C0, I2C_INT_ERR); i2c_interrupt_disable(I2C0, I2C_INT_BUF); i2c_interrupt_disable(I2C0, I2C_INT_EV); - currentState.isMemoryWrite = isWrite; - //Setup DMA - currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; - currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - currentState.dma_init_struct.number = number_of_byte; - currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - if (currentState.isMemoryWrite) { - dma_deinit(DMA0, DMA_CH5); - currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; - dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); - } else { - dma_deinit(DMA0, DMA_CH6); - currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; - dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); - } - if (!currentState.isMemoryWrite) { - i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); + currentState.isMemoryWrite = isWrite; + currentState.wakePart = isWakeOnly; + if (!isWakeOnly) { + //Setup DMA + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + if (currentState.isMemoryWrite) { + dma_deinit(DMA0, DMA_CH5); + currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; + dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); + } else { + dma_deinit(DMA0, DMA_CH6); + currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; + dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); + } + + if (!currentState.isMemoryWrite) { + i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); + } } + //Clear flags + I2C_STAT0(I2C0) = 0; + I2C_STAT1(I2C0) = 0; + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + currentState.currentStep = Write_start; //Always start in write mode TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { @@ -92,6 +102,23 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 i2c_stop_on_bus(I2C0); return false; } +// if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { +// i2c_flag_clear(I2C0, I2C_FLAG_AERR); +// //Arb error - we lost the bus / nacked +// currentState.currentStep = Error_occured; +// } else if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { +// i2c_flag_clear(I2C0, I2C_FLAG_BERR); +// // Bus Error +// currentState.currentStep = Error_occured; +// } else if (i2c_flag_get(I2C0, I2C_FLAG_LOSTARB)) { +// i2c_flag_clear(I2C0, I2C_FLAG_LOSTARB); +// // Bus Error +// currentState.currentStep = Error_occured; +// } else if (i2c_flag_get(I2C0, I2C_FLAG_PECERR)) { +// i2c_flag_clear(I2C0, I2C_FLAG_PECERR); +// // Bus Error +// currentState.currentStep = Error_occured; +// } switch (currentState.currentStep) { case Error_occured: @@ -109,37 +136,36 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 currentState.currentStep = Write_device_address; } break; - case Read_start: - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - i2c_start_on_bus(I2C0); - currentState.currentStep = Read_device_address; - } - break; + case Write_device_address: /* i2c master sends START signal successfully */ if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); currentState.currentStep = Write_device_memory_address; } break; - case Read_device_address: - if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { - i2c_master_addressing(I2C0, DevAddress, I2C_RECEIVER); - currentState.currentStep = Read_device_data_start; - } - break; case Write_device_memory_address: //Send the device memory location + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + + if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_BERR); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); //Arb error - we lost the bus / nacked currentState.currentStep = Error_occured; - } - if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + } else if (currentState.wakePart) { + //We are stopping here + currentState.currentStep = Send_stop; + } else if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { // Write out the 8 byte address i2c_data_transmit(I2C0, memory_address); + if (currentState.isMemoryWrite) { currentState.currentStep = Write_device_data_start; } else { @@ -147,6 +173,7 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 } } } + break; case Write_device_data_start: @@ -168,18 +195,30 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 currentState.currentStep = Send_stop; } } - + break; + case Read_start: + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + i2c_start_on_bus(I2C0); + currentState.currentStep = Read_device_address; + } + break; + case Read_device_address: + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + i2c_master_addressing(I2C0, DevAddress, I2C_RECEIVER); + currentState.currentStep = Read_device_data_start; + } break; case Read_device_data_start: if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { //Arb error - we lost the bus / nacked currentState.currentStep = Error_occured; } - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); /* one byte master reception procedure (polling) */ if (number_of_byte == 0) { - currentState.currentStep = Send_stop; } else if (number_of_byte == 1) { /* disable acknowledge */ @@ -234,7 +273,7 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) { if (!lock()) return false; - bool res = perform_i2c_transaction(DevAddress, read_address, p_buffer, number_of_byte, false); + bool res = perform_i2c_transaction(DevAddress, read_address, p_buffer, number_of_byte, false, false); if (!res) { I2C_Unstick(); } @@ -245,7 +284,7 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) { if (!lock()) return false; - bool res = perform_i2c_transaction(DevAddress, MemAddress, p_buffer, number_of_byte, true); + bool res = perform_i2c_transaction(DevAddress, MemAddress, p_buffer, number_of_byte, true, false); if (!res) { I2C_Unstick(); } @@ -290,109 +329,15 @@ 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 + // wakepart is a special case where only the device address is sent if (!lock()) return false; - - i2c_interrupt_disable(I2C0, I2C_INT_ERR); - i2c_interrupt_disable(I2C0, I2C_INT_EV); - i2c_interrupt_disable(I2C0, I2C_INT_BUF); - - uint8_t state = I2C_START; - uint16_t timeout = 0; - bool done = false; - bool timedout = false; - while (!(done || timedout)) { - switch (state) { - case I2C_START: - /* i2c master sends start signal only when the bus is idle */ - while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_start_on_bus(I2C0); - timeout = 0; - state = I2C_SEND_ADDRESS; - } else { - I2C_Unstick(); - timeout = 0; - state = I2C_START; - } - break; - case I2C_SEND_ADDRESS: - /* i2c master sends START signal successfully */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - timeout = 0; - state = I2C_CLEAR_ADDRESS_FLAG; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - case I2C_CLEAR_ADDRESS_FLAG: - /* address flag set means i2c slave sends ACK */ - while ((!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) && (timeout < I2C_TIME_OUT )) { - timeout++; - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - // Address NACK'd - unlock(); - return false; - } - } - if (timeout < I2C_TIME_OUT) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - timeout = 0; - state = I2C_STOP; - } else { - // Dont retry as this means a NAK - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - unlock(); - return false; - } - break; - - case I2C_STOP: - /* send a stop condition to I2C bus */ - i2c_stop_on_bus(I2C0); - /* i2c master sends STOP signal successfully */ - while ((I2C_CTL0(I2C0) & 0x0200) && (timeout < I2C_TIME_OUT )) { - timeout++; - } - if (timeout < I2C_TIME_OUT) { - timeout = 0; - state = I2C_END; - done = true; - } else { - timedout = true; - done = true; - timeout = 0; - state = I2C_START; - } - break; - default: - state = I2C_START; - timeout = 0; - break; - } + bool res = perform_i2c_transaction(DevAddress, 0, NULL, 0, false, true); + if (!res) { + I2C_Unstick(); } unlock(); - return timedout == false; + return res; } void I2C_EV_IRQ() { From c210bf983c78557049418debe90fab37f2bc698b Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 19:38:51 +1100 Subject: [PATCH 09/40] Split --- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 339 +++++++++++++------------ 1 file changed, 175 insertions(+), 164 deletions(-) diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index f13bc3c1..2f061b98 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -47,11 +47,181 @@ struct i2c_state { i2c_step currentStep; bool isMemoryWrite; bool wakePart; + uint8_t deviceAddress; + uint8_t memoryAddress; + uint8_t * buffer; + uint16_t numberOfBytes; dma_parameter_struct dma_init_struct; }; volatile i2c_state currentState; +void perform_i2c_step() { + //Performs next step of the i2c state machine + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); + //Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_BERR); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_LOSTARB)) { + i2c_flag_clear(I2C0, I2C_FLAG_LOSTARB); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_PECERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_PECERR); + // Bus Error + currentState.currentStep = Error_occured; + } + switch (currentState.currentStep) { + case Error_occured: + i2c_stop_on_bus(I2C0); + break; + case Write_start: + + /* enable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_ENABLE); + /* i2c master sends start signal only when the bus is idle */ + if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { + /* send the start signal */ + i2c_start_on_bus(I2C0); + currentState.currentStep = Write_device_address; + } + break; + + case Write_device_address: + /* i2c master sends START signal successfully */ + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + i2c_master_addressing(I2C0, currentState.deviceAddress, I2C_TRANSMITTER); + currentState.currentStep = Write_device_memory_address; + } + break; + case Write_device_memory_address: + //Send the device memory location + + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + + if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_BERR); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); + //Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } else if (currentState.wakePart) { + //We are stopping here + currentState.currentStep = Send_stop; + } else if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { + // Write out the 8 byte address + i2c_data_transmit(I2C0, currentState.memoryAddress); + + if (currentState.isMemoryWrite) { + currentState.currentStep = Write_device_data_start; + } else { + currentState.currentStep = Read_start; + } + } + } + + break; + case Write_device_data_start: + + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH5); + currentState.currentStep = Write_device_data_finish; + } + break; + + case Write_device_data_finish: //Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + currentState.currentStep = Send_stop; + } + } + break; + case Read_start: + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + i2c_start_on_bus(I2C0); + currentState.currentStep = Read_device_address; + } + break; + case Read_device_address: + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + i2c_master_addressing(I2C0, currentState.deviceAddress, I2C_RECEIVER); + currentState.currentStep = Read_device_data_start; + } + break; + case Read_device_data_start: + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + //Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } + /* one byte master reception procedure (polling) */ + if (currentState.numberOfBytes == 0) { + currentState.currentStep = Send_stop; + } else if (currentState.numberOfBytes == 1) { + /* disable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_DISABLE); + /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register + * (I2C_STAT0 has already been read) */ + i2c_flag_get(I2C0, I2C_FLAG_ADDSEND); //sat0 + i2c_flag_get(I2C0, I2C_FLAG_I2CBSY); //sat1 + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + /* wait for the byte to be received */ + while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) + ; + /* read the byte received from the EEPROM */ + *currentState.buffer = i2c_data_receive(I2C0); + currentState.currentStep = Wait_stop; + } else { /* more than one byte master reception procedure (DMA) */ + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH6); + currentState.currentStep = Read_device_data_finish; + } + } + break; + case Read_device_data_finish: //Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) { + currentState.currentStep = Send_stop; + } + + break; + case Send_stop: + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + currentState.currentStep = Wait_stop; + break; + case Wait_stop: + /* i2c master sends STOP signal successfully */ + if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { + currentState.currentStep = Done; + } + break; + default: + //If we get here something is amiss + return; + } +} + bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8_t *p_buffer, uint16_t number_of_byte, bool isWrite, bool isWakeOnly) { { //TODO is this required @@ -66,6 +236,10 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 currentState.isMemoryWrite = isWrite; currentState.wakePart = isWakeOnly; + currentState.deviceAddress = DevAddress; + currentState.memoryAddress = memory_address; + currentState.numberOfBytes = number_of_byte; + currentState.buffer = p_buffer; if (!isWakeOnly) { //Setup DMA currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; @@ -102,170 +276,7 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 i2c_stop_on_bus(I2C0); return false; } -// if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { -// i2c_flag_clear(I2C0, I2C_FLAG_AERR); -// //Arb error - we lost the bus / nacked -// currentState.currentStep = Error_occured; -// } else if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { -// i2c_flag_clear(I2C0, I2C_FLAG_BERR); -// // Bus Error -// currentState.currentStep = Error_occured; -// } else if (i2c_flag_get(I2C0, I2C_FLAG_LOSTARB)) { -// i2c_flag_clear(I2C0, I2C_FLAG_LOSTARB); -// // Bus Error -// currentState.currentStep = Error_occured; -// } else if (i2c_flag_get(I2C0, I2C_FLAG_PECERR)) { -// i2c_flag_clear(I2C0, I2C_FLAG_PECERR); -// // Bus Error -// currentState.currentStep = Error_occured; -// } - switch (currentState.currentStep) { - case Error_occured: - - i2c_stop_on_bus(I2C0); - return false; - break; - case Write_start: - - /* enable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_ENABLE); - /* i2c master sends start signal only when the bus is idle */ - if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { - /* send the start signal */ - i2c_start_on_bus(I2C0); - currentState.currentStep = Write_device_address; - } - break; - - case Write_device_address: - /* i2c master sends START signal successfully */ - if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER); - currentState.currentStep = Write_device_memory_address; - } - break; - case Write_device_memory_address: - //Send the device memory location - - if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - - if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_BERR); - // Bus Error - currentState.currentStep = Error_occured; - } else if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - //Arb error - we lost the bus / nacked - currentState.currentStep = Error_occured; - } else if (currentState.wakePart) { - //We are stopping here - currentState.currentStep = Send_stop; - } else if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { - // Write out the 8 byte address - i2c_data_transmit(I2C0, memory_address); - - if (currentState.isMemoryWrite) { - currentState.currentStep = Write_device_data_start; - } else { - currentState.currentStep = Read_start; - } - } - } - - break; - case Write_device_data_start: - - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH5); - currentState.currentStep = Write_device_data_finish; - } - break; - - case Write_device_data_finish: //Wait for complete then goto stop - /* wait until BTC bit is set */ - if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - currentState.currentStep = Send_stop; - } - } - break; - case Read_start: - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - i2c_start_on_bus(I2C0); - currentState.currentStep = Read_device_address; - } - break; - case Read_device_address: - if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - i2c_master_addressing(I2C0, DevAddress, I2C_RECEIVER); - currentState.currentStep = Read_device_data_start; - } - break; - case Read_device_data_start: - if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - //Arb error - we lost the bus / nacked - currentState.currentStep = Error_occured; - } - /* one byte master reception procedure (polling) */ - if (number_of_byte == 0) { - currentState.currentStep = Send_stop; - } else if (number_of_byte == 1) { - /* disable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_DISABLE); - /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register - * (I2C_STAT0 has already been read) */ - i2c_flag_get(I2C0, I2C_FLAG_ADDSEND); //sat0 - i2c_flag_get(I2C0, I2C_FLAG_I2CBSY); //sat1 - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - /* wait for the byte to be received */ - while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) - ; - /* read the byte received from the EEPROM */ - *p_buffer = i2c_data_receive(I2C0); - currentState.currentStep = Wait_stop; - } else { /* more than one byte master reception procedure (DMA) */ - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH6); - currentState.currentStep = Read_device_data_finish; - } - } - break; - case Read_device_data_finish: //Wait for complete then goto stop - /* wait until BTC bit is set */ - if (dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) { - currentState.currentStep = Send_stop; - } - - break; - case Send_stop: - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - currentState.currentStep = Wait_stop; - break; - case Wait_stop: - /* i2c master sends STOP signal successfully */ - if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { - currentState.currentStep = Done; - } - break; - default: - //If we get here something is amiss - return false; - } + perform_i2c_step(); } return true; } From 2bfb6745e4ed790d35da66c459e9944677b04f44 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 19:54:37 +1100 Subject: [PATCH 10/40] Update policy_engine.cpp --- source/Core/Drivers/FUSB302/policy_engine.cpp | 973 +++++++++--------- 1 file changed, 488 insertions(+), 485 deletions(-) diff --git a/source/Core/Drivers/FUSB302/policy_engine.cpp b/source/Core/Drivers/FUSB302/policy_engine.cpp index 5ce5428e..b8c83bd7 100644 --- a/source/Core/Drivers/FUSB302/policy_engine.cpp +++ b/source/Core/Drivers/FUSB302/policy_engine.cpp @@ -21,614 +21,617 @@ #include "protocol_tx.h" #include #include -bool PolicyEngine::pdNegotiationComplete; -int PolicyEngine::current_voltage_mv; -int PolicyEngine::_requested_voltage; -bool PolicyEngine::_unconstrained_power; -union pd_msg PolicyEngine::currentMessage; -uint16_t PolicyEngine::hdr_template; -bool PolicyEngine::_explicit_contract; -int8_t PolicyEngine::_hard_reset_counter; -int8_t PolicyEngine::_old_tcc_match; -uint8_t PolicyEngine::_pps_index; -uint8_t PolicyEngine::_last_pps; -osThreadId PolicyEngine::TaskHandle = NULL; -uint32_t PolicyEngine::TaskBuffer[PolicyEngine::TaskStackSize]; -osStaticThreadDef_t PolicyEngine::TaskControlBlock; -union pd_msg PolicyEngine::tempMessage; -union pd_msg PolicyEngine::_last_dpm_request; +bool PolicyEngine::pdNegotiationComplete; +int PolicyEngine::current_voltage_mv; +int PolicyEngine::_requested_voltage; +bool PolicyEngine::_unconstrained_power; +union pd_msg PolicyEngine::currentMessage; +uint16_t PolicyEngine::hdr_template; +bool PolicyEngine::_explicit_contract; +int8_t PolicyEngine::_hard_reset_counter; +int8_t PolicyEngine::_old_tcc_match; +uint8_t PolicyEngine::_pps_index; +uint8_t PolicyEngine::_last_pps; +osThreadId PolicyEngine::TaskHandle = NULL; +uint32_t PolicyEngine::TaskBuffer[PolicyEngine::TaskStackSize]; +osStaticThreadDef_t PolicyEngine::TaskControlBlock; +union pd_msg PolicyEngine::tempMessage; +union pd_msg PolicyEngine::_last_dpm_request; PolicyEngine::policy_engine_state PolicyEngine::state = PESinkStartup; -StaticQueue_t PolicyEngine::xStaticQueue; -uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)]; -QueueHandle_t PolicyEngine::messagesWaiting = NULL; -EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL; -StaticEventGroup_t PolicyEngine::xCreatedEventGroup; -void PolicyEngine::init() { - messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue); - // Create static thread at PDB_PRIO_PE priority - osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, &TaskControlBlock); - TaskHandle = osThreadCreate(osThread(PolEng), NULL); - xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup); +StaticQueue_t PolicyEngine::xStaticQueue; +uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)]; +QueueHandle_t PolicyEngine::messagesWaiting = NULL; +EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL; +StaticEventGroup_t PolicyEngine::xCreatedEventGroup; +void PolicyEngine::init() { + messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue); + // Create static thread at PDB_PRIO_PE priority + osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, &TaskControlBlock); + TaskHandle = osThreadCreate(osThread(PolEng), NULL); + xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup); } void PolicyEngine::notify(uint32_t notification) { - if (xEventGroupHandle != NULL) { - xEventGroupSetBits(xEventGroupHandle, notification); - } + if (xEventGroupHandle != NULL) { + xEventGroupSetBits(xEventGroupHandle, notification); + } } void PolicyEngine::pe_task(const void *arg) { - (void)arg; - // Internal thread loop - hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK; - /* Initialize the old_tcc_match */ - _old_tcc_match = -1; - /* Initialize the pps_index */ - _pps_index = 8; - /* Initialize the last_pps */ - _last_pps = 8; + (void) arg; + // Internal thread loop + hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK; + /* Initialize the old_tcc_match */ + _old_tcc_match = -1; + /* Initialize the pps_index */ + _pps_index = 8; + /* Initialize the last_pps */ + _last_pps = 8; - for (;;) { - // Loop based on state - switch (state) { + for (;;) { + // Loop based on state + switch (state) { - case PESinkStartup: - state = pe_sink_startup(); - break; - case PESinkDiscovery: - state = pe_sink_discovery(); - break; - case PESinkWaitCap: - state = pe_sink_wait_cap(); - break; - case PESinkEvalCap: - state = pe_sink_eval_cap(); - break; - case PESinkSelectCap: - state = pe_sink_select_cap(); - break; - case PESinkTransitionSink: - state = pe_sink_transition_sink(); - break; - case PESinkReady: - state = pe_sink_ready(); - break; - case PESinkGetSourceCap: - state = pe_sink_get_source_cap(); - break; - case PESinkGiveSinkCap: - state = pe_sink_give_sink_cap(); - break; - case PESinkHardReset: - state = pe_sink_hard_reset(); - break; - case PESinkTransitionDefault: - state = pe_sink_transition_default(); - break; - case PESinkSoftReset: - state = pe_sink_soft_reset(); - break; - case PESinkSendSoftReset: - state = pe_sink_send_soft_reset(); - break; - case PESinkSendNotSupported: - state = pe_sink_send_not_supported(); - break; - case PESinkChunkReceived: - state = pe_sink_chunk_received(); - break; - case PESinkSourceUnresponsive: - state = pe_sink_source_unresponsive(); - break; - case PESinkNotSupportedReceived: - state = pe_sink_not_supported_received(); - break; - default: - state = PESinkStartup; - break; - } - } + case PESinkStartup: + state = pe_sink_startup(); + break; + case PESinkDiscovery: + state = pe_sink_discovery(); + break; + case PESinkWaitCap: + state = pe_sink_wait_cap(); + break; + case PESinkEvalCap: + state = pe_sink_eval_cap(); + break; + case PESinkSelectCap: + state = pe_sink_select_cap(); + break; + case PESinkTransitionSink: + state = pe_sink_transition_sink(); + break; + case PESinkReady: + state = pe_sink_ready(); + break; + case PESinkGetSourceCap: + state = pe_sink_get_source_cap(); + break; + case PESinkGiveSinkCap: + state = pe_sink_give_sink_cap(); + break; + case PESinkHardReset: + state = pe_sink_hard_reset(); + break; + case PESinkTransitionDefault: + state = pe_sink_transition_default(); + break; + case PESinkSoftReset: + state = pe_sink_soft_reset(); + break; + case PESinkSendSoftReset: + state = pe_sink_send_soft_reset(); + break; + case PESinkSendNotSupported: + state = pe_sink_send_not_supported(); + break; + case PESinkChunkReceived: + state = pe_sink_chunk_received(); + break; + case PESinkSourceUnresponsive: + state = pe_sink_source_unresponsive(); + break; + case PESinkNotSupportedReceived: + state = pe_sink_not_supported_received(); + break; + default: + state = PESinkStartup; + break; + } + } } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_startup() { - /* We don't have an explicit contract currently */ - _explicit_contract = false; + /* We don't have an explicit contract currently */ + _explicit_contract = false; - // If desired could send an alert that PD is starting + // If desired could send an alert that PD is starting - /* No need to reset the protocol layer here. There are two ways into this - * state: startup and exiting hard reset. On startup, the protocol layer - * is reset by the startup procedure. When exiting hard reset, the - * protocol layer is reset by the hard reset state machine. Since it's - * already done somewhere else, there's no need to do it again here. */ + /* No need to reset the protocol layer here. There are two ways into this + * state: startup and exiting hard reset. On startup, the protocol layer + * is reset by the startup procedure. When exiting hard reset, the + * protocol layer is reset by the hard reset state machine. Since it's + * already done somewhere else, there's no need to do it again here. */ - return PESinkDiscovery; + return PESinkDiscovery; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_discovery() { - /* Wait for VBUS. Since it's our only power source, we already know that - * we have it, so just move on. */ + /* Wait for VBUS. Since it's our only power source, we already know that + * we have it, so just move on. */ - return PESinkWaitCap; + return PESinkWaitCap; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() { - /* Fetch a message from the protocol layer */ - eventmask_t evt = 0; - if (readMessage()) { - evt = PDB_EVT_PE_MSG_RX_PEND; - } else { - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET, - // Wait for cap timeout - PD_T_TYPEC_SINK_WAIT_CAP); - } - /* If we timed out waiting for Source_Capabilities, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkWaitCap; - } - /* If we're too hot, we shouldn't negotiate power yet */ - if (evt & PDB_EVT_PE_I_OVRTEMP) { - return PESinkWaitCap; - } + /* Fetch a message from the protocol layer */ + eventmask_t evt = 0; + if (readMessage()) { + evt = PDB_EVT_PE_MSG_RX_PEND; + } else { + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET, + // Wait for cap timeout + PD_T_TYPEC_SINK_WAIT_CAP); + } + /* If we timed out waiting for Source_Capabilities, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkWaitCap; + } + /* If we're too hot, we shouldn't negotiate power yet */ + if (evt & PDB_EVT_PE_I_OVRTEMP) { + return PESinkWaitCap; + } - /* If we got a message */ - if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) { - /* Get the message */ - while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) { - /* If we got a Source_Capabilities message, read it. */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { - /* First, determine what PD revision we're using */ - if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) { - /* If the other end is using at least version 3.0, we'll - * use version 3.0. */ - if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) { - hdr_template |= PD_SPECREV_3_0; - /* Otherwise, use 2.0. Don't worry about the 1.0 case - * because we don't have hardware for PD 1.0 signaling. */ - } else { - hdr_template |= PD_SPECREV_2_0; - } - } - return PESinkEvalCap; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } - evt = 0; - } - return PESinkWaitCap; // wait for more messages? - } + /* If we got a message */ + if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) { + /* Get the message */ + while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) { + /* If we got a Source_Capabilities message, read it. */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { + /* First, determine what PD revision we're using */ + if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) { + /* If the other end is using at least version 3.0, we'll + * use version 3.0. */ + if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) { + hdr_template |= PD_SPECREV_3_0; + /* Otherwise, use 2.0. Don't worry about the 1.0 case + * because we don't have hardware for PD 1.0 signaling. */ + } else { + hdr_template |= PD_SPECREV_2_0; + } + } + return PESinkEvalCap; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } + evt = 0; + } + return PESinkWaitCap; // wait for more messages? + } - /* If we failed to get a message, send a hard reset */ - return PESinkHardReset; + /* If we failed to get a message, send a hard reset */ + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_eval_cap() { - /* If we have a Source_Capabilities message, remember the index of the - * first PPS APDO so we can check if the request is for a PPS APDO in - * PE_SNK_Select_Cap. */ - /* Start by assuming we won't find a PPS APDO (set the index greater - * than the maximum possible) */ - _pps_index = 8; - /* Search for the first PPS APDO */ - for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) { - if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) { - _pps_index = i + 1; - break; - } - } - /* New capabilities also means we can't be making a request from the - * same PPS APDO */ - _last_pps = 8; + /* If we have a Source_Capabilities message, remember the index of the + * first PPS APDO so we can check if the request is for a PPS APDO in + * PE_SNK_Select_Cap. */ + /* Start by assuming we won't find a PPS APDO (set the index greater + * than the maximum possible) */ + _pps_index = 8; + /* Search for the first PPS APDO */ + for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) { + if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) { + _pps_index = i + 1; + break; + } + } + /* New capabilities also means we can't be making a request from the + * same PPS APDO */ + _last_pps = 8; - /* Ask the DPM what to request */ - if (pdbs_dpm_evaluate_capability(&tempMessage, &_last_dpm_request)) { + /* Ask the DPM what to request */ + if (pdbs_dpm_evaluate_capability(&tempMessage, &_last_dpm_request)) { - return PESinkSelectCap; - } + return PESinkSelectCap; + } - return PESinkWaitCap; + return PESinkWaitCap; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() { - /* Transmit the request */ - waitForEvent(0xFFFF, 0); // clear pending - ProtocolTransmit::pushMessage(&_last_dpm_request); - // Send indication that there is a message pending - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET || evt == 0) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) { - return PESinkHardReset; - } + /* Transmit the request */ + waitForEvent(0xFFFF, 0); // clear pending + ProtocolTransmit::pushMessage(&_last_dpm_request); + // Send indication that there is a message pending + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET || evt == 0) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) { + return PESinkHardReset; + } - /* Wait for a response */ - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If we didn't get a response before the timeout, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } + /* Wait for a response */ + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If we didn't get a response before the timeout, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } - /* Get the response message */ - if (messageWaiting()) { - readMessage(); - /* If the source accepted our request, wait for the new power */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* Get the response message */ + if (messageWaiting()) { + readMessage(); + /* If the source accepted our request, wait for the new power */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkTransitionSink; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSoftReset; - /* If the message was Wait or Reject */ - } else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) { - /* If we don't have an explicit contract, wait for capabilities */ - if (!_explicit_contract) { - return PESinkWaitCap; - /* If we do have an explicit contract, go to the ready state */ - } else { - return PESinkReady; - } - } else { - return PESinkSendSoftReset; - } - } - return PESinkHardReset; + return PESinkTransitionSink; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSoftReset; + /* If the message was Wait or Reject */ + } else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* If we don't have an explicit contract, wait for capabilities */ + if (!_explicit_contract) { + return PESinkWaitCap; + /* If we do have an explicit contract, go to the ready state */ + } else { + return PESinkReady; + } + } else { + return PESinkSendSoftReset; + } + } + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() { - /* Wait for the PS_RDY message */ - eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If no message was received, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } + /* Wait for the PS_RDY message */ + eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If no message was received, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } - /* If we received a message, read it */ - if (messageWaiting()) { - readMessage(); - /* If we got a PS_RDY, handle it */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) { - /* We just finished negotiating an explicit contract */ - _explicit_contract = true; + /* If we received a message, read it */ + if (messageWaiting()) { + readMessage(); + /* If we got a PS_RDY, handle it */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* We just finished negotiating an explicit contract */ + _explicit_contract = true; - /* Set the output appropriately */ - pdbs_dpm_transition_requested(); + /* Set the output appropriately */ + pdbs_dpm_transition_requested(); - return PESinkReady; - /* If there was a protocol error, send a hard reset */ - } else { - /* Turn off the power output before this hard reset to make sure we - * don't supply an incorrect voltage to the device we're powering. - */ - pdbs_dpm_transition_default(); + return PESinkReady; + /* If there was a protocol error, send a hard reset */ + } else { + /* Turn off the power output before this hard reset to make sure we + * don't supply an incorrect voltage to the device we're powering. + */ + pdbs_dpm_transition_default(); - return PESinkHardReset; - } - } + return PESinkHardReset; + } + } - return PESinkHardReset; + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() { - eventmask_t evt; + eventmask_t evt; - /* Wait for an event */ - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP); + /* Wait for an event */ + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } - /* If we overheated, send a hard reset */ - if (evt & PDB_EVT_PE_I_OVRTEMP) { - return PESinkHardReset; - } + /* If we overheated, send a hard reset */ + if (evt & PDB_EVT_PE_I_OVRTEMP) { + return PESinkHardReset; + } - /* If we received a message */ - if (evt & PDB_EVT_PE_MSG_RX) { - if (messageWaiting()) { - readMessage(); - /* Ignore vendor-defined messages */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) { + /* If we received a message */ + if (evt & PDB_EVT_PE_MSG_RX) { + if (messageWaiting()) { + readMessage(); + /* Ignore vendor-defined messages */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) { - return PESinkReady; - /* Ignore Ping messages */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkReady; + /* Ignore Ping messages */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkReady; - /* DR_Swap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkReady; + /* DR_Swap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* Get_Source_Cap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSendNotSupported; + /* Get_Source_Cap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* PR_Swap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSendNotSupported; + /* PR_Swap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* VCONN_Swap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSendNotSupported; + /* VCONN_Swap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* Request messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) { + return PESinkSendNotSupported; + /* Request messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) { - return PESinkSendNotSupported; - /* Sink_Capabilities messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { + return PESinkSendNotSupported; + /* Sink_Capabilities messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { - return PESinkSendNotSupported; - /* Handle GotoMin messages */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) { - /* GiveBack is not supported */ - return PESinkSendNotSupported; + return PESinkSendNotSupported; + /* Handle GotoMin messages */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* GiveBack is not supported */ + return PESinkSendNotSupported; - /* Evaluate new Source_Capabilities */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { - /* Don't free the message: we need to keep the - * Source_Capabilities message so we can evaluate it. */ - return PESinkEvalCap; - /* Give sink capabilities when asked */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* Evaluate new Source_Capabilities */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { + /* Don't free the message: we need to keep the + * Source_Capabilities message so we can evaluate it. */ + return PESinkEvalCap; + /* Give sink capabilities when asked */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkGiveSinkCap; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkGiveSinkCap; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSoftReset; - /* PD 3.0 messges */ - } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { - /* If the message is a multi-chunk extended message, let it - * time out. */ - if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) { + return PESinkSoftReset; + /* PD 3.0 messges */ + } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { + /* If the message is a multi-chunk extended message, let it + * time out. */ + if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) { - return PESinkChunkReceived; - /* Tell the DPM a message we sent got a response of - * Not_Supported. */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkChunkReceived; + /* Tell the DPM a message we sent got a response of + * Not_Supported. */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkNotSupportedReceived; - /* If we got an unknown message, send a soft reset */ - } else { + return PESinkNotSupportedReceived; + /* If we got an unknown message, send a soft reset */ + } else { - return PESinkSendSoftReset; - } - /* If we got an unknown message, send a soft reset ??? */ - } else { + return PESinkSendSoftReset; + } + } else { + /* if we get an unknown message code, silently ignore it*/ + return PESinkReady; + } + } + } - return PESinkSendSoftReset; - } - } - } - - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() { - /* Get a message object */ - union pd_msg *get_source_cap = &tempMessage; - /* Make a Get_Source_Cap message */ - get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0); - /* Transmit the Get_Source_Cap */ - ProtocolTransmit::pushMessage(get_source_cap); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* Free the sent message */ - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* Get a message object */ + union pd_msg *get_source_cap = &tempMessage; + /* Make a Get_Source_Cap message */ + get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0); + /* Transmit the Get_Source_Cap */ + ProtocolTransmit::pushMessage(get_source_cap); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Free the sent message */ + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() { - /* Get a message object */ - union pd_msg *snk_cap = &tempMessage; - /* Get our capabilities from the DPM */ - pdbs_dpm_get_sink_capability(snk_cap); + /* Get a message object */ + union pd_msg *snk_cap = &tempMessage; + /* Get our capabilities from the DPM */ + pdbs_dpm_get_sink_capability(snk_cap); - /* Transmit our capabilities */ - ProtocolTransmit::pushMessage(snk_cap); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Transmit our capabilities */ + ProtocolTransmit::pushMessage(snk_cap); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* Free the Sink_Capabilities message */ + /* Free the Sink_Capabilities message */ - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_hard_reset() { - /* If we've already sent the maximum number of hard resets, assume the - * source is unresponsive. */ - if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) { - return PESinkSourceUnresponsive; - } - // So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU - // So therefore we went get anywhere :) - /* Increment HardResetCounter */ - _hard_reset_counter++; + /* If we've already sent the maximum number of hard resets, assume the + * source is unresponsive. */ + if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) { + return PESinkSourceUnresponsive; + } + // So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU + // So therefore we went get anywhere :) + /* Increment HardResetCounter */ + _hard_reset_counter++; - return PESinkTransitionDefault; + return PESinkTransitionDefault; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_default() { - _explicit_contract = false; + _explicit_contract = false; - /* Tell the DPM to transition to default power */ - pdbs_dpm_transition_default(); + /* Tell the DPM to transition to default power */ + pdbs_dpm_transition_default(); - /* There is no local hardware to reset. */ - /* Since we never change our data role from UFP, there is no reason to set - * it here. */ + /* There is no local hardware to reset. */ + /* Since we never change our data role from UFP, there is no reason to set + * it here. */ - return PESinkStartup; + return PESinkStartup; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() { - /* No need to explicitly reset the protocol layer here. It resets itself - * when a Soft_Reset message is received. */ + /* No need to explicitly reset the protocol layer here. It resets itself + * when a Soft_Reset message is received. */ - /* Get a message object */ - union pd_msg accept; - /* Make an Accept message */ - accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0); - /* Transmit the Accept */ - ProtocolTransmit::pushMessage(&accept); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* Free the sent message */ + /* Get a message object */ + union pd_msg accept; + /* Make an Accept message */ + accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0); + /* Transmit the Accept */ + ProtocolTransmit::pushMessage(&accept); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Free the sent message */ - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - return PESinkWaitCap; + return PESinkWaitCap; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() { - /* No need to explicitly reset the protocol layer here. It resets itself - * just before a Soft_Reset message is transmitted. */ + /* No need to explicitly reset the protocol layer here. It resets itself + * just before a Soft_Reset message is transmitted. */ - /* Get a message object */ - union pd_msg *softrst = &tempMessage; - /* Make a Soft_Reset message */ - softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0); - /* Transmit the soft reset */ - ProtocolTransmit::pushMessage(softrst); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* Get a message object */ + union pd_msg *softrst = &tempMessage; + /* Make a Soft_Reset message */ + softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0); + /* Transmit the soft reset */ + ProtocolTransmit::pushMessage(softrst); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - /* Wait for a response */ - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If we didn't get a response before the timeout, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } + /* Wait for a response */ + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If we didn't get a response before the timeout, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } - /* Get the response message */ - if (messageWaiting()) { - readMessage(); - /* If the source accepted our soft reset, wait for capabilities. */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* Get the response message */ + if (messageWaiting()) { + readMessage(); + /* If the source accepted our soft reset, wait for capabilities. */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkWaitCap; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkWaitCap; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSoftReset; - /* Otherwise, send a hard reset */ - } else { + return PESinkSoftReset; + /* Otherwise, send a hard reset */ + } else { - return PESinkHardReset; - } - } - return PESinkHardReset; + return PESinkHardReset; + } + } + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() { - /* Get a message object */ - union pd_msg *not_supported = &tempMessage; + /* Get a message object */ + union pd_msg *not_supported = &tempMessage; - if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_2_0) { - /* Make a Reject message */ - not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0); - } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { - /* Make a Not_Supported message */ - not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0); - } + if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_2_0) { + /* Make a Reject message */ + not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0); + } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { + /* Make a Not_Supported message */ + not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0); + } - /* Transmit the message */ - ProtocolTransmit::pushMessage(not_supported); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Transmit the message */ + ProtocolTransmit::pushMessage(not_supported); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a soft reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkSendSoftReset; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a soft reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkSendSoftReset; + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() { - /* Wait for tChunkingNotSupported */ - eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } + /* Wait for tChunkingNotSupported */ + eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } - return PESinkSendNotSupported; + return PESinkSendNotSupported; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_not_supported_received() { - /* Inform the Device Policy Manager that we received a Not_Supported - * message. */ + /* Inform the Device Policy Manager that we received a Not_Supported + * message. */ - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() { - // Sit and chill, as PD is not working - osDelay(PD_T_PD_DEBOUNCE); + // Sit and chill, as PD is not working + osDelay(PD_T_PD_DEBOUNCE); - return PESinkSourceUnresponsive; + return PESinkSourceUnresponsive; } -uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) { return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); } +uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) { + return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); +} -bool PolicyEngine::isPD3_0() { return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; } +bool PolicyEngine::isPD3_0() { + return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; +} From 2f73c99fa46f71690a44a798fe181112109cfd29 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 20:29:26 +1100 Subject: [PATCH 11/40] Check hall effect sensor is present before threshold --- source/Core/Threads/GUIThread.cpp | 1579 +++++++++++++++-------------- 1 file changed, 790 insertions(+), 789 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index d1ccd054..651e8395 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -26,731 +26,732 @@ extern "C" { #include "policy_engine.h" #endif // File local variables -extern uint32_t currentTempTargetDegC; +extern uint32_t currentTempTargetDegC; extern TickType_t lastMovementTime; extern osThreadId GUITaskHandle; extern osThreadId MOVTaskHandle; extern osThreadId PIDTaskHandle; -static bool shouldBeSleeping(bool inAutoStart = false); -static bool shouldShutdown(); -void showWarnings(); +static bool shouldBeSleeping(bool inAutoStart = false); +static bool shouldShutdown(); +void showWarnings(); #define MOVEMENT_INACTIVITY_TIME (60 * configTICK_RATE_HZ) #define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ) static TickType_t lastHallEffectSleepStart = 0; -static uint16_t min(uint16_t a, uint16_t b) { - if (a > b) - return b; - else - return a; +static uint16_t min(uint16_t a, uint16_t b) { + if (a > b) + return b; + else + return a; } void warnUser(const char *warning, const int font, const int timeout) { - OLED::setFont(font); - OLED::clearScreen(); - OLED::setCursor(0, 0); - OLED::print(warning); - OLED::refresh(); - waitForButtonPressOrTimeout(timeout); + OLED::setFont(font); + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print(warning); + OLED::refresh(); + waitForButtonPressOrTimeout(timeout); } void printVoltage() { - uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0); - OLED::printNumber(volt / 10, 2); - OLED::print(SymbolDot); - OLED::printNumber(volt % 10, 1); + uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0); + OLED::printNumber(volt / 10, 2); + OLED::print(SymbolDot); + OLED::printNumber(volt % 10, 1); } void GUIDelay() { - // Called in all UI looping tasks, - // This limits the re-draw rate to the LCD and also lets the DMA run - // As the gui task can very easily fill this bus with transactions, which will - // prevent the movement detection from running - osDelay(50); + // Called in all UI looping tasks, + // This limits the re-draw rate to the LCD and also lets the DMA run + // As the gui task can very easily fill this bus with transactions, which will + // prevent the movement detection from running + osDelay(50); } void gui_drawTipTemp(bool symbol) { - // Draw tip temp handling unit conversion & tolerance near setpoint - uint32_t Temp = 0; - if (systemSettings.temperatureInF) { - Temp = TipThermoModel::getTipInF(); - } else - { - Temp = TipThermoModel::getTipInC(); - } + // Draw tip temp handling unit conversion & tolerance near setpoint + uint32_t Temp = 0; + if (systemSettings.temperatureInF) { + Temp = TipThermoModel::getTipInF(); + } else { + Temp = TipThermoModel::getTipInC(); + } - OLED::printNumber(Temp, 3); // Draw the tip temp out - if (symbol) { - if (OLED::getFont() == 0) { - // Big font, can draw nice symbols - if (systemSettings.temperatureInF) - OLED::drawSymbol(0); - else - OLED::drawSymbol(1); - } else { - // Otherwise fall back to chars - if (systemSettings.temperatureInF) - OLED::print(SymbolDegF); - else - OLED::print(SymbolDegC); - } - } + OLED::printNumber(Temp, 3); // Draw the tip temp out + if (symbol) { + if (OLED::getFont() == 0) { + // Big font, can draw nice symbols + if (systemSettings.temperatureInF) + OLED::drawSymbol(0); + else + OLED::drawSymbol(1); + } else { + // Otherwise fall back to chars + if (systemSettings.temperatureInF) + OLED::print(SymbolDegF); + else + OLED::print(SymbolDegC); + } + } } #ifdef POW_DC // returns true if undervoltage has occured static bool checkVoltageForExit() { - if (!getIsPoweredByDCIN()) { - return false; - } - uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0); + if (!getIsPoweredByDCIN()) { + return false; + } + uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0); - // Dont check for first 2 seconds while the ADC stabilizes and the DMA fills - // the buffer - if (xTaskGetTickCount() > (TICKS_SECOND * 2)) { - if ((v < lookupVoltageLevel())) { - currentTempTargetDegC = 0; - OLED::clearScreen(); - OLED::setCursor(0, 0); - if (systemSettings.detailedSoldering) { - OLED::setFont(1); - OLED::print(UndervoltageString); - OLED::setCursor(0, 8); - OLED::print(InputVoltageString); - printVoltage(); - OLED::print(SymbolVolts); - } else { - OLED::setFont(0); - OLED::print(UVLOWarningString); - } + // Dont check for first 2 seconds while the ADC stabilizes and the DMA fills + // the buffer + if (xTaskGetTickCount() > (TICKS_SECOND * 2)) { + if ((v < lookupVoltageLevel())) { + currentTempTargetDegC = 0; + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (systemSettings.detailedSoldering) { + OLED::setFont(1); + OLED::print(UndervoltageString); + OLED::setCursor(0, 8); + OLED::print(InputVoltageString); + printVoltage(); + OLED::print(SymbolVolts); + } else { + OLED::setFont(0); + OLED::print(UVLOWarningString); + } - OLED::refresh(); - GUIDelay(); - waitForButtonPress(); - return true; - } - } - return false; + OLED::refresh(); + GUIDelay(); + waitForButtonPress(); + return true; + } + } + return false; } #endif static void gui_drawBatteryIcon() { #if defined(POW_PD) || defined(POW_QC) - if (!getIsPoweredByDCIN()) { - // On TS80 we replace this symbol with the voltage we are operating on - // If <9V then show single digit, if not show dual small ones vertically stacked - uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); - if (V % 10 >= 5) - V = V / 10 + 1; // round up - else - V = V / 10; - if (V >= 10) { - int16_t xPos = OLED::getCursorX(); - OLED::setFont(1); - OLED::printNumber(V / 10, 1); - OLED::setCursor(xPos, 8); - OLED::printNumber(V % 10, 1); - OLED::setFont(0); - OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char - } else { - OLED::printNumber(V, 1); - } - return; - } + if (!getIsPoweredByDCIN()) { + // On TS80 we replace this symbol with the voltage we are operating on + // If <9V then show single digit, if not show dual small ones vertically stacked + uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); + if (V % 10 >= 5) + V = V / 10 + 1; // round up + else + V = V / 10; + if (V >= 10) { + int16_t xPos = OLED::getCursorX(); + OLED::setFont(1); + OLED::printNumber(V / 10, 1); + OLED::setCursor(xPos, 8); + OLED::printNumber(V % 10, 1); + OLED::setFont(0); + OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char + } else { + OLED::printNumber(V, 1); + } + return; + } #endif #ifdef POW_DC - if (systemSettings.minDCVoltageCells) { - // User is on a lithium battery - // we need to calculate which of the 10 levels they are on - uint8_t cellCount = systemSettings.minDCVoltageCells + 2; - uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount; - // Should give us approx cell voltage X10 - // Range is 42 -> 33 = 9 steps therefore we will use battery 0-9 - if (cellV < 33) - cellV = 33; - cellV -= 33; // Should leave us a number of 0-9 - if (cellV > 9) - cellV = 9; - OLED::drawBattery(cellV + 1); - } else { - OLED::drawSymbol(15); // Draw the DC Logo - } + if (systemSettings.minDCVoltageCells) { + // User is on a lithium battery + // we need to calculate which of the 10 levels they are on + uint8_t cellCount = systemSettings.minDCVoltageCells + 2; + uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount; + // Should give us approx cell voltage X10 + // Range is 42 -> 33 = 9 steps therefore we will use battery 0-9 + if (cellV < 33) + cellV = 33; + cellV -= 33; // Should leave us a number of 0-9 + if (cellV > 9) + cellV = 9; + OLED::drawBattery(cellV + 1); + } else { + OLED::drawSymbol(15); // Draw the DC Logo + } #endif } static void gui_solderingTempAdjust() { - uint32_t lastChange = xTaskGetTickCount(); - currentTempTargetDegC = 0; - uint32_t autoRepeatTimer = 0; - uint8_t autoRepeatAcceleration = 0; - bool waitForRelease = false; - ButtonState buttons = getButtonState(); - if (buttons != BUTTON_NONE) { - // Temp adjust entered by long-pressing F button. - waitForRelease = true; - } - for (;;) { - OLED::setCursor(0, 0); - OLED::clearScreen(); - OLED::setFont(0); - buttons = getButtonState(); - if (buttons) { - if (waitForRelease) { - buttons = BUTTON_NONE; - } - lastChange = xTaskGetTickCount(); - } else { - waitForRelease = false; - } - switch (buttons) { - case BUTTON_NONE: - // stay - autoRepeatAcceleration = 0; - break; - case BUTTON_BOTH: - // exit - return; - break; - case BUTTON_B_LONG: - if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; - } else - systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; + uint32_t lastChange = xTaskGetTickCount(); + currentTempTargetDegC = 0; + uint32_t autoRepeatTimer = 0; + uint8_t autoRepeatAcceleration = 0; + bool waitForRelease = false; + ButtonState buttons = getButtonState(); + if (buttons != BUTTON_NONE) { + // Temp adjust entered by long-pressing F button. + waitForRelease = true; + } + for (;;) { + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); + buttons = getButtonState(); + if (buttons) { + if (waitForRelease) { + buttons = BUTTON_NONE; + } + lastChange = xTaskGetTickCount(); + } else { + waitForRelease = false; + } + switch (buttons) { + case BUTTON_NONE: + // stay + autoRepeatAcceleration = 0; + break; + case BUTTON_BOTH: + // exit + return; + break; + case BUTTON_B_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; + } else + systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; - autoRepeatTimer = xTaskGetTickCount(); - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_B_SHORT: - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; - } else - systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; - break; - case BUTTON_F_LONG: - if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; - } else - systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; - autoRepeatTimer = xTaskGetTickCount(); - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_F_SHORT: - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10 - } else - systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10 - break; - default: - break; - } - if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { - autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; - } - // constrain between 10-450 C - if (systemSettings.temperatureInF) { - if (systemSettings.SolderingTemp > 850) - systemSettings.SolderingTemp = 850; - if (systemSettings.SolderingTemp < 60) - systemSettings.SolderingTemp = 60; - } else { - if (systemSettings.SolderingTemp > 450) - systemSettings.SolderingTemp = 450; - if (systemSettings.SolderingTemp < 10) - systemSettings.SolderingTemp = 10; - } + autoRepeatTimer = xTaskGetTickCount(); + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_B_SHORT: + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; + } else + systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; + break; + case BUTTON_F_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; + } else + systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; + autoRepeatTimer = xTaskGetTickCount(); + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_F_SHORT: + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10 + } else + systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10 + break; + default: + break; + } + if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { + autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; + } + // constrain between 10-450 C + if (systemSettings.temperatureInF) { + if (systemSettings.SolderingTemp > 850) + systemSettings.SolderingTemp = 850; + if (systemSettings.SolderingTemp < 60) + systemSettings.SolderingTemp = 60; + } else { + if (systemSettings.SolderingTemp > 450) + systemSettings.SolderingTemp = 450; + if (systemSettings.SolderingTemp < 10) + systemSettings.SolderingTemp = 10; + } - if (xTaskGetTickCount() - lastChange > 2000) - return; // exit if user just doesn't press anything for a bit + if (xTaskGetTickCount() - lastChange > 2000) + return; // exit if user just doesn't press anything for a bit #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); - } else { - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); - } + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); + } else { + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); + } - OLED::print(SymbolSpace); - OLED::printNumber(systemSettings.SolderingTemp, 3); - if (systemSettings.temperatureInF) - OLED::drawSymbol(0); - else - { - OLED::drawSymbol(1); - } - OLED::print(SymbolSpace); + OLED::print(SymbolSpace); + OLED::printNumber(systemSettings.SolderingTemp, 3); + if (systemSettings.temperatureInF) + OLED::drawSymbol(0); + else { + OLED::drawSymbol(1); + } + OLED::print(SymbolSpace); #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); - } else { - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); - } - OLED::refresh(); - GUIDelay(); - } + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); + } else { + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); + } + OLED::refresh(); + GUIDelay(); + } } static bool shouldShutdown() { - if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0 - if (lastMovementTime) { - if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) { - return true; - } - } - if (lastHallEffectSleepStart) { - if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) { - return true; - } - } - } - return false; + if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0 + if (lastMovementTime) { + if (((TickType_t) (xTaskGetTickCount() - lastMovementTime)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) { + return true; + } + } + if (lastHallEffectSleepStart) { + if (((TickType_t) (xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) { + return true; + } + } + } + return false; } static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) { - // Drop to sleep temperature and display until movement or button press + // Drop to sleep temperature and display until movement or button press - for (;;) { - // user moved or pressed a button, go back to soldering - // If in the first two seconds we disable this to let accelerometer warm up + for (;;) { + // user moved or pressed a button, go back to soldering + // If in the first two seconds we disable this to let accelerometer warm up #ifdef POW_DC - if (checkVoltageForExit()) - return 1; // return non-zero on error + if (checkVoltageForExit()) + return 1; // return non-zero on error #endif - if (systemSettings.temperatureInF) { - currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp)); - } else { - currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp); - } - // draw the lcd - uint16_t tipTemp; - if (systemSettings.temperatureInF) - tipTemp = TipThermoModel::getTipInF(); - else { - tipTemp = TipThermoModel::getTipInC(); - } + if (systemSettings.temperatureInF) { + currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp)); + } else { + currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp); + } + // draw the lcd + uint16_t tipTemp; + if (systemSettings.temperatureInF) + tipTemp = TipThermoModel::getTipInF(); + else { + tipTemp = TipThermoModel::getTipInC(); + } - OLED::clearScreen(); - OLED::setCursor(0, 0); - if (systemSettings.detailedSoldering) { - OLED::setFont(1); - OLED::print(SleepingAdvancedString); - OLED::setCursor(0, 8); - OLED::print(SleepingTipAdvancedString); - OLED::printNumber(tipTemp, 3); - if (systemSettings.temperatureInF) - OLED::print(SymbolDegF); - else { - OLED::print(SymbolDegC); - } + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (systemSettings.detailedSoldering) { + OLED::setFont(1); + OLED::print(SleepingAdvancedString); + OLED::setCursor(0, 8); + OLED::print(SleepingTipAdvancedString); + OLED::printNumber(tipTemp, 3); + if (systemSettings.temperatureInF) + OLED::print(SymbolDegF); + else { + OLED::print(SymbolDegC); + } - OLED::print(SymbolSpace); - printVoltage(); - OLED::print(SymbolVolts); - } else { - OLED::setFont(0); - OLED::print(SleepingSimpleString); - OLED::printNumber(tipTemp, 3); - if (systemSettings.temperatureInF) - OLED::drawSymbol(0); - else { - OLED::drawSymbol(1); - } - } + OLED::print(SymbolSpace); + printVoltage(); + OLED::print(SymbolVolts); + } else { + OLED::setFont(0); + OLED::print(SleepingSimpleString); + OLED::printNumber(tipTemp, 3); + if (systemSettings.temperatureInF) + OLED::drawSymbol(0); + else { + OLED::drawSymbol(1); + } + } - OLED::refresh(); - GUIDelay(); - if (!shouldBeSleeping(autoStarted)) { - return 0; - } - if (shouldShutdown()) { - // shutdown - currentTempTargetDegC = 0; - return 1; // we want to exit soldering mode - } - } - return 0; + OLED::refresh(); + GUIDelay(); + if (!shouldBeSleeping(autoStarted)) { + return 0; + } + if (shouldShutdown()) { + // shutdown + currentTempTargetDegC = 0; + return 1; // we want to exit soldering mode + } + } + return 0; } static void display_countdown(int sleepThres) { - /* - * Print seconds or minutes (if > 99 seconds) until sleep - * mode is triggered. - */ - int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; - TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime; - if (downCount > (99 * TICKS_SECOND)) { - OLED::printNumber(downCount / 60000 + 1, 2); - OLED::print(SymbolMinutes); - } else { - OLED::printNumber(downCount / 1000 + 1, 2); - OLED::print(SymbolSeconds); - } + /* + * Print seconds or minutes (if > 99 seconds) until sleep + * mode is triggered. + */ + int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; + TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime; + if (downCount > (99 * TICKS_SECOND)) { + OLED::printNumber(downCount / 60000 + 1, 2); + OLED::print(SymbolMinutes); + } else { + OLED::printNumber(downCount / 1000 + 1, 2); + OLED::print(SymbolSeconds); + } } static uint32_t getSleepTimeout() { - if (systemSettings.sensitivity && systemSettings.SleepTime) { + if (systemSettings.sensitivity && systemSettings.SleepTime) { - uint32_t sleepThres = 0; - if (systemSettings.SleepTime < 6) - sleepThres = systemSettings.SleepTime * 10 * 1000; - else - sleepThres = (systemSettings.SleepTime - 5) * 60 * 1000; - return sleepThres; - } - return 0; + uint32_t sleepThres = 0; + if (systemSettings.SleepTime < 6) + sleepThres = systemSettings.SleepTime * 10 * 1000; + else + sleepThres = (systemSettings.SleepTime - 5) * 60 * 1000; + return sleepThres; + } + return 0; } static bool shouldBeSleeping(bool inAutoStart) { - // Return true if the iron should be in sleep mode - if (systemSettings.sensitivity && systemSettings.SleepTime) { - if (inAutoStart) { - // In auto start we are asleep until movement - if (lastMovementTime == 0 && lastButtonTime == 0) { - return true; - } - } - if (lastMovementTime > 0 || lastButtonTime > 0) { - if ((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout() && (xTaskGetTickCount() - lastButtonTime) > getSleepTimeout()) { - return true; - } - } - } + // Return true if the iron should be in sleep mode + if (systemSettings.sensitivity && systemSettings.SleepTime) { + if (inAutoStart) { + // In auto start we are asleep until movement + if (lastMovementTime == 0 && lastButtonTime == 0) { + return true; + } + } + if (lastMovementTime > 0 || lastButtonTime > 0) { + if (((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout()) && ((xTaskGetTickCount() - lastButtonTime) > getSleepTimeout())) { + return true; + } + } + } #ifdef HALL_SENSOR - // If the hall effect sensor is enabled in the build, check if its over - // threshold, and if so then we force sleep - if (lookupHallEffectThreshold()) { - int16_t hallEffectStrength = getRawHallEffect(); - if (hallEffectStrength < 0) - hallEffectStrength = -hallEffectStrength; - // Have absolute value of measure of magnetic field strength - if (hallEffectStrength > lookupHallEffectThreshold()) { - if (lastHallEffectSleepStart == 0) { - lastHallEffectSleepStart = xTaskGetTickCount(); - } - if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) { - return true; - } - } else { - lastHallEffectSleepStart = 0; - } - } + // If the hall effect sensor is enabled in the build, check if its over + // threshold, and if so then we force sleep + if (getHallSensorFitted() && lookupHallEffectThreshold()) { + int16_t hallEffectStrength = getRawHallEffect(); + if (hallEffectStrength < 0) + hallEffectStrength = -hallEffectStrength; + // Have absolute value of measure of magnetic field strength + if (hallEffectStrength > lookupHallEffectThreshold()) { + if (lastHallEffectSleepStart == 0) { + lastHallEffectSleepStart = xTaskGetTickCount(); + } + if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) { + return true; + } + } else { + lastHallEffectSleepStart = 0; + } + } #endif - return false; + return false; } static void gui_solderingMode(uint8_t jumpToSleep) { - /* - * * Soldering (gui_solderingMode) - * -> Main loop where we draw temp, and animations - * --> User presses buttons and they goto the temperature adjust screen - * ---> Display the current setpoint temperature - * ---> Use buttons to change forward and back on temperature - * ---> Both buttons or timeout for exiting - * --> Long hold front button to enter boost mode - * ---> Just temporarily sets the system into the alternate temperature for - * PID control - * --> Long hold back button to exit - * --> Double button to exit - * --> Long hold double button to toggle key lock - */ - bool boostModeOn = false; - bool buttonsLocked = false; + /* + * * Soldering (gui_solderingMode) + * -> Main loop where we draw temp, and animations + * --> User presses buttons and they goto the temperature adjust screen + * ---> Display the current setpoint temperature + * ---> Use buttons to change forward and back on temperature + * ---> Both buttons or timeout for exiting + * --> Long hold front button to enter boost mode + * ---> Just temporarily sets the system into the alternate temperature for + * PID control + * --> Long hold back button to exit + * --> Double button to exit + * --> Long hold double button to toggle key lock + */ + bool boostModeOn = false; + bool buttonsLocked = false; - if (jumpToSleep) { - if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) { - lastButtonTime = xTaskGetTickCount(); - return; // If the function returns non-0 then exit - } - } - for (;;) { - ButtonState buttons = getButtonState(); - if (buttonsLocked && (systemSettings.lockingMode != 0)) { // If buttons locked - switch (buttons) { - case BUTTON_NONE: - boostModeOn = false; - break; - case BUTTON_BOTH_LONG: - // Unlock buttons - buttonsLocked = false; - warnUser(UnlockingKeysString, 0, TICKS_SECOND); - break; - case BUTTON_F_LONG: - // if boost mode is enabled turn it on - if (systemSettings.BoostTemp && (systemSettings.lockingMode == 1)) { - boostModeOn = true; - } - break; - // fall through - case BUTTON_BOTH: - case BUTTON_B_LONG: - case BUTTON_F_SHORT: - case BUTTON_B_SHORT: - // Do nothing and display a lock warming - warnUser(WarningKeysLockedString, 0, TICKS_SECOND / 2); - break; - default: - break; - } - } else { // Button not locked - switch (buttons) { - case BUTTON_NONE: - // stay - boostModeOn = false; - break; - case BUTTON_BOTH: - // exit - return; - break; - case BUTTON_B_LONG: - return; // exit on back long hold - break; - case BUTTON_F_LONG: - // if boost mode is enabled turn it on - if (systemSettings.BoostTemp) - boostModeOn = true; - break; - case BUTTON_F_SHORT: - case BUTTON_B_SHORT: { - uint16_t oldTemp = systemSettings.SolderingTemp; - gui_solderingTempAdjust(); // goto adjust temp mode - if (oldTemp != systemSettings.SolderingTemp) { - saveSettings(); // only save on change - } - } break; - case BUTTON_BOTH_LONG: - if (systemSettings.lockingMode != 0) { - // Lock buttons - buttonsLocked = true; - warnUser(LockingKeysString, 0, TICKS_SECOND); - } - break; - default: - break; - } - } - // else we update the screen information - OLED::setCursor(0, 0); - OLED::clearScreen(); - OLED::setFont(0); - // Draw in the screen details - if (systemSettings.detailedSoldering) { - OLED::setFont(1); - OLED::print(SolderingAdvancedPowerPrompt); // Power: - OLED::printNumber(x10WattHistory.average() / 10, 2); - OLED::print(SymbolDot); - OLED::printNumber(x10WattHistory.average() % 10, 1); - OLED::print(SymbolWatts); + if (jumpToSleep) { + if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) { + lastButtonTime = xTaskGetTickCount(); + return; // If the function returns non-0 then exit + } + } + for (;;) { + ButtonState buttons = getButtonState(); + if (buttonsLocked && (systemSettings.lockingMode != 0)) { // If buttons locked + switch (buttons) { + case BUTTON_NONE: + boostModeOn = false; + break; + case BUTTON_BOTH_LONG: + // Unlock buttons + buttonsLocked = false; + warnUser(UnlockingKeysString, 0, TICKS_SECOND); + break; + case BUTTON_F_LONG: + // if boost mode is enabled turn it on + if (systemSettings.BoostTemp && (systemSettings.lockingMode == 1)) { + boostModeOn = true; + } + break; + // fall through + case BUTTON_BOTH: + case BUTTON_B_LONG: + case BUTTON_F_SHORT: + case BUTTON_B_SHORT: + // Do nothing and display a lock warming + warnUser(WarningKeysLockedString, 0, TICKS_SECOND / 2); + break; + default: + break; + } + } else { // Button not locked + switch (buttons) { + case BUTTON_NONE: + // stay + boostModeOn = false; + break; + case BUTTON_BOTH: + // exit + return; + break; + case BUTTON_B_LONG: + return; // exit on back long hold + break; + case BUTTON_F_LONG: + // if boost mode is enabled turn it on + if (systemSettings.BoostTemp) + boostModeOn = true; + break; + case BUTTON_F_SHORT: + case BUTTON_B_SHORT: { + uint16_t oldTemp = systemSettings.SolderingTemp; + gui_solderingTempAdjust(); // goto adjust temp mode + if (oldTemp != systemSettings.SolderingTemp) { + saveSettings(); // only save on change + } + } + break; + case BUTTON_BOTH_LONG: + if (systemSettings.lockingMode != 0) { + // Lock buttons + buttonsLocked = true; + warnUser(LockingKeysString, 0, TICKS_SECOND); + } + break; + default: + break; + } + } + // else we update the screen information + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); + // Draw in the screen details + if (systemSettings.detailedSoldering) { + OLED::setFont(1); + OLED::print(SolderingAdvancedPowerPrompt); // Power: + OLED::printNumber(x10WattHistory.average() / 10, 2); + OLED::print(SymbolDot); + OLED::printNumber(x10WattHistory.average() % 10, 1); + OLED::print(SymbolWatts); - if (systemSettings.sensitivity && systemSettings.SleepTime) { - OLED::print(SymbolSpace); - display_countdown(getSleepTimeout()); - } + if (systemSettings.sensitivity && systemSettings.SleepTime) { + OLED::print(SymbolSpace); + display_countdown(getSleepTimeout()); + } - OLED::setCursor(0, 8); - OLED::print(SleepingTipAdvancedString); - gui_drawTipTemp(true); - OLED::print(SymbolSpace); - printVoltage(); - OLED::print(SymbolVolts); - } else { - // We switch the layout direction depending on the orientation of the oled - if (OLED::getRotation()) { - // battery - gui_drawBatteryIcon(); - OLED::print(SymbolSpace); // Space out gap between battery <-> temp - gui_drawTipTemp(true); // Draw current tip temp + OLED::setCursor(0, 8); + OLED::print(SleepingTipAdvancedString); + gui_drawTipTemp(true); + OLED::print(SymbolSpace); + printVoltage(); + OLED::print(SymbolVolts); + } else { + // We switch the layout direction depending on the orientation of the oled + if (OLED::getRotation()) { + // battery + gui_drawBatteryIcon(); + OLED::print(SymbolSpace); // Space out gap between battery <-> temp + gui_drawTipTemp(true); // Draw current tip temp - // We draw boost arrow if boosting, or else gap temp <-> heat - // indicator - if (boostModeOn) - OLED::drawSymbol(2); - else - OLED::print(SymbolSpace); + // We draw boost arrow if boosting, or else gap temp <-> heat + // indicator + if (boostModeOn) + OLED::drawSymbol(2); + else + OLED::print(SymbolSpace); - // Draw heating/cooling symbols - OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); - } else { - // Draw heating/cooling symbols - OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); - // We draw boost arrow if boosting, or else gap temp <-> heat - // indicator - if (boostModeOn) - OLED::drawSymbol(2); - else - OLED::print(SymbolSpace); - gui_drawTipTemp(true); // Draw current tip temp + // Draw heating/cooling symbols + OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); + } else { + // Draw heating/cooling symbols + OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); + // We draw boost arrow if boosting, or else gap temp <-> heat + // indicator + if (boostModeOn) + OLED::drawSymbol(2); + else + OLED::print(SymbolSpace); + gui_drawTipTemp(true); // Draw current tip temp - OLED::print(SymbolSpace); // Space out gap between battery <-> temp + OLED::print(SymbolSpace); // Space out gap between battery <-> temp - gui_drawBatteryIcon(); - } - } - OLED::refresh(); + gui_drawBatteryIcon(); + } + } + OLED::refresh(); - // Update the setpoints for the temperature - if (boostModeOn) { - if (systemSettings.temperatureInF) - currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp); - else { - currentTempTargetDegC = (systemSettings.BoostTemp); - } - } else { - if (systemSettings.temperatureInF) - currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp); - else { - currentTempTargetDegC = (systemSettings.SolderingTemp); - } - } + // Update the setpoints for the temperature + if (boostModeOn) { + if (systemSettings.temperatureInF) + currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp); + else { + currentTempTargetDegC = (systemSettings.BoostTemp); + } + } else { + if (systemSettings.temperatureInF) + currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp); + else { + currentTempTargetDegC = (systemSettings.SolderingTemp); + } + } #ifdef POW_DC - // Undervoltage test - if (checkVoltageForExit()) { - lastButtonTime = xTaskGetTickCount(); - return; - } + // Undervoltage test + if (checkVoltageForExit()) { + lastButtonTime = xTaskGetTickCount(); + return; + } #endif - if (shouldBeSleeping()) { - if (gui_SolderingSleepingMode(false, false)) { - return; // If the function returns non-0 then exit - } - } - // slow down ui update rate - GUIDelay(); - } + if (shouldBeSleeping()) { + if (gui_SolderingSleepingMode(false, false)) { + return; // If the function returns non-0 then exit + } + } + // slow down ui update rate + GUIDelay(); + } } void showDebugMenu(void) { - uint8_t screen = 0; - ButtonState b; - OLED::setFont(1); // small font - for (;;) { - OLED::clearScreen(); // Ensure the buffer starts clean - OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) - OLED::print(SymbolVersionNumber); // Print version number - OLED::setCursor(0, 8); // second line - OLED::print(DebugMenu[screen]); - switch (screen) { - case 0: // Just prints date - break; - case 1: - // High water mark for GUI - OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5); - break; - case 2: - // High water mark for the Movement task - OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5); - break; - case 3: - // High water mark for the PID task - OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5); - break; - case 4: - // system up time stamp - OLED::printNumber(xTaskGetTickCount() / 100, 5); - break; - case 5: - // Movement time stamp - OLED::printNumber(lastMovementTime / 100, 5); - break; - case 6: - // Raw Tip - { OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6); } - break; - case 7: - // Temp in C - OLED::printNumber(TipThermoModel::getTipInC(), 5); - break; - case 8: - // Handle Temp - OLED::printNumber(getHandleTemperature(), 3); - break; - case 9: - // Voltage input - printVoltage(); - break; - case 10: - // Print PCB ID number - OLED::printNumber(DetectedAccelerometerVersion, 2); - break; - case 11: - // Power negotiation status - if (getIsPoweredByDCIN()) { - OLED::printNumber(0, 1); - } else { - // We are not powered via DC, so want to display the appropriate state for PD or QC - bool poweredbyPD = false; + uint8_t screen = 0; + ButtonState b; + OLED::setFont(1); // small font + for (;;) { + OLED::clearScreen(); // Ensure the buffer starts clean + OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) + OLED::print(SymbolVersionNumber); // Print version number + OLED::setCursor(0, 8); // second line + OLED::print(DebugMenu[screen]); + switch (screen) { + case 0: // Just prints date + break; + case 1: + // High water mark for GUI + OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5); + break; + case 2: + // High water mark for the Movement task + OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5); + break; + case 3: + // High water mark for the PID task + OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5); + break; + case 4: + // system up time stamp + OLED::printNumber(xTaskGetTickCount() / 100, 5); + break; + case 5: + // Movement time stamp + OLED::printNumber(lastMovementTime / 100, 5); + break; + case 6: + // Raw Tip + { + OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6); + } + break; + case 7: + // Temp in C + OLED::printNumber(TipThermoModel::getTipInC(), 5); + break; + case 8: + // Handle Temp + OLED::printNumber(getHandleTemperature(), 3); + break; + case 9: + // Voltage input + printVoltage(); + break; + case 10: + // Print PCB ID number + OLED::printNumber(DetectedAccelerometerVersion, 2); + break; + case 11: + // Power negotiation status + if (getIsPoweredByDCIN()) { + OLED::printNumber(0, 1); + } else { + // We are not powered via DC, so want to display the appropriate state for PD or QC + bool poweredbyPD = false; #ifdef POW_PD - if (usb_pd_detect()) { - // We are PD capable - if (PolicyEngine::pdHasNegotiated()) { - // We are powered via PD - poweredbyPD = true; - } - } + if (usb_pd_detect()) { + // We are PD capable + if (PolicyEngine::pdHasNegotiated()) { + // We are powered via PD + poweredbyPD = true; + } + } #endif - if (poweredbyPD) { - OLED::printNumber(2, 1); - } else { + if (poweredbyPD) { + OLED::printNumber(2, 1); + } else { - OLED::printNumber(1, 1); - } - } - break; - case 12: - // Max deg C limit - OLED::printNumber(TipThermoModel::getTipMaxInC(), 3); - break; - default: - break; - } + OLED::printNumber(1, 1); + } + } + break; + case 12: + // Max deg C limit + OLED::printNumber(TipThermoModel::getTipMaxInC(), 3); + break; + default: + break; + } - OLED::refresh(); - b = getButtonState(); - if (b == BUTTON_B_SHORT) - return; - else if (b == BUTTON_F_SHORT) { - screen++; - screen = screen % 13; - } - GUIDelay(); - } + OLED::refresh(); + b = getButtonState(); + if (b == BUTTON_B_SHORT) + return; + else if (b == BUTTON_F_SHORT) { + screen++; + screen = screen % 13; + } + GUIDelay(); + } } void showWarnings() { - // Display alert if settings were reset - if (settingsWereReset) { - if (SettingsResetMessage[0] == '\x01') { // `\x01` is used as newline. - // Empty first line means that this uses large font (for CJK). - warnUser(SettingsResetMessage + 1, 0, 10 * TICKS_SECOND); - } else { - warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND); - } - } + // Display alert if settings were reset + if (settingsWereReset) { + if (SettingsResetMessage[0] == '\x01') { // `\x01` is used as newline. + // Empty first line means that this uses large font (for CJK). + warnUser(SettingsResetMessage + 1, 0, 10 * TICKS_SECOND); + } else { + warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND); + } + } #ifndef NO_WARN_MISSING - // We also want to alert if accel or pd is not detected / not responding - // In this case though, we dont want to nag the user _too_ much - // So only show first 2 times - while (DetectedAccelerometerVersion == ACCELEROMETERS_SCANNING) { - osDelay(5); - } - // Display alert if accelerometer is not detected - if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER) { - if (systemSettings.accelMissingWarningCounter < 2) { - systemSettings.accelMissingWarningCounter++; - saveSettings(); - warnUser(NoAccelerometerMessage, 1, 10 * TICKS_SECOND); - } - } + // We also want to alert if accel or pd is not detected / not responding + // In this case though, we dont want to nag the user _too_ much + // So only show first 2 times + while (DetectedAccelerometerVersion == ACCELEROMETERS_SCANNING) { + osDelay(5); + } + // Display alert if accelerometer is not detected + if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER) { + if (systemSettings.accelMissingWarningCounter < 2) { + systemSettings.accelMissingWarningCounter++; + saveSettings(); + warnUser(NoAccelerometerMessage, 1, 10 * TICKS_SECOND); + } + } #ifdef POW_PD - // We expect pd to be present - if (!usb_pd_detect()) { - if (systemSettings.pdMissingWarningCounter < 2) { - systemSettings.pdMissingWarningCounter++; - saveSettings(); - warnUser(NoPowerDeliveryMessage, 1, 10 * TICKS_SECOND); - } - } + // We expect pd to be present + if (!usb_pd_detect()) { + if (systemSettings.pdMissingWarningCounter < 2) { + systemSettings.pdMissingWarningCounter++; + saveSettings(); + warnUser(NoPowerDeliveryMessage, 1, 10 * TICKS_SECOND); + } + } #endif #endif } @@ -758,183 +759,183 @@ void showWarnings() { uint8_t idleScreenBGF[sizeof(idleScreenBG)]; /* StartGUITask function */ void startGUITask(void const *argument __unused) { - OLED::initialize(); // start up the LCD + OLED::initialize(); // start up the LCD - uint8_t tempWarningState = 0; - bool buttonLockout = false; - bool tempOnDisplay = false; - bool tipDisconnectedDisplay = false; - { - // Generate the flipped screen into ram for later use - // flipped is generated by flipping each row - for (int row = 0; row < 2; row++) { - for (int x = 0; x < 84; x++) { - idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84) + (83 - x)]; - } - } - } - getTipRawTemp(1); // reset filter - OLED::setRotation(systemSettings.OrientationMode & 1); - uint32_t ticks = xTaskGetTickCount(); - ticks += 4000; // 4 seconds from now - while (xTaskGetTickCount() < ticks) { - if (showBootLogoIfavailable() == false) - ticks = xTaskGetTickCount(); - ButtonState buttons = getButtonState(); - if (buttons) - ticks = xTaskGetTickCount(); // make timeout now so we will exit - GUIDelay(); - } + uint8_t tempWarningState = 0; + bool buttonLockout = false; + bool tempOnDisplay = false; + bool tipDisconnectedDisplay = false; + { + // Generate the flipped screen into ram for later use + // flipped is generated by flipping each row + for (int row = 0; row < 2; row++) { + for (int x = 0; x < 84; x++) { + idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84) + (83 - x)]; + } + } + } + getTipRawTemp(1); // reset filter + OLED::setRotation(systemSettings.OrientationMode & 1); + uint32_t ticks = xTaskGetTickCount(); + ticks += 4000; // 4 seconds from now + while (xTaskGetTickCount() < ticks) { + if (showBootLogoIfavailable() == false) + ticks = xTaskGetTickCount(); + ButtonState buttons = getButtonState(); + if (buttons) + ticks = xTaskGetTickCount(); // make timeout now so we will exit + GUIDelay(); + } - showWarnings(); + showWarnings(); - if (systemSettings.autoStartMode) { - // jump directly to the autostart mode - gui_solderingMode(systemSettings.autoStartMode - 1); - buttonLockout = true; - } + if (systemSettings.autoStartMode) { + // jump directly to the autostart mode + gui_solderingMode(systemSettings.autoStartMode - 1); + buttonLockout = true; + } - for (;;) { - ButtonState buttons = getButtonState(); - if (buttons != BUTTON_NONE) { - OLED::setDisplayState(OLED::DisplayState::ON); - OLED::setFont(0); - } - if (tempWarningState == 2) - buttons = BUTTON_F_SHORT; - if (buttons != BUTTON_NONE && buttonLockout) - buttons = BUTTON_NONE; - else - buttonLockout = false; + for (;;) { + ButtonState buttons = getButtonState(); + if (buttons != BUTTON_NONE) { + OLED::setDisplayState(OLED::DisplayState::ON); + OLED::setFont(0); + } + if (tempWarningState == 2) + buttons = BUTTON_F_SHORT; + if (buttons != BUTTON_NONE && buttonLockout) + buttons = BUTTON_NONE; + else + buttonLockout = false; - switch (buttons) { - case BUTTON_NONE: - // Do nothing - break; - case BUTTON_BOTH: - // Not used yet - // In multi-language this might be used to reset language on a long hold - // or some such - break; + switch (buttons) { + case BUTTON_NONE: + // Do nothing + break; + case BUTTON_BOTH: + // Not used yet + // In multi-language this might be used to reset language on a long hold + // or some such + break; - case BUTTON_B_LONG: - // Show the version information - showDebugMenu(); - break; - case BUTTON_F_LONG: - gui_solderingTempAdjust(); - saveSettings(); - break; - case BUTTON_F_SHORT: - gui_solderingMode(0); // enter soldering mode - buttonLockout = true; - break; - case BUTTON_B_SHORT: - enterSettingsMenu(); // enter the settings menu - buttonLockout = true; - break; - default: - break; - } + case BUTTON_B_LONG: + // Show the version information + showDebugMenu(); + break; + case BUTTON_F_LONG: + gui_solderingTempAdjust(); + saveSettings(); + break; + case BUTTON_F_SHORT: + gui_solderingMode(0); // enter soldering mode + buttonLockout = true; + break; + case BUTTON_B_SHORT: + enterSettingsMenu(); // enter the settings menu + buttonLockout = true; + break; + default: + break; + } - currentTempTargetDegC = 0; // ensure tip is off - getInputVoltageX10(systemSettings.voltageDiv, 0); - uint32_t tipTemp = TipThermoModel::getTipInC(); + currentTempTargetDegC = 0; // ensure tip is off + getInputVoltageX10(systemSettings.voltageDiv, 0); + uint32_t tipTemp = TipThermoModel::getTipInC(); - // Preemptively turn the display on. Turn it off if and only if - // the tip temperature is below 50 degrees C *and* motion sleep - // detection is enabled *and* there has been no activity (movement or - // button presses) in a while. - // This is zero cost really as state is only changed on display updates - OLED::setDisplayState(OLED::DisplayState::ON); + // Preemptively turn the display on. Turn it off if and only if + // the tip temperature is below 50 degrees C *and* motion sleep + // detection is enabled *and* there has been no activity (movement or + // button presses) in a while. + // This is zero cost really as state is only changed on display updates + OLED::setDisplayState(OLED::DisplayState::ON); - if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { - OLED::setDisplayState(OLED::DisplayState::OFF); - } - uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; - // Clear the lcd buffer - OLED::clearScreen(); - OLED::setCursor(0, 0); - if (systemSettings.detailedIDLE) { - OLED::setFont(1); - if (tipTemp > tipDisconnectedThres) { - OLED::print(TipDisconnectedString); - } else { - OLED::print(IdleTipString); - gui_drawTipTemp(false); - OLED::print(IdleSetString); - OLED::printNumber(systemSettings.SolderingTemp, 3); - } - OLED::setCursor(0, 8); + if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { + OLED::setDisplayState(OLED::DisplayState::OFF); + } + uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; + // Clear the lcd buffer + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (systemSettings.detailedIDLE) { + OLED::setFont(1); + if (tipTemp > tipDisconnectedThres) { + OLED::print(TipDisconnectedString); + } else { + OLED::print(IdleTipString); + gui_drawTipTemp(false); + OLED::print(IdleSetString); + OLED::printNumber(systemSettings.SolderingTemp, 3); + } + OLED::setCursor(0, 8); - OLED::print(InputVoltageString); - printVoltage(); + OLED::print(InputVoltageString); + printVoltage(); - } else { - OLED::setFont(0); + } else { + OLED::setFont(0); #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - OLED::drawArea(12, 0, 84, 16, idleScreenBG); - OLED::setCursor(0, 0); - gui_drawBatteryIcon(); - } else { - OLED::drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up - // on right side of screen - OLED::setCursor(84, 0); - gui_drawBatteryIcon(); - } - tipDisconnectedDisplay = false; - if (tipTemp > 55) - tempOnDisplay = true; - else if (tipTemp < 45) - tempOnDisplay = false; - if (tipTemp > tipDisconnectedThres) { - tempOnDisplay = false; - tipDisconnectedDisplay = true; - } - if (tempOnDisplay || tipDisconnectedDisplay) { - // draw temp over the start soldering button - // Location changes on screen rotation + OLED::drawArea(12, 0, 84, 16, idleScreenBG); + OLED::setCursor(0, 0); + gui_drawBatteryIcon(); + } else { + OLED::drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up + // on right side of screen + OLED::setCursor(84, 0); + gui_drawBatteryIcon(); + } + tipDisconnectedDisplay = false; + if (tipTemp > 55) + tempOnDisplay = true; + else if (tipTemp < 45) + tempOnDisplay = false; + if (tipTemp > tipDisconnectedThres) { + tempOnDisplay = false; + tipDisconnectedDisplay = true; + } + if (tempOnDisplay || tipDisconnectedDisplay) { + // draw temp over the start soldering button + // Location changes on screen rotation #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - // in right handed mode we want to draw over the first part - OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp - OLED::setCursor(56, 0); + // in right handed mode we want to draw over the first part + OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp + OLED::setCursor(56, 0); - } else { - OLED::fillArea(0, 0, 41, 16, 0); // clear the area - OLED::setCursor(0, 0); - } - // If we have a tip connected draw the temp, if not we leave it blank - if (!tipDisconnectedDisplay) { - // draw in the temp - if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16))) - gui_drawTipTemp(false); // draw in the temp - } else { - // Draw in missing tip symbol + } else { + OLED::fillArea(0, 0, 41, 16, 0); // clear the area + OLED::setCursor(0, 0); + } + // If we have a tip connected draw the temp, if not we leave it blank + if (!tipDisconnectedDisplay) { + // draw in the temp + if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16))) + gui_drawTipTemp(false); // draw in the temp + } else { + // Draw in missing tip symbol #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - // in right handed mode we want to draw over the first part - OLED::drawArea(55, 0, 41, 16, disconnectedTipIcon); + // in right handed mode we want to draw over the first part + OLED::drawArea(55, 0, 41, 16, disconnectedTipIcon); - } else { - OLED::drawArea(0, 0, 41, 16, disconnectedTipIcon); - } - } - } - } + } else { + OLED::drawArea(0, 0, 41, 16, disconnectedTipIcon); + } + } + } + } - OLED::refresh(); - GUIDelay(); - } + OLED::refresh(); + GUIDelay(); + } } From 3e56826e04ed422e590c2d3dc8c53b3e579dff18 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 24 Feb 2021 20:30:36 +1100 Subject: [PATCH 12/40] Run formatter --- source/Core/BSP/Pine64/BSP.cpp | 165 +- source/Core/BSP/Pine64/Debug.cpp | 56 +- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 570 +++--- source/Core/Drivers/FUSB302/policy_engine.cpp | 972 +++++----- source/Core/Drivers/TipThermoModel.h | 2 +- source/Core/Inc/Settings.h | 10 +- source/Core/Inc/Translation.h | 2 +- source/Core/Src/Settings.cpp | 30 +- source/Core/Src/gui.cpp | 19 +- source/Core/Threads/GUIThread.cpp | 1577 ++++++++--------- 10 files changed, 1688 insertions(+), 1715 deletions(-) diff --git a/source/Core/BSP/Pine64/BSP.cpp b/source/Core/BSP/Pine64/BSP.cpp index 8bbcd495..e29abea2 100644 --- a/source/Core/BSP/Pine64/BSP.cpp +++ b/source/Core/BSP/Pine64/BSP.cpp @@ -9,123 +9,114 @@ #include "main.hpp" #include -const uint16_t powerPWM = 255; -const uint8_t holdoffTicks = 25; // delay of 7 ms -const uint8_t tempMeasureTicks = 25; +const uint16_t powerPWM = 255; +const uint8_t holdoffTicks = 25; // delay of 7 ms +const uint8_t tempMeasureTicks = 25; uint16_t totalPWM; // htim2.Init.Period, the full PWM cycle // 2 second filter (ADC is PID_TIM_HZ Hz) -history rawTempFilter = { { 0 }, 0, 0 }; -void resetWatchdog() { - fwdgt_counter_reload(); -} +history rawTempFilter = {{0}, 0, 0}; +void resetWatchdog() { fwdgt_counter_reload(); } uint16_t getTipInstantTemperature() { - volatile uint16_t sum = 0; // 12 bit readings * 8*2 -> 16 bits + volatile uint16_t sum = 0; // 12 bit readings * 8*2 -> 16 bits - for (int i = 0; i < 4; i++) { - sum += adc_inserted_data_read(ADC0, i); - sum += adc_inserted_data_read(ADC1, i); - } - return sum; // 8x over sample + for (int i = 0; i < 4; i++) { + sum += adc_inserted_data_read(ADC0, i); + sum += adc_inserted_data_read(ADC1, i); + } + return sum; // 8x over sample } uint16_t getTipRawTemp(uint8_t refresh) { - if (refresh) { - uint16_t lastSample = getTipInstantTemperature(); - rawTempFilter.update(lastSample); - return lastSample; - } else { - return rawTempFilter.average(); - } + if (refresh) { + uint16_t lastSample = getTipInstantTemperature(); + rawTempFilter.update(lastSample); + return lastSample; + } else { + return rawTempFilter.average(); + } } uint16_t getHandleTemperature() { #ifdef TEMP_TMP36 - // We return the current handle temperature in X10 C - // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for - // example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) = - // 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125 - // mV per count So we need to subtract an offset of 0.5V to center on 0C - // (4964.8 counts) - // - int32_t result = getADC(0); - result -= 4965; // remove 0.5V offset - // 10mV per C - // 99.29 counts per Deg C above 0C - result *= 100; - result /= 993; - return result; + // We return the current handle temperature in X10 C + // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for + // example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) = + // 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125 + // mV per count So we need to subtract an offset of 0.5V to center on 0C + // (4964.8 counts) + // + int32_t result = getADC(0); + result -= 4965; // remove 0.5V offset + // 10mV per C + // 99.29 counts per Deg C above 0C + result *= 100; + result /= 993; + return result; #else #error #endif } uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) { - static uint8_t preFillneeded = 10; - static uint32_t samples[BATTFILTERDEPTH]; - static uint8_t index = 0; - if (preFillneeded) { - for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) - samples[i] = getADC(1); - preFillneeded--; - } - if (sample) { - samples[index] = getADC(1); - index = (index + 1) % BATTFILTERDEPTH; - } - uint32_t sum = 0; + static uint8_t preFillneeded = 10; + static uint32_t samples[BATTFILTERDEPTH]; + static uint8_t index = 0; + if (preFillneeded) { + for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) + samples[i] = getADC(1); + preFillneeded--; + } + if (sample) { + samples[index] = getADC(1); + index = (index + 1) % BATTFILTERDEPTH; + } + uint32_t sum = 0; - for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) - sum += samples[i]; + for (uint8_t i = 0; i < BATTFILTERDEPTH; i++) + sum += samples[i]; - sum /= BATTFILTERDEPTH; - if (divisor == 0) { - divisor = 1; - } - return sum * 4 / divisor; + sum /= BATTFILTERDEPTH; + if (divisor == 0) { + divisor = 1; + } + return sum * 4 / divisor; } void unstick_I2C() { - /* configure SDA/SCL for GPIO */ - GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin; - gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); - for (int i = 0; i < 8; i++) { - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - GPIO_BOP(GPIOB) |= SCL_Pin; - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - asm("nop"); - GPIO_BOP(GPIOB) &= SCL_Pin; - } - /* connect PB6 to I2C0_SCL */ - /* connect PB7 to I2C0_SDA */ - gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); + /* configure SDA/SCL for GPIO */ + GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin; + gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); + for (int i = 0; i < 8; i++) { + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + GPIO_BOP(GPIOB) |= SCL_Pin; + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + GPIO_BOP(GPIOB) &= SCL_Pin; + } + /* connect PB6 to I2C0_SCL */ + /* connect PB7 to I2C0_SDA */ + gpio_init(SDA_GPIO_Port, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); } -uint8_t getButtonA() { - return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; -} -uint8_t getButtonB() { - return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; -} +uint8_t getButtonA() { return (gpio_input_bit_get(KEY_A_GPIO_Port, KEY_A_Pin) == SET) ? 1 : 0; } +uint8_t getButtonB() { return (gpio_input_bit_get(KEY_B_GPIO_Port, KEY_B_Pin) == SET) ? 1 : 0; } void reboot() { - // Spin for watchdog - for (;;) { - } + // Spin for watchdog + for (;;) {} } -void delay_ms(uint16_t count) { - delay_1ms(count); -} +void delay_ms(uint16_t count) { delay_1ms(count); } uint32_t __get_IPSR(void) { - return 0; // To shut-up CMSIS + return 0; // To shut-up CMSIS } diff --git a/source/Core/BSP/Pine64/Debug.cpp b/source/Core/BSP/Pine64/Debug.cpp index 354985fb..de40fe7d 100644 --- a/source/Core/BSP/Pine64/Debug.cpp +++ b/source/Core/BSP/Pine64/Debug.cpp @@ -9,39 +9,39 @@ extern "C" { #include "gd32vf103_usart.h" } -char uartOutputBuffer[uartOutputBufferLength]; -volatile uint32_t currentOutputPos = 0xFF; -volatile uint32_t outputLength = 0; +char uartOutputBuffer[uartOutputBufferLength]; +volatile uint32_t currentOutputPos = 0xFF; +volatile uint32_t outputLength = 0; extern volatile uint8_t pendingPWM; -void log_system_state(int32_t PWMWattsx10) { - if (currentOutputPos == 0xFF) { +void log_system_state(int32_t PWMWattsx10) { + if (currentOutputPos == 0xFF) { - // Want to print a CSV log out the uart - // Tip_Temp_C,Handle_Temp_C,Output_Power_Wattx10,PWM,Tip_Raw\r\n - // 3+1+3+1+3+1+3+1+5+2 = 23, so sizing at 32 for now + // Want to print a CSV log out the uart + // Tip_Temp_C,Handle_Temp_C,Output_Power_Wattx10,PWM,Tip_Raw\r\n + // 3+1+3+1+3+1+3+1+5+2 = 23, so sizing at 32 for now - outputLength = snprintf(uartOutputBuffer, uartOutputBufferLength, "%lu,%u,%li,%u,%lu\r\n", // - TipThermoModel::getTipInC(false), // Tip temp in C - getHandleTemperature(), // Handle temp in C X10 - PWMWattsx10, // Output Wattage - pendingPWM, // PWM - TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true) // Tip temp in uV - ); + outputLength = snprintf(uartOutputBuffer, uartOutputBufferLength, "%lu,%u,%li,%u,%lu\r\n", // + TipThermoModel::getTipInC(false), // Tip temp in C + getHandleTemperature(), // Handle temp in C X10 + PWMWattsx10, // Output Wattage + pendingPWM, // PWM + TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true) // Tip temp in uV + ); - // Now print this out the uart via IRQ (DMA cant be used as oled has it) - currentOutputPos = 0; - /* enable USART1 Transmit Buffer Empty interrupt */ - usart_interrupt_enable(UART_PERIF, USART_INT_TBE); - } + // Now print this out the uart via IRQ (DMA cant be used as oled has it) + currentOutputPos = 0; + /* enable USART1 Transmit Buffer Empty interrupt */ + usart_interrupt_enable(UART_PERIF, USART_INT_TBE); + } } void USART1_IRQHandler(void) { - if (RESET != usart_interrupt_flag_get(UART_PERIF, USART_INT_FLAG_TBE)) { - /* write one byte to the transmit data register */ - usart_data_transmit(UART_PERIF, uartOutputBuffer[currentOutputPos++]); - if (currentOutputPos >= outputLength) { - currentOutputPos = 0xFF; // Mark done - usart_interrupt_disable(UART_PERIF, USART_INT_TBE); - } - } + if (RESET != usart_interrupt_flag_get(UART_PERIF, USART_INT_FLAG_TBE)) { + /* write one byte to the transmit data register */ + usart_data_transmit(UART_PERIF, uartOutputBuffer[currentOutputPos++]); + if (currentOutputPos >= outputLength) { + currentOutputPos = 0xFF; // Mark done + usart_interrupt_disable(UART_PERIF, USART_INT_TBE); + } + } } diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index 2f061b98..aebcbbd1 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -12,349 +12,337 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore = nullptr; StaticSemaphore_t FRToSI2C::xSemaphoreBuffer; #define I2C_TIME_OUT (uint16_t)(12000) void FRToSI2C::CpltCallback() { - // TODO + // TODO } -bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { - return Mem_Write(address, reg, &data, 1); -} +bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { return Mem_Write(address, reg, &data, 1); } uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) { - uint8_t temp = 0; - Mem_Read(add, reg, &temp, 1); - return temp; + uint8_t temp = 0; + Mem_Read(add, reg, &temp, 1); + return temp; } enum i2c_step { -//Write+read steps - Write_start, //Sending start on bus - Write_device_address, //start sent, send device address - Write_device_memory_address, //device address sent, write the memory location - Write_device_data_start, // Write all of the remaining data using DMA - Write_device_data_finish, // Write all of the remaining data using DMA + // Write+read steps + Write_start, // Sending start on bus + Write_device_address, // start sent, send device address + Write_device_memory_address, // device address sent, write the memory location + Write_device_data_start, // Write all of the remaining data using DMA + Write_device_data_finish, // Write all of the remaining data using DMA - Read_start, //second read - Read_device_address, // Send device address again for the read - Read_device_data_start, //read device data via DMA - Read_device_data_finish, //read device data via DMA - Send_stop, // send the stop at the end of the transaction - Wait_stop, // Wait for stop to send and we are done - Done, //Finished - Error_occured, //Error occured on the bus + Read_start, // second read + Read_device_address, // Send device address again for the read + Read_device_data_start, // read device data via DMA + Read_device_data_finish, // read device data via DMA + Send_stop, // send the stop at the end of the transaction + Wait_stop, // Wait for stop to send and we are done + Done, // Finished + Error_occured, // Error occured on the bus }; struct i2c_state { - i2c_step currentStep; - bool isMemoryWrite; - bool wakePart; - uint8_t deviceAddress; - uint8_t memoryAddress; - uint8_t * buffer; - uint16_t numberOfBytes; - dma_parameter_struct dma_init_struct; - + i2c_step currentStep; + bool isMemoryWrite; + bool wakePart; + uint8_t deviceAddress; + uint8_t memoryAddress; + uint8_t * buffer; + uint16_t numberOfBytes; + dma_parameter_struct dma_init_struct; }; volatile i2c_state currentState; void perform_i2c_step() { - //Performs next step of the i2c state machine - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - //Arb error - we lost the bus / nacked - currentState.currentStep = Error_occured; - } else if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_BERR); - // Bus Error - currentState.currentStep = Error_occured; - } else if (i2c_flag_get(I2C0, I2C_FLAG_LOSTARB)) { - i2c_flag_clear(I2C0, I2C_FLAG_LOSTARB); - // Bus Error - currentState.currentStep = Error_occured; - } else if (i2c_flag_get(I2C0, I2C_FLAG_PECERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_PECERR); - // Bus Error - currentState.currentStep = Error_occured; - } - switch (currentState.currentStep) { - case Error_occured: - i2c_stop_on_bus(I2C0); - break; - case Write_start: + // Performs next step of the i2c state machine + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); + // Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_BERR); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_LOSTARB)) { + i2c_flag_clear(I2C0, I2C_FLAG_LOSTARB); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_PECERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_PECERR); + // Bus Error + currentState.currentStep = Error_occured; + } + switch (currentState.currentStep) { + case Error_occured: + i2c_stop_on_bus(I2C0); + break; + case Write_start: - /* enable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_ENABLE); - /* i2c master sends start signal only when the bus is idle */ - if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { - /* send the start signal */ - i2c_start_on_bus(I2C0); - currentState.currentStep = Write_device_address; - } - break; + /* enable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_ENABLE); + /* i2c master sends start signal only when the bus is idle */ + if (!i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) { + /* send the start signal */ + i2c_start_on_bus(I2C0); + currentState.currentStep = Write_device_address; + } + break; - case Write_device_address: - /* i2c master sends START signal successfully */ - if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - i2c_master_addressing(I2C0, currentState.deviceAddress, I2C_TRANSMITTER); - currentState.currentStep = Write_device_memory_address; - } - break; - case Write_device_memory_address: - //Send the device memory location + case Write_device_address: + /* i2c master sends START signal successfully */ + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + i2c_master_addressing(I2C0, currentState.deviceAddress, I2C_TRANSMITTER); + currentState.currentStep = Write_device_memory_address; + } + break; + case Write_device_memory_address: + // Send the device memory location - if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { // addr sent + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_BERR); - // Bus Error - currentState.currentStep = Error_occured; - } else if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - i2c_flag_clear(I2C0, I2C_FLAG_AERR); - //Arb error - we lost the bus / nacked - currentState.currentStep = Error_occured; - } else if (currentState.wakePart) { - //We are stopping here - currentState.currentStep = Send_stop; - } else if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { - // Write out the 8 byte address - i2c_data_transmit(I2C0, currentState.memoryAddress); + if (i2c_flag_get(I2C0, I2C_FLAG_BERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_BERR); + // Bus Error + currentState.currentStep = Error_occured; + } else if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + i2c_flag_clear(I2C0, I2C_FLAG_AERR); + // Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } else if (currentState.wakePart) { + // We are stopping here + currentState.currentStep = Send_stop; + } else if (i2c_flag_get(I2C0, I2C_FLAG_TBE)) { + // Write out the 8 byte address + i2c_data_transmit(I2C0, currentState.memoryAddress); - if (currentState.isMemoryWrite) { - currentState.currentStep = Write_device_data_start; - } else { - currentState.currentStep = Read_start; - } - } - } + if (currentState.isMemoryWrite) { + currentState.currentStep = Write_device_data_start; + } else { + currentState.currentStep = Read_start; + } + } + } - break; - case Write_device_data_start: + break; + case Write_device_data_start: - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH5); - currentState.currentStep = Write_device_data_finish; - } - break; + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH5); + currentState.currentStep = Write_device_data_finish; + } + break; - case Write_device_data_finish: //Wait for complete then goto stop - /* wait until BTC bit is set */ - if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - currentState.currentStep = Send_stop; - } - } - break; - case Read_start: - /* wait until BTC bit is set */ - if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { - i2c_start_on_bus(I2C0); - currentState.currentStep = Read_device_address; - } - break; - case Read_device_address: - if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - i2c_master_addressing(I2C0, currentState.deviceAddress, I2C_RECEIVER); - currentState.currentStep = Read_device_data_start; - } - break; - case Read_device_data_start: - if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { //addr sent - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { - //Arb error - we lost the bus / nacked - currentState.currentStep = Error_occured; - } - /* one byte master reception procedure (polling) */ - if (currentState.numberOfBytes == 0) { - currentState.currentStep = Send_stop; - } else if (currentState.numberOfBytes == 1) { - /* disable acknowledge */ - i2c_ack_config(I2C0, I2C_ACK_DISABLE); - /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register - * (I2C_STAT0 has already been read) */ - i2c_flag_get(I2C0, I2C_FLAG_ADDSEND); //sat0 - i2c_flag_get(I2C0, I2C_FLAG_I2CBSY); //sat1 - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - /* wait for the byte to be received */ - while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) - ; - /* read the byte received from the EEPROM */ - *currentState.buffer = i2c_data_receive(I2C0); - currentState.currentStep = Wait_stop; - } else { /* more than one byte master reception procedure (DMA) */ - /* enable I2C0 DMA */ - i2c_dma_enable(I2C0, I2C_DMA_ON); - /* enable DMA0 channel5 */ - dma_channel_enable(DMA0, DMA_CH6); - currentState.currentStep = Read_device_data_finish; - } - } - break; - case Read_device_data_finish: //Wait for complete then goto stop - /* wait until BTC bit is set */ - if (dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) { - currentState.currentStep = Send_stop; - } + case Write_device_data_finish: // Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH5, DMA_FLAG_FTF)) { + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + currentState.currentStep = Send_stop; + } + } + break; + case Read_start: + /* wait until BTC bit is set */ + if (i2c_flag_get(I2C0, I2C_FLAG_BTC)) { + i2c_start_on_bus(I2C0); + currentState.currentStep = Read_device_address; + } + break; + case Read_device_address: + if (i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) { + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + i2c_master_addressing(I2C0, currentState.deviceAddress, I2C_RECEIVER); + currentState.currentStep = Read_device_data_start; + } + break; + case Read_device_data_start: + if (i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) { // addr sent + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + if (i2c_flag_get(I2C0, I2C_FLAG_AERR)) { + // Arb error - we lost the bus / nacked + currentState.currentStep = Error_occured; + } + /* one byte master reception procedure (polling) */ + if (currentState.numberOfBytes == 0) { + currentState.currentStep = Send_stop; + } else if (currentState.numberOfBytes == 1) { + /* disable acknowledge */ + i2c_ack_config(I2C0, I2C_ACK_DISABLE); + /* clear ADDSEND register by reading I2C_STAT0 then I2C_STAT1 register + * (I2C_STAT0 has already been read) */ + i2c_flag_get(I2C0, I2C_FLAG_ADDSEND); // sat0 + i2c_flag_get(I2C0, I2C_FLAG_I2CBSY); // sat1 + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + /* wait for the byte to be received */ + while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) + ; + /* read the byte received from the EEPROM */ + *currentState.buffer = i2c_data_receive(I2C0); + currentState.currentStep = Wait_stop; + } else { /* more than one byte master reception procedure (DMA) */ + /* enable I2C0 DMA */ + i2c_dma_enable(I2C0, I2C_DMA_ON); + /* enable DMA0 channel5 */ + dma_channel_enable(DMA0, DMA_CH6); + currentState.currentStep = Read_device_data_finish; + } + } + break; + case Read_device_data_finish: // Wait for complete then goto stop + /* wait until BTC bit is set */ + if (dma_flag_get(DMA0, DMA_CH6, DMA_FLAG_FTF)) { + currentState.currentStep = Send_stop; + } - break; - case Send_stop: - /* send a stop condition to I2C bus*/ - i2c_stop_on_bus(I2C0); - currentState.currentStep = Wait_stop; - break; - case Wait_stop: - /* i2c master sends STOP signal successfully */ - if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { - currentState.currentStep = Done; - } - break; - default: - //If we get here something is amiss - return; - } + break; + case Send_stop: + /* send a stop condition to I2C bus*/ + i2c_stop_on_bus(I2C0); + currentState.currentStep = Wait_stop; + break; + case Wait_stop: + /* i2c master sends STOP signal successfully */ + if ((I2C_CTL0(I2C0) & 0x0200) != 0x0200) { + currentState.currentStep = Done; + } + break; + default: + // If we get here something is amiss + return; + } } bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8_t *p_buffer, uint16_t number_of_byte, bool isWrite, bool isWakeOnly) { - { - //TODO is this required - /* disable I2C0 */ - i2c_disable(I2C0); - /* enable I2C0 */ - i2c_enable(I2C0); - } - i2c_interrupt_disable(I2C0, I2C_INT_ERR); - i2c_interrupt_disable(I2C0, I2C_INT_BUF); - i2c_interrupt_disable(I2C0, I2C_INT_EV); + { + // TODO is this required + /* disable I2C0 */ + i2c_disable(I2C0); + /* enable I2C0 */ + i2c_enable(I2C0); + } + i2c_interrupt_disable(I2C0, I2C_INT_ERR); + i2c_interrupt_disable(I2C0, I2C_INT_BUF); + i2c_interrupt_disable(I2C0, I2C_INT_EV); - currentState.isMemoryWrite = isWrite; - currentState.wakePart = isWakeOnly; - currentState.deviceAddress = DevAddress; - currentState.memoryAddress = memory_address; - currentState.numberOfBytes = number_of_byte; - currentState.buffer = p_buffer; - if (!isWakeOnly) { - //Setup DMA - currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; - currentState.dma_init_struct.memory_addr = (uint32_t) p_buffer; - currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; - currentState.dma_init_struct.number = number_of_byte; - currentState.dma_init_struct.periph_addr = (uint32_t) &I2C_DATA(I2C0); - currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; - currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; - currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; - if (currentState.isMemoryWrite) { - dma_deinit(DMA0, DMA_CH5); - currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; - dma_init(DMA0, DMA_CH5, (dma_parameter_struct*) ¤tState.dma_init_struct); - } else { - dma_deinit(DMA0, DMA_CH6); - currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; - dma_init(DMA0, DMA_CH6, (dma_parameter_struct*) ¤tState.dma_init_struct); - } + currentState.isMemoryWrite = isWrite; + currentState.wakePart = isWakeOnly; + currentState.deviceAddress = DevAddress; + currentState.memoryAddress = memory_address; + currentState.numberOfBytes = number_of_byte; + currentState.buffer = p_buffer; + if (!isWakeOnly) { + // Setup DMA + currentState.dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; + currentState.dma_init_struct.memory_addr = (uint32_t)p_buffer; + currentState.dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; + currentState.dma_init_struct.number = number_of_byte; + currentState.dma_init_struct.periph_addr = (uint32_t)&I2C_DATA(I2C0); + currentState.dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; + currentState.dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; + currentState.dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; + if (currentState.isMemoryWrite) { + dma_deinit(DMA0, DMA_CH5); + currentState.dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; + dma_init(DMA0, DMA_CH5, (dma_parameter_struct *)¤tState.dma_init_struct); + } else { + dma_deinit(DMA0, DMA_CH6); + currentState.dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; + dma_init(DMA0, DMA_CH6, (dma_parameter_struct *)¤tState.dma_init_struct); + } - if (!currentState.isMemoryWrite) { - i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); - } - } - //Clear flags - I2C_STAT0(I2C0) = 0; - I2C_STAT1(I2C0) = 0; - i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); + if (!currentState.isMemoryWrite) { + i2c_dma_last_transfer_config(I2C0, I2C_DMALST_ON); + } + } + // Clear flags + I2C_STAT0(I2C0) = 0; + I2C_STAT1(I2C0) = 0; + i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND); - currentState.currentStep = Write_start; //Always start in write mode - TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; - while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { - if (xTaskGetTickCount() > timeout) { - i2c_stop_on_bus(I2C0); - return false; - } - perform_i2c_step(); - } - return true; + currentState.currentStep = Write_start; // Always start in write mode + TickType_t timeout = xTaskGetTickCount() + TICKS_SECOND; + while ((currentState.currentStep != Done) && (currentState.currentStep != Error_occured)) { + if (xTaskGetTickCount() > timeout) { + i2c_stop_on_bus(I2C0); + return false; + } + perform_i2c_step(); + } + return true; } bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) { - if (!lock()) - return false; - bool res = perform_i2c_transaction(DevAddress, read_address, p_buffer, number_of_byte, false, false); - if (!res) { - I2C_Unstick(); - } - unlock(); - return res; + if (!lock()) + return false; + bool res = perform_i2c_transaction(DevAddress, read_address, p_buffer, number_of_byte, false, false); + if (!res) { + I2C_Unstick(); + } + unlock(); + return res; } bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) { - if (!lock()) - return false; - bool res = perform_i2c_transaction(DevAddress, MemAddress, p_buffer, number_of_byte, true, false); - if (!res) { - I2C_Unstick(); - } - unlock(); - return res; + if (!lock()) + return false; + bool res = perform_i2c_transaction(DevAddress, MemAddress, p_buffer, number_of_byte, true, false); + if (!res) { + I2C_Unstick(); + } + unlock(); + return res; } -bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { - return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); -} +bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); } bool FRToSI2C::probe(uint16_t DevAddress) { - uint8_t temp[1]; - return Mem_Read(DevAddress, 0x00, temp, sizeof(temp)); + uint8_t temp[1]; + return Mem_Read(DevAddress, 0x00, temp, sizeof(temp)); } -void FRToSI2C::I2C_Unstick() { - unstick_I2C(); -} +void FRToSI2C::I2C_Unstick() { unstick_I2C(); } bool FRToSI2C::lock() { - if (I2CSemaphore == nullptr) { - return false; - } - return xSemaphoreTake(I2CSemaphore, TICKS_SECOND) == pdTRUE; + if (I2CSemaphore == nullptr) { + return false; + } + return xSemaphoreTake(I2CSemaphore, TICKS_SECOND) == pdTRUE; } -void FRToSI2C::unlock() { - xSemaphoreGive(I2CSemaphore); -} +void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); } bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) { - for (int index = 0; index < registersLength; index++) { - if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) { - return false; - } - if (registers[index].pause_ms) { - delay_ms(registers[index].pause_ms); - } - } - return true; + for (int index = 0; index < registersLength; index++) { + if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) { + return false; + } + if (registers[index].pause_ms) { + delay_ms(registers[index].pause_ms); + } + } + return true; } bool FRToSI2C::wakePart(uint16_t DevAddress) { - // wakepart is a special case where only the device address is sent - if (!lock()) - return false; - bool res = perform_i2c_transaction(DevAddress, 0, NULL, 0, false, true); - if (!res) { - I2C_Unstick(); - } - unlock(); - return res; + // wakepart is a special case where only the device address is sent + if (!lock()) + return false; + bool res = perform_i2c_transaction(DevAddress, 0, NULL, 0, false, true); + if (!res) { + I2C_Unstick(); + } + unlock(); + return res; } -void I2C_EV_IRQ() { - -} +void I2C_EV_IRQ() {} void I2C_ER_IRQ() { -//Error callbacks - + // Error callbacks } diff --git a/source/Core/Drivers/FUSB302/policy_engine.cpp b/source/Core/Drivers/FUSB302/policy_engine.cpp index b8c83bd7..e8358f5b 100644 --- a/source/Core/Drivers/FUSB302/policy_engine.cpp +++ b/source/Core/Drivers/FUSB302/policy_engine.cpp @@ -21,617 +21,613 @@ #include "protocol_tx.h" #include #include -bool PolicyEngine::pdNegotiationComplete; -int PolicyEngine::current_voltage_mv; -int PolicyEngine::_requested_voltage; -bool PolicyEngine::_unconstrained_power; -union pd_msg PolicyEngine::currentMessage; -uint16_t PolicyEngine::hdr_template; -bool PolicyEngine::_explicit_contract; -int8_t PolicyEngine::_hard_reset_counter; -int8_t PolicyEngine::_old_tcc_match; -uint8_t PolicyEngine::_pps_index; -uint8_t PolicyEngine::_last_pps; -osThreadId PolicyEngine::TaskHandle = NULL; -uint32_t PolicyEngine::TaskBuffer[PolicyEngine::TaskStackSize]; -osStaticThreadDef_t PolicyEngine::TaskControlBlock; -union pd_msg PolicyEngine::tempMessage; -union pd_msg PolicyEngine::_last_dpm_request; +bool PolicyEngine::pdNegotiationComplete; +int PolicyEngine::current_voltage_mv; +int PolicyEngine::_requested_voltage; +bool PolicyEngine::_unconstrained_power; +union pd_msg PolicyEngine::currentMessage; +uint16_t PolicyEngine::hdr_template; +bool PolicyEngine::_explicit_contract; +int8_t PolicyEngine::_hard_reset_counter; +int8_t PolicyEngine::_old_tcc_match; +uint8_t PolicyEngine::_pps_index; +uint8_t PolicyEngine::_last_pps; +osThreadId PolicyEngine::TaskHandle = NULL; +uint32_t PolicyEngine::TaskBuffer[PolicyEngine::TaskStackSize]; +osStaticThreadDef_t PolicyEngine::TaskControlBlock; +union pd_msg PolicyEngine::tempMessage; +union pd_msg PolicyEngine::_last_dpm_request; PolicyEngine::policy_engine_state PolicyEngine::state = PESinkStartup; -StaticQueue_t PolicyEngine::xStaticQueue; -uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)]; -QueueHandle_t PolicyEngine::messagesWaiting = NULL; -EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL; -StaticEventGroup_t PolicyEngine::xCreatedEventGroup; -void PolicyEngine::init() { - messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue); - // Create static thread at PDB_PRIO_PE priority - osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, &TaskControlBlock); - TaskHandle = osThreadCreate(osThread(PolEng), NULL); - xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup); +StaticQueue_t PolicyEngine::xStaticQueue; +uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)]; +QueueHandle_t PolicyEngine::messagesWaiting = NULL; +EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL; +StaticEventGroup_t PolicyEngine::xCreatedEventGroup; +void PolicyEngine::init() { + messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue); + // Create static thread at PDB_PRIO_PE priority + osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, &TaskControlBlock); + TaskHandle = osThreadCreate(osThread(PolEng), NULL); + xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup); } void PolicyEngine::notify(uint32_t notification) { - if (xEventGroupHandle != NULL) { - xEventGroupSetBits(xEventGroupHandle, notification); - } + if (xEventGroupHandle != NULL) { + xEventGroupSetBits(xEventGroupHandle, notification); + } } void PolicyEngine::pe_task(const void *arg) { - (void) arg; - // Internal thread loop - hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK; - /* Initialize the old_tcc_match */ - _old_tcc_match = -1; - /* Initialize the pps_index */ - _pps_index = 8; - /* Initialize the last_pps */ - _last_pps = 8; + (void)arg; + // Internal thread loop + hdr_template = PD_DATAROLE_UFP | PD_POWERROLE_SINK; + /* Initialize the old_tcc_match */ + _old_tcc_match = -1; + /* Initialize the pps_index */ + _pps_index = 8; + /* Initialize the last_pps */ + _last_pps = 8; - for (;;) { - // Loop based on state - switch (state) { + for (;;) { + // Loop based on state + switch (state) { - case PESinkStartup: - state = pe_sink_startup(); - break; - case PESinkDiscovery: - state = pe_sink_discovery(); - break; - case PESinkWaitCap: - state = pe_sink_wait_cap(); - break; - case PESinkEvalCap: - state = pe_sink_eval_cap(); - break; - case PESinkSelectCap: - state = pe_sink_select_cap(); - break; - case PESinkTransitionSink: - state = pe_sink_transition_sink(); - break; - case PESinkReady: - state = pe_sink_ready(); - break; - case PESinkGetSourceCap: - state = pe_sink_get_source_cap(); - break; - case PESinkGiveSinkCap: - state = pe_sink_give_sink_cap(); - break; - case PESinkHardReset: - state = pe_sink_hard_reset(); - break; - case PESinkTransitionDefault: - state = pe_sink_transition_default(); - break; - case PESinkSoftReset: - state = pe_sink_soft_reset(); - break; - case PESinkSendSoftReset: - state = pe_sink_send_soft_reset(); - break; - case PESinkSendNotSupported: - state = pe_sink_send_not_supported(); - break; - case PESinkChunkReceived: - state = pe_sink_chunk_received(); - break; - case PESinkSourceUnresponsive: - state = pe_sink_source_unresponsive(); - break; - case PESinkNotSupportedReceived: - state = pe_sink_not_supported_received(); - break; - default: - state = PESinkStartup; - break; - } - } + case PESinkStartup: + state = pe_sink_startup(); + break; + case PESinkDiscovery: + state = pe_sink_discovery(); + break; + case PESinkWaitCap: + state = pe_sink_wait_cap(); + break; + case PESinkEvalCap: + state = pe_sink_eval_cap(); + break; + case PESinkSelectCap: + state = pe_sink_select_cap(); + break; + case PESinkTransitionSink: + state = pe_sink_transition_sink(); + break; + case PESinkReady: + state = pe_sink_ready(); + break; + case PESinkGetSourceCap: + state = pe_sink_get_source_cap(); + break; + case PESinkGiveSinkCap: + state = pe_sink_give_sink_cap(); + break; + case PESinkHardReset: + state = pe_sink_hard_reset(); + break; + case PESinkTransitionDefault: + state = pe_sink_transition_default(); + break; + case PESinkSoftReset: + state = pe_sink_soft_reset(); + break; + case PESinkSendSoftReset: + state = pe_sink_send_soft_reset(); + break; + case PESinkSendNotSupported: + state = pe_sink_send_not_supported(); + break; + case PESinkChunkReceived: + state = pe_sink_chunk_received(); + break; + case PESinkSourceUnresponsive: + state = pe_sink_source_unresponsive(); + break; + case PESinkNotSupportedReceived: + state = pe_sink_not_supported_received(); + break; + default: + state = PESinkStartup; + break; + } + } } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_startup() { - /* We don't have an explicit contract currently */ - _explicit_contract = false; + /* We don't have an explicit contract currently */ + _explicit_contract = false; - // If desired could send an alert that PD is starting + // If desired could send an alert that PD is starting - /* No need to reset the protocol layer here. There are two ways into this - * state: startup and exiting hard reset. On startup, the protocol layer - * is reset by the startup procedure. When exiting hard reset, the - * protocol layer is reset by the hard reset state machine. Since it's - * already done somewhere else, there's no need to do it again here. */ + /* No need to reset the protocol layer here. There are two ways into this + * state: startup and exiting hard reset. On startup, the protocol layer + * is reset by the startup procedure. When exiting hard reset, the + * protocol layer is reset by the hard reset state machine. Since it's + * already done somewhere else, there's no need to do it again here. */ - return PESinkDiscovery; + return PESinkDiscovery; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_discovery() { - /* Wait for VBUS. Since it's our only power source, we already know that - * we have it, so just move on. */ + /* Wait for VBUS. Since it's our only power source, we already know that + * we have it, so just move on. */ - return PESinkWaitCap; + return PESinkWaitCap; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() { - /* Fetch a message from the protocol layer */ - eventmask_t evt = 0; - if (readMessage()) { - evt = PDB_EVT_PE_MSG_RX_PEND; - } else { - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET, - // Wait for cap timeout - PD_T_TYPEC_SINK_WAIT_CAP); - } - /* If we timed out waiting for Source_Capabilities, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkWaitCap; - } - /* If we're too hot, we shouldn't negotiate power yet */ - if (evt & PDB_EVT_PE_I_OVRTEMP) { - return PESinkWaitCap; - } + /* Fetch a message from the protocol layer */ + eventmask_t evt = 0; + if (readMessage()) { + evt = PDB_EVT_PE_MSG_RX_PEND; + } else { + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET, + // Wait for cap timeout + PD_T_TYPEC_SINK_WAIT_CAP); + } + /* If we timed out waiting for Source_Capabilities, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkWaitCap; + } + /* If we're too hot, we shouldn't negotiate power yet */ + if (evt & PDB_EVT_PE_I_OVRTEMP) { + return PESinkWaitCap; + } - /* If we got a message */ - if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) { - /* Get the message */ - while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) { - /* If we got a Source_Capabilities message, read it. */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { - /* First, determine what PD revision we're using */ - if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) { - /* If the other end is using at least version 3.0, we'll - * use version 3.0. */ - if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) { - hdr_template |= PD_SPECREV_3_0; - /* Otherwise, use 2.0. Don't worry about the 1.0 case - * because we don't have hardware for PD 1.0 signaling. */ - } else { - hdr_template |= PD_SPECREV_2_0; - } - } - return PESinkEvalCap; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } - evt = 0; - } - return PESinkWaitCap; // wait for more messages? - } + /* If we got a message */ + if (evt & (PDB_EVT_PE_MSG_RX | PDB_EVT_PE_MSG_RX_PEND)) { + /* Get the message */ + while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) { + /* If we got a Source_Capabilities message, read it. */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { + /* First, determine what PD revision we're using */ + if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) { + /* If the other end is using at least version 3.0, we'll + * use version 3.0. */ + if ((tempMessage.hdr & PD_HDR_SPECREV) >= PD_SPECREV_3_0) { + hdr_template |= PD_SPECREV_3_0; + /* Otherwise, use 2.0. Don't worry about the 1.0 case + * because we don't have hardware for PD 1.0 signaling. */ + } else { + hdr_template |= PD_SPECREV_2_0; + } + } + return PESinkEvalCap; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } + evt = 0; + } + return PESinkWaitCap; // wait for more messages? + } - /* If we failed to get a message, send a hard reset */ - return PESinkHardReset; + /* If we failed to get a message, send a hard reset */ + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_eval_cap() { - /* If we have a Source_Capabilities message, remember the index of the - * first PPS APDO so we can check if the request is for a PPS APDO in - * PE_SNK_Select_Cap. */ - /* Start by assuming we won't find a PPS APDO (set the index greater - * than the maximum possible) */ - _pps_index = 8; - /* Search for the first PPS APDO */ - for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) { - if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) { - _pps_index = i + 1; - break; - } - } - /* New capabilities also means we can't be making a request from the - * same PPS APDO */ - _last_pps = 8; + /* If we have a Source_Capabilities message, remember the index of the + * first PPS APDO so we can check if the request is for a PPS APDO in + * PE_SNK_Select_Cap. */ + /* Start by assuming we won't find a PPS APDO (set the index greater + * than the maximum possible) */ + _pps_index = 8; + /* Search for the first PPS APDO */ + for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) { + if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) { + _pps_index = i + 1; + break; + } + } + /* New capabilities also means we can't be making a request from the + * same PPS APDO */ + _last_pps = 8; - /* Ask the DPM what to request */ - if (pdbs_dpm_evaluate_capability(&tempMessage, &_last_dpm_request)) { + /* Ask the DPM what to request */ + if (pdbs_dpm_evaluate_capability(&tempMessage, &_last_dpm_request)) { - return PESinkSelectCap; - } + return PESinkSelectCap; + } - return PESinkWaitCap; + return PESinkWaitCap; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() { - /* Transmit the request */ - waitForEvent(0xFFFF, 0); // clear pending - ProtocolTransmit::pushMessage(&_last_dpm_request); - // Send indication that there is a message pending - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET || evt == 0) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) { - return PESinkHardReset; - } + /* Transmit the request */ + waitForEvent(0xFFFF, 0); // clear pending + ProtocolTransmit::pushMessage(&_last_dpm_request); + // Send indication that there is a message pending + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET || evt == 0) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_ERR) == PDB_EVT_PE_TX_ERR) { + return PESinkHardReset; + } - /* Wait for a response */ - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If we didn't get a response before the timeout, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } + /* Wait for a response */ + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If we didn't get a response before the timeout, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } - /* Get the response message */ - if (messageWaiting()) { - readMessage(); - /* If the source accepted our request, wait for the new power */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* Get the response message */ + if (messageWaiting()) { + readMessage(); + /* If the source accepted our request, wait for the new power */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkTransitionSink; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSoftReset; - /* If the message was Wait or Reject */ - } else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) { - /* If we don't have an explicit contract, wait for capabilities */ - if (!_explicit_contract) { - return PESinkWaitCap; - /* If we do have an explicit contract, go to the ready state */ - } else { - return PESinkReady; - } - } else { - return PESinkSendSoftReset; - } - } - return PESinkHardReset; + return PESinkTransitionSink; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSoftReset; + /* If the message was Wait or Reject */ + } else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* If we don't have an explicit contract, wait for capabilities */ + if (!_explicit_contract) { + return PESinkWaitCap; + /* If we do have an explicit contract, go to the ready state */ + } else { + return PESinkReady; + } + } else { + return PESinkSendSoftReset; + } + } + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() { - /* Wait for the PS_RDY message */ - eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If no message was received, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } + /* Wait for the PS_RDY message */ + eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If no message was received, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } - /* If we received a message, read it */ - if (messageWaiting()) { - readMessage(); - /* If we got a PS_RDY, handle it */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) { - /* We just finished negotiating an explicit contract */ - _explicit_contract = true; + /* If we received a message, read it */ + if (messageWaiting()) { + readMessage(); + /* If we got a PS_RDY, handle it */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* We just finished negotiating an explicit contract */ + _explicit_contract = true; - /* Set the output appropriately */ - pdbs_dpm_transition_requested(); + /* Set the output appropriately */ + pdbs_dpm_transition_requested(); - return PESinkReady; - /* If there was a protocol error, send a hard reset */ - } else { - /* Turn off the power output before this hard reset to make sure we - * don't supply an incorrect voltage to the device we're powering. - */ - pdbs_dpm_transition_default(); + return PESinkReady; + /* If there was a protocol error, send a hard reset */ + } else { + /* Turn off the power output before this hard reset to make sure we + * don't supply an incorrect voltage to the device we're powering. + */ + pdbs_dpm_transition_default(); - return PESinkHardReset; - } - } + return PESinkHardReset; + } + } - return PESinkHardReset; + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() { - eventmask_t evt; + eventmask_t evt; - /* Wait for an event */ - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP); + /* Wait for an event */ + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } - /* If we overheated, send a hard reset */ - if (evt & PDB_EVT_PE_I_OVRTEMP) { - return PESinkHardReset; - } + /* If we overheated, send a hard reset */ + if (evt & PDB_EVT_PE_I_OVRTEMP) { + return PESinkHardReset; + } - /* If we received a message */ - if (evt & PDB_EVT_PE_MSG_RX) { - if (messageWaiting()) { - readMessage(); - /* Ignore vendor-defined messages */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) { + /* If we received a message */ + if (evt & PDB_EVT_PE_MSG_RX) { + if (messageWaiting()) { + readMessage(); + /* Ignore vendor-defined messages */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) { - return PESinkReady; - /* Ignore Ping messages */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkReady; + /* Ignore Ping messages */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkReady; - /* DR_Swap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkReady; + /* DR_Swap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* Get_Source_Cap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSendNotSupported; + /* Get_Source_Cap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* PR_Swap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSendNotSupported; + /* PR_Swap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* VCONN_Swap messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkSendNotSupported; + /* VCONN_Swap messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSendNotSupported; - /* Request messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) { + return PESinkSendNotSupported; + /* Request messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) { - return PESinkSendNotSupported; - /* Sink_Capabilities messages are not supported */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { + return PESinkSendNotSupported; + /* Sink_Capabilities messages are not supported */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { - return PESinkSendNotSupported; - /* Handle GotoMin messages */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) { - /* GiveBack is not supported */ - return PESinkSendNotSupported; + return PESinkSendNotSupported; + /* Handle GotoMin messages */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* GiveBack is not supported */ + return PESinkSendNotSupported; - /* Evaluate new Source_Capabilities */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { - /* Don't free the message: we need to keep the - * Source_Capabilities message so we can evaluate it. */ - return PESinkEvalCap; - /* Give sink capabilities when asked */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* Evaluate new Source_Capabilities */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) { + /* Don't free the message: we need to keep the + * Source_Capabilities message so we can evaluate it. */ + return PESinkEvalCap; + /* Give sink capabilities when asked */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkGiveSinkCap; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkGiveSinkCap; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSoftReset; - /* PD 3.0 messges */ - } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { - /* If the message is a multi-chunk extended message, let it - * time out. */ - if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) { + return PESinkSoftReset; + /* PD 3.0 messges */ + } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { + /* If the message is a multi-chunk extended message, let it + * time out. */ + if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) { - return PESinkChunkReceived; - /* Tell the DPM a message we sent got a response of - * Not_Supported. */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkChunkReceived; + /* Tell the DPM a message we sent got a response of + * Not_Supported. */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkNotSupportedReceived; - /* If we got an unknown message, send a soft reset */ - } else { + return PESinkNotSupportedReceived; + /* If we got an unknown message, send a soft reset */ + } else { - return PESinkSendSoftReset; - } - } else { - /* if we get an unknown message code, silently ignore it*/ - return PESinkReady; - } - } - } + return PESinkSendSoftReset; + } + } else { + /* if we get an unknown message code, silently ignore it*/ + return PESinkReady; + } + } + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() { - /* Get a message object */ - union pd_msg *get_source_cap = &tempMessage; - /* Make a Get_Source_Cap message */ - get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0); - /* Transmit the Get_Source_Cap */ - ProtocolTransmit::pushMessage(get_source_cap); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* Free the sent message */ - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* Get a message object */ + union pd_msg *get_source_cap = &tempMessage; + /* Make a Get_Source_Cap message */ + get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0); + /* Transmit the Get_Source_Cap */ + ProtocolTransmit::pushMessage(get_source_cap); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Free the sent message */ + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() { - /* Get a message object */ - union pd_msg *snk_cap = &tempMessage; - /* Get our capabilities from the DPM */ - pdbs_dpm_get_sink_capability(snk_cap); + /* Get a message object */ + union pd_msg *snk_cap = &tempMessage; + /* Get our capabilities from the DPM */ + pdbs_dpm_get_sink_capability(snk_cap); - /* Transmit our capabilities */ - ProtocolTransmit::pushMessage(snk_cap); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Transmit our capabilities */ + ProtocolTransmit::pushMessage(snk_cap); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* Free the Sink_Capabilities message */ + /* Free the Sink_Capabilities message */ - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_hard_reset() { - /* If we've already sent the maximum number of hard resets, assume the - * source is unresponsive. */ - if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) { - return PESinkSourceUnresponsive; - } - // So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU - // So therefore we went get anywhere :) - /* Increment HardResetCounter */ - _hard_reset_counter++; + /* If we've already sent the maximum number of hard resets, assume the + * source is unresponsive. */ + if (_hard_reset_counter > PD_N_HARD_RESET_COUNT) { + return PESinkSourceUnresponsive; + } + // So, we could send a hardreset here; however that will cause a power cycle on the PSU end.. Which will then reset this MCU + // So therefore we went get anywhere :) + /* Increment HardResetCounter */ + _hard_reset_counter++; - return PESinkTransitionDefault; + return PESinkTransitionDefault; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_default() { - _explicit_contract = false; + _explicit_contract = false; - /* Tell the DPM to transition to default power */ - pdbs_dpm_transition_default(); + /* Tell the DPM to transition to default power */ + pdbs_dpm_transition_default(); - /* There is no local hardware to reset. */ - /* Since we never change our data role from UFP, there is no reason to set - * it here. */ + /* There is no local hardware to reset. */ + /* Since we never change our data role from UFP, there is no reason to set + * it here. */ - return PESinkStartup; + return PESinkStartup; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() { - /* No need to explicitly reset the protocol layer here. It resets itself - * when a Soft_Reset message is received. */ + /* No need to explicitly reset the protocol layer here. It resets itself + * when a Soft_Reset message is received. */ - /* Get a message object */ - union pd_msg accept; - /* Make an Accept message */ - accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0); - /* Transmit the Accept */ - ProtocolTransmit::pushMessage(&accept); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* Free the sent message */ + /* Get a message object */ + union pd_msg accept; + /* Make an Accept message */ + accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0); + /* Transmit the Accept */ + ProtocolTransmit::pushMessage(&accept); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Free the sent message */ - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - return PESinkWaitCap; + return PESinkWaitCap; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() { - /* No need to explicitly reset the protocol layer here. It resets itself - * just before a Soft_Reset message is transmitted. */ + /* No need to explicitly reset the protocol layer here. It resets itself + * just before a Soft_Reset message is transmitted. */ - /* Get a message object */ - union pd_msg *softrst = &tempMessage; - /* Make a Soft_Reset message */ - softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0); - /* Transmit the soft reset */ - ProtocolTransmit::pushMessage(softrst); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a hard reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkHardReset; - } + /* Get a message object */ + union pd_msg *softrst = &tempMessage; + /* Make a Soft_Reset message */ + softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0); + /* Transmit the soft reset */ + ProtocolTransmit::pushMessage(softrst); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a hard reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkHardReset; + } - /* Wait for a response */ - evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If we didn't get a response before the timeout, send a hard reset */ - if (evt == 0) { - return PESinkHardReset; - } + /* Wait for a response */ + evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If we didn't get a response before the timeout, send a hard reset */ + if (evt == 0) { + return PESinkHardReset; + } - /* Get the response message */ - if (messageWaiting()) { - readMessage(); - /* If the source accepted our soft reset, wait for capabilities. */ - if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { + /* Get the response message */ + if (messageWaiting()) { + readMessage(); + /* If the source accepted our soft reset, wait for capabilities. */ + if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkWaitCap; - /* If the message was a Soft_Reset, do the soft reset procedure */ - } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { + return PESinkWaitCap; + /* If the message was a Soft_Reset, do the soft reset procedure */ + } else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) { - return PESinkSoftReset; - /* Otherwise, send a hard reset */ - } else { + return PESinkSoftReset; + /* Otherwise, send a hard reset */ + } else { - return PESinkHardReset; - } - } - return PESinkHardReset; + return PESinkHardReset; + } + } + return PESinkHardReset; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() { - /* Get a message object */ - union pd_msg *not_supported = &tempMessage; + /* Get a message object */ + union pd_msg *not_supported = &tempMessage; - if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_2_0) { - /* Make a Reject message */ - not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0); - } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { - /* Make a Not_Supported message */ - not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0); - } + if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_2_0) { + /* Make a Reject message */ + not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0); + } else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) { + /* Make a Not_Supported message */ + not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0); + } - /* Transmit the message */ - ProtocolTransmit::pushMessage(not_supported); - ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); - eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); + /* Transmit the message */ + ProtocolTransmit::pushMessage(not_supported); + ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX); + eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } - /* If the message transmission failed, send a soft reset */ - if ((evt & PDB_EVT_PE_TX_DONE) == 0) { - return PESinkSendSoftReset; - } + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } + /* If the message transmission failed, send a soft reset */ + if ((evt & PDB_EVT_PE_TX_DONE) == 0) { + return PESinkSendSoftReset; + } - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() { - /* Wait for tChunkingNotSupported */ - eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED); - /* If we got reset signaling, transition to default */ - if (evt & PDB_EVT_PE_RESET) { - return PESinkTransitionDefault; - } + /* Wait for tChunkingNotSupported */ + eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED); + /* If we got reset signaling, transition to default */ + if (evt & PDB_EVT_PE_RESET) { + return PESinkTransitionDefault; + } - return PESinkSendNotSupported; + return PESinkSendNotSupported; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_not_supported_received() { - /* Inform the Device Policy Manager that we received a Not_Supported - * message. */ + /* Inform the Device Policy Manager that we received a Not_Supported + * message. */ - return PESinkReady; + return PESinkReady; } PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() { - // Sit and chill, as PD is not working - osDelay(PD_T_PD_DEBOUNCE); + // Sit and chill, as PD is not working + osDelay(PD_T_PD_DEBOUNCE); - return PESinkSourceUnresponsive; + return PESinkSourceUnresponsive; } -uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) { - return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); -} +uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) { return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); } -bool PolicyEngine::isPD3_0() { - return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; -} +bool PolicyEngine::isPD3_0() { return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; } diff --git a/source/Core/Drivers/TipThermoModel.h b/source/Core/Drivers/TipThermoModel.h index 4af4ab3c..b595c736 100644 --- a/source/Core/Drivers/TipThermoModel.h +++ b/source/Core/Drivers/TipThermoModel.h @@ -21,7 +21,7 @@ public: static uint32_t convertTipRawADCToDegC(uint16_t rawADC); static uint32_t convertTipRawADCToDegF(uint16_t rawADC); // Returns the uV of the tip reading before the op-amp compensating for pullups - static uint32_t convertTipRawADCTouV(uint16_t rawADC,bool skipCalOffset=false); + static uint32_t convertTipRawADCTouV(uint16_t rawADC, bool skipCalOffset = false); static uint32_t convertCtoF(uint32_t degC); static uint32_t convertFtoC(uint32_t degF); diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index 95170db2..fecc42f4 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -32,11 +32,11 @@ typedef struct { // into soldering mode when power is applied uint8_t ShutdownTime; // Time until unit shuts down if left alone - uint8_t coolingTempBlink : 1; // Should the temperature blink on the cool - // down screen until its <50C - uint8_t detailedIDLE : 1; // Detailed idle screen - uint8_t detailedSoldering : 1; // Detailed soldering screens - uint8_t temperatureInF : 1; // Should the temp be in F or C (true is F) + uint8_t coolingTempBlink : 1; // Should the temperature blink on the cool + // down screen until its <50C + uint8_t detailedIDLE : 1; // Detailed idle screen + uint8_t detailedSoldering : 1; // Detailed soldering screens + uint8_t temperatureInF : 1; // Should the temp be in F or C (true is F) uint8_t descriptionScrollSpeed : 1; // Description scroll speed uint8_t lockingMode : 2; // Store the locking mode uint8_t KeepAwakePulse; // Keep Awake pulse power in 0.1 watts (10 = 1Watt) diff --git a/source/Core/Inc/Translation.h b/source/Core/Inc/Translation.h index 018303cc..53855f35 100644 --- a/source/Core/Inc/Translation.h +++ b/source/Core/Inc/Translation.h @@ -10,7 +10,7 @@ #include "stdint.h" extern const uint8_t USER_FONT_12[]; extern const uint8_t USER_FONT_6x8[]; -extern const bool HasFahrenheit; +extern const bool HasFahrenheit; extern const char *SettingsShortNames[29][2]; extern const char *SettingsDescriptions[29]; diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 9cdb44ce..acd17b41 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -53,21 +53,21 @@ void resetSettings() { systemSettings.SleepTemp = SLEEP_TEMP; // Temperature the iron sleeps at - default 150.0 C systemSettings.SleepTime = SLEEP_TIME; // How many seconds/minutes we wait until going // to sleep - default 1 min - systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C - systemSettings.minDCVoltageCells = CUT_OUT_SETTING; // default to no cut-off voltage - systemSettings.QCIdealVoltage = 0; // Default to 9V for QC3.0 Voltage - systemSettings.version = SETTINGSVERSION; // Store the version number to allow for easier upgrades - systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen - systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users) - systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic - systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity - systemSettings.voltageDiv = VOLTAGE_DIV; // Default divider from schematic - systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off - systemSettings.BoostTemp = BOOST_TEMP; // default to 400C - systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety - systemSettings.lockingMode = LOCKING_MODE; // Disable locking for safety - systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C - systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0 + systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C + systemSettings.minDCVoltageCells = CUT_OUT_SETTING; // default to no cut-off voltage + systemSettings.QCIdealVoltage = 0; // Default to 9V for QC3.0 Voltage + systemSettings.version = SETTINGSVERSION; // Store the version number to allow for easier upgrades + systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen + systemSettings.detailedIDLE = DETAILED_IDLE; // Detailed idle screen (off for first time users) + systemSettings.OrientationMode = ORIENTATION_MODE; // Default to automatic + systemSettings.sensitivity = SENSITIVITY; // Default high sensitivity + systemSettings.voltageDiv = VOLTAGE_DIV; // Default divider from schematic + systemSettings.ShutdownTime = SHUTDOWN_TIME; // How many minutes until the unit turns itself off + systemSettings.BoostTemp = BOOST_TEMP; // default to 400C + systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety + systemSettings.lockingMode = LOCKING_MODE; // Disable locking for safety + systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C + systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0 systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 9cecf546..762b9161 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -157,15 +157,16 @@ const menuitem solderingMenu[] = { {NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE }; const menuitem UIMenu[] = { -/* - // Language - * Scrolling Speed - * Temperature Unit - * Display orientation - * Cooldown blink - * Reverse Temp change buttons + - - */ - {(const char *)SettingsDescriptions[5], settings_setTempF, settings_displayTempF}, /* Temperature units, this has to be the first element in the array to work with the logic in settings_enterUIMenu() */ + /* + // Language + * Scrolling Speed + * Temperature Unit + * Display orientation + * Cooldown blink + * Reverse Temp change buttons + - + */ + {(const char *)SettingsDescriptions[5], settings_setTempF, + settings_displayTempF}, /* Temperature units, this has to be the first element in the array to work with the logic in settings_enterUIMenu() */ {(const char *)SettingsDescriptions[7], settings_setDisplayRotation, settings_displayDisplayRotation}, /*Display Rotation*/ {(const char *)SettingsDescriptions[10], settings_setCoolingBlinkEnabled, settings_displayCoolingBlinkEnabled}, /*Cooling blink warning*/ {(const char *)SettingsDescriptions[15], settings_setScrollSpeed, settings_displayScrollSpeed}, /*Scroll Speed for descriptions*/ diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 651e8395..1fbb14f8 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -26,732 +26,729 @@ extern "C" { #include "policy_engine.h" #endif // File local variables -extern uint32_t currentTempTargetDegC; +extern uint32_t currentTempTargetDegC; extern TickType_t lastMovementTime; extern osThreadId GUITaskHandle; extern osThreadId MOVTaskHandle; extern osThreadId PIDTaskHandle; -static bool shouldBeSleeping(bool inAutoStart = false); -static bool shouldShutdown(); -void showWarnings(); +static bool shouldBeSleeping(bool inAutoStart = false); +static bool shouldShutdown(); +void showWarnings(); #define MOVEMENT_INACTIVITY_TIME (60 * configTICK_RATE_HZ) #define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ) static TickType_t lastHallEffectSleepStart = 0; -static uint16_t min(uint16_t a, uint16_t b) { - if (a > b) - return b; - else - return a; +static uint16_t min(uint16_t a, uint16_t b) { + if (a > b) + return b; + else + return a; } void warnUser(const char *warning, const int font, const int timeout) { - OLED::setFont(font); - OLED::clearScreen(); - OLED::setCursor(0, 0); - OLED::print(warning); - OLED::refresh(); - waitForButtonPressOrTimeout(timeout); + OLED::setFont(font); + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print(warning); + OLED::refresh(); + waitForButtonPressOrTimeout(timeout); } void printVoltage() { - uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0); - OLED::printNumber(volt / 10, 2); - OLED::print(SymbolDot); - OLED::printNumber(volt % 10, 1); + uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0); + OLED::printNumber(volt / 10, 2); + OLED::print(SymbolDot); + OLED::printNumber(volt % 10, 1); } void GUIDelay() { - // Called in all UI looping tasks, - // This limits the re-draw rate to the LCD and also lets the DMA run - // As the gui task can very easily fill this bus with transactions, which will - // prevent the movement detection from running - osDelay(50); + // Called in all UI looping tasks, + // This limits the re-draw rate to the LCD and also lets the DMA run + // As the gui task can very easily fill this bus with transactions, which will + // prevent the movement detection from running + osDelay(50); } void gui_drawTipTemp(bool symbol) { - // Draw tip temp handling unit conversion & tolerance near setpoint - uint32_t Temp = 0; - if (systemSettings.temperatureInF) { - Temp = TipThermoModel::getTipInF(); - } else { - Temp = TipThermoModel::getTipInC(); - } + // Draw tip temp handling unit conversion & tolerance near setpoint + uint32_t Temp = 0; + if (systemSettings.temperatureInF) { + Temp = TipThermoModel::getTipInF(); + } else { + Temp = TipThermoModel::getTipInC(); + } - OLED::printNumber(Temp, 3); // Draw the tip temp out - if (symbol) { - if (OLED::getFont() == 0) { - // Big font, can draw nice symbols - if (systemSettings.temperatureInF) - OLED::drawSymbol(0); - else - OLED::drawSymbol(1); - } else { - // Otherwise fall back to chars - if (systemSettings.temperatureInF) - OLED::print(SymbolDegF); - else - OLED::print(SymbolDegC); - } - } + OLED::printNumber(Temp, 3); // Draw the tip temp out + if (symbol) { + if (OLED::getFont() == 0) { + // Big font, can draw nice symbols + if (systemSettings.temperatureInF) + OLED::drawSymbol(0); + else + OLED::drawSymbol(1); + } else { + // Otherwise fall back to chars + if (systemSettings.temperatureInF) + OLED::print(SymbolDegF); + else + OLED::print(SymbolDegC); + } + } } #ifdef POW_DC // returns true if undervoltage has occured static bool checkVoltageForExit() { - if (!getIsPoweredByDCIN()) { - return false; - } - uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0); + if (!getIsPoweredByDCIN()) { + return false; + } + uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0); - // Dont check for first 2 seconds while the ADC stabilizes and the DMA fills - // the buffer - if (xTaskGetTickCount() > (TICKS_SECOND * 2)) { - if ((v < lookupVoltageLevel())) { - currentTempTargetDegC = 0; - OLED::clearScreen(); - OLED::setCursor(0, 0); - if (systemSettings.detailedSoldering) { - OLED::setFont(1); - OLED::print(UndervoltageString); - OLED::setCursor(0, 8); - OLED::print(InputVoltageString); - printVoltage(); - OLED::print(SymbolVolts); - } else { - OLED::setFont(0); - OLED::print(UVLOWarningString); - } + // Dont check for first 2 seconds while the ADC stabilizes and the DMA fills + // the buffer + if (xTaskGetTickCount() > (TICKS_SECOND * 2)) { + if ((v < lookupVoltageLevel())) { + currentTempTargetDegC = 0; + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (systemSettings.detailedSoldering) { + OLED::setFont(1); + OLED::print(UndervoltageString); + OLED::setCursor(0, 8); + OLED::print(InputVoltageString); + printVoltage(); + OLED::print(SymbolVolts); + } else { + OLED::setFont(0); + OLED::print(UVLOWarningString); + } - OLED::refresh(); - GUIDelay(); - waitForButtonPress(); - return true; - } - } - return false; + OLED::refresh(); + GUIDelay(); + waitForButtonPress(); + return true; + } + } + return false; } #endif static void gui_drawBatteryIcon() { #if defined(POW_PD) || defined(POW_QC) - if (!getIsPoweredByDCIN()) { - // On TS80 we replace this symbol with the voltage we are operating on - // If <9V then show single digit, if not show dual small ones vertically stacked - uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); - if (V % 10 >= 5) - V = V / 10 + 1; // round up - else - V = V / 10; - if (V >= 10) { - int16_t xPos = OLED::getCursorX(); - OLED::setFont(1); - OLED::printNumber(V / 10, 1); - OLED::setCursor(xPos, 8); - OLED::printNumber(V % 10, 1); - OLED::setFont(0); - OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char - } else { - OLED::printNumber(V, 1); - } - return; - } + if (!getIsPoweredByDCIN()) { + // On TS80 we replace this symbol with the voltage we are operating on + // If <9V then show single digit, if not show dual small ones vertically stacked + uint8_t V = getInputVoltageX10(systemSettings.voltageDiv, 0); + if (V % 10 >= 5) + V = V / 10 + 1; // round up + else + V = V / 10; + if (V >= 10) { + int16_t xPos = OLED::getCursorX(); + OLED::setFont(1); + OLED::printNumber(V / 10, 1); + OLED::setCursor(xPos, 8); + OLED::printNumber(V % 10, 1); + OLED::setFont(0); + OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char + } else { + OLED::printNumber(V, 1); + } + return; + } #endif #ifdef POW_DC - if (systemSettings.minDCVoltageCells) { - // User is on a lithium battery - // we need to calculate which of the 10 levels they are on - uint8_t cellCount = systemSettings.minDCVoltageCells + 2; - uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount; - // Should give us approx cell voltage X10 - // Range is 42 -> 33 = 9 steps therefore we will use battery 0-9 - if (cellV < 33) - cellV = 33; - cellV -= 33; // Should leave us a number of 0-9 - if (cellV > 9) - cellV = 9; - OLED::drawBattery(cellV + 1); - } else { - OLED::drawSymbol(15); // Draw the DC Logo - } + if (systemSettings.minDCVoltageCells) { + // User is on a lithium battery + // we need to calculate which of the 10 levels they are on + uint8_t cellCount = systemSettings.minDCVoltageCells + 2; + uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount; + // Should give us approx cell voltage X10 + // Range is 42 -> 33 = 9 steps therefore we will use battery 0-9 + if (cellV < 33) + cellV = 33; + cellV -= 33; // Should leave us a number of 0-9 + if (cellV > 9) + cellV = 9; + OLED::drawBattery(cellV + 1); + } else { + OLED::drawSymbol(15); // Draw the DC Logo + } #endif } static void gui_solderingTempAdjust() { - uint32_t lastChange = xTaskGetTickCount(); - currentTempTargetDegC = 0; - uint32_t autoRepeatTimer = 0; - uint8_t autoRepeatAcceleration = 0; - bool waitForRelease = false; - ButtonState buttons = getButtonState(); - if (buttons != BUTTON_NONE) { - // Temp adjust entered by long-pressing F button. - waitForRelease = true; - } - for (;;) { - OLED::setCursor(0, 0); - OLED::clearScreen(); - OLED::setFont(0); - buttons = getButtonState(); - if (buttons) { - if (waitForRelease) { - buttons = BUTTON_NONE; - } - lastChange = xTaskGetTickCount(); - } else { - waitForRelease = false; - } - switch (buttons) { - case BUTTON_NONE: - // stay - autoRepeatAcceleration = 0; - break; - case BUTTON_BOTH: - // exit - return; - break; - case BUTTON_B_LONG: - if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; - } else - systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; + uint32_t lastChange = xTaskGetTickCount(); + currentTempTargetDegC = 0; + uint32_t autoRepeatTimer = 0; + uint8_t autoRepeatAcceleration = 0; + bool waitForRelease = false; + ButtonState buttons = getButtonState(); + if (buttons != BUTTON_NONE) { + // Temp adjust entered by long-pressing F button. + waitForRelease = true; + } + for (;;) { + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); + buttons = getButtonState(); + if (buttons) { + if (waitForRelease) { + buttons = BUTTON_NONE; + } + lastChange = xTaskGetTickCount(); + } else { + waitForRelease = false; + } + switch (buttons) { + case BUTTON_NONE: + // stay + autoRepeatAcceleration = 0; + break; + case BUTTON_BOTH: + // exit + return; + break; + case BUTTON_B_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; + } else + systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; - autoRepeatTimer = xTaskGetTickCount(); - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_B_SHORT: - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; - } else - systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; - break; - case BUTTON_F_LONG: - if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; - } else - systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; - autoRepeatTimer = xTaskGetTickCount(); - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_F_SHORT: - if (systemSettings.ReverseButtonTempChangeEnabled) { - systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10 - } else - systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10 - break; - default: - break; - } - if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { - autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; - } - // constrain between 10-450 C - if (systemSettings.temperatureInF) { - if (systemSettings.SolderingTemp > 850) - systemSettings.SolderingTemp = 850; - if (systemSettings.SolderingTemp < 60) - systemSettings.SolderingTemp = 60; - } else { - if (systemSettings.SolderingTemp > 450) - systemSettings.SolderingTemp = 450; - if (systemSettings.SolderingTemp < 10) - systemSettings.SolderingTemp = 10; - } + autoRepeatTimer = xTaskGetTickCount(); + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_B_SHORT: + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; + } else + systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; + break; + case BUTTON_F_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep; + } else + systemSettings.SolderingTemp += systemSettings.TempChangeLongStep; + autoRepeatTimer = xTaskGetTickCount(); + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_F_SHORT: + if (systemSettings.ReverseButtonTempChangeEnabled) { + systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10 + } else + systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10 + break; + default: + break; + } + if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { + autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; + } + // constrain between 10-450 C + if (systemSettings.temperatureInF) { + if (systemSettings.SolderingTemp > 850) + systemSettings.SolderingTemp = 850; + if (systemSettings.SolderingTemp < 60) + systemSettings.SolderingTemp = 60; + } else { + if (systemSettings.SolderingTemp > 450) + systemSettings.SolderingTemp = 450; + if (systemSettings.SolderingTemp < 10) + systemSettings.SolderingTemp = 10; + } - if (xTaskGetTickCount() - lastChange > 2000) - return; // exit if user just doesn't press anything for a bit + if (xTaskGetTickCount() - lastChange > 2000) + return; // exit if user just doesn't press anything for a bit #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); - } else { - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); - } + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); + } else { + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); + } - OLED::print(SymbolSpace); - OLED::printNumber(systemSettings.SolderingTemp, 3); - if (systemSettings.temperatureInF) - OLED::drawSymbol(0); - else { - OLED::drawSymbol(1); - } - OLED::print(SymbolSpace); + OLED::print(SymbolSpace); + OLED::printNumber(systemSettings.SolderingTemp, 3); + if (systemSettings.temperatureInF) + OLED::drawSymbol(0); + else { + OLED::drawSymbol(1); + } + OLED::print(SymbolSpace); #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); - } else { - OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); - } - OLED::refresh(); - GUIDelay(); - } + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus); + } else { + OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus); + } + OLED::refresh(); + GUIDelay(); + } } static bool shouldShutdown() { - if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0 - if (lastMovementTime) { - if (((TickType_t) (xTaskGetTickCount() - lastMovementTime)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) { - return true; - } - } - if (lastHallEffectSleepStart) { - if (((TickType_t) (xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t) (systemSettings.ShutdownTime * TICKS_MIN)) { - return true; - } - } - } - return false; + if (systemSettings.ShutdownTime) { // only allow shutdown exit if time > 0 + if (lastMovementTime) { + if (((TickType_t)(xTaskGetTickCount() - lastMovementTime)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) { + return true; + } + } + if (lastHallEffectSleepStart) { + if (((TickType_t)(xTaskGetTickCount() - lastHallEffectSleepStart)) > (TickType_t)(systemSettings.ShutdownTime * TICKS_MIN)) { + return true; + } + } + } + return false; } static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) { - // Drop to sleep temperature and display until movement or button press + // Drop to sleep temperature and display until movement or button press - for (;;) { - // user moved or pressed a button, go back to soldering - // If in the first two seconds we disable this to let accelerometer warm up + for (;;) { + // user moved or pressed a button, go back to soldering + // If in the first two seconds we disable this to let accelerometer warm up #ifdef POW_DC - if (checkVoltageForExit()) - return 1; // return non-zero on error + if (checkVoltageForExit()) + return 1; // return non-zero on error #endif - if (systemSettings.temperatureInF) { - currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp)); - } else { - currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp); - } - // draw the lcd - uint16_t tipTemp; - if (systemSettings.temperatureInF) - tipTemp = TipThermoModel::getTipInF(); - else { - tipTemp = TipThermoModel::getTipInC(); - } + if (systemSettings.temperatureInF) { + currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp)); + } else { + currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp); + } + // draw the lcd + uint16_t tipTemp; + if (systemSettings.temperatureInF) + tipTemp = TipThermoModel::getTipInF(); + else { + tipTemp = TipThermoModel::getTipInC(); + } - OLED::clearScreen(); - OLED::setCursor(0, 0); - if (systemSettings.detailedSoldering) { - OLED::setFont(1); - OLED::print(SleepingAdvancedString); - OLED::setCursor(0, 8); - OLED::print(SleepingTipAdvancedString); - OLED::printNumber(tipTemp, 3); - if (systemSettings.temperatureInF) - OLED::print(SymbolDegF); - else { - OLED::print(SymbolDegC); - } + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (systemSettings.detailedSoldering) { + OLED::setFont(1); + OLED::print(SleepingAdvancedString); + OLED::setCursor(0, 8); + OLED::print(SleepingTipAdvancedString); + OLED::printNumber(tipTemp, 3); + if (systemSettings.temperatureInF) + OLED::print(SymbolDegF); + else { + OLED::print(SymbolDegC); + } - OLED::print(SymbolSpace); - printVoltage(); - OLED::print(SymbolVolts); - } else { - OLED::setFont(0); - OLED::print(SleepingSimpleString); - OLED::printNumber(tipTemp, 3); - if (systemSettings.temperatureInF) - OLED::drawSymbol(0); - else { - OLED::drawSymbol(1); - } - } + OLED::print(SymbolSpace); + printVoltage(); + OLED::print(SymbolVolts); + } else { + OLED::setFont(0); + OLED::print(SleepingSimpleString); + OLED::printNumber(tipTemp, 3); + if (systemSettings.temperatureInF) + OLED::drawSymbol(0); + else { + OLED::drawSymbol(1); + } + } - OLED::refresh(); - GUIDelay(); - if (!shouldBeSleeping(autoStarted)) { - return 0; - } - if (shouldShutdown()) { - // shutdown - currentTempTargetDegC = 0; - return 1; // we want to exit soldering mode - } - } - return 0; + OLED::refresh(); + GUIDelay(); + if (!shouldBeSleeping(autoStarted)) { + return 0; + } + if (shouldShutdown()) { + // shutdown + currentTempTargetDegC = 0; + return 1; // we want to exit soldering mode + } + } + return 0; } static void display_countdown(int sleepThres) { - /* - * Print seconds or minutes (if > 99 seconds) until sleep - * mode is triggered. - */ - int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; - TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime; - if (downCount > (99 * TICKS_SECOND)) { - OLED::printNumber(downCount / 60000 + 1, 2); - OLED::print(SymbolMinutes); - } else { - OLED::printNumber(downCount / 1000 + 1, 2); - OLED::print(SymbolSeconds); - } + /* + * Print seconds or minutes (if > 99 seconds) until sleep + * mode is triggered. + */ + int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; + TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime; + if (downCount > (99 * TICKS_SECOND)) { + OLED::printNumber(downCount / 60000 + 1, 2); + OLED::print(SymbolMinutes); + } else { + OLED::printNumber(downCount / 1000 + 1, 2); + OLED::print(SymbolSeconds); + } } static uint32_t getSleepTimeout() { - if (systemSettings.sensitivity && systemSettings.SleepTime) { + if (systemSettings.sensitivity && systemSettings.SleepTime) { - uint32_t sleepThres = 0; - if (systemSettings.SleepTime < 6) - sleepThres = systemSettings.SleepTime * 10 * 1000; - else - sleepThres = (systemSettings.SleepTime - 5) * 60 * 1000; - return sleepThres; - } - return 0; + uint32_t sleepThres = 0; + if (systemSettings.SleepTime < 6) + sleepThres = systemSettings.SleepTime * 10 * 1000; + else + sleepThres = (systemSettings.SleepTime - 5) * 60 * 1000; + return sleepThres; + } + return 0; } static bool shouldBeSleeping(bool inAutoStart) { - // Return true if the iron should be in sleep mode - if (systemSettings.sensitivity && systemSettings.SleepTime) { - if (inAutoStart) { - // In auto start we are asleep until movement - if (lastMovementTime == 0 && lastButtonTime == 0) { - return true; - } - } - if (lastMovementTime > 0 || lastButtonTime > 0) { - if (((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout()) && ((xTaskGetTickCount() - lastButtonTime) > getSleepTimeout())) { - return true; - } - } - } + // Return true if the iron should be in sleep mode + if (systemSettings.sensitivity && systemSettings.SleepTime) { + if (inAutoStart) { + // In auto start we are asleep until movement + if (lastMovementTime == 0 && lastButtonTime == 0) { + return true; + } + } + if (lastMovementTime > 0 || lastButtonTime > 0) { + if (((xTaskGetTickCount() - lastMovementTime) > getSleepTimeout()) && ((xTaskGetTickCount() - lastButtonTime) > getSleepTimeout())) { + return true; + } + } + } #ifdef HALL_SENSOR - // If the hall effect sensor is enabled in the build, check if its over - // threshold, and if so then we force sleep - if (getHallSensorFitted() && lookupHallEffectThreshold()) { - int16_t hallEffectStrength = getRawHallEffect(); - if (hallEffectStrength < 0) - hallEffectStrength = -hallEffectStrength; - // Have absolute value of measure of magnetic field strength - if (hallEffectStrength > lookupHallEffectThreshold()) { - if (lastHallEffectSleepStart == 0) { - lastHallEffectSleepStart = xTaskGetTickCount(); - } - if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) { - return true; - } - } else { - lastHallEffectSleepStart = 0; - } - } + // If the hall effect sensor is enabled in the build, check if its over + // threshold, and if so then we force sleep + if (getHallSensorFitted() && lookupHallEffectThreshold()) { + int16_t hallEffectStrength = getRawHallEffect(); + if (hallEffectStrength < 0) + hallEffectStrength = -hallEffectStrength; + // Have absolute value of measure of magnetic field strength + if (hallEffectStrength > lookupHallEffectThreshold()) { + if (lastHallEffectSleepStart == 0) { + lastHallEffectSleepStart = xTaskGetTickCount(); + } + if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) { + return true; + } + } else { + lastHallEffectSleepStart = 0; + } + } #endif - return false; + return false; } static void gui_solderingMode(uint8_t jumpToSleep) { - /* - * * Soldering (gui_solderingMode) - * -> Main loop where we draw temp, and animations - * --> User presses buttons and they goto the temperature adjust screen - * ---> Display the current setpoint temperature - * ---> Use buttons to change forward and back on temperature - * ---> Both buttons or timeout for exiting - * --> Long hold front button to enter boost mode - * ---> Just temporarily sets the system into the alternate temperature for - * PID control - * --> Long hold back button to exit - * --> Double button to exit - * --> Long hold double button to toggle key lock - */ - bool boostModeOn = false; - bool buttonsLocked = false; + /* + * * Soldering (gui_solderingMode) + * -> Main loop where we draw temp, and animations + * --> User presses buttons and they goto the temperature adjust screen + * ---> Display the current setpoint temperature + * ---> Use buttons to change forward and back on temperature + * ---> Both buttons or timeout for exiting + * --> Long hold front button to enter boost mode + * ---> Just temporarily sets the system into the alternate temperature for + * PID control + * --> Long hold back button to exit + * --> Double button to exit + * --> Long hold double button to toggle key lock + */ + bool boostModeOn = false; + bool buttonsLocked = false; - if (jumpToSleep) { - if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) { - lastButtonTime = xTaskGetTickCount(); - return; // If the function returns non-0 then exit - } - } - for (;;) { - ButtonState buttons = getButtonState(); - if (buttonsLocked && (systemSettings.lockingMode != 0)) { // If buttons locked - switch (buttons) { - case BUTTON_NONE: - boostModeOn = false; - break; - case BUTTON_BOTH_LONG: - // Unlock buttons - buttonsLocked = false; - warnUser(UnlockingKeysString, 0, TICKS_SECOND); - break; - case BUTTON_F_LONG: - // if boost mode is enabled turn it on - if (systemSettings.BoostTemp && (systemSettings.lockingMode == 1)) { - boostModeOn = true; - } - break; - // fall through - case BUTTON_BOTH: - case BUTTON_B_LONG: - case BUTTON_F_SHORT: - case BUTTON_B_SHORT: - // Do nothing and display a lock warming - warnUser(WarningKeysLockedString, 0, TICKS_SECOND / 2); - break; - default: - break; - } - } else { // Button not locked - switch (buttons) { - case BUTTON_NONE: - // stay - boostModeOn = false; - break; - case BUTTON_BOTH: - // exit - return; - break; - case BUTTON_B_LONG: - return; // exit on back long hold - break; - case BUTTON_F_LONG: - // if boost mode is enabled turn it on - if (systemSettings.BoostTemp) - boostModeOn = true; - break; - case BUTTON_F_SHORT: - case BUTTON_B_SHORT: { - uint16_t oldTemp = systemSettings.SolderingTemp; - gui_solderingTempAdjust(); // goto adjust temp mode - if (oldTemp != systemSettings.SolderingTemp) { - saveSettings(); // only save on change - } - } - break; - case BUTTON_BOTH_LONG: - if (systemSettings.lockingMode != 0) { - // Lock buttons - buttonsLocked = true; - warnUser(LockingKeysString, 0, TICKS_SECOND); - } - break; - default: - break; - } - } - // else we update the screen information - OLED::setCursor(0, 0); - OLED::clearScreen(); - OLED::setFont(0); - // Draw in the screen details - if (systemSettings.detailedSoldering) { - OLED::setFont(1); - OLED::print(SolderingAdvancedPowerPrompt); // Power: - OLED::printNumber(x10WattHistory.average() / 10, 2); - OLED::print(SymbolDot); - OLED::printNumber(x10WattHistory.average() % 10, 1); - OLED::print(SymbolWatts); + if (jumpToSleep) { + if (gui_SolderingSleepingMode(jumpToSleep == 2, true) == 1) { + lastButtonTime = xTaskGetTickCount(); + return; // If the function returns non-0 then exit + } + } + for (;;) { + ButtonState buttons = getButtonState(); + if (buttonsLocked && (systemSettings.lockingMode != 0)) { // If buttons locked + switch (buttons) { + case BUTTON_NONE: + boostModeOn = false; + break; + case BUTTON_BOTH_LONG: + // Unlock buttons + buttonsLocked = false; + warnUser(UnlockingKeysString, 0, TICKS_SECOND); + break; + case BUTTON_F_LONG: + // if boost mode is enabled turn it on + if (systemSettings.BoostTemp && (systemSettings.lockingMode == 1)) { + boostModeOn = true; + } + break; + // fall through + case BUTTON_BOTH: + case BUTTON_B_LONG: + case BUTTON_F_SHORT: + case BUTTON_B_SHORT: + // Do nothing and display a lock warming + warnUser(WarningKeysLockedString, 0, TICKS_SECOND / 2); + break; + default: + break; + } + } else { // Button not locked + switch (buttons) { + case BUTTON_NONE: + // stay + boostModeOn = false; + break; + case BUTTON_BOTH: + // exit + return; + break; + case BUTTON_B_LONG: + return; // exit on back long hold + break; + case BUTTON_F_LONG: + // if boost mode is enabled turn it on + if (systemSettings.BoostTemp) + boostModeOn = true; + break; + case BUTTON_F_SHORT: + case BUTTON_B_SHORT: { + uint16_t oldTemp = systemSettings.SolderingTemp; + gui_solderingTempAdjust(); // goto adjust temp mode + if (oldTemp != systemSettings.SolderingTemp) { + saveSettings(); // only save on change + } + } break; + case BUTTON_BOTH_LONG: + if (systemSettings.lockingMode != 0) { + // Lock buttons + buttonsLocked = true; + warnUser(LockingKeysString, 0, TICKS_SECOND); + } + break; + default: + break; + } + } + // else we update the screen information + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); + // Draw in the screen details + if (systemSettings.detailedSoldering) { + OLED::setFont(1); + OLED::print(SolderingAdvancedPowerPrompt); // Power: + OLED::printNumber(x10WattHistory.average() / 10, 2); + OLED::print(SymbolDot); + OLED::printNumber(x10WattHistory.average() % 10, 1); + OLED::print(SymbolWatts); - if (systemSettings.sensitivity && systemSettings.SleepTime) { - OLED::print(SymbolSpace); - display_countdown(getSleepTimeout()); - } + if (systemSettings.sensitivity && systemSettings.SleepTime) { + OLED::print(SymbolSpace); + display_countdown(getSleepTimeout()); + } - OLED::setCursor(0, 8); - OLED::print(SleepingTipAdvancedString); - gui_drawTipTemp(true); - OLED::print(SymbolSpace); - printVoltage(); - OLED::print(SymbolVolts); - } else { - // We switch the layout direction depending on the orientation of the oled - if (OLED::getRotation()) { - // battery - gui_drawBatteryIcon(); - OLED::print(SymbolSpace); // Space out gap between battery <-> temp - gui_drawTipTemp(true); // Draw current tip temp + OLED::setCursor(0, 8); + OLED::print(SleepingTipAdvancedString); + gui_drawTipTemp(true); + OLED::print(SymbolSpace); + printVoltage(); + OLED::print(SymbolVolts); + } else { + // We switch the layout direction depending on the orientation of the oled + if (OLED::getRotation()) { + // battery + gui_drawBatteryIcon(); + OLED::print(SymbolSpace); // Space out gap between battery <-> temp + gui_drawTipTemp(true); // Draw current tip temp - // We draw boost arrow if boosting, or else gap temp <-> heat - // indicator - if (boostModeOn) - OLED::drawSymbol(2); - else - OLED::print(SymbolSpace); + // We draw boost arrow if boosting, or else gap temp <-> heat + // indicator + if (boostModeOn) + OLED::drawSymbol(2); + else + OLED::print(SymbolSpace); - // Draw heating/cooling symbols - OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); - } else { - // Draw heating/cooling symbols - OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); - // We draw boost arrow if boosting, or else gap temp <-> heat - // indicator - if (boostModeOn) - OLED::drawSymbol(2); - else - OLED::print(SymbolSpace); - gui_drawTipTemp(true); // Draw current tip temp + // Draw heating/cooling symbols + OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); + } else { + // Draw heating/cooling symbols + OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average())); + // We draw boost arrow if boosting, or else gap temp <-> heat + // indicator + if (boostModeOn) + OLED::drawSymbol(2); + else + OLED::print(SymbolSpace); + gui_drawTipTemp(true); // Draw current tip temp - OLED::print(SymbolSpace); // Space out gap between battery <-> temp + OLED::print(SymbolSpace); // Space out gap between battery <-> temp - gui_drawBatteryIcon(); - } - } - OLED::refresh(); + gui_drawBatteryIcon(); + } + } + OLED::refresh(); - // Update the setpoints for the temperature - if (boostModeOn) { - if (systemSettings.temperatureInF) - currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp); - else { - currentTempTargetDegC = (systemSettings.BoostTemp); - } - } else { - if (systemSettings.temperatureInF) - currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp); - else { - currentTempTargetDegC = (systemSettings.SolderingTemp); - } - } + // Update the setpoints for the temperature + if (boostModeOn) { + if (systemSettings.temperatureInF) + currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp); + else { + currentTempTargetDegC = (systemSettings.BoostTemp); + } + } else { + if (systemSettings.temperatureInF) + currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp); + else { + currentTempTargetDegC = (systemSettings.SolderingTemp); + } + } #ifdef POW_DC - // Undervoltage test - if (checkVoltageForExit()) { - lastButtonTime = xTaskGetTickCount(); - return; - } + // Undervoltage test + if (checkVoltageForExit()) { + lastButtonTime = xTaskGetTickCount(); + return; + } #endif - if (shouldBeSleeping()) { - if (gui_SolderingSleepingMode(false, false)) { - return; // If the function returns non-0 then exit - } - } - // slow down ui update rate - GUIDelay(); - } + if (shouldBeSleeping()) { + if (gui_SolderingSleepingMode(false, false)) { + return; // If the function returns non-0 then exit + } + } + // slow down ui update rate + GUIDelay(); + } } void showDebugMenu(void) { - uint8_t screen = 0; - ButtonState b; - OLED::setFont(1); // small font - for (;;) { - OLED::clearScreen(); // Ensure the buffer starts clean - OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) - OLED::print(SymbolVersionNumber); // Print version number - OLED::setCursor(0, 8); // second line - OLED::print(DebugMenu[screen]); - switch (screen) { - case 0: // Just prints date - break; - case 1: - // High water mark for GUI - OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5); - break; - case 2: - // High water mark for the Movement task - OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5); - break; - case 3: - // High water mark for the PID task - OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5); - break; - case 4: - // system up time stamp - OLED::printNumber(xTaskGetTickCount() / 100, 5); - break; - case 5: - // Movement time stamp - OLED::printNumber(lastMovementTime / 100, 5); - break; - case 6: - // Raw Tip - { - OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6); - } - break; - case 7: - // Temp in C - OLED::printNumber(TipThermoModel::getTipInC(), 5); - break; - case 8: - // Handle Temp - OLED::printNumber(getHandleTemperature(), 3); - break; - case 9: - // Voltage input - printVoltage(); - break; - case 10: - // Print PCB ID number - OLED::printNumber(DetectedAccelerometerVersion, 2); - break; - case 11: - // Power negotiation status - if (getIsPoweredByDCIN()) { - OLED::printNumber(0, 1); - } else { - // We are not powered via DC, so want to display the appropriate state for PD or QC - bool poweredbyPD = false; + uint8_t screen = 0; + ButtonState b; + OLED::setFont(1); // small font + for (;;) { + OLED::clearScreen(); // Ensure the buffer starts clean + OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) + OLED::print(SymbolVersionNumber); // Print version number + OLED::setCursor(0, 8); // second line + OLED::print(DebugMenu[screen]); + switch (screen) { + case 0: // Just prints date + break; + case 1: + // High water mark for GUI + OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5); + break; + case 2: + // High water mark for the Movement task + OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5); + break; + case 3: + // High water mark for the PID task + OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5); + break; + case 4: + // system up time stamp + OLED::printNumber(xTaskGetTickCount() / 100, 5); + break; + case 5: + // Movement time stamp + OLED::printNumber(lastMovementTime / 100, 5); + break; + case 6: + // Raw Tip + { OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6); } + break; + case 7: + // Temp in C + OLED::printNumber(TipThermoModel::getTipInC(), 5); + break; + case 8: + // Handle Temp + OLED::printNumber(getHandleTemperature(), 3); + break; + case 9: + // Voltage input + printVoltage(); + break; + case 10: + // Print PCB ID number + OLED::printNumber(DetectedAccelerometerVersion, 2); + break; + case 11: + // Power negotiation status + if (getIsPoweredByDCIN()) { + OLED::printNumber(0, 1); + } else { + // We are not powered via DC, so want to display the appropriate state for PD or QC + bool poweredbyPD = false; #ifdef POW_PD - if (usb_pd_detect()) { - // We are PD capable - if (PolicyEngine::pdHasNegotiated()) { - // We are powered via PD - poweredbyPD = true; - } - } + if (usb_pd_detect()) { + // We are PD capable + if (PolicyEngine::pdHasNegotiated()) { + // We are powered via PD + poweredbyPD = true; + } + } #endif - if (poweredbyPD) { - OLED::printNumber(2, 1); - } else { + if (poweredbyPD) { + OLED::printNumber(2, 1); + } else { - OLED::printNumber(1, 1); - } - } - break; - case 12: - // Max deg C limit - OLED::printNumber(TipThermoModel::getTipMaxInC(), 3); - break; - default: - break; - } + OLED::printNumber(1, 1); + } + } + break; + case 12: + // Max deg C limit + OLED::printNumber(TipThermoModel::getTipMaxInC(), 3); + break; + default: + break; + } - OLED::refresh(); - b = getButtonState(); - if (b == BUTTON_B_SHORT) - return; - else if (b == BUTTON_F_SHORT) { - screen++; - screen = screen % 13; - } - GUIDelay(); - } + OLED::refresh(); + b = getButtonState(); + if (b == BUTTON_B_SHORT) + return; + else if (b == BUTTON_F_SHORT) { + screen++; + screen = screen % 13; + } + GUIDelay(); + } } void showWarnings() { - // Display alert if settings were reset - if (settingsWereReset) { - if (SettingsResetMessage[0] == '\x01') { // `\x01` is used as newline. - // Empty first line means that this uses large font (for CJK). - warnUser(SettingsResetMessage + 1, 0, 10 * TICKS_SECOND); - } else { - warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND); - } - } + // Display alert if settings were reset + if (settingsWereReset) { + if (SettingsResetMessage[0] == '\x01') { // `\x01` is used as newline. + // Empty first line means that this uses large font (for CJK). + warnUser(SettingsResetMessage + 1, 0, 10 * TICKS_SECOND); + } else { + warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND); + } + } #ifndef NO_WARN_MISSING - // We also want to alert if accel or pd is not detected / not responding - // In this case though, we dont want to nag the user _too_ much - // So only show first 2 times - while (DetectedAccelerometerVersion == ACCELEROMETERS_SCANNING) { - osDelay(5); - } - // Display alert if accelerometer is not detected - if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER) { - if (systemSettings.accelMissingWarningCounter < 2) { - systemSettings.accelMissingWarningCounter++; - saveSettings(); - warnUser(NoAccelerometerMessage, 1, 10 * TICKS_SECOND); - } - } + // We also want to alert if accel or pd is not detected / not responding + // In this case though, we dont want to nag the user _too_ much + // So only show first 2 times + while (DetectedAccelerometerVersion == ACCELEROMETERS_SCANNING) { + osDelay(5); + } + // Display alert if accelerometer is not detected + if (DetectedAccelerometerVersion == NO_DETECTED_ACCELEROMETER) { + if (systemSettings.accelMissingWarningCounter < 2) { + systemSettings.accelMissingWarningCounter++; + saveSettings(); + warnUser(NoAccelerometerMessage, 1, 10 * TICKS_SECOND); + } + } #ifdef POW_PD - // We expect pd to be present - if (!usb_pd_detect()) { - if (systemSettings.pdMissingWarningCounter < 2) { - systemSettings.pdMissingWarningCounter++; - saveSettings(); - warnUser(NoPowerDeliveryMessage, 1, 10 * TICKS_SECOND); - } - } + // We expect pd to be present + if (!usb_pd_detect()) { + if (systemSettings.pdMissingWarningCounter < 2) { + systemSettings.pdMissingWarningCounter++; + saveSettings(); + warnUser(NoPowerDeliveryMessage, 1, 10 * TICKS_SECOND); + } + } #endif #endif } @@ -759,183 +756,183 @@ void showWarnings() { uint8_t idleScreenBGF[sizeof(idleScreenBG)]; /* StartGUITask function */ void startGUITask(void const *argument __unused) { - OLED::initialize(); // start up the LCD + OLED::initialize(); // start up the LCD - uint8_t tempWarningState = 0; - bool buttonLockout = false; - bool tempOnDisplay = false; - bool tipDisconnectedDisplay = false; - { - // Generate the flipped screen into ram for later use - // flipped is generated by flipping each row - for (int row = 0; row < 2; row++) { - for (int x = 0; x < 84; x++) { - idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84) + (83 - x)]; - } - } - } - getTipRawTemp(1); // reset filter - OLED::setRotation(systemSettings.OrientationMode & 1); - uint32_t ticks = xTaskGetTickCount(); - ticks += 4000; // 4 seconds from now - while (xTaskGetTickCount() < ticks) { - if (showBootLogoIfavailable() == false) - ticks = xTaskGetTickCount(); - ButtonState buttons = getButtonState(); - if (buttons) - ticks = xTaskGetTickCount(); // make timeout now so we will exit - GUIDelay(); - } + uint8_t tempWarningState = 0; + bool buttonLockout = false; + bool tempOnDisplay = false; + bool tipDisconnectedDisplay = false; + { + // Generate the flipped screen into ram for later use + // flipped is generated by flipping each row + for (int row = 0; row < 2; row++) { + for (int x = 0; x < 84; x++) { + idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84) + (83 - x)]; + } + } + } + getTipRawTemp(1); // reset filter + OLED::setRotation(systemSettings.OrientationMode & 1); + uint32_t ticks = xTaskGetTickCount(); + ticks += 4000; // 4 seconds from now + while (xTaskGetTickCount() < ticks) { + if (showBootLogoIfavailable() == false) + ticks = xTaskGetTickCount(); + ButtonState buttons = getButtonState(); + if (buttons) + ticks = xTaskGetTickCount(); // make timeout now so we will exit + GUIDelay(); + } - showWarnings(); + showWarnings(); - if (systemSettings.autoStartMode) { - // jump directly to the autostart mode - gui_solderingMode(systemSettings.autoStartMode - 1); - buttonLockout = true; - } + if (systemSettings.autoStartMode) { + // jump directly to the autostart mode + gui_solderingMode(systemSettings.autoStartMode - 1); + buttonLockout = true; + } - for (;;) { - ButtonState buttons = getButtonState(); - if (buttons != BUTTON_NONE) { - OLED::setDisplayState(OLED::DisplayState::ON); - OLED::setFont(0); - } - if (tempWarningState == 2) - buttons = BUTTON_F_SHORT; - if (buttons != BUTTON_NONE && buttonLockout) - buttons = BUTTON_NONE; - else - buttonLockout = false; + for (;;) { + ButtonState buttons = getButtonState(); + if (buttons != BUTTON_NONE) { + OLED::setDisplayState(OLED::DisplayState::ON); + OLED::setFont(0); + } + if (tempWarningState == 2) + buttons = BUTTON_F_SHORT; + if (buttons != BUTTON_NONE && buttonLockout) + buttons = BUTTON_NONE; + else + buttonLockout = false; - switch (buttons) { - case BUTTON_NONE: - // Do nothing - break; - case BUTTON_BOTH: - // Not used yet - // In multi-language this might be used to reset language on a long hold - // or some such - break; + switch (buttons) { + case BUTTON_NONE: + // Do nothing + break; + case BUTTON_BOTH: + // Not used yet + // In multi-language this might be used to reset language on a long hold + // or some such + break; - case BUTTON_B_LONG: - // Show the version information - showDebugMenu(); - break; - case BUTTON_F_LONG: - gui_solderingTempAdjust(); - saveSettings(); - break; - case BUTTON_F_SHORT: - gui_solderingMode(0); // enter soldering mode - buttonLockout = true; - break; - case BUTTON_B_SHORT: - enterSettingsMenu(); // enter the settings menu - buttonLockout = true; - break; - default: - break; - } + case BUTTON_B_LONG: + // Show the version information + showDebugMenu(); + break; + case BUTTON_F_LONG: + gui_solderingTempAdjust(); + saveSettings(); + break; + case BUTTON_F_SHORT: + gui_solderingMode(0); // enter soldering mode + buttonLockout = true; + break; + case BUTTON_B_SHORT: + enterSettingsMenu(); // enter the settings menu + buttonLockout = true; + break; + default: + break; + } - currentTempTargetDegC = 0; // ensure tip is off - getInputVoltageX10(systemSettings.voltageDiv, 0); - uint32_t tipTemp = TipThermoModel::getTipInC(); + currentTempTargetDegC = 0; // ensure tip is off + getInputVoltageX10(systemSettings.voltageDiv, 0); + uint32_t tipTemp = TipThermoModel::getTipInC(); - // Preemptively turn the display on. Turn it off if and only if - // the tip temperature is below 50 degrees C *and* motion sleep - // detection is enabled *and* there has been no activity (movement or - // button presses) in a while. - // This is zero cost really as state is only changed on display updates - OLED::setDisplayState(OLED::DisplayState::ON); + // Preemptively turn the display on. Turn it off if and only if + // the tip temperature is below 50 degrees C *and* motion sleep + // detection is enabled *and* there has been no activity (movement or + // button presses) in a while. + // This is zero cost really as state is only changed on display updates + OLED::setDisplayState(OLED::DisplayState::ON); - if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { - OLED::setDisplayState(OLED::DisplayState::OFF); - } - uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; - // Clear the lcd buffer - OLED::clearScreen(); - OLED::setCursor(0, 0); - if (systemSettings.detailedIDLE) { - OLED::setFont(1); - if (tipTemp > tipDisconnectedThres) { - OLED::print(TipDisconnectedString); - } else { - OLED::print(IdleTipString); - gui_drawTipTemp(false); - OLED::print(IdleSetString); - OLED::printNumber(systemSettings.SolderingTemp, 3); - } - OLED::setCursor(0, 8); + if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { + OLED::setDisplayState(OLED::DisplayState::OFF); + } + uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5; + // Clear the lcd buffer + OLED::clearScreen(); + OLED::setCursor(0, 0); + if (systemSettings.detailedIDLE) { + OLED::setFont(1); + if (tipTemp > tipDisconnectedThres) { + OLED::print(TipDisconnectedString); + } else { + OLED::print(IdleTipString); + gui_drawTipTemp(false); + OLED::print(IdleSetString); + OLED::printNumber(systemSettings.SolderingTemp, 3); + } + OLED::setCursor(0, 8); - OLED::print(InputVoltageString); - printVoltage(); + OLED::print(InputVoltageString); + printVoltage(); - } else { - OLED::setFont(0); + } else { + OLED::setFont(0); #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - OLED::drawArea(12, 0, 84, 16, idleScreenBG); - OLED::setCursor(0, 0); - gui_drawBatteryIcon(); - } else { - OLED::drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up - // on right side of screen - OLED::setCursor(84, 0); - gui_drawBatteryIcon(); - } - tipDisconnectedDisplay = false; - if (tipTemp > 55) - tempOnDisplay = true; - else if (tipTemp < 45) - tempOnDisplay = false; - if (tipTemp > tipDisconnectedThres) { - tempOnDisplay = false; - tipDisconnectedDisplay = true; - } - if (tempOnDisplay || tipDisconnectedDisplay) { - // draw temp over the start soldering button - // Location changes on screen rotation + OLED::drawArea(12, 0, 84, 16, idleScreenBG); + OLED::setCursor(0, 0); + gui_drawBatteryIcon(); + } else { + OLED::drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up + // on right side of screen + OLED::setCursor(84, 0); + gui_drawBatteryIcon(); + } + tipDisconnectedDisplay = false; + if (tipTemp > 55) + tempOnDisplay = true; + else if (tipTemp < 45) + tempOnDisplay = false; + if (tipTemp > tipDisconnectedThres) { + tempOnDisplay = false; + tipDisconnectedDisplay = true; + } + if (tempOnDisplay || tipDisconnectedDisplay) { + // draw temp over the start soldering button + // Location changes on screen rotation #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - // in right handed mode we want to draw over the first part - OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp - OLED::setCursor(56, 0); + // in right handed mode we want to draw over the first part + OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp + OLED::setCursor(56, 0); - } else { - OLED::fillArea(0, 0, 41, 16, 0); // clear the area - OLED::setCursor(0, 0); - } - // If we have a tip connected draw the temp, if not we leave it blank - if (!tipDisconnectedDisplay) { - // draw in the temp - if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16))) - gui_drawTipTemp(false); // draw in the temp - } else { - // Draw in missing tip symbol + } else { + OLED::fillArea(0, 0, 41, 16, 0); // clear the area + OLED::setCursor(0, 0); + } + // If we have a tip connected draw the temp, if not we leave it blank + if (!tipDisconnectedDisplay) { + // draw in the temp + if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 26 < 16))) + gui_drawTipTemp(false); // draw in the temp + } else { + // Draw in missing tip symbol #ifdef OLED_FLIP - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif - // in right handed mode we want to draw over the first part - OLED::drawArea(55, 0, 41, 16, disconnectedTipIcon); + // in right handed mode we want to draw over the first part + OLED::drawArea(55, 0, 41, 16, disconnectedTipIcon); - } else { - OLED::drawArea(0, 0, 41, 16, disconnectedTipIcon); - } - } - } - } + } else { + OLED::drawArea(0, 0, 41, 16, disconnectedTipIcon); + } + } + } + } - OLED::refresh(); - GUIDelay(); - } + OLED::refresh(); + GUIDelay(); + } } From 8a4d20be2566066e7fd0f45697f294d8de8661b3 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 25 Feb 2021 19:27:22 +1100 Subject: [PATCH 13/40] Update I2C_Wrapper.cpp --- source/Core/BSP/Pine64/I2C_Wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/BSP/Pine64/I2C_Wrapper.cpp b/source/Core/BSP/Pine64/I2C_Wrapper.cpp index aebcbbd1..04d1e288 100644 --- a/source/Core/BSP/Pine64/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pine64/I2C_Wrapper.cpp @@ -275,7 +275,7 @@ bool perform_i2c_transaction(uint16_t DevAddress, uint16_t memory_address, uint8 } perform_i2c_step(); } - return true; + return currentState.currentStep == Done; } bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) { From cd4c122493ebf9457b500c7ed8d48e93d924adf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 2 Mar 2021 00:01:25 +0100 Subject: [PATCH 14/40] make_translation.py: only use bdflib when necessary --- Translations/make_translation.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Translations/make_translation.py b/Translations/make_translation.py index f498cdfd..38171344 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -5,12 +5,12 @@ import argparse import json import os import io +import functools from datetime import datetime import sys import fontTables import re import subprocess -from bdflib import reader as bdfreader HERE = os.path.dirname(__file__) @@ -20,8 +20,11 @@ except NameError: to_unicode = str -with open(os.path.join(HERE, "wqy-bitmapsong/wenquanyi_9pt.bdf"), "rb") as handle: - cjkFont = bdfreader.read_bdf(handle) +@functools.lru_cache(maxsize=None) +def cjkFont(): + from bdflib import reader as bdfreader + with open(os.path.join(HERE, "wqy-bitmapsong/wenquanyi_9pt.bdf"), "rb") as f: + return bdfreader.read_bdf(f) def log(message): @@ -184,7 +187,7 @@ def getLetterCounts(defs, lang): def getCJKGlyph(sym): from bdflib.model import Glyph try: - glyph: Glyph = cjkFont[ord(sym)] + glyph: Glyph = cjkFont()[ord(sym)] except: return None data = glyph.data From ccc77f3f7212ebaad3ba6b690bbb74b4cb1422b8 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:41:58 +0100 Subject: [PATCH 15/40] Update translation_UK.json --- Translations/translation_UK.json | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index f2ab5e94..6c8274fa 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -7,14 +7,14 @@ "SettingsCalibrationWarning": "Переконайтеся, що жало охололо до кімнатної температури, перш ніж продовжувати!", "SettingsResetWarning": "Ви дійсно хочете скинути налаштування до значень за замовчуванням? ", "UVLOWarningString": "АККУМ--", - "UndervoltageString": "Низ. напруга", + "UndervoltageString": "Низька\nнапруга", "InputVoltageString": "Жив.(B): ", "WarningTipTempString": "Жало t°: ", "BadTipString": "ЖАЛО--", "SleepingSimpleString": "ZzZzz", "SleepingAdvancedString": "Очікування...", "WarningSimpleString": "ГАРЯЧЕ!", - "WarningAdvancedString": "!!! ГАРЯЧЕ ЖАЛО !!!", + "WarningAdvancedString": "!!! ГАРЯЧЕ !!!\n!!! ЖАЛО !!!", "SleepingTipAdvancedString": "Жало:", "IdleTipString": "Жало:", "IdleSetString": " ->", @@ -23,7 +23,7 @@ "OffString": "Вимк", "ResetOKMessage": "Скидання OK", "YourGainMessage": "Приріст:", - "SettingsResetMessage": "Налаштування скинуті!", + "SettingsResetMessage": "Налаштування\nскинуті!", "NoAccelerometerMessage": "Акселерометр\nне виявлено!", "NoPowerDeliveryMessage": "USB-PD IC\nне виявлено!", "LockingKeysString": " ЗАБЛОКОВАНО", @@ -54,7 +54,7 @@ "Параметри", "пайки" ], - "desc": "Налаштування для режиму пайки. Діють при включеному жалі." + "desc": "Налаштування для режиму пайки. Діють при увімкненому жалі." }, "PowerSavingMenu": { "text2": [ @@ -65,8 +65,8 @@ }, "UIMenu": { "text2": [ - "Інтерфейс", - "" + "Параметри", + "інтерфейсу" ], "desc": "Параметри користувальницького інтерфейсу." }, @@ -84,11 +84,11 @@ "Джерело", "живлення" ], - "desc": "Встановлення напруги відключення. " + "desc": "Встановлює напругу відсічки. " }, "SleepTemperature": { "text2": [ - "Темпер.", + "Температура", "сну" ], "desc": "Температура режиму очікування " @@ -105,12 +105,12 @@ "Часу до", "вимкнення" ], - "desc": "Час до відключення <Хвилини>" + "desc": "Час до вимкнення <Хвилини>" }, "MotionSensitivity": { "text2": [ - "Чутл. сенсо-", - "ру руху" + "Чутливість", + "сенсору руху" ], "desc": "Акселерометр <0 - Вимк. 1 - мін. чутливості 9 - макс. чутливості>" }, @@ -140,7 +140,7 @@ "Темпер.", "Турбо" ], - "desc": "Температура в Турбо-режимі" + "desc": "Температура в \"Турбо\" режимі" }, "AutoStart": { "text2": [ @@ -152,13 +152,13 @@ "CooldownBlink": { "text2": [ "Показ t° при", - "охолодж." + "охолодженні" ], "desc": "Показувати температуру на екрані охолодження, поки жало залишається гарячим, при цьому екран моргає" }, "TemperatureCalibration": { "text2": [ - "Калібровка", + "Калібрування", "температури" ], "desc": "Калібрування температурного датчика." @@ -179,8 +179,8 @@ }, "AdvancedSoldering": { "text2": [ - "Детальний ре-", - "жим пайки" + "Детальний", + "режим пайки" ], "desc": "Показувати детальну інформацію при пайці." }, @@ -194,7 +194,7 @@ "TipModel": { "text2": [ "Модель", - "Жало" + "жала" ], "desc": "Вибір моделі жала" }, @@ -215,14 +215,14 @@ "QCMaxVoltage": { "text2": [ "Потужність", - "дж. живл." + "дж. живлення" ], "desc": "Потужність джерела живлення в Ватах" }, "PowerLimit": { "text2": [ - "Макс.", - "потуж." + "Максимальна", + "потужність" ], "desc": "Макс. потужність, яку може використовувати паяльник <Ват>" }, @@ -235,14 +235,14 @@ }, "TempChangeShortStep": { "text2": [ - "Зм. темп.", + "Зміна темп.", "коротко?" ], "desc": "Змінювати температуру при короткому натисканні!" }, "TempChangeLongStep": { "text2": [ - "Зм. темп.", + "Зміна темп.", "довго?" ], "desc": "Змінювати температуру при довгому натисканні!" @@ -256,10 +256,10 @@ }, "TipGain": { "text2": [ - "Modify", - "tip gain" + "Змінити", + "підсилею жала" ], - "desc": "Tip gain" + "desc": "Підсилення жала" }, "HallEffSensitivity": { "text2": [ From 6ef411aaf6bf480a35b5d0252653375a775d9b1e Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:43:27 +0100 Subject: [PATCH 16/40] Update translation_RU.json --- Translations/translation_RU.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index 1923c0d4..27e65b31 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -7,14 +7,14 @@ "SettingsCalibrationWarning": "Прежде чем продолжить, пожалуйста, убедитесь, что жало имеет комнатную температуру!", "SettingsResetWarning": "Вы уверены, что хотите сбросить настройки к значениям по умолчанию?", "UVLOWarningString": "НАПРЯЖ--", - "UndervoltageString": "Низк. напряжение", + "UndervoltageString": "Низкое\nнапряжение", "InputVoltageString": "Питание В: ", "WarningTipTempString": "Темп. жала: ", "BadTipString": "ЖАЛО--", "SleepingSimpleString": "Zzzz", "SleepingAdvancedString": "Ожидание...", "WarningSimpleString": "ГОРЯЧО!", - "WarningAdvancedString": "!!! ГОРЯЧЕЕ ЖАЛО !!!", + "WarningAdvancedString": "!!! ГОРЯЧЕЕ !!!\n!!! ЖАЛО !!!", "SleepingTipAdvancedString": "Жало:", "IdleTipString": "Жало:", "IdleSetString": " ->", @@ -23,7 +23,7 @@ "OffString": "Выкл.", "ResetOKMessage": "Сброс OK", "YourGainMessage": "Прирост:", - "SettingsResetMessage": "Настройки сброшены!", + "SettingsResetMessage": "Настройки\nсброшены!", "NoAccelerometerMessage": "Не определен\nакселерометр!", "NoPowerDeliveryMessage": "No USB-PD IC\ndetected!", "LockingKeysString": " LOCKED", From eef3d9b1322a32e9ba4d47aafeb8ef82dc8a3f2f Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:51:44 +0100 Subject: [PATCH 17/40] Update translation_UK.json --- Translations/translation_UK.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 6c8274fa..975cc0c6 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -137,7 +137,7 @@ }, "BoostTemperature": { "text2": [ - "Темпер.", + "Температура", "Турбо" ], "desc": "Температура в \"Турбо\" режимі" @@ -147,7 +147,7 @@ "Гарячий", "старт" ], - "desc": "Режим з яким запускається паяльник при подачі живлення <П=Пайка, О=Очікування, К=Очікування при кімн. темп., В=Вимк.>" + "desc": "Режим в якому запускається паяльник при ввімкненні <П=Пайка, О=Очікування, К=Очікування при кімн. темп., В=Вимк.>" }, "CooldownBlink": { "text2": [ From fc5bd670fd7f9c2ecf5fad1ee6cd211bec6072bf Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:53:49 +0100 Subject: [PATCH 18/40] Update translation_UK.json --- Translations/translation_UK.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 975cc0c6..7bbc6f6c 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -271,7 +271,7 @@ "LockingMode": { "text2": [ "Дозволити", - "блокування кнопок" + "блок. кнопок" ], "desc": "Під час пайки тривале натискання обох кнопок заблокує їх <В=Вимк, Т=Тільки турбо, П=Повне>" } From 6342e594d85a7372d2d9d7d5c62a9664adae39c9 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:54:32 +0100 Subject: [PATCH 19/40] Update translation_UK.json --- Translations/translation_UK.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 7bbc6f6c..c3045fe5 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -252,7 +252,7 @@ "Пульс.", "Навантаж." ], - "desc": "Деякі PowerBank-и з часом вимк. живлення, якщо пристрій споживає дуже мало енергії (це потрібно щоб паяльник не вимкнувся з часом)" + "desc": "Деякі PowerBank-и з часом вимк. живлення, якщо пристрій споживає дуже мало енергії)" }, "TipGain": { "text2": [ From fbad20746f8a3b6dcd7e113862397971d20c34d6 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:56:04 +0100 Subject: [PATCH 20/40] Update translation_UK.json --- Translations/translation_UK.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index c3045fe5..938810f8 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -88,7 +88,7 @@ }, "SleepTemperature": { "text2": [ - "Температура", + "Темпер.", "сну" ], "desc": "Температура режиму очікування " @@ -257,7 +257,7 @@ "TipGain": { "text2": [ "Змінити", - "підсилею жала" + "підсил. жала" ], "desc": "Підсилення жала" }, From 2e57306431adeb70017e10326cab3c0e7fa7ed0f Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 14:57:22 +0100 Subject: [PATCH 21/40] Update translation_UK.json --- Translations/translation_UK.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 938810f8..1ea72484 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -221,8 +221,8 @@ }, "PowerLimit": { "text2": [ - "Максимальна", - "потужність" + "Макс.", + "потуж." ], "desc": "Макс. потужність, яку може використовувати паяльник <Ват>" }, From 746bba9da6c90b594d564e6dd9b171b1f2594f6f Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 15:05:07 +0100 Subject: [PATCH 22/40] Update translation_UK.json --- Translations/translation_UK.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 1ea72484..5f3f9666 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -137,7 +137,7 @@ }, "BoostTemperature": { "text2": [ - "Температура", + "Темпер.", "Турбо" ], "desc": "Температура в \"Турбо\" режимі" From 5625e60d19e93742d8ca6b0d7011e0aec7d0d7a5 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 15:10:24 +0100 Subject: [PATCH 23/40] Update translation_UK.json --- Translations/translation_UK.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 5f3f9666..e508150d 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -21,7 +21,7 @@ "TipDisconnectedString": "Жало вимкнено!", "SolderingAdvancedPowerPrompt": "Живлення: ", "OffString": "Вимк", - "ResetOKMessage": "Скидання OK", + "ResetOKMessage": "Скид. OK", "YourGainMessage": "Приріст:", "SettingsResetMessage": "Налаштування\nскинуті!", "NoAccelerometerMessage": "Акселерометр\nне виявлено!", From 038542b2fb9ed1dfcae979af9648850a1e5737dd Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sat, 6 Mar 2021 15:17:55 +0100 Subject: [PATCH 24/40] Update translation_UK.json --- Translations/translation_UK.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index e508150d..bc86fedd 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -26,9 +26,9 @@ "SettingsResetMessage": "Налаштування\nскинуті!", "NoAccelerometerMessage": "Акселерометр\nне виявлено!", "NoPowerDeliveryMessage": "USB-PD IC\nне виявлено!", - "LockingKeysString": " ЗАБЛОКОВАНО", - "UnlockingKeysString": "РОЗБЛОКОВАНО", - "WarningKeysLockedString": "!ЗАБЛОКОВАНО!" + "LockingKeysString": " ЗАБЛОК.", + "UnlockingKeysString": "РОЗБЛОК.", + "WarningKeysLockedString": "!ЗАБЛОК!" }, "characters": { "SettingRightChar": "П", From def2aa89fd09d048abcb77ad4afc8b11d665d889 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sun, 7 Mar 2021 11:34:04 +0100 Subject: [PATCH 25/40] Add more voltage settings --- Translations/make_translation.py | 1 + Translations/translation_BG.json | 14 +++++ Translations/translation_CS.json | 14 +++++ Translations/translation_DA.json | 14 +++++ Translations/translation_DE.json | 14 +++++ Translations/translation_EN.json | 14 +++++ Translations/translation_ES.json | 14 +++++ Translations/translation_FI.json | 14 +++++ Translations/translation_FR.json | 14 +++++ Translations/translation_HR.json | 14 +++++ Translations/translation_HU.json | 14 +++++ Translations/translation_IT.json | 14 +++++ Translations/translation_LT.json | 14 +++++ Translations/translation_NL.json | 14 +++++ Translations/translation_NL_BE.json | 14 +++++ Translations/translation_NO.json | 14 +++++ Translations/translation_PL.json | 14 +++++ Translations/translation_PT.json | 14 +++++ Translations/translation_RU.json | 14 +++++ Translations/translation_SK.json | 14 +++++ Translations/translation_SL.json | 14 +++++ Translations/translation_SR_CYRL.json | 14 +++++ Translations/translation_SR_LATN.json | 14 +++++ Translations/translation_SV.json | 14 +++++ Translations/translation_TR.json | 14 +++++ Translations/translation_UK.json | 14 +++++ Translations/translation_YUE_HK.json | 14 +++++ Translations/translation_ZH_TW.json | 14 +++++ Translations/translations_def.js | 15 ++++- source/Core/Drivers/Font.h | 36 ++++++++++++ source/Core/Inc/Settings.h | 1 + source/Core/Inc/Translation.h | 3 +- source/Core/Src/Settings.cpp | 3 +- source/Core/Src/gui.cpp | 80 ++++++++++++++++++++------- source/configuration.h | 7 ++- 35 files changed, 498 insertions(+), 26 deletions(-) diff --git a/Translations/make_translation.py b/Translations/make_translation.py index 38171344..68483673 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -100,6 +100,7 @@ def getConstants(): consants.append(("SymbolWatts", "W")) consants.append(("SymbolVolts", "V")) consants.append(("SymbolDC", "DC")) + consants.append(("SymbolNA", "N/A")) consants.append(("SymbolCellCount", "S")) consants.append(("SymbolVersionNumber", buildVersion)) return consants diff --git a/Translations/translation_BG.json b/Translations/translation_BG.json index 3fb24b8e..9d76adc6 100644 --- a/Translations/translation_BG.json +++ b/Translations/translation_BG.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Поялник", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_CS.json b/Translations/translation_CS.json index af1103c9..b5e8f196 100644 --- a/Translations/translation_CS.json +++ b/Translations/translation_CS.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Pájecí", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_DA.json b/Translations/translation_DA.json index b98220a1..8d01757d 100644 --- a/Translations/translation_DA.json +++ b/Translations/translation_DA.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Soldering", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_DE.json b/Translations/translation_DE.json index 34eeae44..3aa14041 100644 --- a/Translations/translation_DE.json +++ b/Translations/translation_DE.json @@ -50,6 +50,13 @@ "SettingLockFullChar": "V" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Löt-", @@ -275,6 +282,13 @@ "sperre" ], "desc": "Langes drücken beider Tasten im Lötmodus sperrt diese " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_EN.json b/Translations/translation_EN.json index d208a386..f24e6ba6 100644 --- a/Translations/translation_EN.json +++ b/Translations/translation_EN.json @@ -50,6 +50,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Soldering", @@ -275,6 +282,13 @@ "buttons" ], "desc": "When soldering, long press both buttons, to lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_ES.json b/Translations/translation_ES.json index 8adca0d9..269bbae8 100644 --- a/Translations/translation_ES.json +++ b/Translations/translation_ES.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Ajustes de", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_FI.json b/Translations/translation_FI.json index d2319978..a9ba9308 100644 --- a/Translations/translation_FI.json +++ b/Translations/translation_FI.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Juotos-", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_FR.json b/Translations/translation_FR.json index a9b7e15e..33c357f0 100644 --- a/Translations/translation_FR.json +++ b/Translations/translation_FR.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "V" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Paramètres", @@ -274,6 +281,13 @@ "capteur effet hall" ], "desc": "Sensibilité du capteur à effet Hall lors de la détection de mise en veille " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_HR.json b/Translations/translation_HR.json index 11f6c884..3b0e08a5 100644 --- a/Translations/translation_HR.json +++ b/Translations/translation_HR.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Postavke", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_HU.json b/Translations/translation_HU.json index 03d549a3..d07f84d6 100644 --- a/Translations/translation_HU.json +++ b/Translations/translation_HU.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "T" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Forrasztási", @@ -274,6 +281,13 @@ "enged." ], "desc": "Forrasztás közben mindkét gombot hosszan lenyomva rögzíti a hőmérsékletet (K=ki B=csak \"boost\" mód T=teljes lezárás)" + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_IT.json b/Translations/translation_IT.json index cd1fd539..6d094fcb 100644 --- a/Translations/translation_IT.json +++ b/Translations/translation_IT.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "C" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Opzioni", @@ -274,6 +281,13 @@ "tasti" ], "desc": "Blocca i tasti durante la modalità Saldatura; tieni premuto entrambi per bloccare/sbloccare " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_LT.json b/Translations/translation_LT.json index 3563bcca..f6736a37 100644 --- a/Translations/translation_LT.json +++ b/Translations/translation_LT.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "V" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Litavimo", @@ -274,6 +281,13 @@ "užraktas" ], "desc": "Lituodami, ilgai paspauskite abu mygtukus, kad juos užrakintumėte " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_NL.json b/Translations/translation_NL.json index d4abf365..ae6de8ed 100644 --- a/Translations/translation_NL.json +++ b/Translations/translation_NL.json @@ -49,6 +49,13 @@ "SettingSensitivityHigh": "H" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Soldeer", @@ -274,6 +281,13 @@ "knoppen" ], "desc": "Tijdens solderen lang op beide knoppen drukken, blokkeert ze. " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_NL_BE.json b/Translations/translation_NL_BE.json index 2713d418..1644e038 100644 --- a/Translations/translation_NL_BE.json +++ b/Translations/translation_NL_BE.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Soldeer", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_NO.json b/Translations/translation_NO.json index fa90ecf4..06996705 100644 --- a/Translations/translation_NO.json +++ b/Translations/translation_NO.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Lodde-", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_PL.json b/Translations/translation_PL.json index 1a92b0f9..6da7e2bb 100644 --- a/Translations/translation_PL.json +++ b/Translations/translation_PL.json @@ -50,6 +50,13 @@ "SettingLockFullChar": "P" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Lutowanie", @@ -275,6 +282,13 @@ "przycisków" ], "desc": "W trybie lutowania, wciśnij oba przyciski aby je zablokować " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_PT.json b/Translations/translation_PT.json index 4bf003d1..d2dcbf63 100644 --- a/Translations/translation_PT.json +++ b/Translations/translation_PT.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Configurações", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index 27e65b31..d6594cc6 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "П" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Параметры", @@ -274,6 +281,13 @@ "блок. кнопок" ], "desc": "При работе длинное нажатие обеих кнопок блокирует их <О=Отключено, Т=Только турбо, П=Полная блокировка>" + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_SK.json b/Translations/translation_SK.json index a53dcae8..d7d7d5d7 100644 --- a/Translations/translation_SK.json +++ b/Translations/translation_SK.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "P" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Nastavenie", @@ -274,6 +281,13 @@ "tlačidiel" ], "desc": "Zamknutie tlačidiel - dlhé stlačenie oboch naraz počas spájkovania " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_SL.json b/Translations/translation_SL.json index 2f7c6a90..1fbde992 100644 --- a/Translations/translation_SL.json +++ b/Translations/translation_SL.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "P" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Nastavitve", @@ -274,6 +281,13 @@ "zaklep gumbov" ], "desc": "Za zaklep med spajkanjem drži oba gumba " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_SR_CYRL.json b/Translations/translation_SR_CYRL.json index 9fa61a14..06a98425 100644 --- a/Translations/translation_SR_CYRL.json +++ b/Translations/translation_SR_CYRL.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Поставке", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_SR_LATN.json b/Translations/translation_SR_LATN.json index 43e64b7d..1dbc82a8 100644 --- a/Translations/translation_SR_LATN.json +++ b/Translations/translation_SR_LATN.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Postavke", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_SV.json b/Translations/translation_SV.json index a3411b75..ea2af8bb 100644 --- a/Translations/translation_SV.json +++ b/Translations/translation_SV.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Lödnings-", @@ -274,6 +281,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_TR.json b/Translations/translation_TR.json index 8c0f3881..cee79539 100644 --- a/Translations/translation_TR.json +++ b/Translations/translation_TR.json @@ -46,6 +46,13 @@ "SettingLockFullChar": "F" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Lehimleme", @@ -292,6 +299,13 @@ "locking" ], "desc": "When soldering, long press on both buttons lock them " + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } \ No newline at end of file diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index bc86fedd..2382245a 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -49,6 +49,13 @@ "SettingLockFullChar": "П" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "Параметри", @@ -274,6 +281,13 @@ "блок. кнопок" ], "desc": "Під час пайки тривале натискання обох кнопок заблокує їх <В=Вимк, Т=Тільки турбо, П=Повне>" + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_YUE_HK.json b/Translations/translation_YUE_HK.json index a79691e6..2417e771 100644 --- a/Translations/translation_YUE_HK.json +++ b/Translations/translation_YUE_HK.json @@ -50,6 +50,13 @@ "SettingLockFullChar": "全" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "", @@ -275,6 +282,13 @@ "撳掣鎖定" ], "desc": "喺焊接模式時,同時長撳兩粒掣啓用撳掣鎖定 <無=停用 | 增=只鎖定增熱模式 | 全=鎖定全部>" + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translation_ZH_TW.json b/Translations/translation_ZH_TW.json index 02c39d66..9142b004 100644 --- a/Translations/translation_ZH_TW.json +++ b/Translations/translation_ZH_TW.json @@ -50,6 +50,13 @@ "SettingLockFullChar": "全" }, "menuGroups": { + "PowerMenu": { + "text2": [ + "Power", + "settings" + ], + "desc": "Power settings" + }, "SolderingMenu": { "text2": [ "", @@ -275,6 +282,13 @@ "按鍵鎖定" ], "desc": "於焊接模式時,同時長按兩個按鍵啟用按鍵鎖定 <無=停用 | 增=只鎖定增熱模式 | 全=鎖定全部>" + }, + "MinVolCell": { + "text2": [ + "Maximum", + "voltage" + ], + "desc": "Minimum allowed voltage per cell" } } } diff --git a/Translations/translations_def.js b/Translations/translations_def.js index 82cc9ff0..c4f265f6 100644 --- a/Translations/translations_def.js +++ b/Translations/translations_def.js @@ -173,7 +173,8 @@ var def = { "id": "SettingSensitivityHigh", "len": 1 - }, { + }, + { "id": "SettingLockDisableChar", "len": 1, "default": "D" @@ -190,6 +191,10 @@ var def = } ], "menuGroups": [ + { + "id": "PowerMenu", + "maxLen": 11 + }, { "id": "SolderingMenu", "maxLen": 11 @@ -342,10 +347,16 @@ var def = "id": "HallEffSensitivity", "maxLen": 6, "maxLen2": 8 - }, { + }, + { "id": "LockingMode", "maxLen": 6, "maxLen2": 13 + }, + { + "id": "MinVolCell", + "maxLen": 4, + "maxLen2": 9 } ] } diff --git a/source/Core/Drivers/Font.h b/source/Core/Drivers/Font.h index 5ada9fd4..c6b5180e 100644 --- a/source/Core/Drivers/Font.h +++ b/source/Core/Drivers/Font.h @@ -150,6 +150,42 @@ const uint8_t disconnectedTipIcon[] = { * */ const uint8_t SettingsMenuIcons[] = { + // Power + // width = 16 + // height = 16 + 0xC0, + 0xB0, + 0x8C, + 0x83, + 0x01, + 0x01, + 0x21, + 0x31, + 0xA9, + 0x65, + 0x03, + 0x42, + 0x62, + 0x52, + 0xCA, + 0x06, + 0x60, + 0x58, + 0x26, + 0x11, + 0x08, + 0xC4, + 0xB2, + 0x4D, + 0x23, + 0x10, + 0x08, + 0x04, + 0x02, + 0x01, + 0x00, + 0x00, + // Soldering // width = 16 // height = 16 diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index fecc42f4..c71975f7 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -25,6 +25,7 @@ typedef struct { uint16_t SleepTemp; // temp to drop to in sleep uint8_t SleepTime; // minutes timeout to sleep uint8_t minDCVoltageCells; // The voltage we cut out at for under voltage when powered by DC jack + uint8_t minVoltageCells; // Minimum allowed voltage per cell <3S - 3.0V (30)> <4S - 2.4V (24)> <...> (Minimum recommended 2.7V) uint8_t QCIdealVoltage; // Desired QC3.0 voltage (9,12,20V) uint8_t OrientationMode : 2; // Selects between Auto,Right and left handed layouts uint8_t sensitivity : 4; // Sensitivity of accelerometer (5 bits) diff --git a/source/Core/Inc/Translation.h b/source/Core/Inc/Translation.h index 53855f35..541a8a49 100644 --- a/source/Core/Inc/Translation.h +++ b/source/Core/Inc/Translation.h @@ -14,7 +14,7 @@ extern const bool HasFahrenheit; extern const char *SettingsShortNames[29][2]; extern const char *SettingsDescriptions[29]; -extern const char *SettingsMenuEntries[4]; +extern const char *SettingsMenuEntries[5]; extern const char *SettingsCalibrationDone; extern const char *SettingsCalibrationWarning; @@ -76,6 +76,7 @@ extern const char *SymbolSeconds; extern const char *SymbolWatts; extern const char *SymbolVolts; extern const char *SymbolDC; +extern const char *SymbolNA; extern const char *SymbolCellCount; extern const char *SymbolVersionNumber; diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index acd17b41..3cdc8296 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -46,7 +46,7 @@ uint8_t lookupVoltageLevel() { if (systemSettings.minDCVoltageCells == 0) return 90; // 9V since iron does not function effectively below this else - return (systemSettings.minDCVoltageCells * 33) + (33 * 2); + return (systemSettings.minDCVoltageCells * systemSettings.minVoltageCells) + (systemSettings.minVoltageCells * 2); } void resetSettings() { memset((void *)&systemSettings, 0, sizeof(systemSettingsType)); @@ -55,6 +55,7 @@ void resetSettings() { // to sleep - default 1 min systemSettings.SolderingTemp = SOLDERING_TEMP; // Default soldering temp is 320.0 C systemSettings.minDCVoltageCells = CUT_OUT_SETTING; // default to no cut-off voltage + systemSettings.minVoltageCells = RECOM_VOL_CELL; // Minimum voltage per cell (Recommended 3.3V (33)) systemSettings.QCIdealVoltage = 0; // Default to 9V for QC3.0 Voltage systemSettings.version = SETTINGSVERSION; // Store the version number to allow for easier upgrades systemSettings.detailedSoldering = DETAILED_SOLDERING; // Detailed soldering screen diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 762b9161..3bddfd4f 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -19,6 +19,8 @@ void gui_Menu(const menuitem *menu); #ifdef POW_DC static bool settings_setInputVRange(void); static void settings_displayInputVRange(void); +static bool settings_setInputMinVRange(void); +static void settings_displayInputMinVRange(void); #endif #ifdef POW_QC static bool settings_setQCInputV(void); @@ -73,10 +75,12 @@ static void settings_displayHallEffect(void); static bool settings_setHallEffect(void); #endif // Menu functions -static void settings_displaySolderingMenu(void); -static bool settings_enterSolderingMenu(void); static void settings_displayPowerMenu(void); static bool settings_enterPowerMenu(void); +static void settings_displaySolderingMenu(void); +static bool settings_enterSolderingMenu(void); +static void settings_displayPowerSavingMenu(void); +static bool settings_enterPowerSavingMenu(void); static void settings_displayUIMenu(void); static bool settings_enterUIMenu(void); static void settings_displayAdvancedMenu(void); @@ -84,7 +88,9 @@ static bool settings_enterAdvancedMenu(void); /* * Root Settings Menu * - * Power Source + * Power Menu + * Power Source + * * Soldering * Boost Mode Enabled * Boost Mode Temp @@ -121,26 +127,34 @@ static bool settings_enterAdvancedMenu(void); */ const menuitem rootSettingsMenu[]{ /* - * Power Source + * Power Menu * Soldering Menu * Power Saving Menu * UI Menu * Advanced Menu * Exit */ -#ifdef POW_DC - {(const char *)SettingsDescriptions[0], settings_setInputVRange, settings_displayInputVRange}, /*Voltage input*/ -#endif -#ifdef POW_QC - {(const char *)SettingsDescriptions[19], settings_setQCInputV, settings_displayQCInputV}, /*Voltage input*/ -#endif + {(const char *)NULL, settings_enterPowerMenu, settings_displayPowerMenu}, /*Power*/ {(const char *)NULL, settings_enterSolderingMenu, settings_displaySolderingMenu}, /*Soldering*/ - {(const char *)NULL, settings_enterPowerMenu, settings_displayPowerMenu}, /*Sleep Options Menu*/ + {(const char *)NULL, settings_enterPowerSavingMenu, settings_displayPowerSavingMenu}, /*Sleep Options Menu*/ {(const char *)NULL, settings_enterUIMenu, settings_displayUIMenu}, /*UI Menu*/ {(const char *)NULL, settings_enterAdvancedMenu, settings_displayAdvancedMenu}, /*Advanced Menu*/ {NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE }; +const menuitem powerMenu[] = { + /* + * Power Source + */ +#ifdef POW_DC + {(const char *)SettingsDescriptions[0], settings_setInputVRange, settings_displayInputVRange}, /*Voltage input*/ + {(const char *)SettingsDescriptions[28], settings_setInputMinVRange, settings_displayInputMinVRange}, /*Minimum voltage input*/ +#endif +#ifdef POW_QC + {(const char *)SettingsDescriptions[19], settings_setQCInputV, settings_displayQCInputV}, /*Voltage input*/ +#endif + {NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE +}; const menuitem solderingMenu[] = { /* * Boost Mode Enabled @@ -173,7 +187,7 @@ const menuitem UIMenu[] = { {(const char *)SettingsDescriptions[21], settings_setReverseButtonTempChangeEnabled, settings_displayReverseButtonTempChangeEnabled}, /* Reverse Temp change buttons + - */ {NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE }; -const menuitem PowerMenu[] = { +const menuitem PowerSavingMenu[] = { /* * Sleep Temp * Sleep Time @@ -294,7 +308,9 @@ static int userConfirmation(const char *message) { #ifdef POW_DC static bool settings_setInputVRange(void) { systemSettings.minDCVoltageCells = (systemSettings.minDCVoltageCells + 1) % 5; - return systemSettings.minDCVoltageCells == 4; + if (systemSettings.minDCVoltageCells == 1 && systemSettings.minVoltageCells < 30) + systemSettings.minVoltageCells = 30; + return systemSettings.minDCVoltageCells == 5; } static void settings_displayInputVRange(void) { @@ -307,6 +323,27 @@ static void settings_displayInputVRange(void) { OLED::print(SymbolDC); } } + +static bool settings_setInputMinVRange(void) { + systemSettings.minVoltageCells = (systemSettings.minVoltageCells + 1) % 38; + if (systemSettings.minDCVoltageCells == 1 && systemSettings.minVoltageCells < 30) + systemSettings.minVoltageCells = 30; + else if(systemSettings.minVoltageCells < 24) + systemSettings.minVoltageCells = 24; + return systemSettings.minVoltageCells == 38; +} + +static void settings_displayInputMinVRange(void) { + if (systemSettings.minDCVoltageCells) { + printShortDescription(28, 4); + OLED::printNumber(systemSettings.minVoltageCells / 10, 2); + OLED::print(SymbolDot); + OLED::printNumber(systemSettings.minVoltageCells % 10, 1); + } else { + printShortDescription(28, 5); + OLED::print(SymbolNA); + } +} #endif #ifdef POW_QC static bool settings_setQCInputV(void) { @@ -904,22 +941,27 @@ static void displayMenu(size_t index) { } static void settings_displayCalibrateVIN(void) { printShortDescription(13, 5); } -static void settings_displaySolderingMenu(void) { displayMenu(0); } +static void settings_displayPowerMenu(void) { displayMenu(0); } +static bool settings_enterPowerMenu(void) { + gui_Menu(powerMenu); + return false; +} +static void settings_displaySolderingMenu(void) { displayMenu(1); } static bool settings_enterSolderingMenu(void) { gui_Menu(solderingMenu); return false; } -static void settings_displayPowerMenu(void) { displayMenu(1); } -static bool settings_enterPowerMenu(void) { - gui_Menu(PowerMenu); +static void settings_displayPowerSavingMenu(void) { displayMenu(2); } +static bool settings_enterPowerSavingMenu(void) { + gui_Menu(PowerSavingMenu); return false; } -static void settings_displayUIMenu(void) { displayMenu(2); } +static void settings_displayUIMenu(void) { displayMenu(3); } static bool settings_enterUIMenu(void) { gui_Menu(HasFahrenheit ? UIMenu : UIMenu + 1); return false; } -static void settings_displayAdvancedMenu(void) { displayMenu(3); } +static void settings_displayAdvancedMenu(void) { displayMenu(4); } static bool settings_enterAdvancedMenu(void) { gui_Menu(advancedMenu); return false; diff --git a/source/configuration.h b/source/configuration.h index 6ae7d372..a326dfc8 100644 --- a/source/configuration.h +++ b/source/configuration.h @@ -88,9 +88,10 @@ #define DETAILED_SOLDERING 0 // 0: Disable 1: Enable - Default 0 #define DETAILED_IDLE 0 // 0: Disable 1: Enable - Default 0 -#define CUT_OUT_SETTING 0 // default to no cut-off voltage -#define TEMPERATURE_INF 0 // default to 0 -#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow +#define CUT_OUT_SETTING 0 // default to no cut-off voltage +#define RECOM_VOL_CELL 33 // Minimum voltage per cell (Recommended 3.3V (33)) +#define TEMPERATURE_INF 0 // default to 0 +#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow #define OP_AMP_Rf_TS100 750 * 1000 // 750 Kilo-ohms -> From schematic, R1 #define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2 From 9e77b84a14d188d6651b9fc0a1e40d2eabe1c477 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sun, 7 Mar 2021 11:41:00 +0100 Subject: [PATCH 26/40] Increment settings version --- source/Core/Inc/Settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index c71975f7..828fa334 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -10,7 +10,7 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ #include -#define SETTINGSVERSION (0x25) +#define SETTINGSVERSION (0x26) /*Change this if you change the struct below to prevent people getting \ out of sync*/ From b5b60dfb1ed72aac7e9d49821823eb25dbea7438 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Sun, 7 Mar 2021 14:00:07 +0100 Subject: [PATCH 27/40] Create Power.jpg --- Development Resources/Images/Power.jpg | Bin 0 -> 1082 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Development Resources/Images/Power.jpg diff --git a/Development Resources/Images/Power.jpg b/Development Resources/Images/Power.jpg new file mode 100644 index 0000000000000000000000000000000000000000..340b2bce3da4a35568f69482495e18a3c009beec GIT binary patch literal 1082 zcmex=O1eh6>7?=bZ znFSgDA7PMZU|?j0n9TqMj7-cdtZeKYoLt;M1zQCem>8LvnOK-vSy@`H|qMvW5}awt1(JSZA;@q>zSQc)8pmzcPOq?D?fx`w8fiK&^ng{76V zi>sTvho@I?NN8AiL}XNQN@`kqMrKxVNoiSmMP*fUOKV$uM`zch$y26In?7UatVN5L zEM2yI#mZHiHgDOwZTpU$yAB;ba`f2o6DLnyx_ss8wd*%--g@}x@sp>|p1*kc>f@)+ zU%r0({^RE_kiQrinBhSN@fe!F1cClyVqsxsVF&q(k*OSrnFU!`6%E;h90S=C3x$=8 z8aYIqCNA7~kW<+>=!0ld(M2vX6_bamA3 z`p17sh4qp7TmAd~$SM)bpf zhPRRr-pkbJeQ19h`nX;u{Cb`FkLKU8S@Gianf$_k0zT%yVf~%^qxu`$k6N>dA1;3@ z`nyQ4KB@oK=5Kp`tbF*NfuTn5T7B01j$8J}{LjE_pL(A^^PcHP|2KgL{_yaLi}fAIUyaPxQkkJlfCkHvHB)2%4-Z>Z;YYc7AdU-(bekGD(fF6`&8 ziC_4`bf10Qjr&`|yY@-fow?7u|G|P=HdZS0KX}gnq4u`@&EDT0brOxc z^`D`s?4Ls2)%vYUKc)Qkd5PShl>9UN9=|6=j^|=j-Tg0!y)d~|E~XM z5c&F_K}Npw*SVPw Date: Mon, 8 Mar 2021 06:43:20 +0100 Subject: [PATCH 28/40] N/A now translatable --- Translations/make_translation.py | 1 - Translations/translation_BG.json | 3 ++- Translations/translation_CS.json | 3 ++- Translations/translation_DA.json | 3 ++- Translations/translation_DE.json | 3 ++- Translations/translation_EN.json | 3 ++- Translations/translation_ES.json | 3 ++- Translations/translation_FI.json | 3 ++- Translations/translation_FR.json | 3 ++- Translations/translation_HR.json | 3 ++- Translations/translation_HU.json | 3 ++- Translations/translation_IT.json | 3 ++- Translations/translation_LT.json | 3 ++- Translations/translation_NL.json | 3 ++- Translations/translation_NL_BE.json | 3 ++- Translations/translation_NO.json | 3 ++- Translations/translation_PL.json | 3 ++- Translations/translation_PT.json | 3 ++- Translations/translation_RU.json | 3 ++- Translations/translation_SK.json | 3 ++- Translations/translation_SL.json | 3 ++- Translations/translation_SR_CYRL.json | 3 ++- Translations/translation_SR_LATN.json | 3 ++- Translations/translation_SV.json | 3 ++- Translations/translation_TR.json | 3 ++- Translations/translation_UK.json | 3 ++- Translations/translation_YUE_HK.json | 3 ++- Translations/translation_ZH_TW.json | 3 ++- Translations/translations_def.js | 5 +++++ source/Core/Inc/Translation.h | 2 +- source/Core/Src/gui.cpp | 4 ++-- 31 files changed, 62 insertions(+), 31 deletions(-) diff --git a/Translations/make_translation.py b/Translations/make_translation.py index 68483673..38171344 100755 --- a/Translations/make_translation.py +++ b/Translations/make_translation.py @@ -100,7 +100,6 @@ def getConstants(): consants.append(("SymbolWatts", "W")) consants.append(("SymbolVolts", "V")) consants.append(("SymbolDC", "DC")) - consants.append(("SymbolNA", "N/A")) consants.append(("SymbolCellCount", "S")) consants.append(("SymbolVersionNumber", buildVersion)) return consants diff --git a/Translations/translation_BG.json b/Translations/translation_BG.json index 9d76adc6..0171ca8c 100644 --- a/Translations/translation_BG.json +++ b/Translations/translation_BG.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_CS.json b/Translations/translation_CS.json index b5e8f196..2e25de02 100644 --- a/Translations/translation_CS.json +++ b/Translations/translation_CS.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_DA.json b/Translations/translation_DA.json index 8d01757d..a136823d 100644 --- a/Translations/translation_DA.json +++ b/Translations/translation_DA.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_DE.json b/Translations/translation_DE.json index 3aa14041..a6da3d8a 100644 --- a/Translations/translation_DE.json +++ b/Translations/translation_DE.json @@ -47,7 +47,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "V" + "SettingLockFullChar": "V", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_EN.json b/Translations/translation_EN.json index f24e6ba6..18fecfee 100644 --- a/Translations/translation_EN.json +++ b/Translations/translation_EN.json @@ -47,7 +47,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_ES.json b/Translations/translation_ES.json index 269bbae8..a7ef28e5 100644 --- a/Translations/translation_ES.json +++ b/Translations/translation_ES.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_FI.json b/Translations/translation_FI.json index a9ba9308..068579c3 100644 --- a/Translations/translation_FI.json +++ b/Translations/translation_FI.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_FR.json b/Translations/translation_FR.json index 33c357f0..9c8de52c 100644 --- a/Translations/translation_FR.json +++ b/Translations/translation_FR.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "V" + "SettingLockFullChar": "V", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_HR.json b/Translations/translation_HR.json index 3b0e08a5..99f540b3 100644 --- a/Translations/translation_HR.json +++ b/Translations/translation_HR.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_HU.json b/Translations/translation_HU.json index d07f84d6..526846d6 100644 --- a/Translations/translation_HU.json +++ b/Translations/translation_HU.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "M", "SettingLockDisableChar": "K", "SettingLockBoostChar": "B", - "SettingLockFullChar": "T" + "SettingLockFullChar": "T", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_IT.json b/Translations/translation_IT.json index 6d094fcb..fbd6d966 100644 --- a/Translations/translation_IT.json +++ b/Translations/translation_IT.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "A", "SettingLockDisableChar": "D", "SettingLockBoostChar": "T", - "SettingLockFullChar": "C" + "SettingLockFullChar": "C", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_LT.json b/Translations/translation_LT.json index f6736a37..7af113d2 100644 --- a/Translations/translation_LT.json +++ b/Translations/translation_LT.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "A", "SettingLockDisableChar": "I", "SettingLockBoostChar": "T", - "SettingLockFullChar": "V" + "SettingLockFullChar": "V", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_NL.json b/Translations/translation_NL.json index ae6de8ed..1fed8f36 100644 --- a/Translations/translation_NL.json +++ b/Translations/translation_NL.json @@ -46,7 +46,8 @@ "SettingSensitivityOff": "O", "SettingSensitivityLow": "L", "SettingSensitivityMedium": "M", - "SettingSensitivityHigh": "H" + "SettingSensitivityHigh": "H", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_NL_BE.json b/Translations/translation_NL_BE.json index 1644e038..512118c4 100644 --- a/Translations/translation_NL_BE.json +++ b/Translations/translation_NL_BE.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_NO.json b/Translations/translation_NO.json index 06996705..393a3b92 100644 --- a/Translations/translation_NO.json +++ b/Translations/translation_NO.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_PL.json b/Translations/translation_PL.json index 6da7e2bb..8f114f3f 100644 --- a/Translations/translation_PL.json +++ b/Translations/translation_PL.json @@ -47,7 +47,8 @@ "SettingSensitivityHigh": "W", "SettingLockDisableChar": "W", "SettingLockBoostChar": "B", - "SettingLockFullChar": "P" + "SettingLockFullChar": "P", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_PT.json b/Translations/translation_PT.json index d2dcbf63..be6184b3 100644 --- a/Translations/translation_PT.json +++ b/Translations/translation_PT.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index d6594cc6..07a9796f 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "В", "SettingLockDisableChar": "О", "SettingLockBoostChar": "Т", - "SettingLockFullChar": "П" + "SettingLockFullChar": "П", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_SK.json b/Translations/translation_SK.json index d7d7d5d7..9f3dff08 100644 --- a/Translations/translation_SK.json +++ b/Translations/translation_SK.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "V", "SettingLockDisableChar": "Z", "SettingLockBoostChar": "B", - "SettingLockFullChar": "P" + "SettingLockFullChar": "P", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_SL.json b/Translations/translation_SL.json index 1fbde992..bd4e653a 100644 --- a/Translations/translation_SL.json +++ b/Translations/translation_SL.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "V", "SettingLockDisableChar": "O", "SettingLockBoostChar": "L", - "SettingLockFullChar": "P" + "SettingLockFullChar": "P", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_SR_CYRL.json b/Translations/translation_SR_CYRL.json index 06a98425..3486f423 100644 --- a/Translations/translation_SR_CYRL.json +++ b/Translations/translation_SR_CYRL.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_SR_LATN.json b/Translations/translation_SR_LATN.json index 1dbc82a8..e10e5624 100644 --- a/Translations/translation_SR_LATN.json +++ b/Translations/translation_SR_LATN.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_SV.json b/Translations/translation_SV.json index ea2af8bb..7accc0f4 100644 --- a/Translations/translation_SV.json +++ b/Translations/translation_SV.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_TR.json b/Translations/translation_TR.json index cee79539..17e38d9f 100644 --- a/Translations/translation_TR.json +++ b/Translations/translation_TR.json @@ -43,7 +43,8 @@ "SettingSensitivityHigh": "H", "SettingLockDisableChar": "D", "SettingLockBoostChar": "B", - "SettingLockFullChar": "F" + "SettingLockFullChar": "F", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 2382245a..64e86186 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -46,7 +46,8 @@ "SettingSensitivityHigh": "М", "SettingLockDisableChar": "В", "SettingLockBoostChar": "Т", - "SettingLockFullChar": "П" + "SettingLockFullChar": "П", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_YUE_HK.json b/Translations/translation_YUE_HK.json index 2417e771..bc6e05c1 100644 --- a/Translations/translation_YUE_HK.json +++ b/Translations/translation_YUE_HK.json @@ -47,7 +47,8 @@ "SettingSensitivityHigh": "高", "SettingLockDisableChar": "無", "SettingLockBoostChar": "增", - "SettingLockFullChar": "全" + "SettingLockFullChar": "全", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translation_ZH_TW.json b/Translations/translation_ZH_TW.json index 9142b004..93157208 100644 --- a/Translations/translation_ZH_TW.json +++ b/Translations/translation_ZH_TW.json @@ -47,7 +47,8 @@ "SettingSensitivityHigh": "高", "SettingLockDisableChar": "無", "SettingLockBoostChar": "增", - "SettingLockFullChar": "全" + "SettingLockFullChar": "全", + "SettingNAChar": "N/A" }, "menuGroups": { "PowerMenu": { diff --git a/Translations/translations_def.js b/Translations/translations_def.js index c4f265f6..c9a5961a 100644 --- a/Translations/translations_def.js +++ b/Translations/translations_def.js @@ -188,6 +188,11 @@ var def = "id": "SettingLockFullChar", "len": 1, "default": "F" + }, + { + "id": "SettingNAChar", + "len": 3, + "default": "N/A" } ], "menuGroups": [ diff --git a/source/Core/Inc/Translation.h b/source/Core/Inc/Translation.h index 541a8a49..21507b8c 100644 --- a/source/Core/Inc/Translation.h +++ b/source/Core/Inc/Translation.h @@ -60,6 +60,7 @@ extern const char *SettingSensitivityHigh; extern const char *SettingLockDisableChar; extern const char *SettingLockBoostChar; extern const char *SettingLockFullChar; +extern const char *SettingNAChar; extern const char *SettingFastChar; extern const char *SettingSlowChar; @@ -76,7 +77,6 @@ extern const char *SymbolSeconds; extern const char *SymbolWatts; extern const char *SymbolVolts; extern const char *SymbolDC; -extern const char *SymbolNA; extern const char *SymbolCellCount; extern const char *SymbolVersionNumber; diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 3bddfd4f..945eab36 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -90,7 +90,7 @@ static bool settings_enterAdvancedMenu(void); * * Power Menu * Power Source - * + * * Soldering * Boost Mode Enabled * Boost Mode Temp @@ -341,7 +341,7 @@ static void settings_displayInputMinVRange(void) { OLED::printNumber(systemSettings.minVoltageCells % 10, 1); } else { printShortDescription(28, 5); - OLED::print(SymbolNA); + OLED::print(SettingNAChar); } } #endif From 783b14eeb6d26b9605c2b0e10d482343e1dc9bf9 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 11:36:06 +0100 Subject: [PATCH 29/40] Maximum -> Minimum --- Translations/translation_BG.json | 2 +- Translations/translation_CS.json | 2 +- Translations/translation_DA.json | 2 +- Translations/translation_DE.json | 2 +- Translations/translation_EN.json | 2 +- Translations/translation_ES.json | 2 +- Translations/translation_FI.json | 2 +- Translations/translation_FR.json | 2 +- Translations/translation_HR.json | 2 +- Translations/translation_HU.json | 2 +- Translations/translation_IT.json | 2 +- Translations/translation_LT.json | 2 +- Translations/translation_NL.json | 2 +- Translations/translation_NL_BE.json | 2 +- Translations/translation_NO.json | 2 +- Translations/translation_PL.json | 2 +- Translations/translation_PT.json | 2 +- Translations/translation_RU.json | 2 +- Translations/translation_SK.json | 2 +- Translations/translation_SL.json | 2 +- Translations/translation_SR_CYRL.json | 2 +- Translations/translation_SR_LATN.json | 2 +- Translations/translation_SV.json | 2 +- Translations/translation_TR.json | 2 +- Translations/translation_UK.json | 2 +- Translations/translation_YUE_HK.json | 2 +- Translations/translation_ZH_TW.json | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Translations/translation_BG.json b/Translations/translation_BG.json index 0171ca8c..c59cede6 100644 --- a/Translations/translation_BG.json +++ b/Translations/translation_BG.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_CS.json b/Translations/translation_CS.json index 2e25de02..8b373f51 100644 --- a/Translations/translation_CS.json +++ b/Translations/translation_CS.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_DA.json b/Translations/translation_DA.json index a136823d..0859c233 100644 --- a/Translations/translation_DA.json +++ b/Translations/translation_DA.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_DE.json b/Translations/translation_DE.json index a6da3d8a..2bb581e8 100644 --- a/Translations/translation_DE.json +++ b/Translations/translation_DE.json @@ -286,7 +286,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_EN.json b/Translations/translation_EN.json index 18fecfee..2697bf4b 100644 --- a/Translations/translation_EN.json +++ b/Translations/translation_EN.json @@ -286,7 +286,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_ES.json b/Translations/translation_ES.json index a7ef28e5..fb89fcc9 100644 --- a/Translations/translation_ES.json +++ b/Translations/translation_ES.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_FI.json b/Translations/translation_FI.json index 068579c3..8d10536c 100644 --- a/Translations/translation_FI.json +++ b/Translations/translation_FI.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_FR.json b/Translations/translation_FR.json index 9c8de52c..7365479c 100644 --- a/Translations/translation_FR.json +++ b/Translations/translation_FR.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_HR.json b/Translations/translation_HR.json index 99f540b3..1158c034 100644 --- a/Translations/translation_HR.json +++ b/Translations/translation_HR.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_HU.json b/Translations/translation_HU.json index 526846d6..612f6407 100644 --- a/Translations/translation_HU.json +++ b/Translations/translation_HU.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_IT.json b/Translations/translation_IT.json index fbd6d966..80ef7886 100644 --- a/Translations/translation_IT.json +++ b/Translations/translation_IT.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_LT.json b/Translations/translation_LT.json index 7af113d2..c25d5fea 100644 --- a/Translations/translation_LT.json +++ b/Translations/translation_LT.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_NL.json b/Translations/translation_NL.json index 1fed8f36..c3d59735 100644 --- a/Translations/translation_NL.json +++ b/Translations/translation_NL.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_NL_BE.json b/Translations/translation_NL_BE.json index 512118c4..90cdea43 100644 --- a/Translations/translation_NL_BE.json +++ b/Translations/translation_NL_BE.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_NO.json b/Translations/translation_NO.json index 393a3b92..990e1c83 100644 --- a/Translations/translation_NO.json +++ b/Translations/translation_NO.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_PL.json b/Translations/translation_PL.json index 8f114f3f..0b820b45 100644 --- a/Translations/translation_PL.json +++ b/Translations/translation_PL.json @@ -286,7 +286,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_PT.json b/Translations/translation_PT.json index be6184b3..ab24e50d 100644 --- a/Translations/translation_PT.json +++ b/Translations/translation_PT.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index 07a9796f..49f7240b 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_SK.json b/Translations/translation_SK.json index 9f3dff08..3a7058bf 100644 --- a/Translations/translation_SK.json +++ b/Translations/translation_SK.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_SL.json b/Translations/translation_SL.json index bd4e653a..afe9666c 100644 --- a/Translations/translation_SL.json +++ b/Translations/translation_SL.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_SR_CYRL.json b/Translations/translation_SR_CYRL.json index 3486f423..5c85fc9b 100644 --- a/Translations/translation_SR_CYRL.json +++ b/Translations/translation_SR_CYRL.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_SR_LATN.json b/Translations/translation_SR_LATN.json index e10e5624..5b38c369 100644 --- a/Translations/translation_SR_LATN.json +++ b/Translations/translation_SR_LATN.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_SV.json b/Translations/translation_SV.json index 7accc0f4..a2c58cd8 100644 --- a/Translations/translation_SV.json +++ b/Translations/translation_SV.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_TR.json b/Translations/translation_TR.json index 17e38d9f..cf09370a 100644 --- a/Translations/translation_TR.json +++ b/Translations/translation_TR.json @@ -303,7 +303,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 64e86186..6a17ec53 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -285,7 +285,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_YUE_HK.json b/Translations/translation_YUE_HK.json index bc6e05c1..4b3b7eed 100644 --- a/Translations/translation_YUE_HK.json +++ b/Translations/translation_YUE_HK.json @@ -286,7 +286,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" diff --git a/Translations/translation_ZH_TW.json b/Translations/translation_ZH_TW.json index 93157208..841c1fca 100644 --- a/Translations/translation_ZH_TW.json +++ b/Translations/translation_ZH_TW.json @@ -286,7 +286,7 @@ }, "MinVolCell": { "text2": [ - "Maximum", + "Minimum", "voltage" ], "desc": "Minimum allowed voltage per cell" From f6b53fedf3d4e01dae2af4aeb9da81c2fcc36535 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Mon, 8 Mar 2021 21:42:10 +1100 Subject: [PATCH 30/40] Prep release 2.15 --- source/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/version.h b/source/version.h index 96fba0c7..c7d32e68 100644 --- a/source/version.h +++ b/source/version.h @@ -4,4 +4,4 @@ * i.e.: BUILD_VERSION = 'Rel. v2.08' --> Will generated to: 'v2.08.1a2b3c4' */ -#define BUILD_VERSION "v2.14" +#define BUILD_VERSION "v2.15" From 9449ac896e2dc5465fbc805bc89c595b26c0b17b Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:05:40 +0100 Subject: [PATCH 31/40] Fix Battery icon --- source/Core/Threads/GUIThread.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 1fbb14f8..0a04b2f3 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -160,11 +160,11 @@ static void gui_drawBatteryIcon() { uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount; // Should give us approx cell voltage X10 // Range is 42 -> 33 = 9 steps therefore we will use battery 0-9 - if (cellV < 33) - cellV = 33; - cellV -= 33; // Should leave us a number of 0-9 - if (cellV > 9) - cellV = 9; + if (cellV < systemSettings.minVoltageCells) + cellV = systemSettings.minVoltageCells; + cellV -= systemSettings.minVoltageCells; // Should leave us a number of 0-9 + if (cellV > (uint32_t)(42 - systemSettings.minVoltageCells)) + cellV = 42 - systemSettings.minVoltageCells; OLED::drawBattery(cellV + 1); } else { OLED::drawSymbol(15); // Draw the DC Logo From 6a81f92efdecd55288c915ba5cd36ca781b71494 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:12:20 +0100 Subject: [PATCH 32/40] Update GUIThread.cpp --- source/Core/Threads/GUIThread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 0a04b2f3..3c3776c8 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -163,8 +163,8 @@ static void gui_drawBatteryIcon() { if (cellV < systemSettings.minVoltageCells) cellV = systemSettings.minVoltageCells; cellV -= systemSettings.minVoltageCells; // Should leave us a number of 0-9 - if (cellV > (uint32_t)(42 - systemSettings.minVoltageCells)) - cellV = 42 - systemSettings.minVoltageCells; + if (cellV > 9) + cellV = 9; OLED::drawBattery(cellV + 1); } else { OLED::drawSymbol(15); // Draw the DC Logo From c380cab159eaffa2b3065968810a6bd0ede79936 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:15:52 +0100 Subject: [PATCH 33/40] Update GUIThread.cpp --- source/Core/Threads/GUIThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 3c3776c8..f58a1e8c 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -159,7 +159,7 @@ static void gui_drawBatteryIcon() { uint8_t cellCount = systemSettings.minDCVoltageCells + 2; uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0) / cellCount; // Should give us approx cell voltage X10 - // Range is 42 -> 33 = 9 steps therefore we will use battery 0-9 + // Range is 42 -> Minimum voltage setting (systemSettings.minVoltageCells) = 9 steps therefore we will use battery 0-9 if (cellV < systemSettings.minVoltageCells) cellV = systemSettings.minVoltageCells; cellV -= systemSettings.minVoltageCells; // Should leave us a number of 0-9 From dd7d2a4830fff7937f1b5e2a09ce7457a552af3a Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 12:32:25 +0100 Subject: [PATCH 34/40] Update UK, RU and PL languages --- Translations/translation_PL.json | 14 +++++++------- Translations/translation_RU.json | 14 +++++++------- Translations/translation_UK.json | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Translations/translation_PL.json b/Translations/translation_PL.json index 0b820b45..2e4c5b96 100644 --- a/Translations/translation_PL.json +++ b/Translations/translation_PL.json @@ -48,15 +48,15 @@ "SettingLockDisableChar": "W", "SettingLockBoostChar": "B", "SettingLockFullChar": "P", - "SettingNAChar": "N/A" + "SettingNAChar": "N/D" }, "menuGroups": { "PowerMenu": { "text2": [ - "Power", - "settings" + "Ustawienia", + "zasilania" ], - "desc": "Power settings" + "desc": "Zasilanie i minimalne napięcie na komórkę" }, "SolderingMenu": { "text2": [ @@ -286,10 +286,10 @@ }, "MinVolCell": { "text2": [ - "Minimum", - "voltage" + "Minimalne", + "napięcie" ], - "desc": "Minimum allowed voltage per cell" + "desc": "Minimalne dozwolone napięcie na komórkę <3S — 3.0V - 3.7V, 4/5/6S — 2.4V - 3.7V>" } } } diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index 49f7240b..5c780d1c 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -47,15 +47,15 @@ "SettingLockDisableChar": "О", "SettingLockBoostChar": "Т", "SettingLockFullChar": "П", - "SettingNAChar": "N/A" + "SettingNAChar": "Н/Д" }, "menuGroups": { "PowerMenu": { "text2": [ - "Power", - "settings" + "Параметры", + "питания" ], - "desc": "Power settings" + "desc": "Источник питания и минимальное напряжение на ячейку" }, "SolderingMenu": { "text2": [ @@ -285,10 +285,10 @@ }, "MinVolCell": { "text2": [ - "Minimum", - "voltage" + "Мин.", + "напр." ], - "desc": "Minimum allowed voltage per cell" + "desc": "Минимальное разрешенное напряжение на ячейку <В вольтах> <3S — 3.0V - 3.7V, 4/5/6S — 2.4V - 3.7V>" } } } diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index 6a17ec53..fcf8d186 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -47,15 +47,15 @@ "SettingLockDisableChar": "В", "SettingLockBoostChar": "Т", "SettingLockFullChar": "П", - "SettingNAChar": "N/A" + "SettingNAChar": "Н/Д" }, "menuGroups": { "PowerMenu": { "text2": [ - "Power", - "settings" + "Параметри", + "живлення" ], - "desc": "Power settings" + "desc": "Джерело живлення, та мінамільна напруга на комірку" }, "SolderingMenu": { "text2": [ @@ -285,10 +285,10 @@ }, "MinVolCell": { "text2": [ - "Minimum", - "voltage" + "Мін.", + "напруга" ], - "desc": "Minimum allowed voltage per cell" + "desc": "Мінімальна дозволена напруга на комірку <В вольтах> <3S — 3.0V - 3.7V, 4/5/6S — 2.4V - 3.7V>" } } } From 75406848657d2b2a3989681f17c54de796eff222 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 13:19:25 +0100 Subject: [PATCH 35/40] Fix scroll blink --- source/Core/Src/gui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index 945eab36..9b9f254f 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -310,7 +310,7 @@ static bool settings_setInputVRange(void) { systemSettings.minDCVoltageCells = (systemSettings.minDCVoltageCells + 1) % 5; if (systemSettings.minDCVoltageCells == 1 && systemSettings.minVoltageCells < 30) systemSettings.minVoltageCells = 30; - return systemSettings.minDCVoltageCells == 5; + return systemSettings.minDCVoltageCells == 4; } static void settings_displayInputVRange(void) { @@ -330,7 +330,7 @@ static bool settings_setInputMinVRange(void) { systemSettings.minVoltageCells = 30; else if(systemSettings.minVoltageCells < 24) systemSettings.minVoltageCells = 24; - return systemSettings.minVoltageCells == 38; + return systemSettings.minVoltageCells == 37; } static void settings_displayInputMinVRange(void) { From 69ffe4948c77dfdd8d6cf8ab4a9dcc0e75935fba Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 15:52:12 +0100 Subject: [PATCH 36/40] Fix text in RU and UK translations --- Translations/translation_RU.json | 2 +- Translations/translation_UK.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index 5c780d1c..29621499 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -7,7 +7,7 @@ "SettingsCalibrationWarning": "Прежде чем продолжить, пожалуйста, убедитесь, что жало имеет комнатную температуру!", "SettingsResetWarning": "Вы уверены, что хотите сбросить настройки к значениям по умолчанию?", "UVLOWarningString": "НАПРЯЖ--", - "UndervoltageString": "Низкое\nнапряжение", + "UndervoltageString": "Низкое напряжение", "InputVoltageString": "Питание В: ", "WarningTipTempString": "Темп. жала: ", "BadTipString": "ЖАЛО--", diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index fcf8d186..38a7c6eb 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -7,7 +7,7 @@ "SettingsCalibrationWarning": "Переконайтеся, що жало охололо до кімнатної температури, перш ніж продовжувати!", "SettingsResetWarning": "Ви дійсно хочете скинути налаштування до значень за замовчуванням? ", "UVLOWarningString": "АККУМ--", - "UndervoltageString": "Низька\nнапруга", + "UndervoltageString": "Низька напруга", "InputVoltageString": "Жив.(B): ", "WarningTipTempString": "Жало t°: ", "BadTipString": "ЖАЛО--", From cb34af357fc0f3aded4a18c3d8a53f4b1acb7332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 8 Mar 2021 19:17:04 +0100 Subject: [PATCH 37/40] translations: track more generation dependencies --- source/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Makefile b/source/Makefile index 95175df5..9636c99c 100644 --- a/source/Makefile +++ b/source/Makefile @@ -319,7 +319,7 @@ $(OUT_OBJS_S): $(OUTPUT_DIR)/%.o: %.S Makefile @echo 'Building file: $<' @$(AS) -c $(AFLAGS) $< -o $@ -Core/Gen/Translation.%.cpp: ../Translations/translation_%.json Makefile ../Translations/make_translation.py ../Translations/translations_commons.js +Core/Gen/Translation.%.cpp: ../Translations/translation_%.json Makefile ../Translations/make_translation.py ../Translations/translations_commons.js ../Translations/fontTables.py ../Translations/wqy-bitmapsong/wenquanyi_9pt.bdf @test -d $(@D) || mkdir -p $(@D) @echo 'Generating translations for language $*' @python3 ../Translations/make_translation.py -o $(PWD)/$@ $* From 7c73b775cbd569cec98a6e6901a45064636d1e83 Mon Sep 17 00:00:00 2001 From: PlayDay <18056374+playday3008@users.noreply.github.com> Date: Mon, 8 Mar 2021 19:39:01 +0100 Subject: [PATCH 38/40] Update fontTables.py --- Translations/fontTables.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Translations/fontTables.py b/Translations/fontTables.py index cd6b83f4..ace27318 100755 --- a/Translations/fontTables.py +++ b/Translations/fontTables.py @@ -10,8 +10,6 @@ def getFontMap(): "&": "0x00,0x00,0x00,0xB8,0xFC,0xC6,0xE2,0x3E,0x1C,0x00,0x00,0x00,0x00,0x00,0x1F,0x3F,0x31,0x21,0x37,0x1E,0x1C,0x36,0x22,0x00,", "'": "0x00,0x00,0x00,0x00,0x27,0x3F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", "(": "0x00,0x00,0x00,0xF0,0xFC,0xFE,0x07,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x1F,0x38,0x20,0x20,0x00,0x00,0x00,", - "(": "0x00,0x00,0x00,0xF0,0xFC,0xFE,0x07,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0x1F,0x38,0x20,0x20,0x00,0x00,0x00,", - ")": "0x00,0x00,0x00,0x01,0x01,0x07,0xFE,0xFC,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x38,0x1F,0x0F,0x03,0x00,0x00,0x00,", ")": "0x00,0x00,0x00,0x01,0x01,0x07,0xFE,0xFC,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x38,0x1F,0x0F,0x03,0x00,0x00,0x00,", "*": "0x00,0x00,0x98,0xB8,0xE0,0xF8,0xF8,0xE0,0xB8,0x98,0x00,0x00,0x00,0x00,0x0C,0x0E,0x03,0x0F,0x0F,0x03,0x0E,0x0C,0x00,0x00,", "+": "0x00,0x00,0x80,0x80,0x80,0xF0,0xF0,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x0F,0x01,0x01,0x01,0x00,0x00,", @@ -23,7 +21,6 @@ def getFontMap(): "1": "0x00,0x00,0x00,0x0C,0x0C,0x0E,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x3F,0x3F,0x30,0x30,0x30,0x00,", "2": "0x00,0x1C,0x1E,0x07,0x03,0x03,0x83,0xC3,0xE3,0x77,0x3E,0x1C,0x00,0x30,0x38,0x3C,0x3E,0x37,0x33,0x31,0x30,0x30,0x30,0x30,", "3": "0x00,0x0C,0x0E,0x07,0xC3,0xC3,0xC3,0xC3,0xC3,0xE7,0x7E,0x3C,0x00,0x0C,0x1C,0x38,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0E,", - "З": "0x00,0x0C,0x0E,0x07,0xC3,0xC3,0xC3,0xC3,0xC3,0xE7,0x7E,0x3C,0x00,0x0C,0x1C,0x38,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0E,", "4": "0x00,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x07,0xFF,0xFF,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x3F,0x3F,0x03,0x03,", "5": "0x00,0x3F,0x7F,0x63,0x63,0x63,0x63,0x63,0x63,0xE3,0xC3,0x83,0x00,0x0C,0x1C,0x38,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x0F,", "6": "0x00,0xC0,0xF0,0xF8,0xDC,0xCE,0xC7,0xC3,0xC3,0xC3,0x80,0x00,0x00,0x0F,0x1F,0x39,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0F,", @@ -31,7 +28,6 @@ def getFontMap(): "8": "0x00,0x00,0xBC,0xFE,0xE7,0xC3,0xC3,0xC3,0xE7,0xFE,0xBC,0x00,0x00,0x0F,0x1F,0x39,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0F,", "9": "0x00,0x3C,0x7E,0xE7,0xC3,0xC3,0xC3,0xC3,0xC3,0xE7,0xFE,0xFC,0x00,0x00,0x00,0x30,0x30,0x30,0x38,0x1C,0x0E,0x07,0x03,0x00,", ":": "0x00,0x00,0x00,0x00,0x70,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,", - ":": "0x00,0x00,0x00,0x00,0x70,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,", ";": "0x00,0x00,0x00,0x00,0x70,0x70,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9C,0xFC,0x7C,0x00,0x00,0x00,0x00,0x00,", "<": "0x00,0x00,0xC0,0xE0,0xF0,0x38,0x1C,0x0E,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00,0x00,", "=": "0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x00,", @@ -39,12 +35,10 @@ def getFontMap(): "?": "0x00,0x1C,0x1E,0x07,0x03,0x83,0xC3,0xE3,0x77,0x3E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x37,0x00,0x00,0x00,0x00,0x00,", "@": "0x00,0xF8,0xFE,0x07,0xF3,0xFB,0x1B,0xFB,0xFB,0x07,0xFE,0xF8,0x00,0x0F,0x1F,0x18,0x33,0x37,0x36,0x37,0x37,0x36,0x03,0x01,", "A": "0x00,0x00,0x00,0xE0,0xFC,0x1F,0x1F,0xFC,0xE0,0x00,0x00,0x00,0x00,0x38,0x3F,0x07,0x06,0x06,0x06,0x06,0x07,0x3F,0x38,0x00,", - "А": "0x00,0x00,0x00,0xE0,0xFC,0x1F,0x1F,0xFC,0xE0,0x00,0x00,0x00,0x00,0x38,0x3F,0x07,0x06,0x06,0x06,0x06,0x07,0x3F,0x38,0x00,", "B": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xE7,0xFE,0xBC,0x00,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0F,0x00,", "C": "0x00,0xF0,0xFC,0x0E,0x07,0x03,0x03,0x03,0x07,0x0E,0x0C,0x00,0x00,0x03,0x0F,0x1C,0x38,0x30,0x30,0x30,0x38,0x1C,0x0C,0x00,", "D": "0x00,0xFF,0xFF,0x03,0x03,0x03,0x03,0x07,0x0E,0xFC,0xF0,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x38,0x1C,0x0F,0x03,0x00,", "E": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0x03,0x03,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,", - "E": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0x03,0x03,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,", "F": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0x03,0x03,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", "G": "0x00,0xF0,0xFC,0x0E,0x07,0x03,0xC3,0xC3,0xC3,0xC7,0xC6,0x00,0x00,0x03,0x0F,0x1C,0x38,0x30,0x30,0x30,0x30,0x3F,0x3F,0x00,", "H": "0x00,0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xFF,0xFF,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x00,", @@ -67,10 +61,8 @@ def getFontMap(): "X": "0x00,0x03,0x0F,0x1C,0x30,0xE0,0xE0,0x30,0x1C,0x0F,0x03,0x00,0x00,0x30,0x3C,0x0E,0x03,0x01,0x01,0x03,0x0E,0x3C,0x30,0x00,", "Y": "0x00,0x03,0x0F,0x3C,0xF0,0xC0,0xC0,0xF0,0x3C,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,", "Z": "0x00,0x03,0x03,0x03,0x03,0xC3,0xE3,0x33,0x1F,0x0F,0x03,0x00,0x00,0x30,0x3C,0x3E,0x33,0x31,0x30,0x30,0x30,0x30,0x30,0x00,", - "Z": "0x00,0x03,0x03,0x03,0x03,0xC3,0xE3,0x33,0x1F,0x0F,0x03,0x00,0x00,0x30,0x3C,0x3E,0x33,0x31,0x30,0x30,0x30,0x30,0x30,0x00,", "[": "0x00,0x00,0x00,0xFF,0xFF,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x00,0x00,0x00,", "\\": "0x00,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x18,", - "\\": "0x00,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x18,", "]": "0x00,0x00,0x00,0x03,0x03,0x03,0x03,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x3F,0x3F,0x00,0x00,0x00,", "^": "0x00,0x60,0x70,0x38,0x1C,0x0E,0x07,0x0E,0x1C,0x38,0x70,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", "_": "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,", @@ -101,7 +93,6 @@ def getFontMap(): "x": "0x00,0x60,0xE0,0xC0,0x80,0x00,0x80,0xC0,0xE0,0x60,0x00,0x00,0x00,0x30,0x38,0x1D,0x0F,0x07,0x0F,0x1D,0x38,0x30,0x00,0x00,", "y": "0x00,0x00,0x60,0xE0,0x80,0x00,0x00,0x80,0xE0,0x60,0x00,0x00,0x00,0x00,0x00,0x81,0xE7,0x7E,0x1E,0x07,0x01,0x00,0x00,0x00,", "z": "0x00,0x60,0x60,0x60,0x60,0x60,0xE0,0xE0,0x60,0x20,0x00,0x00,0x00,0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x30,0x00,0x00,", - "z": "0x00,0x60,0x60,0x60,0x60,0x60,0xE0,0xE0,0x60,0x20,0x00,0x00,0x00,0x30,0x38,0x3C,0x36,0x33,0x31,0x30,0x30,0x30,0x00,0x00,", "{": "0x00,0x00,0x80,0xC0,0xFC,0x7E,0x07,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x1F,0x3F,0x70,0x60,0x60,0x60,0x00,0x00,", "|": "0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,", "}": "0x00,0x00,0x03,0x03,0x03,0x07,0x7E,0xFC,0xC0,0x80,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x70,0x3F,0x1F,0x01,0x00,0x00,0x00,", @@ -209,15 +200,15 @@ def getFontMap(): "Ѝ": "0x00,0xFF,0xFF,0x00,0x01,0xC3,0xF2,0x38,0x0E,0xFF,0xFF,0x00,0x00,0x3F,0x3F,0x1C,0x07,0x03,0x00,0x00,0x00,0x3F,0x3F,0x00,", "Ў": "0x00,0x07,0x1F,0x7C,0xF1,0xC1,0xC1,0xF1,0x7C,0x1F,0x07,0x00,0x00,0x00,0x30,0x30,0x3C,0x0F,0x07,0x01,0x00,0x00,0x00,0x00,", "Џ": "0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x1F,0x1F,0x18,0x18,0x78,0x78,0x18,0x18,0x1F,0x1F,0x00,", - # "A":"0x00,0x80,0xE0,0x78,0x1E,0x07,0x07,0x1E,0x78,0xE0,0x80,0x00,0x00,0x3F,0x3F,0x06,0x06,0x06,0x06,0x06,0x06,0x3F,0x3F,0x00," , + "А": "0x00,0x00,0x00,0xE0,0xFC,0x1F,0x1F,0xFC,0xE0,0x00,0x00,0x00,0x00,0x38,0x3F,0x07,0x06,0x06,0x06,0x06,0x07,0x3F,0x38,0x00,", "Б": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0x83,0x00,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0F,0x00,", "В": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xE7,0xFE,0xBC,0x00,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0F,0x00,", "Г": "0x00,0xFF,0xFF,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", - "Г": "0x00,0xFF,0xFF,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", + "Ґ": "0x00,0xFC,0xFC,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0F,0x0F,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", "Д": "0x00,0x00,0xF8,0xFE,0x0F,0x03,0x03,0x03,0xFF,0xFF,0x00,0x00,0x00,0x70,0x7F,0x1F,0x18,0x18,0x18,0x18,0x1F,0x7F,0x70,0x00,", "Е": "0x00,0xFF,0xFF,0xC3,0xC3,0xC3,0xC3,0xC3,0xC3,0x03,0x03,0x00,0x00,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,", "Ж": "0x00,0x03,0x0F,0xFC,0xE0,0xFF,0xFF,0xE0,0xFC,0x0F,0x03,0x00,0x00,0x38,0x3F,0x07,0x00,0x3F,0x3F,0x00,0x07,0x3F,0x38,0x00,", - "Ж": "0x00,0x03,0x0F,0xFC,0xE0,0xFF,0xFF,0xE0,0xFC,0x0F,0x03,0x00,0x00,0x38,0x3F,0x07,0x00,0x3F,0x3F,0x00,0x07,0x3F,0x38,0x00,", + "З": "0x0C,0x0E,0x07,0x03,0xC3,0xC3,0xC3,0xC3,0xC3,0xE7,0x7E,0x3C,0x0C,0x1C,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x0E,", "И": "0x00,0xFF,0xFF,0x00,0x00,0xC0,0xF0,0x38,0x0E,0xFF,0xFF,0x00,0x00,0x3F,0x3F,0x1C,0x07,0x03,0x00,0x00,0x00,0x3F,0x3F,0x00,", "Й": "0x00,0xFF,0xFF,0x00,0x02,0xC3,0xF1,0x38,0x0E,0xFF,0xFF,0x00,0x00,0x3F,0x3F,0x1C,0x07,0x03,0x00,0x00,0x00,0x3F,0x3F,0x00,", "К": "0x00,0xFF,0xFF,0xC0,0xE0,0xF0,0x38,0x1C,0x0E,0x07,0x03,0x00,0x00,0x3F,0x3F,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00,", @@ -246,11 +237,11 @@ def getFontMap(): "б": "0x00,0xE0,0xF0,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x1F,0x3F,0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x1E,0x00,", "в": "0x00,0xF0,0xF0,0x30,0x30,0x30,0x30,0x30,0xF0,0xE0,0x00,0x00,0x00,0x3F,0x3F,0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x1E,0x00,", "г": "0x00,0xF0,0xF0,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", + "ґ": "0x00,0xF0,0xF0,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x3C,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,", "д": "0x00,0x00,0xC0,0xE0,0x70,0x30,0x30,0x30,0xF0,0xF0,0x00,0x00,0x00,0x60,0x7F,0x3F,0x30,0x30,0x30,0x30,0x3F,0x7F,0x60,0x00,", "е": "0x00,0xE0,0xF0,0x30,0x30,0x30,0x30,0x30,0x30,0xF0,0xE0,0x00,0x00,0x1F,0x3F,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x00,", "ж": "0x00,0x30,0xF0,0xC0,0x00,0xF0,0xF0,0x00,0xC0,0xF0,0x30,0x00,0x00,0x30,0x3C,0x0F,0x03,0x3F,0x3F,0x03,0x0F,0x3C,0x30,0x00,", "з": "0x00,0x60,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0xF0,0xE0,0x00,0x00,0x18,0x38,0x30,0x33,0x33,0x33,0x33,0x33,0x3F,0x1D,0x00,", - "З": "0x00,0x60,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0xF0,0xE0,0x00,0x00,0x18,0x38,0x30,0x33,0x33,0x33,0x33,0x33,0x3F,0x1D,0x00,", "и": "0x00,0xF0,0xF0,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF0,0x00,0x00,0x3F,0x3F,0x1C,0x0E,0x07,0x03,0x01,0x00,0x3F,0x3F,0x00,", "й": "0x00,0xF0,0xF0,0x00,0x04,0x08,0x88,0xC4,0xE0,0xF0,0xF0,0x00,0x00,0x3F,0x3F,0x1C,0x0E,0x07,0x03,0x01,0x00,0x3F,0x3F,0x00,", "к": "0x00,0xF0,0xF0,0x80,0x80,0xC0,0xE0,0x70,0x30,0x10,0x00,0x00,0x00,0x3F,0x3F,0x03,0x03,0x07,0x0E,0x1C,0x38,0x30,0x20,0x00,", @@ -520,7 +511,6 @@ def getSmallFontMap(): "|": "0x00, 0x00, 0x77, 0x00, 0x00, 0x00,", "}": "0x00, 0x00, 0x41, 0x36, 0x08, 0x00,", "~": "0x02, 0x01, 0x02, 0x04, 0x02, 0x00,", - "^": "0x04, 0x02, 0x01, 0x02, 0x04, 0x00,", "¡": "0x00, 0x00, 0x79, 0x00, 0x00, 0x00,", "¢": "0x1c, 0x22, 0x7f, 0x22, 0x10, 0x00,", "£": "0x50, 0x7e, 0x51, 0x41, 0x42, 0x00,", @@ -635,6 +625,7 @@ def getSmallFontMap(): "Б": "0x7f, 0x49, 0x49, 0x49, 0x31, 0x00,", "В": "0x7f, 0x49, 0x49, 0x49, 0x36, 0x00,", "Г": "0x7f, 0x01, 0x01, 0x01, 0x01, 0x00,", + "Ґ": "0x7E, 0x02, 0x02, 0x02, 0x03, 0x00,", "Д": "0x60, 0x3f, 0x21, 0x3f, 0x60, 0x00,", "Е": "0x7f, 0x49, 0x49, 0x49, 0x41, 0x00,", "Ж": "0x77, 0x08, 0x7f, 0x08, 0x77, 0x00,", @@ -655,8 +646,8 @@ def getSmallFontMap(): "Х": "0x63, 0x14, 0x08, 0x14, 0x63, 0x00,", "Ц": "0x3f, 0x20, 0x20, 0x3f, 0x60, 0x00,", "Ч": "0x07, 0x08, 0x08, 0x08, 0x7f, 0x00,", - "Ш": "0x3f, 0x20, 0x3f, 0x20, 0x3f, 0x00,", - "Щ": "0x3f, 0x20, 0x3f, 0x20, 0x3f, 0x60,", + "Ш": "0x7F, 0x40, 0x7F, 0x40, 0x7F, 0x00,", + "Щ": "0x7F, 0x40, 0x7F, 0x40, 0x7F, 0xC0,", "Ъ": "0x01, 0x7f, 0x48, 0x48, 0x30, 0x00,", "Ы": "0x7f, 0x48, 0x30, 0x00, 0x7f, 0x00,", "Ь": "0x00, 0x7f, 0x48, 0x48, 0x30, 0x00,", @@ -667,6 +658,7 @@ def getSmallFontMap(): "б": "0x3c, 0x4a, 0x4a, 0x4a, 0x30, 0x00,", "в": "0x7c, 0x54, 0x54, 0x54, 0x28, 0x00,", "г": "0x7c, 0x04, 0x04, 0x04, 0x04, 0x00,", + "ґ": "0x7C, 0x04, 0x04, 0x04, 0x06, 0x00,", "д": "0x40, 0x3c, 0x24, 0x3c, 0x60, 0x00,", "е": "0x38, 0x54, 0x54, 0x54, 0x18, 0x00,", "ж": "0x6c, 0x10, 0x7c, 0x10, 0x6c, 0x00,", @@ -687,8 +679,8 @@ def getSmallFontMap(): "х": "0x44, 0x28, 0x10, 0x28, 0x44, 0x00,", "ц": "0x3c, 0x20, 0x20, 0x3c, 0x60, 0x00,", "ч": "0x0c, 0x10, 0x10, 0x10, 0x7c, 0x00,", - "ш": "0x3c, 0x20, 0x3c, 0x20, 0x3c, 0x00,", - "щ": "0x3c, 0x20, 0x3c, 0x20, 0x7c, 0x00,", + "ш": "0x7C, 0x40, 0x7C, 0x40, 0x7C, 0x00,", + "щ": "0x7C, 0x40, 0x7C, 0x40, 0xFC, 0x00,", "ъ": "0x04, 0x7c, 0x50, 0x20, 0x00, 0x00,", "ы": "0x7c, 0x50, 0x20, 0x00, 0x7c, 0x00,", "ь": "0x00, 0x7c, 0x50, 0x20, 0x00, 0x00,", From 69bf0503789f7771005f90e0fe5ed16497dcc17a Mon Sep 17 00:00:00 2001 From: HanaO00 <17810985+HanaO00@users.noreply.github.com> Date: Wed, 10 Mar 2021 01:55:04 +0100 Subject: [PATCH 39/40] Update translation_FR.json --- Translations/translation_FR.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Translations/translation_FR.json b/Translations/translation_FR.json index 7365479c..612a570a 100644 --- a/Translations/translation_FR.json +++ b/Translations/translation_FR.json @@ -285,10 +285,10 @@ }, "MinVolCell": { "text2": [ - "Minimum", - "voltage" + "Tension", + "minimale" ], - "desc": "Minimum allowed voltage per cell" + "desc": "Tension minimale autorisée par cellule" } } } From 2220155045a5e4c152d381b57bd1f6ea0926d0ab Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Thu, 11 Mar 2021 14:04:34 -0500 Subject: [PATCH 40/40] Add 18v for pinecil --- source/Core/BSP/Pine64/BSP_PD.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/Core/BSP/Pine64/BSP_PD.c b/source/Core/BSP/Pine64/BSP_PD.c index 7a282409..8608c814 100644 --- a/source/Core/BSP/Pine64/BSP_PD.c +++ b/source/Core/BSP/Pine64/BSP_PD.c @@ -15,11 +15,12 @@ const uint16_t USB_PD_Desired_Levels[] = { // mV desired input, mA minimum required current // Tip is ~ 7.5 ohms 20000, 2666, // 20V, 2.6A + 18000, 2400, // 18V, 2.4A 15000, 2000, // 15V 2A 12000, 1600, // 12V @ 1.6A 9000, 1200, // 9V @ 1.2A 5000, 100, // 5V @ whatever }; -const uint8_t USB_PD_Desired_Levels_Len = 5; +const uint8_t USB_PD_Desired_Levels_Len = 6; #endif