Skip to content

Commit 32dc4c7

Browse files
committed
Fixed example compilation for esp32
1 parent 1bebbcd commit 32dc4c7

File tree

2 files changed

+26
-21
lines changed
  • examples/esp32_idf/uart

2 files changed

+26
-21
lines changed

examples/esp32_idf/uart/tinyslip_generator/main/main.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "freertos/task.h"
2727
#include "driver/uart.h"
2828
#include "driver/gpio.h"
29-
#include <TinyProtocolFd.h>
29+
#include <TinyProtocolSlip.h>
3030
#include <chrono>
3131
#include <stdio.h>
3232

@@ -67,7 +67,9 @@ void tx_task(void *arg)
6767
{
6868
for (;;)
6969
{
70-
proto.run_tx( 100 );
70+
uint8_t tx_buf[4];
71+
int len = proto.run_tx( tx_buf, sizeof tx_buf );
72+
uart_write_bytes(UART_NUM_1, (const char *)buffer, len);
7173
}
7274
vTaskDelete( NULL );
7375
}
@@ -76,7 +78,9 @@ void rx_task(void *arg)
7678
{
7779
for (;;)
7880
{
79-
proto.run_rx( 100 );
81+
uint8_t rx_buf[4];
82+
int rx_len = uart_read_bytes(UART_NUM_1, (uint8_t *)rx_buf, sizeof rx_buf, 100);
83+
proto.run_rx( rx_buf, rx_len );
8084
}
8185
vTaskDelete( NULL );
8286
}
@@ -105,13 +109,7 @@ void main_task(void *args)
105109
proto.setSendTimeout( 100 );
106110
#endif
107111
/* Redirect all protocol communication to Serial0 UART */
108-
#if defined(TINY_MULTITHREAD)
109-
proto.begin([](void *p, const void *b, int s)->int { return uart_write_bytes(UART_NUM_1, (const char *)b, s); },
110-
[](void *p, void *b, int s)->int { return uart_read_bytes(UART_NUM_1, (uint8_t *)b, s, 10); });
111-
#else
112-
proto.begin([](void *p, const void *b, int s)->int { return uart_tx_chars(UART_NUM_1, (const char *)b, s); },
113-
[](void *p, void *b, int s)->int { return uart_read_bytes(UART_NUM_1, (uint8_t *)b, s, 0); });
114-
#endif
112+
proto.begin();
115113

116114
#if defined(TINY_MULTITHREAD)
117115
xTaskCreate( tx_task, "tx_task", 2096, NULL, 1, NULL );

examples/esp32_idf/uart/tinyslip_loopback/main/main.cpp

+18-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ void tx_task(void *arg)
7272
{
7373
for (;;)
7474
{
75-
proto.run_tx( 100 );
75+
uint8_t tx_buf[4];
76+
int len = proto.run_tx( tx_buf, sizeof tx_buf );
77+
uart_write_bytes(UART_NUM_1, (const char *)buffer, len);
7678
}
7779
vTaskDelete( NULL );
7880
}
@@ -97,24 +99,29 @@ void main_task(void *args)
9799
/* Lets process all incoming frames */
98100
proto.setReceiveCallback( onReceive );
99101
/* Redirect all protocol communication to Serial0 UART */
100-
#if defined(TINY_MULTITHREAD)
101-
proto.begin([](void *p, const void *b, int s)->int { return uart_write_bytes(UART_NUM_1, (const char *)b, s); },
102-
[](void *p, void *b, int s)->int { return uart_read_bytes(UART_NUM_1, (uint8_t *)b, s, 10); });
103-
#else
104-
proto.begin([](void *p, const void *b, int s)->int { return uart_tx_chars(UART_NUM_1, (const char *)b, s); },
105-
[](void *p, void *b, int s)->int { return uart_read_bytes(UART_NUM_1, (uint8_t *)b, s, 0); });
106-
#endif
102+
proto.begin();
107103

108104
#if defined(TINY_MULTITHREAD)
109105
xTaskCreate( tx_task, "tx_task", 2096, NULL, 1, NULL );
110106
#endif
111107
for(;;)
112108
{
113109
#if defined(TINY_MULTITHREAD)
114-
proto.run_rx(100);
110+
uint8_t rx_buf[4];
111+
int rx_len = uart_read_bytes(UART_NUM_1, (uint8_t *)rx_buf, sizeof rx_buf, 10);
112+
proto.run_rx( rx_buf, rx_len );
115113
#else
116-
proto.run_rx();
117-
proto.run_tx();
114+
uint8_t rx_buf[4];
115+
int rx_len = uart_read_bytes(UART_NUM_1, (uint8_t *)rx_buf, sizeof rx_buf, 0);
116+
proto.run_rx( rx_buf, rx_len );
117+
118+
uint8_t tx_buf[4];
119+
int tx_len = proto.run_tx( tx_buf, sizeof tx_buf );
120+
int sent = 0;
121+
while ( sent < tx_len )
122+
{
123+
sent += uart_tx_chars(UART_NUM_1, (const char *)tx_buf + sent, tx_len - sent);
124+
}
118125
#endif
119126
}
120127
vTaskDelete( NULL );

0 commit comments

Comments
 (0)