Update Arduboy2 library

Add support for microcade
fix eeprom function warnings
inlined setRGBled On/Off functions
This commit is contained in:
Mr.Blinky 2022-12-11 15:21:52 +01:00
parent fc95424467
commit 32e8b1d25c
3 changed files with 119 additions and 99 deletions

View File

@ -86,13 +86,22 @@ void Arduboy2Base::flashlight()
void Arduboy2Base::systemButtons()
{
while (pressed(B_BUTTON)) {
#if defined(MICROCADE)
setRGBledRedOff();
setRGBledGreenOff();
#endif
setRGBledBlueOn();
sysCtrlSound(UP_BUTTON + B_BUTTON, GREEN_LED, 0xff);
sysCtrlSound(DOWN_BUTTON + B_BUTTON, RED_LED, 0);
delayByte(200);
}
#if defined(MICROCADE)
setRGBledRedOn();
setRGBledGreenOn();
setRGBledBlueOn();
#else
setRGBledBlueOff();
#endif
}
void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal)
@ -101,7 +110,7 @@ void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal)
setRGBledBlueOff();
delayByte(200);
digitalWriteRGB(led, RGB_ON); // turn on "acknowledge" LED
eeprom_update_byte(eepromAudioOnOff, eeVal);
eeprom_update_byte((uint8_t*)eepromAudioOnOff, eeVal);
delayShort(500);
digitalWriteRGB(led, RGB_OFF); // turn off "acknowledge" LED
@ -181,13 +190,23 @@ bool Arduboy2Base::bootLogoShell(void (&drawLogo)(int16_t))
if (showLEDs) {
setRGBledRedOn();
#if defined (MICROCADE)
setRGBledGreenOff();
setRGBledBlueOff();
#endif
}
for (int16_t y = -15; y <= 24; y++) {
if (pressed(RIGHT_BUTTON)) {
#if defined(MICROCADE)
setRGBledRedOn();
setRGBledGreenOn();
setRGBledBlueOn();
#else
setRGBledRedOff();
setRGBledGreenOff();
//setRGBledblueOff(); // Blue LED not turned on inside loop
#endif
return false;
}
@ -209,7 +228,12 @@ bool Arduboy2Base::bootLogoShell(void (&drawLogo)(int16_t))
setRGBledBlueOn();
}
delayShort(400);
#if !defined (MICROCADE)
setRGBledBlueOff();
#else
setRGBledGreenOn();
setRGBledRedOn();
#endif
return true;
}
@ -1072,21 +1096,21 @@ bool Arduboy2Base::collide(Rect rect1, Rect rect2)
uint16_t Arduboy2Base::readUnitID()
{
return eeprom_read_byte(eepromUnitID) |
(((uint16_t)(eeprom_read_byte(eepromUnitID + 1))) << 8);
return eeprom_read_byte((uint8_t*)eepromUnitID) |
(((uint16_t)(eeprom_read_byte((uint8_t*)(eepromUnitID + 1)))) << 8);
}
void Arduboy2Base::writeUnitID(uint16_t id)
{
eeprom_update_byte(eepromUnitID, (uint8_t)(id & 0xff));
eeprom_update_byte(eepromUnitID + 1, (uint8_t)(id >> 8));
eeprom_update_byte((uint8_t*)eepromUnitID, (uint8_t)(id & 0xff));
eeprom_update_byte((uint8_t*)eepromUnitID + 1, (uint8_t)(id >> 8));
}
uint8_t Arduboy2Base::readUnitName(char* name)
{
char val;
uint8_t dest;
uint8_t src = eepromUnitName;
uint8_t* src = (uint8_t*)eepromUnitName;
for (dest = 0; dest < ARDUBOY_UNIT_NAME_LEN; dest++)
{
@ -1105,7 +1129,7 @@ uint8_t Arduboy2Base::readUnitName(char* name)
void Arduboy2Base::writeUnitName(const char* name)
{
bool done = false;
uint8_t dest = eepromUnitName;
uint8_t* dest = (uint8_t*)eepromUnitName;
for (uint8_t src = 0; src < ARDUBOY_UNIT_NAME_LEN; src++)
{
@ -1120,41 +1144,41 @@ void Arduboy2Base::writeUnitName(const char* name)
bool Arduboy2Base::readShowBootLogoFlag()
{
return (eeprom_read_byte(eepromSysFlags) & sysFlagShowLogoMask);
return (eeprom_read_byte((uint8_t*)eepromSysFlags) & sysFlagShowLogoMask);
}
void Arduboy2Base::writeShowBootLogoFlag(bool val)
{
uint8_t flags = eeprom_read_byte(eepromSysFlags);
uint8_t flags = eeprom_read_byte((uint8_t*)eepromSysFlags);
bitWrite(flags, sysFlagShowLogoBit, val);
eeprom_update_byte(eepromSysFlags, flags);
eeprom_update_byte((uint8_t*)eepromSysFlags, flags);
}
bool Arduboy2Base::readShowUnitNameFlag()
{
return (eeprom_read_byte(eepromSysFlags) & sysFlagUnameMask);
return (eeprom_read_byte((uint8_t*)eepromSysFlags) & sysFlagUnameMask);
}
void Arduboy2Base::writeShowUnitNameFlag(bool val)
{
uint8_t flags = eeprom_read_byte(eepromSysFlags);
uint8_t flags = eeprom_read_byte((uint8_t*)eepromSysFlags);
bitWrite(flags, sysFlagUnameBit, val);
eeprom_update_byte(eepromSysFlags, flags);
eeprom_update_byte((uint8_t*)eepromSysFlags, flags);
}
bool Arduboy2Base::readShowBootLogoLEDsFlag()
{
return (eeprom_read_byte(eepromSysFlags) & sysFlagShowLogoLEDsMask);
return (eeprom_read_byte((uint8_t*)eepromSysFlags) & sysFlagShowLogoLEDsMask);
}
void Arduboy2Base::writeShowBootLogoLEDsFlag(bool val)
{
uint8_t flags = eeprom_read_byte(eepromSysFlags);
uint8_t flags = eeprom_read_byte((uint8_t*)eepromSysFlags);
bitWrite(flags, sysFlagShowLogoLEDsBit, val);
eeprom_update_byte(eepromSysFlags, flags);
eeprom_update_byte((uint8_t*)eepromSysFlags, flags);
}
void Arduboy2Base::swapInt16(int16_t& a, int16_t& b)
@ -1305,11 +1329,11 @@ void Arduboy2::bootLogoExtra()
return;
}
c = eeprom_read_byte(eepromUnitName);
c = eeprom_read_byte((uint8_t*)eepromUnitName);
if (c != 0xFF && c != 0x00)
{
uint8_t i = eepromUnitName;
uint8_t* i = (uint8_t*)eepromUnitName;
cursor_x = 50 - (64 - WIDTH / 2);
cursor_y = 56;
@ -1318,7 +1342,7 @@ void Arduboy2::bootLogoExtra()
write(c);
c = eeprom_read_byte(++i);
}
while (i < eepromUnitName + ARDUBOY_UNIT_NAME_LEN);
while ((uint16_t)i < eepromUnitName + ARDUBOY_UNIT_NAME_LEN);
display();
delayShort(1000);

View File

@ -194,7 +194,10 @@ void Arduboy2Core::bootPins()
#ifdef ARDUBOY_10
// Port B INPUT_PULLUP or HIGH
PORTB = (_BV(RED_LED_BIT) | _BV(BLUE_LED_BIT) //RGB LED off
PORTB = (0
#ifndef MICROCADE
| _BV(RED_LED_BIT) | _BV(BLUE_LED_BIT) //RGB LED off
#endif
#ifndef AB_ALTERNATE_WIRING
| _BV(GREEN_LED_BIT)
#endif
@ -231,7 +234,7 @@ void Arduboy2Core::bootPins()
// Speaker: Not set here. Controlled by audio class
// Port D INPUT_PULLUP or HIGH
PORTD = (
#if defined(AB_ALTERNATE_WIRING)
#if (defined(AB_ALTERNATE_WIRING) && !defined(MICROCADE))
_BV(GREEN_LED_BIT) |
#endif
#if !(defined(ARDUINO_AVR_MICRO))
@ -1182,63 +1185,9 @@ void Arduboy2Core::flipHorizontal(bool flipped)
/* RGB LED */
void Arduboy2Core::setRGBledRedOn()
{
#ifndef LCD_ST7565
bitClear(RED_LED_PORT, RED_LED_BIT); // Red on
#else
bitSet(RED_LED_PORT, RED_LED_BIT); // Red on
#endif
}
void Arduboy2Core::setRGBledRedOff()
{
#ifndef LCD_ST7565
bitSet(RED_LED_PORT, RED_LED_BIT); // Red off
#else
bitClear(RED_LED_PORT, RED_LED_BIT); // Red off
#endif
}
void Arduboy2Core::setRGBledGreenOn()
{
#ifndef LCD_ST7565
bitClear(GREEN_LED_PORT, GREEN_LED_BIT); // Green on
#else
bitSet(GREEN_LED_PORT, GREEN_LED_BIT); // Green on
#endif
}
void Arduboy2Core::setRGBledGreenOff()
{
#ifndef LCD_ST7565
bitSet(GREEN_LED_PORT, GREEN_LED_BIT); // Green off
#else
bitClear(GREEN_LED_PORT, GREEN_LED_BIT); // Green off
#endif
}
void Arduboy2Core::setRGBledBlueOn()
{
#ifndef LCD_ST7565
bitClear(BLUE_LED_PORT, BLUE_LED_BIT); // Blue on
#else
bitSet(BLUE_LED_PORT, BLUE_LED_BIT); // Blue on
#endif
}
void Arduboy2Core::setRGBledBlueOff()
{
#ifndef LCD_ST7565
bitSet(BLUE_LED_PORT, BLUE_LED_BIT); // Blue off
#else
bitClear(BLUE_LED_PORT, BLUE_LED_BIT); // Blue off
#endif
}
void Arduboy2Core::setRGBled(uint8_t red, uint8_t green, uint8_t blue)
{
#ifdef LCD_ST7565
#if defined (LCD_ST7565) || (MICROCADE)
if ((red | green | blue) == 0) //prevent backlight off
{
red = 255;
@ -1335,7 +1284,7 @@ void Arduboy2Core::freeRGBled()
void Arduboy2Core::digitalWriteRGB(uint8_t red, uint8_t green, uint8_t blue)
{
#ifdef LCD_ST7565
#if defined (LCD_ST7565) || (MICROCADE)
if ((red & green & blue) == RGB_OFF) //prevent backlight off
{
red = RGB_ON;

View File

@ -830,12 +830,59 @@ class Arduboy2Core : public Arduboy2NoUSB
*/
static void sendLCDCommand(uint8_t command);
static void setRGBledRedOn();
static void setRGBledRedOff();
static void setRGBledGreenOn();
static void setRGBledGreenOff();
static void setRGBledBlueOn();
static void setRGBledBlueOff();
static void inline setRGBledRedOn()__attribute__((always_inline))
{
#ifndef LCD_ST7565
bitClear(RED_LED_PORT, RED_LED_BIT); // Red on
#else
bitSet(RED_LED_PORT, RED_LED_BIT); // Red on
#endif
}
static void inline setRGBledRedOff()__attribute__((always_inline))
{
#ifndef LCD_ST7565
bitSet(RED_LED_PORT, RED_LED_BIT); // Red off
#else
bitClear(RED_LED_PORT, RED_LED_BIT); // Red off
#endif
}
static void inline setRGBledGreenOn()__attribute__((always_inline))
{
#ifndef LCD_ST7565
bitClear(GREEN_LED_PORT, GREEN_LED_BIT); // Green on
#else
bitSet(GREEN_LED_PORT, GREEN_LED_BIT); // Green on
#endif
}
static void inline setRGBledGreenOff()__attribute__((always_inline))
{
#ifndef LCD_ST7565
bitSet(GREEN_LED_PORT, GREEN_LED_BIT); // Green off
#else
bitClear(GREEN_LED_PORT, GREEN_LED_BIT); // Green off
#endif
}
static void inline setRGBledBlueOn()__attribute__((always_inline))
{
#ifndef LCD_ST7565
bitClear(BLUE_LED_PORT, BLUE_LED_BIT); // Blue on
#else
bitSet(BLUE_LED_PORT, BLUE_LED_BIT); // Blue on
#endif
}
static void inline setRGBledBlueOff()__attribute__((always_inline))
{
#ifndef LCD_ST7565
bitSet(BLUE_LED_PORT, BLUE_LED_BIT); // Blue off
#else
bitClear(BLUE_LED_PORT, BLUE_LED_BIT); // Blue off
#endif
}
/** \brief
* Set the light output of the RGB LED.