TEAMUSB / Mbed 2 deprecated TEAMUSB_SLAVE

Dependencies:   USBHost mbed

Fork of USBHostKeyboard_HelloWorld by TEAMUSB

Files at this revision

API Documentation at this revision

Comitter:
armdran
Date:
Mon May 04 15:01:26 2015 +0000
Parent:
13:b05908f05e81
Child:
15:363c54cb2032
Commit message:
- platform & pin switch; - queue size changed; - auto restart on spi failure implemented

Changed in this revision

KL46Z-USBHost.lib Show diff for this revision Revisions of this file
USBHost.lib 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
mbed-rtos.lib Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/KL46Z-USBHost.lib	Thu Apr 16 14:43:44 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/va009039/code/KL46Z-USBHost/#47978c25c9b8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBHost.lib	Mon May 04 15:01:26 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBHost/#c4141c99241d
--- a/main.cpp	Thu Apr 16 14:43:44 2015 +0000
+++ b/main.cpp	Mon May 04 15:01:26 2015 +0000
@@ -1,7 +1,11 @@
 #include "mbed.h"
 #include "USBHostKeyboard.h"
-#include "rtos.h"
-//#include <queue>   
+#include "time.h"
+
+extern "C" void mbed_reset();
+
+clock_t spi_begin = 0;
+clock_t spi_end = 0;
 
 typedef struct {
     uint8_t key;        
@@ -9,10 +13,10 @@
 } keyPress_t;
 
 DigitalOut led(LED1);
-SPISlave device(D11, D12, D13, D10);
-DigitalOut ir(D9);
-Queue<keyPress_t, 16> _keyQueue;
-MemoryPool<keyPress_t, 16> mpool;
+SPISlave device(p5, p6, p7, p8);
+DigitalOut ir(p21);
+Queue<keyPress_t, 1024> _keyQueue;
+MemoryPool<keyPress_t, 1024> mpool;
 
 uint8_t spi_reply_blocking(uint8_t reply = 0x00, bool sendIr = 0) {
     device.reply(reply);
@@ -30,14 +34,18 @@
 void onKeyMod(uint8_t key, uint8_t modifier) {
     keyPress_t *keypress = mpool.alloc();
     keypress->key = key;
-    keypress->modifier = modifier;    
+    keypress->modifier = modifier;
     _keyQueue.put(keypress);
 }
 
 void spi_task(void const *) {
+    
     while(1){
         osEvent evt = _keyQueue.get();
         if (evt.status == osEventMessage) {
+            
+            spi_begin = clock(); 
+            
             keyPress_t *keypress = (keyPress_t*)evt.value.p;
             uint8_t key = keypress->key;
             uint8_t modifier = keypress->modifier;
@@ -60,7 +68,9 @@
                 printf("    key ack ok\r\n");
              
             mpool.free(keypress);
-                
+            
+            spi_end = clock();
+                            
         }            
     }
 }
@@ -83,16 +93,30 @@
         printf("eventhandler attached\r\n");
         // wait until the keyboard is disconnected
         while(keyboard.connected()) {
-            USBHost::poll();
+            //USBHost::poll();
+            Thread::wait(500);
         }
         printf("disconnected\r\n");
     }
 }
 
+void alive_task(void const *) {
+    while(1) {
+        if(spi_begin > spi_end) {
+            float diff = ((float)clock() - (float)spi_begin) / CLOCKS_PER_SEC;
+            if(diff > .5) {
+                mbed_reset();
+            }
+        }
+        Thread::wait(2000);
+    }
+}
+
 int main() {
     ir = 0;
     Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
     Thread spiTask(spi_task, NULL, osPriorityNormal, 256 * 4);
+    Thread aliveTask(alive_task, NULL, osPriorityNormal, 256 * 4);
     device.frequency(1000000);
     device.format(8, 1);
     while(1) {}
--- a/mbed-rtos.lib	Thu Apr 16 14:43:44 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#d3d0e710b443
--- a/mbed.bld	Thu Apr 16 14:43:44 2015 +0000
+++ b/mbed.bld	Mon May 04 15:01:26 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058
\ No newline at end of file