@geastack/core 0.1.41 → 0.1.42

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.
@@ -0,0 +1,58 @@
1
+ #pragma once
2
+
3
+ #include <cstddef>
4
+ #include <cstdint>
5
+
6
+ // Target-owned implementation. Unsupported platforms report unavailable.
7
+ extern "C" {
8
+ bool gea_uart_open(int port, int tx, int rx, int baud, int rxBytes, int txBytes)
9
+ __attribute__((weak));
10
+ bool gea_uart_is_open(int port) __attribute__((weak));
11
+ void gea_uart_close(int port) __attribute__((weak));
12
+ int gea_uart_read(int port, void *bytes, std::size_t capacity)
13
+ __attribute__((weak));
14
+ int gea_uart_write(int port, const void *bytes, std::size_t length)
15
+ __attribute__((weak));
16
+ int gea_uart_available(int port) __attribute__((weak));
17
+ int gea_uart_writable(int port) __attribute__((weak));
18
+ }
19
+
20
+ namespace gea::platform::uart {
21
+ struct Config {
22
+ int tx;
23
+ int rx;
24
+ int baudRate;
25
+ int rxBufferSize = 4096;
26
+ int txBufferSize = 4096;
27
+ };
28
+
29
+ class Uart {
30
+ public:
31
+ static bool open(int port, const Config &config) {
32
+ return gea_uart_open &&
33
+ gea_uart_open(port, config.tx, config.rx, config.baudRate,
34
+ config.rxBufferSize, config.txBufferSize);
35
+ }
36
+ static bool isOpen(int port) {
37
+ return gea_uart_is_open && gea_uart_is_open(port);
38
+ }
39
+ static void close(int port) {
40
+ if (gea_uart_close)
41
+ gea_uart_close(port);
42
+ }
43
+ // Nonblocking. -1 means unavailable/closed/error; 0 means no progress.
44
+ static int read(int port, void *bytes, std::size_t capacity) {
45
+ return gea_uart_read ? gea_uart_read(port, bytes, capacity) : -1;
46
+ }
47
+ // Enqueues the complete buffer, or returns 0 if it cannot fit yet.
48
+ static int write(int port, const void *bytes, std::size_t length) {
49
+ return gea_uart_write ? gea_uart_write(port, bytes, length) : -1;
50
+ }
51
+ static int available(int port) {
52
+ return gea_uart_available ? gea_uart_available(port) : -1;
53
+ }
54
+ static int writable(int port) {
55
+ return gea_uart_writable ? gea_uart_writable(port) : -1;
56
+ }
57
+ };
58
+ } // namespace gea::platform::uart
package/index.d.ts CHANGED
@@ -1322,6 +1322,33 @@ export interface GpioController {
1322
1322
 
1323
1323
  export declare const Gpio: GpioController
1324
1324
 
1325
+ export interface UartOptions {
1326
+ tx: number
1327
+ rx: number
1328
+ baudRate: number
1329
+ /** Receive/transmit queue bytes. Defaults to 4096 each. */
1330
+ rxBufferSize?: number
1331
+ txBufferSize?: number
1332
+ }
1333
+
1334
+ /** Hardware UART, 8 data bits, no parity, one stop bit (8N1). */
1335
+ export interface UartController {
1336
+ /** Claims a free controller and pins. False on conflict/invalid configuration. */
1337
+ open(port: number, options: UartOptions): boolean
1338
+ isOpen(port: number): boolean
1339
+ close(port: number): void
1340
+ /** Nonblocking read into the supplied view; returns bytes read, or -1 on error. */
1341
+ read(port: number, buffer: Uint8Array): number
1342
+ /** Nonblocking whole-buffer enqueue; 0 means backpressure, -1 means error. */
1343
+ write(port: number, buffer: Uint8Array): number
1344
+ /** Queued readable bytes, or -1 when unavailable. */
1345
+ available(port: number): number
1346
+ /** Writable queue capacity, or -1 when unavailable. */
1347
+ writable(port: number): number
1348
+ }
1349
+
1350
+ export declare const Uart: UartController
1351
+
1325
1352
  export interface LedController {
1326
1353
  // A WS2812/NeoPixel strand on one pin — what "the onboard LED" is on most
1327
1354
  // modern ESP32 modules.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/core",
3
- "version": "0.1.41",
3
+ "version": "0.1.42",
4
4
  "description": "GeaStack app API, reactivity headers, runtime sources, and type declarations.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "@geajs/core": "1.5.1",
67
67
  "@geajs/vite-plugin": "1.5.0",
68
68
  "@geastack/compiler": "^1.0.29",
69
- "@geastack/geatsc-plugin-gea": "^0.1.22",
69
+ "@geastack/geatsc-plugin-gea": "0.1.23",
70
70
  "opentype.js": "^2.0.0",
71
71
  "vite": "^8.0.0"
72
72
  }
package/runtime/host.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  // fails the representation coverage guard for the whole `Geolocation` literal
7
7
  // below. lib.dom's GeolocationPositionError also carries PERMISSION_DENIED /
8
8
  // POSITION_UNAVAILABLE / TIMEOUT, which our host object never sets.
9
+ import type { UartOptions } from '../index'
9
10
  import type {
10
11
  CanvasRenderingContext2D,
11
12
  GeolocationCoordinates,
@@ -354,6 +355,15 @@ declare const __gea_Gpio: {
354
355
  write(pin: number, level: boolean): boolean
355
356
  read(pin: number): boolean
356
357
  }
358
+ declare const __gea_Uart: {
359
+ open(port: number, tx: number, rx: number, baud: number, rxBytes: number, txBytes: number): boolean
360
+ isOpen(port: number): boolean
361
+ close(port: number): void
362
+ read(port: number, buffer: Uint8Array): number
363
+ write(port: number, buffer: Uint8Array): number
364
+ available(port: number): number
365
+ writable(port: number): number
366
+ }
357
367
  declare const __gea_Led: {
358
368
  // A WS2812/NeoPixel strand on one pin — what "the onboard LED" is on most
359
369
  // modern ESP32 modules. set() is the one-call default (attach if needed,
@@ -1031,6 +1041,31 @@ export const Gpio = {
1031
1041
  return __gea_Gpio.read(pin)
1032
1042
  },
1033
1043
  }
1044
+ export const Uart = {
1045
+ open(port: number, options: UartOptions): boolean {
1046
+ if (typeof __gea_Uart === 'undefined') return false
1047
+ return __gea_Uart.open(port, options.tx, options.rx, options.baudRate,
1048
+ options.rxBufferSize ?? 4096, options.txBufferSize ?? 4096)
1049
+ },
1050
+ isOpen(port: number): boolean {
1051
+ return typeof __gea_Uart !== 'undefined' && __gea_Uart.isOpen(port)
1052
+ },
1053
+ close(port: number): void {
1054
+ if (typeof __gea_Uart !== 'undefined') __gea_Uart.close(port)
1055
+ },
1056
+ read(port: number, buffer: Uint8Array): number {
1057
+ return typeof __gea_Uart !== 'undefined' ? __gea_Uart.read(port, buffer) : -1
1058
+ },
1059
+ write(port: number, buffer: Uint8Array): number {
1060
+ return typeof __gea_Uart !== 'undefined' ? __gea_Uart.write(port, buffer) : -1
1061
+ },
1062
+ available(port: number): number {
1063
+ return typeof __gea_Uart !== 'undefined' ? __gea_Uart.available(port) : -1
1064
+ },
1065
+ writable(port: number): number {
1066
+ return typeof __gea_Uart !== 'undefined' ? __gea_Uart.writable(port) : -1
1067
+ },
1068
+ }
1034
1069
  export const Led = {
1035
1070
  set(pin: number, r: number, g: number, b: number): boolean {
1036
1071
  return __gea_Led.set(pin, r, g, b)
@@ -57,6 +57,8 @@ export type {
57
57
  * gets today.
58
58
  */
59
59
  export type {
60
+ UartOptions,
61
+ UartController,
60
62
  AccelerometerController,
61
63
  AccelerometerReading,
62
64
  AppsController,