@geastack/targets 0.1.100-mosaico-pins.1 → 0.1.100-uart.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/targets",
|
|
3
|
-
"version": "0.1.100-
|
|
3
|
+
"version": "0.1.100-uart.2",
|
|
4
4
|
"description": "Native embedded build targets (ESP32-IDF, RP2350) for geastack apps: board sources, target catalog, and CMake glue driven by the gea CLI.",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@geastack/chips": "^0.1.6",
|
|
40
40
|
"@geastack/compiler": "^1.0.25",
|
|
41
|
-
"@geastack/core": "
|
|
41
|
+
"@geastack/core": "0.1.39-uart.1",
|
|
42
42
|
"@geastack/elements": "^0.1.5",
|
|
43
43
|
"@geastack/engine": "^0.1.15",
|
|
44
44
|
"@geastack/geaos": "^0.1.3",
|
|
45
|
-
"@geastack/geatsc-plugin-gea": "
|
|
46
|
-
"@geastack/host": "
|
|
45
|
+
"@geastack/geatsc-plugin-gea": "0.1.21-uart.1",
|
|
46
|
+
"@geastack/host": "0.1.14-uart.2"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"test": "for f in $(git ls-files | grep -E '(^|/)(test[-_][^/]*|[^/]*\\.test)\\.mjs$'); do echo \"==> $f\"; node \"$f\" || exit 1; done"
|
|
@@ -59,6 +59,7 @@ idf_component_register(
|
|
|
59
59
|
# flag travels through the link INTERFACE because this component is a static
|
|
60
60
|
# archive, so a PRIVATE option would stop at the archive.
|
|
61
61
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl$<COMMA>-u$<COMMA>gea_gpio_link_bindings")
|
|
62
|
+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl$<COMMA>-u$<COMMA>gea_uart_link_bindings")
|
|
62
63
|
if(GEA_EMBEDDED_APP)
|
|
63
64
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl$<COMMA>-u$<COMMA>gea_mjpeg_link_bindings")
|
|
64
65
|
endif()
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#include "platform/uart.h"
|
|
2
|
+
#include "driver/gpio.h"
|
|
3
|
+
#include "driver/uart.h"
|
|
4
|
+
#include "soc/soc_caps.h"
|
|
5
|
+
#include <array>
|
|
6
|
+
#include <limits>
|
|
7
|
+
#include <mutex>
|
|
8
|
+
|
|
9
|
+
// Board resource policy is separate from the chip's GPIO matrix capability.
|
|
10
|
+
extern "C" bool gea_board_uart_pin_allowed(int pin) __attribute__((weak));
|
|
11
|
+
extern "C" void gea_uart_link_bindings() {}
|
|
12
|
+
|
|
13
|
+
namespace {
|
|
14
|
+
struct Port {
|
|
15
|
+
bool open = false;
|
|
16
|
+
gea::platform::uart::Config config{-1, -1, 0};
|
|
17
|
+
};
|
|
18
|
+
std::array<Port, SOC_UART_HP_NUM> ports{};
|
|
19
|
+
std::mutex mutex;
|
|
20
|
+
bool validPort(int port) {
|
|
21
|
+
return port >= 0 && port < static_cast<int>(ports.size());
|
|
22
|
+
}
|
|
23
|
+
bool usablePin(int pin, bool output) {
|
|
24
|
+
if (pin < 0 || pin >= GPIO_NUM_MAX)
|
|
25
|
+
return false;
|
|
26
|
+
if (output ? !GPIO_IS_VALID_OUTPUT_GPIO(pin) : !GPIO_IS_VALID_GPIO(pin))
|
|
27
|
+
return false;
|
|
28
|
+
return !gea_board_uart_pin_allowed || gea_board_uart_pin_allowed(pin);
|
|
29
|
+
}
|
|
30
|
+
bool configured(int port) { return validPort(port) && ports[port].open; }
|
|
31
|
+
int writable(int port) {
|
|
32
|
+
std::size_t bytes = 0;
|
|
33
|
+
if (uart_get_tx_buffer_free_size(static_cast<uart_port_t>(port), &bytes) !=
|
|
34
|
+
ESP_OK)
|
|
35
|
+
return -1;
|
|
36
|
+
// IDF's ring buffer also needs an item header and alignment for each write.
|
|
37
|
+
return bytes > 32 ? static_cast<int>(bytes - 32) : 0;
|
|
38
|
+
}
|
|
39
|
+
} // namespace
|
|
40
|
+
|
|
41
|
+
extern "C" bool gea_uart_open(int port, int tx, int rx, int baud, int rxBytes,
|
|
42
|
+
int txBytes) {
|
|
43
|
+
std::lock_guard lock(mutex);
|
|
44
|
+
if (!validPort(port) || !usablePin(tx, true) || !usablePin(rx, false) ||
|
|
45
|
+
tx == rx || baud < 1 || baud > 5000000 || rxBytes < 256 ||
|
|
46
|
+
rxBytes > 65536 || txBytes < 256 || txBytes > 65536)
|
|
47
|
+
return false;
|
|
48
|
+
#if defined(CONFIG_ESP_CONSOLE_UART_NUM)
|
|
49
|
+
if (port == CONFIG_ESP_CONSOLE_UART_NUM)
|
|
50
|
+
return false;
|
|
51
|
+
#endif
|
|
52
|
+
const auto uart = static_cast<uart_port_t>(port);
|
|
53
|
+
if (ports[port].open) {
|
|
54
|
+
const auto &old = ports[port].config;
|
|
55
|
+
return old.tx == tx && old.rx == rx && old.baudRate == baud &&
|
|
56
|
+
old.rxBufferSize == rxBytes && old.txBufferSize == txBytes;
|
|
57
|
+
}
|
|
58
|
+
if (uart_is_driver_installed(uart))
|
|
59
|
+
return false;
|
|
60
|
+
for (const auto &other : ports) {
|
|
61
|
+
if (other.open && (other.config.tx == tx || other.config.rx == tx ||
|
|
62
|
+
other.config.tx == rx || other.config.rx == rx))
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
uart_config_t config{};
|
|
66
|
+
config.baud_rate = baud;
|
|
67
|
+
config.data_bits = UART_DATA_8_BITS;
|
|
68
|
+
config.parity = UART_PARITY_DISABLE;
|
|
69
|
+
config.stop_bits = UART_STOP_BITS_1;
|
|
70
|
+
config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
|
|
71
|
+
config.source_clk = UART_SCLK_DEFAULT;
|
|
72
|
+
// Allocate before routing pins: a failed allocation cannot disturb the
|
|
73
|
+
// harness.
|
|
74
|
+
if (uart_driver_install(uart, rxBytes, txBytes, 0, nullptr, 0) != ESP_OK)
|
|
75
|
+
return false;
|
|
76
|
+
if (uart_param_config(uart, &config) != ESP_OK ||
|
|
77
|
+
uart_set_pin(uart, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) !=
|
|
78
|
+
ESP_OK ||
|
|
79
|
+
uart_set_rx_full_threshold(uart, 96) != ESP_OK ||
|
|
80
|
+
uart_set_rx_timeout(uart, 2) != ESP_OK) {
|
|
81
|
+
uart_driver_delete(uart);
|
|
82
|
+
gpio_reset_pin(static_cast<gpio_num_t>(tx));
|
|
83
|
+
gpio_reset_pin(static_cast<gpio_num_t>(rx));
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
ports[port] = {true, {tx, rx, baud, rxBytes, txBytes}};
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
extern "C" bool gea_uart_is_open(int port) {
|
|
90
|
+
std::lock_guard lock(mutex);
|
|
91
|
+
return configured(port);
|
|
92
|
+
}
|
|
93
|
+
extern "C" void gea_uart_close(int port) {
|
|
94
|
+
std::lock_guard lock(mutex);
|
|
95
|
+
if (!configured(port))
|
|
96
|
+
return;
|
|
97
|
+
uart_driver_delete(static_cast<uart_port_t>(port));
|
|
98
|
+
gpio_reset_pin(static_cast<gpio_num_t>(ports[port].config.tx));
|
|
99
|
+
gpio_reset_pin(static_cast<gpio_num_t>(ports[port].config.rx));
|
|
100
|
+
ports[port] = {};
|
|
101
|
+
}
|
|
102
|
+
extern "C" int gea_uart_read(int port, void *bytes, std::size_t capacity) {
|
|
103
|
+
std::lock_guard lock(mutex);
|
|
104
|
+
if (!configured(port) || (!bytes && capacity) ||
|
|
105
|
+
capacity > std::numeric_limits<int>::max())
|
|
106
|
+
return -1;
|
|
107
|
+
return capacity ? uart_read_bytes(static_cast<uart_port_t>(port), bytes,
|
|
108
|
+
capacity, 0)
|
|
109
|
+
: 0;
|
|
110
|
+
}
|
|
111
|
+
extern "C" int gea_uart_write(int port, const void *bytes, std::size_t length) {
|
|
112
|
+
std::lock_guard lock(mutex);
|
|
113
|
+
if (!configured(port) || (!bytes && length) ||
|
|
114
|
+
length > std::numeric_limits<int>::max())
|
|
115
|
+
return -1;
|
|
116
|
+
if (!length)
|
|
117
|
+
return 0;
|
|
118
|
+
const int free = writable(port);
|
|
119
|
+
if (free < 0)
|
|
120
|
+
return -1;
|
|
121
|
+
if (length > static_cast<std::size_t>(free))
|
|
122
|
+
return 0;
|
|
123
|
+
return uart_write_bytes(static_cast<uart_port_t>(port), bytes, length);
|
|
124
|
+
}
|
|
125
|
+
extern "C" int gea_uart_available(int port) {
|
|
126
|
+
std::lock_guard lock(mutex);
|
|
127
|
+
if (!configured(port))
|
|
128
|
+
return -1;
|
|
129
|
+
std::size_t bytes = 0;
|
|
130
|
+
return uart_get_buffered_data_len(static_cast<uart_port_t>(port), &bytes) ==
|
|
131
|
+
ESP_OK
|
|
132
|
+
? static_cast<int>(bytes)
|
|
133
|
+
: -1;
|
|
134
|
+
}
|
|
135
|
+
extern "C" int gea_uart_writable(int port) {
|
|
136
|
+
std::lock_guard lock(mutex);
|
|
137
|
+
return configured(port) ? writable(port) : -1;
|
|
138
|
+
}
|
|
@@ -1,89 +1,42 @@
|
|
|
1
|
-
#include "driver/gpio.h"
|
|
2
|
-
#include "driver/uart.h"
|
|
3
|
-
#include "esp_err.h"
|
|
4
|
-
#include "freertos/FreeRTOS.h"
|
|
5
1
|
#include "mosaico_peer_uart.h"
|
|
6
2
|
#include "mosaico_peer_uart_pins.h"
|
|
7
|
-
#include
|
|
8
|
-
|
|
9
|
-
// The board validates configurable signal contacts before either UART opens.
|
|
10
|
-
// Adjacent boards also need common ground; never join output power rails.
|
|
11
|
-
struct Pins {
|
|
12
|
-
uart_port_t uart;
|
|
13
|
-
int tx, rx;
|
|
14
|
-
};
|
|
3
|
+
#include "platform/uart.h"
|
|
4
|
+
|
|
15
5
|
namespace peer = gea::platform::board::peer;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
bool opened = false;
|
|
20
|
-
} // namespace
|
|
21
|
-
extern "C" bool gea_mosaico_peer_uart_open(uint32_t baud) {
|
|
6
|
+
using gea::platform::uart::Uart;
|
|
7
|
+
|
|
8
|
+
extern "C" bool gea_board_uart_pin_allowed(int pin) {
|
|
22
9
|
#if GEA_MOSAICO_CAMERA_ENABLED
|
|
23
|
-
// Camera expansion owns these side GPIOs when that capability is enabled.
|
|
24
10
|
return false;
|
|
11
|
+
#else
|
|
12
|
+
return peer::isExpansionGpio(pin);
|
|
25
13
|
#endif
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Compatibility for native apps using the original side-link entry points.
|
|
17
|
+
// New applications configure controllers through the public Uart API.
|
|
18
|
+
extern "C" bool gea_mosaico_peer_uart_open(uint32_t baud) {
|
|
28
19
|
if (baud < 115200 || baud > 5000000)
|
|
29
20
|
return false;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
config.data_bits = UART_DATA_8_BITS;
|
|
39
|
-
config.parity = UART_PARITY_DISABLE;
|
|
40
|
-
config.stop_bits = UART_STOP_BITS_1;
|
|
41
|
-
config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
|
|
42
|
-
config.source_clk = UART_SCLK_DEFAULT;
|
|
43
|
-
// RX driver storage and TX ring are reserved once, off the audio path.
|
|
44
|
-
if (uart_param_config(p.uart, &config) != ESP_OK ||
|
|
45
|
-
uart_set_pin(p.uart, p.tx, p.rx, UART_PIN_NO_CHANGE,
|
|
46
|
-
UART_PIN_NO_CHANGE) != ESP_OK ||
|
|
47
|
-
uart_driver_install(p.uart, 4096, 4096, 0, nullptr, 0) != ESP_OK) {
|
|
48
|
-
for (unsigned i = 0; i < installed; ++i)
|
|
49
|
-
uart_driver_delete(pins[i].uart);
|
|
50
|
-
for (const auto &reset : pins) {
|
|
51
|
-
gpio_reset_pin(static_cast<gpio_num_t>(reset.tx));
|
|
52
|
-
gpio_reset_pin(static_cast<gpio_num_t>(reset.rx));
|
|
53
|
-
}
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
++installed;
|
|
57
|
-
uart_set_rx_full_threshold(p.uart, 96);
|
|
58
|
-
uart_set_rx_timeout(p.uart, 2);
|
|
59
|
-
}
|
|
60
|
-
opened = true;
|
|
61
|
-
return true;
|
|
21
|
+
const bool leftWasOpen = Uart::isOpen(1);
|
|
22
|
+
if (!Uart::open(1, {peer::left.tx, peer::left.rx, static_cast<int>(baud)}))
|
|
23
|
+
return false;
|
|
24
|
+
if (Uart::open(2, {peer::right.tx, peer::right.rx, static_cast<int>(baud)}))
|
|
25
|
+
return true;
|
|
26
|
+
if (!leftWasOpen)
|
|
27
|
+
Uart::close(1);
|
|
28
|
+
return false;
|
|
62
29
|
}
|
|
63
|
-
extern "C" void gea_mosaico_peer_uart_close(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (const auto &p : pins) {
|
|
67
|
-
uart_driver_delete(p.uart);
|
|
68
|
-
gpio_reset_pin(static_cast<gpio_num_t>(p.tx));
|
|
69
|
-
gpio_reset_pin(static_cast<gpio_num_t>(p.rx));
|
|
70
|
-
}
|
|
71
|
-
opened = false;
|
|
30
|
+
extern "C" void gea_mosaico_peer_uart_close() {
|
|
31
|
+
Uart::close(1);
|
|
32
|
+
Uart::close(2);
|
|
72
33
|
}
|
|
73
34
|
extern "C" int gea_mosaico_peer_uart_read(unsigned side, void *bytes,
|
|
74
35
|
size_t capacity) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return uart_read_bytes(pins[side].uart, bytes, capacity, 0);
|
|
36
|
+
return side < 2 ? Uart::read(static_cast<int>(side) + 1, bytes, capacity)
|
|
37
|
+
: -1;
|
|
78
38
|
}
|
|
79
39
|
extern "C" int gea_mosaico_peer_uart_write(unsigned side, const void *bytes,
|
|
80
40
|
size_t length) {
|
|
81
|
-
|
|
82
|
-
return -1;
|
|
83
|
-
// The transport task owns this call. DSP only pushes its preallocated queue.
|
|
84
|
-
size_t free = 0;
|
|
85
|
-
if (uart_get_tx_buffer_free_size(pins[side].uart, &free) != ESP_OK ||
|
|
86
|
-
free < length + 32)
|
|
87
|
-
return 0;
|
|
88
|
-
return uart_write_bytes(pins[side].uart, bytes, length);
|
|
41
|
+
return side < 2 ? Uart::write(static_cast<int>(side) + 1, bytes, length) : -1;
|
|
89
42
|
}
|