commit bffb3465f93e69701c9b64dfa833cf7b0a55e690
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Mon Jan 14 11:15:20 2019 +0100

    Added new periphery hardware (PCAL6524 GPIO extender and AT42QT1050 touch sensor) to the PowerManagement, including unit tests.

diff --git a/modules/PowerManagement_1-1/module.c b/modules/PowerManagement_1-1/module.c
index 1cb6894..11fa65f 100644
--- a/modules/PowerManagement_1-1/module.c
+++ b/modules/PowerManagement_1-1/module.c
@@ -153,11 +153,11 @@ ROMCONST apalControlGpio_t moduleGpioIrInt1 = {
     /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
 #elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
-    /* active state   */ APAL_GPIO_ACTIVE_LOW,
-    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
+    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
+    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
 #elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
-    /* active state   */ APAL_GPIO_ACTIVE_LOW,
-    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
+    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
+    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
 #else
     /* active state   */ APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ APAL_GPIO_EDGE_NONE,
@@ -356,11 +356,11 @@ ROMCONST apalControlGpio_t moduleGpioIrInt2 = {
     /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
 #elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
-    /* active state   */ APAL_GPIO_ACTIVE_LOW,
-    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
+    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
+    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
 #elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
-    /* active state   */ APAL_GPIO_ACTIVE_LOW,
-    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
+    /* active state   */ (PCAL6524_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
+    /* interrupt edge */ PCAL6524_LLD_INT_EDGE,
 #else
     /* active state   */ APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ APAL_GPIO_EDGE_NONE,
@@ -383,11 +383,11 @@ ROMCONST apalControlGpio_t moduleGpioTouchInt = {
     /* active state   */ (MPR121_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ MPR121_LLD_INT_EDGE,
 #elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X)
-    /* active state   */ APAL_GPIO_ACTIVE_LOW,
-    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
+    /* active state   */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
+    /* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
 #elif (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X)
-    /* active state   */ APAL_GPIO_ACTIVE_LOW,
-    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
+    /* active state   */ (AT42QT1050_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
+    /* interrupt edge */ AT42QT1050_LLD_INT_EDGE,
 #else
     /* active state   */ APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ APAL_GPIO_EDGE_NONE,
@@ -667,11 +667,41 @@ VCNL4020Driver moduleLldProximity2 = {
 #endif /* BOARD_SENSORRING == BOARD_PROXIMITYSENSOR */
 
 #if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
-// TODO
+
+PCAL6524Driver moduleLldGpioExtender1 = {
+  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
+  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
+};
+
+PCAL6524Driver moduleLldGpioExtender2 = {
+  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
+  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
+};
+
+AT42QT1050Driver moduleLldTouch = {
+  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
+  /* I²C address  */ AT42QT1050_LLD_I2C_ADDRSEL_LOW,
+};
+
 #endif /* BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X */
 
 #if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
-// TODO
+
+PCAL6524Driver moduleLldGpioExtender1 = {
+  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM18_PM33_GAUGEREAR,
+  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
+};
+
+PCAL6524Driver moduleLldGpioExtender2 = {
+  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
+  /* I²C address  */ PCAL6524_LLD_I2C_ADDR_VDD,
+};
+
+AT42QT1050Driver moduleLldTouch = {
+  /* I²C driver   */ &MODULE_HAL_I2C_SR_PM42_PM50_PMVDD_EEPROM_GAUGEFRONT,
+  /* I²C address  */ AT42QT1050_LLD_I2C_ADDRSEL_LOW,
+};
+
 #endif /* BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X */
 
 /** @} */
@@ -1290,11 +1320,157 @@ aos_unittest_t moduleUtAlldVcnl4020 = {
 #endif /* BOARD_SENSORRING == BOARD_PROXIMITYSENSOR */
 
 #if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X) || defined(__DOXYGEN__)
-// TODO
+
+/*
+ * PCAL6524 (GPIO extender)
+ */
+static int _utShellCmdCb_AlldPcal6524(BaseSequentialStream* stream, int argc, char* argv[])
+{
+  // evaluate arguments
+  if (argc == 2) {
+    if (strcmp(argv[1], "#1") == 0) {
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender1;
+      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #1");
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
+      return AOS_OK;
+    }
+    else if (strcmp(argv[1], "#2") == 0) {
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender2;
+      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #2");
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
+      return AOS_OK;
+    }
+  }
+  // print help
+  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
+  chprintf(stream, "Options:\n");
+  chprintf(stream, "  #1\n");
+  chprintf(stream, "    Test the GPIO extender on the I2C bus #1.\n");
+  chprintf(stream, "  #2\n");
+  chprintf(stream, "    Test the GPIO extender on the I2C bus #2.\n");
+  return AOS_INVALID_ARGUMENTS;
+}
+static ut_pcal6524data_t _utAlldPcal6524Data = {
+  /* driver   */ NULL,
+  /* timeout  */ MICROSECONDS_PER_SECOND,
+};
+aos_unittest_t moduleUtAlldPcal6524 = {
+  /* name           */ "PCAL6524",
+  /* info           */ "GPIO extender",
+  /* test function  */ utAlldPcal6524Func,
+  /* shell command  */ {
+    /* name     */ "unittest:GPIOExtender",
+    /* callback */ _utShellCmdCb_AlldPcal6524,
+    /* next     */ NULL,
+  },
+  /* data           */ &_utAlldPcal6524Data,
+};
+
+/*
+ * AT42QT1050 (touch sensor)
+ */
+static int _utShellCmdCb_AlldAt42qt1050(BaseSequentialStream* stream, int argc, char* argv[])
+{
+  (void)argc;
+  (void)argv;
+  aosUtRun(stream, &moduleUtAlldAt42qt1050, NULL);
+  return AOS_OK;
+}
+static ut_at42qt1050data_t _utAlldMpr121Data= {
+  /* AT42QT1050 driver  */ &moduleLldTouch,
+  /* timeout            */ MICROSECONDS_PER_SECOND,
+  /* event source       */ &aos.events.io,
+  /* event flags        */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
+};
+aos_unittest_t moduleUtAlldAt42qt1050 = {
+  /* name           */ "AT42QT1050",
+  /* info           */ "touch sensor",
+  /* test function  */ utAlldAt42qt1050Func,
+  /* shell command  */ {
+    /* name     */ "unittest:Touch",
+    /* callback */ _utShellCmdCb_AlldAt42qt1050,
+    /* next     */ NULL,
+  },
+  /* data           */ &_utAlldMpr121Data,
+};
+
 #endif /* BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L0X */
 
 #if (BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X) || defined(__DOXYGEN__)
-// TODO
+
+/*
+ * PCAL6524 (GPIO extender)
+ */
+static int _utShellCmdCb_AlldPcal6524(BaseSequentialStream* stream, int argc, char* argv[])
+{
+  // evaluate arguments
+  if (argc == 2) {
+    if (strcmp(argv[1], "#1") == 0) {
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender1;
+      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #1");
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
+      return AOS_OK;
+    }
+    else if (strcmp(argv[1], "#2") == 0) {
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = &moduleLldGpioExtender2;
+      aosUtRun(stream, &moduleUtAlldPcal6524, "I2C bus #2");
+      ((ut_pcal6524data_t*)moduleUtAlldPcal6524.data)->pcal6524d = NULL;
+      return AOS_OK;
+    }
+  }
+  // print help
+  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
+  chprintf(stream, "Options:\n");
+  chprintf(stream, "  #1\n");
+  chprintf(stream, "    Test the GPIO extender on the I2C bus #1.\n");
+  chprintf(stream, "  #2\n");
+  chprintf(stream, "    Test the GPIO extender on the I2C bus #2.\n");
+  return AOS_INVALID_ARGUMENTS;
+}
+static ut_pcal6524data_t _utAlldPcal6524Data = {
+  /* driver   */ NULL,
+  /* timeout  */ MICROSECONDS_PER_SECOND,
+};
+aos_unittest_t moduleUtAlldPcal6524 = {
+  /* name           */ "PCAL6524",
+  /* info           */ "GPIO extender",
+  /* test function  */ utAlldPcal6524Func,
+  /* shell command  */ {
+    /* name     */ "unittest:GPIOExtender",
+    /* callback */ _utShellCmdCb_AlldPcal6524,
+    /* next     */ NULL,
+  },
+  /* data           */ &_utAlldPcal6524Data,
+};
+
+/*
+ * AT42QT1050 (touch sensor)
+ */
+static int _utShellCmdCb_AlldAt42qt1050(BaseSequentialStream* stream, int argc, char* argv[])
+{
+  (void)argc;
+  (void)argv;
+  aosUtRun(stream, &moduleUtAlldAt42qt1050, NULL);
+  return AOS_OK;
+}
+static ut_at42qt1050data_t _utAlldMpr121Data= {
+  /* AT42QT1050 driver  */ &moduleLldTouch,
+  /* timeout            */ MICROSECONDS_PER_SECOND,
+  /* event source       */ &aos.events.io,
+  /* event flags        */ MODULE_OS_IOEVENTFLAGS_TOUCHINT,
+};
+aos_unittest_t moduleUtAlldAt42qt1050 = {
+  /* name           */ "AT42QT1050",
+  /* info           */ "touch sensor",
+  /* test function  */ utAlldAt42qt1050Func,
+  /* shell command  */ {
+    /* name     */ "unittest:Touch",
+    /* callback */ _utShellCmdCb_AlldAt42qt1050,
+    /* next     */ NULL,
+  },
+  /* data           */ &_utAlldMpr121Data,
+};
+
 #endif /* BOARD_SENSORRING == BOARD_DISTANCESENSOR_VL53L1X */
 
 #endif /* AMIROOS_CFG_TESTS_ENABLE == true */
