chirimenBLE for TY51822

Dependencies:   mbed BLE_API nRF51822

Revision:
1:4d21403a5251
Parent:
0:6b1b97df8a36
--- a/main.cpp	Thu Dec 13 02:05:08 2018 +0000
+++ b/main.cpp	Mon Dec 24 23:59:17 2018 +0000
@@ -1,3 +1,16 @@
+/*
+ * Chirimen BLE farmware
+ * copylight KDDI Technorogy
+ *
+ * change log
+ * 2018/11/28 初回リリース
+ * 2018/12/03 GPIO端子の初期値不定を修正
+ * 2018/12/19 GPIO ドライブ能力変更 (0.5mA -> 5mA)
+ * 2018/12/20 nRF51ライブラリのバグ対策 -- RTS/CTSの割り当て禁止
+ *            送信出力を +4dBmに規定
+ */
+
+
 #include "mbed.h"
 #include "BLE.h"
 
@@ -17,7 +30,6 @@
 #define DEBUG(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
-
 #ifdef MICROBIT
 // micro:bit matrix-led
 DigitalOut col0(P0_4, 0);
@@ -36,7 +48,6 @@
 #define CMD_ADC_INPUT   0x30
 #define CMD_ADC_READ    0x31
 
-
 // Bluetooth Low Energy
 BLE ble;
 static Gap::ConnectionParams_t connectionParams;
@@ -136,8 +147,18 @@
         eventGpioPins[gpioNum] = 0;     // イベント監視対象外
         reloadGpioCondition(); // 設定を更新
     }
+    
+    // nRF51ライブラリのバグ対策 -- RTS/CTSの割り当て禁止
+    NRF_UART0->PSELRTS = 0xFFFFFFFF;
+    NRF_UART0->PSELCTS = 0xFFFFFFFF;
 }
 
+// set high drive (Low/High 5mA)
+void hiDriveGpio(int gpioNum) {
+    NRF_GPIO->PIN_CNF[gpioNum] =
+        (NRF_GPIO->PIN_CNF[gpioNum] & ~GPIO_PIN_CNF_DRIVE_Msk) |
+        (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos);
+}
 /* --- BLE callbacks ------------------------------------------------------------------- */
 void onDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)    // Mod
 {
@@ -183,8 +204,6 @@
     statData[0] = 0;
     statData[1] = VERSION_NUM;
     ble.gattServer().write(gStatCharacteristic.getValueAttribute().getHandle(), statData, 4);
-
-
 }
 
 void ConnectTimeoutCallback(Gap::TimeoutSource_t source)
@@ -300,6 +319,9 @@
                 DEBUG("set GPIO output  %d\r\n",gCmdData[4]);
                 gports[gpioNum] = 0; // inital state low
                 gports[gpioNum].output();
+                hiDriveGpio(gpioNum); // set high drive (Low/High 5mA)
+
+
             } else {
                 DEBUG("set GPIO input %d\r\n",gCmdData[4]);
                 gports[gpioNum].input();
@@ -533,6 +555,7 @@
     gScanGPIO = 0;
 
     initGpio();
+    hiDriveGpio(GPIO_LED_CONNECT);
     DEBUG("PowerON version %d\n\r",VERSION_NUM);
     
     /* Initialise the nRF51822 */
@@ -547,7 +570,10 @@
     ble.onDataSent(DataSentCallback);
     ble.onUpdatesEnabled(UpdatesEnabledCallBack);
     ble.onUpdatesDisabled(UpdatesDisabledCallBack);
-
+    
+    // set TX power
+    // Valid values are -40, -20, -16, -12, -8, -4, 0, 4)
+    ble.setTxPower(4);
 
     /* setup advertising */
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
@@ -564,7 +590,6 @@
 
     ble.addService(gGpioService);
 
-// tako();
     LED_CONNECT = 0;
     for (;; ) {
         ble.waitForEvent();