Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierBrassoud committed Feb 17, 2024
1 parent 4b44221 commit 542ff89
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 144 deletions.
2 changes: 1 addition & 1 deletion examples/blink/blink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* | 12 | GND | - |
* | 13 | LCD write (+3.3V !) | 49 ⚡ |
* | 14 | GND | - |
*
*
* ⚡ Require a 3.3v level-shifter, screen makes shadows and may be destroyed after long use.
* 🔺 Require a 10k pull-up resistor wired between 3.3V and Arduino pin
*/
Expand Down
6 changes: 3 additions & 3 deletions examples/buttons/buttons.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
* | 12 | GND | - |
* | 13 | LCD write (+3.3V !) | 49 ⚡ |
* | 14 | GND | - |
*
*
* ⚡ Require a 3.3v level-shifter, screen makes shadows and may be destroyed after long use.
* 🔺 Require a 10k pull-up resistor wired between 3.3V and Arduino pin
*/

#if defined(ARDUINO_ARCH_AVR)
#define BAUD_RATE 115200
#define BAUD_RATE 115200
#else
#define BAUD_RATE 9600
#define BAUD_RATE 9600
#endif

#include <Epson_PNL_CE02.h>
Expand Down
8 changes: 4 additions & 4 deletions examples/display/display.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @version 1.0
*
* @copyright MIT license
*
*
* | Pin | Purpose | MEGA 2560 |
* |-----|-------------------------------------------|---------------|
* | 1 | 3-STATE Output Enable Input (OE) | 45 |
Expand All @@ -25,11 +25,11 @@
* | 12 | GND | - |
* | 13 | LCD write (+3.3V !) | 49 ⚡ |
* | 14 | GND | - |
*
*
* ⚡ Require a 3.3v level-shifter, screen makes shadows and may be destroyed after long use.
* 🔺 Require a 10k pull-up resistor wired between 3.3V and Arduino pin
*
*
*
* Adaptation:
* 1. Download [MCUFRIEND_kbv v3](https://github.com/prenticedavid/MCUFRIEND_kbv)
* 2. Edit *MCUFRIEND_kbv/utility/mcufriend_shield.h*:
Expand All @@ -48,7 +48,7 @@
* ``` c++
* controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH);
* tft.begin(0x9163);
*
*
*/

#include <Epson_PNL_CE02.h>
Expand Down
142 changes: 71 additions & 71 deletions examples/full/full.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
* | 12 | GND | - |
* | 13 | LCD write (+3.3V !) | 49 ⚡ |
* | 14 | GND | - |
*
*
* ⚡ Require a 3.3v level-shifter, screen makes shadows and may be destroyed after long use.
* 🔺 Require a 10k pull-up resistor wired between 3.3V and Arduino pin
*
*
* Fix OneButton issue: https://github.com/mathertel/OneButton/issues/136#issuecomment-1891117014
*/

#if defined(ARDUINO_ARCH_AVR)
#define BAUD_RATE 115200
#define BAUD_RATE 115200
#else
#define BAUD_RATE 9600
#define BAUD_RATE 9600
#endif

// install the OneButton library via Library Manager
Expand Down Expand Up @@ -89,96 +89,96 @@ OneButton powerButton(POWER_BUTTON);

void printClick(void *button)
{
Serial.print("Click: ");
Serial.println((char *)button);
Serial.print("Click: ");
Serial.println((char *)button);
}

void colorClick(void *color)
{
tft.fillScreen((uint16_t)color);
tft.fillScreen((uint16_t)color);
}

byte powerState = HIGH;
void togglePower()
{
Serial.println("Click: power long - toggle power");
Serial.println("Click: power long - toggle power");

// reverse power (turns off when on, on when off)
powerState = !powerState;
// reverse power (turns off when on, on when off)
powerState = !powerState;

// send new power LED state.
controlPanel.extenderWrite(POWER_LED, !powerState);
// send new power LED state.
controlPanel.extenderWrite(POWER_LED, !powerState);

// send new power SCREEN state.
controlPanel.extenderWrite(LCD_BACKLIGHT, powerState);
// send new power SCREEN state.
controlPanel.extenderWrite(LCD_BACKLIGHT, powerState);
}

// function declarations
void setup()
{
Serial.begin(BAUD_RATE);
controlPanel.begin();

controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH);
tft.begin(0x9163); // ILI9163C

rightButton = new OneButton();
okButton = new OneButton();
upButton = new OneButton();
leftButton = new OneButton();
startButton = new OneButton();
downButton = new OneButton();
stopButton = new OneButton();
homeButton = new OneButton();

homeOkButton = new OneButton();

// Single buttons events
rightButton->attachClick(printClick, (void *)"right");
okButton->attachClick(printClick, (void *)"ok");
upButton->attachClick(printClick, (void *)"up");
leftButton->attachClick(printClick, (void *)"left");
startButton->attachClick(printClick, (void *)"start");
downButton->attachClick(printClick, (void *)"down");
stopButton->attachClick(printClick, (void *)"stop");
homeButton->attachClick(printClick, (void *)"home");
rightButton->attachClick(colorClick, (void *)TFT_LIGHTGREY);
okButton->attachClick(colorClick, (void *)TFT_BLUE);
upButton->attachClick(colorClick, (void *)TFT_ORANGE);
leftButton->attachClick(colorClick, (void *)TFT_MAGENTA);
startButton->attachClick(colorClick, (void *)TFT_GREEN);
downButton->attachClick(colorClick, (void *)TFT_PURPLE);
stopButton->attachClick(colorClick, (void *)TFT_RED);
homeButton->attachClick(colorClick, (void *)TFT_YELLOW);
homeButton->attachDoubleClick(printClick, (void *)"home x2");
homeButton->attachLongPressStop(printClick, (void *)"home long");

// Parallel buttons events
homeOkButton->attachClick(printClick, (void *)"home + ok");

powerButton.attachClick(printClick, (void *)"power");
powerButton.attachLongPressStop(togglePower);
Serial.begin(BAUD_RATE);
controlPanel.begin();

controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH);
tft.begin(0x9163); // ILI9163C

rightButton = new OneButton();
okButton = new OneButton();
upButton = new OneButton();
leftButton = new OneButton();
startButton = new OneButton();
downButton = new OneButton();
stopButton = new OneButton();
homeButton = new OneButton();

homeOkButton = new OneButton();

// Single buttons events
rightButton->attachClick(printClick, (void *)"right");
okButton->attachClick(printClick, (void *)"ok");
upButton->attachClick(printClick, (void *)"up");
leftButton->attachClick(printClick, (void *)"left");
startButton->attachClick(printClick, (void *)"start");
downButton->attachClick(printClick, (void *)"down");
stopButton->attachClick(printClick, (void *)"stop");
homeButton->attachClick(printClick, (void *)"home");

rightButton->attachClick(colorClick, (void *)TFT_LIGHTGREY);
okButton->attachClick(colorClick, (void *)TFT_BLUE);
upButton->attachClick(colorClick, (void *)TFT_ORANGE);
leftButton->attachClick(colorClick, (void *)TFT_MAGENTA);
startButton->attachClick(colorClick, (void *)TFT_GREEN);
downButton->attachClick(colorClick, (void *)TFT_PURPLE);
stopButton->attachClick(colorClick, (void *)TFT_RED);
homeButton->attachClick(colorClick, (void *)TFT_YELLOW);

homeButton->attachDoubleClick(printClick, (void *)"home x2");
homeButton->attachLongPressStop(printClick, (void *)"home long");

// Parallel buttons events
homeOkButton->attachClick(printClick, (void *)"home + ok");

powerButton.attachClick(printClick, (void *)"power");
powerButton.attachLongPressStop(togglePower);
}

void loop()
{
byte buttonsSequence = controlPanel.readButtons();
byte buttonsSequence = controlPanel.readButtons();

rightButton->tick(isButtonPressed(buttonsSequence, RIGHT));
okButton->tick(isButtonPressed(buttonsSequence, OK));
upButton->tick(isButtonPressed(buttonsSequence, UP));
leftButton->tick(isButtonPressed(buttonsSequence, LEFT));
startButton->tick(isButtonPressed(buttonsSequence, START));
downButton->tick(isButtonPressed(buttonsSequence, DOWN));
stopButton->tick(isButtonPressed(buttonsSequence, STOP));
homeButton->tick(isButtonPressed(buttonsSequence, HOME));
rightButton->tick(isButtonPressed(buttonsSequence, RIGHT));
okButton->tick(isButtonPressed(buttonsSequence, OK));
upButton->tick(isButtonPressed(buttonsSequence, UP));
leftButton->tick(isButtonPressed(buttonsSequence, LEFT));
startButton->tick(isButtonPressed(buttonsSequence, START));
downButton->tick(isButtonPressed(buttonsSequence, DOWN));
stopButton->tick(isButtonPressed(buttonsSequence, STOP));
homeButton->tick(isButtonPressed(buttonsSequence, HOME));

// Custom isButtonPressed bits manipulation
homeOkButton->tick(isButtonPressed(buttonsSequence, HOME) && isButtonPressed(buttonsSequence, OK));
// Custom isButtonPressed bits manipulation
homeOkButton->tick(isButtonPressed(buttonsSequence, HOME) && isButtonPressed(buttonsSequence, OK));

powerButton.tick();
powerButton.tick();

delay(50);
delay(50);
}
120 changes: 73 additions & 47 deletions extras/mcufriend_specials/MEGA_2560.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @author Xavier BRASSOUD ([email protected])
* @brief Based on MCUFRIEND_kbv special "USE_MEGA_8BIT_PORTC_SHIELD".
* Copy-paste this new special inside MCUFRIEND_kbv/utility/mcufriend_special.h
*
*
* Need explicit instantiation of Epson_PNL_CE02 as it's used here as extern member:
* Epson_PNL_CE02 controlPanel(...);
*
*
* See examples/display, or examples/full for complete usage.
*
*
* This special is adapted for a MEGA2560 with the following pin mapping:
* | Pin | Purpose | MEGA 2560 |
* |-----|-------------------------------------------|---------------|
Expand All @@ -26,15 +26,15 @@
* | 12 | GND | - |
* | 13 | LCD write (+3.3V !) | 49 ⚡ |
* | 14 | GND | - |
*
*
* ⚡ Require a 3.3v level-shifter, screen makes shadows and may be destroyed after long use.
* 🔺 Require a 10k pull-up resistor wired between 3.3V and Arduino pin
*
*
* @version 0.1
* @date 2024-02-13
*
*
* @copyright MIT license
*
*
*/

// Paste to the top of mcufriend_special.h
Expand Down Expand Up @@ -68,47 +68,73 @@ extern Epson_PNL_CE02 controlPanel;
#define RD_PORT UNUSED_PORT
#define RD_PIN -1

#define write_8(x) \
({ \
controlPanel.displayWrite(x); \
})
#define write_8(x) ({ controlPanel.displayWrite(x); })

#define read_8() ( PINC )
#define setWriteDir() { DDRC = 0xFF; }
#define setReadDir() { DDRC = 0x00; }
#define write8(x) { write_8(x); WR_ACTIVE; WR_STROBE; }
#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst) { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst) { RD_STROBE; dst = read_8(); RD_IDLE; RD_STROBE; dst = (dst<<8) | read_8(); RD_IDLE; }
#define read_8() (PINC)
#define setWriteDir() \
{ \
DDRC = 0xFF; \
}
#define setReadDir() \
{ \
DDRC = 0x00; \
}
#define write8(x) \
{ \
write_8(x); \
WR_ACTIVE; \
WR_STROBE; \
}
#define write16(x) \
{ \
uint8_t h = (x) >> 8, l = x; \
write8(h); \
write8(l); \
}
#define READ_8(dst) \
{ \
RD_STROBE; \
dst = read_8(); \
RD_IDLE; \
}
#define READ_16(dst) \
{ \
RD_STROBE; \
dst = read_8(); \
RD_IDLE; \
RD_STROBE; \
dst = (dst << 8) | read_8(); \
RD_IDLE; \
}

#define PIN_LOW(p, b) \
({ \
if (&p != &VIRTUAL_PORT) \
{ \
(p) &= ~(1 << (b)); \
} \
else \
{ \
controlPanel.extenderWrite((ExtenderPin)b, LOW); \
} \
})
#define PIN_LOW(p, b) \
({ \
if (&p != &VIRTUAL_PORT) \
{ \
(p) &= ~(1 << (b)); \
} \
else \
{ \
controlPanel.extenderWrite((ExtenderPin)b, LOW); \
} \
})

#define PIN_HIGH(p, b) \
({ \
if (&p != &VIRTUAL_PORT) \
{ \
(p) |= (1 << (b)); \
} \
else \
{ \
controlPanel.extenderWrite((ExtenderPin)b, HIGH); \
} \
})
#define PIN_HIGH(p, b) \
({ \
if (&p != &VIRTUAL_PORT) \
{ \
(p) |= (1 << (b)); \
} \
else \
{ \
controlPanel.extenderWrite((ExtenderPin)b, HIGH); \
} \
})

#define PIN_OUTPUT(p, b) \
({ \
if (&p != &VIRTUAL_PORT) \
{ \
*(&p - 1) |= (1 << (b)); \
} \
})
#define PIN_OUTPUT(p, b) \
({ \
if (&p != &VIRTUAL_PORT) \
{ \
*(&p - 1) |= (1 << (b)); \
} \
})
Loading

0 comments on commit 542ff89

Please sign in to comment.