Skip to content

Commit

Permalink
Add code format, commit format, code spell checks (#17)
Browse files Browse the repository at this point in the history
* .github/workflows: Added workflow for formatting and spell check.

Signed-off-by: Ramya Subramanyam <[email protected]>

* .github/workflows: Rename the build and release action.

Signed-off-by: Ramya Subramanyam <[email protected]>

* ./tools: Helper scripts for gihub actions.

Signed-off-by: Ramya Subramanyam <[email protected]>

* cores/psoc: Formatted source code.

Signed-off-by: Ramya Subramanyam <[email protected]>

* ./docs: Formatted python script.

Signed-off-by: Ramya Subramanyam <[email protected]>

* ./README.md: Added badges for all github actions running.

Signed-off-by: Ramya Subramanyam <[email protected]>

* ./README.md: Modify badges.

Signed-off-by: Eder Julian <[email protected]>

---------

Signed-off-by: Ramya Subramanyam <[email protected]>
Signed-off-by: Eder Julian <[email protected]>
Co-authored-by: Julian Eder <[email protected]>
  • Loading branch information
ramya-subramanyam and ederjc authored Oct 9, 2024
1 parent d78b2cb commit 29c0b77
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Arduino Core PSoC CI compile
name: Build on Linux OS

# on which event should we start push, pull request or schedule dispatches
on:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/code_formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Code format check

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
code-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install packages
run: source tools/ci.sh && ci_c_code_formatting_setup
- name: Make sure there are no local changes
run: git restore .
- name: Run code formatting
run: source tools/ci.sh && ci_c_code_formatting_run
- name: Check code formatting
run: git diff --exit-code
13 changes: 13 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Code spell check

on: [push, pull_request]

jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# codespell version should be kept in sync with .pre-commit-config.yml
- run: pip install --user codespell==2.2.6 tomli
- run: codespell

18 changes: 18 additions & 0 deletions .github/workflows/commit_formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Commit message check

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '100'
- uses: actions/setup-python@v5
- name: Check commit message formatting
run: source tools/ci.sh && ci_commit_formatting_run
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PSoC-for-Arduino Release Automation
name: Release Automation

on:
release:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Arduino Core for Infineon's PSoC Microcontrollers

[![build on Linux](https://github.com/Infineon/arduino-core-psoc/actions/workflows/compile.yml/badge.svg)](https://github.com/Infineon/arduino-core-psoc/actions)
[![code format check](https://github.com/Infineon/arduino-core-psoc/actions/workflows/code_formatting.yml/badge.svg)](https://github.com/Infineon/arduino-core-psoc/actions)
[![code spell check](https://github.com/Infineon/arduino-core-psoc/actions/workflows/codespell.yml/badge.svg)](https://github.com/Infineon/arduino-core-psoc/actions)
[![commit message check](https://github.com/Infineon/arduino-core-psoc/actions/workflows/commit_formatting.yml/badge.svg)](https://github.com/Infineon/arduino-core-psoc/actions)
[![docs build](https://readthedocs.org/projects/arduino-core-psoc/badge/?version=latest)](https://arduino-core-psoc.readthedocs.io/en/latest/?badge=latest)

This repository integrates Infineon's [PSoC microcontrollers](https://www.infineon.com/cms/de/product/microcontroller/32-bit-psoc-arm-cortex-microcontroller/) into the [Arduino ecosystem](https://www.arduino.cc/en/main/software).
Expand Down Expand Up @@ -31,4 +35,4 @@ Please visit our [PSoC products page](https://www.infineon.com/cms/de/product/mi
We welcome community contributions! Please refer to our [contribution guidelines](CONTRIBUTING.md). Your help is greatly appreciated 👐

## License
Refer to the [license](LICENSE.md) file for more details about this project's license.
Refer to the [license](LICENSE.md) file for more details about this project's license.
10 changes: 5 additions & 5 deletions cores/psoc/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

using namespace arduino;

extern "C"{
extern "C" {
#endif // __cplusplus

// Include Atmel headers
#undef LITTLE_ENDIAN

#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
#define clockCyclesPerMicrosecond() (SystemCoreClock / 1000000L)
#define clockCyclesToMicroseconds(a) (((a) * 1000L) / (SystemCoreClock / 1000L))
#define microsecondsToClockCycles(a) ((a) * (SystemCoreClock / 1000000L))

#ifdef __cplusplus
} // extern "C"
Expand All @@ -50,7 +50,7 @@ extern "C"{
#undef abs
#endif // abs

#define abs(x) ((x)>0?(x):-(x))
#define abs(x) ((x) > 0?(x):-(x))


#ifdef __cplusplus
Expand Down
56 changes: 27 additions & 29 deletions cores/psoc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,45 @@
// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }
void initVariant() {
}


/*
* \brief Main entry point of Arduino application
*/
int main( void )
{
cy_rslt_t result;
int main(void) {
cy_rslt_t result;

/* Initialize the device and board peripherals */
result = cybsp_init();
/* Initialize the device and board peripherals */
result = cybsp_init();

/* Board init failed. Stop program execution */
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/* Board init failed. Stop program execution */
if (result != CY_RSLT_SUCCESS) {
CY_ASSERT(0);
}

/* Enable global interrupts */
__enable_irq();
/* Enable global interrupts */
__enable_irq();

/* Initialize retarget-io to use the debug UART port */
result = cy_retarget_io_init_fc(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX,
CYBSP_DEBUG_UART_CTS,CYBSP_DEBUG_UART_RTS,CY_RETARGET_IO_BAUDRATE);
/* Initialize retarget-io to use the debug UART port */
result = cy_retarget_io_init_fc(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX,
CYBSP_DEBUG_UART_CTS, CYBSP_DEBUG_UART_RTS, CY_RETARGET_IO_BAUDRATE);

/* retarget-io init failed. Stop program execution */
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/* retarget-io init failed. Stop program execution */
if (result != CY_RSLT_SUCCESS) {
CY_ASSERT(0);
}

printf("Hello world from Infineon PSoC Arduino CORE :) :) :) !!!\n");
initVariant();
printf("Hello world from Infineon PSoC Arduino CORE :) :) :) !!!\n");
initVariant();

setup();
setup();

for (;;)
{
loop();
}
for (;;)
{
loop();
}

return 0;
return 0;
}
39 changes: 18 additions & 21 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
import textwrap

# Check if we're running on Read the Docs' servers
read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
read_the_docs_build = os.environ.get("READTHEDOCS", None) == "True"

# -- Project information -----------------------------------------------------

project = 'Arduino Core for PSoC™'
copyright = '2024 Infineon Technologies AG'
author = 'Infineon Technologies AG'
project = "Arduino Core for PSoC™"
copyright = "2024 Infineon Technologies AG"
author = "Infineon Technologies AG"

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
#...
# ...

# At top on conf.py (with other import statements)
# import recommonmark
Expand All @@ -45,8 +45,8 @@
# app.add_transform(AutoStructify)

extensions = [
'sphinx_tabs.tabs',
'sphinxemoji.sphinxemoji',
"sphinx_tabs.tabs",
"sphinxemoji.sphinxemoji",
# 'sphinx.ext.autodoc',
# 'sphinx.ext.intersphinx',
# 'sphinx.ext.autosectionlabel',
Expand All @@ -60,7 +60,6 @@
# 'sphinx.ext.inheritance_diagram',
# 'breathe',
# 'exhale'

]

autosectionlabel_prefix_document = True
Expand All @@ -69,48 +68,46 @@
# }

source_suffix = [
'.rst',
".rst",
# '.md'
]

suppress_warnings = ['autosectionlabel.*', 'epub.duplicated_toc_entry']
suppress_warnings = ["autosectionlabel.*", "epub.duplicated_toc_entry"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# Tell sphinx what the primary language being documented is.
primary_domain = 'cpp'
primary_domain = "cpp"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "build", "Thumbs.db", ".DS_Store"]

highlight_language = 'c++'
highlight_language = "c++"

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.

html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"
# html_theme_options = {
# "head_font_family" : "Source Sans Pro",
# "font_family" : "Source Sans Pro",
# "body_text_align" : "justify",
# }

html_logo = 'img/ifx_logo_white_green_s.png'
html_logo = "img/ifx_logo_white_green_s.png"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_templates']
html_static_path = ["_templates"]

# -- Breathe configuration -------------------------------------------------

breathe_projects = {
"Arduino Core for PSoC": "build/xml/"
}
breathe_projects = {"Arduino Core for PSoC": "build/xml/"}
breathe_default_project = "Arduino Core for PSoC"
breathe_default_members = ('members', 'undoc-members')
breathe_default_members = ("members", "undoc-members")
37 changes: 37 additions & 0 deletions tools/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if which nproc > /dev/null; then
MAKEOPTS="-j$(nproc)"
else
MAKEOPTS="-j$(sysctl -n hw.ncpu)"
fi

# Ensure known OPEN_MAX (NO_FILES) limit.
ulimit -n 1024

########################################################################################
# c code formatting

function ci_c_code_formatting_setup {
sudo apt-get install black
black --version
sudo apt-get install uncrustify
uncrustify --version
}

function ci_c_code_formatting_run {
python tools/codeformat.py -v
}

########################################################################################
# commit formatting

function ci_commit_formatting_run {
git remote add upstream https://github.com/Infineon/arduino-core-psoc.git
git fetch --depth=100 upstream main
# If the common ancestor commit hasn't been found, fetch more.
git merge-base upstream/main HEAD || git fetch --unshallow upstream main
# For a PR, upstream/main..HEAD ends with a merge commit into main, exclude that one.
python tools/verifygitlog.py -n5 -v --no-merges
}

Loading

0 comments on commit 29c0b77

Please sign in to comment.