summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBernhard Tittelbach <xro@realraum.at>2012-05-20 03:10:19 +0000
committerBernhard Tittelbach <xro@realraum.at>2012-05-20 03:10:19 +0000
commit1dbde8414c388cced9f373b33c4196e9464155d9 (patch)
tree59492b781ede8d66cf253aa2c99bd3689296f80b /tools
parentadded avr.include.mk with reset capability (diff)
much more cooler reset
git-svn-id: https://svn.spreadspace.org/mur.sat@453 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'tools')
-rw-r--r--tools/atmega324u_usbhid/reset.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/tools/atmega324u_usbhid/reset.c b/tools/atmega324u_usbhid/reset.c
index 7955b1b..63252e1 100644
--- a/tools/atmega324u_usbhid/reset.c
+++ b/tools/atmega324u_usbhid/reset.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
-
+#include <unistd.h>
+#include <stdint.h>
#include "hid.h"
@@ -9,14 +10,42 @@ void sendstr(char * tosend)
rawhid_send(0, tosend, strlen(tosend),1000);
}
+#define NUM_DEVICE_IDS 3
+uint16_t dev_ids[] = {0x0481, 0x0480, 0x0482};
+
int main (int argc, char *argv[])
{
// C-based example is 16C0:0480:FFAB:0200
- int r = rawhid_open(1, 0x16C0, 0x0481, 0xFFAB, 0x0200);
+ int r,d,w;
+ for (d=0; d<NUM_DEVICE_IDS; d++)
+ {
+ r = rawhid_open(1, 0x16C0, dev_ids[d], 0xFFAB, 0x0200);
+ if (r > 0)
+ break;
+ }
if (r <= 0) {
- printf("no rawhid device found\n");
- return -1;
+ printf("no rawhid device found, already in bootloader ?\n");
+ return 0;
+ }
+ sendstr("r"); // clear the buffer
+
+ //now wait until device is gone
+
+ for (w=0; w < 12; w++)
+ {
+ r = rawhid_open(1, 0x16C0, dev_ids[d], 0xFFAB, 0x0200);
+ if (r > 0)
+ {
+ rawhid_close(r);
+ sleep(1);
+ }
+ else
+ {
+ printf("device gone, reboot finished\n");
+ sleep(1);
+ return 0;
+ }
}
- sendstr("r"); // clear the buffer
- return 0;
+ printf("device still there, reboot did not work ?\n");
+ return -1;
}