Skip to content

Commit

Permalink
mbed: Implement host communication over USB/serial
Browse files Browse the repository at this point in the history
Can now be reprogrammed live from Flowhub!
  • Loading branch information
jonnor committed Feb 7, 2014
1 parent f847050 commit 8ebdb4e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -69,8 +69,9 @@ build-avr: install
cd build/avr && $(AVROBJCOPY) -j .text -j .data -O ihex firmware.elf firmware.hex
$(AVRSIZE) -A build/avr/firmware.elf

build-mbed:
build-mbed: install
cd thirdparty/mbed && python2 workspace_tools/build.py -t GCC_ARM -m LPC1768
rm -rf build/mbed
mkdir -p build/mbed
node microflo.js generate $(MBED_GRAPH) build/mbed/main.cpp mbed
cp Makefile.mbed build/mbed/Makefile
Expand Down
2 changes: 1 addition & 1 deletion Makefile.mbed
Expand Up @@ -9,7 +9,7 @@ MBED_OBJDIR=$(MBED_DIR)/TARGET_LPC1768/TOOLCHAIN_GCC_ARM
GCC_BIN =
PROJECT = firmware
OBJECTS = ./main.o
SYS_OBJECTS = $(MBED_OBJDIR)/cmsis_nvic.o $(MBED_OBJDIR)/system_LPC17xx.o $(MBED_OBJDIR)/startup_LPC17xx.o
SYS_OBJECTS = $(MBED_OBJDIR)/cmsis_nvic.o $(MBED_OBJDIR)/system_LPC17xx.o $(MBED_OBJDIR)/startup_LPC17xx.o $(MBED_OBJDIR)/retarget.o
INCLUDE_PATHS = -I. -I$(SOURCE_DIR) -I$(MBED_DIR) -I$(MBED_DIR)/TARGET_LPC1768 -I$(MBED_OBJDIR)
LIBRARY_PATHS = -L$(MBED_OBJDIR)
LIBRARIES = -lmbed
Expand Down
8 changes: 6 additions & 2 deletions microflo/components.cpp
Expand Up @@ -896,18 +896,22 @@ class ATUSBKEY : public Component {

class MbedLPC : public Component {
public:
MbedLPC() : Component(outPorts, 4) {}
MbedLPC() : Component(outPorts, MbedLPCPorts::OutPorts::pin24+1) {}
virtual void process(Packet in, MicroFlo::PortId port) {
using namespace MbedLPCPorts;
if (in.isSetup()) {
send(Packet((long)LED1), OutPorts::led1);
send(Packet((long)LED2), OutPorts::led2);
send(Packet((long)LED3), OutPorts::led3);
send(Packet((long)LED4), OutPorts::led4);
send(Packet((long)p21), OutPorts::pin21);
send(Packet((long)p22), OutPorts::pin22);
send(Packet((long)p23), OutPorts::pin23);
send(Packet((long)p24), OutPorts::pin24);
}
}
private:
Connection outPorts[4];
Connection outPorts[MbedLPCPorts::OutPorts::pin24+1];
};

#else
Expand Down
6 changes: 5 additions & 1 deletion microflo/components.json
Expand Up @@ -316,7 +316,11 @@
"led1": { "id": 0 },
"led2": { "id": 1 },
"led3": { "id": 2 },
"led4": { "id": 3 }
"led4": { "id": 3 },
"pin21": { "id": 4 },
"pin22": { "id": 5 },
"pin23": { "id": 6 },
"pin24": { "id": 7 }
},
"inPorts": {}
},
Expand Down
10 changes: 5 additions & 5 deletions microflo/mbed.hpp
Expand Up @@ -14,23 +14,23 @@ class MbedIO : public IO {

private:
Timer timer;
Serial usbSerial;
public:
MbedIO()
: usbSerial(USBTX, USBRX)
{
timer.start();
}

// Serial
virtual void SerialBegin(int serialDevice, int baudrate) {
// FIXME
usbSerial.baud(baudrate);
}
virtual long SerialDataAvailable(int serialDevice) {
// FIXME
return false;
return usbSerial.readable();
}
virtual unsigned char SerialRead(int serialDevice) {
// FIXME
return 0;
return usbSerial.getc();
}
virtual void SerialWrite(int serialDevice, unsigned char b) {
// FIXME
Expand Down

0 comments on commit 8ebdb4e

Please sign in to comment.