Add empty EEPROM HAL implementation
parent
dfb57bcae5
commit
9e4bd97968
|
|
@ -188,6 +188,7 @@ target_sources(
|
||||||
src/hal/avr/cpu.cpp
|
src/hal/avr/cpu.cpp
|
||||||
src/hal/avr/usart.cpp
|
src/hal/avr/usart.cpp
|
||||||
src/hal/avr/shr16.cpp
|
src/hal/avr/shr16.cpp
|
||||||
|
src/hal/avr/eeprom.cpp
|
||||||
src/hal/adc.cpp
|
src/hal/adc.cpp
|
||||||
src/modules/protocol.cpp
|
src/modules/protocol.cpp
|
||||||
src/modules/buttons.cpp
|
src/modules/buttons.cpp
|
||||||
|
|
@ -197,6 +198,7 @@ target_sources(
|
||||||
src/modules/idler.cpp
|
src/modules/idler.cpp
|
||||||
src/modules/leds.cpp
|
src/modules/leds.cpp
|
||||||
src/modules/motion.cpp
|
src/modules/motion.cpp
|
||||||
|
src/modules/permanent_storage.cpp
|
||||||
src/modules/selector.cpp
|
src/modules/selector.cpp
|
||||||
src/logic/command_base.cpp
|
src/logic/command_base.cpp
|
||||||
src/logic/cut_filament.cpp
|
src/logic/cut_filament.cpp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "../eeprom.h"
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace eeprom {
|
||||||
|
|
||||||
|
uint8_t ReadByte(const uint8_t *addr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace eeprom
|
||||||
|
} // namespace hal
|
||||||
|
|
@ -2,19 +2,19 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace hal {
|
namespace hal {
|
||||||
namespace EEPROM {
|
namespace eeprom {
|
||||||
|
|
||||||
/// EEPROM interface
|
/// EEPROM interface
|
||||||
void WriteByte(const uint8_t *addr, uint8_t value);
|
extern void WriteByte(const uint8_t *addr, uint8_t value);
|
||||||
void UpdateByte(const uint8_t *addr, uint8_t value);
|
extern void UpdateByte(const uint8_t *addr, uint8_t value);
|
||||||
uint8_t ReadByte(const uint8_t *addr);
|
extern uint8_t ReadByte(const uint8_t *addr);
|
||||||
|
|
||||||
void WriteWord(const uint8_t *addr, uint16_t value);
|
extern void WriteWord(const uint8_t *addr, uint16_t value);
|
||||||
void UpdateWord(const uint8_t *addr, uint16_t value);
|
extern void UpdateWord(const uint8_t *addr, uint16_t value);
|
||||||
uint16_t ReadWord(const uint8_t *addr);
|
extern uint16_t ReadWord(const uint8_t *addr);
|
||||||
|
|
||||||
/// @returns physical end address of EEPROM memory end
|
/// @returns physical end address of EEPROM memory end
|
||||||
constexpr const uint16_t End();
|
extern constexpr const uint16_t End();
|
||||||
|
|
||||||
} // namespace EEPROM
|
} // namespace EEPROM
|
||||||
} // namespace hal
|
} // namespace hal
|
||||||
|
|
|
||||||
|
|
@ -44,17 +44,17 @@ namespace permanent_storage {
|
||||||
static const uint16_t eepromBowdenLenMaximum = 16000u; ///< Maximum bowden length (~792 mm)
|
static const uint16_t eepromBowdenLenMaximum = 16000u; ///< Maximum bowden length (~792 mm)
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
if (hal::EEPROM::ReadByte((const uint8_t *)hal::EEPROM::End()) != layoutVersion) {
|
if (hal::eeprom::ReadByte((const uint8_t *)hal::eeprom::End()) != layoutVersion) {
|
||||||
EraseAll();
|
EraseAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Erase the whole EEPROM
|
/// @brief Erase the whole EEPROM
|
||||||
void EraseAll() {
|
void EraseAll() {
|
||||||
for (uint16_t i = 0; i < hal::EEPROM::End(); i++) {
|
for (uint16_t i = 0; i < hal::eeprom::End(); i++) {
|
||||||
hal::EEPROM::UpdateByte((uint8_t *)i, static_cast<uint8_t>(eepromEmpty));
|
hal::eeprom::UpdateByte((uint8_t *)i, static_cast<uint8_t>(eepromEmpty));
|
||||||
}
|
}
|
||||||
hal::EEPROM::UpdateByte((const uint8_t *)hal::EEPROM::End(), layoutVersion);
|
hal::eeprom::UpdateByte((const uint8_t *)hal::eeprom::End(), layoutVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Is filament number valid?
|
/// @brief Is filament number valid?
|
||||||
|
|
@ -83,10 +83,10 @@ namespace permanent_storage {
|
||||||
uint16_t BowdenLength::get() {
|
uint16_t BowdenLength::get() {
|
||||||
uint8_t filament = 0 /*active_extruder*/; //@@TODO
|
uint8_t filament = 0 /*active_extruder*/; //@@TODO
|
||||||
if (validFilament(filament)) {
|
if (validFilament(filament)) {
|
||||||
uint16_t bowdenLength = hal::EEPROM::ReadByte((const uint8_t *)&(eepromBase->eepromBowdenLen[filament]));
|
uint16_t bowdenLength = hal::eeprom::ReadByte((const uint8_t *)&(eepromBase->eepromBowdenLen[filament]));
|
||||||
|
|
||||||
if (eepromEmpty == bowdenLength) {
|
if (eepromEmpty == bowdenLength) {
|
||||||
const uint8_t LengthCorrectionLegacy = hal::EEPROM::ReadByte(&(eepromBase->eepromLengthCorrection));
|
const uint8_t LengthCorrectionLegacy = hal::eeprom::ReadByte(&(eepromBase->eepromLengthCorrection));
|
||||||
if (LengthCorrectionLegacy <= 200) {
|
if (LengthCorrectionLegacy <= 200) {
|
||||||
bowdenLength = eepromLengthCorrectionBase + LengthCorrectionLegacy * 10;
|
bowdenLength = eepromLengthCorrectionBase + LengthCorrectionLegacy * 10;
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ namespace permanent_storage {
|
||||||
/// @brief Store bowden length permanently.
|
/// @brief Store bowden length permanently.
|
||||||
BowdenLength::~BowdenLength() {
|
BowdenLength::~BowdenLength() {
|
||||||
if (validFilament(filament))
|
if (validFilament(filament))
|
||||||
hal::EEPROM::UpdateWord((const uint8_t *)&(eepromBase->eepromBowdenLen[filament]), length);
|
hal::eeprom::UpdateWord((const uint8_t *)&(eepromBase->eepromBowdenLen[filament]), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Get filament storage status
|
/// @brief Get filament storage status
|
||||||
|
|
@ -148,12 +148,12 @@ namespace permanent_storage {
|
||||||
/// @retval 0xff Uninitialized EEPROM or no 2 values agrees
|
/// @retval 0xff Uninitialized EEPROM or no 2 values agrees
|
||||||
|
|
||||||
uint8_t FilamentLoaded::getStatus() {
|
uint8_t FilamentLoaded::getStatus() {
|
||||||
if (hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[0])) == hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[1])))
|
if (hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[0])) == hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[1])))
|
||||||
return hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[0]));
|
return hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[0]));
|
||||||
if (hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[0])) == hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[2])))
|
if (hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[0])) == hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[2])))
|
||||||
return hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[0]));
|
return hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[0]));
|
||||||
if (hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[1])) == hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[2])))
|
if (hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[1])) == hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[2])))
|
||||||
return hal::EEPROM::ReadByte(&(eepromBase->eepromFilamentStatus[1]));
|
return hal::eeprom::ReadByte(&(eepromBase->eepromFilamentStatus[1]));
|
||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +163,7 @@ namespace permanent_storage {
|
||||||
/// @retval false Failed
|
/// @retval false Failed
|
||||||
bool FilamentLoaded::setStatus(uint8_t status) {
|
bool FilamentLoaded::setStatus(uint8_t status) {
|
||||||
for (uint8_t i = 0; i < ARR_SIZE(eeprom_t::eepromFilamentStatus); ++i) {
|
for (uint8_t i = 0; i < ARR_SIZE(eeprom_t::eepromFilamentStatus); ++i) {
|
||||||
hal::EEPROM::UpdateByte(&(eepromBase->eepromFilamentStatus[i]), status);
|
hal::eeprom::UpdateByte(&(eepromBase->eepromFilamentStatus[i]), status);
|
||||||
}
|
}
|
||||||
if (getStatus() == status)
|
if (getStatus() == status)
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -187,7 +187,7 @@ namespace permanent_storage {
|
||||||
case KeyFront2:
|
case KeyFront2:
|
||||||
index = ARR_SIZE(eeprom_t::eepromFilament) - 1; // It is the last one, if no dirty index found
|
index = ARR_SIZE(eeprom_t::eepromFilament) - 1; // It is the last one, if no dirty index found
|
||||||
for (uint16_t i = 0; i < ARR_SIZE(eeprom_t::eepromFilament); ++i) {
|
for (uint16_t i = 0; i < ARR_SIZE(eeprom_t::eepromFilament); ++i) {
|
||||||
if (status != (hal::EEPROM::ReadByte(&(eepromBase->eepromFilament[i])) >> 4)) {
|
if (status != (hal::eeprom::ReadByte(&(eepromBase->eepromFilament[i])) >> 4)) {
|
||||||
index = i - 1;
|
index = i - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -197,7 +197,7 @@ namespace permanent_storage {
|
||||||
case KeyReverse2:
|
case KeyReverse2:
|
||||||
index = 0; // It is the last one, if no dirty index found
|
index = 0; // It is the last one, if no dirty index found
|
||||||
for (int16_t i = (ARR_SIZE(eeprom_t::eepromFilament) - 1); i >= 0; --i) {
|
for (int16_t i = (ARR_SIZE(eeprom_t::eepromFilament) - 1); i >= 0; --i) {
|
||||||
if (status != (hal::EEPROM::ReadByte(&(eepromBase->eepromFilament[i])) >> 4)) {
|
if (status != (hal::eeprom::ReadByte(&(eepromBase->eepromFilament[i])) >> 4)) {
|
||||||
index = i + 1;
|
index = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -217,7 +217,7 @@ namespace permanent_storage {
|
||||||
int16_t index = getIndex();
|
int16_t index = getIndex();
|
||||||
if ((index < 0) || (static_cast<uint16_t>(index) >= ARR_SIZE(eeprom_t::eepromFilament)))
|
if ((index < 0) || (static_cast<uint16_t>(index) >= ARR_SIZE(eeprom_t::eepromFilament)))
|
||||||
return false;
|
return false;
|
||||||
const uint8_t rawFilament = hal::EEPROM::ReadByte(&(eepromBase->eepromFilament[index]));
|
const uint8_t rawFilament = hal::eeprom::ReadByte(&(eepromBase->eepromFilament[index]));
|
||||||
filament = 0x0f & rawFilament;
|
filament = 0x0f & rawFilament;
|
||||||
if (filament > 4)
|
if (filament > 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -250,8 +250,8 @@ namespace permanent_storage {
|
||||||
if (!setStatus(status))
|
if (!setStatus(status))
|
||||||
return false;
|
return false;
|
||||||
uint8_t filamentRaw = ((status << 4) & 0xf0) + (filament & 0x0f);
|
uint8_t filamentRaw = ((status << 4) & 0xf0) + (filament & 0x0f);
|
||||||
hal::EEPROM::UpdateByte(&(eepromBase->eepromFilament[index]), filamentRaw);
|
hal::eeprom::UpdateByte(&(eepromBase->eepromFilament[index]), filamentRaw);
|
||||||
if (filamentRaw == hal::EEPROM::ReadByte(&(eepromBase->eepromFilament[index])))
|
if (filamentRaw == hal::eeprom::ReadByte(&(eepromBase->eepromFilament[index])))
|
||||||
return true;
|
return true;
|
||||||
getNext(status);
|
getNext(status);
|
||||||
if (!setStatus(status))
|
if (!setStatus(status))
|
||||||
|
|
@ -330,8 +330,8 @@ namespace permanent_storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DriveError::getL() {
|
uint8_t DriveError::getL() {
|
||||||
uint8_t first = hal::EEPROM::ReadByte(&(eepromBase->eepromDriveErrorCountL[0]));
|
uint8_t first = hal::eeprom::ReadByte(&(eepromBase->eepromDriveErrorCountL[0]));
|
||||||
uint8_t second = hal::EEPROM::ReadByte(&(eepromBase->eepromDriveErrorCountL[1]));
|
uint8_t second = hal::eeprom::ReadByte(&(eepromBase->eepromDriveErrorCountL[1]));
|
||||||
|
|
||||||
if (0xff == first && 0 == second)
|
if (0xff == first && 0 == second)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -339,15 +339,15 @@ namespace permanent_storage {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriveError::setL(uint8_t lowByte) {
|
void DriveError::setL(uint8_t lowByte) {
|
||||||
hal::EEPROM::UpdateByte(&(eepromBase->eepromDriveErrorCountL[lowByte % 2]), lowByte - 1);
|
hal::eeprom::UpdateByte(&(eepromBase->eepromDriveErrorCountL[lowByte % 2]), lowByte - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t DriveError::getH() {
|
uint8_t DriveError::getH() {
|
||||||
return (hal::EEPROM::ReadByte(&(eepromBase->eepromDriveErrorCountH)) + 1);
|
return (hal::eeprom::ReadByte(&(eepromBase->eepromDriveErrorCountH)) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DriveError::setH(uint8_t highByte) {
|
void DriveError::setH(uint8_t highByte) {
|
||||||
hal::EEPROM::UpdateByte(&(eepromBase->eepromDriveErrorCountH), highByte - 1);
|
hal::eeprom::UpdateByte(&(eepromBase->eepromDriveErrorCountH), highByte - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace permanent_storage
|
} // namespace permanent_storage
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue