commit 0b989911121411d561b0127517f258468aa2e528
Author: Cung Sang <csang@techfak.uni-bielefeld.de>
Date:   Fri Aug 9 12:55:10 2019 +0200

    added DW1000 test and demo on top of Light Ring module

diff --git a/modules/LightRing_1-2/module.h b/modules/LightRing_1-2/module.h
index ffb29a4..02431f3 100644
--- a/modules/LightRing_1-2/module.h
+++ b/modules/LightRing_1-2/module.h
@@ -36,6 +36,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /*===========================================================================*/
 
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+#if (BOARD_DW1000_CONNECTED == true)
+void process_deca_irq(void);
+apalGpioState_t port_CheckEXT_IRQ(void) ;
+#endif /* (BOARD_DW1000_CONNECTED == true) */
+
+void set_SPI_chip_select(void);
+void clear_SPI_chip_select(void);
+void reset_DW1000(void);
+
+#if defined(__cplusplus)
+}
+#endif /* defined(__cplusplus) */
+
 /** @} */
 
 /*===========================================================================*/
@@ -85,11 +103,32 @@ extern SerialConfig moduleHalProgIfConfig;
  */
 extern SPIConfig moduleHalSpiLightConfig;
 
+#if (BOARD_DW1000_CONNECTED == true)
+/**
+ * @brief   SPI interface driver for UWB DW1000 module.
+ */
+#define MODULE_HAL_SPI_UWB                      SPID2
+
+/**
+ * @brief   Configuration for the high-speed SPI interface driver of DW1000 module.
+ */
+extern SPIConfig moduleHalSpiUwbHsConfig;
+
+/**
+ * @brief   Configuration for the low-speed SPI interface driver of DW1000 module.
+ */
+extern SPIConfig moduleHalSpiUwbLsConfig;
+
+#else
+
 /**
  * @brief   SPI interface driver for the breakout header.
  */
 #define MODULE_HAL_SPI_BREAKOUT                 SPID2
 
+#endif /* BOARD_DW1000_CONNECTED == true*/
+
+
 /**
  * @brief   UART interface driver for the breakout header (alternative to serial).
  */
@@ -156,16 +195,6 @@ extern apalControlGpio_t moduleGpioBreakoutIo6;
 extern ROMCONST apalControlGpio_t moduleGpioSysUartDn;
 
 /**
- * @brief   IO_7 breakout signal GPIO.
- */
-extern apalControlGpio_t moduleGpioBreakoutIo7;
-
-/**
- * @brief   IO_8 breakout signal GPIO.
- */
-extern apalControlGpio_t moduleGpioBreakoutIo8;
-
-/**
  * @brief   IO_4 breakout signal GPIO.
  */
 extern apalControlGpio_t moduleGpioBreakoutIo4;
@@ -176,11 +205,6 @@ extern apalControlGpio_t moduleGpioBreakoutIo4;
 extern apalControlGpio_t moduleGpioBreakoutIo1;
 
 /**
- * @brief   IO_2 breakout signal GPIO.
- */
-extern apalControlGpio_t moduleGpioBreakoutIo2;
-
-/**
  * @brief   LED output signal GPIO.
  */
 extern ROMCONST apalControlGpio_t moduleGpioLed;
@@ -215,6 +239,48 @@ extern ROMCONST apalControlGpio_t moduleGpioSysPd;
  */
 extern ROMCONST apalControlGpio_t moduleGpioSysSync;
 
