diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 03600dd..fa738ec 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,3 +8,5 @@ updates: directory: / # Check the repository's workflows under /.github/workflows/ schedule: interval: daily + labels: + - "topic: infrastructure" diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index 0d969f6..3e0d26c 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Arduino Lint uses: arduino/arduino-lint-action@v1 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 8821028..c692243 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -64,7 +64,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Compile examples uses: arduino/compile-sketches@v1 @@ -83,7 +83,7 @@ jobs: sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }} - name: Save sketches report as workflow artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 01bee87..3f6b03f 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 0000000..94938f3 --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,138 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md +name: Sync Labels + +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + pull_request: + paths: + - ".github/workflows/sync-labels.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + schedule: + # Run daily at 8 AM UTC to sync with changes to shared label configurations. + - cron: "0 8 * * *" + workflow_dispatch: + repository_dispatch: + +env: + CONFIGURATIONS_FOLDER: .github/label-configuration-files + CONFIGURATIONS_ARTIFACT: label-configuration-files + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: | + sudo npm install \ + --global \ + ajv-cli \ + ajv-formats + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "${{ steps.download-schema.outputs.file-path }}" \ + -d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}" + + download: + needs: check + runs-on: ubuntu-latest + + strategy: + matrix: + filename: + # Filenames of the shared configurations to apply to the repository in addition to the local configuration. + # https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels + - universal.yml + + steps: + - name: Download + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v3 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable + echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV" + + - name: Determine whether to dry run + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "::set-output name=flag::--dry-run" + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Download configuration files artifact + uses: actions/download-artifact@v3 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v2 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Merge label configuration files + run: | + # Merge all configuration files + shopt -s extglob + cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}" + + - name: Install github-label-sync + run: sudo npm install --global github-label-sync + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} diff --git a/docs/api.md b/docs/api.md index 71b6989..f408c29 100644 --- a/docs/api.md +++ b/docs/api.md @@ -104,40 +104,6 @@ The number of bytes available to read. * [sendBreakMicroseconds()](#sendbreakmicroseconds) * [setPins()](#setpins) -### `available()` - -Get the number of bytes (characters) available for reading from the RS485 port. This is data that already arrived and is stored in the serial receive buffer. - -#### Syntax - -``` -RS485.available() -``` - -#### Parameters - -None. - -#### Returns - -The number of bytes available to read. - -#### See also - -* [begin()](#begin) -* [end()](#end) -* [peek()](#peek) -* [read()](#read) -* [write()](#write) -* [flush()](#flush) -* [beginTransmission()](#begintransmission) -* [endTransmission()](#endtransmission) -* [receive()](#receive) -* [noReceive()](#noreceive) -* [sendBreak()](#sendbreak) -* [sendBreakMicroseconds()](#sendbreakmicroseconds) -* [setPins()](#setpins) - ### `peek()` Returns the next byte (character) of the incoming serial data without removing it from the internal serial buffer. That is, successive calls to peek() will return the same character, as will the next call to read(). diff --git a/docs/readme.md b/docs/readme.md index 2a2608a..5e8adf7 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,7 +1,7 @@ # Arduino RS485 library -The Arduino RS485 library enables you to send and receive data using the RS-485 standard with Arduino® RS485 Shields, like the MKR 485 Shield. Please refer to the MKR RS485 Shield documentation for the specific settings about half, full duplex, and termination. +The Arduino RS485 library enables you to send and receive data using the RS-485 standard with Arduino® RS485 Shields, like the MKR 485 Shield. Please refer to the [MKR RS485 Shield](https://www.arduino.cc/en/Guide/MKR485Shield) documentation for the specific settings about half, full duplex, and termination. This library supports the MAX3157 and equivalent chipsets. @@ -9,4 +9,4 @@ To use this library: ``` #include -``` \ No newline at end of file +``` diff --git a/library.properties b/library.properties index ffd6dfe..55c4a06 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoRS485 -version=1.0.2 +version=1.0.3 author=Arduino maintainer=Arduino sentence=Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. diff --git a/src/RS485.cpp b/src/RS485.cpp index ba6e80f..20a6451 100644 --- a/src/RS485.cpp +++ b/src/RS485.cpp @@ -19,6 +19,18 @@ #include "RS485.h" +#ifdef __MBED__ +#include "pinDefinitions.h" +RS485Class::RS485Class(HardwareSerial& hwSerial, PinName txPin, PinName dePin, PinName rePin) : + _serial(&hwSerial), + _txPin(PinNameToIndex(txPin)), + _dePin(PinNameToIndex(dePin)), + _rePin(PinNameToIndex(rePin)), + _transmisionBegun(false) +{ +} +#endif + RS485Class::RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin) : _serial(&hwSerial), _txPin(txPin), @@ -71,13 +83,13 @@ void RS485Class::end() { _serial->end(); - if (_rePin > -1) { - digitalWrite(_rePin, LOW); + if (_dePin > -1) { + digitalWrite(_dePin, LOW); pinMode(_dePin, INPUT); } - if (_dePin > -1) { - digitalWrite(_dePin, LOW); + if (_rePin > -1) { + digitalWrite(_rePin, LOW); pinMode(_rePin, INPUT); } } @@ -186,4 +198,8 @@ void RS485Class::setDelays(int predelay, int postdelay) _postdelay = postdelay; } +#ifdef RS485_SERIAL_PORT +RS485Class RS485(RS485_SERIAL_PORT, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN); +#else RS485Class RS485(SERIAL_PORT_HARDWARE, RS485_DEFAULT_TX_PIN, RS485_DEFAULT_DE_PIN, RS485_DEFAULT_RE_PIN); +#endif diff --git a/src/RS485.h b/src/RS485.h index 050b253..cc298b2 100644 --- a/src/RS485.h +++ b/src/RS485.h @@ -22,19 +22,26 @@ #include +#ifndef RS485_DEFAULT_TX_PIN #ifdef PIN_SERIAL1_TX #define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX #else #define RS485_DEFAULT_TX_PIN 1 #endif +#endif #ifdef __AVR__ #define RS485_DEFAULT_DE_PIN 2 #define RS485_DEFAULT_RE_PIN -1 +#elif ARDUINO_NANO_RP2040_CONNECT +#define RS485_DEFAULT_DE_PIN A1 +#define RS485_DEFAULT_RE_PIN A0 #else +#ifndef RS485_DEFAULT_DE_PIN #define RS485_DEFAULT_DE_PIN A6 #define RS485_DEFAULT_RE_PIN A5 #endif +#endif #define RS485_DEFAULT_PRE_DELAY 50 @@ -42,6 +49,9 @@ class RS485Class : public Stream { public: +#ifdef __MBED__ + RS485Class(HardwareSerial& hwSerial, PinName txPin, PinName dePin, PinName rePin); +#endif RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin); virtual void begin(unsigned long baudrate);