summaryrefslogtreecommitdiff
path: root/usb-pjon
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-05-03 19:44:47 +0200
committerChristian Pointner <equinox@spreadspace.org>2016-05-03 19:44:47 +0200
commit5e855e95761b936ddba1c964c329c15219f59afd (patch)
treef32a595e28ee00503f9fea91d19bdae322cb875f /usb-pjon
parentadd PJON source to contrib makefile (diff)
added external lib PJON - not working yet..
Diffstat (limited to 'usb-pjon')
-rw-r--r--usb-pjon/Makefile5
-rw-r--r--usb-pjon/usb-pjon.cpp29
2 files changed, 30 insertions, 4 deletions
diff --git a/usb-pjon/Makefile b/usb-pjon/Makefile
index 2848646..e9aecc2 100644
--- a/usb-pjon/Makefile
+++ b/usb-pjon/Makefile
@@ -21,12 +21,11 @@
##
NAME := usb-pjon
-BOARD_TYPE := minimus32
+BOARD_TYPE := teensy2
CXX_OBJ := $(NAME).o
LIBS := util led lufa-descriptor-usbserial usbio
CXX_LIBS := arduino-stub
-EXTERNAL_LIBS := lufa
-#EXTERNAL_LIBS := lufa pjon
+EXTERNAL_LIBS := lufa pjon
SPREADAVR_PATH := ..
PJON_PATH := $(SPREADAVR_PATH)/contrib/PJON
diff --git a/usb-pjon/usb-pjon.cpp b/usb-pjon/usb-pjon.cpp
index eb4e7f8..66d58e1 100644
--- a/usb-pjon/usb-pjon.cpp
+++ b/usb-pjon/usb-pjon.cpp
@@ -31,14 +31,36 @@
#include "usbio.h"
#include "Arduino.h"
-//#include "PJON.h"
+#include "PJON.h"
+PJON bus(5, 45); // Bus connection to pin 12, device id 45
+
+void error_handler(uint8_t code, uint8_t data) {
+ if(code == CONNECTION_LOST) {
+ printf("Connection with device ID %d is lost.\r\n", data);
+ }
+ if(code == PACKETS_BUFFER_FULL) {
+ printf("Packet buffer is full, has now a length of %d\r\n", data);
+ printf("Possible wrong bus configuration!\r\n");
+ printf("higher MAX_PACKETS in PJON.h if necessary.\r\n");
+ }
+ if(code == MEMORY_FULL) {
+ printf("Packet memory allocation failed. Memory is full.\r\n");
+ }
+ if(code == CONTENT_TOO_LONG) {
+ printf("Content is too long, length: %d\r\n", data);
+ }
+ if(code == ID_ACQUISITION_FAIL) {
+ printf("Can't acquire a free id %d\r\n", data);
+ }
+}
void handle_cmd(uint8_t cmd)
{
switch(cmd) {
case '0': led_off(); break;
case '1': led_on(); break;
+ case 's': bus.send(44, "hello", 5); break;
case '!': reset2bootloader(); break;
default: printf("error\r\n"); return;
}
@@ -55,6 +77,10 @@ int main(void)
usbio_init();
sei();
+ arduino_init();
+ bus.begin();
+ bus.set_error(error_handler);
+
for(;;) {
int16_t BytesReceived = usbio_bytes_received();
while(BytesReceived > 0) {
@@ -66,5 +92,6 @@ int main(void)
}
usbio_task();
+ bus.update();
}
}