Skip to content

Add writeWord writeBlock #34

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

Merged
merged 7 commits into from
Jun 18, 2024
Merged

Add writeWord writeBlock #34

merged 7 commits into from
Jun 18, 2024

Conversation

edspark
Copy link
Contributor

@edspark edspark commented May 30, 2024

This adds two new functions that target the same functionality as writeByte(): writeWord() and writeBlock(). The intent is to be able to send data over I2C without indexing to a register. This is helpful in the case where the device simply expects I2C commands over I2C. Examples of this include products like the new Ultrasonic Distance Sensor, Quad Relay, Qwiic Twist, Qwiic RFID, etc. Basically devices, at least in the examples I listed, that have micro-controllers that act as peripherals.

edspark added 2 commits May 30, 2024 06:20
* Updates descriptions to indicate that these functions to not index to a given register.
@edspark edspark requested a review from gigapod May 30, 2024 17:17
@sfe-SparkFro
Copy link
Contributor

sfe-SparkFro commented Jun 4, 2024

Haven't reviewed, but in testing the Ultrasonic Arduino lib, I get the following warning:

c:\Users\Dryw\Documents\Arduino\libraries\SparkFun_Toolkit\src\sfeTkArdI2C.cpp: In member function 'virtual sfeTkError_t sfeTkArdI2C::writeBlock(const uint8_t*, size_t)':
c:\Users\Dryw\Documents\Arduino\libraries\SparkFun_Toolkit\src\sfeTkArdI2C.cpp:129:9: error: unused variable 'nData' [-Werror=unused-variable]
  129 |     int nData = 0;
      |         ^~~~~
cc1plus.exe: some warnings being treated as errors

I strongly recommend setting "Compiler warnings" in Arduino to "All" so these warnings show up

@edspark
Copy link
Contributor Author

edspark commented Jun 5, 2024

I've been using the arduino-cli and didn't even think to increase verbosity! I will do that!

@@ -87,14 +87,32 @@ class sfeTkIBus
{
public:
/**--------------------------------------------------------------------------
* @brief Write a single byte to the device*
* @brief Send a single byte to the device*
Copy link
Member

Choose a reason for hiding this comment

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

Since all the methods use a "write*" naming pattern, shouldn't this be Write?

FWIW: Normally send/receive are used with network based operations - at least in my experience ....

Copy link
Contributor Author

@edspark edspark Jun 5, 2024

Choose a reason for hiding this comment

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

You're completely right. I was trying to get at the fact that it doesn't physically write bits/bytes to a register and so "send" seemed to fit. However, you're write (a joke there). I'll adjust to this: "Write a single byte, without indexing to a register". Something to that effect. I also have a few more things that I want to add to this pull request.

@edspark
Copy link
Contributor Author

edspark commented Jun 6, 2024

I added a few more methods for reading from a device without a register parameter. This compliments the previously added write methods. I have enabled warnings to makes sure I didn't miss those, and I've also adjusted the language around the description of the new and existing methods in the pull request. Many apologies for the disjointed manner of this pull request.

@edspark
Copy link
Contributor Author

edspark commented Jun 17, 2024

Can I get another look at this? There's a library that is dependent on these functions going live this week. Thanks!

Copy link
Member

@gigapod gigapod left a comment

Choose a reason for hiding this comment

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

Summary:

  • Unclear why the read*() methods were added - they are the same as readRegister*() in the arduino impl
  • Added a method to implement writeBlock/Region() and reuse some code
  • Was the SPI implementation provided for the added methods to the bus interface?
    - And verify these make sense for an SPI device - if not, then these methods should not be in the core interface.
  • Has your changes been tested using the test action in the repo (or just compile the test sketch locally with different platforms)?

Happy to review this with you tomorrow.

edspark added 3 commits June 18, 2024 10:29
* Changes the name of `writeBlock()` to `writeRegion()`
* `writeRegion()` now calls `writeRegisterRegionAddress()` function
* `writeRegisterRegionAddress()` now has a nullptr check before indexing to an address on write
*Adds `writeWord()` and `writeRegion()`
@edspark
Copy link
Contributor Author

edspark commented Jun 18, 2024

Issues addressed, may I get another look @gigapod? Thank you!

Copy link
Member

@gigapod gigapod left a comment

Choose a reason for hiding this comment

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

Everything looks good - based on the comments and code from yesterday.

On thing to note - Make sure this is tested with device drivers that are already using the toolkit ... it should, but this is a good regression test.

@edspark edspark merged commit 5c4d2bc into main Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants