mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-27 03:26:36 +11:00
Moved float and double functions into modules.
Makes the docs cleaner.
This commit is contained in:
parent
ae66ac4cb6
commit
e1afb70bd2
2 changed files with 300 additions and 274 deletions
|
@ -138,7 +138,7 @@ fn main() -> ! {
|
||||||
// Some functions require a look-up in a table. First we do the lookup and
|
// Some functions require a look-up in a table. First we do the lookup and
|
||||||
// find the function pointer in ROM (you only want to do this once per
|
// find the function pointer in ROM (you only want to do this once per
|
||||||
// function).
|
// function).
|
||||||
let fmul = hal::rom_data::fmul();
|
let fmul = hal::rom_data::float_funcs::fmul();
|
||||||
|
|
||||||
// Then we can call the function whenever we want
|
// Then we can call the function whenever we want
|
||||||
let start_rom = cortex_m::peripheral::SYST::get_current();
|
let start_rom = cortex_m::peripheral::SYST::get_current();
|
||||||
|
|
|
@ -209,7 +209,10 @@ pub fn soft_double_table() -> *const usize {
|
||||||
rom_table_lookup(DATA_TABLE, *b"SD")
|
rom_table_lookup(DATA_TABLE, *b"SD")
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! float_funcs {
|
/// ROM functions using single-precision arithmetic (i.e. 'f64' in Rust terms)
|
||||||
|
pub mod float_funcs {
|
||||||
|
|
||||||
|
macro_rules! make_functions {
|
||||||
(
|
(
|
||||||
$(
|
$(
|
||||||
$(#[$outer:meta])*
|
$(#[$outer:meta])*
|
||||||
|
@ -237,7 +240,7 @@ macro_rules! float_funcs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float_funcs! {
|
make_functions! {
|
||||||
/// Returns a function that will calculate `a + b`
|
/// Returns a function that will calculate `a + b`
|
||||||
0x00 fadd(a: f32, b: f32) -> f32;
|
0x00 fadd(a: f32, b: f32) -> f32;
|
||||||
/// Returns a function that will calculate `a - b`
|
/// Returns a function that will calculate `a - b`
|
||||||
|
@ -246,6 +249,9 @@ float_funcs! {
|
||||||
0x08 fmul(a: f32, b: f32) -> f32;
|
0x08 fmul(a: f32, b: f32) -> f32;
|
||||||
/// Returns a function that will calculate `a / b`
|
/// Returns a function that will calculate `a / b`
|
||||||
0x0c fdiv(a: f32, b: f32) -> f32;
|
0x0c fdiv(a: f32, b: f32) -> f32;
|
||||||
|
|
||||||
|
// 0x10 and 0x14 are deprecated
|
||||||
|
|
||||||
/// Returns a function that will calculate `sqrt(v)` (or return -Infinity if v is negative)
|
/// Returns a function that will calculate `sqrt(v)` (or return -Infinity if v is negative)
|
||||||
0x18 fsqrt(v: f32) -> f32;
|
0x18 fsqrt(v: f32) -> f32;
|
||||||
/// Returns a function that will convert an f32 to a signed integer,
|
/// Returns a function that will convert an f32 to a signed integer,
|
||||||
|
@ -295,11 +301,17 @@ float_funcs! {
|
||||||
/// Returns a function that will calculate the tangent of `angle`. The value
|
/// Returns a function that will calculate the tangent of `angle`. The value
|
||||||
/// of `angle` is in radians, and must be in the range `-1024` to `1024`
|
/// of `angle` is in radians, and must be in the range `-1024` to `1024`
|
||||||
0x44 ftan(angle: f32) -> f32;
|
0x44 ftan(angle: f32) -> f32;
|
||||||
|
|
||||||
|
// 0x48 is deprecated
|
||||||
|
|
||||||
/// Returns a function that will calculate the exponential value of `v`,
|
/// Returns a function that will calculate the exponential value of `v`,
|
||||||
/// i.e. `e ** v`
|
/// i.e. `e ** v`
|
||||||
0x4c fexp(v: f32) -> f32;
|
0x4c fexp(v: f32) -> f32;
|
||||||
/// Returns a function that will calculate the natural logarithm of `v`. If `v <= 0` return -Infinity
|
/// Returns a function that will calculate the natural logarithm of `v`. If `v <= 0` return -Infinity
|
||||||
0x50 fln(v: f32) -> f32;
|
0x50 fln(v: f32) -> f32;
|
||||||
|
|
||||||
|
// These are only on BootROM v2 or higher
|
||||||
|
|
||||||
/// Returns a function that will compare two floating point numbers, returning:
|
/// Returns a function that will compare two floating point numbers, returning:
|
||||||
/// • 0 if a == b
|
/// • 0 if a == b
|
||||||
/// • -1 if a < b
|
/// • -1 if a < b
|
||||||
|
@ -328,7 +340,7 @@ float_funcs! {
|
||||||
/// and clamping the result to lie within the range `-0x8000000000000000` to
|
/// and clamping the result to lie within the range `-0x8000000000000000` to
|
||||||
/// `0x7FFFFFFFFFFFFFFF`
|
/// `0x7FFFFFFFFFFFFFFF`
|
||||||
0x6c float_to_int64(v: f32) -> i64;
|
0x6c float_to_int64(v: f32) -> i64;
|
||||||
/// Returns a function that will convert a f32 to a signed fixed point
|
/// Returns a function that will convert an f32 to a signed fixed point
|
||||||
/// 64-bit integer representation where n specifies the position of the
|
/// 64-bit integer representation where n specifies the position of the
|
||||||
/// binary point in the resulting fixed point representation - e.g. `f(0.5f,
|
/// binary point in the resulting fixed point representation - e.g. `f(0.5f,
|
||||||
/// 16) == 0x8000`. This method rounds towards -Infinity, and clamps the
|
/// 16) == 0x8000`. This method rounds towards -Infinity, and clamps the
|
||||||
|
@ -349,8 +361,12 @@ float_funcs! {
|
||||||
/// Converts an f32 to an f64.
|
/// Converts an f32 to an f64.
|
||||||
0x7c float_to_double(v: f32) -> f64;
|
0x7c float_to_double(v: f32) -> f64;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! double_funcs {
|
/// Functions using double-precision arithmetic (i.e. 'f64' in Rust terms)
|
||||||
|
pub mod double_funcs {
|
||||||
|
|
||||||
|
macro_rules! make_double_funcs {
|
||||||
(
|
(
|
||||||
$(
|
$(
|
||||||
$(#[$outer:meta])*
|
$(#[$outer:meta])*
|
||||||
|
@ -378,7 +394,7 @@ macro_rules! double_funcs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double_funcs! {
|
make_double_funcs! {
|
||||||
/// Returns a function that will calculate `a + b`
|
/// Returns a function that will calculate `a + b`
|
||||||
0x00 dadd(a: f64, b: f64) -> f64;
|
0x00 dadd(a: f64, b: f64) -> f64;
|
||||||
/// Returns a function that will calculate `a - b`
|
/// Returns a function that will calculate `a - b`
|
||||||
|
@ -387,6 +403,9 @@ double_funcs! {
|
||||||
0x08 dmul(a: f64, b: f64) -> f64;
|
0x08 dmul(a: f64, b: f64) -> f64;
|
||||||
/// Returns a function that will calculate `a / b`
|
/// Returns a function that will calculate `a / b`
|
||||||
0x0c ddiv(a: f64, b: f64) -> f64;
|
0x0c ddiv(a: f64, b: f64) -> f64;
|
||||||
|
|
||||||
|
// 0x10 and 0x14 are deprecated
|
||||||
|
|
||||||
/// Returns a function that will calculate `sqrt(v)` (or return -Infinity if v is negative)
|
/// Returns a function that will calculate `sqrt(v)` (or return -Infinity if v is negative)
|
||||||
0x18 dsqrt(v: f64) -> f64;
|
0x18 dsqrt(v: f64) -> f64;
|
||||||
/// Returns a function that will convert an f64 to a signed integer,
|
/// Returns a function that will convert an f64 to a signed integer,
|
||||||
|
@ -431,16 +450,22 @@ double_funcs! {
|
||||||
/// of `angle` is in radians, and must be in the range `-1024` to `1024`
|
/// of `angle` is in radians, and must be in the range `-1024` to `1024`
|
||||||
0x3c dcos(angle: f64) -> f64;
|
0x3c dcos(angle: f64) -> f64;
|
||||||
/// Returns a function that will calculate the sine of `angle`. The value of
|
/// Returns a function that will calculate the sine of `angle`. The value of
|
||||||
/// `angle` is in radians, and must be in the range -1024 to 1024
|
/// `angle` is in radians, and must be in the range `-1024` to `1024`
|
||||||
0x40 dsin(angle: f64) -> f64;
|
0x40 dsin(angle: f64) -> f64;
|
||||||
/// Returns a function that will calculate the tangent of `angle`. The value
|
/// Returns a function that will calculate the tangent of `angle`. The value
|
||||||
/// of `angle` is in radians, and must be in the range `-1024` to `1024`
|
/// of `angle` is in radians, and must be in the range `-1024` to `1024`
|
||||||
0x44 dtan(angle: f64) -> f64;
|
0x44 dtan(angle: f64) -> f64;
|
||||||
|
|
||||||
|
// 0x48 is deprecated
|
||||||
|
|
||||||
/// Returns a function that will calculate the exponential value of `v`,
|
/// Returns a function that will calculate the exponential value of `v`,
|
||||||
/// i.e. `e ** v`
|
/// i.e. `e ** v`
|
||||||
0x4c dexp(v: f64) -> f64;
|
0x4c dexp(v: f64) -> f64;
|
||||||
/// Returns a function that will calculate the natural logarithm of v. If v <= 0 return -Infinity
|
/// Returns a function that will calculate the natural logarithm of v. If v <= 0 return -Infinity
|
||||||
0x50 dln(v: f64) -> f64;
|
0x50 dln(v: f64) -> f64;
|
||||||
|
|
||||||
|
// These are only on BootROM v2 or higher
|
||||||
|
|
||||||
/// Returns a function that will compare two floating point numbers, returning:
|
/// Returns a function that will compare two floating point numbers, returning:
|
||||||
/// • 0 if a == b
|
/// • 0 if a == b
|
||||||
/// • -1 if a < b
|
/// • -1 if a < b
|
||||||
|
@ -487,6 +512,7 @@ double_funcs! {
|
||||||
/// resulting integer to lie within the range `0x0000000000000000` to
|
/// resulting integer to lie within the range `0x0000000000000000` to
|
||||||
/// `0xFFFFFFFFFFFFFFFF`
|
/// `0xFFFFFFFFFFFFFFFF`
|
||||||
0x78 double_to_ufix64(v: f64, n: i32) -> u64;
|
0x78 double_to_ufix64(v: f64, n: i32) -> u64;
|
||||||
/// Returns a function that will convert an f64 to a f32
|
/// Returns a function that will convert an f64 to an f32
|
||||||
0x7c double_to_float(v: f64) -> f32;
|
0x7c double_to_float(v: f64) -> f32;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue