feat: use c++ - #7
Conversation
|
Don't merge yet, this needs a lot more testing. |
Discussed internally, this is a rather large change.
ncorrea210
left a comment
There was a problem hiding this comment.
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.
| 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; }; |
There was a problem hiding this comment.
Would be good to add a quick brief as to what these functions do.
| /// 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>; |
There was a problem hiding this comment.
Why not directly use std::span?
There was a problem hiding this comment.
This enforces byte buffers, also needs a bit less typing.
| // 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); | ||
| } |
There was a problem hiding this comment.
If this function is only meant to be used in gd5f1gq5xe.cpp then it should probably be static.
There was a problem hiding this comment.
It is in an anonymous namespace, which has internal linkage.
|
overall though it looks nice, am enjoying the cpp |
Discussed internally, this is a rather large change. Really sorry about that. Couple of changes
There are some interesting stuff for the
Protocolabstract class, feel free to criticize and discuss. One cool benefit of this rewrite is that we no longer have #ifdefs anywhere outside ofhal.h.