Skip to content

Commit

Permalink
Added support for JTAG/USB serial device intended as GND station via …
Browse files Browse the repository at this point in the history
…USB instead of FTDI

To be tested. Compiles already.
  • Loading branch information
seeul8er committed Jun 16, 2024
1 parent e92c488 commit 05bad2f
Show file tree
Hide file tree
Showing 9 changed files with 2,133 additions and 136 deletions.
27 changes: 26 additions & 1 deletion main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
menu "DB Webserver Configuration"
menu "DroneBridge for ESP32 Configuration"

choice
prompt "Serial interface for data."
default DB_SERIAL_OPTION_UART
help
Select serial interface.
USB/JTAG on the official HWv1.x boards for DroneBridge for ESP32 is connected to the USB-C port.
By using this port a ground station can connect to the ESP32 without the use of an UART-to-USB adapter.
Intended for use on ground station ESP32 units directly connected to a GCS computer via USB.
Requires ESP_CONSOLE_SECONDARY_NONE set to yes.
WARNING: No logging available via USB port when USB/JTAG option is selected. Use debugging UART0 as specified by console settings for logging and diagnostics.
config DB_SERIAL_OPTION_UART
bool "UART"
help
Use the UART specified in the web interface for serial communication.
config DB_SERIAL_OPTION_JTAG
bool "USB/JTAG"
depends on ESP_CONSOLE_SECONDARY_NONE
help
Use the JTAG interface for serial communication.
This inferface is attached to the USB port of the official DroneBridge for ESP32 PCB in HW v1.x versions.
A ground control station can connect to the USB port directly without having to use a FTDI in between.
Not intended for connecting to a UAV etc. Use native UART instead.
WARNING: No logging available via USB port.
endchoice

choice WEB_DEPLOY_MODE
prompt "Website deploy mode"
Expand Down
24 changes: 12 additions & 12 deletions main/db_esp32_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ void read_process_uart(int *tcp_clients, uint *transparent_buff_pos, uint *msp_l
break;
case 3:
case 4:
db_parse_mavlink(tcp_clients, udp_conn_list, msp_message_buffer, transparent_buff_pos);
db_read_serial_parse_mavlink(tcp_clients, udp_conn_list, msp_message_buffer, transparent_buff_pos);
break;
case 5:
default:
db_parse_transparent(tcp_clients, udp_conn_list, serial_buffer, transparent_buff_pos);
db_read_serial_parse_transparent(tcp_clients, udp_conn_list, serial_buffer, transparent_buff_pos);
break;
}
}
Expand All @@ -342,10 +342,10 @@ void read_process_uart(int *tcp_clients, uint *transparent_buff_pos, uint *msp_l
*/
_Noreturn void control_module_esp_now(){
ESP_LOGI(TAG, "Starting control module (ESP-NOW)");
// only open serial socket/UART if PINs are not matching - matching PIN nums mean they still need to be defined by
// the user no pre-defined pins as of this release since ESP32 boards have wildly different pin configurations
int uart_socket = open_serial_socket();
if (uart_socket == ESP_FAIL) {
int serial_socket = ESP_FAIL;
// open serial socket for comms with FC or GCS
serial_socket = open_serial_socket();
if (serial_socket == ESP_FAIL) {
ESP_LOGE(TAG, "UART socket not opened. Aborting start of control module.");
vTaskDelete(NULL);
}
Expand All @@ -363,7 +363,7 @@ _Noreturn void control_module_esp_now(){
read_process_uart(NULL, &transparent_buff_pos, &msp_ltm_buff_pos, msp_message_buffer, serial_buffer,
&db_msp_ltm_port);
if (db_uart_write_queue != NULL && xQueueReceive(db_uart_write_queue, &db_espnow_uart_evt, 0) == pdTRUE) {
write_to_uart(db_espnow_uart_evt.data, db_espnow_uart_evt.data_len);
write_to_serial(db_espnow_uart_evt.data, db_espnow_uart_evt.data_len);
free(db_espnow_uart_evt.data);
} else {
if (db_uart_write_queue == NULL) ESP_LOGE(TAG, "db_uart_write_queue is NULL!");
Expand Down Expand Up @@ -474,9 +474,9 @@ void handle_internal_telemetry(int tel_sock, uint8_t *udp_buffer, socklen_t *soc
*/
_Noreturn void control_module_udp_tcp() {
ESP_LOGI(TAG, "Starting control module (Wi-Fi)");
int uart_socket = open_serial_socket();
if (uart_socket == ESP_FAIL) {
ESP_LOGE(TAG, "UART socket not opened. Aborting start of control module.");
esp_err_t serial_socket_status = open_serial_socket();
if (serial_socket_status == ESP_FAIL) {
ESP_LOGE(TAG, "JTAG serial socket not opened. Aborting start of control module.");
vTaskDelete(NULL);
}

Expand Down Expand Up @@ -521,7 +521,7 @@ _Noreturn void control_module_udp_tcp() {
if (tcp_clients[i] > 0) {
ssize_t recv_length = recv(tcp_clients[i], tcp_client_buffer, TCP_BUFF_SIZ, 0);
if (recv_length > 0) {
write_to_uart(tcp_client_buffer, recv_length);
write_to_serial(tcp_client_buffer, recv_length);
} else if (recv_length == 0) {
shutdown(tcp_clients[i], 0);
close(tcp_clients[i]);
Expand All @@ -542,7 +542,7 @@ _Noreturn void control_module_udp_tcp() {
ssize_t recv_length = recvfrom(udp_conn_list->udp_socket, udp_buffer, UDP_BUF_SIZE, 0,
(struct sockaddr *) &new_db_udp_client.udp_client, &udp_socklen);
if (recv_length > 0) {
write_to_uart(udp_buffer, recv_length);
write_to_serial(udp_buffer, recv_length);
// Allows to register new app on different port. Used e.g. for UDP conn setup in sta-mode.
// Devices/Ports added this way cannot be removed in sta-mode since UDP is connectionless, and we cannot
// determine if the client is still existing. This will blow up the list connected devices.
Expand Down
Loading

0 comments on commit 05bad2f

Please sign in to comment.