Skip to content

feat: use c++ - #7

Open
wispl wants to merge 1 commit into
mainfrom
cpp-migration
Open

feat: use c++#7
wispl wants to merge 1 commit into
mainfrom
cpp-migration

Conversation

@wispl

@wispl wispl commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Discussed internally, this is a rather large change. Really sorry about that. Couple of changes

  1. use c++ classes to simplify and make things more readable, we can discuss optimizations later
  2. cmake magic to conditionally compile in spi, i2c, uart, and co. files only when they are enabled in cubemx
  3. swapped to gtest + fff, no more dependence on ruby

There are some interesting stuff for the Protocol abstract class, feel free to criticize and discuss. One cool benefit of this rewrite is that we no longer have #ifdefs anywhere outside of hal.h.

@wispl

wispl commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator Author

Don't merge yet, this needs a lot more testing.

Discussed internally, this is a rather large change.

@ncorrea210 ncorrea210 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Haven't looked through it all 100% of the way, these are some initial thoughts though. Main thing is that private functions (private to the .cpp file) should probably be static, and I am not sure about this using Span = ... stuff.

Comment thread include/flash/flash.h
Comment on lines +16 to +24
virtual ~Flash() = default;
virtual bool init() = 0;
uint32_t mount();
uint32_t unmount();
uint32_t bootcount(bool update);
uint32_t open(lfs_file_t* file, const char* filename);
uint32_t close(lfs_file_t* file);
bool append(lfs_file_t* file, const uint8_t* bytes, size_t size);
bool ready() const { return is_ready; };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be good to add a quick brief as to what these functions do.

Comment on lines +38 to +42
/// Span ---
/// A quick primer on span, it just a regular C buffer but it also
/// includes the size, really convenient, we will be using this a lot
using Span = std::span<uint8_t>;
using ConstSpan = std::span<const uint8_t>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not directly use std::span?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This enforces byte buffers, also needs a bit less typing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess. Not sure if I am a big fan though. @dmanslick thoughts?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am fine with removing it, though that does mean we have to do do std::span<uint8_t>(...) instead.

Comment thread src/flash/gd5f1gq5xe.cpp
@ncorrea210

Copy link
Copy Markdown
Contributor

overall though it looks nice, am enjoying the cpp

@dmanslick

Copy link
Copy Markdown

I don't think I understand the purpose of this "Platform" namespace. If it is going to be used everywhere, what is the benefit of the namespace besides knowing that these classes are from the common drivers repo? And if that's its purpose, I think calling the namespace "Common" is better suited. In any case, doesn't it make more sense for sensors to be in their own "Sensors" namespace, protocols to be in their own "Protocols" namespace, etc?

@wispl

wispl commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

It is a namespace collision thing, but right now it is more of a convention. Libraries generally add a namespace to all their exports so it is something like library_name::module::item.

I am fine with removing it, or calling it something else. Technically your sensor example would be Platform::Sensors::BMP581. I just slapped everything under a Platform cause I don't see too much of a reason for sub namespaces yet.

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