Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Inline functions and make parameters const
Browse files Browse the repository at this point in the history
Apparently the Arduino compiler ignores "inline" because it tries to
optimise for size. However, all functions are only called once so
there shouldn't be any size penalty for inlining.
  • Loading branch information
MarkKoz committed May 8, 2022
1 parent c393a04 commit ab93a46
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const uint_fast8_t PIN_MUTE = 9;
const byte MIDI_ALL_SOUNDS_OFF = 120;
const byte MIDI_ALL_NOTES_OFF = 123;

bool is_reset_msg(const MidiMessage& msg);
void set_note(uint_fast8_t note, uint_fast8_t octave);
void set_voltage(float voltage);
inline bool is_reset_msg(const MidiMessage& msg) __attribute__((always_inline));
inline void set_note(uint_fast8_t note, uint_fast8_t octave) __attribute__((always_inline));
inline void set_voltage(float voltage) __attribute__((always_inline));

void setup()
{
Expand Down Expand Up @@ -52,12 +52,12 @@ bool is_reset_msg(const MidiMessage& msg)
&& (msg.param1 == MIDI_ALL_NOTES_OFF || msg.param1 == MIDI_ALL_SOUNDS_OFF);
}

void set_note(uint_fast8_t note, uint_fast8_t octave)
void set_note(const uint_fast8_t note, const uint_fast8_t octave)
{
set_voltage(octave + (note / 12.0F));
}

void set_voltage(float voltage)
void set_voltage(const float voltage)
{
PORTD = static_cast<uint8_t>(lroundf(ONE_VOLT * voltage));
}

0 comments on commit ab93a46

Please sign in to comment.