diff --git a/src/shared/drivers/i2c/I2C.h b/src/shared/drivers/i2c/I2C.h index 42835840e9c4a4a1b4fac10327e723ddb447d743..a97cbb99cf2bb3e00ea6f30c67402455ec2f9709 100644 --- a/src/shared/drivers/i2c/I2C.h +++ b/src/shared/drivers/i2c/I2C.h @@ -98,7 +98,7 @@ public: * @param slaveConfig The configuration struct of the slave device. * @param registerAddress Byte that represents the address of the register. * @param registerContent Where to store the content of the register. - * @returns True if the write is successful, false otherwise. + * @returns True if the read is successful, false otherwise. */ [[nodiscard]] bool readRegister( const I2CDriver::I2CSlaveConfig &slaveConfig, @@ -131,7 +131,7 @@ public: * @param registerAddress Byte that represents the address of the register. * @param buffer Data buffer where to store the data read. * @param nBytes Number of bytes to read. - * @returns True if the write is successful, false otherwise. + * @returns True if the read is successful, false otherwise. */ [[nodiscard]] bool readFromRegister( const I2CDriver::I2CSlaveConfig &slaveConfig, @@ -260,7 +260,7 @@ public: * @param registerAddress Byte that represents the address of the register. * @param buffer Data buffer where to store the data read. * @param nBytes Number of bytes to read. - * @returns True if the write is successful, false otherwise. + * @returns True if the read is successful, false otherwise. */ [[nodiscard]] bool readFromRegister( const I2CDriver::I2CSlaveConfig &slaveConfig, diff --git a/src/shared/drivers/i2c/I2CDriver.h b/src/shared/drivers/i2c/I2CDriver.h index 9d639636f496188ab786134e8db81909acef545f..3ce150aa0c17ea20d3b04e97830ab84d12888672 100644 --- a/src/shared/drivers/i2c/I2CDriver.h +++ b/src/shared/drivers/i2c/I2CDriver.h @@ -65,9 +65,14 @@ public: // [TODO] limit speed possibilities at compile time with ifdefs? enum Speed : uint8_t { - STANDARD = 0, - FAST = 1, - FAST_PLUS = 2 + STANDARD = 0, + FAST = 1, +#ifdef _ARCH_CORTEXM7_STM32F7 + FAST_PLUS = 2, + MAX_SPEED = FAST_PLUS +#else + MAX_SPEED = FAST +#endif // _ARCH_CORTEXM7_STM32F7 }; enum Addressing : uint8_t @@ -242,8 +247,16 @@ private: void setupPeripheral(const I2CSlaveConfig &slaveConfig); #ifdef _ARCH_CORTEXM7_STM32F7 + /** + * @brief Sets up the transaction, so if we have to make a read or write + * transaction and performs the setup of the reload. + */ inline void setupTransaction(); + /** + * @brief Sets up the reload, so configures the registers in order to + * read/write the bytes left + */ inline void setupReload(); #endif // _ARCH_CORTEXM7_STM32F7 diff --git a/src/tests/drivers/i2c/test-i2c-driver.cpp b/src/tests/drivers/i2c/test-i2c-driver.cpp index 0b40f814e233ea2f727dfdf913cc0160c6b41992..2519269dee3e776ced94616492eddfc3f0fdf331 100644 --- a/src/tests/drivers/i2c/test-i2c-driver.cpp +++ b/src/tests/drivers/i2c/test-i2c-driver.cpp @@ -19,6 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <diagnostic/CpuMeter/CpuMeter.h> #include <iostream> @@ -80,6 +81,7 @@ typedef struct I2CSensor BMP180{0b1110111, 0xD0, 0x55, {0xE0, 0xB6}}; I2CSensor BME280{0b1110110, 0xD0, 0x60, {0xE0, 0xB6}}; I2CSensor OLED{0b0111100, 0xD0, 0x43, {}}; +I2CSensor LPS{0b1011100, 0xF, 0xB4, {}}; I2CDriver::I2CSlaveConfig BMP180Config{BMP180.addressSensor, I2CDriver::Addressing::BIT7, @@ -93,6 +95,9 @@ I2CDriver::I2CSlaveConfig OLEDConfig{OLED.addressSensor, I2CDriver::Addressing::BIT7, I2CDriver::Speed::STANDARD}; +I2CDriver::I2CSlaveConfig LPSConfig{ + LPS.addressSensor, I2CDriver::Addressing::BIT7, I2CDriver::Speed::STANDARD}; + bool i2cDriver(I2CDriver &i2c, I2CSensor sensor, I2CDriver::I2CSlaveConfig sensorConfig) { @@ -127,7 +132,9 @@ bool i2cDriver(I2CDriver &i2c, I2CSensor sensor, int main() { - int nRepeat = 10; + I2CDriver i2c(I2C1, i1scl2::getPin(), i1sda2::getPin()); + + int nRepeat = 50; // // thread that uses 100% CPU // std::thread t( @@ -137,13 +144,12 @@ int main() // ; // }); - I2CDriver i2c(I2C1, i1scl2::getPin(), i1sda2::getPin()); - for (;;) { // resetting status of read sensors bool statusOLED = true; bool statusBMP = true; + bool statusLPS = true; for (int i = 0; i < nRepeat; i++) { @@ -155,16 +161,20 @@ int main() #endif // _ARCH_CORTEXM7_STM32F7 }) { - statusBMP &= i2cDriver( - i2c, BMP180, - {BMP180.addressSensor, I2CDriver::Addressing::BIT7, speed}); statusOLED &= i2cDriver( i2c, OLED, {OLED.addressSensor, I2CDriver::Addressing::BIT7, speed}); + statusBMP &= i2cDriver( + i2c, BMP180, + {BMP180.addressSensor, I2CDriver::Addressing::BIT7, speed}); + statusLPS &= i2cDriver( + i2c, LPS, + {LPS.addressSensor, I2CDriver::Addressing::BIT7, speed}); } } - printf("OLED:%d\tBMP:%d\n", statusOLED, statusBMP); + printf("CPU: %5.1f OLED:%d BMP:%d LPS:%d\n", + CpuMeter::getCpuStats().mean, statusOLED, statusBMP, statusLPS); } return 0; } diff --git a/src/tests/drivers/i2c/test-i2c.cpp b/src/tests/drivers/i2c/test-i2c.cpp index caa0dde6af61b53f6ec7064d24fe0141c7b7fb36..a84942dfb9ad307f399eb8ec1eeeea0f3799119c 100644 --- a/src/tests/drivers/i2c/test-i2c.cpp +++ b/src/tests/drivers/i2c/test-i2c.cpp @@ -20,6 +20,8 @@ * THE SOFTWARE. */ +#include <diagnostic/CpuMeter/CpuMeter.h> + #include <iostream> #include "drivers/i2c/I2C.h" @@ -80,6 +82,7 @@ typedef struct I2CSensor BMP180{0b1110111, 0xD0, 0x55, {0xE0, 0xB6}}; I2CSensor BME280{0b1110110, 0xD0, 0x60, {0xE0, 0xB6}}; I2CSensor OLED{0b0111100, 0xD0, 0x43, {}}; +I2CSensor LPS{0b1011100, 0xF, 0xB4, {}}; I2CDriver::I2CSlaveConfig BMP180Config{BMP180.addressSensor, I2CDriver::Addressing::BIT7, @@ -88,10 +91,11 @@ I2CDriver::I2CSlaveConfig BMP180Config{BMP180.addressSensor, I2CDriver::I2CSlaveConfig BME280Config{BME280.addressSensor, I2CDriver::Addressing::BIT7, I2CDriver::Speed::STANDARD}; - I2CDriver::I2CSlaveConfig OLEDConfig{OLED.addressSensor, I2CDriver::Addressing::BIT7, I2CDriver::Speed::STANDARD}; +I2CDriver::I2CSlaveConfig LPSConfig{ + LPS.addressSensor, I2CDriver::Addressing::BIT7, I2CDriver::Speed::STANDARD}; bool i2cDriver(I2C &i2c, I2CSensor sensor, I2CDriver::I2CSlaveConfig sensorConfig) @@ -141,27 +145,31 @@ int main() // resetting status of read sensors bool statusOLED = true; bool statusBMP = true; + bool statusLPS = true; for (int i = 0; i < nRepeat; i++) { - for (I2CDriver::Speed speed : - {I2CDriver::Speed::STANDARD, I2CDriver::Speed::FAST + for (I2CDriver::Speed speed : {I2CDriver::Speed::FAST #ifdef _ARCH_CORTEXM7_STM32F7 - , - I2CDriver::Speed::FAST_PLUS + , + I2CDriver::Speed::FAST_PLUS #endif // _ARCH_CORTEXM7_STM32F7 }) { - statusBMP &= i2cDriver( - i2c, BMP180, - {BMP180.addressSensor, I2CDriver::Addressing::BIT7, speed}); statusOLED &= i2cDriver( i2c, OLED, {OLED.addressSensor, I2CDriver::Addressing::BIT7, speed}); + statusBMP &= i2cDriver( + i2c, BMP180, + {BMP180.addressSensor, I2CDriver::Addressing::BIT7, speed}); + statusLPS &= i2cDriver( + i2c, LPS, + {LPS.addressSensor, I2CDriver::Addressing::BIT7, speed}); } } - printf("OLED:%d\tBMP:%d\n", statusOLED, statusBMP); + printf("CPU: %5.1f OLED:%d BMP:%d LPS:%d\n", + CpuMeter::getCpuStats().mean, statusOLED, statusBMP, statusLPS); } return 0; }