Skip to content

Add writeByte. Add support for I2C restarts #25

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 1 commit into from
Dec 12, 2023
Merged

Conversation

PaulZC
Copy link
Contributor

@PaulZC PaulZC commented Dec 12, 2023

  • Add writeByte for both I2C and SPI - needed by the ADS1219 on I2C
  • Add support for I2C restart vs. stop
    • Many devices specify a restart between set-register-address and read-register-value
    • This is I2C-specific and may be needed on non-Arduino platforms too
    • Added setStop and getStop
  • Corrected readRegisterRegion
    • The beginTransmission and endTransmission should be inside the if (bFirstInter)

Add writeByte for both I2C and SPI - needed by the ADS1219 on I2C
Add support for I2C restart vs. stop (many devices require a restart between set-register-address and read-register-value). This is I2C-specific and may be needed on non-Arduino platforms too. Added setStop and getStop.
Corrected readRegisterRegion: the beginTransmission and endTransmission should be inside the if(bFirstInter).
@PaulZC
Copy link
Contributor Author

PaulZC commented Dec 12, 2023

TODO: readRegisterRegion should be returning sfeTkError_t to be safe and consistent with the other methods. On error, it currently returns kSTkErrFail - which makes no sense...

I propose changing:

int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes)

to:

sfeTkError_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes, size_t *readBytes)

and return the number of bytes read in readBytes.

@gigapod
Copy link
Member

gigapod commented Dec 12, 2023

TODO: readRegisterRegion should be returning sfeTkError_t to be safe and consistent with the other methods. On error, it currently returns kSTkErrFail - which makes no sense...

I propose changing:

int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes)

to:

sfeTkError_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes, size_t *readBytes)

and return the number of bytes read in readBytes.

Yeah, I missed that in my quick revision last week - and typedef equivalence kept the compiler from complaining.

@@ -34,7 +34,7 @@ class sfeTkII2C : public sfeTkIBus
sfeTkII2C() : _address{kNoAddress}
{
}
sfeTkII2C(uint8_t addr) : _address{addr}
sfeTkII2C(uint8_t addr) : _address{addr}, _stop{true}
Copy link
Member

Choose a reason for hiding this comment

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

I'd move the initialization of _stop{true} to the default ctor - the constructor without arguments(the method above this one).

And since _stop is a uint8_t, should the default value be 1? I would specify the number, not the value of true in the initializer).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. 1 is the correct choice. The Arduino source uses a mixture of uint8_t but with bool terminology. Let's stick with 1.

@PaulZC
Copy link
Contributor Author

PaulZC commented Dec 12, 2023

If you have time to jump on this, please go for it! Otherwise, I'm very happy to pick this up in the morning.

Long story short, the ToolKit is working very nicely in the ADS1219 library!

@gigapod
Copy link
Member

gigapod commented Dec 12, 2023

Great to hear it's working !! Thanks for updates/additions.

I'll merge it and tweak the constructor ... and the Arduino version so it get's picked up by the Arduino lib bot

@gigapod gigapod merged commit 1e24077 into main Dec 12, 2023
@gigapod gigapod deleted the Add_Non-Register_Write branch December 12, 2023 19:12
@SFE-Brudnerd
Copy link
Contributor

TODO: readRegisterRegion should be returning sfeTkError_t to be safe and consistent with the other methods. On error, it currently returns kSTkErrFail - which makes no sense...
I propose changing:

int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes)

to:

sfeTkError_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes, size_t *readBytes)

and return the number of bytes read in readBytes.

Yeah, I missed that in my quick revision last week - and typedef equivalence kept the compiler from complaining.

I'll take a crack at this in my other branch so that I can incorporate that into my UV library too.

@gigapod
Copy link
Member

gigapod commented Dec 12, 2023

TODO: readRegisterRegion should be returning sfeTkError_t to be safe and consistent with the other methods. On error, it currently returns kSTkErrFail - which makes no sense...
I propose changing:

int32_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes)

to:

sfeTkError_t sfeTkArdI2C::readRegisterRegion(uint8_t devReg, uint8_t *data, size_t numBytes, size_t *readBytes)

and return the number of bytes read in readBytes.

Yeah, I missed that in my quick revision last week - and typedef equivalence kept the compiler from complaining.

I'll take a crack at this in my other branch so that I can incorporate that into my UV library too.

....I have this written and about to do a PR with some tweaks to the stop message API...

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