Skip to content

Commit 09fc023

Browse files
committed
fix: register namespaced host functions directly, remove RSS wrapper modules
- Rewrite C++ ABI table from __esp32_* to gpio::*, i2c::*, mcu::*, serial::* format — RustScript use-import resolves to these strings - Remove programs/framework/ (no forwarding layer needed) - Update blinky and smoke programs to use namespace imports directly - Update test callback and import assertions to match new names
1 parent eb95533 commit 09fc023

8 files changed

Lines changed: 63 additions & 180 deletions

File tree

firmware/host_framework.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -334,30 +334,30 @@ int32_t serial_read(const rustscript_value *args, rustscript_value *result) {
334334
}
335335

336336
constexpr host_export HOST_EXPORTS[] = {
337-
{"__esp32_gpio_configure", 2, gpio_configure},
338-
{"__esp32_gpio_write", 2, gpio_write},
339-
{"__esp32_gpio_read", 1, gpio_read},
340-
{"__esp32_gpio_analog_read", 1, gpio_analog_read},
341-
{"__esp32_gpio_pwm", 4, gpio_pwm},
342-
{"__esp32_i2c_begin", 3, i2c_begin},
343-
{"__esp32_i2c_end", 0, i2c_end},
344-
{"__esp32_i2c_write", 2, i2c_write},
345-
{"__esp32_i2c_write_register", 3, i2c_write_register},
346-
{"__esp32_i2c_read", 2, i2c_read},
347-
{"__esp32_i2c_read_register", 3, i2c_read_register},
348-
{"__esp32_mcu_delay_ms", 1, mcu_delay_ms},
349-
{"__esp32_mcu_delay_us", 1, mcu_delay_us},
350-
{"__esp32_mcu_millis", 0, mcu_millis},
351-
{"__esp32_mcu_micros", 0, mcu_micros},
352-
{"__esp32_mcu_cpu_frequency_mhz", 0, mcu_cpu_frequency},
353-
{"__esp32_mcu_free_heap", 0, mcu_free_heap},
354-
{"__esp32_mcu_flash_size", 0, mcu_flash_size},
355-
{"__esp32_mcu_random", 0, mcu_random},
356-
{"__esp32_mcu_restart", 0, mcu_restart},
357-
{"__esp32_mcu_deep_sleep_us", 1, mcu_deep_sleep},
358-
{"__esp32_serial_write", 1, serial_write},
359-
{"__esp32_serial_available", 0, serial_available},
360-
{"__esp32_serial_read", 1, serial_read},
337+
{"gpio::configure", 2, gpio_configure},
338+
{"gpio::digital_write", 2, gpio_write},
339+
{"gpio::digital_read", 1, gpio_read},
340+
{"gpio::analog_read", 1, gpio_analog_read},
341+
{"gpio::pwm_write", 4, gpio_pwm},
342+
{"i2c::open", 3, i2c_begin},
343+
{"i2c::close", 0, i2c_end},
344+
{"i2c::transmit", 2, i2c_write},
345+
{"i2c::transmit_register", 3, i2c_write_register},
346+
{"i2c::receive", 2, i2c_read},
347+
{"i2c::receive_register", 3, i2c_read_register},
348+
{"mcu::delay_ms", 1, mcu_delay_ms},
349+
{"mcu::delay_us", 1, mcu_delay_us},
350+
{"mcu::millis", 0, mcu_millis},
351+
{"mcu::micros", 0, mcu_micros},
352+
{"mcu::cpu_frequency_mhz", 0, mcu_cpu_frequency},
353+
{"mcu::free_heap", 0, mcu_free_heap},
354+
{"mcu::flash_size", 0, mcu_flash_size},
355+
{"mcu::random", 0, mcu_random},
356+
{"mcu::restart", 0, mcu_restart},
357+
{"mcu::deep_sleep_us", 1, mcu_deep_sleep},
358+
{"serial::write_line", 1, serial_write},
359+
{"serial::available", 0, serial_available},
360+
{"serial::read_bytes", 1, serial_read},
361361
};
362362

