Multitech xDot Utils

Revision:
1:73cea350269e
Parent:
0:a5748bc6e3e1
Child:
2:8d1c64670642
--- a/MultitechDot.cpp	Mon May 15 00:59:32 2017 +0300
+++ b/MultitechDot.cpp	Thu Jul 20 16:43:35 2017 +0300
@@ -1,5 +1,13 @@
+#include "ChannelPlan.h"
+#include "plans/ChannelPlan_EU868.h"
 #include "MultitechDot.h"
 
+MultitechDot *MultitechDot::getInstance() {
+    using namespace lora;
+    ChannelPlan *plan = new ChannelPlan_EU868();
+    return (MultitechDot *) mDot::getInstance(plan);
+}
+
 void MultitechDot::config(uint8_t *network_address, uint8_t *network_session_key, uint8_t *data_session_key,
                           uint8_t frequency_sub_band, bool public_network, uint8_t ack) {
     if (!this->getStandbyFlag()) {
@@ -58,9 +66,7 @@
     logInfo("version ------------------ %s", this->getId().c_str());
     logInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(this->getDeviceId()).c_str());
     logInfo("frequency band ----------- %s", this->FrequencyBandStr(this->getFrequencyBand()).c_str());
-    if (this->getFrequencySubBand() != this->FB_EU868) {
-        logInfo("frequency sub band ------- %u", this->getFrequencySubBand());
-    }
+    logInfo("frequency sub band ------- %u", this->getFrequencySubBand());
     logInfo("public network ----------- %s", this->getPublicNetwork() ? "on" : "off");
     logInfo("=========================");
     logInfo("credentials configuration");
@@ -502,14 +508,26 @@
     if (!deepsleep) {
         // restore the GPIO state.
         this->sleep_restore_io();
+        this->sleep_reset_hsi();
     }
 }
 
+void MultitechDot::sleep_reset_hsi() {
+    // Enable the HSI (to clock the ADC)
+    RCC_OscInitTypeDef RCC_OscInitStruct;
+    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
+    HAL_RCC_OscConfig(&RCC_OscInitStruct);
+}
+
 void MultitechDot::sleep_save_io() {
+    logInfo("Save GPIO states");
     xdot_save_gpio_state();
 }
 
 void MultitechDot::sleep_configure_io() {
+    logInfo("Configure GPIO for lowest current");
     // GPIO Ports Clock Enable
             __GPIOA_CLK_ENABLE();
             __GPIOB_CLK_ENABLE();
@@ -576,6 +594,7 @@
 }
 
 void MultitechDot::sleep_restore_io() {
+    logInfo("Restore GPIO states");
     xdot_restore_gpio_state();
 }