From bb6dc6884496adba8850ec89e151b5349ff4b6da Mon Sep 17 00:00:00 2001 From: Xavier Brassoud Date: Thu, 2 May 2024 23:53:24 +0200 Subject: [PATCH] ci: Quality gates and release management (#4) * ci: Initialize CI pipelines Add release-please * Add Arduino, C++ and PR title linters * Test c++ linter * Remove matrix * Fix cpp lint style * Define .clang-format style * Clang format * Refactor: clang-tidy compliant * ci: cpp-linter adaptations * Provide action permissions * Move permissions * test permissions #2 * Test permissions #3 * Test permissions #4 * Ignore extras from quality Extras are written following external library conventions * Update clang-tidy version * Install Arduino CLI * Switch to PIO checks for consistency * Fix clang-tidy * Add clang-format * Add voluntary format error * clang-format * Fix release-please * Fix release-please missing files * Remove testing branch from release * Fix duplicate launched action: Quality Gates * Enhance PIO build process * Fix cast issues * Allow all architectures * Update example section * Add arduino-lint * Add CONTRIBUTING.md * Publish to PlatformIO Library manager * Switch Arduino lint to submit Switch back to "update" when approved by the Arduino Team * Rename scripts folder to pio-tools * Set lib_deps per example * Add sponsorship program * Shortened sentence in "using display" section --- .clang-format | 1 + .clang-tidy | 46 +++++++ .github/FUNDING.yml | 1 + .github/workflows/lint_git.yml | 20 +++ .github/workflows/quality.yml | 51 ++++++++ .github/workflows/release.yml | 50 ++++++++ .release-please-manifest.json | 3 + CONTRIBUTING.md | 17 +++ README.md | 113 ++++++++++------- REVERSE.md | 2 +- docs/pcb_layers.xcf | Bin 594642 -> 591311 bytes examples/blink/blink.ino | 28 ++--- examples/buttons/buttons.ino | 31 ++--- examples/display/display.ino | 32 +++-- examples/full/full.ino | 167 +++++++++++++------------- extras/mcufriend_specials/MEGA_2560.h | 118 ++++++++++-------- library.json | 54 ++++++++- library.properties | 6 +- pio-tools/inotocpp.py | 18 +++ platformio.ini | 44 +++++-- release-please-config.json | 21 ++++ src/Epson_PNL_CE02.cpp | 102 ++++++++-------- src/Epson_PNL_CE02.h | 107 ++++++++++++----- 23 files changed, 707 insertions(+), 325 deletions(-) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/lint_git.yml create mode 100644 .github/workflows/quality.yml create mode 100644 .github/workflows/release.yml create mode 100644 .release-please-manifest.json create mode 100644 CONTRIBUTING.md create mode 100644 pio-tools/inotocpp.py create mode 100644 release-please-config.json diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3e5f49c --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: Microsoft \ No newline at end of file diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..c887357 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,46 @@ +--- +Checks: > + -*, + clang-diagnostic-*, + clang-analyzer-*, + bugprone-*, + google-*, + cert-*-c, + misc-*, + performance-*, + portability-*, + readability-*, + modernize-*, + -modernize-use-trailing-return-type + +WarningsAsErrors: '' +AnalyzeTemporaryDtors: false +FormatStyle: file +HeaderFilterRegex: '' +CheckOptions: + - key: readability-identifier-naming.NamespaceCase + value: lower_case + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.StructCase + value: CamelCase + - key: readability-identifier-naming.UnionCase + value: CamelCase + - key: readability-identifier-naming.TemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.FunctionCase + value: camelBack + - key: readability-identifier-naming.VariableCase + value: camelBack + - key: readability-identifier-naming.PrivateMemberSuffix + value: _ + - key: readability-identifier-naming.ProtectedMemberSuffix + value: _ + - key: readability-identifier-naming.MacroDefinitionCase + value: UPPER_CASE + - key: readability-identifier-naming.ConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.PointerParameterCase + value: CamelCase + - key: readability-identifier-naming.PointerParameterPrefix + value: p \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..7ece582 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: paypal.me/XavierBrassoud \ No newline at end of file diff --git a/.github/workflows/lint_git.yml b/.github/workflows/lint_git.yml new file mode 100644 index 0000000..4dab2cd --- /dev/null +++ b/.github/workflows/lint_git.yml @@ -0,0 +1,20 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + lint-git: + name: Validate PR title + runs-on: ubuntu-22.04 + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100644 index 0000000..6741b71 --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,51 @@ +--- +name: Quality Gates + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: # Allows to trigger the workflow manually in GitHub UI + +permissions: + contents: write + pull-requests: write + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: arduino-lint + uses: arduino/arduino-lint-action@v1 + with: + library-manager: submit # TODO: swith to "update" when approved by the Arduino Team + compliance: strict + + - name: Code format + uses: jidicula/clang-format-action@v4.11.0 + with: + clang-format-version: '15' # equals to PIO clang version + check-path: 'src' + + - name: Cache pio and pip + uses: actions/cache@v3 + with: + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio + + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install PlatformIO Core + run: pip install --upgrade platformio + + - name: Code lint + run: pio check --fail-on-defect=high --fail-on-defect=medium diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fe29813 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +name: release-please + +jobs: + + release-please: + runs-on: ubuntu-22.04 + steps: + # Add packages to update into release-please-config.json + - name: Write new version to packages + uses: google-github-actions/release-please-action@v4 + with: + token: ${{ secrets.MAINTAINER_PAT }} + target-branch: ${{ github.ref_name }} + + # Steps bellow occurs only when a version is created + - uses: actions/checkout@v4 + if: ${{ steps.release.outputs.release_created }} + + - name: Cache pio and pip + if: ${{ steps.release.outputs.release_created }} + uses: actions/cache@v3 + with: + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio + + - uses: actions/setup-python@v4 + if: ${{ steps.release.outputs.release_created }} + with: + python-version: '3.9' + + - name: Install PlatformIO Core + if: ${{ steps.release.outputs.release_created }} + run: pip install --upgrade platformio + + - name: PlatformIO publish + if: ${{ steps.release.outputs.release_created }} + env: + PLATFORMIO_AUTH_TOKEN: ${{ secrets.PIO_PAT }} + run: pio package publish --type library --no-interactive diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..cd7caa8 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.0" +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..bc6d4b5 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,17 @@ +# Contribution Guidlines + +The best way to ask for help or propose a new idea is to [create a new issue](https://github.com/XavierBrassoud/Arduino_Epson_PNL_CE02/issues/new) while creating a Pull Request with your code changes allows you to share your own innovations with the rest of the community. + +The following are some guidelines to observe when creating issues or PRs: + +- Be friendly; it is important that we can all enjoy a safe space as we are all working on the same project and it is okay for people to have different ideas + +- [Use code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code); it helps us help you when we can read your code! On that note also refrain from pasting more than 30 lines of code in a post, instead [create a gist](https://gist.github.com/) if you need to share large snippets + +- Titles follows [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) (eg. *feat: My Awesome Feature*, *fix(topic): Something bad*) + +- Be detailed; refrain from mentioning code problems without sharing your source code and always give information regarding your board and version of the library + +- Ensure your code are properly formed with `clang-format` and passes quality gates with `pio checks` + +- Using [Visual Studio Code](https://code.visualstudio.com/) with the [PlatformIO](https://platformio.org/) [extension](https://platformio.org/install/ide?install=vscode) is highly recommended diff --git a/README.md b/README.md index 725493a..1780cd9 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Library to repurposing the control panel (PNL CE02) of EPSON XP 520/530/540 prin - [Let's play!](#lets-play) - [Using display](#using-display) - [Library documentation](#library-documentation) + - [Epson\_PNL\_CE02\_Pinout Struct](#epson_pnl_ce02_pinout-struct) - [Epson\_PNL\_CE02 Class](#epson_pnl_ce02-class) - [Constructor](#constructor) - [Functions](#functions) @@ -18,6 +19,7 @@ Library to repurposing the control panel (PNL CE02) of EPSON XP 520/530/540 prin - [ButtonMask](#buttonmask) - [ExtenderPin](#extenderpin) - [Credits](#credits) +- [Like this project? :heart:](#like-this-project-heart) ## Motivation @@ -41,9 +43,9 @@ Happy hacking! ## Hardware requirements - * Arduino (tested with Arduino MEGA 2560) - * FPC 14 pin 1.0mm adapter (avoid pads destroyed by soldering) - * Level shifter (5v to 3.3v) + * [Arduino](https://amzn.to/3y5obqz) (tested with Arduino MEGA 2560) + * [FPC 14 pin 1.0mm adapter](https://amzn.to/3wiy5EJ) (avoid pads destroyed by soldering) + * [Level shifter](https://amzn.to/3Qrx6ZL) (5v to 3.3v) * Control panel (PNL CE02) of EPSON XP 520/530/540 printers (obviously) ## Connecting the control panel @@ -81,20 +83,22 @@ Happy hacking! ``` c++ #include -enum -{ +Epson_PNL_CE02_Pinout pinout = { /* Control panel to Arduino pinout */ - EXTENDER_OE = 45, // FFC 1 - SERIAL_OUT = 50, // SPI MISO / FFC 2 - POWER_BUTTON = 46, // FFC 4 - LCD_RESET = 47, // FFC 6 - CLOCK = 52, // SPI SCK / FFC 9 - SERIAL_IN = 51, // SPI MOSI / FFC 10 - LATCH = 48, // FFC 11 - LCD_WRITE = 49, // FFC 13 + .EXTENDER_OE = 45, // FFC 1 + .SERIAL_OUT = 50, // SPI MISO / FFC 2 + .POWER_BUTTON = 46, // FFC 4 + .LCD_RESET = 47, // FFC 6 + .CLOCK = 52, // SPI SCK / FFC 9 + .SERIAL_IN = 51, // SPI MOSI / FFC 10 + .LATCH = 48, // FFC 11 + .LCD_WRITE = 49, // FFC 13 }; -Epson_PNL_CE02 controlPanel(EXTENDER_OE, SERIAL_OUT, POWER_BUTTON, LCD_RESET, CLOCK, SERIAL_IN, LATCH, LCD_WRITE); +Epson_PNL_CE02 controlPanel(&pinout); + +const byte OK = static_cast(ButtonMask::OK); +const byte HOME = static_cast(ButtonMask::HOME); void setup() { @@ -110,7 +114,7 @@ void loop() Serial.println("Button OK pressed!"); break; case OK | HOME: - Serial.println("Button OK and button LEFT pressed!"); + Serial.println("Button OK and button HOME pressed!"); break; } @@ -135,25 +139,29 @@ This library is not a GFX library. You can rely on [Adafruit GFX](https://github such as the excellent [MCUFRIEND_kbv](https://github.com/prenticedavid/MCUFRIEND_kbv) library. Here is an adaptation using [MCUFRIEND_kbv](https://github.com/prenticedavid/MCUFRIEND_kbv) library: -1. Download [MCUFRIEND_kbv v3](https://github.com/prenticedavid/MCUFRIEND_kbv) +1. Locate your [MCUFRIEND_kbv v3](https://github.com/prenticedavid/MCUFRIEND_kbv) library: + 1. [PlatformIO](https://platformio.org/) users: directly edit in `.pio/libdeps//MCUFRIEND_kbv` + 2. Other users: download [MCUFRIEND_kbv v3](https://github.com/prenticedavid/MCUFRIEND_kbv) 2. Edit *MCUFRIEND_kbv/utility/mcufriend_shield.h*: 1. Uncomment `#define USE_SPECIAL` - 2. Uncomment `#define SUPPORT_9163` 3. Edit *MCUFRIEND_kbv/MCUFRIEND_kbv.cpp*: - 1. Go to `#ifdef SUPPORT_9163` section - 2. Replace `*p16 = 160;` by `*p16 = 128;` -5. Edit *MCUFRIEND_kbv/utility/mcufriend_special.h*: + 1. Uncomment `#define SUPPORT_9163` + 2. Go to `#ifdef SUPPORT_9163` section + 3. Replace `*p16 = 160;` by `*p16 = 128;` +4. Edit *MCUFRIEND_kbv/utility/mcufriend_special.h*: 1. Write to the top of mcufriend_special.h `#define USE_EPSON_PNL_CE02` 2. Copy content from *extras/mcufriend_specials/.h* file 3. Paste to the SPECIAL definitions of *mcufriend_special.h*, somewhere between `#if` and `#else` -6. Your code requires: +5. Your code requires: 1. Definition for `Epson_PNL_CE02 controlPanel(...)` 2. Turn display ON before INIT: ``` c++ - controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH); + controlPanel.extenderWrite(ExtenderPin::LCD_BACKLIGHT, HIGH); tft.begin(0x9163); ``` +`examples/display` and `examples/full` depend on the adaptation above. + [examples/display]([examples/display/display.ino]): ``` c++ @@ -161,20 +169,19 @@ Here is an adaptation using [MCUFRIEND_kbv](https://github.com/prenticedavid/MCU #include #include -enum -{ +Epson_PNL_CE02_Pinout pinout = { /* Control panel to Arduino pinout */ - EXTENDER_OE = 45, // FFC 1 - SERIAL_OUT = 50, // SPI MISO / FFC 2 - POWER_BUTTON = 46, // FFC 4 - LCD_RESET = 47, // FFC 6 - CLOCK = 52, // SPI SCK / FFC 9 - SERIAL_IN = 51, // SPI MOSI / FFC 10 - LATCH = 48, // FFC 11 - LCD_WRITE = 49, // FFC 13 + .EXTENDER_OE = 45, // FFC 1 + .SERIAL_OUT = 50, // SPI MISO / FFC 2 + .POWER_BUTTON = 46, // FFC 4 + .LCD_RESET = 47, // FFC 6 + .CLOCK = 52, // SPI SCK / FFC 9 + .SERIAL_IN = 51, // SPI MOSI / FFC 10 + .LATCH = 48, // FFC 11 + .LCD_WRITE = 49, // FFC 13 }; -Epson_PNL_CE02 controlPanel(EXTENDER_OE, SERIAL_OUT, POWER_BUTTON, LCD_RESET, CLOCK, SERIAL_IN, LATCH, LCD_WRITE); +Epson_PNL_CE02 controlPanel(&pinout); MCUFRIEND_kbv tft; @@ -183,10 +190,10 @@ void setup() controlPanel.begin(); // STEP 1: Turn display ON - controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH); + controlPanel.extenderWrite(ExtenderPin::LCD_BACKLIGHT, HIGH); // STEP 2: INIT display - tft.begin(0x9163); // ILI9163C + tft.begin(0x9163); // Force ILI9163C as the control panel wired the display in write-only mode // STEP 3: Use display tft.fillScreen(TFT_RED); @@ -204,21 +211,26 @@ void loop() ## Library documentation +### Epson_PNL_CE02_Pinout Struct + +| Member | Pin | Description | +| ---------------- | --- | ---------------------------------------------------------------------- | +| `EXTENDER_OE` | #1 | Extender output enable pin. Unused. | +| `SERIAL_OUT` | #2 | Serial output pin. Read value for buttons. (SPI MISO) | +| `POWER_BUTTON` | #4 | Dedicated pin for the power button. | +| `LCD_RESET` | #6 | Display reset pin. Refer to ["Using display"](#using-display) section. | +| `CLOCK` | #9 | Shared clock pin for extender, buttons and display. (SPI SCK) | +| `SERIAL_IN` | #10 | Serial input pin. Write value in extender. (SPI MOSI) | +| `LATCH` | #11 | Write extender selector. | +| `LCD_WRITE` | #13 | Display write pin. Refer to ["Using display"](#using-display) section. | ### Epson_PNL_CE02 Class #### Constructor -| Parameter | Description | -| ---------------- | ------------------------------------------------------------- | -| `oePin` | Extender output enable pin. Unused. | -| `serOutPin` | Serial output pin. Read value for buttons. (SPI MISO) | -| `powerButtonPin` | Dedicated pin for the power button. | -| `lcdResetPin` | Display reset pin. | -| `clockPin` | Shared clock pin for extender, buttons and display. (SPI SCK) | -| `serInPin` | Serial input pin. Write value in extender. (SPI MOSI) | -| `latchPin` | Write extender selector. | -| `lcdWritePin` | Display write pin. | +| Parameter | Description | +| ---------------- | ---------------------------------------------------------------------- | +| `pPinout` | Reference to [`Epson_PNL_CE02_Pinout`](#epson_pnl_ce02_pinout-struct). | #### Functions @@ -271,3 +283,14 @@ Examples uses: And... EPSON for the control panel 😉 + + +## Like this project? :heart: + +:star: [Star this project](https://github.com/XavierBrassoud/Arduino_Epson_PNL_CE02/star) to provide better visibility to the community! + +:computer: Support this project by purchasing [affiliated hardwares](https://amzn.to/3y5obqz) + +:coffee: [Buy me a coffee](paypal.me/XavierBrassoud) + +Thank you! diff --git a/REVERSE.md b/REVERSE.md index 130b178..4b74e31 100644 --- a/REVERSE.md +++ b/REVERSE.md @@ -22,7 +22,7 @@ We can identify 3 components, from left to right: ## Identifying display -This was the hard part of this project. The only reference was GIANTPLUS printed on the flex ribbon cable of the screen. After hours of searching, I can't identify this screen. +This was the hard part of this project. The only reference was "307328101 GIANTPLUS 1526" printed on the flex ribbon cable of the screen. After hours of searching, I can't identify this screen. The deducted information was: * the 8-bit parallel interface wired through the VHC164 diff --git a/docs/pcb_layers.xcf b/docs/pcb_layers.xcf index fe6b376d380a188279b89cb2f6b6eb6c93dc1752..d8f6cd3bcc45066c7851e43463e4c7f8bc59842c 100644 GIT binary patch delta 14205 zcmZA833N`^`p5CJGpkwJgv1atHBUhek%SU6F>3`?6h%it>(#nSqC#(EG%KZMf+$)M zLscnC1vO7G57%^c;GT1S-@DfT{kk<;0$H((7_|MY-gz{HC$o8Y#D5mZw+9bA{!Ir|b2XKgzk9 z%9~}iP#KjX+l0&Eh2)3?nW+hx`4bf9EtkLh%KLR)?O(~=8V4r-UHF-KYX2?d)uPRG zAZ$9$!9}a`B){QG+g2xoQ*6@iF1krb$=_cCUGoko>t&uViq{?p5m8- zumuir^;j>@U|=I2!$0IJ<*^-(!BqSnugIW+SRec1WYj`hLBBY$$FhPR>p*a6jK&ej z1cRAi@F|U#6jsTq#GUb>EHxe%;g3ivg}h?N_WiAp<~k7a7AE2bJc%!4Xc)G|(WsQN zLU$08o26e;T)G~zC1va_aqe%GVNc3vPpmRLaT%Vt3{PBEpSQ~L#ASKnvTRA&nL45D zD*OraWjS)ETt(tYtBd=$a&ZiNigWQh%tN*+EKqS6PZXxhSYhvGE$-CPFRO3KnFUO~ zTMiX!=+tm;EQ;iPIL{K^z%7T$1$DSG*;BbM@nl?%zaTTJLh@9J)_4_?r^;8vTk*WC z>W8(khpWe`I+1}TxEpWEYQ?b$vUJtHAYOyV@lW|GOID+i;u>$@6kO?Or$ddS4E$Tx zEQfT&n!|{ba5J8fwOHs{uM&5|cwC74@Q$qgvaNl8t9CO6Xw9|N5v|&E)Y>FN?dLkL z4il`y1na!ZIE}B)cH&F2ZULl&)+3AS+gs(_->T1E)jzKj8~7o6)j)e?HDIe6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#cQ>0 z(wOxKR4rJoPo?t}hqa;llQp0DZ1ZK!_YRy7x4sj;b*M+q}J`EHo z51T;cy0yS-=oyfXSU?$MEkFhpxT|rW02s)((H`k>!}ZT}_y=A1J;iFq|1a?1Uo`vQSdaZbo)Eur(VuvY{l7V+{z4b* zzd8;7?Sp<5*2honMc$v-F*sk#J(Y{OFLSY6h;L9eZo%(1|2cR0 -enum -{ +Epson_PNL_CE02_Pinout pinout = { /* Control panel to Arduino pinout */ - EXTENDER_OE = 45, // FFC 1 - SERIAL_OUT = 50, // SPI MISO / FFC 2 - POWER_BUTTON = 46, // FFC 4 - LCD_RESET = 47, // FFC 6 - CLOCK = 52, // SPI SCK / FFC 9 - SERIAL_IN = 51, // SPI MOSI / FFC 10 - LATCH = 48, // FFC 11 - LCD_WRITE = 49, // FFC 13 + .EXTENDER_OE = 45, // FFC 1 + .SERIAL_OUT = 50, // SPI MISO / FFC 2 + .POWER_BUTTON = 46, // FFC 4 + .LCD_RESET = 47, // FFC 6 + .CLOCK = 52, // SPI SCK / FFC 9 + .SERIAL_IN = 51, // SPI MOSI / FFC 10 + .LATCH = 48, // FFC 11 + .LCD_WRITE = 49, // FFC 13 }; -Epson_PNL_CE02 controlPanel(EXTENDER_OE, SERIAL_OUT, POWER_BUTTON, LCD_RESET, CLOCK, SERIAL_IN, LATCH, LCD_WRITE); +Epson_PNL_CE02 controlPanel(&pinout); void setup() { @@ -53,12 +51,12 @@ void setup() void loop() { // turns ON power LED (active LOW) - controlPanel.extenderWrite(POWER_LED, LOW); + controlPanel.extenderWrite(ExtenderPin::POWER_LED, LOW); delay(1000); // turns OFF power LED - controlPanel.extenderWrite(POWER_LED, HIGH); + controlPanel.extenderWrite(ExtenderPin::POWER_LED, HIGH); delay(1000); } \ No newline at end of file diff --git a/examples/buttons/buttons.ino b/examples/buttons/buttons.ino index 4b5f598..7a56835 100644 --- a/examples/buttons/buttons.ino +++ b/examples/buttons/buttons.ino @@ -4,7 +4,6 @@ * @brief A basic buttons playground using Epson_PNL_CE02 library. * Get an advanced usage of buttons in the OneButton sketch. * @version 1.0 - * @date 2023-12-22 * * @copyright MIT license * @@ -24,33 +23,35 @@ * | 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 -enum -{ +Epson_PNL_CE02_Pinout pinout = { /* Control panel to Arduino pinout */ - EXTENDER_OE = 45, // FFC 1 - SERIAL_OUT = 50, // SPI MISO / FFC 2 - POWER_BUTTON = 46, // FFC 4 - LCD_RESET = 47, // FFC 6 - CLOCK = 52, // SPI SCK / FFC 9 - SERIAL_IN = 51, // SPI MOSI / FFC 10 - LATCH = 48, // FFC 11 - LCD_WRITE = 49, // FFC 13 + .EXTENDER_OE = 45, // FFC 1 + .SERIAL_OUT = 50, // SPI MISO / FFC 2 + .POWER_BUTTON = 46, // FFC 4 + .LCD_RESET = 47, // FFC 6 + .CLOCK = 52, // SPI SCK / FFC 9 + .SERIAL_IN = 51, // SPI MOSI / FFC 10 + .LATCH = 48, // FFC 11 + .LCD_WRITE = 49, // FFC 13 }; -Epson_PNL_CE02 controlPanel(EXTENDER_OE, SERIAL_OUT, POWER_BUTTON, LCD_RESET, CLOCK, SERIAL_IN, LATCH, LCD_WRITE); +Epson_PNL_CE02 controlPanel(&pinout); + +const byte OK = static_cast(ButtonMask::OK); +const byte HOME = static_cast(ButtonMask::HOME); void setup() { diff --git a/examples/display/display.ino b/examples/display/display.ino index 1a89ce9..b23730f 100644 --- a/examples/display/display.ino +++ b/examples/display/display.ino @@ -6,10 +6,9 @@ * parallel interface. * This sketch running only on Arduino MEGA 2560. * @version 1.0 - * @date 2023-12-28 * * @copyright MIT license - * + * * | Pin | Purpose | MEGA 2560 | * |-----|-------------------------------------------|---------------| * | 1 | 3-STATE Output Enable Input (OE) | 45 | @@ -26,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*: @@ -49,26 +48,25 @@ * ``` c++ * controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH); * tft.begin(0x9163); - * + * */ #include /****************************** Epson_PNL_CE02 *******************************/ -enum -{ +Epson_PNL_CE02_Pinout pinout = { /* Control panel to Arduino pinout */ - EXTENDER_OE = 45, // FFC 1 - SERIAL_OUT = 50, // SPI MISO / FFC 2 - POWER_BUTTON = 46, // FFC 4 - LCD_RESET = 47, // FFC 6 - CLOCK = 52, // SPI SCK / FFC 9 - SERIAL_IN = 51, // SPI MOSI / FFC 10 - LATCH = 48, // FFC 11 - LCD_WRITE = 49, // FFC 13 + .EXTENDER_OE = 45, // FFC 1 + .SERIAL_OUT = 50, // SPI MISO / FFC 2 + .POWER_BUTTON = 46, // FFC 4 + .LCD_RESET = 47, // FFC 6 + .CLOCK = 52, // SPI SCK / FFC 9 + .SERIAL_IN = 51, // SPI MOSI / FFC 10 + .LATCH = 48, // FFC 11 + .LCD_WRITE = 49, // FFC 13 }; -Epson_PNL_CE02 controlPanel(EXTENDER_OE, SERIAL_OUT, POWER_BUTTON, LCD_RESET, CLOCK, SERIAL_IN, LATCH, LCD_WRITE); +Epson_PNL_CE02 controlPanel(&pinout); /******************************* MCUFRIEND_kbv *******************************/ @@ -89,7 +87,7 @@ void setup() controlPanel.begin(); // STEP 1: Turn display ON - controlPanel.extenderWrite(LCD_BACKLIGHT, HIGH); + controlPanel.extenderWrite(ExtenderPin::LCD_BACKLIGHT, HIGH); // STEP 2: INIT display tft.begin(0x9163); // Force ILI9163C as the control panel wired the display in write-only mode diff --git a/examples/full/full.ino b/examples/full/full.ino index d6fde4a..d00bee3 100644 --- a/examples/full/full.ino +++ b/examples/full/full.ino @@ -4,7 +4,6 @@ * @brief Full playground using Epson_PNL_CE02 library with OneButton library * and MCUFRIEND_kbv. See "display" example to wire the display correctly. * @version 1.0 - * @date 2023-12-22 * * @copyright MIT license * @@ -24,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 @@ -43,20 +42,19 @@ #include -enum -{ +Epson_PNL_CE02_Pinout pinout = { /* Control panel to Arduino pinout */ - EXTENDER_OE = 45, // FFC 1 - SERIAL_OUT = 50, // SPI MISO / FFC 2 - POWER_BUTTON = 46, // FFC 4 - LCD_RESET = 47, // FFC 6 - CLOCK = 52, // SPI SCK / FFC 9 - SERIAL_IN = 51, // SPI MOSI / FFC 10 - LATCH = 48, // FFC 11 - LCD_WRITE = 49, // FFC 13 + .EXTENDER_OE = 45, // FFC 1 + .SERIAL_OUT = 50, // SPI MISO / FFC 2 + .POWER_BUTTON = 46, // FFC 4 + .LCD_RESET = 47, // FFC 6 + .CLOCK = 52, // SPI SCK / FFC 9 + .SERIAL_IN = 51, // SPI MOSI / FFC 10 + .LATCH = 48, // FFC 11 + .LCD_WRITE = 49, // FFC 13 }; -Epson_PNL_CE02 controlPanel(EXTENDER_OE, SERIAL_OUT, POWER_BUTTON, LCD_RESET, CLOCK, SERIAL_IN, LATCH, LCD_WRITE); +Epson_PNL_CE02 controlPanel(&pinout); /******************************* MCUFRIEND_kbv *******************************/ @@ -86,100 +84,101 @@ OneButton *homeButton; OneButton *homeOkButton; // Power button has a dedicated pin -OneButton powerButton(POWER_BUTTON); +OneButton powerButton(pinout.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(ExtenderPin::POWER_LED, !powerState); - // send new power SCREEN state. - controlPanel.extenderWrite(LCD_BACKLIGHT, powerState); + // send new power SCREEN state. + controlPanel.extenderWrite(ExtenderPin::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(ExtenderPin::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, ButtonMask::RIGHT)); + okButton->tick(isButtonPressed(buttonsSequence, ButtonMask::OK)); + upButton->tick(isButtonPressed(buttonsSequence, ButtonMask::UP)); + leftButton->tick(isButtonPressed(buttonsSequence, ButtonMask::LEFT)); + startButton->tick(isButtonPressed(buttonsSequence, ButtonMask::START)); + downButton->tick(isButtonPressed(buttonsSequence, ButtonMask::DOWN)); + stopButton->tick(isButtonPressed(buttonsSequence, ButtonMask::STOP)); + homeButton->tick(isButtonPressed(buttonsSequence, ButtonMask::HOME)); - // Custom isButtonPressed bits manipulation - homeOkButton->tick(isButtonPressed(buttonsSequence, HOME) && isButtonPressed(buttonsSequence, OK)); + // Custom isButtonPressed bits manipulation + homeOkButton->tick(isButtonPressed(buttonsSequence, ButtonMask::HOME) && + isButtonPressed(buttonsSequence, ButtonMask::OK)); - powerButton.tick(); + powerButton.tick(); - delay(50); + delay(50); } diff --git a/extras/mcufriend_specials/MEGA_2560.h b/extras/mcufriend_specials/MEGA_2560.h index 499a845..e4b5616 100644 --- a/extras/mcufriend_specials/MEGA_2560.h +++ b/extras/mcufriend_specials/MEGA_2560.h @@ -3,12 +3,12 @@ * @author Xavier BRASSOUD (contact@xavierbrassoud.fr) * @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 | * |-----|-------------------------------------------|---------------| @@ -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 @@ -60,55 +60,75 @@ extern Epson_PNL_CE02 controlPanel; #define VIRTUAL_PORT _MMIO_BYTE(0XFF) // Set Virtual Port for PIN_ methods #define CD_PORT VIRTUAL_PORT -#define CD_PIN LCD_DC // D4 VHC595 +#define CD_PIN static_cast(ExtenderPin::LCD_DC) // D4 VHC595 #define CS_PORT VIRTUAL_PORT -#define CS_PIN LCD_CS // D3 VHC595 +#define CS_PIN static_cast(ExtenderPin::LCD_CS) // D3 VHC595 #define UNUSED_PORT _MMIO_BYTE(0XFE) // Disable READ methods as the control panel wired the display in write-only mode #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)); \ + } \ + }) diff --git a/library.json b/library.json index c7d2094..ffa2f23 100644 --- a/library.json +++ b/library.json @@ -21,16 +21,58 @@ "platforms": "*", "examples": [ { - "name": "CE02test", - "base": "examples/OneButton", + "name": "blink", + "base": "examples/blink", "files": [ + "platformio.ini", "src/Epson_PNL_CE02.h", "src/Epson_PNL_CE02.cpp", - "OneButton.cpp" + "blink.ino" + ] + }, + { + "name": "buttons", + "base": "examples/buttons", + "files": [ + "platformio.ini", + "src/Epson_PNL_CE02.h", + "src/Epson_PNL_CE02.cpp", + "buttons.ino" + ] + }, + { + "name": "display", + "base": "examples/display", + "files": [ + "platformio.ini", + "src/Epson_PNL_CE02.h", + "src/Epson_PNL_CE02.cpp", + "display.ino" + ], + "dependencies": { + "prenticedavid/MCUFRIEND_kbv": "^3", + "adafruit/Adafruit GFX Library": "^1", + "adafruit/Adafruit BusIO": "^1", + "Wire": "*", + "SPI": "*" + } + }, + { + "name": "buttons", + "base": "examples/full", + "files": [ + "platformio.ini", + "src/Epson_PNL_CE02.h", + "src/Epson_PNL_CE02.cpp", + "full.ino" ], - "dependencies": - { - "mathertel/OneButton": "^2.5.0" + "dependencies": { + "mathertel/OneButton": "^2.5.0", + "prenticedavid/MCUFRIEND_kbv": "^3", + "adafruit/Adafruit GFX Library": "^1", + "adafruit/Adafruit BusIO": "^1", + "Wire": "*", + "SPI": "*" } } ] diff --git a/library.properties b/library.properties index 274955e..ecf8a74 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,11 @@ name=Epson_PNL_CE02 -version=0.0.0 author=Xavier BRASSOUD maintainer=Xavier BRASSOUD sentence=Library to repurposing the control panel (PNL CE02) of EPSON XP 520/530/540 printers from an Arduino. paragraph=Supports buttons inputs and screen display. category=Display url=https://github.com/XavierBrassoud/Arduino_Epson_PNL_CE02 -architectures=avr \ No newline at end of file +architectures=* +# x-release-please-start-version +version=0.0.0 +# x-release-please-end \ No newline at end of file diff --git a/pio-tools/inotocpp.py b/pio-tools/inotocpp.py new file mode 100644 index 0000000..6c417b6 --- /dev/null +++ b/pio-tools/inotocpp.py @@ -0,0 +1,18 @@ +# PlatformIO convert only the first INO files found in src folder. +# This implementation convert only the first INO files found in custom_example_dir. +# +# Refer to: https://github.com/platformio/platformio-core/issues/4730#issuecomment-1836004680 +# Xavier BRASSOUD - v1.0 + + +import glob +import os + +Import("env") + +def FindInoNodes(env): + project_dir = glob.escape(env.subst("$PROJECT_DIR")) + example_dir = env.GetProjectOption("custom_example_dir") + return env.Glob(os.path.join(project_dir, f"{example_dir}/*.ino")) + +env.AddMethod(FindInoNodes) diff --git a/platformio.ini b/platformio.ini index 79c6498..b823cf8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,25 +8,45 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[platformio] -lib_dir = src ;This points to the library sources itself -src_dir = examples/full ;this points to a single example *.ino sketch which includes the setup/loop functions - -[env:megaatmega2560] +[env] platform = atmelavr board = megaatmega2560 framework = arduino +check_tool = cppcheck, clangtidy +check_flags = + clangtidy: --config-file=.clang-tidy monitor_speed = 115200 -custom_example = examples/full -lib_extra_dirs = . ;this points to the root directory where the arduino library is located + +build_flags = -I src + +extra_scripts = pre:pio-tools/inotocpp.py ; refer to: https://github.com/platformio/platformio-core/issues/4730#issuecomment-1836004680 +custom_example_dir = examples +build_src_filter = + +<.> + +<../${env.custom_example_dir}> + +[env:example_blink] +custom_example_dir = examples/blink + +[env:example_buttons] +custom_example_dir = examples/buttons + +[env:example_display] +custom_example_dir = examples/display +lib_deps = + prenticedavid/MCUFRIEND_kbv @ ^3 + adafruit/Adafruit GFX Library @ ^1 + adafruit/Adafruit BusIO @ ^1 + Wire + SPI + +[env:example_full] +custom_example_dir = examples/full lib_deps = - ; Sketch example OneButton depends on the latest 2.x stable version of OneButton. - ; The minimum required version is 2.5.0. mathertel/OneButton @ ^2.5.0 - ; Display depends on the latest 3.x stable version of TFT_eSPI. - ; The minimum required version is 3.0.0 prenticedavid/MCUFRIEND_kbv @ ^3 adafruit/Adafruit GFX Library @ ^1 adafruit/Adafruit BusIO @ ^1 Wire - SPI \ No newline at end of file + SPI + \ No newline at end of file diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..07ce439 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,21 @@ +{ + "packages": { + ".": { + "changelog-path": "CHANGELOG.md", + "release-type": "simple", + "draft": false, + "prerelease": false, + "extra-files": [ + "library.properties", + { + "type": "json", + "path": "library.json", + "jsonpath": "$.version" + }, + "src/Epson_PNL_CE02.h", + "src/Epson_PNL_CE02.cpp" + ] + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} \ No newline at end of file diff --git a/src/Epson_PNL_CE02.cpp b/src/Epson_PNL_CE02.cpp index 45e9899..f373856 100644 --- a/src/Epson_PNL_CE02.cpp +++ b/src/Epson_PNL_CE02.cpp @@ -1,5 +1,5 @@ /** - * @file Epson_PNL_CE02.h + * @file Epson_PNL_CE02.cpp * @author Xavier BRASSOUD (contact@xavierbrassoud.fr) * @brief Library to repurposing the control panel (PNL CE02) of EPSON XP 520/530/540 * printers from an Arduino. @@ -27,82 +27,85 @@ * | 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.0 - * @date 2023-12-22 + * @version 0.0.0 # x-release-please-version * * @copyright MIT license */ +#include "Epson_PNL_CE02.h" #include #include -#include -#include "Epson_PNL_CE02.h" - -const char *buttonNames[8] = { - "Right", - "Ok", - "Up", - "Left", - "Start", - "Down", - "Stop", - "Home", -}; // UTILS -const char *buttonName(ButtonMask flag) +// cppcheck-suppress unusedFunction +const char *buttonName(ButtonMask mask) { - const double bitPos = log(flag) / log(2); - return buttonNames[(int)bitPos]; + switch (mask) + { + case ButtonMask::RIGHT: + return "Right"; + case ButtonMask::OK: + return "Ok"; + case ButtonMask::UP: + return "Up"; + case ButtonMask::LEFT: + return "Left"; + case ButtonMask::START: + return "Start"; + case ButtonMask::DOWN: + return "Down"; + case ButtonMask::STOP: + return "Stop"; + case ButtonMask::HOME: + return "Home"; + } + return "Unknown"; } -const bool isButtonPressed(byte sequence, ButtonMask flag) +// cppcheck-suppress unusedFunction +bool isButtonPressed(byte sequence, ButtonMask mask) { - return (sequence & flag) != 0; // Check if key pressed 0000{key}000, key>0 if set + return (sequence & static_cast(mask)) != 0; // Check if key pressed 0000{key}000, key>0 if set } // CTOR -Epson_PNL_CE02::Epson_PNL_CE02(int oePin, int serOutPin, int powerButtonPin, int lcdResetPin, int clockPin, int serInPin, int latchPin, int lcdWritePin) +Epson_PNL_CE02::Epson_PNL_CE02(Epson_PNL_CE02_Pinout *pPinout) : pins(pPinout) { - Epson_PNL_CE02::oePin = oePin; - Epson_PNL_CE02::serOutPin = serOutPin; - Epson_PNL_CE02::powerButtonPin = powerButtonPin; - Epson_PNL_CE02::clockPin = clockPin; - Epson_PNL_CE02::serInPin = serInPin; - Epson_PNL_CE02::latchPin = latchPin; } // PUBLICS -void Epson_PNL_CE02::begin() +void Epson_PNL_CE02::begin() const { - pinMode(powerButtonPin, INPUT); + pinMode(pins->POWER_BUTTON, INPUT); - pinMode(oePin, OUTPUT); - pinMode(latchPin, OUTPUT); - pinMode(clockPin, OUTPUT); - pinMode(serInPin, OUTPUT); - pinMode(serOutPin, INPUT); + pinMode(pins->EXTENDER_OE, OUTPUT); + pinMode(pins->LATCH, OUTPUT); + pinMode(pins->CLOCK, OUTPUT); + pinMode(pins->SERIAL_IN, OUTPUT); + pinMode(pins->SERIAL_OUT, INPUT); - SPI.begin(); - SPI.beginTransaction(SPISettings(F_CPU / 2, MSBFIRST, SPI_MODE0)); // Max SPI speed + SPIClass::begin(); + SPIClass::beginTransaction(SPISettings(F_CPU / 2, MSBFIRST, SPI_MODE0)); // Max SPI speed - digitalWrite(oePin, LOW); + digitalWrite(pins->EXTENDER_OE, LOW); } +// cppcheck-suppress unusedFunction void Epson_PNL_CE02::extenderWrite(ExtenderPin pin, byte mode) { - bitWrite(buffer, pin, mode); + bitWrite(buffer, (byte)pin, mode); synchronize(); } +// cppcheck-suppress unusedFunction void Epson_PNL_CE02::displayWrite(byte data) { - SPI.transfer(data); + SPIClass::transfer(data); } byte Epson_PNL_CE02::readButtons() @@ -110,20 +113,21 @@ byte Epson_PNL_CE02::readButtons() return synchronize(); } -bool Epson_PNL_CE02::isPowerButtonPressed() +// cppcheck-suppress unusedFunction +bool Epson_PNL_CE02::isPowerButtonPressed() const { - return digitalRead(powerButtonPin) == LOW; + return digitalRead(pins->POWER_BUTTON) == LOW; } // PRIVATES - -byte Epson_PNL_CE02::synchronize() +byte Epson_PNL_CE02::synchronize() const { // STEP 1: Send control information (Power LED, LCD backlight, LCD CS, LCD D/C) through 74HC595 - digitalWrite(latchPin, LOW); // enables parallel inputs - SPI.transfer(buffer); + digitalWrite(pins->LATCH, LOW); // enables parallel inputs + SPIClass::transfer(buffer); // STEP 2: Receive buttons inputs through 74LV165A - digitalWrite(latchPin, HIGH); // disable parallel inputs and enable serial output + digitalWrite(pins->LATCH, HIGH); // disable parallel inputs and enable serial output - return 0b11111111 ^ SPI.transfer(0xff); // read buttons (invert cause output is HIGH) + const byte FULL_MASK = 0b11111111; + return FULL_MASK ^ SPIClass::transfer(FULL_MASK); // read buttons (invert cause output is HIGH) } diff --git a/src/Epson_PNL_CE02.h b/src/Epson_PNL_CE02.h index d1b2afd..f2dd183 100644 --- a/src/Epson_PNL_CE02.h +++ b/src/Epson_PNL_CE02.h @@ -27,26 +27,25 @@ * | 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.0 - * @date 2023-12-22 + * @version 0.0.0 # x-release-please-version * * @copyright MIT license */ -#ifndef Epson_PNL_CE02_H -#define Epson_PNL_CE02_H +#ifndef EPSON_PNL_CE02_H +#define EPSON_PNL_CE02_H #include /** * @brief Buttons 8-bit mapping. */ -enum ButtonMask +enum class ButtonMask : byte // NOLINT(readability-identifier-naming): Bug clangtidy v15: enum detected as variable { RIGHT = 0b10000000, // 0b11111110 OK = 0b01000000, // 0b11111101 @@ -61,7 +60,7 @@ enum ButtonMask /** * @brief Shift register pins (VHC595) */ -enum ExtenderPin +enum class ExtenderPin : byte // NOLINT(readability-identifier-naming): Bug clangtidy v15: enum detected as variable { /** * @brief Control the state of the power led (active LOW). @@ -74,12 +73,12 @@ enum ExtenderPin LCD_BACKLIGHT = 6, /** - * @brief Control the state of the display CS pin (ChipSelect, active HIGH). + * @brief Control the state of the display ChipSelect pin (active HIGH). */ LCD_CS = 5, /** - * @brief Control the state of the display D/C pin (Data / Command, active HIGH). + * @brief Control the state of the display Data/Command pin (active HIGH). */ LCD_DC = 4 }; @@ -100,7 +99,63 @@ const char *buttonName(ButtonMask mask); * @return true * @return false */ -const bool isButtonPressed(byte sequence, ButtonMask mask); +bool isButtonPressed(byte sequence, ButtonMask mask); + +/** + * @brief Control panel to Arduino pinout. + * + */ +struct Epson_PNL_CE02_Pinout +{ + + /** + * @brief [UNUSED] Extender output enable pin. + * Pin #1 + */ + const byte EXTENDER_OE; + + /** + * @brief Serial output pin. Read value for buttons. (SPI MISO) + * Pin #2 + */ + const byte SERIAL_OUT; + + /** + * @brief Dedicated pin for the power button. + * Pin #4 + */ + const byte POWER_BUTTON; + + /** + * @brief Display reset pin. Refer to "Using display" section. + * Pin #6 + */ + const byte LCD_RESET; + + /** + * @brief Shared clock pin for extender, buttons and display. (SPI SCK) + * Pin #9 + */ + const byte CLOCK; + + /** + * @brief Serial input pin. Write value in extender. (SPI MOSI) + * Pin #10 + */ + const byte SERIAL_IN; + + /** + * @brief Write extender selector. + * Pin #11 + */ + const byte LATCH; + + /** + * @brief Display write pin. Refer to "Using display" section. + * Pin #13 + */ + const byte LCD_WRITE; +}; /** * @brief Board class controller. @@ -118,28 +173,21 @@ const bool isButtonPressed(byte sequence, ButtonMask mask); * } * ``` */ -class Epson_PNL_CE02 +class Epson_PNL_CE02 // NOLINT(readability-identifier-naming): Exception to follow common Arduino Library style naming { -public: + public: /** * @brief Construct a new Epson_PNL_CE02 object * - * @param oePin Extender output enable pin. Unused. - * @param serOutPin Serial output pin. Read value for buttons. (SPI MISO) - * @param powerButtonPin Dedicated pin for the power button. - * @param lcdResetPin Display reset pin. - * @param clockPin Shared clock pin for extender, buttons and display. (SPI SCK) - * @param serInPin Serial input pin. Write value in extender. (SPI MOSI) - * @param latchPin Write extender selector. - * @param lcdWritePin Display write pin. + * @param pPinout Reference to Epson_PNL_CE02_Pinout structure. */ - Epson_PNL_CE02(int oePin, int serOutPin, int powerButtonPin, int lcdResetPin, int clockPin, int serInPin, int latchPin, int lcdWritePin); + explicit Epson_PNL_CE02(Epson_PNL_CE02_Pinout *pPinout); /** * @brief Set pins directions and initialize SPI bus. */ - void begin(); + void begin() const; /** * @brief Send a HIGH or a LOW value to the control panel extender pin (refer to ExtenderPin). @@ -154,7 +202,7 @@ class Epson_PNL_CE02 * * @param data parallel data (D0-D7) byte */ - void displayWrite(byte data); + static void displayWrite(byte data); /** * @brief Read current pressed buttons in 8-bit sequence (`0`: no pressed, `1`: pressed). @@ -171,12 +219,11 @@ class Epson_PNL_CE02 * @return true * @return false */ - bool isPowerButtonPressed(); + bool isPowerButtonPressed() const; -private: - unsigned int oePin, serOutPin, powerButtonPin, clockPin, serInPin, latchPin; - byte buttonsSequence; // SERIAL OUT 74LV165A - All buttons except power - byte buffer; // SERIAL IN 74HC595 - Control panel extender (refer to ExtenderPin) + private: + Epson_PNL_CE02_Pinout *pins; + byte buffer{0b0}; // SERIAL IN 74HC595 - Control panel extender (refer to ExtenderPin) /** * @brief Read and write to shift registers that control buttons, power led and display. @@ -184,7 +231,7 @@ class Epson_PNL_CE02 * * @return byte Current pressed buttons in 8-bit sequence */ - byte synchronize(); + byte synchronize() const; }; -#endif // Epson_PNL_CE02_H \ No newline at end of file +#endif // Epson_PNL_CE02_H