363363
bool host_name_equals(const uint8_t *name, size_t name_len, const char *expected) {

programs/esp32-blinky.rss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use framework::gpio as gpio;
2-
use framework::mcu as mcu;
3-
use framework::serial as serial;
1+
use gpio;
2+
use mcu;
3+
use serial;
44

55
let led_pin = 8;
66
let configured: bool = gpio::configure(led_pin, 1);

programs/framework-api-smoke.rss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use framework::gpio as gpio;
2-
use framework::i2c as i2c;
3-
use framework::mcu as mcu;
4-
use framework::serial as serial;
1+
use gpio;
2+
use i2c;
3+
use mcu;
4+
use serial;
55

66
let configured: bool = gpio::configure(8, 1);
77
let written: bool = gpio::digital_write(8, configured);

programs/framework/gpio.rss

Lines changed: 0 additions & 26 deletions
This file was deleted.

programs/framework/i2c.rss

Lines changed: 0 additions & 32 deletions
This file was deleted.

programs/framework/mcu.rss

Lines changed: 0 additions & 50 deletions
This file was deleted.

programs/framework/serial.rss

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/ffi.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ unsafe extern "C" fn host_callback(
3232
let name = unsafe { slice::from_raw_parts(name, name_len) };
3333
let args = unsafe { slice::from_raw_parts(args, arg_count) };
3434
match name {
35-
b"__esp32_gpio_configure"
35+
b"gpio::configure"
3636
if args.len() == 2
3737
&& args[0].tag == RustScriptValueTag::Int as u8
3838
&& args[1].tag == RustScriptValueTag::Int as u8 =>
@@ -41,7 +41,7 @@ unsafe extern "C" fn host_callback(
4141
state.mode = args[1].integer;
4242
unsafe { set_bool_result(result, true) }
4343
}
44-
b"__esp32_gpio_write"
44+
b"gpio::digital_write" | b"gpio_digital_write"
4545
if args.len() == 2
4646
&& args[0].tag == RustScriptValueTag::Int as u8
4747
&& args[1].tag == RustScriptValueTag::Bool as u8 =>
@@ -51,18 +51,18 @@ unsafe extern "C" fn host_callback(
5151
state.gpio_writes += 1;
5252
unsafe { set_bool_result(result, true) }
5353
}
54-
b"__esp32_gpio_read" if args.len() == 1 && args[0].tag == RustScriptValueTag::Int as u8 => {
54+
b"gpio::digital_read"
55+
if args.len() == 1 && args[0].tag == RustScriptValueTag::Int as u8 =>
56+
{
5557
state.pin = args[0].integer;
5658
state.gpio_reads += 1;
5759
unsafe { set_bool_result(result, state.high) }
5860
}
59-
b"__esp32_mcu_delay_ms"
60-
if args.len() == 1 && args[0].tag == RustScriptValueTag::Int as u8 =>
61-
{
61+
b"mcu::delay_ms" if args.len() == 1 && args[0].tag == RustScriptValueTag::Int as u8 => {
6262
state.delayed_ms += args[0].integer;
6363
0
6464
}
65-
b"__esp32_serial_write"
65+
b"serial::write_line"
6666
if args.len() == 1 && args[0].tag == RustScriptValueTag::String as u8 =>
6767
{
6868
if args[0].len != 0 && args[0].data.is_null() {
@@ -116,8 +116,8 @@ fn scalar_ffi_values_round_trip() {
116116
fn c_abi_runs_vmbc_and_dispatches_host_call() {
117117
let bytes = compile_vmbc(
118118
r#"
119-
fn __esp32_gpio_write(pin: int, high: bool) -> bool;
120-
let ok: bool = __esp32_gpio_write(8, true);
119+
fn gpio_digital_write(pin: int, high: bool) -> bool;
120+
let ok: bool = gpio_digital_write(8, true);
121121
"#,
122122
);
123123
let mut state = BoardState::default();
@@ -167,7 +167,7 @@ fn esp32_program_runs_through_real_ffi_path() {
167167
}
168168

169169
#[test]
170-
fn framework_modules_compile_to_private_board_imports() {
170+
fn framework_namespace_imports_compile_correctly() {
171171
let source =
172172
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("programs/framework-api-smoke.rss");
173173
let compiled = compile_source_file(&source).expect("framework API should compile");
@@ -179,21 +179,28 @@ fn framework_modules_compile_to_private_board_imports() {
179179
.collect::<std::collections::BTreeSet<_>>();
180180

181181
for expected in [
182-
"__esp32_gpio_configure",
183-
"__esp32_gpio_write",
184-
"__esp32_gpio_read",
185-
"__esp32_gpio_analog_read",
186-
"__esp32_gpio_pwm",
187-
"__esp32_i2c_begin",
188-
"__esp32_i2c_end",
189-
"__esp32_i2c_write",
190-
"__esp32_i2c_write_register",
191-
"__esp32_i2c_read",
192-
"__esp32_i2c_read_register",
193-
"__esp32_mcu_delay_ms",
194-
"__esp32_mcu_free_heap",
195-
"__esp32_serial_write",
196-
"__esp32_serial_read",
182+
"gpio::configure",
183+
"gpio::digital_write",
184+
"gpio::digital_read",
185+
"gpio::analog_read",
186+
"gpio::pwm_write",
187+
"i2c::open",
188+
"i2c::close",
189+
"i2c::transmit",
190+
"i2c::transmit_register",
191+
"i2c::receive",
192+
"i2c::receive_register",
193+
"mcu::delay_ms",
194+
"mcu::delay_us",
195+
"mcu::millis",
196+
"mcu::micros",
197+
"mcu::cpu_frequency_mhz",
198+
"mcu::free_heap",
199+
"mcu::flash_size",
200+
"mcu::random",
201+
"serial::write_line",
202+
"serial::available",
203+
"serial::read_bytes",
197204
] {
198205
assert!(imports.contains(expected), "missing host import {expected}");
199206
}

0 commit comments

Comments
 (0)