Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Buildscripts/DevicetreeCompiler/source/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
with open(filename, "w") as file:
file.write(dedent('''\
// Default headers
#include <Tactility/Device.h>
#include <Tactility/Driver.h>
#include <Tactility/Log.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/log.h>
// DTS headers
'''))

Expand Down
96 changes: 96 additions & 0 deletions CODING_STYLE_C.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# C coding Style

## Naming

### Files

Files are lower snake case.

- Files: `^[0-9a-z_]+$`
- Directories: `^[0-9a-z_]+$`

Example:
```c
some_feature.c
some_feature.h
```

### Folders

Project folders include:
- `source` for source files and public header files
- `private` for private header files
- `include` for projects that require separate header files

### Macros and consts

These are all upper snake case:

```c
#define MY_CONST 1
#define PRINT_SOMETHING() printf("something")
const int ANOTHER_CONST = 1;
```

### Variables

Variable names and function parameters are lower snake case:

```c
int some_variable;
```

### Enumerations and Structs

Enums and struct types are upper camel case.
Its fields use lower snake case.

```c
struct ThreadData {
int some_attribute;
};
```

```c
enum SomeResult {
Ok,
NotSupported,
Error
};
```

### Function names

Function names are lower snake case.

Example:

```c
void get_limit() {
// ...
}
```

If a set of functions relates to a `struct`, the CamelCase struct name is converted to a snake_case_ prefix for the function name:

```c
struct TextMessage {
// ...
};

void text_message_set(struct TextMessage* message) { /* ... */ }

void text_message_get(struct TextMessage* message) { /* ... */ }

```

### Typedef of simple value types

Typedefs for simple value types (such as int, int64_t, char) are lower snake case.
They are postfixed with `_t`

Examples:

```c
typedef uint32_t thread_id_t;
```
9 changes: 6 additions & 3 deletions CODING_STYLE.md → CODING_STYLE_CPP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All code should target C++ language revision 20.

If you use CLion, please enable the setting called "Enable ClangFormat" under Settings > Editor > Code Style.

# C projects with C++ code

In projects that expose a C API with internal C++ code, the C naming conventions are used for language features that are shared.

## Naming

### Files
Expand All @@ -21,8 +25,7 @@ SomeFeature.cpp
SomeFeature.h
```

Private/internal headers are postfixed with `Private` before the file extension.
Like `SomeFeaturePrivate.h`
Private/internal headers are placed in a `Private/` directory.

### Folders

Expand Down Expand Up @@ -69,7 +72,7 @@ struct ThreadData {
`enum class` or `enum struct` is preferred over plain `enum` because of scoping. It's styled like this:

```c++
enum class {
enum class SomeType {
Ok,
NotSupported,
Error
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tlora-pager/Source/Drivers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Tactility/Driver.h>
#include <tactility/driver.h>

extern "C" {

Expand Down
4 changes: 2 additions & 2 deletions Devices/lilygo-tlora-pager/Source/bindings/tlora_pager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
extern "C" {
#endif

#include <Tactility/bindings/bindings.h>
#include <Tactility/drivers/Root.h>
#include <tactility/bindings/bindings.h>
#include <tactility/drivers/root.h>
#include <drivers/TloraPager.h>

DEFINE_DEVICETREE(tlora_pager, struct RootConfig)
Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tlora-pager/Source/drivers/Register.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Tactility/Driver.h>
#include <tactility/driver.h>

extern "C" {

Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tlora-pager/Source/drivers/TloraPager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "TloraPager.h"

#include <Tactility/Driver.h>
#include <tactility/driver.h>

#include <esp_log.h>

Expand Down
2 changes: 1 addition & 1 deletion Devices/lilygo-tlora-pager/Source/drivers/TloraPager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C" {
#endif

#include <Tactility/drivers/Root.h>
#include <tactility/drivers/root.h>

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/dts-v1/;

#include <bindings/tlora_pager.h>
#include <Tactility/bindings/esp32_gpio.h>
#include <Tactility/bindings/esp32_i2c.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_i2c.h>

/ {
compatible = "lilygo,tlora-pager";
Expand Down
2 changes: 1 addition & 1 deletion Devices/placeholder.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/dts-v1/;

#include <Tactility/bindings/root.h>
#include <tactility/bindings/root.h>

/ {
compatible = "root";
Expand Down
4 changes: 2 additions & 2 deletions Devices/simulator/Source/LvglTask.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "LvglTask.h"

#include <Tactility/Check.h>
#include <Tactility/Thread.h>
#include <Tactility/Logger.h>
#include <Tactility/RecursiveMutex.h>
#include <Tactility/Thread.h>
#include <tactility/check.h>
#include <Tactility/lvgl/LvglSync.h>

#include <lvgl.h>
Expand Down
2 changes: 1 addition & 1 deletion Devices/simulator/Source/hal/SdlDisplay.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "SdlTouch.h"
#include <Tactility/Check.h>
#include <tactility/check.h>
#include <Tactility/hal/display/DisplayDevice.h>

/** Hack: variable comes from LvglTask.cpp */
Expand Down
4 changes: 2 additions & 2 deletions Devices/simulator/Source/hal/SdlKeyboard.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tactility/Check.h>
#include <Tactility/TactilityCore.h>
#include <tactility/check.h>
#include <Tactility/hal/keyboard/KeyboardDevice.h>

class SdlKeyboard final : public tt::hal::keyboard::KeyboardDevice {

Expand Down
2 changes: 1 addition & 1 deletion Devices/simulator/Source/hal/SdlTouch.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "Tactility/hal/touch/TouchDevice.h"
#include <Tactility/Check.h>
#include <Tactility/TactilityCore.h>
#include <tactility/check.h>

class SdlTouch final : public tt::hal::touch::TouchDevice {

Expand Down
2 changes: 1 addition & 1 deletion Devices/simulator/simulator.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/dts-v1/;

#include <Tactility/bindings/root.h>
#include <tactility/bindings/root.h>

/ {
model = "Simulator";
Expand Down
2 changes: 1 addition & 1 deletion Drivers/DRV2605/Source/Drv2605.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Drv2605.h"

#include <Tactility/Check.h>
#include <tactility/check.h>
#include <Tactility/Logger.h>

static const auto LOGGER = tt::Logger("DRV2605");
Expand Down
6 changes: 3 additions & 3 deletions Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "EspLcdDisplay.h"
#include "EspLcdDisplayDriver.h"

#include <cassert>
#include <esp_lvgl_port_disp.h>
#include <Tactility/Check.h>
#include <Tactility/Logger.h>
#include <tactility/check.h>
#include <Tactility/hal/touch/TouchDevice.h>
#include <cassert>
#include <esp_lvgl_port_disp.h>

static const auto LOGGER = tt::Logger("EspLcdDisplay");

Expand Down
2 changes: 1 addition & 1 deletion Drivers/EspLcdCompat/Source/EspLcdDisplay.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Tactility/Lock.h>
#include <Tactility/Check.h>
#include <tactility/check.h>
#include <Tactility/hal/display/DisplayDevice.h>

#include <esp_lcd_types.h>
Expand Down
6 changes: 3 additions & 3 deletions Drivers/EspLcdCompat/Source/EspLcdDisplayV2.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "EspLcdDisplayV2.h"
#include "EspLcdDisplayDriver.h"

#include <cassert>
#include <esp_lvgl_port_disp.h>
#include <Tactility/Check.h>
#include <Tactility/Logger.h>
#include <tactility/check.h>
#include <Tactility/hal/touch/TouchDevice.h>
#include <cassert>
#include <esp_lvgl_port_disp.h>

static const auto LOGGER = tt::Logger("EspLcdDispV2");

Expand Down
4 changes: 2 additions & 2 deletions Drivers/EspLcdCompat/Source/EspLcdDisplayV2.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <esp_lcd_panel_dev.h>
#include <Tactility/Check.h>
#include <Tactility/Lock.h>
#include <tactility/check.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <esp_lcd_panel_dev.h>

#include <esp_lcd_types.h>
#include <esp_lvgl_port_disp.h>
Expand Down
2 changes: 1 addition & 1 deletion Drivers/RgbDisplay/Source/RgbDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "RgbDisplay.h"

#include <Tactility/Check.h>
#include <tactility/check.h>
#include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/Logger.h>

Expand Down
2 changes: 1 addition & 1 deletion Firmware/Source/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Tactility/Tactility.h>

#include <Tactility/Driver.h>
#include <tactility/driver.h>
#include <devicetree.h>

#ifdef ESP_PLATFORM
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <Tactility/bindings/bindings.h>
#include <Tactility/drivers/Esp32Gpio.h>
#include <tactility/bindings/bindings.h>
#include <tactility/drivers/esp32_gpio.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <Tactility/bindings/bindings.h>
#include <Tactility/drivers/Esp32I2c.h>
#include <tactility/bindings/bindings.h>
#include <tactility/drivers/esp32_i2c.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <Tactility/drivers/Gpio.h>
#include <tactility/drivers/gpio.h>
#include <hal/i2c_types.h>

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

#include <esp_err.h>

#include <Tactility/Error.h>
#include <tactility/error.h>

error_t esp_err_to_error(esp_err_t error);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
#include <driver/gpio.h>

#include <Tactility/Driver.h>
#include <Tactility/drivers/Esp32Gpio.h>
#include <tactility/driver.h>
#include <tactility/drivers/esp32_gpio.h>

#include <Tactility/ErrorEsp32.h>
#include <Tactility/Log.h>
#include <Tactility/drivers/Gpio.h>
#include <Tactility/drivers/GpioController.h>
#include <tactility/error_esp32.h>
#include <tactility/log.h>
#include <tactility/drivers/gpio.h>
#include <tactility/drivers/gpio_controller.h>

#define TAG LOG_TAG(esp32_gpio)

Expand Down
Loading
Loading