summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-05-05 17:47:13 +0200
committerNao Pross <naopross@thearcway.org>2018-05-05 17:53:20 +0200
commitb51fb2210af1b6eb4ee8dbc31f77a14a3f3d5230 (patch)
treee6fe4c0ce6164e289bd8014773eaae0553ede163
parentAdd led class (diff)
downloadSAMLiquidSmoke-b51fb2210af1b6eb4ee8dbc31f77a14a3f3d5230.tar.gz
SAMLiquidSmoke-b51fb2210af1b6eb4ee8dbc31f77a14a3f3d5230.zip
Add command selection code, note: split() does't work yet
-rw-r--r--main.cpp114
-rw-r--r--nbproject/Makefile-default.mk36
-rw-r--r--nbproject/Makefile-genesis.properties4
-rw-r--r--nbproject/configurations.xml98
4 files changed, 228 insertions, 24 deletions
diff --git a/main.cpp b/main.cpp
index 860460c..fec1ba0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -15,8 +15,13 @@
#include "hal/uart.tpp"
#include "hal/pin.tpp"
+// high level
+#include "led.hpp"
+
// standard library
#include <string>
+#include <vector>
+#include <algorithm>
// microchip libraries
extern "C" {
@@ -24,34 +29,123 @@ extern "C" {
// #include <proc/p32mx470f512h.h>
}
+std::vector<std::string> split(const std::string& str, const char sep)
+{
+ std::vector<std::string> v;
+
+ size_t last = 0;
+ size_t next = 0;
+
+ while ((next = str.find(sep, last)) != std::string::npos) {
+ v.push_back(str.substr(next, next +1));
+ last = next + 1;
+ }
+
+ v.push_back(str.substr(last));
+
+ return v;
+}
+
+void strip(std::string &str)
+{
+ const std::string strip_chars = "\n\r\b\t\f";
+ for (const char &ch : strip_chars) {
+ str.erase(std::remove_if(str.begin(), str.end(), [ch](const char &c){ return c == ch; }), str.end());
+ }
+}
int main(int argc, char** argv)
{
osc::initialize();
interrupts::initialize();
+
+ // initialize uart and enable echo
uart::initialize<1>();
+ uart::echo<1>(true);
+
+ // initialize pin as outputs
+ io_pin<4> led1_pin(&LATEbits, &TRISEbits, &PORTEbits);
+ io_pin<6> led2_pin(&LATEbits, &TRISEbits, &PORTEbits);
+ io_pin<7> led3_pin(&LATEbits, &TRISEbits, &PORTEbits);
- pin<4> led1(&LATEbits, &TRISEbits, &PORTEbits);
- pin<6> led2(&LATEbits, &TRISEbits, &PORTEbits);
- pin<7> led3(&LATEbits, &TRISEbits, &PORTEbits);
+ // build leds
+ led led1(static_cast<gpio *>(&led1_pin), led::color::RED);
+ led led2(static_cast<gpio *>(&led2_pin), led::color::GREEN);
+ led led3(static_cast<gpio *>(&led3_pin), led::color::YELLOW);
+#ifdef DEBUG
led1.set(1);
led2.set(1);
led3.set(1);
uart::write<1>("started\n\r");
+#endif
while (true) {
+ std::string input = "";
+
+ // write prompt
+ uart::write<1>("> ");
+
while (uart::rx_buffer<1>().empty());
- while (uart::rx_buffer<1>().size() > 0) {
- char c = uart::read<1>();
-
- uart::write<1>(c);
- uart::write<1>("\n\r");
- }
+ do {
+ input += uart::read_wait<1>();
+ } while (uart::rx_buffer<1>().front() != '\r');
+ // remove '\r' from the RX buffer
+ uart::rx_buffer<1>().pop();
+
+#ifdef DEBUG
+ uart::write<1>("\n\rinput: ");
+ uart::print<1>(input);
+#endif
+
+ // remove weird symbols
+ strip(input);
+
+ // split
+ const std::vector<std::string> command = split(input, ' ');
- led1.toggle();
+#ifdef DEBUG
+ for (const std::string &s : command) {
+ uart::print<1>(s);
+ }
+#endif
+
+ if (command.size() == 1) {
+ if (command[0] == "help") {
+ uart::print<1>("TODO: help text");
+ }
+ } else if (command.size() == 3) {
+ if (command[0] == "show") {
+ uart::print<1>(led1.to_string());
+ uart::print<1>(led2.to_string());
+ uart::print<1>(led3.to_string());
+ continue;
+ }
+
+ if (command[0] == "set") {
+ if (command[1] == "baudrate") {
+ // TODO
+ }
+ }
+ } else if (command.size() == 4) {
+ if (command[0] == "set") {
+ if (command[1] == "led") {
+ if (command[2] == "red") {
+ led1.set((command[3] == "on"));
+ } else if (command[2] == "green") {
+ led2.set((command[3] == "on"));
+ } else if (command[2] == "yellow") {
+ led3.set((command[3] == "on"));
+ } else if (command[2] == "all") {
+ led1.set((command[3] == "on"));
+ led2.set((command[3] == "on"));
+ led3.set((command[3] == "on"));
+ }
+ }
+ }
+ }
}
return 0;
diff --git a/nbproject/Makefile-default.mk b/nbproject/Makefile-default.mk
index 920c95b..3dcd31b 100644
--- a/nbproject/Makefile-default.mk
+++ b/nbproject/Makefile-default.mk
@@ -57,17 +57,17 @@ OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
# Source Files Quoted if spaced
-SOURCEFILES_QUOTED_IF_SPACED=main.cpp hal/hwconfig.cpp
+SOURCEFILES_QUOTED_IF_SPACED=hal/hwconfig.cpp main.cpp led.cpp
# Object Files Quoted if spaced
-OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/main.o ${OBJECTDIR}/hal/hwconfig.o
-POSSIBLE_DEPFILES=${OBJECTDIR}/main.o.d ${OBJECTDIR}/hal/hwconfig.o.d
+OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/hal/hwconfig.o ${OBJECTDIR}/main.o ${OBJECTDIR}/led.o
+POSSIBLE_DEPFILES=${OBJECTDIR}/hal/hwconfig.o.d ${OBJECTDIR}/main.o.d ${OBJECTDIR}/led.o.d
# Object Files
-OBJECTFILES=${OBJECTDIR}/main.o ${OBJECTDIR}/hal/hwconfig.o
+OBJECTFILES=${OBJECTDIR}/hal/hwconfig.o ${OBJECTDIR}/main.o ${OBJECTDIR}/led.o
# Source Files
-SOURCEFILES=main.cpp hal/hwconfig.cpp
+SOURCEFILES=hal/hwconfig.cpp main.cpp led.cpp
CFLAGS=
@@ -112,30 +112,42 @@ endif
# ------------------------------------------------------------------------------------
# Rules for buildStep: compileCPP
ifeq ($(TYPE_IMAGE), DEBUG_RUN)
+${OBJECTDIR}/hal/hwconfig.o: hal/hwconfig.cpp nbproject/Makefile-${CND_CONF}.mk
+ @${MKDIR} "${OBJECTDIR}/hal"
+ @${RM} ${OBJECTDIR}/hal/hwconfig.o.d
+ @${RM} ${OBJECTDIR}/hal/hwconfig.o
+ @${FIXDEPS} "${OBJECTDIR}/hal/hwconfig.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPKOBSKDEPlatformTool=1 -fframe-base-loclist -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/hal/hwconfig.o.d" -o ${OBJECTDIR}/hal/hwconfig.o hal/hwconfig.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
+
${OBJECTDIR}/main.o: main.cpp nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} "${OBJECTDIR}"
@${RM} ${OBJECTDIR}/main.o.d
@${RM} ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPKOBSKDEPlatformTool=1 -fframe-base-loclist -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
+${OBJECTDIR}/led.o: led.cpp nbproject/Makefile-${CND_CONF}.mk
+ @${MKDIR} "${OBJECTDIR}"
+ @${RM} ${OBJECTDIR}/led.o.d
+ @${RM} ${OBJECTDIR}/led.o
+ @${FIXDEPS} "${OBJECTDIR}/led.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPKOBSKDEPlatformTool=1 -fframe-base-loclist -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/led.o.d" -o ${OBJECTDIR}/led.o led.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
+
+else
${OBJECTDIR}/hal/hwconfig.o: hal/hwconfig.cpp nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} "${OBJECTDIR}/hal"
@${RM} ${OBJECTDIR}/hal/hwconfig.o.d
@${RM} ${OBJECTDIR}/hal/hwconfig.o
- @${FIXDEPS} "${OBJECTDIR}/hal/hwconfig.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -D__DEBUG -DPKOBSKDEPlatformTool=1 -fframe-base-loclist -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/hal/hwconfig.o.d" -o ${OBJECTDIR}/hal/hwconfig.o hal/hwconfig.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
+ @${FIXDEPS} "${OBJECTDIR}/hal/hwconfig.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/hal/hwconfig.o.d" -o ${OBJECTDIR}/hal/hwconfig.o hal/hwconfig.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
-else
${OBJECTDIR}/main.o: main.cpp nbproject/Makefile-${CND_CONF}.mk
@${MKDIR} "${OBJECTDIR}"
@${RM} ${OBJECTDIR}/main.o.d
@${RM} ${OBJECTDIR}/main.o
@${FIXDEPS} "${OBJECTDIR}/main.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/main.o.d" -o ${OBJECTDIR}/main.o main.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
-${OBJECTDIR}/hal/hwconfig.o: hal/hwconfig.cpp nbproject/Makefile-${CND_CONF}.mk
- @${MKDIR} "${OBJECTDIR}/hal"
- @${RM} ${OBJECTDIR}/hal/hwconfig.o.d
- @${RM} ${OBJECTDIR}/hal/hwconfig.o
- @${FIXDEPS} "${OBJECTDIR}/hal/hwconfig.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/hal/hwconfig.o.d" -o ${OBJECTDIR}/hal/hwconfig.o hal/hwconfig.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
+${OBJECTDIR}/led.o: led.cpp nbproject/Makefile-${CND_CONF}.mk
+ @${MKDIR} "${OBJECTDIR}"
+ @${RM} ${OBJECTDIR}/led.o.d
+ @${RM} ${OBJECTDIR}/led.o
+ @${FIXDEPS} "${OBJECTDIR}/led.o.d" $(SILENT) -rsi ${MP_CC_DIR}../ -c ${MP_CPPC} $(MP_EXTRA_CC_PRE) -g -x c++ -c -mprocessor=$(MP_PROCESSOR_OPTION) -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF "${OBJECTDIR}/led.o.d" -o ${OBJECTDIR}/led.o led.cpp -DXPRJ_default=$(CND_CONF) $(COMPARISON_BUILD)
endif
diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties
index a13ad0c..bd9d9ba 100644
--- a/nbproject/Makefile-genesis.properties
+++ b/nbproject/Makefile-genesis.properties
@@ -1,8 +1,8 @@
#
-#Fri May 04 18:20:47 CEST 2018
+#Sat May 05 14:33:20 CEST 2018
default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=fcf9db1a3d46b4ef4e0a46afcbf02251
default.languagetoolchain.dir=/opt/microchip/xc32/v2.05/bin
-configurations-xml=1b1713a10a7ac2a1a8df14051c73140a
+configurations-xml=4957a7627114c3c1c982e099652971a3
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=c8c2915d32f5d7e4be49831bc9827ab0
default.languagetoolchain.version=2.05
host.platform=linux
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index bbc3864..8f500b7 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -40,6 +40,8 @@
<itemPath>mcc_generated_files/uart1.c</itemPath>
</logicalFolder>
<itemPath>main.cpp</itemPath>
+ <itemPath>led.hpp</itemPath>
+ <itemPath>led.cpp</itemPath>
</logicalFolder>
<logicalFolder name="ExternalFiles"
displayName="Important Files"
@@ -244,22 +246,118 @@
<item path="mcc_generated_files/interrupt_manager.c"
ex="true"
overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/interrupt_manager.h"
ex="true"
overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/mcc.c" ex="true" overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/mcc.h" ex="true" overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/pin_manager.c" ex="true" overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/pin_manager.h" ex="true" overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/uart1.c" ex="true" overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
<item path="mcc_generated_files/uart1.h" ex="true" overriding="false">
+ <C32>
+ </C32>
+ <C32-AR>
+ </C32-AR>
+ <C32-AS>
+ </C32-AS>
+ <C32-LD>
+ </C32-LD>
+ <C32CPP>
+ </C32CPP>
+ <C32Global>
+ </C32Global>
</item>
</conf>
</confs>