@geastack/host 0.1.14-uart.1 → 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.
- package/include/host/uart.h +23 -5
- package/package.json +1 -1
package/include/host/uart.h
CHANGED
|
@@ -27,11 +27,29 @@ struct UartFacade {
|
|
|
27
27
|
gea::platform::uart::Uart::close(integer(port));
|
|
28
28
|
}
|
|
29
29
|
template <typename Bytes> double read(double port, Bytes &&bytes) const {
|
|
30
|
-
static_assert(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
}
|
|
35
53
|
}
|
|
36
54
|
template <typename Bytes>
|
|
37
55
|
double write(double port, const Bytes &bytes) const {
|