Skip to content

Commit

Permalink
Rename headers to .hpp (#334)
Browse files Browse the repository at this point in the history
* Renames all shared files from .h to .hpp

* Bindings, app to hpp. Update documentation image
  • Loading branch information
BlakeFreer authored Nov 28, 2024
1 parent 8ebc274 commit d486ef2
Show file tree
Hide file tree
Showing 148 changed files with 548 additions and 518 deletions.
11 changes: 11 additions & 0 deletions docs/docs/firmware/architecture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# draw.io

The architecture diagram is made with draw.io. Install that first.

To export, go `File -> Export as -> PNG`, then

- Size: 300%
- Select "Transparent Background"
- Disable "Include copy of diagram"

Repeat for the Light and Dark versions.
Binary file modified docs/docs/firmware/architecture/arch_diagram-Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/docs/firmware/architecture/arch_diagram-Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 30 additions & 30 deletions docs/docs/firmware/architecture/arch_diagram.drawio

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/docs/firmware/architecture/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ The peripheral implementations are in the MCAL (Microcontroller Abstraction Laye

At the app level, `DigitalInput` has just a single method `Read()`. This method takes no parameters and should return a boolean indicating the state of the input.

```c++ title="shared/periph/gpio.h"
```c++ title="shared/periph/gpio.hpp"
#pragma once

class DigitalInput {
Expand All @@ -117,11 +117,11 @@ The peripheral implementations are in the MCAL (Microcontroller Abstraction Laye
We do not specify a port or pin in this class. They are provided when an object is constructed in the project's platform layer, allowing this class to be reused for any stm32f767 digital input.

```c++ title="mcal/stm32f767/periph/gpio.h"
```c++ title="mcal/stm32f767/periph/gpio.hpp"
#pragma once

#include <cstdint>
#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"
#include "stm32f7xx_hal.h"

namespace mcal::stm32f767::periph {
Expand All @@ -146,12 +146,12 @@ The peripheral implementations are in the MCAL (Microcontroller Abstraction Laye

A command line interface does not have physical pins to read but the digital input behaviour can be implemented by prompting the user for a boolean input.

```c++ title="mcal/cli/periph/gpio.h"
```c++ title="mcal/cli/periph/gpio.hpp"
#pragma once

#include <iostream>
#include <string>
#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"

namespace mcal::cli::periph {

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/firmware/project-structure/inc/bindings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"

namespace bindings {

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/firmware/project-structure/inc/cli/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <iostream>

#include "../../bindings.h"
#include "mcal/cli/periph/gpio.h"
#include "shared/periph/gpio.h"
#include "../../bindings.hpp"
#include "mcal/cli/periph/gpio.hpp"
#include "shared/periph/gpio.hpp"

namespace mcal {

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/firmware/project-structure/inc/main.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "bindings.h"
#include "bindings.hpp"

int main() {
bindings::Initialize();
Expand Down
34 changes: 17 additions & 17 deletions docs/docs/firmware/project-structure/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ You should now have the following directory structure.

A key feature of our firmware architecture is the complete abstraction of the app-level code from any specific platform implementation (See the [Architecture](../architecture.md) article). The two layers are interfaced by the "bindings" contract which we will write first.

Create a new file `bindings.h` in the project directory. This is a header file since it only _declares_ the interface objects and methods rather than using or implementing them.
Create a new file `bindings.hpp` in the project directory. This is a header file since it only _declares_ the interface objects and methods rather than using or implementing them.

```c++ title="projects/MyBlink/bindings.h"
```c++ title="projects/MyBlink/bindings.hpp"
--8<--
inc/bindings.h:1:1
inc/bindings.hpp:1:1

inc/bindings.h:5:5
inc/bindings.hpp:5:5

inc/bindings.h:12:12
inc/bindings.hpp:12:12
--8<--
```

Expand All @@ -66,32 +66,32 @@ inc/bindings.h:12:12

We now add 3 elements to our contract.

1. A digital output which we will call `indicator`. Include the `shared/periph/gpio.h` to gain access to the app-level `DigitalOutput` class.
1. A digital output which we will call `indicator`. Include the `shared/periph/gpio.hpp` to gain access to the app-level `DigitalOutput` class.

```c++ title="projects/MyBlink/bindings.h" hl_lines="3 7"
```c++ title="projects/MyBlink/bindings.hpp" hl_lines="3 7"
--8<--
inc/bindings.h:1:7
inc/bindings.hpp:1:7

inc/bindings.h:12:12
inc/bindings.hpp:12:12
--8<--
```

> Notice the ampersand `&` in the type specifier. This makes `indicator` a _reference_ to a `DigitalOutput` object. This is necessary since `DigitalOutput` is a virtual class so its size-in-memory is not defined.

2. A function to wait between toggling. Time delay mechanisms are platform specific and thus must be included in the bindings contract. We will declare a `DelayMS` function which receives an `unsigned int` representing the number of milliseconds to delay for.

```c++ title="projects/MyBlink/bindings.h" hl_lines="9"
```c++ title="projects/MyBlink/bindings.hpp" hl_lines="9"
--8<--
inc/bindings.h:1:9
inc/bindings.hpp:1:9

inc/bindings.h:12:12
inc/bindings.hpp:12:12
--8<--
```

3. An initialization function. Some platforms must execute initialization code before they are ready to run. For example, stm32f767 has several `HAL_*_Init` functions which configure the peripherals. We include an `Initialize` function in bindings so that each platform can define its own behaviour.

```c++ title="projects/MyBlink/bindings.h" hl_lines="10"
--8<-- "inc/bindings.h"
```c++ title="projects/MyBlink/bindings.hpp" hl_lines="10"
--8<-- "inc/bindings.hpp"
```

This completes the bindings contract. We can now write the application code, knowing that the platforms will all satisfy this contract.
Expand All @@ -115,7 +115,7 @@ Create a `main.cc` file in the project folder.

In this simple project, all functions and peripherals are inside the `bindings` namespace. A more complex project could have app-level functions defined in `main.cc`.

The `SetHigh` and `SetLow` methods of `indicator` are declared in the virtual class under `shared/periph/gpio.h`.
The `SetHigh` and `SetLow` methods of `indicator` are declared in the virtual class under `shared/periph/gpio.hpp`.

### CMake Sources

Expand All @@ -130,7 +130,7 @@ This concludes the app-level code. Your project directory should look like
projects/
└── MyBlink/
├── platforms/
├── bindings.h
├── bindings.hpp
├── CMakeLists.txt
├── main.cc
└── README.md
Expand All @@ -143,7 +143,7 @@ We will create a platform implementation for the command line interface and the

Create a `cli` subfolder of `MyBlink/platforms`. We will satisfy the bindings contract in a `bindings.cc` file.

1. Configure the `indicator` output. The concrete peripheral implementation is provided by `mcal/cli/periph/gpio.h`. Include this header and create a peripheral.
1. Configure the `indicator` output. The concrete peripheral implementation is provided by `mcal/cli/periph/gpio.hpp`. Include this header and create a peripheral.

```c++ title="projects/MyBlink/platforms/cli/bindings.cc"
--8<--
Expand Down
2 changes: 1 addition & 1 deletion firmware/cmake/cangen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ add_custom_target(

add_dependencies(main generated_can)

# Link ETL which is needed for generated/can/msg_registry.h
# Link ETL which is needed for generated/can/msg_registry.hpp
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <iostream>
#include <string>

#include "shared/periph/adc.h"
#include "shared/periph/adc.hpp"

namespace mcal::cli::periph {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
#include <iostream>
#include <string>

#include "shared/periph/analog_output.h"
#include "shared/periph/analog_output.hpp"

namespace mcal::cli::periph {

class AnalogOutput : public shared::periph::AnalogOutput {
public:
AnalogOutput(std::string name) : name_(name) {}

void SetVoltage (float voltage) override {
std::cout << "Setting AnalogOutput " << name_ << " to " << voltage << " V"
<< std::endl;
void SetVoltage(float voltage) override {
std::cout << "Setting AnalogOutput " << name_ << " to " << voltage
<< " V" << std::endl;
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include <iomanip>
#include <iostream>

#include "shared/comms/can/raw_can_msg.h"
#include "shared/periph/can.h"
#include "shared/comms/can/raw_can_msg.hpp"
#include "shared/periph/can.hpp"

namespace mcal::cli::periph {

class CanBase : public shared::periph::CanBase {
public:
CanBase(std::string can_iface) : iface_(can_iface){};
CanBase(std::string can_iface) : iface_(can_iface) {};

void Setup() {
std::cout << "can interface: " << iface_ << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <iostream>
#include <string>

#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"

namespace mcal::cli::periph {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <iostream>
#include <string>

#include "shared/periph/pwm.h"
#include "shared/util/mappers/clamper.h"
#include "shared/periph/pwm.hpp"
#include "shared/util/mappers/clamper.hpp"

namespace mcal::cli::periph {

Expand All @@ -27,8 +27,8 @@ class PWMOutput : public shared::periph::PWMOutput {
duty_cycle_ =
shared::util::Clamper<float>::Evaluate(duty_cycle, 0, 100);

std::cout << "Setting PWM " << name_ << " duty cycle to " << duty_cycle_ << "%"
<< std::endl;
std::cout << "Setting PWM " << name_ << " duty cycle to " << duty_cycle_
<< "%" << std::endl;
}

float GetDutyCycle() override {
Expand All @@ -38,15 +38,15 @@ class PWMOutput : public shared::periph::PWMOutput {
}

void SetFrequency(float frequency) override {
frequency_ = std::max((float) 0, frequency);
frequency_ = std::max((float)0, frequency);

std::cout << "Setting PWM " << name_ << " frequency to " << frequency_
<< " Hz" << std::endl;
}

float GetFrequency() override {
std::cout << "PWM " << name_ << " has frequency " << frequency_
<< " Hz" << std::endl;
std::cout << "PWM " << name_ << " has frequency " << frequency_ << " Hz"
<< std::endl;
return frequency_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdint>
#include <string>

#include "shared/periph/adc.h"
#include "shared/periph/adc.hpp"

namespace mcal::lnx::periph {

Expand Down
2 changes: 1 addition & 1 deletion firmware/mcal/linux/periph/can.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <thread>

#include "can.h"
#include "shared/comms/can/raw_can_msg.h"
#include "shared/comms/can/raw_can_msg.hpp"
#include "vcan/vcan.h"

static std::string message_to_string(const shared::can::RawCanMsg& msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <queue>
#include <thread>

#include "mcal/linux/periph/vcan/vcan.h"
#include "shared/comms/can/raw_can_msg.h"
#include "shared/periph/can.h"
#include "mcal/linux/periph/vcan/vcan.hpp"
#include "shared/comms/can/raw_can_msg.hpp"
#include "shared/periph/can.hpp"
#include "vcan/vcan.h"

namespace mcal::lnx::periph {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string>

#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"

namespace mcal::lnx::periph {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <iostream>
#include <string>

#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"

namespace mcal::lnx::periph {
class DigitalOutput : public shared::periph::DigitalOutput {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <cstdint>
#include <string>

#include "shared/periph/adc.h"
#include "shared/util/mappers/linear_map.h"
#include "shared/periph/adc.hpp"
#include "shared/util/mappers/linear_map.hpp"
#include "validation/sil/sil_client.h"

namespace mcal::raspi::periph {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <queue>
#include <thread>

#include "shared/comms/can/raw_can_msg.h"
#include "shared/periph/can.h"
#include "shared/comms/can/raw_can_msg.hpp"
#include "shared/periph/can.hpp"
#include "third-party/etl/include/etl/queue.h"

namespace mcal::raspi::periph {
Expand All @@ -33,7 +33,7 @@ class CanBase : public shared::periph::CanBase {
};

void Setup() {
// Create a socket
// Create a socket
sock_ = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (sock_ < 0) {
perror("Error creating socket");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <iostream>
#include <string>

#include "shared/periph/gpio.h"
#include "shared/periph/gpio.hpp"
#include "validation/sil/sil_client.h"

namespace mcal::raspi::periph {
Expand Down Expand Up @@ -52,7 +52,6 @@ class DigitalOutput : public shared::periph::DigitalOutput {
}

void SetLow() override {

return sil_client_.SetDigitalLevel(ecu_name_, sig_name_, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <iostream>
#include <string>

#include "shared/periph/pwm.h"
#include "shared/util/mappers/clamper.h"
#include "shared/periph/pwm.hpp"
#include "shared/util/mappers/clamper.hpp"

namespace mcal::raspi::periph {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#pragma once

#include "cmsis_os2.h"
#include "shared/os/fifo.h"
#include "shared/os/os.h"
#include "shared/os/fifo.hpp"
#include "shared/os/os.hpp"

namespace mcal::stm32f767::os {

Expand Down
Loading

0 comments on commit d486ef2

Please sign in to comment.