@geastack/host 0.1.13 → 0.1.14-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.
@@ -23,6 +23,7 @@
23
23
  #include "host/memory.h"
24
24
  #include "host/input.h"
25
25
  #include "host/gpio.h"
26
+ #include "host/uart.h"
26
27
  #include "host/clock.h"
27
28
  #include "host/profiler.h"
28
29
  #include "host/storage.h"
@@ -0,0 +1,69 @@
1
+ #pragma once
2
+
3
+ #include "platform/uart.h"
4
+ #include <cmath>
5
+ #include <limits>
6
+ #include <type_traits>
7
+
8
+ namespace gea::host {
9
+ struct UartFacade {
10
+ static int integer(double value) {
11
+ return std::isfinite(value) && value >= 0 &&
12
+ value <= std::numeric_limits<int>::max() &&
13
+ std::trunc(value) == value
14
+ ? static_cast<int>(value)
15
+ : -1;
16
+ }
17
+ bool open(double port, double tx, double rx, double baud, double rxBytes,
18
+ double txBytes) const {
19
+ return gea::platform::uart::Uart::open(
20
+ integer(port), {integer(tx), integer(rx), integer(baud),
21
+ integer(rxBytes), integer(txBytes)});
22
+ }
23
+ bool isOpen(double port) const {
24
+ return gea::platform::uart::Uart::isOpen(integer(port));
25
+ }
26
+ void close(double port) const {
27
+ gea::platform::uart::Uart::close(integer(port));
28
+ }
29
+ template <typename Bytes> double read(double port, Bytes &&bytes) const {
30
+ static_assert(std::is_same_v<std::remove_cvref_t<decltype(*bytes.data())>,
31
+ std::uint8_t>);
32
+ if constexpr (requires {
33
+ bytes.buffer();
34
+ bytes.byteOffset();
35
+ }) {
36
+ // The compiler passes a const TypedArray VIEW. Its ArrayBuffer remains
37
+ // mutable: receive into that shared backing store, respecting subarrays.
38
+ // data() preserves the runtime's detached-buffer check before accessing
39
+ // it.
40
+ (void)bytes.data();
41
+ const auto count = bytes.size();
42
+ auto *destination = count
43
+ ? bytes.buffer()->data() +
44
+ static_cast<std::size_t>(bytes.byteOffset())
45
+ : nullptr;
46
+ return gea::platform::uart::Uart::read(integer(port), destination, count);
47
+ } else {
48
+ static_assert(
49
+ !std::is_const_v<std::remove_reference_t<decltype(*bytes.data())>>);
50
+ return gea::platform::uart::Uart::read(integer(port), bytes.data(),
51
+ bytes.size());
52
+ }
53
+ }
54
+ template <typename Bytes>
55
+ double write(double port, const Bytes &bytes) const {
56
+ static_assert(std::is_same_v<std::remove_cvref_t<decltype(*bytes.data())>,
57
+ std::uint8_t>);
58
+ return gea::platform::uart::Uart::write(integer(port), bytes.data(),
59
+ bytes.size());
60
+ }
61
+ double available(double port) const {
62
+ return gea::platform::uart::Uart::available(integer(port));
63
+ }
64
+ double writable(double port) const {
65
+ return gea::platform::uart::Uart::writable(integer(port));
66
+ }
67
+ };
68
+ inline constexpr UartFacade Uart{};
69
+ } // namespace gea::host
@@ -169,6 +169,10 @@ class VideoPixels {
169
169
  void* result = nullptr;
170
170
  if (posix_memalign(&result, 16, (bytes + 15) & ~std::size_t(15)) != 0) return nullptr;
171
171
  return static_cast<std::uint16_t*>(result);
172
+ #elif defined(_WIN32)
173
+ // The MSVC CRT has no aligned_alloc: its aligned blocks come from
174
+ // _aligned_malloc and must go back through _aligned_free (see release).
175
+ return static_cast<std::uint16_t*>(_aligned_malloc((bytes + 15) & ~std::size_t(15), 16));
172
176
  #else
173
177
  return static_cast<std::uint16_t*>(::aligned_alloc(16, (bytes + 15) & ~std::size_t(15)));
174
178
  #endif
@@ -177,6 +181,8 @@ class VideoPixels {
177
181
  static void release(std::uint16_t* pointer) noexcept {
178
182
  #ifdef ESP_PLATFORM
179
183
  heap_caps_free(pointer);
184
+ #elif defined(_WIN32)
185
+ _aligned_free(pointer);
180
186
  #else
181
187
  std::free(pointer);
182
188
  #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/host",
3
- "version": "0.1.13",
3
+ "version": "0.1.14-uart.2",
4
4
  "description": "GeaStack host bindings and platform service sources.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {