configure uart serial
This commit is contained in:
parent
a3d0dfdfbc
commit
e7f0e18d32
3 changed files with 55 additions and 8 deletions
|
@ -7,9 +7,22 @@
|
|||
#include <driver/uart.h>
|
||||
|
||||
#include "comm_esp32_hardwareserial.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
comm_esp32_hardwareserial::comm_esp32_hardwareserial(const int uart_nr, const int rx_pin, const int tx_pin, const int bitrate) : uart_nr(uart_nr)
|
||||
comm_esp32_hardwareserial::comm_esp32_hardwareserial(const int uart_nr, const int rx_pin, const int tx_pin, const int bitrate) :
|
||||
uart_nr(uart_nr),
|
||||
rx_pin(rx_pin), tx_pin(tx_pin),
|
||||
bitrate(bitrate)
|
||||
{
|
||||
}
|
||||
|
||||
comm_esp32_hardwareserial::~comm_esp32_hardwareserial()
|
||||
{
|
||||
ESP_ERROR_CHECK(uart_driver_delete(uart_nr));
|
||||
}
|
||||
|
||||
bool comm_esp32_hardwareserial::begin()
|
||||
{
|
||||
// Configure UART parameters
|
||||
static uart_config_t uart_config = {
|
||||
|
@ -20,20 +33,32 @@ comm_esp32_hardwareserial::comm_esp32_hardwareserial(const int uart_nr, const in
|
|||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.rx_flow_ctrl_thresh = 122,
|
||||
};
|
||||
ESP_ERROR_CHECK(uart_param_config(uart_nr, &uart_config));
|
||||
|
||||
ESP_ERROR_CHECK(uart_set_pin(uart_nr, tx_pin, rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
if (uart_param_config(uart_nr, &uart_config) != ESP_OK) {
|
||||
DOLOG(warning, false, "uart_param_config(%d, %d) failed", uart_nr, bitrate);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (uart_set_pin(uart_nr, tx_pin, rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) != ESP_OK) {
|
||||
DOLOG(warning, false, "uart_set_pin(%d, %d, %d) failed", uart_nr, rx_pin, tx_pin);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup UART buffered IO with event queue
|
||||
const int uart_buffer_size = 1024 * 2;
|
||||
static QueueHandle_t uart_queue;
|
||||
// Install UART driver using an event queue here
|
||||
ESP_ERROR_CHECK(uart_driver_install(uart_nr, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
|
||||
if (uart_driver_install(uart_nr, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0) != ESP_OK) {
|
||||
DOLOG(warning, false, "uart_driver_install(%d) failed", uart_nr);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
comm_esp32_hardwareserial::~comm_esp32_hardwareserial()
|
||||
std::string comm_esp32_hardwareserial::get_identifier() const
|
||||
{
|
||||
ESP_ERROR_CHECK(uart_driver_delete(uart_nr));
|
||||
return format("UART:%d/RX:%d/TX:%d/@:%d", uart_nr, rx_pin, tx_pin, bitrate);
|
||||
}
|
||||
|
||||
bool comm_esp32_hardwareserial::is_connected()
|
||||
|
|
|
@ -3,17 +3,25 @@
|
|||
|
||||
#include "gen.h"
|
||||
#include "comm.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
class comm_esp32_hardwareserial: public comm
|
||||
{
|
||||
private:
|
||||
const int uart_nr { 1};
|
||||
const int uart_nr { 1 };
|
||||
const int rx_pin { -1 };
|
||||
const int tx_pin { -1 };
|
||||
const int bitrate { 38400 };
|
||||
|
||||
public:
|
||||
comm_esp32_hardwareserial(const int uart_nr, const int rx_pin, const int tx_pin, const int bps);
|
||||
virtual ~comm_esp32_hardwareserial();
|
||||
|
||||
bool begin() override;
|
||||
|
||||
std::string get_identifier() const;
|
||||
|
||||
bool is_connected() override;
|
||||
|
||||
bool has_data() override;
|
||||
|
|
16
debugger.cpp
16
debugger.cpp
|
@ -14,11 +14,16 @@
|
|||
|
||||
#include "breakpoint_parser.h"
|
||||
#include "bus.h"
|
||||
#if IS_POSIX
|
||||
#include "comm_posix_tty.h"
|
||||
#endif
|
||||
#include "comm_tcp_socket_client.h"
|
||||
#include "comm_tcp_socket_server.h"
|
||||
#include "console.h"
|
||||
#include "cpu.h"
|
||||
#if defined(ESP32)
|
||||
#include "comm_esp32_hardwareserial.h"
|
||||
#endif
|
||||
#include "disk_backend.h"
|
||||
#if IS_POSIX || defined(_WIN32)
|
||||
#include "disk_backend_file.h"
|
||||
|
@ -298,8 +303,17 @@ void configure_comm(console *const cnsl, std::vector<comm *> & device_list)
|
|||
device_list.at(device_nr) = new comm_posix_tty(temp_dev, std::stoi(temp_bitrate));
|
||||
rc = device_list.at(device_nr)->begin();
|
||||
}
|
||||
#elif defined(ESP32)
|
||||
std::string temp_dev = cnsl->read_line("Uart number (0...2): ");
|
||||
std::string temp_rx = cnsl->read_line("RX pin: ");
|
||||
std::string temp_tx = cnsl->read_line("TX pin: ");
|
||||
std::string temp_bitrate = cnsl->read_line("bitrate: ");
|
||||
if (temp_dev.empty() == false && temp_bitrate.empty() == false && temp_rx.empty() == false && temp_tx.empty() == false) {
|
||||
delete device_list.at(device_nr);
|
||||
device_list.at(device_nr) = new comm_esp32_hardwareserial(std::stoi(temp_dev), std::stoi(temp_rx), std::stoi(temp_tx), std::stoi(temp_bitrate));
|
||||
rc = device_list.at(device_nr)->begin();
|
||||
}
|
||||
#else
|
||||
// TODO
|
||||
cnsl->put_string_lf("Not implemented yet");
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue