Skip to content

Commit

Permalink
Daniel/duo/full hardened malloc removal (#241)
Browse files Browse the repository at this point in the history
* huge refactor and cleanup
* fixed major bugs
* added more mode slots via flash storage
* added one click to toggle off auto cycle
* adv modesharing is led selection now
* adv color select and pattern select had to be removed
  • Loading branch information
Unreal-Dan authored Apr 30, 2024
1 parent 6b79341 commit ba55bd0
Show file tree
Hide file tree
Showing 103 changed files with 6,617 additions and 23,370 deletions.
44 changes: 35 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ CPU_SPEED = 10000000L
# the port for serial upload
SERIAL_PORT = COM11

# whether eeprom is erased on flash (must write this fuse first to take effect)
SAVE_EEPROM = 1
FUSE0 = 0b00000000
FUSE2 = 0x02
FUSE5 = 0b1100010$(SAVE_EEPROM)
FUSE6 = 0x04

# WDTCFG { PERIOD=OFF, WINDOW=OFF }
WDTCFG = 0b00000000
# BODCFG { SLEEP=DIS, ACTIVE=DIS, SAMPFREQ=1KHZ, LVL=BODLEVEL0 }
BODCFG = 0x00
# OSCCFG { FREQSEL=20mhz, OSCLOCK=CLEAR }
OSCCFG = 0x02
# RESERVED
#FUSE3 = 0x00
# TCD0CFG { CMPA=CLEAR, CMPB=CLEAR, CMPC=CLEAR, CMPD=CLEAR, CMPAEN=CLEAR, CPMCEN=CLEAR, CMPDEN=CLEAR }
TCD0CFG = 0x00
# SYSCFG0
SYSCFG0 = 0b1100010$(SAVE_EEPROM)
# SYSCFG1 { SUT=64ms }
SYSCFG1 = 0x07
# fuse7 = APPEND
FUSE7 = 0x00
APPEND = 0x00
# fuse8 = BOOTEND
FUSE8 = 0x7e
# This controls the amount of storage for modes at the end of the flash memory,
# it is the boundary for the segment that can be rewritten by the program, 0x7e
# means 0x7e00/0x8000 bytes are program and 0x200 bytes are reserved for flash
# storage of modes, this does not include the eeprom.
BOOTEND = 0x7e

CFLAGS = -g \
-Os \
Expand Down Expand Up @@ -107,7 +123,7 @@ all: $(TARGET).hex
$(OBJDUMP) --disassemble --source --line-numbers --demangle --section=.text $(TARGET).elf > $(TARGET).lst
$(NM) --numeric-sort --line-numbers --demangle --print-size --format=s $(TARGET).elf > $(TARGET).map
chmod +x avrsize.sh
./avrsize.sh $(TARGET).elf
./avrsize.sh $(TARGET).elf $(BOOTEND)00

$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O binary -R .eeprom $(TARGET).elf $(TARGET).bin
Expand All @@ -124,11 +140,21 @@ $(TARGET).elf: $(OBJS)
$(CC) $(CFLAGS) -c $< -o $@

upload: $(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -Ufuse0:w:$(FUSE0):m -Ufuse2:w:$(FUSE2):m -Ufuse5:w:$(FUSE5):m -Ufuse6:w:$(FUSE6):m -Ufuse7:w:$(FUSE7):m -Ufuse8:w:$(FUSE8):m -Uflash:w:$(TARGET).hex:i
$(AVRDUDE) $(AVRDUDE_FLAGS) \
-Ufuse0:w:$(WDTCFG):m \
-Ufuse1:w:$(BODCFG):m \
-Ufuse2:w:$(OSCCFG):m \
-Ufuse4:w:$(TCD0CFG):m \
-Ufuse5:w:$(SYSCFG0):m \
-Ufuse6:w:$(SYSCFG1):m \
-Ufuse7:w:$(APPEND):m \
-Ufuse8:w:$(BOOTEND):m \
-Uflash:w:$(TARGET).hex:i

# upload via SerialUPDI
serial: $(TARGET).hex
$(PYTHON) -u $(PYPROG) -t uart -u $(SERIAL_PORT) -b 921600 -d $(AVRDUDE_CHIP) --fuses 0:$(FUSE0) 2:$(FUSE2) 5:$(FUSE5) 6:$(FUSE6) 7:$(FUSE7) 8:$(FUSE8) -f $< -a write -v
$(PYTHON) -u $(PYPROG) -t uart -u $(SERIAL_PORT) -b 921600 -d $(AVRDUDE_CHIP) \
--fuses 0:$(WDTCFG) 1:$(BODCFG) 2:$(OSCCFG) 4:$(TCD0CFG) 5:$(SYSCFG0) 6:$(SYSCFG1) 7:$(APPEND) 8:$(BOOTEND) -f $< -a write -v

ifneq ($(OS),Windows_NT) # Linux
build: all
Expand Down
8 changes: 1 addition & 7 deletions VortexEngine/VortexEngine.cppproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@
<Compile Include="src\Patterns\Multi\LighthousePattern.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MateriaPattern.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MeteorPattern.cpp">
<SubType>compile</SubType>
</Compile>
Expand Down Expand Up @@ -455,9 +452,6 @@
<Compile Include="src\Patterns\Multi\LighthousePattern.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MateriaPattern.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\Patterns\Multi\MeteorPattern.h">
<SubType>compile</SubType>
</Compile>
Expand Down Expand Up @@ -606,4 +600,4 @@
<Folder Include="src\Wireless\" />
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>
</Project>
18 changes: 10 additions & 8 deletions VortexEngine/VortexLib/VortexLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,16 @@ EMSCRIPTEN_BINDINGS(Vortex) {
.function("sanity", &ByteStream::sanity)
.function("checkCRC", &ByteStream::checkCRC)
.function("isCRCDirty", &ByteStream::isCRCDirty)
.function("serialize", select_overload<bool(uint8_t)>(&ByteStream::serialize))
.function("serialize16", select_overload<bool(uint16_t)>(&ByteStream::serialize))
.function("serialize32", select_overload<bool(uint32_t)>(&ByteStream::serialize))
.function("serialize8", &ByteStream::serialize8)
.function("serialize16", &ByteStream::serialize16)
.function("serialize32", &ByteStream::serialize32)
.function("resetUnserializer", &ByteStream::resetUnserializer)
.function("moveUnserializer", &ByteStream::moveUnserializer)
.function("unserializerAtEnd", &ByteStream::unserializerAtEnd)
.function("unserialize8", &ByteStream::unserialize8)
.function("unserialize16", &ByteStream::unserialize16)
.function("unserialize32", &ByteStream::unserialize32)
// TODO: provide better apis here
//.function("unserialize8", &ByteStream::unserialize8)
//.function("unserialize16", &ByteStream::unserialize16)
//.function("unserialize32", &ByteStream::unserialize32)
.function("peek8", &ByteStream::peek8)
.function("peek16", &ByteStream::peek16)
.function("peek32", &ByteStream::peek32)
Expand Down Expand Up @@ -658,8 +659,9 @@ bool Vortex::init(VortexCallbacks *callbacks)

// init the engine
VortexEngine::init();
// clear the modes
//Modes::clearModes();
// load the modes
// TODO: don't load modes here? separate api?
Modes::load();
// save and set undo buffer
doSave();

Expand Down
20 changes: 7 additions & 13 deletions VortexEngine/src/Buttons/Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,26 @@
// This will simply point at Buttons::m_button.
Button *g_pButton = nullptr;

// static members
Button Buttons::m_buttons[NUM_BUTTONS];

bool Buttons::init()
{
// initialize the button on pin 1
if (!m_buttons[0].init(1)) {
g_pButton = new Button();
if (!g_pButton) {
return false;
}
g_pButton = &m_buttons[0];
return true;
// init the button on pin 1
return g_pButton->init(1);
}

void Buttons::cleanup()
{
delete g_pButton;
}

void Buttons::update()
{
// would iterate all buttons and check them here
// but there's only one button so
for (uint8_t i = 0; i < NUM_BUTTONS; ++i) {
m_buttons[i].update();
}
g_pButton->update();
#ifdef VORTEX_LIB
// read input from the vortex lib interface, for example Vortex::shortClick()
Vortex::handleInputQueue(m_buttons, NUM_BUTTONS);
Vortex::handleInputQueue(g_pButton, NUM_BUTTONS);
#endif
}
2 changes: 0 additions & 2 deletions VortexEngine/src/Buttons/Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Buttons
static uint8_t numButtons() { return NUM_BUTTONS; }

private:
// feel free to add more I guess
static Button m_buttons[NUM_BUTTONS];
};

// best way I think
Expand Down
30 changes: 22 additions & 8 deletions VortexEngine/src/Colors/ColorTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,32 @@ RGBColor RGBColor::adjustBrightness(uint8_t fadeBy)
return *this;
}

void RGBColor::serialize(ByteStream &buffer) const
bool RGBColor::serialize(ByteStream &buffer) const
{
buffer.serialize(red);
buffer.serialize(green);
buffer.serialize(blue);
if (!buffer.serialize8(red)) {
return false;
}
if (!buffer.serialize8(green)) {
return false;
}
if (!buffer.serialize8(blue)) {
return false;
}
return true;
}

void RGBColor::unserialize(ByteStream &buffer)
bool RGBColor::unserialize(ByteStream &buffer)
{
buffer.unserialize(&red);
buffer.unserialize(&green);
buffer.unserialize(&blue);
if (!buffer.unserialize8(&red)) {
return false;
}
if (!buffer.unserialize8(&green)) {
return false;
}
if (!buffer.unserialize8(&blue)) {
return false;
}
return true;
}

// ========================================================
Expand Down
4 changes: 2 additions & 2 deletions VortexEngine/src/Colors/ColorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class RGBColor
void clear();

RGBColor adjustBrightness(uint8_t fadeBy);
void serialize(ByteStream &buffer) const;
void unserialize(ByteStream &buffer);
bool serialize(ByteStream &buffer) const;
bool unserialize(ByteStream &buffer);

uint32_t raw() const { return ((uint32_t)red << 16) | ((uint32_t)green << 8) | (uint32_t)blue; }

Expand Down
Loading

0 comments on commit ba55bd0

Please sign in to comment.