+#if (BOARD_DW1000_CONNECTED == true)
+/**
+ * @brief   DW1000 reset output signal
+ * @note    the reset pin should be drived as low by MCU to activate.
+ *          Then, put back the reset pin as input to MCU (tri-state float on the air
+ *          is not supported in AMiRo)
+ */
+extern ROMCONST apalControlGpio_t moduleGpioDw1000Reset;
+
+/**
+ * @brief   DW1000 wakeup signal
+ */
+extern ROMCONST apalControlGpio_t moduleGpioDw1000WakeUp;
+
+/**
+ * @brief   DW1000 interrupt IRQn input signal.
+ */
+extern ROMCONST apalControlGpio_t moduleGpioDw1000Irqn;
+
+/**
+ * @brief   DW1000 SPI chip select  output signal.
+ */
+extern ROMCONST apalControlGpio_t moduleGpioSpiChipSelect ;
+
+#else
+/**
+ * @brief   IO_2 breakout signal GPIO.
+ */
+extern apalControlGpio_t moduleGpioBreakoutIo2;
+
+/**
+ * @brief   IO_7 breakout signal GPIO.
+ */
+extern apalControlGpio_t moduleGpioBreakoutIo7;
+
+/**
+ * @brief   IO_8 breakout signal GPIO.
+ */
+extern apalControlGpio_t moduleGpioBreakoutIo8;
+
+#endif /* BOARD_DW1000_CONNECTED == true */
+
 /** @} */
 
 /*===========================================================================*/
@@ -275,6 +341,11 @@ extern ROMCONST apalControlGpio_t moduleGpioSysSync;
 #define MODULE_OS_IOEVENTFLAGS_BREAKOUTIO8      AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_8))
 
 /**
+ * @brief   Event flag to be set on a DW1000 interrupt.
+ */
+#define MODULE_OS_IOEVENTFLAGS_DW1000           AOS_IOEVENT_FLAG(PAL_PAD(LINE_IO_8))
+
+/**
  * @brief   Event flag to be set on a SYS_PD interrupt.
  */
 #define MODULE_OS_IOEVENTFLAGS_SYSPD            AOS_IOEVENT_FLAG(PAL_PAD(LINE_SYS_PD_N))
@@ -292,7 +363,17 @@ extern ROMCONST char* moduleShellPrompt;
  */
 #define MODULE_INIT_INTERRUPTS() {                                            \
   /* breakout interrupts must be enabled explicitely */                       \
+  MODULE_INIT_INTERRUPTS_DW1000();                                            \
 }
+#if (BOARD_DW1000_CONNECTED == true)
+  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
+    palSetLineCallback(moduleGpioDw1000Irqn.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioDw1000Irqn.gpio->line);  \
+    palEnableLineEvent(moduleGpioDw1000Irqn.gpio->line, APAL2CH_EDGE(moduleGpioDw1000Irqn.meta.edge));                  \
+  }
+#else /* (BOARD_DW1000_CONNECTED == true) */
+  #define MODULE_INIT_INTERRUPTS_DW1000() {                                   \
+  }
+#endif /* (BOARD_DW1000_CONNECTED == true) */
 
 /**
  * @brief   Unit test initialization hook.
@@ -305,7 +386,16 @@ extern ROMCONST char* moduleShellPrompt;
   aosShellAddCommand(&aos.shell, &moduleTestMic9404xShellCmd);                \
   aosShellAddCommand(&aos.shell, &moduleTestTlc5947ShellCmd);                 \
   aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
+  MODULE_INIT_TESTS_DW1000();                                                 \
 }
+#if (BOARD_DW1000_CONNECTED == true)
+  #define MODULE_INIT_TESTS_DW1000() {                                        \
+    aosShellAddCommand(&aos.shell, &moduleTestDw1000ShellCmd);                \
+  }
+#else /* defined(AMIROLLD_CFG_DW1000) */
+  #define MODULE_INIT_TESTS_DW1000() {                                        \
+  }
+#endif /* BOARD_DW1000_CONNECTED == true */
 
 /**
  * @brief   Periphery communication interfaces initialization hook.
@@ -320,7 +410,16 @@ extern ROMCONST char* moduleShellPrompt;
   i2cStart(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT, &moduleHalI2cEepromPwrmtrBreakoutConfig);  \
   /* SPI */                                                                   \
   spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig);                  \
+  MODULE_INIT_PERIPHERY_COMM_DW1000();                                        \
 }
+#if (BOARD_DW1000_CONNECTED == true)
+  #define MODULE_INIT_PERIPHERY_COMM_DW1000() {                               \
+  spiStart(&MODULE_HAL_SPI_UWB, &moduleHalSpiUwbLsConfig);                    \
+  }
+#else /* defined(AMIROLLD_CFG_DW1000) */
+  #define MODULE_INIT_PERIPHERY_COMM_DW1000() {                               \
+  }
+#endif /* BOARD_DW1000_CONNECTED == true */
 
 /**
  * @brief   Periphery communication interface deinitialization hook.
@@ -330,8 +429,36 @@ extern ROMCONST char* moduleShellPrompt;
   spiStop(&MODULE_HAL_SPI_LIGHT);                                             \
   /* I2C */                                                                   \
   i2cStop(&MODULE_HAL_I2C_EEPROM_PWRMTR_BREAKOUT);                            \
+  MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000();                                    \
   /* don't stop the serial driver so messages can still be printed */         \
 }
+#if (BOARD_DW1000_CONNECTED == true)
+#define MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000() {                             \
+  /* SPI */                                                                   \
+  spiStop(&MODULE_HAL_SPI_UWB);                                               \
+}
+#else /* defined(AMIROLLD_CFG_DW1000) */
+  #define MODULE_SHUTDOWN_PERIPHERY_COMM_DW1000() {                           \
+  }
+#endif /* BOARD_DW1000_CONNECTED == true */
+
+
+/**
+ * @brief   HOOK to call process_deca_irq() func when the dw1000 interrupt pin is activated.
+ */
+#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) {                               \
+  MODULE_MAIN_LOOP_IO_EVENT_DW1000();                                         \
+}
+#if (BOARD_DW1000_CONNECTED == true)
+  #define MODULE_MAIN_LOOP_IO_EVENT_DW1000() {                                \
+    if(eventflags & MODULE_OS_IOEVENTFLAGS_DW1000) {                          \
+      process_deca_irq();                                                     \
+    }                                                                         \
+  }
+#else /* defined(AMIROLLD_CFG_DW1000) */
+  #define MODULE_MAIN_LOOP_IO_EVENT_DW1000() {                                \
+  }
+#endif /* BOARD_DW1000_CONNECTED == true */
 
 /** @} */
 
@@ -396,6 +523,7 @@ extern ROMCONST char* moduleShellPrompt;
 #include <alld_MIC9404x.h>
 // TODO: add SNx5C3221E
 #include <alld_TLC5947.h>
+#include <alld_DW1000.h>
 
 /**
  * @brief   EEPROM driver.
@@ -445,6 +573,15 @@ extern MIC9404xDriver moduleLldPowerSwitchVsys;
  */
 extern TLC5947Driver moduleLldLedPwm;
 
+/**
+ * @brief   DW1000 driver.
+ */
+void setHighSpeed_SPI(bool speedValue, DW1000Driver* drv);
+#if (BOARD_DW1000_CONNECTED == true)
+extern DW1000Driver moduleLldDw1000;
+extern MIC9404xDriver moduleLldPowerSwitchDw1000;
+#endif /* (BOARD_DW1000_CONNECTED == true) */
+
 /** @} */
 
 /*===========================================================================*/
@@ -487,6 +624,14 @@ extern aos_shellcommand_t moduleTestTlc5947ShellCmd;
  */
 extern aos_shellcommand_t moduleTestAllShellCmd;
 
+
+#if (BOARD_DW1000_CONNECTED == true)
+/**
+ * @brief   DW1000 (UWB transmitter) test command.
+ */
+extern aos_shellcommand_t moduleTestDw1000ShellCmd;
+#endif /* (BOARD_DW1000_CONNECTED == true) */
+
 #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
 
 /** @} */
