commit 126ace3c7d3dca82b8e9eee0474558ba582047d9
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Fri Feb 8 15:20:45 2019 +0100

    Updated AMiRo-LLD and adapted the MPU6050 unit test accordingly.
    NOTE: Unfortunately, the unit test fails =(

diff --git a/modules/NUCLEO-L476RG/alldconf.h b/modules/NUCLEO-L476RG/alldconf.h
index de110f8..a644f5c 100644
--- a/modules/NUCLEO-L476RG/alldconf.h
+++ b/modules/NUCLEO-L476RG/alldconf.h
@@ -18,10 +18,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
- * @brief   AMiRo-LLD configuration file for the STM32L476RG-NUCLEO64 module.
+ * @brief   AMiRo-LLD configuration file for the NUCLEO-L476RG module.
  * @details Contains the application specific AMiRo-LLD settings.
  *
- * @addtogroup STM32L476RG-NUCLEO64_config
+ * @addtogroup NUCLEO-L476RG_config
  * @{
  */
 
@@ -43,6 +43,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #define AMIROLLD_CFG_TIME_SIZE                  32
 
+/**
+ * @brief   Enable flag for the MPU6050 proximity sensor.
+ * @note    Uncomment this if the device is attached.
+ */
+//#define AMIROLLD_CFG_MPU6050                    1
+
 #endif /* ALLDCONF_H */
 
 /** @} */
diff --git a/modules/NUCLEO-L476RG/aosconf.h b/modules/NUCLEO-L476RG/aosconf.h
index b135fd3..a905f8a 100644
--- a/modules/NUCLEO-L476RG/aosconf.h
+++ b/modules/NUCLEO-L476RG/aosconf.h
@@ -18,10 +18,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
- * @brief   AMiRo-OS Configuration file for the STM32L476RG-NUCLEO64 module.
+ * @brief   AMiRo-OS Configuration file for the NUCLEO-L476RG module.
  * @details Contains the application specific AMiRo-OS settings.
  *
- * @addtogroup STM32L476RG-NUCLEO64_aos_config
+ * @addtogroup NUCLEO-L476RG_aos_config
  * @{
  */
 
diff --git a/modules/NUCLEO-L476RG/halconf.h b/modules/NUCLEO-L476RG/halconf.h
index 968c775..0b57bf8 100644
--- a/modules/NUCLEO-L476RG/halconf.h
+++ b/modules/NUCLEO-L476RG/halconf.h
@@ -18,12 +18,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
- * @brief   HAL configuration header for the DiWheelDrive v1.1 module.
+ * @brief   HAL configuration header for the NUCLEO-L476RG module.
  * @details HAL configuration file, this file allows to enable or disable the
  *          various device drivers from your application. You may also use
  *          this file in order to override the device drivers default settings.
  *
- * @addtogroup STM32L476RGNUCLEO64_HAL_CONF
+ * @addtogroup NUCLEO-L476RG_HAL_CONF
  * @{
  */
 
@@ -33,6 +33,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define _CHIBIOS_HAL_CONF_
 #define _CHIBIOS_HAL_CONF_VER_6_0_
 
+#include <alldconf.h>
 #include "mcuconf.h"
 
 /**
@@ -88,8 +89,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * @brief   Enables the I2C subsystem.
  */
 #if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
+// enable if MPU6050 demo is enabled
+#if defined(AMIROLLD_CFG_MPU6050)
+#define HAL_USE_I2C                         TRUE
+#else
 #define HAL_USE_I2C                         FALSE
 #endif
+#endif
 
 /**
  * @brief   Enables the I2S subsystem.
diff --git a/modules/NUCLEO-L476RG/module.c b/modules/NUCLEO-L476RG/module.c
index 039d8cd..307162b 100644
--- a/modules/NUCLEO-L476RG/module.c
+++ b/modules/NUCLEO-L476RG/module.c
@@ -18,13 +18,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
- * @brief   Structures and constant for the STM32L476RG-NUCLEO64 module.
+ * @brief   Structures and constant for the NUCLEO-L476RG module.
  *
- * @addtogroup STM32L476RG-NUCLEO64_module
+ * @addtogroup NUCLEO-L476RG_module
  * @{
  */
 
-#include "module.h"
+#include <amiroos.h>
 
 /*===========================================================================*/
 /**
@@ -49,6 +49,16 @@ SerialConfig moduleHalProgIfConfig = {
   /* CR1      */ 0,
 };
 
+#if defined(AMIROLLD_CFG_MPU6050)
+
+I2CConfig moduleHalI2c3Config = {
+  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_COMM_MPU6050() hook
+  /* CR1        */ 0,
+  /* CR2        */ 0,
+};
+
+#endif /* defined(AMIROLLD_CFG_MPU6050) */
+
 /** @} */
 
 /*===========================================================================*/
@@ -121,6 +131,15 @@ ROMCONST char* moduleShellPrompt = "NUCLEO-L476RG";
  */
 /*===========================================================================*/
 
+#if defined(AMIROLLD_CFG_MPU6050)
+
+MPU6050Driver moduleLldMpu6050 = {
+  /* I2C Driver       */ &MODULE_HAL_I2C3,
+  /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
+};
+
+#endif /* defined(AMIROLLD_CFG_MPU6050) */
+
 /** @} */
 
 /*===========================================================================*/
@@ -131,6 +150,34 @@ ROMCONST char* moduleShellPrompt = "NUCLEO-L476RG";
 /*===========================================================================*/
 #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
 
+#if defined(AMIROLLD_CFG_MPU6050)
+
+/* MPU6050 */
+static int _utShellCmdCb_AlldMpu6050(BaseSequentialStream* stream, int argc, char* argv[])
+{
+  (void)argc;
+  (void)argv;
+  aosUtRun(stream, &moduleUtAlldMpu6050, NULL);
+  return AOS_OK;
+}
+static ut_mpu6050data_t _utAlldMpu6050Data = {
+   /* driver */ &moduleLldMpu6050,
+  /* timeout  */ MICROSECONDS_PER_SECOND,
+};
+aos_unittest_t moduleUtAlldMpu6050 = {
+  /* name           */ "MPU6050",
+  /* info           */ "accelerometer and gyroscope",
+  /* test function  */ utAlldMpu6050Func,
+  /* shell command  */ {
+    /* name     */ "unittest:Accelerometer&Gyroscope",
+    /* callback */ _utShellCmdCb_AlldMpu6050,
+    /* next     */ NULL,
+  },
+  /* data           */ &_utAlldMpu6050Data
+};
+
+#endif /* defined(AMIROLLD_CFG_MPU6050) */
+
 #endif /* AMIROOS_CFG_TESTS_ENABLE == true */
 
 /** @} */
diff --git a/modules/NUCLEO-L476RG/module.h b/modules/NUCLEO-L476RG/module.h
index 51f5600..dbbceaa 100644
--- a/modules/NUCLEO-L476RG/module.h
+++ b/modules/NUCLEO-L476RG/module.h
@@ -18,9 +18,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
  * @file
- * @brief   Structures and constant for the STM32L476RG-NUCLEO64 module.
+ * @brief   Structures and constant for the NUCLEO-L476RG module.
  *
- * @addtogroup STM32L476RG-NUCLEO64_module
+ * @addtogroup NUCLEO-L476RG_module
  * @{
  */
 
@@ -28,6 +28,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define AMIROOS_MODULE_H
 
 #include <amiroos.h>
+#include <math.h>
 
 /*===========================================================================*/
 /**
@@ -60,6 +61,20 @@ extern SerialConfig moduleHalProgIfConfig;
  */
 #define MODULE_HAL_RTC                          RTCD1
 
+#if defined(AMIROLLD_CFG_MPU6050)
+
+/**
+ * @brief   I2C driver to access multiplexer, proximity sensors 5 to 8, power monitors for VSYS4.2, VIO 5.0 and VDD, EEPROM, touch sensor, and fuel gauge (front battery).
+ */
+#define MODULE_HAL_I2C3                         I2CD3
+
+/**
+ * @brief   Configuration for the I2C driver #3.
+ */
+extern I2CConfig moduleHalI2c3Config;
+
+#endif /* defined(AMIROLLD_CFG_MPU6050) */
+
 /** @} */
 
 /*===========================================================================*/
@@ -115,7 +130,16 @@ extern ROMCONST char* moduleShellPrompt;
  */
 #define MODULE_INIT_TESTS() {                                                 \
   /* add unit-test shell commands */                                          \
+  MODULE_INIT_TEST_MPU6050();                                                 \
 }
+#if defined(AMIROLLD_CFG_MPU6050)
+  #define MODULE_INIT_TEST_MPU6050() {                                        \
+    /* add unit-test shell commands */                                        \
+    aosShellAddCommand(&aos.shell, &moduleUtAlldMpu6050.shellcmd);            \
+  }
+#else
+  #define MODULE_INIT_TEST_MPU6050() {}
+#endif
 
 /**
  * @brief   Periphery communication interfaces initialization hook.
@@ -123,7 +147,33 @@ extern ROMCONST char* moduleShellPrompt;
 #define MODULE_INIT_PERIPHERY_COMM() {                                        \
   /* serial driver */                                                         \
   sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
+  /* MPU6050 demo */                                                          \
+  MODULE_INIT_PERIPHERY_COMM_MPU6050();                                       \
 }
+#if defined(AMIROLLD_CFG_MPU6050)
+  #define MODULE_INIT_PERIPHERY_COMM_MPU6050() {                              \
+    /* maximum I2C frequency is 1MHz for this MCU */                          \
+    uint32_t i2c3_freq = 1000000;                                             \
+    /* find minimum amon all devices connected to this bus */                 \
+    i2c3_freq = (MPU6050_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : i2c3_freq;  \
+    /* calculate PRESC (prescaler):                                           \
+     *   target is 1/(I2CXCLK * (PRESC + 1)) = 125ns                          \
+     */                                                                       \
+    moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \
+    /* SCL shall be low half of the time. */                                  \
+    moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \
+    /* SCL shall be high half the time of low or slightly longer. */          \
+    moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos;  \
+    /* SDA shall be delayed 1/10 of SCL low, or shorter */                    \
+    moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos;  \
+    /* SCL shall be delyed twice as long as SDA, but longer than 0. */        \
+    moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos;  \
+    /* now we can start the I2C driver */                                     \
+    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
+  }
+#else
+  #define MODULE_INIT_PERIPHERY_COMM_MPU6050() {}
+#endif
 
 /**
  * @brief   Periphery communication interface deinitialization hook.
@@ -160,6 +210,17 @@ extern ROMCONST char* moduleShellPrompt;
  */
 /*===========================================================================*/
 
+#if defined(AMIROLLD_CFG_MPU6050)
+
+#include <alld_MPU6050.h>
+
+/**
+ * @brief   Accelerometer (MPU6050) driver.
+ */
+extern MPU6050Driver moduleLldMpu6050;
+
+#endif /* defined(AMIROLLD_CFG_MPU6050) */
+
 /** @} */
 
 /*===========================================================================*/
@@ -170,6 +231,17 @@ extern ROMCONST char* moduleShellPrompt;
 /*===========================================================================*/
 #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
 
+#if defined(AMIROLLD_CFG_MPU6050)
+
+#include <ut_alld_MPU6050_v1.h>
+
+/**
+ * @brief   MPU6050 unit test object.
+ */
+extern aos_unittest_t moduleUtAlldMpu6050;
+
+#endif /* defined(AMIROLLD_CFG_MPU6050) */
+
 #endif /* AMIROOS_CFG_TESTS_ENABLE == true */
 
 /** @} */
diff --git a/modules/PowerManagement_1-1/module.h b/modules/PowerManagement_1-1/module.h
index 08f6b35..dc36183 100644
--- a/modules/PowerManagement_1-1/module.h
+++ b/modules/PowerManagement_1-1/module.h
@@ -434,7 +434,7 @@ extern ROMCONST char* moduleShellPrompt;
 #define MODULE_INIT_TESTS() {                                                 \
   /* add unit-test shell commands */                                          \
   aosShellAddCommand(&aos.shell, &moduleUtAdcVsys.shellcmd);                  \
-  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01b.shellcmd);            \
+  aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01b.shellcmd);             \
   aosShellAddCommand(&aos.shell, &moduleUtAlldBq24103a.shellcmd);             \
   aosShellAddCommand(&aos.shell, &moduleUtAlldBq27500.shellcmd);              \
   aosShellAddCommand(&aos.shell, &moduleUtAlldBq27500Bq24103a.shellcmd);      \
