From 9e66a26b88729692dae14643b7e241ee913dd995 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" <5425387+Ralim@users.noreply.github.com> Date: Fri, 7 Oct 2022 18:53:27 +1100 Subject: [PATCH 01/10] Update Setup.cpp --- source/Core/BSP/Pinecilv2/Setup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Core/BSP/Pinecilv2/Setup.cpp b/source/Core/BSP/Pinecilv2/Setup.cpp index 85ffcf63..adfbc1c9 100644 --- a/source/Core/BSP/Pinecilv2/Setup.cpp +++ b/source/Core/BSP/Pinecilv2/Setup.cpp @@ -37,7 +37,7 @@ void hardware_init() { setup_timer_scheduler(); setup_adc(); setup_pwm(); - I2C_ClockSet(I2C0_ID, 200000); // Sets clock to around 175kHz + I2C_ClockSet(I2C0_ID, 100000); // Sets clock to around 175kHz TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_1, 0); } void setup_pwm(void) { From 7b600b61d34c59394548dd4f55100f5107ba01b9 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 6 Nov 2022 22:07:48 +1100 Subject: [PATCH 02/10] Cleanup --- .../bl702_driver/hal_drv/src/hal_i2c.c | 147 ++++++------------ 1 file changed, 48 insertions(+), 99 deletions(-) diff --git a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/hal_drv/src/hal_i2c.c b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/hal_drv/src/hal_i2c.c index cbc88824..7b0d4de4 100644 --- a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/hal_drv/src/hal_i2c.c +++ b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/hal_drv/src/hal_i2c.c @@ -21,8 +21,8 @@ * */ #include "hal_i2c.h" -#include "bl702_i2c.h" #include "bl702_glb.h" +#include "bl702_i2c.h" static i2c_device_t i2cx_device[I2C_MAX_INDEX] = { #ifdef BSP_USING_I2C0 @@ -39,65 +39,16 @@ static i2c_device_t i2cx_device[I2C_MAX_INDEX] = { * @param oflag * @return int */ -int i2c_open(struct device *dev, uint16_t oflag) -{ - i2c_device_t *i2c_device = (i2c_device_t *)dev; +int i2c_open(struct device *dev, uint16_t oflag) { + i2c_device_t *i2c_device = (i2c_device_t *)dev; - if (i2c_device->mode == I2C_HW_MODE) { - I2C_SetPrd(i2c_device->id, i2c_device->phase); - } + if (i2c_device->mode == I2C_HW_MODE) { + I2C_SetPrd(i2c_device->id, i2c_device->phase); + } - return 0; + return 0; } -// int i2c_close(struct device *dev) -// { - -// return 0; -// } - -// int i2c_control(struct device *dev, int cmd, void *args) -// { -// //i2c_device_t *i2c_device = (i2c_device_t *)dev; - -// switch (cmd) -// { -// case DEVICE_CTRL_SET_INT /* constant-expression */: - -// break; -// case DEVICE_CTRL_CLR_INT /* constant-expression */: -// /* code */ -// /* Enable UART interrupt*/ - -// break; -// case DEVICE_CTRL_GET_INT /* constant-expression */: -// /* code */ -// break; -// case DEVICE_CTRL_CONFIG /* constant-expression */: -// /* code */ -// break; -// case 4 /* constant-expression */: -// /* code */ -// break; -// case 5 /* constant-expression */: -// /* code */ -// break; -// default: -// break; -// } - -// return 0; -// } -// int i2c_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size) -// { - -// return 0; -// } -// int i2c_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size) -// { - -// return 0; -// } /** * @brief * @@ -106,26 +57,25 @@ int i2c_open(struct device *dev, uint16_t oflag) * @param flag * @return int */ -int i2c_register(enum i2c_index_type index, const char *name) -{ - struct device *dev; +int i2c_register(enum i2c_index_type index, const char *name) { + struct device *dev; - if (I2C_MAX_INDEX == 0) { - return -DEVICE_EINVAL; - } + if (I2C_MAX_INDEX == 0) { + return -DEVICE_EINVAL; + } - dev = &(i2cx_device[index].parent); + dev = &(i2cx_device[index].parent); - dev->open = i2c_open; - dev->close = NULL; - dev->control = NULL; - dev->write = NULL; - dev->read = NULL; + dev->open = i2c_open; + dev->close = NULL; + dev->control = NULL; + dev->write = NULL; + dev->read = NULL; - dev->type = DEVICE_CLASS_I2C; - dev->handle = NULL; + dev->type = DEVICE_CLASS_I2C; + dev->handle = NULL; - return device_register(dev, name); + return device_register(dev, name); } /** * @brief @@ -135,38 +85,37 @@ int i2c_register(enum i2c_index_type index, const char *name) * @param num * @return uint32_t */ -int i2c_transfer(struct device *dev, i2c_msg_t msgs[], uint32_t num) -{ - i2c_msg_t *msg; - I2C_Transfer_Cfg i2cCfg = { 0 }; +int i2c_transfer(struct device *dev, i2c_msg_t msgs[], uint32_t num) { + i2c_msg_t *msg; + I2C_Transfer_Cfg i2cCfg = {0}; - i2c_device_t *i2c_device = (i2c_device_t *)dev; + i2c_device_t *i2c_device = (i2c_device_t *)dev; - if (i2c_device->mode == I2C_HW_MODE) { - for (uint32_t i = 0; i < num; i++) { - msg = &msgs[i]; - i2cCfg.slaveAddr = msg->slaveaddr; - i2cCfg.stopEveryByte = DISABLE; - i2cCfg.subAddr = msg->subaddr; - i2cCfg.dataSize = msg->len; - i2cCfg.data = msg->buf; + if (i2c_device->mode == I2C_HW_MODE) { + for (uint32_t i = 0; i < num; i++) { + msg = &msgs[i]; + i2cCfg.slaveAddr = msg->slaveaddr; + i2cCfg.stopEveryByte = DISABLE; + i2cCfg.subAddr = msg->subaddr; + i2cCfg.dataSize = msg->len; + i2cCfg.data = msg->buf; - if (msg->flags & SUB_ADDR_0BYTE) { - i2cCfg.subAddrSize = 0; - } else if (msg->flags & SUB_ADDR_1BYTE) { - i2cCfg.subAddrSize = 1; - } else if (msg->flags & SUB_ADDR_2BYTE) { - i2cCfg.subAddrSize = 2; - } + if (msg->flags & SUB_ADDR_0BYTE) { + i2cCfg.subAddrSize = 0; + } else if (msg->flags & SUB_ADDR_1BYTE) { + i2cCfg.subAddrSize = 1; + } else if (msg->flags & SUB_ADDR_2BYTE) { + i2cCfg.subAddrSize = 2; + } - if ((msg->flags & I2C_RW_MASK) == I2C_WR) { - return I2C_MasterSendBlocking(i2c_device->id, &i2cCfg); - } else if ((msg->flags & I2C_RW_MASK) == I2C_RD) { - return I2C_MasterReceiveBlocking(i2c_device->id, &i2cCfg); - } - } - } else { + if ((msg->flags & I2C_RW_MASK) == I2C_WR) { + return I2C_MasterSendBlocking(i2c_device->id, &i2cCfg); + } else if ((msg->flags & I2C_RW_MASK) == I2C_RD) { + return I2C_MasterReceiveBlocking(i2c_device->id, &i2cCfg); + } } + } else { + } - return 0; + return 0; } \ No newline at end of file From eacb6ac1cd67459a01ea773e5291fbb2cc14cbcd Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 6 Nov 2022 22:07:55 +1100 Subject: [PATCH 03/10] Use ROM --- source/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Makefile b/source/Makefile index f2e54411..f2842429 100644 --- a/source/Makefile +++ b/source/Makefile @@ -269,8 +269,8 @@ LDSCRIPT=./Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/bl702_flash.ld CPUFLAGS= -march=rv32imafc \ -mabi=ilp32f \ -mcmodel=medany -fsigned-char -fno-builtin -nostartfiles \ - -DportasmHANDLE_INTERRUPT=FreeRTOS_Interrupt_Handler -DARCH_RISCV -D__RISCV_FEATURE_MVE=0 -DportUSING_MPU_WRAPPERS=0 -# -DBFLB_USE_ROM_DRIVER=1 + -DportasmHANDLE_INTERRUPT=FreeRTOS_Interrupt_Handler -DARCH_RISCV -D__RISCV_FEATURE_MVE=0 -DportUSING_MPU_WRAPPERS=0 -DDBFLB_USE_ROM_DRIVER=1 + DEV_LDFLAGS=-nostartfiles DEV_AFLAGS= DEV_GLOBAL_DEFS= From d3ac9eb7b27ebfcba77744e44520130ad1158fac Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Nov 2022 18:16:17 +1100 Subject: [PATCH 04/10] Cleanup comments --- .../bl702_driver/std_drv/src/bl702_i2c.c | 314 +++++++++--------- 1 file changed, 157 insertions(+), 157 deletions(-) diff --git a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_i2c.c b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_i2c.c index 1398efed..b43c892a 100644 --- a/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_i2c.c +++ b/source/Core/BSP/Pinecilv2/bl_mcu_sdk/drivers/bl702_driver/std_drv/src/bl702_i2c.c @@ -89,14 +89,14 @@ intCallback_Type *i2cIntCbfArra[I2C_ID_MAX][I2C_INT_ALL] = {{NULL}}; * @{ */ -/****************************************************************************/ /** - * @brief I2C interrupt handler - * - * @param i2cNo: I2C ID type - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C interrupt handler + * + * @param i2cNo: I2C ID type + * + * @return None + * + *******************************************************************************/ #ifndef BFLB_USE_HAL_DRIVER static void I2C_IntHandler(I2C_ID_Type i2cNo) { uint32_t tmpVal; @@ -157,15 +157,15 @@ static void I2C_IntHandler(I2C_ID_Type i2cNo) { * @{ */ -/****************************************************************************/ /** - * @brief I2C write word data - * - * @param i2cNo: I2C ID type - * @param data: Data word - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C write word data + * + * @param i2cNo: I2C ID type + * @param data: Data word + * + * @return None + * + *******************************************************************************/ void I2C_SendWord(I2C_ID_Type i2cNo, uint32_t data) { uint32_t I2Cx = I2C_BASE; @@ -174,14 +174,14 @@ void I2C_SendWord(I2C_ID_Type i2cNo, uint32_t data) { BL_WR_REG(I2Cx, I2C_FIFO_WDATA, data); } -/****************************************************************************/ /** - * @brief I2C read word data - * - * @param i2cNo: I2C ID type - * - * @return word data - * - *******************************************************************************/ +/** + * @brief I2C read word data + * + * @param i2cNo: I2C ID type + * + * @return word data + * + *******************************************************************************/ uint32_t I2C_RecieveWord(I2C_ID_Type i2cNo) { uint32_t I2Cx = I2C_BASE; @@ -190,14 +190,14 @@ uint32_t I2C_RecieveWord(I2C_ID_Type i2cNo) { return BL_RD_REG(I2Cx, I2C_FIFO_RDATA); } -/****************************************************************************/ /** - * @brief I2C enable - * - * @param i2cNo: I2C ID type - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C enable + * + * @param i2cNo: I2C ID type + * + * @return None + * + *******************************************************************************/ void I2C_Enable(I2C_ID_Type i2cNo) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -210,14 +210,14 @@ void I2C_Enable(I2C_ID_Type i2cNo) { BL_WR_REG(I2Cx, I2C_CONFIG, tmpVal); } -/****************************************************************************/ /** - * @brief I2C disable - * - * @param i2cNo: I2C ID type - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C disable + * + * @param i2cNo: I2C ID type + * + * @return None + * + *******************************************************************************/ void I2C_Disable(I2C_ID_Type i2cNo) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -243,14 +243,14 @@ void I2C_Disable(I2C_ID_Type i2cNo) { BL_WR_REG(I2Cx, I2C_INT_STS, tmpVal); } -/****************************************************************************/ /** - * @brief I2C set global reset function - * - * @param i2cNo: I2C ID type - * - * @return SUCCESS or ERROR - * - *******************************************************************************/ +/** + * @brief I2C set global reset function + * + * @param i2cNo: I2C ID type + * + * @return SUCCESS or ERROR + * + *******************************************************************************/ BL_Err_Type I2C_Reset(I2C_ID_Type i2cNo) { /* Check the parameters */ CHECK_PARAM(IS_I2C_ID_TYPE(i2cNo)); @@ -259,16 +259,16 @@ BL_Err_Type I2C_Reset(I2C_ID_Type i2cNo) { return SUCCESS; } -/****************************************************************************/ /** - * @brief I2C init function - * - * @param i2cNo: I2C ID type - * @param direct: I2C read or write direct - * @param cfg: I2C transfer config struct - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C init function + * + * @param i2cNo: I2C ID type + * @param direct: I2C read or write direct + * @param cfg: I2C transfer config struct + * + * @return None + * + *******************************************************************************/ void I2C_Init(I2C_ID_Type i2cNo, I2C_Direction_Type direct, I2C_Transfer_Cfg *cfg) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -308,15 +308,15 @@ void I2C_Init(I2C_ID_Type i2cNo, I2C_Direction_Type direct, I2C_Transfer_Cfg *cf #endif } -/****************************************************************************/ /** - * @brief Set de-glitch function cycle count value - * - * @param i2cNo: I2C ID type - * @param cnt: De-glitch function cycle count - * - * @return SUCCESS - * - *******************************************************************************/ +/** + * @brief Set de-glitch function cycle count value + * + * @param i2cNo: I2C ID type + * @param cnt: De-glitch function cycle count + * + * @return SUCCESS + * + *******************************************************************************/ BL_Err_Type I2C_SetDeglitchCount(I2C_ID_Type i2cNo, uint8_t cnt) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -343,15 +343,15 @@ BL_Err_Type I2C_SetDeglitchCount(I2C_ID_Type i2cNo, uint8_t cnt) { return SUCCESS; } -/****************************************************************************/ /** - * @brief Set i2c prd - * - * @param i2cNo: I2C ID type - * @param phase: I2C phase value - * - * @return None - * - *******************************************************************************/ +/** + * @brief Set i2c prd + * + * @param i2cNo: I2C ID type + * @param phase: I2C phase value + * + * @return None + * + *******************************************************************************/ void I2C_SetPrd(I2C_ID_Type i2cNo, uint8_t phase) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -380,15 +380,15 @@ void I2C_SetPrd(I2C_ID_Type i2cNo, uint8_t phase) { BL_WR_REG(I2Cx, I2C_PRD_DATA, tmpVal); } -/****************************************************************************/ /** - * @brief I2C set scl output clock - * - * @param i2cNo: I2C ID type - * @param clk: Clock set - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C set scl output clock + * + * @param i2cNo: I2C ID type + * @param clk: Clock set + * + * @return None + * + *******************************************************************************/ void I2C_ClockSet(I2C_ID_Type i2cNo, uint32_t clk) { uint8_t bclkDiv = 0; @@ -412,15 +412,15 @@ void I2C_ClockSet(I2C_ID_Type i2cNo, uint32_t clk) { } } -/****************************************************************************/ /** - * @brief I2C set scl sync - * - * @param i2cNo: I2C ID type - * @param enable: Enable or disable I2C scl sync - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C set scl sync + * + * @param i2cNo: I2C ID type + * @param enable: Enable or disable I2C scl sync + * + * @return None + * + *******************************************************************************/ void I2C_SetSclSync(I2C_ID_Type i2cNo, uint8_t enable) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -439,14 +439,14 @@ void I2C_SetSclSync(I2C_ID_Type i2cNo, uint8_t enable) { BL_WR_REG(I2Cx, I2C_CONFIG, tmpVal); } -/****************************************************************************/ /** - * @brief Get i2c busy state - * - * @param i2cNo: I2C ID type - * - * @return RESET or SET - * - *******************************************************************************/ +/** + * @brief Get i2c busy state + * + * @param i2cNo: I2C ID type + * + * @return RESET or SET + * + *******************************************************************************/ BL_Sts_Type I2C_IsBusy(I2C_ID_Type i2cNo) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -458,14 +458,14 @@ BL_Sts_Type I2C_IsBusy(I2C_ID_Type i2cNo) { return ((BL_IS_REG_BIT_SET(tmpVal, I2C_STS_I2C_BUS_BUSY)) ? SET : RESET); } -/****************************************************************************/ /** - * @brief Get i2c transfer end state - * - * @param i2cNo: I2C ID type - * - * @return RESET or SET - * - *******************************************************************************/ +/** + * @brief Get i2c transfer end state + * + * @param i2cNo: I2C ID type + * + * @return RESET or SET + * + *******************************************************************************/ BL_Sts_Type I2C_TransferEndStatus(I2C_ID_Type i2cNo) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -477,15 +477,15 @@ BL_Sts_Type I2C_TransferEndStatus(I2C_ID_Type i2cNo) { return ((BL_IS_REG_BIT_SET(tmpVal, I2C_END_INT)) ? SET : RESET); } -/****************************************************************************/ /** - * @brief I2C master write block data - * - * @param i2cNo: I2C ID type - * @param cfg: I2C transfer config struct - * - * @return SUCCESS or ERROR - * - *******************************************************************************/ +/** + * @brief I2C master write block data + * + * @param i2cNo: I2C ID type + * @param cfg: I2C transfer config struct + * + * @return SUCCESS or ERROR + * + *******************************************************************************/ BL_Err_Type I2C_MasterSendBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg) { uint8_t i; uint32_t timeOut = 0; @@ -550,15 +550,15 @@ BL_Err_Type I2C_MasterSendBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg) { return SUCCESS; } -/****************************************************************************/ /** - * @brief I2C master read block data - * - * @param i2cNo: I2C ID type - * @param cfg: I2C transfer config struct - * - * @return SUCCESS or ERROR - * - *******************************************************************************/ +/** + * @brief I2C master read block data + * + * @param i2cNo: I2C ID type + * @param cfg: I2C transfer config struct + * + * @return SUCCESS or ERROR + * + *******************************************************************************/ BL_Err_Type I2C_MasterReceiveBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg) { uint8_t i = 0; uint32_t timeOut = 0; @@ -643,16 +643,16 @@ BL_Err_Type I2C_MasterReceiveBlocking(I2C_ID_Type i2cNo, I2C_Transfer_Cfg *cfg) return SUCCESS; } -/****************************************************************************/ /** - * @brief Mask/Unmask the I2C interrupt - * - * @param i2cNo: I2C ID type - * @param intType: Specifies the interrupt type - * @param intMask: Enable/Disable Specified interrupt type - * - * @return None - * - *******************************************************************************/ +/** + * @brief Mask/Unmask the I2C interrupt + * + * @param i2cNo: I2C ID type + * @param intType: Specifies the interrupt type + * @param intMask: Enable/Disable Specified interrupt type + * + * @return None + * + *******************************************************************************/ void I2C_IntMask(I2C_ID_Type i2cNo, I2C_INT_Type intType, BL_Mask_Type intMask) { uint32_t tmpVal; uint32_t I2Cx = I2C_BASE; @@ -783,16 +783,16 @@ void I2C_IntMask(I2C_ID_Type i2cNo, I2C_INT_Type intType, BL_Mask_Type intMask) BL_WR_REG(I2Cx, I2C_INT_STS, tmpVal); } -/****************************************************************************/ /** - * @brief Install I2C interrupt callback function - * - * @param i2cNo: I2C ID type - * @param intType: Specifies the interrupt type - * @param cbFun: Pointer to interrupt callback function. The type should be void (*fn)(void) - * - * @return None - * - *******************************************************************************/ +/** + * @brief Install I2C interrupt callback function + * + * @param i2cNo: I2C ID type + * @param intType: Specifies the interrupt type + * @param cbFun: Pointer to interrupt callback function. The type should be void (*fn)(void) + * + * @return None + * + *******************************************************************************/ #ifndef BFLB_USE_HAL_DRIVER void I2C_Int_Callback_Install(I2C_ID_Type i2cNo, I2C_INT_Type intType, intCallback_Type *cbFun) { /* Check the parameters */ @@ -803,14 +803,14 @@ void I2C_Int_Callback_Install(I2C_ID_Type i2cNo, I2C_INT_Type intType, intCallba } #endif -/****************************************************************************/ /** - * @brief I2C IRQ handler - * - * @param None - * - * @return None - * - *******************************************************************************/ +/** + * @brief I2C IRQ handler + * + * @param None + * + * @return None + * + *******************************************************************************/ #ifndef BFLB_USE_HAL_DRIVER void I2C_IRQHandler(void) { I2C_IntHandler(I2C0_ID); } #endif From 461165e982a1a8a28530751443218e0d197cfb46 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Nov 2022 18:38:35 +1100 Subject: [PATCH 05/10] Bugfix display off --- source/Core/Threads/GUIThread.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index a22b3e78..63ce1c9a 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -1105,17 +1105,18 @@ void startGUITask(void const *argument) { } else { setStatusLED(LED_STANDBY); } - // Preemptively turn the display on. Turn it off if and only if + // 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) && getSettingValue(SettingsOptions::Sensitivity) && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) { OLED::setDisplayState(OLED::DisplayState::OFF); setStatusLED(LED_OFF); + }else { + OLED::setDisplayState(OLED::DisplayState::ON); } // Clear the lcd buffer OLED::clearScreen(); From 1ac00c56ea9460ac5b471eb10cfa255fd42d6633 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Nov 2022 18:43:36 +1100 Subject: [PATCH 06/10] Raise up clock rate with deglitch enabled --- source/Core/BSP/Pinecilv2/Setup.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/Core/BSP/Pinecilv2/Setup.cpp b/source/Core/BSP/Pinecilv2/Setup.cpp index adfbc1c9..d221f8ef 100644 --- a/source/Core/BSP/Pinecilv2/Setup.cpp +++ b/source/Core/BSP/Pinecilv2/Setup.cpp @@ -37,7 +37,11 @@ void hardware_init() { setup_timer_scheduler(); setup_adc(); setup_pwm(); - I2C_ClockSet(I2C0_ID, 100000); // Sets clock to around 175kHz + I2C_SetSclSync(I2C0_ID,1); + I2C_SetDeglitchCount(I2C0_ID,1); // Turn on de-glitch + //Note on I2C clock rate @ 100Khz the screen update == 20ms which is too long for USB-PD to work + //200kHz and above works + I2C_ClockSet(I2C0_ID, 300000); // Sets clock to around 25 kHz less than set here TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_1, 0); } void setup_pwm(void) { From 3e666487683f0d8f5ff8d1d2b7924acb6989657f Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Nov 2022 18:43:43 +1100 Subject: [PATCH 07/10] Force full redraw on rotate --- source/Core/Drivers/OLED.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index 54574248..9210da51 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -361,13 +361,17 @@ void OLED::setRotation(bool leftHanded) { OLED_Setup_Array[9].val = 0xA0; } I2C_CLASS::writeRegistersBulk(DEVICEADDR_OLED, OLED_Setup_Array, sizeof(OLED_Setup_Array) / sizeof(OLED_Setup_Array[0])); - + osDelay(TICKS_10MS); inLeftHandedMode = leftHanded; screenBuffer[5] = inLeftHandedMode ? 0 : 32; // display is shifted by 32 in left handed // mode as driver ram is 128 wide screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; // End address of the ram segment we are writing to (96 wide) screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0; + //Force a screen refresh + const int len = FRAMEBUFFER_START + (OLED_WIDTH * 2); + I2C_CLASS::Transmit(DEVICEADDR_OLED, screenBuffer, len); + osDelay(TICKS_10MS); } void OLED::setBrightness(uint8_t contrast) { From 91279874dc1dbe6979fd2df2f5ea23bb9fcfcfef Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sun, 20 Nov 2022 21:15:55 +1100 Subject: [PATCH 08/10] Critical wrap I2C --- source/Core/BSP/Pinecilv2/I2C_Wrapper.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/Core/BSP/Pinecilv2/I2C_Wrapper.cpp b/source/Core/BSP/Pinecilv2/I2C_Wrapper.cpp index ce80e330..e3112b05 100644 --- a/source/Core/BSP/Pinecilv2/I2C_Wrapper.cpp +++ b/source/Core/BSP/Pinecilv2/I2C_Wrapper.cpp @@ -40,7 +40,9 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_b i2cCfg.data = p_buffer; i2cCfg.subAddrSize = 1; // one byte address +taskENTER_CRITICAL(); err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg); + taskEXIT_CRITICAL(); bool res = err == SUCCESS; if (!res) { I2C_Unstick(); @@ -61,8 +63,9 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_bu i2cCfg.dataSize = number_of_byte; i2cCfg.data = p_buffer; i2cCfg.subAddrSize = 1; // one byte address - +taskENTER_CRITICAL(); err = I2C_MasterSendBlocking(I2C0_ID, &i2cCfg); + taskEXIT_CRITICAL(); bool res = err == SUCCESS; if (!res) { I2C_Unstick(); From a2821bba38f7ee863e95bcf0c83c9fd95d589f9a Mon Sep 17 00:00:00 2001 From: Dmitry Gribenchuk Date: Thu, 24 Nov 2022 19:53:45 +0200 Subject: [PATCH 09/10] update translation_BE.json translation_PL.json translation_UK.json translation_RU.json --- Translations/translation_BE.json | 4 ++-- Translations/translation_PL.json | 4 ++-- Translations/translation_RU.json | 4 ++-- Translations/translation_UK.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Translations/translation_BE.json b/Translations/translation_BE.json index 5521fe5c..03feb4b8 100644 --- a/Translations/translation_BE.json +++ b/Translations/translation_BE.json @@ -8,8 +8,8 @@ ], "tempUnitFahrenheit": false, "messages": { - "SettingsCalibrationWarning": "Before rebooting, make sure tip & handle are at room temperature!", - "CJCCalibrating": "calibrating", + "SettingsCalibrationWarning": "Пераканайцеся, што пры наступнай загрузцы наканечнік і ручка маюць пакаёвую тэмпературу!", + "CJCCalibrating": "каліброўка", "SettingsResetWarning": "Вы ўпэннены, што жадаеце зкінуць налады да першапачатковых значэнняў?", "UVLOWarningString": "НАПРУГА--", "UndervoltageString": "Нізкая напруга", diff --git a/Translations/translation_PL.json b/Translations/translation_PL.json index c12fb1b3..32706f68 100644 --- a/Translations/translation_PL.json +++ b/Translations/translation_PL.json @@ -7,8 +7,8 @@ ], "tempUnitFahrenheit": false, "messages": { - "SettingsCalibrationWarning": "Before rebooting, make sure tip & handle are at room temperature!", - "CJCCalibrating": "calibrating", + "SettingsCalibrationWarning": "Upewnij się, że końcówka i uchwyt mają temperaturę pokojową podczas następnego rozruchu!", + "CJCCalibrating": "kalibracja", "SettingsResetWarning": "Czy na pewno chcesz przywrócić ustawienia fabryczne?", "UVLOWarningString": "NIS. NAP", "UndervoltageString": "Zbyt niskie nap.", diff --git a/Translations/translation_RU.json b/Translations/translation_RU.json index 8bdd5adf..1d03137b 100644 --- a/Translations/translation_RU.json +++ b/Translations/translation_RU.json @@ -8,8 +8,8 @@ ], "tempUnitFahrenheit": false, "messages": { - "SettingsCalibrationWarning": "Before rebooting, make sure tip & handle are at room temperature!", - "CJCCalibrating": "calibrating", + "SettingsCalibrationWarning": "Пожалуйста, убедитесь, что жало и корпус имеют комнатную температуру при следующей загрузке!", + "CJCCalibrating": "калибровка", "SettingsResetWarning": "Вы уверены, что хотите сбросить настройки к значениям по умолчанию?", "UVLOWarningString": "НАПРЯЖ--", "UndervoltageString": "Низ. напряжение", diff --git a/Translations/translation_UK.json b/Translations/translation_UK.json index fefe5f41..de50102c 100644 --- a/Translations/translation_UK.json +++ b/Translations/translation_UK.json @@ -8,8 +8,8 @@ ], "tempUnitFahrenheit": false, "messages": { - "SettingsCalibrationWarning": "Before rebooting, make sure tip & handle are at room temperature!", - "CJCCalibrating": "calibrating", + "SettingsCalibrationWarning": "Під час наступного завантаження переконайтеся, що жало і ручка мають кімнатну температуру!", + "CJCCalibrating": "калібрування", "SettingsResetWarning": "Ви дійсно хочете скинути налаштування до значень за замовчуванням? (A=Так, В=Ні)", "UVLOWarningString": "АККУМ--", "UndervoltageString": "Низька напруга", From c55ecbff6cf4eaad86dbd686a84ed54b128d1196 Mon Sep 17 00:00:00 2001 From: discip <53649486+discip@users.noreply.github.com> Date: Thu, 24 Nov 2022 23:56:15 +0100 Subject: [PATCH 10/10] fixed CJC calibration rule Did not calibrate if *handle temp* was higher than *tip temp*. --- 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 cb8ded01..bef78d14 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -98,7 +98,7 @@ void performCJCC() { // Calibrate Cold Junction Compensation directly at boot, before internal components get warm. OLED::refresh(); osDelay(50); - if (!isTipDisconnected() && (TipThermoModel::getTipInC() - getHandleTemperature(0) / 10) < 10) { + if (!isTipDisconnected() && abs( int(TipThermoModel::getTipInC() - getHandleTemperature(0) / 10)) < 10) { uint16_t setoffset = 0; // If the thermo-couple at the end of the tip, and the handle are at // equilibrium, then the output should be zero, as there is no temperature @@ -1231,4 +1231,4 @@ void startGUITask(void const *argument) { GUIDelay(); } } -} \ No newline at end of file +}