vex_sdk_jumptable/
lib.rs

1#![no_std]
2#![deny(unsafe_op_in_unsafe_fn)]
3#![allow(non_camel_case_types)]
4#![allow(non_upper_case_globals)]
5#![allow(non_snake_case)]
6#![feature(c_variadic)]
7
8pub mod abs_enc;
9pub mod adi;
10pub mod ai_vision;
11pub mod arm;
12pub mod battery;
13pub mod competition;
14pub mod controller;
15pub mod device;
16pub mod display;
17pub mod distance;
18pub mod file;
19pub mod generic_radio;
20pub mod generic_serial;
21pub mod gps;
22pub mod imu;
23pub mod led;
24pub mod light_tower;
25pub mod magnet;
26pub mod motor;
27pub mod optical;
28pub mod pneumatic;
29pub mod range;
30pub mod serial;
31pub mod system;
32pub mod task;
33pub mod touch;
34pub mod vision;
35
36pub use abs_enc::*;
37pub use adi::*;
38pub use ai_vision::*;
39pub use arm::*;
40pub use battery::*;
41pub use competition::*;
42pub use controller::*;
43pub use device::*;
44pub use display::*;
45pub use distance::*;
46pub use file::*;
47pub use generic_radio::*;
48pub use generic_serial::*;
49pub use gps::*;
50pub use imu::*;
51pub use led::*;
52pub use light_tower::*;
53pub use magnet::*;
54pub use motor::*;
55pub use optical::*;
56pub use pneumatic::*;
57pub use range::*;
58pub use serial::*;
59pub use system::*;
60pub use task::*;
61pub use touch::*;
62pub use vision::*;
63
64pub const JUMP_TABLE_START: usize = 0x037fc000;
65
66#[cfg(not(target_os = "vexos"))]
67compile_error!("`vex-sdk-jumptable` does not support this target.");
68
69#[macro_export]
70macro_rules! map_jump_table {
71    (
72        $(
73            $offset:expr =>
74            $(#[$meta:meta])* $vis:vis fn $name:ident($($arg:ident: $arg_ty:ty $(,)?),*) $(-> $ret:ty)?
75        ),+ $(,)?
76    ) => {
77        $(
78            $(#[$meta])*
79            #[doc = "# Safety\nCalls to jumptable functions are unsafe because jumptable functions are owned by VEXos and we cannot guarantee their safety."]
80            #[unsafe(no_mangle)]
81            $vis unsafe extern "system" fn $name($($arg: $arg_ty),*) $(-> $ret)? {
82                unsafe {
83                    (*(($crate::JUMP_TABLE_START + $offset) as *const extern "system" fn($($arg_ty,)*) $(-> $ret)?))($($arg,)*)
84                }
85            }
86        )+
87    };
88}