Fix compilation

pull/25/head
D.R.racer 2021-06-14 10:25:28 +02:00 committed by DRracer
parent d6c9e58e66
commit 58fe013471
3 changed files with 59 additions and 41 deletions

View File

@ -7,5 +7,8 @@ uint8_t ReadByte(const uint8_t *addr) {
return 0; return 0;
} }
void UpdateByte(const uint8_t *addr, uint8_t value) {
}
} // namespace eeprom } // namespace eeprom
} // namespace hal } // namespace hal

View File

@ -11,6 +11,7 @@
#include "modules/buttons.h" #include "modules/buttons.h"
#include "modules/finda.h" #include "modules/finda.h"
#include "modules/fsensor.h" #include "modules/fsensor.h"
#include "modules/globals.h"
#include "modules/idler.h" #include "modules/idler.h"
#include "modules/leds.h" #include "modules/leds.h"
#include "modules/protocol.h" #include "modules/protocol.h"
@ -24,12 +25,25 @@
#include "logic/tool_change.h" #include "logic/tool_change.h"
#include "logic/unload_filament.h" #include "logic/unload_filament.h"
static modules::protocol::Protocol protocol; namespace mb = modules::buttons;
namespace mp = modules::protocol;
namespace mf = modules::finda;
namespace mfs = modules::fsensor;
namespace mi = modules::idler;
namespace ml = modules::leds;
namespace ms = modules::selector;
namespace mg = modules::globals;
namespace hu = hal::usart;
/// Global instance of the protocol codec
static mp::Protocol protocol;
/// A command that resulted in the currently on-going operation
logic::CommandBase *currentCommand = &logic::noCommand; logic::CommandBase *currentCommand = &logic::noCommand;
/// remember the request message that started the currently running command /// remember the request message that started the currently running command
modules::protocol::RequestMsg currentCommandRq(modules::protocol::RequestMsgCodes::unknown, 0); mp::RequestMsg currentCommandRq(mp::RequestMsgCodes::unknown, 0);
// examples and test code shall be located here // examples and test code shall be located here
void TmpPlayground() { void TmpPlayground() {
@ -61,17 +75,17 @@ void TmpPlayground() {
// break; // break;
sei(); sei();
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
hal::usart::usart1.puts("1234567890\n"); hu::usart1.puts("1234567890\n");
} }
/// One-time setup of HW and SW components /// One-time setup of HW and SW components
@ -82,22 +96,24 @@ void setup() {
cpu::Init(); cpu::Init();
mg::globals.Init();
// watchdog init // watchdog init
shr16::shr16.Init(); shr16::shr16.Init();
modules::leds::leds.SetMode(4, modules::leds::Color::green, modules::leds::Mode::blink0); ml::leds.SetMode(4, ml::Color::green, ml::Mode::blink0);
modules::leds::leds.Step(0); ml::leds.Step(0);
// @@TODO if the shift register doesn't work we really can't signalize anything, only internal variables will be accessible if the UART works // @@TODO if the shift register doesn't work we really can't signalize anything, only internal variables will be accessible if the UART works
hal::usart::USART::USART_InitTypeDef usart_conf = { hu::USART::USART_InitTypeDef usart_conf = {
.rx_pin = gpio::GPIO_pin(GPIOD, 2), .rx_pin = gpio::GPIO_pin(GPIOD, 2),
.tx_pin = gpio::GPIO_pin(GPIOD, 3), .tx_pin = gpio::GPIO_pin(GPIOD, 3),
.baudrate = 115200, .baudrate = 115200,
}; };
hal::usart::usart1.Init(&usart_conf); hu::usart1.Init(&usart_conf);
modules::leds::leds.SetMode(3, modules::leds::Color::green, modules::leds::Mode::on); ml::leds.SetMode(3, ml::Color::green, ml::Mode::on);
modules::leds::leds.Step(0); ml::leds.Step(0);
// @@TODO if both shift register and the UART are dead, we are sitting ducks :( // @@TODO if both shift register and the UART are dead, we are sitting ducks :(
@ -111,23 +127,22 @@ void setup() {
.cpol = 1, .cpol = 1,
}; };
spi::Init(SPI0, &spi_conf); spi::Init(SPI0, &spi_conf);
modules::leds::leds.SetMode(2, modules::leds::Color::green, modules::leds::Mode::on); ml::leds.SetMode(2, ml::Color::green, ml::Mode::on);
modules::leds::leds.Step(0); ml::leds.Step(0);
// tmc::Init() // tmc::Init()
modules::leds::leds.SetMode(1, modules::leds::Color::green, modules::leds::Mode::on); ml::leds.SetMode(1, ml::Color::green, ml::Mode::on);
modules::leds::leds.Step(0); ml::leds.Step(0);
// adc::Init(); // adc::Init();
modules::leds::leds.SetMode(0, modules::leds::Color::green, modules::leds::Mode::on); ml::leds.SetMode(0, ml::Color::green, ml::Mode::on);
modules::leds::leds.Step(0); ml::leds.Step(0);
} }
void SendMessage(const modules::protocol::ResponseMsg &msg) { void SendMessage(const mp::ResponseMsg &msg) {
} }
void PlanCommand(const modules::protocol::RequestMsg &rq) { void PlanCommand(const mp::RequestMsg &rq) {
namespace mp = modules::protocol;
if (currentCommand->Error() == ErrorCode::OK) { if (currentCommand->Error() == ErrorCode::OK) {
// we are allowed to start a new command as the previous one is in the OK finished state // we are allowed to start a new command as the previous one is in the OK finished state
switch (rq.code) { switch (rq.code) {
@ -155,7 +170,6 @@ void PlanCommand(const modules::protocol::RequestMsg &rq) {
} }
void ReportRunningCommand() { void ReportRunningCommand() {
namespace mp = modules::protocol;
mp::ResponseMsgParamCodes commandStatus; mp::ResponseMsgParamCodes commandStatus;
uint8_t value = 0; uint8_t value = 0;
switch (currentCommand->Error()) { switch (currentCommand->Error()) {
@ -174,15 +188,14 @@ void ReportRunningCommand() {
SendMessage(mp::ResponseMsg(currentCommandRq, commandStatus, value)); SendMessage(mp::ResponseMsg(currentCommandRq, commandStatus, value));
} }
void ProcessRequestMsg(const modules::protocol::RequestMsg &rq) { void ProcessRequestMsg(const mp::RequestMsg &rq) {
namespace mp = modules::protocol;
switch (rq.code) { switch (rq.code) {
case mp::RequestMsgCodes::Button: case mp::RequestMsgCodes::Button:
// behave just like if the user pressed a button // behave just like if the user pressed a button
break; break;
case mp::RequestMsgCodes::Finda: case mp::RequestMsgCodes::Finda:
// immediately report FINDA status // immediately report FINDA status
SendMessage(mp::ResponseMsg(rq, mp::ResponseMsgParamCodes::Accepted, modules::finda::finda.Pressed())); SendMessage(mp::ResponseMsg(rq, mp::ResponseMsgParamCodes::Accepted, mf::finda.Pressed()));
break; break;
case mp::RequestMsgCodes::Mode: case mp::RequestMsgCodes::Mode:
// immediately switch to normal/stealth as requested // immediately switch to normal/stealth as requested
@ -217,9 +230,9 @@ void ProcessRequestMsg(const modules::protocol::RequestMsg &rq) {
/// @returns true if a request was successfully finished /// @returns true if a request was successfully finished
bool CheckMsgs() { bool CheckMsgs() {
using mpd = modules::protocol::DecodeStatus; using mpd = mp::DecodeStatus;
while (!hal::usart::usart1.ReadEmpty()) { while (!hu::usart1.ReadEmpty()) {
switch (protocol.DecodeRequest(hal::usart::usart1.Read())) { switch (protocol.DecodeRequest(hu::usart1.Read())) {
case mpd::MessageCompleted: case mpd::MessageCompleted:
// process the input message // process the input message
return true; return true;
@ -253,12 +266,12 @@ void loop() {
if (CheckMsgs()) { if (CheckMsgs()) {
ProcessRequestMsg(protocol.GetRequestMsg()); ProcessRequestMsg(protocol.GetRequestMsg());
} }
modules::buttons::buttons.Step(hal::adc::ReadADC(0)); mb::buttons.Step(hal::adc::ReadADC(0));
modules::leds::leds.Step(0); ml::leds.Step(0);
modules::finda::finda.Step(0); mf::finda.Step(0);
modules::fsensor::fsensor.Step(0); mfs::fsensor.Step(0);
modules::idler::idler.Step(); mi::idler.Step();
modules::selector::selector.Step(); ms::selector.Step();
currentCommand->Step(); currentCommand->Step();
// add a watchdog reset // add a watchdog reset
} }

View File

@ -4,6 +4,8 @@
namespace modules { namespace modules {
namespace globals { namespace globals {
Globals globals;
void Globals::Init() { void Globals::Init() {
modules::permanent_storage::FilamentLoaded::get(activeSlot); //@@TODO check for errors modules::permanent_storage::FilamentLoaded::get(activeSlot); //@@TODO check for errors
// @@TODO where to obtain information whether a slot is loaded with a filament? // @@TODO where to obtain information whether a slot is loaded with a filament?