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.

Comment thread src/flash/gd5f1gq5xe.cpp
Comment on lines +43 to +48
// Note that this flash has a page size of 2048, so we actually only need 11
// bytes for the column address.
int write_enable(Protocol* protocol) {
uint8_t cmd[] = {GD5F_WRITE_ENABLE};
return protocol->write(ConstSpan(cmd), {}, AddressSize::None);
}

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.

If this function is only meant to be used in gd5f1gq5xe.cpp then it should probably be static.

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.

It is in an anonymous namespace, which has internal linkage.

@ncorrea210

Copy link
Copy Markdown
Contributor

overall though it looks nice, am enjoying the cpp

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.

2 participants