Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

API Improvement - Wire Library

オープン
#244 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
api, embedded-iot

調査の方向性

まず、SAMD および AVR の Wire 実装に重複しているバッファリングロジックを比較し、次に Arduino Core API で提案された低レベルの I2C 抽象化をどのように公開できるかを検討します。決定論的なタイミング要件に照らして、ステータス、ポーリング、および ISR の要件を評価します。完了とするには、合意済みの API 設計と、Wire との互換性を維持する完全な実装が必要です。

索引モデルが issue の本文から書いたものです。

説明

enhancement
API component

There should be consideration for improving the Wire library.

Description

I propose a lower-level version of the Wire library that is more tethered to what's actually happening on the hardware.
The current implementation imposes unnecessary buffering and busy-loops, that it's not usable in any situation where timing is critical.
I propose supplementing the Arduino Core with a new I2C interface, which the Wire library can use as a HAL component.

My suggestion is this (roughly):

enum class I2CStatus {
    Ready,       // Ready for the next operation
    Busy,        // Currently processing
    Error,       // An error occurred
    Completed    // Operation completed successfully
};

class I2C {
public:
    virtual ~I2C() = default;

    // Start the I2C communication (generate START condition)
    virtual void start(uint8_t address, bool write) = 0;

    // Stop the I2C communication (generate STOP condition)
    virtual void stop() = 0;

    // Write a single byte to the I2C bus
    virtual void writeByte(uint8_t byte) = 0;

    // Send ack to respond to an incoming byte
    virtual void sendAck(bool ack) = 0;

    // Check the current status of the I2C bus
    virtual I2CStatus getStatus() const = 0;

    // Polling mechanism or ISR-driven handling will manage the progress
    virtual void process() = 0;

   // Returns 1 if a byte has been read
   virtual int available() = 0;

  // Returns a byte that has been read or a -1
  virtual int read() = 0;
};

In regards to the ISR functions, you would have one for start conditions, stop conditions, reads, write,s etc. I didn't include them in this code example, but you'd probably want to add those as well.

Is this a breaking change?

It doesn't have to be. This can be implemented as a lower-level I2C library, and utilized in the Wire library. I noticed in both the SAMD core an the AVR code, a lot of the buffering logic in the Wire library is duplicated. Having this lower-level platform abstraction could potentially reduce some of that by making the Wire library a higher level library. Although I think the Wire library should be deprecated, it would still be good to have it for backwards compatibility. Here's what I mean:

class TwoWire final
{
public:
  TwoWire(I2C* bus)
    : bus_(bus)
  {}
  int endTransmission()
  {
    bus_->start(); // send start condition
    // This polling/blocking behavior would be kept for compatibility, but the user's of the lower level library would be able to bypass it.
    while (bus_->getStatus() != I2CStatus::Busy) {
      busy_->process();
    }
    // error checking would go here
    // write start address with R/W bit
    // poll again, as shown above
    // perform the write operations
    return 0; // success
  }
private:
  I2C* bus_{};
};

I've left out some detail out because I think the code gets the point across.
However if that's not true, I can elaborate more.

Additional information

The reason this is important to me is because I see Arduino as a good framework for cross-platform embedded programming (specifically when it comes to prototyping). The I2C busy loops are an issue for me because they make it more difficult to get deterministic timing. The reason why deterministic timing is important for Arduino (as a user):

  • Data acquisition - if I'm trying to gather data reliably at 1 KHz (for example) on multiple sensors, I need to make sure the deadlines are getting hit for each transaction. Currently the API performs all the transactions at endTransmission, which is problematic.
  • Motion Control - There are a lot of devices coming out that use I2C, due to the Qwiic and STEMMA QT interfaces made by SparkFun and Adafruit.

These companies are providing drivers for the I2C boards they're making, but they're limited in their quality due to the Wire API.
Because of the success and widespread adoption of Arduino and the popularity of I2C boards in rapid-prototyping boards, the I2C API needs a more robust, lower level standard.

If you're concerned about the user-friendliness:

  • You can keep the Wire library, and even have it implemented by the new lower level HAL
  • Most Arduino users aren't writing I2C drivers, the board manufactures are. The developers for the board manufactures are usually seasoned professionals.
主要言語
C++
スター
306
フォーク
150
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

arduino/ArduinoCore-API のほかの issue

arduino/ArduinoCore-API の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。