Skip to content

Commit 8cb8d37

Browse files
committed
Cleanup + Documentation
1 parent 334602f commit 8cb8d37

17 files changed

Lines changed: 100 additions & 295 deletions

Firmware/FFBoard/Inc/Axis.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
#include "LocalAnalog.h"
1818
#include "AnalogSource.h"
1919

20-
#include "cppmain.h"
2120
#include "HidFFB.h"
2221
#include "ffb_defs.h"
2322
#include "TimerHandler.h"
2423
#include "ClassChooser.h"
2524
#include "ExtiHandler.h"
2625
#include "EffectsCalculator.h"
2726
#include "FastAvg.h"
28-
//#include "NormalizedAxis.h"
2927

3028

3129
struct Control_t {
@@ -87,7 +85,6 @@ class Axis : public PersistentStorage, public CommandHandler
8785
const ClassIdentifier getInfo();
8886
const ClassType getClassType() override {return ClassType::Axis;};
8987

90-
// TODO add new commands
9188
virtual std::string getHelpstring() { return "FFB axis" ;}
9289
void setupTMC4671();
9390

Firmware/FFBoard/Inc/ChoosableClass.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@
1111
#include "string"
1212

1313
struct ClassIdentifier {
14-
//const std::string name; // Display name of this class
15-
const char* name = nullptr;
16-
// const std::string clsname; // Classname for addressing with string based commands (main or pwmdriver...)
17-
uint16_t id; // TODO replace with classchooser id. Unique id for this class. If multiple instances set unique char at runtime
18-
// uint16_t clstypeId; // The id equivalent to clsname. Classes with the same clsname must have the same clstypeId
19-
// uint8_t unique;
14+
const char* name = nullptr; // Display name of this class
15+
uint16_t id; // The id equivalent to clsname. Classes with the same clsname must have the same id in this field. Classchooser can use this or a separate id for selection
2016
bool hidden = false; // Hide from classchooser listings?
2117
};
2218

Firmware/FFBoard/Inc/HidCommandInterface.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ enum class HidCmdType : uint8_t {write = 0, request = 1, info = 2, writeAddr = 3
2020
// TODO: can only be 25B long. tinyusb will hang otherwise!
2121
typedef struct
2222
{
23-
uint8_t reportId = HID_ID_HIDCMD;
24-
HidCmdType type = HidCmdType::err; // 0x01. Type of report. 0 = write, 1 = request, 2 = error
25-
uint16_t clsid = 0;
26-
uint8_t instance = 0; // Class ID. 16 bits class id, 8 bits used for unique instance number. 255 for broadcast
27-
uint32_t cmd = 0; // 0x02 Use this as an identifier for the command. upper 16 bits for class type
28-
uint64_t data = 0; // 0x03 Use this to transfer data or the primary value
29-
uint64_t addr = 0; // 0x04 Use this to transfer an optional address or second value (CAN for example)
23+
uint8_t reportId = HID_ID_HIDCMD; // Report ID = 0xA1
24+
HidCmdType type = HidCmdType::err; // 0x01. Type of report. 0 = write, 1 = request
25+
uint16_t clsid = 0; // 0x02 Class ID identifies the target class type
26+
uint8_t instance = 0; // 0x03 Class instance number to target a specific instance (often 0). 0xff for broadcast to all instances
27+
uint32_t cmd = 0; // 0x04 Use this as an identifier for the command. upper 16 bits for class type
28+
uint64_t data = 0; // 0x05 Use this to transfer data or the primary value
29+
uint64_t addr = 0; // 0x06 Use this to transfer an optional address or second value (CAN for example)
3030

3131
} __attribute__((packed)) HID_CMD_Data_t;
3232

Firmware/FFBoard/Inc/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SPIPort: public SpiHandler {
7878
void endTransfer(SPIConfig* config);
7979

8080
SPI_HandleTypeDef &hspi;
81-
SPIDevice* current_device;
81+
SPIDevice* current_device = nullptr;
8282
std::vector<OutputPin> csPins; // cs pins and bool true if pin is reserved
8383
std::vector<OutputPin> freePins;
8484

Firmware/FFBoard/Src/Axis.cpp

Lines changed: 15 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717

18-
// TODO class type for parser? (Simhub for example)
1918
//////////////////////////////////////////////
2019

2120
ClassIdentifier Axis::info = {
@@ -57,25 +56,24 @@ Axis::~Axis()
5756
}
5857

5958
const ClassIdentifier Axis::getInfo() {
60-
// ClassIdentifier newinfo = Axis::info;
61-
// newinfo.unique = axis+'X';
59+
6260
return info;
6361
}
6462

6563
void Axis::registerCommands(){
66-
registerCommand("power", Axis_commands::power, "Overall force strength");
67-
registerCommand("degrees", Axis_commands::degrees, "Rotation range in deg.");
68-
registerCommand("esgain", Axis_commands::esgain, "Endstop stiffness");
69-
registerCommand("zeroenc", Axis_commands::zeroenc, "Zero axis");
70-
registerCommand("invert", Axis_commands::invert, "Invert axis");
71-
registerCommand("idlespring", Axis_commands::idlespring, "Idle spring strength");
72-
registerCommand("axisdamper", Axis_commands::axisdamper, "Independent damper effect");
73-
registerCommand("enctype", Axis_commands::enctype, "Encoder type get/set/list");
74-
registerCommand("drvtype", Axis_commands::drvtype, "Motor driver type get/set/list");
75-
registerCommand("pos", Axis_commands::pos, "Axis position");
76-
registerCommand("maxspeed", Axis_commands::maxspeed, "Speed limit in deg/s");
77-
registerCommand("maxtorquerate", Axis_commands::maxtorquerate, "Torque rate limit in counts/ms");
78-
registerCommand("fxratio", Axis_commands::fxratio, "Effect ratio. Reduces effects excluding endstop. 255=100%");
64+
registerCommand("power", Axis_commands::power, "Overall force strength",CMDFLAG_GET | CMDFLAG_SET);
65+
registerCommand("degrees", Axis_commands::degrees, "Rotation range in deg",CMDFLAG_GET | CMDFLAG_SET);
66+
registerCommand("esgain", Axis_commands::esgain, "Endstop stiffness",CMDFLAG_GET | CMDFLAG_SET);
67+
registerCommand("zeroenc", Axis_commands::zeroenc, "Zero axis",CMDFLAG_GET);
68+
registerCommand("invert", Axis_commands::invert, "Invert axis",CMDFLAG_GET | CMDFLAG_SET);
69+
registerCommand("idlespring", Axis_commands::idlespring, "Idle spring strength",CMDFLAG_GET | CMDFLAG_SET);
70+
registerCommand("axisdamper", Axis_commands::axisdamper, "Independent damper effect",CMDFLAG_GET | CMDFLAG_SET);
71+
registerCommand("enctype", Axis_commands::enctype, "Encoder type get/set/list",CMDFLAG_GET | CMDFLAG_SET | CMDFLAG_INFOSTRING);
72+
registerCommand("drvtype", Axis_commands::drvtype, "Motor driver type get/set/list",CMDFLAG_GET | CMDFLAG_SET | CMDFLAG_INFOSTRING);
73+
registerCommand("pos", Axis_commands::pos, "Axis position",CMDFLAG_GET);
74+
registerCommand("maxspeed", Axis_commands::maxspeed, "Speed limit in deg/s",CMDFLAG_GET | CMDFLAG_SET);
75+
registerCommand("maxtorquerate", Axis_commands::maxtorquerate, "Torque rate limit in counts/ms",CMDFLAG_GET | CMDFLAG_SET);
76+
registerCommand("fxratio", Axis_commands::fxratio, "Effect ratio. Reduces effects excluding endstop. 255=100%",CMDFLAG_GET | CMDFLAG_SET);
7977
}
8078

8179
/*
@@ -696,211 +694,7 @@ CommandStatus Axis::command(const ParsedCommand& cmd,std::vector<CommandReply>&
696694
}
697695
return CommandStatus::OK;
698696
}
699-
//
700-
//ParseStatus Axis::command(ParsedCommand_old *cmd, std::string *reply)
701-
//{
702-
// if ((cmd->prefix & 0xDF) != axis){
703-
// return ParseStatus::NOT_FOUND;
704-
// }
705-
//
706-
// ParseStatus flag = ParseStatus::OK;
707-
//
708-
// if (cmd->cmd == "drvtype")
709-
// {
710-
// if (cmd->type == CMDtype::get)
711-
// {
712-
// *reply += std::to_string(this->getDrvType());
713-
// }
714-
// else if (cmd->type == CMDtype::set && this->drv_chooser.isValidClassId(cmd->val))
715-
// {
716-
// setDrvType((cmd->val));
717-
// }
718-
// else
719-
// {
720-
// *reply += drv_chooser.printAvailableClasses(this->conf.drvtype);
721-
// }
722-
// }
723-
// else if (cmd->cmd == "zeroenc")
724-
// {
725-
// if (cmd->type == CMDtype::get)
726-
// {
727-
// this->setPos(0);
728-
// *reply += "Zeroed";
729-
// }
730-
// }
731-
// else if (cmd->cmd == "enctype")
732-
// {
733-
// if (cmd->type == CMDtype::get)
734-
// {
735-
// *reply += std::to_string(this->getEncType());
736-
// }
737-
// else if (cmd->type == CMDtype::set)
738-
// {
739-
// setEncType(cmd->val);
740-
// }
741-
// else
742-
// {
743-
// if(this->drv->hasIntegratedEncoder()){
744-
// *reply += "255:0:"+std::string(this->drv->getInfo().name); // TODO dynamic?
745-
// }else{
746-
// *reply += enc_chooser.printAvailableClasses(this->conf.enctype);
747-
// }
748-
// }
749-
// }
750-
// else if (cmd->cmd == "pos")
751-
// {
752-
// if (cmd->type == CMDtype::get)
753-
// {
754-
// *reply += std::to_string(this->drv->getEncoder()->getPos());
755-
// }
756-
// else if (cmd->type == CMDtype::set && this->drv->getEncoder() != nullptr)
757-
// {
758-
// this->drv->getEncoder()->setPos(cmd->val);
759-
// }
760-
// else
761-
// {
762-
// flag = ParseStatus::ERR;
763-
// *reply += "Err. Setup encoder first";
764-
// }
765-
// }
766-
// else if (cmd->cmd == "maxspeed")
767-
// {
768-
// if (cmd->type == CMDtype::get)
769-
// {
770-
// *reply += std::to_string(maxSpeedDegS);
771-
// }
772-
// else if (cmd->type == CMDtype::set)
773-
// {
774-
// maxSpeedDegS = cmd->val;
775-
// //speedScalerNormalized = getNormalizedSpeedScaler(maxSpeedDegS, degreesOfRotation);
776-
//
777-
// }
778-
// }else if (cmd->cmd == "maxtorquerate")
779-
// {
780-
// if (cmd->type == CMDtype::get)
781-
// {
782-
// *reply += std::to_string(maxTorqueRateMS);
783-
// }
784-
// else if (cmd->type == CMDtype::set)
785-
// {
786-
// maxTorqueRateMS = cmd->val;
787-
// //speedScalerNormalized = getNormalizedSpeedScaler(maxSpeedDegS, degreesOfRotation);
788-
//
789-
// }
790-
// }
791-
//// else if (cmd->cmd == "maxaccel")
792-
//// {
793-
//// if (cmd->type == CMDtype::get)
794-
//// {
795-
//// *reply += std::to_string((uint16_t)(maxAccelDegSS*accelFactor));
796-
//// }
797-
//// else if (cmd->type == CMDtype::set)
798-
//// {
799-
//// maxAccelDegSS = cmd->val / accelFactor;
800-
//// //accelScalerNormalized = getNormalizedAccelScaler(maxAccelDegSS, degreesOfRotation);
801-
//// }
802-
//// }
803-
// else if (cmd->cmd == "fxratio")
804-
// {
805-
// if (cmd->type == CMDtype::get)
806-
// {
807-
// *reply += std::to_string(fx_ratio_i);
808-
// }
809-
// else if (cmd->type == CMDtype::set)
810-
// {
811-
// setFxRatio(cmd->val);
812-
// }
813-
// }
814-
// else if (cmd->cmd == "power")
815-
// {
816-
// if (cmd->type == CMDtype::get)
817-
// {
818-
// *reply += std::to_string(power);
819-
// }
820-
// else if (cmd->type == CMDtype::set)
821-
// {
822-
// setPower(cmd->val);
823-
// }
824-
// }
825-
// else if (cmd->cmd == "degrees")
826-
// {
827-
// if (cmd->type == CMDtype::get)
828-
// {
829-
// *reply += std::to_string(degreesOfRotation);
830-
// }
831-
// else if (cmd->type == CMDtype::set)
832-
// {
833-
// setDegrees(cmd->val);
834-
// }
835-
// }
836-
// else if (cmd->cmd == "esgain")
837-
// {
838-
// if (cmd->type == CMDtype::get)
839-
// {
840-
// *reply += std::to_string(endstop_gain);
841-
// }
842-
// else if (cmd->type == CMDtype::set)
843-
// {
844-
// endstop_gain = cmd->val;
845-
// }
846-
// }
847-
// else if (cmd->cmd == "invert")
848-
// {
849-
// if (cmd->type == CMDtype::get)
850-
// {
851-
// *reply += invertAxis ? "1" : "0";
852-
// }
853-
// else if (cmd->type == CMDtype::set)
854-
// {
855-
// invertAxis = cmd->val >= 1 ? true : false;
856-
// }
857-
// }
858-
// else if (cmd->cmd == "idlespring")
859-
// {
860-
// if (cmd->type == CMDtype::get)
861-
// {
862-
// *reply += std::to_string(idlespringstrength);
863-
// }
864-
// else if (cmd->type == CMDtype::set)
865-
// {
866-
// setIdleSpringStrength(cmd->val);
867-
// }
868-
// }
869-
// else if (cmd->cmd == "axisdamper")
870-
// {
871-
// if (cmd->type == CMDtype::get)
872-
// {
873-
// *reply += std::to_string(damperIntensity);
874-
// }
875-
// else if (cmd->type == CMDtype::set)
876-
// {
877-
// setDamperStrength(cmd->val);
878-
// }
879-
// }
880-
//// else if (cmd->cmd == "calibmetrics")
881-
//// {
882-
//// if (cmd->type == CMDtype::get)
883-
//// {
884-
//// *reply += std::to_string(getSpeedRPMFromEncValue(calibMaxSpeedNormalized, degreesOfRotation)) + ':'
885-
//// + std::to_string(getAccelFromEncValue(calibMaxAccelNormalized, degreesOfRotation));
886-
//// }
887-
//// else if (cmd->type == CMDtype::set)
888-
//// {
889-
//// if (cmd->val == 1) {
890-
//// calibrationInProgress = true;
891-
//// calibMaxAccelNormalized = 0.0;
892-
//// calibMaxSpeedNormalized = 0;
893-
//// } else {
894-
//// calibrationInProgress = false;
895-
//// }
896-
//// }
897-
//// }
898-
// else{
899-
// flag = ParseStatus::NOT_FOUND;
900-
// }
901-
//
902-
// return flag;
903-
//};
697+
904698

905699

906700
/*

Firmware/FFBoard/Src/CAN.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,17 @@ void CANPort::giveSemaphore(){
149149
portYIELD_FROM_ISR(taskWoken);
150150
}
151151

152+
/**
153+
* Transmits a CAN frame on this port
154+
* Wraps the internal transmit function
155+
*/
152156
bool CANPort::sendMessage(CAN_tx_msg msg){
153157
return this->sendMessage(&msg.header,msg.data,&this->txMailbox);
154158
}
155159

160+
/**
161+
* Transmits a CAN frame with separate data and header settings
162+
*/
156163
bool CANPort::sendMessage(CAN_TxHeaderTypeDef *pHeader, uint8_t aData[],uint32_t *pTxMailbox){
157164
if(pTxMailbox == nullptr){
158165
pTxMailbox = &this->txMailbox;

Firmware/FFBoard/Src/CDCcomm.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ std::string CDCcomm::tString;
1717
cpp_freertos::BinarySemaphore CDCcomm::cdcSems[CFG_TUD_CDC] = {cpp_freertos::BinarySemaphore(true)};
1818

1919
CDCcomm::CDCcomm() {
20-
// TODO Auto-generated constructor stub
2120

2221
}
2322

2423
CDCcomm::~CDCcomm() {
25-
// TODO Auto-generated destructor stub
24+
2625
}
2726

2827

@@ -41,6 +40,7 @@ void CDCcomm::cdcFinished(uint8_t itf){
4140

4241
/**
4342
* Sends a string via CDC
43+
* If not everything can be sent it will be buffered for later in a new string
4444
*/
4545
uint16_t CDCcomm::cdcSend(std::string* reply,uint8_t itf){
4646
if(!tud_ready() || reply->empty()){
@@ -62,8 +62,5 @@ uint16_t CDCcomm::cdcSend(std::string* reply,uint8_t itf){
6262
remainingStrs[itf].clear();
6363
}
6464

65-
66-
67-
6865
return cdc_sent;
6966
}

0 commit comments

Comments
 (0)