-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
7745c8e
There was a problem hiding this comment.
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
Have any feedback or feature suggestions? Share it here.