chirimenBLE for TY51822

Dependencies:   mbed BLE_API nRF51822

Files at this revision

API Documentation at this revision

Comitter:
nakamura_bs
Date:
Mon Dec 24 23:59:17 2018 +0000
Parent:
0:6b1b97df8a36
Commit message:
fixed bugs; GPIO8-10 signal output; high drive GPIO output;

Changed in this revision

board.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6b1b97df8a36 -r 4d21403a5251 board.h
--- a/board.h	Thu Dec 13 02:05:08 2018 +0000
+++ b/board.h	Mon Dec 24 23:59:17 2018 +0000
@@ -10,9 +10,9 @@
 #define GPIO_LED_CONNECT P0_21
 
 // user GPIO table
-static const uint8_t validGpioPins[]  = {0,1,2,3,4,5,6,7,8,10};
-uint8_t eventGpioPins[]                 = {0,0,0,0,0,0,0,0,0,0};
-uint8_t currentGpioLevel[]              = {0,0,0,0,0,0,0,0,0,0};
+static const uint8_t validGpioPins[]  = {0,1,2,3,4,5,6,7,8,10,12};
+uint8_t eventGpioPins[]                 = {0,0,0,0,0,0,0,0,0,0,0};
+uint8_t currentGpioLevel[]              = {0,0,0,0,0,0,0,0,0,0,0};
 DigitalInOut gports[] = { // 実際の動作モードはinitGpio()で指定している
     DigitalInOut(P0_0,PIN_INPUT,PullNone,0),
     DigitalInOut(P0_1,PIN_INPUT,PullNone,0),
@@ -24,4 +24,5 @@
     DigitalInOut(P0_7,PIN_INPUT,PullNone,0),
     DigitalInOut(P0_8,PIN_INPUT,PullNone,0),
     DigitalInOut(P0_10,PIN_INPUT,PullNone,0),
+    DigitalInOut(P0_12,PIN_INPUT,PullNone,0),
     };
diff -r 6b1b97df8a36 -r 4d21403a5251 main.cpp
--- 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();