From 5da2f46b0fe437ab805f3a4ebc1eafbdbb30ce6f Mon Sep 17 00:00:00 2001 From: Jake Read <jake.read@cba.mit.edu> Date: Fri, 1 Apr 2022 17:20:18 -0400 Subject: [PATCH] blade plate to new modules --- .gitmodules | 9 +++ .../blade-plate-head/.vscode/extensions.json | 3 + firmware/blade-plate-head/src/main.cpp | 36 ++++++---- firmware/blade-plate-head/src/osap_config.h | 33 ++++++++++ .../src/{syserror.cpp => osap_debug.cpp} | 66 +++++++++---------- firmware/blade-plate-head/src/osap_debug.h | 34 ++++++++++ firmware/blade-plate-head/src/osape | 1 + firmware/blade-plate-head/src/osape_arduino | 1 + firmware/blade-plate-head/src/osape_ucbus | 1 + firmware/blade-plate-head/src/syserror.h | 15 ----- firmware/blade-plate-head/src/ucbus_config.h | 27 ++++++++ 11 files changed, 163 insertions(+), 63 deletions(-) create mode 100644 firmware/blade-plate-head/src/osap_config.h rename firmware/blade-plate-head/src/{syserror.cpp => osap_debug.cpp} (52%) create mode 100644 firmware/blade-plate-head/src/osap_debug.h create mode 160000 firmware/blade-plate-head/src/osape create mode 160000 firmware/blade-plate-head/src/osape_arduino create mode 160000 firmware/blade-plate-head/src/osape_ucbus delete mode 100644 firmware/blade-plate-head/src/syserror.h create mode 100644 firmware/blade-plate-head/src/ucbus_config.h diff --git a/.gitmodules b/.gitmodules index e69de29..7161af4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "firmware/blade-plate-head/src/osape"] + path = firmware/blade-plate-head/src/osape + url = git@github.com:jakeread/osape.git +[submodule "firmware/blade-plate-head/src/osape_ucbus"] + path = firmware/blade-plate-head/src/osape_ucbus + url = git@github.com:jakeread/osape_ucbus.git +[submodule "firmware/blade-plate-head/src/osape_arduino"] + path = firmware/blade-plate-head/src/osape_arduino + url = git@github.com:jakeread/osape_arduino.git diff --git a/firmware/blade-plate-head/.vscode/extensions.json b/firmware/blade-plate-head/.vscode/extensions.json index e80666b..080e70d 100644 --- a/firmware/blade-plate-head/.vscode/extensions.json +++ b/firmware/blade-plate-head/.vscode/extensions.json @@ -3,5 +3,8 @@ // for the documentation about the extensions.json format "recommendations": [ "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" ] } diff --git a/firmware/blade-plate-head/src/main.cpp b/firmware/blade-plate-head/src/main.cpp index 73f11e6..8a2b3a2 100644 --- a/firmware/blade-plate-head/src/main.cpp +++ b/firmware/blade-plate-head/src/main.cpp @@ -3,10 +3,21 @@ #include "config.h" #include "drivers/servo.h" -#include "osape-d21/osape/osap/osap.h" -#include "osape-d21/vertices/vt_usbSerial.h" -#include "osape-d21/vertices/ucbus/ucBusDrop.h" -#include "osape-d21/vertices/ucbus/vt_ucBusDrop.h" +#include "osape/core/osap.h" +#include "osape/vertices/endpoint.h" +#include "osape_arduino/vp_arduinoSerial.h" +#include "osape_ucbus/vb_ucBusDrop.h" + +OSAP osap("blade-plate-head"); + +VPort_ArduinoSerial vpUSBSer(&osap, "arduinoUSBSerial", &Serial); + +VBus vb_ucBusDrop( + &osap, "ucBusDrop", + &vb_ucBusDrop_loop, + &vb_ucBusDrop_send, + &vb_ucBusDrop_cts +); // servo_pwm is on PA08, TCC0-0 @@ -17,22 +28,17 @@ EP_ONDATA_RESPONSES onServoPositionData(uint8_t* data, uint16_t len){ return EP_ONDATA_ACCEPT; } -endpoint_t* servoPositionEP = osapBuildEndpoint("servo current", onServoPositionData); +Endpoint servoPositionEP(&osap, "servo current", onServoPositionData); void setup() { CLKLIGHT_SETUP; BUSLIGHT_SETUP; INDLIGHT_SETUP; + // thing + vpUSBSer.begin(); + vb_ucBusDrop_setup(&vb_ucBusDrop, false, 5); // the servo driver servo_setup(); - // osap setup... - osapSetup("bladePlateHead"); - vt_usbSerial_setup(); - osapAddVertex(vt_usbSerial); - vt_ucBusDrop_setup(false, 5); - osapAddVertex(vt_ucBusDrop); - // demo endpoint (?) - osapAddEndpoint(servoPositionEP); } #define CLK_TICK 125 @@ -40,12 +46,14 @@ unsigned long last_tick = 0; void loop() { // the osap main bb - osapLoop(); + osap.loop(); // blink + /* if(millis() > last_tick + CLK_TICK){ BUSLIGHT_TOGGLE; last_tick = millis(); } + */ } void ucBusDrop_onPacketARx(uint8_t* inBufferA, volatile uint16_t len){} diff --git a/firmware/blade-plate-head/src/osap_config.h b/firmware/blade-plate-head/src/osap_config.h new file mode 100644 index 0000000..1898a3a --- /dev/null +++ b/firmware/blade-plate-head/src/osap_config.h @@ -0,0 +1,33 @@ +/* +osap_config.h + +config options for an osap-embedded build + +Jake Read at the Center for Bits and Atoms +(c) Massachusetts Institute of Technology 2022 + +This work may be reproduced, modified, distributed, performed, and +displayed for any purpose, but must acknowledge the osap project. +Copyright is retained and must be preserved. The work is provided as is; +no warranty is provided, and users accept all liability. +*/ + +#ifndef OSAP_CONFIG_H_ +#define OSAP_CONFIG_H_ + +// size of vertex stacks, lenght, then count, +#define VT_SLOTSIZE 256 +#define VT_STACKSIZE 3 // must be >= 2 for ringbuffer operation +#define VT_MAXCHILDREN 16 +#define VT_MAXITEMSPERTURN 8 + +// max # of endpoints that could be spawned here, +#define MAX_CONTEXT_ENDPOINTS 64 + +// count of routes each endpoint can have, +#define ENDPOINT_MAX_ROUTES 4 + +// if this is defined, please also provide an osap_debug.h +#define OSAP_DEBUG + +#endif \ No newline at end of file diff --git a/firmware/blade-plate-head/src/syserror.cpp b/firmware/blade-plate-head/src/osap_debug.cpp similarity index 52% rename from firmware/blade-plate-head/src/syserror.cpp rename to firmware/blade-plate-head/src/osap_debug.cpp index 861f812..dd93309 100644 --- a/firmware/blade-plate-head/src/syserror.cpp +++ b/firmware/blade-plate-head/src/osap_debug.cpp @@ -1,8 +1,21 @@ -#include "syserror.h" +/* +osap_debug.cpp + +optional escape hatches & indicators + +Jake Read at the Center for Bits and Atoms +(c) Massachusetts Institute of Technology 2020 + +This work may be reproduced, modified, distributed, performed, and +displayed for any purpose, but must acknowledge the osap project. +Copyright is retained and must be preserved. The work is provided as is; +no warranty is provided, and users accept all liability. +*/ + +#include "osap_debug.h" +#include "./osape/core/ts.h" +#include "./osape/utils/cobs.h" #include "indicators.h" -#include "config.h" -#include "osape-d21/osape/osap/ts.h" -#include "osape-d21/osape/utils/cobs.h" uint8_t errBuf[1028]; uint8_t errEncoded[1028]; @@ -41,39 +54,25 @@ void sysErrLightCheck(void){ } } -#ifdef UCBUS_IS_DROP - -void sysError(String msg){ - // noop -} - -#else - // config-your-own-ll-escape-hatch -void sysError(String msg){ +void debugPrint(String msg){ // whatever you want, - //ERRLIGHT_ON; uint32_t len = msg.length(); - errBuf[0] = 0; // serport looks for acks in each msg, this is not one - errBuf[1] = PK_PTR; - errBuf[2] = PK_LLESCAPE_KEY; // the ll-errmsg-key - errBuf[3] = len & 255; - errBuf[4] = (len >> 8) & 255; - errBuf[5] = (len >> 16) & 255; - errBuf[6] = (len >> 24) & 255; - msg.getBytes(&(errBuf[7]), len + 1); - size_t ecl = cobsEncode(errBuf, len + 7, errEncoded); - errEncoded[ecl] = 0; + errBuf[0] = len + 8; // len, key, cobs start + end, strlen (4) + errBuf[1] = 172; // serialLink debug key + errBuf[2] = len & 255; + errBuf[3] = (len >> 8) & 255; + errBuf[4] = (len >> 16) & 255; + errBuf[5] = (len >> 24) & 255; + msg.getBytes(&(errBuf[6]), len + 1); + size_t ecl = cobsEncode(&(errBuf[2]), len + 4, errEncoded); + memcpy(&(errBuf[2]), errEncoded, ecl); + errBuf[errBuf[0] - 1] = 0; // direct escape - //if(Serial.availableForWrite() > (int64_t)ecl){ - Serial.write(errEncoded, ecl + 1); - //Serial.flush(); - //} else { - // ERRLIGHT_ON; - //} + Serial.write(errBuf, errBuf[0]); } -#endif +//#endif void logPacket(uint8_t* pck, uint16_t len){ String errmsg; @@ -84,6 +83,5 @@ void logPacket(uint8_t* pck, uint16_t len){ errmsg += String(pck[i]); errmsg += ", "; } - sysError(errmsg); -} - + debugPrint(errmsg); +} \ No newline at end of file diff --git a/firmware/blade-plate-head/src/osap_debug.h b/firmware/blade-plate-head/src/osap_debug.h new file mode 100644 index 0000000..3c23680 --- /dev/null +++ b/firmware/blade-plate-head/src/osap_debug.h @@ -0,0 +1,34 @@ +/* +osap_debug.h + +optional escape hatches & indicators + +Jake Read at the Center for Bits and Atoms +(c) Massachusetts Institute of Technology 2020 + +This work may be reproduced, modified, distributed, performed, and +displayed for any purpose, but must acknowledge the osap project. +Copyright is retained and must be preserved. The work is provided as is; +no warranty is provided, and users accept all liability. +*/ + +#ifndef OSAP_DEBUG_H_ +#define OSAP_DEBUG_H_ + +#include <Arduino.h> + +void debugPrint(String msg); +void logPacket(uint8_t* pck, uint16_t len); +//void sysError(uint8_t* bytes, uint16_t len); + +void sysErrLightFlash(uint8_t level); +void sysErrLightCheck(void); + +#define ERROR(level, msg) sysErrLightFlash(level); debugPrint(msg) +#define DEBUG(msg) debugPrint(msg) + +#define ERRLIGHT_ON digitalWrite(5, HIGH) +#define ERRLIGHT_OFF digitalWrite(5, LOW) +#define ERRLIGHT_TOGGLE digitalWrite(5, !digitalRead(5)) + +#endif \ No newline at end of file diff --git a/firmware/blade-plate-head/src/osape b/firmware/blade-plate-head/src/osape new file mode 160000 index 0000000..d3aa968 --- /dev/null +++ b/firmware/blade-plate-head/src/osape @@ -0,0 +1 @@ +Subproject commit d3aa968e42184b4b4eccc76dda05d30f4b374288 diff --git a/firmware/blade-plate-head/src/osape_arduino b/firmware/blade-plate-head/src/osape_arduino new file mode 160000 index 0000000..95d5806 --- /dev/null +++ b/firmware/blade-plate-head/src/osape_arduino @@ -0,0 +1 @@ +Subproject commit 95d580692135b43a98ee2f087a1bc51e3cfe1fcb diff --git a/firmware/blade-plate-head/src/osape_ucbus b/firmware/blade-plate-head/src/osape_ucbus new file mode 160000 index 0000000..3abfa86 --- /dev/null +++ b/firmware/blade-plate-head/src/osape_ucbus @@ -0,0 +1 @@ +Subproject commit 3abfa86847d96151b915a7b60b77e2dcafa64230 diff --git a/firmware/blade-plate-head/src/syserror.h b/firmware/blade-plate-head/src/syserror.h deleted file mode 100644 index 489173a..0000000 --- a/firmware/blade-plate-head/src/syserror.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SYSERROR_H_ -#define SYSERROR_H_ - -#include <Arduino.h> - -void sysError(String msg); -void logPacket(uint8_t* pck, uint16_t len); -//void sysError(uint8_t* bytes, uint16_t len); - -void sysErrLightFlash(uint8_t level); -void sysErrLightCheck(void); - -#define ERROR(level, msg) sysErrLightFlash(level); sysError(msg) - -#endif diff --git a/firmware/blade-plate-head/src/ucbus_config.h b/firmware/blade-plate-head/src/ucbus_config.h new file mode 100644 index 0000000..2ce9da1 --- /dev/null +++ b/firmware/blade-plate-head/src/ucbus_config.h @@ -0,0 +1,27 @@ +/* +ucbus_confi.h + +config options for an ucbus instance + +Jake Read at the Center for Bits and Atoms +(c) Massachusetts Institute of Technology 2022 + +This work may be reproduced, modified, distributed, performed, and +displayed for any purpose, but must acknowledge the osap project. +Copyright is retained and must be preserved. The work is provided as is; +no warranty is provided, and users accept all liability. +*/ + +#ifndef UCBUS_CONFIG_H_ +#define UCBUS_CONFIG_H_ + +#define UCBUS_MAX_DROPS 32 +#define UCBUS_IS_DROP +//#define UCBUS_IS_HEAD + +#define UCBUS_BAUD 2 + +//#define UCBUS_IS_D51 +#define UCBUS_IS_D21 + +#endif \ No newline at end of file -- GitLab