From 307c65895473fac84c85d15969dd08a7a46d6e96 Mon Sep 17 00:00:00 2001 From: Slaveyko <38420877+slavysis@users.noreply.github.com> Date: Fri, 25 Jun 2021 15:44:30 +0300 Subject: [PATCH 1/5] Fixes #31 Addressed reset command fixed --- src/mlx90632.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mlx90632.c b/src/mlx90632.c index 405501f..82e637c 100644 --- a/src/mlx90632.c +++ b/src/mlx90632.c @@ -475,6 +475,18 @@ int32_t mlx90632_init(void) int32_t mlx90632_addressed_reset(void) { int32_t ret; + uint16_t reg_ctrl; + uint16_t reg_value; + + ret = mlx90632_i2c_read(MLX90632_REG_CTRL, ®_value); + if (ret < 0) + return ret; + + reg_ctrl = reg_value & ~MLX90632_CFG_PWR_MASK; + reg_ctrl |= MLX90632_PWR_STATUS_STEP; + ret = mlx90632_i2c_write(MLX90632_REG_CTRL, reg_ctrl); + if (ret < 0) + return ret; ret = mlx90632_i2c_write(0x3005, MLX90632_RESET_CMD); if (ret < 0) @@ -482,7 +494,9 @@ int32_t mlx90632_addressed_reset(void) usleep(150, 200); - return 0; + ret = mlx90632_i2c_write(MLX90632_REG_CTRL, reg_value); + + return ret; } int32_t mlx90632_get_measurement_time(uint16_t meas) From e43625223ff25b8c5895659de61c8e5a99c3aa8d Mon Sep 17 00:00:00 2001 From: Slaveyko <38420877+slavysis@users.noreply.github.com> Date: Fri, 25 Jun 2021 15:46:14 +0300 Subject: [PATCH 2/5] Updated test for the addressed reset fix --- test/TestRead.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/test/TestRead.c b/test/TestRead.c index 6416d08..4cedf3c 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -1642,14 +1642,24 @@ void test_set_meas_type_success(void) uint16_t reg_ctrl_mock_med = 0xFE0F; uint16_t reg_ctrl_mock_med1 = 0xFE09; uint16_t reg_ctrl_mock_med2 = 0xFE0B; + uint16_t reg_ctrl_mock_med3 = 0xFE0D; uint16_t reg_ctrl_mock_ext = 0xFF1F; uint16_t reg_ctrl_mock_ext1 = 0xFF19; uint16_t reg_ctrl_mock_ext2 = 0xFF1B; + uint16_t reg_ctrl_mock_ext3 = 0xFF1D; // Switch from medical to extended measurement type + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med3, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); @@ -1665,12 +1675,20 @@ void test_set_meas_type_success(void) TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Switch from extended to medical measurement type + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_ext, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_ext); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_ext3, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_ext, 0); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_ext, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_ext); mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med1, 0); @@ -1683,9 +1701,17 @@ void test_set_meas_type_success(void) TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_MEDICAL)); // Switch from medical to sleeping step medical measurement type + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med3, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); @@ -1701,12 +1727,20 @@ void test_set_meas_type_success(void) TEST_ASSERT_EQUAL_INT(0, mlx90632_set_meas_type(MLX90632_MTYP_MEDICAL_BURST)); // Switch from medical sleeping step to extended sleeping step measurement type + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med2, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med2); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med3, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); - mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med2, 0); + + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med2, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output - mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med2); mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_ext1, 0); @@ -1723,15 +1757,52 @@ void test_set_meas_type_errors(void) { uint16_t reg_ctrl_mock_med = 0xFE0F; uint16_t reg_ctrl_mock_ext1 = 0xFF19; + uint16_t reg_ctrl_mock_step = 0xFF1D; // Invalid input parameter TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_set_meas_type(9)); + // Addressed reset read current reg value error + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, -EPERM); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + + // Addressed reset write step value error + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, -EPERM); + + TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + // Addressed reset command error + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, -EPERM); TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + // Addressed reset restore value error + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, 0); + + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); + usleep_Expect(150, 200); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, -EPERM); + + TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); + // First read fail mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); From 1d595cbb3bdd77a7d44edbeea84a3f93dce2b868 Mon Sep 17 00:00:00 2001 From: Slaveyko <38420877+slavysis@users.noreply.github.com> Date: Fri, 25 Jun 2021 16:20:14 +0300 Subject: [PATCH 3/5] Correct expected value for step mode error --- test/TestRead.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/TestRead.c b/test/TestRead.c index 4cedf3c..4d8bc17 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -1757,7 +1757,7 @@ void test_set_meas_type_errors(void) { uint16_t reg_ctrl_mock_med = 0xFE0F; uint16_t reg_ctrl_mock_ext1 = 0xFF19; - uint16_t reg_ctrl_mock_step = 0xFF1D; + uint16_t reg_ctrl_mock_step = 0xFE0D; // Invalid input parameter TEST_ASSERT_EQUAL_INT(-EINVAL, mlx90632_set_meas_type(9)); @@ -1774,7 +1774,7 @@ void test_set_meas_type_errors(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, -EPERM); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, -EPERM); TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); From 80de5ca188c51a455505b1b03e419ce920f977fd Mon Sep 17 00:00:00 2001 From: Slaveyko <38420877+slavysis@users.noreply.github.com> Date: Fri, 25 Jun 2021 16:33:15 +0300 Subject: [PATCH 4/5] Expect _mock_step value in addressed reset command --- test/TestRead.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TestRead.c b/test/TestRead.c index 4d8bc17..79b8341 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -1774,7 +1774,7 @@ void test_set_meas_type_errors(void) mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); - mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, -EPERM); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, -EPERM); TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); From 7f98a58615fafb67f0f750fc3a9d64aae61132b4 Mon Sep 17 00:00:00 2001 From: Slaveyko <38420877+slavysis@users.noreply.github.com> Date: Fri, 25 Jun 2021 16:53:48 +0300 Subject: [PATCH 5/5] Updated tests for set_meas_type errors --- test/TestRead.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/TestRead.c b/test/TestRead.c index 79b8341..4935a40 100644 --- a/test/TestRead.c +++ b/test/TestRead.c @@ -1804,9 +1804,17 @@ void test_set_meas_type_errors(void) TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // First read fail + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, -EPERM); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); @@ -1814,9 +1822,17 @@ void test_set_meas_type_errors(void) TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // First write fail + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); @@ -1826,9 +1842,17 @@ void test_set_meas_type_errors(void) TEST_ASSERT_EQUAL_INT(-EPERM, mlx90632_set_meas_type(MLX90632_MTYP_EXTENDED)); // Second read fail + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); + mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output + mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med); + + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_step, 0); + mlx90632_i2c_write_ExpectAndReturn(0x3005, MLX90632_RESET_CMD, 0); usleep_Expect(150, 200); + mlx90632_i2c_write_ExpectAndReturn(MLX90632_REG_CTRL, reg_ctrl_mock_med, 0); + mlx90632_i2c_read_ExpectAndReturn(MLX90632_REG_CTRL, ®_ctrl_mock_med, 0); mlx90632_i2c_read_IgnoreArg_value(); // Ignore input of mock since we use it as output mlx90632_i2c_read_ReturnThruPtr_value(®_ctrl_mock_med);