Skip to content

Commit 7745c8e

Browse files
committed
Initial commit
1 parent 14efa86 commit 7745c8e

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

include/serial/Serial.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
namespace OpenShock::Serial {
4+
// Initializes the SerialInputHandler, which listens for incoming serial commands.
5+
bool Init();
6+
} // namespace OpenShock::Serial

src/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ const char* const TAG = "main";
1111
#include "GatewayConnectionManager.h"
1212
#include "Logging.h"
1313
#include "OtaUpdateManager.h"
14+
#include "serial/Serial.h"
1415
#include "serial/SerialInputHandler.h"
1516
#include "util/TaskUtils.h"
1617
#include "VisualStateManager.h"
1718
#include "wifi/WiFiManager.h"
1819
#include "wifi/WiFiScanManager.h"
1920

20-
#include <Arduino.h>
21-
2221
#include <memory>
2322

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

8483
// Arduino setup function
8584
void setup() {
86-
::Serial.begin(115'200);
85+
// esp_log_level_set(ESP_LOG_VERBOSE);
86+
87+
Serial::Init();
88+
89+
// esp_log_level_set(ESP_LOG_VERBOSE);
8790

8891
OpenShock::Config::Init();
8992
OpenShock::OtaUpdateManager::Init();

src/serial/Serial.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <freertos/FreeRTOS.h>
2+
3+
#include "serial/Serial.h"
4+
5+
#include <driver/uart.h>
6+
#include <freertos/task.h>
7+
8+
#define TAG "serial::Serial"
9+
10+
#define UART_NUM UART_NUM_0
11+
#define UART_TXP 1
12+
#define UART_RXP 3
13+
#define UART_BUFFER_SIZE 1024
14+
#define UART_QUEUE_SIZE 10
15+
#define UART_BAUD_RATE 115200
16+
17+
using namespace OpenShock;
18+
19+
bool Serial::Init() {
20+
if (uart_is_driver_installed(UART_NUM)) {
21+
return true;
22+
}
23+
24+
// Configure the UART
25+
uart_config_t uart_config = {
26+
.baud_rate = UART_BAUD_RATE,
27+
.data_bits = UART_DATA_8_BITS,
28+
.parity = UART_PARITY_DISABLE,
29+
.stop_bits = UART_STOP_BITS_1,
30+
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
31+
.source_clk = UART_SCLK_DEFAULT,
32+
}; // default values
33+
34+
esp_err_t err;
35+
36+
err = uart_driver_install(UART_NUM, UART_BUFFER_SIZE, UART_BUFFER_SIZE, UART_QUEUE_SIZE, nullptr, 0);
37+
if (err != ESP_OK) {
38+
return false;
39+
}
40+
41+
err = uart_param_config(UART_NUM, &uart_config);
42+
if (err != ESP_OK) {
43+
return false;
44+
}
45+
46+
err = uart_set_pin(UART_NUM, UART_TXP, UART_RXP, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
47+
if (err != ESP_OK) {
48+
return false;
49+
}
50+
51+
uart_
52+
53+
return true;
54+
}

0 commit comments

Comments
 (0)