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

@ -43,13 +43,13 @@
#define CS_BIT PORTD3
#define PIN_RST 2 // Pro Micro alternative display RST pin (pin 6 favoured for 2nd speaker pin)
#define RST_PORT PORTD
#define RST_BIT PORTD1
#define RST_PORT PORTD
#define RST_BIT PORTD1
#else
#define PIN_CS 12 // Display CS Arduino pin number
#define CS_PORT PORTD // Display CS port
#define CS_BIT PORTD6 // Display CS physical bit number
#define PIN_RST 6 // Display reset Arduino pin number
#define RST_PORT PORTD // Display reset port
#define RST_BIT PORTD7 // Display reset physical bit number
@ -85,20 +85,20 @@
#define I2C_SCL PORTD3
#else
#define I2C_SCL PORTD7
#endif
#endif
#define I2C_SDA PORTD4
//port states
#define I2C_SDA_HIGH() I2C_PORT |= (1 << I2C_SDA)
#define I2C_SCL_HIGH() I2C_PORT |= (1 << I2C_SCL)
#define I2C_SDA_LOW() I2C_PORT &= ~(1 << I2C_SDA)
#define I2C_SCL_LOW() I2C_PORT &= ~(1 << I2C_SCL)
//port directions
#define I2C_SDA_AS_INPUT() I2C_DDR &= ~(1 << I2C_SDA)
#define I2C_SCL_AS_INPUT() I2C_DDR &= ~(1 << I2C_SCL)
#define I2C_SDA_AS_OUTPUT() I2C_DDR |= (1 << I2C_SDA)
#define I2C_SCL_AS_OUTPUT() I2C_DDR |= (1 << I2C_SCL)
// display address, commands
#define SSD1306_I2C_ADDR 0x3c //0x3c:default, 0x3d: alternative)
#define SSD1306_I2C_CMD 0x00
@ -220,7 +220,7 @@
#ifdef AB_ALTERNATE_WIRING
#define PIN_SPEAKER_2 6 //Pro Micro alternative for 2nd speaker pin
#define SPEAKER_2_PORT PORTD
#define SPEAKER_2_PORT PORTD
#define SPEAKER_2_DDR DDRD
#define SPEAKER_2_BIT PORTD7
#else
@ -369,7 +369,7 @@
#if defined(OLED_SH1106) || defined(OLED_SH1106_I2C)
#define OLED_SET_COLUMN_ADDRESS_LO 0x02 //SH1106 only: 1st pixel starts on column 2
#else
#define OLED_SET_COLUMN_ADDRESS_LO 0x00
#define OLED_SET_COLUMN_ADDRESS_LO 0x00
#endif
#define OLED_SET_COLUMN_ADDRESS_HI 0x10
@ -378,7 +378,7 @@
#define WIDTH 96
#else
#define WIDTH 128 //The standard width of the display in pixels
#endif
#endif
#if defined(OLED_128X128)
#define HEIGHT 128
#elif defined(OLED_96X96) || defined(OLED_128X96) || defined(OLED_96X96_ON_128X128) || defined(OLED_128X96_ON_128X128)
@ -586,19 +586,19 @@ class Arduboy2Core : public Arduboy2NoUSB
#if defined (OLED_SSD1306_I2C) || (OLED_SSD1306_I2CX) || (OLED_SH1106_I2C)
static void i2c_start(uint8_t mode);
static void inline i2c_stop() __attribute__((always_inline))
{
// SDA and SCL both are already low, from writing ACK bit no need to change state
I2C_SDA_AS_INPUT(); // switch to input so SDA is pulled up externally first for stop condition
I2C_SCL_AS_INPUT(); // pull up SCL externally
}
static void i2c_sendByte(uint8_t byte);
#endif
//#endif
/** \brief
* Turn the display off.
*
@ -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.
@ -1046,9 +1093,9 @@ class Arduboy2Core : public Arduboy2NoUSB
*/
#ifndef ARDUBOY_CORE
static void delayShort(uint16_t ms) __attribute__ ((noinline));
#else
#else
static void delayShort(uint16_t ms);
#endif
#endif
static void delayByte(uint8_t ms) __attribute__ ((noinline));
/** \brief