@geastack/targets 0.1.102 → 0.1.103

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.102",
3
+ "version": "0.1.103",
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.33",
41
- "@geastack/core": "^0.1.40",
41
+ "@geastack/core": "0.1.42",
42
42
  "@geastack/elements": "^0.1.6",
43
43
  "@geastack/engine": "^0.1.17",
44
44
  "@geastack/geaos": "^0.1.3",
45
- "@geastack/geatsc-plugin-gea": "^0.1.22",
46
- "@geastack/host": "^0.1.15"
45
+ "@geastack/geatsc-plugin-gea": "0.1.23",
46
+ "@geastack/host": "0.1.17"
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"
@@ -75,6 +75,7 @@ idf_component_register(
75
75
  # flag travels through the link INTERFACE because this component is a static
76
76
  # archive, so a PRIVATE option would stop at the archive.
77
77
  target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl$<COMMA>-u$<COMMA>gea_gpio_link_bindings")
78
+ target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl$<COMMA>-u$<COMMA>gea_uart_link_bindings")
78
79
  if(GEA_EMBEDDED_APP)
79
80
  target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl$<COMMA>-u$<COMMA>gea_mjpeg_link_bindings")
80
81
  endif()
@@ -248,6 +248,7 @@ endif()
248
248
  list(APPEND GEA_FW_CXX_SOURCES
249
249
  "${GEA_HOST}/host/gpio.cpp"
250
250
  "${GEA_EMBEDDED_ROOT}/targets/esp32/gpio.cpp"
251
+ "${GEA_EMBEDDED_ROOT}/targets/esp32/uart.cpp"
251
252
  )
252
253
 
253
254
  function(gea_framework_compile_definitions)
@@ -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
+ }
@@ -0,0 +1,68 @@
1
+ #pragma once
2
+
3
+ // Override through the Mosaico board's package.json defines. Defaults retain
4
+ // the original H1 12 -> H2 12 and H1 11 <- H2 11 side-header harness.
5
+ #ifndef GEA_MOSAICO_PEER_LEFT_TX_GPIO
6
+ #define GEA_MOSAICO_PEER_LEFT_TX_GPIO 15
7
+ #endif
8
+ #ifndef GEA_MOSAICO_PEER_LEFT_RX_GPIO
9
+ #define GEA_MOSAICO_PEER_LEFT_RX_GPIO 4
10
+ #endif
11
+ #ifndef GEA_MOSAICO_PEER_RIGHT_TX_GPIO
12
+ #define GEA_MOSAICO_PEER_RIGHT_TX_GPIO 5
13
+ #endif
14
+ #ifndef GEA_MOSAICO_PEER_RIGHT_RX_GPIO
15
+ #define GEA_MOSAICO_PEER_RIGHT_RX_GPIO 38
16
+ #endif
17
+
18
+ namespace gea::platform::board::peer {
19
+ struct PinPair {
20
+ int tx;
21
+ int rx;
22
+ };
23
+
24
+ inline constexpr PinPair left{GEA_MOSAICO_PEER_LEFT_TX_GPIO,
25
+ GEA_MOSAICO_PEER_LEFT_RX_GPIO};
26
+ inline constexpr PinPair right{GEA_MOSAICO_PEER_RIGHT_TX_GPIO,
27
+ GEA_MOSAICO_PEER_RIGHT_RX_GPIO};
28
+
29
+ // Only unclaimed V1.2 expansion GPIOs. In this target GPIO0/1 are the unused
30
+ // expansion I2C bus; the onboard touch/sensors use GPIO56/3. Exclude the
31
+ // codec, display, NAND, power controls, USB/JTAG and UART0 console pins.
32
+ constexpr bool isExpansionGpio(int pin) {
33
+ switch (pin) {
34
+ case 0:
35
+ case 1:
36
+ case 4:
37
+ case 5:
38
+ case 10:
39
+ case 11:
40
+ case 12:
41
+ case 13:
42
+ case 14:
43
+ case 15:
44
+ case 16:
45
+ case 17:
46
+ case 18:
47
+ case 19:
48
+ case 38:
49
+ case 39:
50
+ case 46:
51
+ case 47:
52
+ case 48:
53
+ case 53:
54
+ case 55:
55
+ return true;
56
+ default:
57
+ return false;
58
+ }
59
+ }
60
+
61
+ static_assert(isExpansionGpio(left.tx) && isExpansionGpio(left.rx) &&
62
+ isExpansionGpio(right.tx) && isExpansionGpio(right.rx),
63
+ "Mosaico peer UART pins must be unclaimed expansion GPIOs");
64
+ static_assert(left.tx != left.rx && left.tx != right.tx &&
65
+ left.tx != right.rx && left.rx != right.tx &&
66
+ left.rx != right.rx && right.tx != right.rx,
67
+ "Mosaico peer UART requires four distinct GPIOs");
68
+ } // namespace gea::platform::board::peer
@@ -1,86 +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
- #include <array>
7
- namespace {
8
- // Digital side-header link profile. H1 pin 12 -> H2 pin 12 is right TX
9
- // -> left RX; H1 pin 11 <- H2 pin 11 is right RX <- left TX. Connect only
10
- // these signal contacts plus GND; this does not join output power rails.
11
- struct Pins {
12
- uart_port_t uart;
13
- int tx, rx;
14
- };
15
- constexpr std::array<Pins, 2> pins{{{UART_NUM_1, 15, 4}, {UART_NUM_2, 5, 38}}};
16
- bool opened = false;
17
- } // namespace
18
- extern "C" bool gea_mosaico_peer_uart_open(uint32_t baud) {
2
+ #include "mosaico_peer_uart_pins.h"
3
+ #include "platform/uart.h"
4
+
5
+ namespace peer = gea::platform::board::peer;
6
+ using gea::platform::uart::Uart;
7
+
8
+ extern "C" bool gea_board_uart_pin_allowed(int pin) {
19
9
  #if GEA_MOSAICO_CAMERA_ENABLED
20
- // Camera expansion owns these side GPIOs when that capability is enabled.
21
10
  return false;
11
+ #else
12
+ return peer::isExpansionGpio(pin);
22
13
  #endif
23
- if (opened)
24
- return true;
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) {
25
19
  if (baud < 115200 || baud > 5000000)
26
20
  return false;
27
- // Never steal a UART already claimed by another board capability.
28
- for (const auto &p : pins)
29
- if (uart_is_driver_installed(p.uart))
30
- return false;
31
- unsigned installed = 0;
32
- for (const auto &p : pins) {
33
- uart_config_t config{};
34
- config.baud_rate = baud;
35
- config.data_bits = UART_DATA_8_BITS;
36
- config.parity = UART_PARITY_DISABLE;
37
- config.stop_bits = UART_STOP_BITS_1;
38
- config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
39
- config.source_clk = UART_SCLK_DEFAULT;
40
- // RX driver storage and TX ring are reserved once, off the audio path.
41
- if (uart_param_config(p.uart, &config) != ESP_OK ||
42
- uart_set_pin(p.uart, p.tx, p.rx, UART_PIN_NO_CHANGE,
43
- UART_PIN_NO_CHANGE) != ESP_OK ||
44
- uart_driver_install(p.uart, 4096, 4096, 0, nullptr, 0) != ESP_OK) {
45
- for (unsigned i = 0; i < installed; ++i)
46
- uart_driver_delete(pins[i].uart);
47
- for (const auto &reset : pins) {
48
- gpio_reset_pin(static_cast<gpio_num_t>(reset.tx));
49
- gpio_reset_pin(static_cast<gpio_num_t>(reset.rx));
50
- }
51
- return false;
52
- }
53
- ++installed;
54
- uart_set_rx_full_threshold(p.uart, 96);
55
- uart_set_rx_timeout(p.uart, 2);
56
- }
57
- opened = true;
58
- 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;
59
29
  }
60
- extern "C" void gea_mosaico_peer_uart_close(void) {
61
- if (!opened)
62
- return;
63
- for (const auto &p : pins) {
64
- uart_driver_delete(p.uart);
65
- gpio_reset_pin(static_cast<gpio_num_t>(p.tx));
66
- gpio_reset_pin(static_cast<gpio_num_t>(p.rx));
67
- }
68
- opened = false;
30
+ extern "C" void gea_mosaico_peer_uart_close() {
31
+ Uart::close(1);
32
+ Uart::close(2);
69
33
  }
70
34
  extern "C" int gea_mosaico_peer_uart_read(unsigned side, void *bytes,
71
35
  size_t capacity) {
72
- if (!opened || side >= pins.size() || !bytes || !capacity)
73
- return -1;
74
- 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;
75
38
  }
76
39
  extern "C" int gea_mosaico_peer_uart_write(unsigned side, const void *bytes,
77
40
  size_t length) {
78
- if (!opened || side >= pins.size() || !bytes || !length)
79
- return -1;
80
- // The transport task owns this call. DSP only pushes its preallocated queue.
81
- size_t free = 0;
82
- if (uart_get_tx_buffer_free_size(pins[side].uart, &free) != ESP_OK ||
83
- free < length + 32)
84
- return 0;
85
- return uart_write_bytes(pins[side].uart, bytes, length);
41
+ return side < 2 ? Uart::write(static_cast<int>(side) + 1, bytes, length) : -1;
86
42
  }