diff --git a/source/Core/BSP/MHP30/Software_I2C.h b/source/Core/BSP/MHP30/Software_I2C.h index 411362f5ba..29d8664ba0 100644 --- a/source/Core/BSP/MHP30/Software_I2C.h +++ b/source/Core/BSP/MHP30/Software_I2C.h @@ -10,7 +10,7 @@ #include "BSP.h" #include "configuration.h" #include "stm32f1xx_hal.h" -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD #define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET) #define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET) diff --git a/source/Core/BSP/MHP30/configuration.h b/source/Core/BSP/MHP30/configuration.h index 7cb7e1bdd1..037b36a9ba 100644 --- a/source/Core/BSP/MHP30/configuration.h +++ b/source/Core/BSP/MHP30/configuration.h @@ -159,7 +159,7 @@ #define POW_PD 1 #define TEMP_NTC -#define I2C_SOFT +#define I2C_SOFT_PD #define BATTFILTERDEPTH 8 #define OLED_I2CBB #define ACCEL_EXITS_ON_MOVEMENT diff --git a/source/Core/BSP/Miniware/Software_I2C.h b/source/Core/BSP/Miniware/Software_I2C.h index 5b2924ab06..3be31d818e 100644 --- a/source/Core/BSP/Miniware/Software_I2C.h +++ b/source/Core/BSP/Miniware/Software_I2C.h @@ -10,14 +10,15 @@ #include "BSP.h" #include "configuration.h" #include "stm32f1xx_hal.h" -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD + +#define SOFT_SCL2_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET) +#define SOFT_SCL2_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET) +#define SOFT_SDA2_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET) +#define SOFT_SDA2_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET) +#define SOFT_SDA2_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0) +#define SOFT_SCL2_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0) -#define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET) -#define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET) -#define SOFT_SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET) -#define SOFT_SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET) -#define SOFT_SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port, SDA2_Pin) == GPIO_PIN_SET ? 1 : 0) -#define SOFT_SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port, SCL2_Pin) == GPIO_PIN_SET ? 1 : 0) #define SOFT_I2C_DELAY() \ { \ for (int xx = 0; xx < 15; xx++) { \ diff --git a/source/Core/BSP/Miniware/configuration.h b/source/Core/BSP/Miniware/configuration.h index 896b9dbab7..0088ff6cbe 100644 --- a/source/Core/BSP/Miniware/configuration.h +++ b/source/Core/BSP/Miniware/configuration.h @@ -212,7 +212,7 @@ #define POW_PD 1 #define POW_QC 1 #define TEMP_NTC -#define I2C_SOFT +#define I2C_SOFT_PD #define SC7_ORI_FLIP #endif #endif diff --git a/source/Core/BSP/Miniware/preRTOS.cpp b/source/Core/BSP/Miniware/preRTOS.cpp index f355984e1a..1d3f8bbd86 100644 --- a/source/Core/BSP/Miniware/preRTOS.cpp +++ b/source/Core/BSP/Miniware/preRTOS.cpp @@ -8,6 +8,7 @@ #include "BSP.h" #include "I2CBB.hpp" #include "Pins.h" +#include "configuration.h" #include "Setup.h" #include @@ -17,7 +18,7 @@ void preRToSInit() { HAL_Init(); Setup_HAL(); // Setup all the HAL objects BSPInit(); -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD I2CBB::init(); #endif /* Init the IPC objects */ diff --git a/source/Core/BSP/Sequre_S60/Software_I2C.h b/source/Core/BSP/Sequre_S60/Software_I2C.h index 4c4f5b40e9..53206966f9 100644 --- a/source/Core/BSP/Sequre_S60/Software_I2C.h +++ b/source/Core/BSP/Sequre_S60/Software_I2C.h @@ -10,7 +10,7 @@ #include "BSP.h" #include "configuration.h" #include "stm32f1xx_hal.h" -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD #define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET) #define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET) diff --git a/source/Core/BSP/Sequre_S60/configuration.h b/source/Core/BSP/Sequre_S60/configuration.h index d1c2eeb167..a88958ecbb 100644 --- a/source/Core/BSP/Sequre_S60/configuration.h +++ b/source/Core/BSP/Sequre_S60/configuration.h @@ -158,7 +158,7 @@ #define POW_PD_EXT 1 #define HAS_POWER_DEBUG_MENU #define TEMP_NTC -#define I2C_SOFT // For now we are doing software I2C to get around hardware chip issues +#define I2C_SOFT_PD // For now we are doing software I2C to get around hardware chip issues #define OLED_I2CBB #define MODEL_HAS_DCDC // We dont have DC/DC but have reallly fast PWM that gets us roughly the same place diff --git a/source/Core/BSP/Sequre_S60/preRTOS.cpp b/source/Core/BSP/Sequre_S60/preRTOS.cpp index f355984e1a..d8df5a5b3b 100644 --- a/source/Core/BSP/Sequre_S60/preRTOS.cpp +++ b/source/Core/BSP/Sequre_S60/preRTOS.cpp @@ -17,7 +17,7 @@ void preRToSInit() { HAL_Init(); Setup_HAL(); // Setup all the HAL objects BSPInit(); -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD I2CBB::init(); #endif /* Init the IPC objects */ diff --git a/source/Core/Drivers/I2CBB.cpp b/source/Core/Drivers/I2CBB.cpp index 25af2882cf..a42dba5467 100644 --- a/source/Core/Drivers/I2CBB.cpp +++ b/source/Core/Drivers/I2CBB.cpp @@ -5,7 +5,7 @@ * Author: Ralim */ #include "configuration.h" -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD #include "FreeRTOS.h" #include SemaphoreHandle_t I2CBB::I2CSemaphore = NULL; @@ -24,16 +24,16 @@ void I2CBB::init() { GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(SCL2_GPIO_Port, &GPIO_InitStruct); - SOFT_SDA_HIGH(); - SOFT_SCL_HIGH(); + SOFT_SDA2_HIGH(); + SOFT_SCL2_HIGH(); // To ensure bus is unlocked; we toggle the Clock a bunch of times to make things error out for (int i = 0; i < 128; i++) { - SOFT_SCL_LOW(); + SOFT_SCL2_LOW(); asm("nop"); asm("nop"); asm("nop"); asm("nop"); - SOFT_SCL_HIGH(); + SOFT_SCL2_HIGH(); asm("nop"); asm("nop"); asm("nop"); @@ -69,7 +69,7 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, u unlock(); return false; } - SOFT_SCL_LOW(); + SOFT_SCL2_LOW(); SOFT_I2C_DELAY(); // stop(); start(); @@ -208,23 +208,23 @@ void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, uint16_t Siz void I2CBB::start() { /* I2C Start condition, data line goes low when clock is high */ - SOFT_SCL_HIGH(); - SOFT_SDA_HIGH(); + SOFT_SCL2_HIGH(); + SOFT_SDA2_HIGH(); SOFT_I2C_DELAY(); - SOFT_SDA_LOW(); + SOFT_SDA2_LOW(); SOFT_I2C_DELAY(); - SOFT_SCL_LOW(); + SOFT_SCL2_LOW(); SOFT_I2C_DELAY(); - SOFT_SDA_HIGH(); + SOFT_SDA2_HIGH(); } void I2CBB::stop() { /* I2C Stop condition, clock goes high when data is low */ - SOFT_SDA_LOW(); + SOFT_SDA2_LOW(); SOFT_I2C_DELAY(); - SOFT_SCL_HIGH(); + SOFT_SCL2_HIGH(); SOFT_I2C_DELAY(); - SOFT_SDA_HIGH(); + SOFT_SDA2_HIGH(); SOFT_I2C_DELAY(); } @@ -235,7 +235,7 @@ bool I2CBB::send(uint8_t value) { value <<= 1; } - SOFT_SDA_HIGH(); + SOFT_SDA2_HIGH(); bool ack = (read_bit() == 0); return ack; } @@ -249,7 +249,7 @@ uint8_t I2CBB::read(bool ack) { B |= read_bit(); } - SOFT_SDA_HIGH(); + SOFT_SDA2_HIGH(); if (ack) write_bit(0); else @@ -260,17 +260,17 @@ uint8_t I2CBB::read(bool ack) { uint8_t I2CBB::read_bit() { uint8_t b; - SOFT_SDA_HIGH(); + SOFT_SDA2_HIGH(); SOFT_I2C_DELAY(); - SOFT_SCL_HIGH(); + SOFT_SCL2_HIGH(); SOFT_I2C_DELAY(); - if (SOFT_SDA_READ()) + if (SOFT_SDA2_READ()) b = 1; else b = 0; - SOFT_SCL_LOW(); + SOFT_SCL2_LOW(); return b; } @@ -292,15 +292,15 @@ uint8_t I2CBB::I2C_RegisterRead(uint8_t address, uint8_t reg) { void I2CBB::write_bit(uint8_t val) { if (val) { - SOFT_SDA_HIGH(); + SOFT_SDA2_HIGH(); } else { - SOFT_SDA_LOW(); + SOFT_SDA2_LOW(); } SOFT_I2C_DELAY(); - SOFT_SCL_HIGH(); + SOFT_SCL2_HIGH(); SOFT_I2C_DELAY(); - SOFT_SCL_LOW(); + SOFT_SCL2_LOW(); } bool I2CBB::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) { diff --git a/source/Core/Drivers/I2CBB.hpp b/source/Core/Drivers/I2CBB.hpp index a66d595436..8c539ba710 100644 --- a/source/Core/Drivers/I2CBB.hpp +++ b/source/Core/Drivers/I2CBB.hpp @@ -8,7 +8,7 @@ #ifndef BSP_MINIWARE_I2CBB_HPP_ #define BSP_MINIWARE_I2CBB_HPP_ #include "configuration.h" -#ifdef I2C_SOFT +#ifdef I2C_SOFT_PD #include "BSP.h" #include "FreeRTOS.h" #include "Pins.h"