diff --git a/periphery-lld/AMiRo-LLD b/periphery-lld/AMiRo-LLD
index 5d4d14a..b6364b5 160000
--- a/periphery-lld/AMiRo-LLD
+++ b/periphery-lld/AMiRo-LLD
@@ -1 +1 @@
-Subproject commit 5d4d14a3a119bb8b75f59eaa33496d46e5963a7a
+Subproject commit b6364b519575c41733beff4c8df8b935f373ee53
diff --git a/unittests/periphery-lld/src/ut_alld_MPU6050_v1.c b/unittests/periphery-lld/src/ut_alld_MPU6050_v1.c
index d21531d..cb713fd 100644
--- a/unittests/periphery-lld/src/ut_alld_MPU6050_v1.c
+++ b/unittests/periphery-lld/src/ut_alld_MPU6050_v1.c
@@ -49,18 +49,17 @@ aos_utresult_t utAlldMpu6050Func(BaseSequentialStream* stream, aos_unittest_t* u
 {
     aos_utresult_t result = {0, 0};
 
-    const mpu6050_lld_register_t addr = 0x75; // register to read from
-    uint16_t const data; // buffer for data
-    const uint8_t num = 1; // read one register
-    const apalTime_t timeout = 100; // TODO: Check units
+    uint8_t data[1] = {0};
+    uint32_t status = 0;
 
+    status = mpu6050_lld_read_register(((ut_mpu6050data_t*)ut->data)->mpu, MPU6050_LLD_WHO_AM_I, data, 1, ((ut_mpu6050data_t*)ut->data)->timeout);
+    if (status == APAL_STATUS_OK && data[0] == MPU6050_I_AM) {
+      aosUtPassed(stream, &result);
+    } else {
+      aosUtFailedMsg(stream, &result, "0x%08X | 0x%02X\n", status, data[0]);
+    }
 
-    mpu6050_lld_read_register(((ut_mpu6050data_t*)ut->data)->mpu, addr, &data, num, ((ut_mpu6050data_t*)ut->data)->timeout);
-            /** registers to read:
-            0x75: WHO AM I (should return I2C-Adress without the last bit, which is determined by the state of the AO pin!) returns 0x68
-                      */
-
-  return result; // TODO: Adjust
+  return result;
 }
 
 #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_MPU6050) && (AMIROLLD_CFG_MPU6050 == 1) */
