Skip to content

Conversation

@sfe-SparkFro
Copy link
Contributor

No description provided.

Remove I2C device address requirement for SPI busses
Add error and warning codes
Also refactor some things for consistency
Copy link
Contributor

@SFE-Brudnerd SFE-Brudnerd left a comment

Choose a reason for hiding this comment

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

Overall it's a good start, I think there's just a few different things we should be doing differently, however I like the overall structure as it currently stands.

#define SFE_BUS_E_NO_RESPONSE -4
#define SFE_BUS_E_DATA_TOO_LONG -5
#define SFE_BUS_W_UNKNOWN 1
#define SFE_BUS_W_UNDER_READ 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a 2 or are we ok with multiple warnings with the same code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, typo! Should be 2. IMO every return code should have a unique value so a user can properly debug.

*/
class SfeI2C : public SfeBus
/// @brief An abstract interface for an I2C communication bus
class SFE_I2C : public SFE_Bus
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could be a templated class that is used to create the derived classes.

See Kirk's OLED library wrt the different types of OLEDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not opposed to using a template structure instead of inherited interfaces. Let's discuss this more tomorrow.

Comment on lines +51 to +58
virtual int8_t writeRegisters(uint8_t regAddr, const uint8_t *data, uint8_t numBytes);

/// @brief Reads a number of bytes starting at the given register address.
/// @param regAddr The first register address to read from.
/// @param data Data buffer to read from registers.
/// @param numBytes Number of bytes to read.
/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t readRegisters(uint8_t regAddr, uint8_t *data, uint8_t numBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

These should not be virtual since they're the end implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's probably a copy/paste bug, good catch!

/// @brief An I2C communication bus implementation for Arduino
class SFE_I2C_Arduino : public SFE_I2C
{
public:
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing constructor that defines the _i2cPort pointer.

Copy link
Contributor

Choose a reason for hiding this comment

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

please rename to sfe_i2c_arduino.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thought I'd fixed that, guess not!

#define SFE_BUS_W_UNDER_READ 1

/// @brief An abstract interface for a communication bus
class SFE_Bus
Copy link
Contributor

Choose a reason for hiding this comment

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

Class name does not follow code style conventions. I would rename to: SFEBaseBus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, my mistake! Do we want to use the word "Base" in the name? I know some people have strong opinions about that.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be following how I've seen Kirk do things in the past. Base is usually used for purely virtual classes anyway.

*/
class SfeI2C : public SfeBus
/// @brief An abstract interface for an I2C communication bus
class SFE_I2C : public SFE_Bus
Copy link
Contributor

Choose a reason for hiding this comment

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

Class name does not follow code style conventions. I would rename to: SFEBaseI2C.

#include <Wire.h>

/// @brief An I2C communication bus implementation for Arduino
class SFE_I2C_Arduino : public SFE_I2C
Copy link
Contributor

Choose a reason for hiding this comment

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

Class name does not follow code style conventions. I would rename to: SFEArduinoI2C.

*/
class SfeSPI : public SfeBus
/// @brief An abstract interface for an SPI communication bus
class SFE_SPI : public SFE_Bus
Copy link
Contributor

Choose a reason for hiding this comment

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

Class name does not follow code style conventions. I would rename to: SFEBaseSPI.

#include <SPI.h>

/// @brief An SPI communication bus implementation for Arduino
class SFE_SPI_Arduino : public SFE_SPI
Copy link
Contributor

Choose a reason for hiding this comment

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

Class name does not follow code style conventions. I would rename to: SFEArduinoSPI.

@gigapod gigapod closed this Dec 8, 2023
@SFE-Brudnerd SFE-Brudnerd deleted the i2c_and_spi_interfaces branch December 14, 2023 18:46
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.

4 participants