Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBHostKeyboard_HelloWorld by
Revision 14:c820ae094728, committed 2015-05-04
- 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
--- 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
