Hiroh Satoh / keyboard Featured

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
28:1f843a3daab0
Parent:
27:7370b8994603
Child:
29:ec548c473d50
--- a/main.cpp	Mon Aug 22 23:14:42 2016 +0000
+++ b/main.cpp	Tue Aug 23 15:25:30 2016 +0000
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
+// ignore load us_ticker_api
 #include "mbed.h"
-#include "Ticker.h"
 
 #include "HIDController_BLE.h"
 
@@ -220,8 +220,7 @@
 // (pulled-up and two MCP23017 is configured with open drain INT)
 InterruptIn buttonInt(P0_5);
 
-// Ticker ticker;
-DigitalOut statusLed(P0_4, 1);
+DigitalOut statusLed(P0_4, 0);
 
 
 // Unsed pins. Set to output for power consumption
@@ -239,6 +238,8 @@
 static uint8_t keysA[COLS];
 static uint8_t keysB[COLS];
 static bool state = 0;
+#define is_pressed(keys, row, col) (!!(keys[col] & (1<<row)))
+
 // delay for interrupt
 static volatile int8_t pollCount = 50;
 
@@ -252,10 +253,88 @@
 	NRF_POWER->SYSTEMOFF = 1;
 }
 
+/*
+class MyTimerEvent {
+public:
+	static void irq(uint32_t id) {
+	    MyTimerEvent *timer_event = (MyTimerEvent*)id;
+	    timer_event->handler();
+	}
+	
+	MyTimerEvent() : event(), _ticker_data(get_us_ticker_data()) {
+	    ticker_set_handler(_ticker_data, (&MyTimerEvent::irq));
+	}
+    virtual ~MyTimerEvent() {
+    	remove();
+	}
+
+protected:
+    // The handler called to service the timer event of the derived class
+    virtual void handler() = 0;
+
+    // insert in to linked list
+    void insert(timestamp_t timestamp) {
+        ticker_insert_event(_ticker_data, &event, timestamp, (uint32_t)this);
+	}
+
+    // remove from linked list, if in it
+    void remove() {
+        ticker_remove_event(_ticker_data, &event);
+	}
+
+    ticker_event_t event;
+
+    const ticker_data_t *_ticker_data;
+};
+
+class MyTicker : public MyTimerEvent {
+
+public:
+    MyTicker() : MyTimerEvent() {
+    }
+    
+    void attach(void (*fptr)(void), float t) {
+        attach_us(fptr, t * 1000000.0f);
+    }
+    
+    void attach_us(void (*fptr)(void), timestamp_t t) {
+        _function.attach(fptr);
+        setup(t);
+    }
+    
+    virtual ~MyTicker() {
+        detach();
+    }
+
+    void detach() {
+    	remove();
+    	_function.attach(0);
+    }
+
+protected:
+    void setup(timestamp_t t) {
+    	remove();
+	    _delay = t;
+	    insert(_delay + ticker_read(_ticker_data));
+    }
+    virtual void handler() {
+	    insert(event.timestamp + _delay);
+	    _function.call();
+    }
+
+protected:
+    timestamp_t     _delay;    
+    FunctionPointer _function; 
+};
+
+MyTicker ticker;
+*/
+
 void tickerStatus() {
-	statusLed = !statusLed;
+    statusLed = !statusLed;
 }
 
+
 int main(void) {
 	printf("init\r\n");
 
@@ -333,8 +412,8 @@
 			NRF_UART0->TASKS_STOPTX = 1;
 			NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);
 			/**/
-			
-			
+
+			printf("COUNTER %x\r\n", NRF_RTC1->COUNTER);
 			HIDController::waitForEvent();