diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index 58ac0bd..df39798 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -89,7 +89,7 @@ void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal) digitalWriteRGB(BLUE_LED, RGB_OFF); // turn off blue LED delayShort(200); digitalWriteRGB(led, RGB_ON); // turn on "acknowledge" LED - EEPROM.update(EEPROM_AUDIO_ON_OFF, eeVal); + EEPROM.update(eepromAudioOnOff, eeVal); delayShort(500); digitalWriteRGB(led, RGB_OFF); // turn off "acknowledge" LED @@ -1069,21 +1069,21 @@ bool Arduboy2Base::collide(Rect rect1, Rect rect2) uint16_t Arduboy2Base::readUnitID() { - return EEPROM.read(EEPROM_UNIT_ID) | - (((uint16_t)(EEPROM.read(EEPROM_UNIT_ID + 1))) << 8); + return EEPROM.read(eepromUnitID) | + (((uint16_t)(EEPROM.read(eepromUnitID + 1))) << 8); } void Arduboy2Base::writeUnitID(uint16_t id) { - EEPROM.update(EEPROM_UNIT_ID, (uint8_t)(id & 0xff)); - EEPROM.update(EEPROM_UNIT_ID + 1, (uint8_t)(id >> 8)); + EEPROM.update(eepromUnitID, (uint8_t)(id & 0xff)); + EEPROM.update(eepromUnitID + 1, (uint8_t)(id >> 8)); } uint8_t Arduboy2Base::readUnitName(char* name) { char val; uint8_t dest; - uint8_t src = EEPROM_UNIT_NAME; + uint8_t src = eepromUnitName; for (dest = 0; dest < ARDUBOY_UNIT_NAME_LEN; dest++) { @@ -1102,7 +1102,7 @@ uint8_t Arduboy2Base::readUnitName(char* name) void Arduboy2Base::writeUnitName(char* name) { bool done = false; - uint8_t dest = EEPROM_UNIT_NAME; + uint8_t dest = eepromUnitName; for (uint8_t src = 0; src < ARDUBOY_UNIT_NAME_LEN; src++) { @@ -1117,41 +1117,41 @@ void Arduboy2Base::writeUnitName(char* name) bool Arduboy2Base::readShowBootLogoFlag() { - return (EEPROM.read(EEPROM_SYS_FLAGS) & SYS_FLAG_SHOW_LOGO_MASK); + return (EEPROM.read(eepromSysFlags) & sysFlagShowLogoMask); } void Arduboy2Base::writeShowBootLogoFlag(bool val) { - uint8_t flags = EEPROM.read(EEPROM_SYS_FLAGS); + uint8_t flags = EEPROM.read(eepromSysFlags); - bitWrite(flags, SYS_FLAG_SHOW_LOGO, val); - EEPROM.update(EEPROM_SYS_FLAGS, flags); + bitWrite(flags, sysFlagShowLogoBit, val); + EEPROM.update(eepromSysFlags, flags); } bool Arduboy2Base::readShowUnitNameFlag() { - return (EEPROM.read(EEPROM_SYS_FLAGS) & SYS_FLAG_UNAME_MASK); + return (EEPROM.read(eepromSysFlags) & sysFlagUnameMask); } void Arduboy2Base::writeShowUnitNameFlag(bool val) { - uint8_t flags = EEPROM.read(EEPROM_SYS_FLAGS); + uint8_t flags = EEPROM.read(eepromSysFlags); - bitWrite(flags, SYS_FLAG_UNAME, val); - EEPROM.update(EEPROM_SYS_FLAGS, flags); + bitWrite(flags, sysFlagUnameBit, val); + EEPROM.update(eepromSysFlags, flags); } bool Arduboy2Base::readShowBootLogoLEDsFlag() { - return (EEPROM.read(EEPROM_SYS_FLAGS) & SYS_FLAG_SHOW_LOGO_LEDS_MASK); + return (EEPROM.read(eepromSysFlags) & sysFlagShowLogoLEDsMask); } void Arduboy2Base::writeShowBootLogoLEDsFlag(bool val) { - uint8_t flags = EEPROM.read(EEPROM_SYS_FLAGS); + uint8_t flags = EEPROM.read(eepromSysFlags); - bitWrite(flags, SYS_FLAG_SHOW_LOGO_LEDS, val); - EEPROM.update(EEPROM_SYS_FLAGS, flags); + bitWrite(flags, sysFlagShowLogoLEDsBit, val); + EEPROM.update(eepromSysFlags, flags); } void Arduboy2Base::swapInt16(int16_t& a, int16_t& b) @@ -1232,11 +1232,11 @@ void Arduboy2::bootLogoExtra() return; } - c = EEPROM.read(EEPROM_UNIT_NAME); + c = EEPROM.read(eepromUnitName); if (c != 0xFF && c != 0x00) { - uint8_t i = EEPROM_UNIT_NAME; + uint8_t i = eepromUnitName; cursor_x = 50; cursor_y = 56; @@ -1245,7 +1245,7 @@ void Arduboy2::bootLogoExtra() write(c); c = EEPROM.read(++i); } - while (i < EEPROM_UNIT_NAME + ARDUBOY_UNIT_NAME_LEN); + while (i < eepromUnitName + ARDUBOY_UNIT_NAME_LEN); display(); delayShort(1000); diff --git a/src/Arduboy2.h b/src/Arduboy2.h index 3d97fb6..6796a90 100644 --- a/src/Arduboy2.h +++ b/src/Arduboy2.h @@ -10,6 +10,7 @@ #include #include #include "Arduboy2Core.h" +#include "Arduboy2Audio.h" #include "Arduboy2Beep.h" #include "Sprites.h" #include "SpritesB.h" @@ -63,22 +64,6 @@ */ #define ARDUBOY_UNIT_NAME_BUFFER_SIZE (ARDUBOY_UNIT_NAME_LEN + 1) -#define EEPROM_VERSION 0 -#define EEPROM_SYS_FLAGS 1 -#define EEPROM_AUDIO_ON_OFF 2 -#define EEPROM_UNIT_ID 8 // A uint16_t binary unit ID -#define EEPROM_UNIT_NAME 10 // An up to 6 character unit name - // Cannot contain 0x00, 0xFF, 0x0A, 0x0D - // Lengths less than 6 are padded with 0x00 - -// EEPROM_SYS_FLAGS values -#define SYS_FLAG_UNAME 0 // Display the unit name on the logo screen -#define SYS_FLAG_UNAME_MASK _BV(SYS_FLAG_UNAME) -#define SYS_FLAG_SHOW_LOGO 1 // Show the logo sequence during boot up -#define SYS_FLAG_SHOW_LOGO_MASK _BV(SYS_FLAG_SHOW_LOGO) -#define SYS_FLAG_SHOW_LOGO_LEDS 2 // Flash the RGB led during the boot logo -#define SYS_FLAG_SHOW_LOGO_LEDS_MASK _BV(SYS_FLAG_SHOW_LOGO_LEDS) - /** \brief * Start of EEPROM storage space for sketches. * @@ -89,9 +74,6 @@ */ #define EEPROM_STORAGE_SPACE_START 16 -// eeprom settings above are neded for audio -#include "Arduboy2Audio.h" - // If defined, it is safe to draw outside of the screen boundaries. // Pixels that would exceed the display limits will be ignored. #define PIXEL_SAFE_MODE @@ -233,6 +215,7 @@ struct Point class Arduboy2Base : public Arduboy2Core { friend class Arduboy2Ex; + friend class Arduboy2Audio; public: Arduboy2Base(); @@ -411,10 +394,10 @@ class Arduboy2Base : public Arduboy2Core * developers who wish to quickly start testing, or anyone else who is * impatient and wants to go straight to the actual sketch. * - * If the SYS_FLAG_SHOW_LOGO_LEDS flag in system EEPROM is cleared, + * If the "Show LEDs with boot logo" flag in system EEPROM is cleared, * the RGB LEDs will not be flashed during the logo display sequence. * - * If the SYS_FLAG_SHOW_LOGO flag in system EEPROM is cleared, this function + * If the "Show Boot Logo" flag in system EEPROM is cleared, this function * will return without executing the logo display sequence. * * The prototype for the function provided to draw the logo is: @@ -1427,6 +1410,35 @@ class Arduboy2Base : public Arduboy2Core uint8_t thisFrameStart; bool justRendered; uint8_t lastFrameDurationMs; + + // ----- Map of EEPROM addresses for system use----- + + // EEPROM address 0 is reserved for bootloader use + // This library will not touch it + + // Control flags + static constexpr uint16_t eepromSysFlags = 1; + // Audio mute control. 0 = audio off, non-zero = audio on + static constexpr uint16_t eepromAudioOnOff = 2; + // -- Addresses 3-7 are currently reserved for future use -- + // A uint16_t binary unit ID + static constexpr uint16_t eepromUnitID = 8; // A uint16_t binary unit ID + // An up to 6 character unit name + // The name cannot contain 0x00, 0xFF, 0x0A, 0x0D + // Lengths less than 6 are padded with 0x00 + static constexpr uint16_t eepromUnitName = 10; + // -- User EEPROM space starts at address 16 -- + + // --- map of the bits in the eepromSysFlags byte -- + // Display the unit name on the logo screen + static constexpr uint8_t sysFlagUnameBit = 0; + static constexpr uint8_t sysFlagUnameMask = _BV(sysFlagUnameBit); + // Show the logo sequence during boot up + static constexpr uint8_t sysFlagShowLogoBit = 1; + static constexpr uint8_t sysFlagShowLogoMask = _BV(sysFlagShowLogoBit); + // Flash the RGB led during the boot logo + static constexpr uint8_t sysFlagShowLogoLEDsBit = 2; + static constexpr uint8_t sysFlagShowLogoLEDsMask = _BV(sysFlagShowLogoLEDsBit); }; @@ -1519,10 +1531,10 @@ class Arduboy2 : public Print, public Arduboy2Base * developers who wish to quickly start testing, or anyone else who is * impatient and wants to go straight to the actual sketch. * - * If the SYS_FLAG_SHOW_LOGO_LEDS flag in system EEPROM is cleared, + * If the "Show LEDs with boot logo" flag in system EEPROM is cleared, * the RGB LEDs will not be flashed during the logo display sequence. * - * If the SYS_FLAG_SHOW_LOGO flag in system EEPROM is cleared, this function + * If the "Show Boot Logo" flag in system EEPROM is cleared, this function * will return without executing the logo display sequence. * * \see bootLogo() boot() Arduboy2::bootLogoExtra() @@ -1539,7 +1551,7 @@ class Arduboy2 : public Print, public Arduboy2Base * the bottom of the screen. This function pauses for a short time to allow * the name to be seen. * - * If the SYS_FLAG_UNAME flag in system EEPROM is cleared, this function + * If the "Show Unit Name" flag in system EEPROM is cleared, this function * will return without showing the unit name or pausing. * * \note diff --git a/src/Arduboy2Audio.cpp b/src/Arduboy2Audio.cpp index 701f806..ed23248 100644 --- a/src/Arduboy2Audio.cpp +++ b/src/Arduboy2Audio.cpp @@ -5,7 +5,6 @@ */ #include "Arduboy2.h" -#include "Arduboy2Audio.h" bool Arduboy2Audio::audio_enabled = false; @@ -43,12 +42,12 @@ void Arduboy2Audio::toggle() void Arduboy2Audio::saveOnOff() { - EEPROM.update(EEPROM_AUDIO_ON_OFF, audio_enabled); + EEPROM.update(Arduboy2Base::eepromAudioOnOff, audio_enabled); } void Arduboy2Audio::begin() { - if (EEPROM.read(EEPROM_AUDIO_ON_OFF)) + if (EEPROM.read(Arduboy2Base::eepromAudioOnOff)) on(); else off();