Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Article: Writing your own I2C component for the ESP-Registry #135

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pedrominatel
Copy link
Member

Description

This article is about how to create a new component with the I2C driver and use the GitHub Actions to publish the component to the Registry.

Related

SHTC3 Component

Testing


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@pedrominatel pedrominatel self-assigned this Oct 4, 2024
Copy link
Collaborator

@georgik georgik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider the following changes.

@kumekay Might give some hints for the compote


> Sharing knowledge is one of the most rewarding things you can do.

Before continuing, the component we will write will be available on [GitHub](https://github.com), so this article will be focused on GitHub as our versioning platform and you will need an account in order to publish your own component.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please point this link to some template, or example code, that can promote our contribution. Pointing just to github.com does not bring much value.


{{< github repo="esp-rs/esp-rust-board" >}}

### The new ESP-IDF I2C driver
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why somebody writing a new component should care about migration guide?
We should point the user how to write it in new style. IMO this part is good for separate article how to upgrade from old driver.


```yaml
version: 1.0.0
targets:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's worth mentioning how can one list a specific target, for universal componet like this it might make sense to skip all the lines, which will be future proof and component could work with future chips introduced in ESP-IDF. I guess in this type of sensor, there is nothing specific which would require just specific family.

idf : ">=5.3"
```

- **version**: This contains the component version following the version format `major.minor.patch` (0.0.0).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide here a link to the version documentation, because people are often confused why is the version 1.2.3~8.

- **targets**: This is the list of the supported targets.
- **description**: Brief description about the component.
- **url**: URL to the component page or company page.
- **repository**: URL to the GitHub component repository ending with `.git`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two options, using https:// or git@. We should recommend the first option for public archives, since it does not requires authentication on GitHub.


On this task, the sensor will be woken up, the readout will be read and processed, and then the sensor will return to sleep mode.

#### Bonus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to rename the chapter from bonus to Creating Kconfig (optional).
Many people do not know about the Kconfig and how to use it. This might be good source for a new article.

matrix:
idf_ver: ["release-v5.3", "latest"]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, consider using espressif/esp-idf-ci-action@v1.1.0. Using containers may cause additional issues.
https://github.com/georgik/esp32-sdl3-example/blob/main/.github/workflows/build.yml#L48

steps:
- uses: actions/checkout@master

- name: Upload components to component service
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding CI tests before pushing the component to registry:
https://github.com/georgik/esp32-sdl3-example/blob/main/.github/workflows/test.yml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to write something later.

</figure>

```bash
idf.py create-project-from-example "pedrominatel/shtc3^1.1.0:shtc3_read"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, consider other commands to build and flash the project. The README after the creation does not contain instructions. It was necessary to perform:

idf.py set-target esp32c3
idf.py build flash monitor

Plus CTRL+] to quit the monitor (this is confusing many people who would expect simple CTRL+C)

BTW: The app is rebooting:

I (288) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (296) main_task: Started on CPU0
I (296) main_task: Calling app_main()
I (296) gpio: GPIO[17]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40380102
0x40380102: _panic_handler at components/riscv/vectors.S:134


Publishing a component is not just about sharing code—it’s about sharing knowledge. When you contribute a component to the registry, you’re helping developers solve challenges and build better solutions. Depending on the impact and adoption of your component, you may gain recognition and appreciation from the developer community.

This article is not just a guide on how to create an I2C component; it’s an encouragement for you to start sharing your work and expertise with others. Every contribution helps build a stronger, more collaborative community.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add chapter with links:

  • component registry
  • compote (since it' might be better to upload from local computer furst before moving to GitHub)
  • link to repo with your sensors

@pedrominatel pedrominatel added the needs review Needs someone to be assigned to review label Oct 8, 2024
@pedrominatel
Copy link
Member Author

Please consider the following changes.

@kumekay Might give some hints for the compote

Thank you @georgik for your review. I've provided the new version with the proposed changes. Can you please review it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Needs someone to be assigned to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants