Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Oct 9, 2024
1 parent 14efa86 commit 7745c8e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
6 changes: 6 additions & 0 deletions include/serial/Serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace OpenShock::Serial {
// Initializes the SerialInputHandler, which listens for incoming serial commands.
bool Init();
} // namespace OpenShock::Serial
9 changes: 6 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ const char* const TAG = "main";
#include "GatewayConnectionManager.h"
#include "Logging.h"
#include "OtaUpdateManager.h"
#include "serial/Serial.h"
#include "serial/SerialInputHandler.h"
#include "util/TaskUtils.h"
#include "VisualStateManager.h"
#include "wifi/WiFiManager.h"
#include "wifi/WiFiScanManager.h"

#include <Arduino.h>

#include <memory>

// Internal setup function, returns true if setup succeeded, false otherwise.
Expand Down Expand Up @@ -83,7 +82,11 @@ void appSetup() {

// Arduino setup function
void setup() {
::Serial.begin(115'200);
// esp_log_level_set(ESP_LOG_VERBOSE);

Serial::Init();

// esp_log_level_set(ESP_LOG_VERBOSE);

OpenShock::Config::Init();
OpenShock::OtaUpdateManager::Init();
Expand Down
54 changes: 54 additions & 0 deletions src/serial/Serial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <freertos/FreeRTOS.h>

#include "serial/Serial.h"

#include <driver/uart.h>
#include <freertos/task.h>

#define TAG "serial::Serial"

#define UART_NUM UART_NUM_0
#define UART_TXP 1
#define UART_RXP 3
#define UART_BUFFER_SIZE 1024
#define UART_QUEUE_SIZE 10
#define UART_BAUD_RATE 115200

using namespace OpenShock;

bool Serial::Init() {
if (uart_is_driver_installed(UART_NUM)) {
return true;
}

// Configure the UART
uart_config_t uart_config = {
.baud_rate = UART_BAUD_RATE,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_DEFAULT,
}; // default values

esp_err_t err;

err = uart_driver_install(UART_NUM, UART_BUFFER_SIZE, UART_BUFFER_SIZE, UART_QUEUE_SIZE, nullptr, 0);
if (err != ESP_OK) {
return false;
}

err = uart_param_config(UART_NUM, &uart_config);
if (err != ESP_OK) {
return false;
}

err = uart_set_pin(UART_NUM, UART_TXP, UART_RXP, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
if (err != ESP_OK) {
return false;
}

uart_

return true;
}

1 comment on commit 7745c8e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v18.1.8) reports: 2 file(s) not formatted
  • src/main.cpp
  • src/serial/Serial.cpp

Have any feedback or feature suggestions? Share it here.

Please sign in to comment.