Compare commits
No commits in common. "9756ef39b757ae1588dc5834afc42c91c49f6d63" and "471717a36f0a95879d92028a16b98ea497041880" have entirely different histories.
9756ef39b7
...
471717a36f
26 changed files with 1075 additions and 763 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -106,9 +106,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cbindgen"
|
name = "cbindgen"
|
||||||
version = "0.29.0"
|
version = "0.28.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684"
|
checksum = "eadd868a2ce9ca38de7eeafdcec9c7065ef89b42b32f0839278d55f35c54d1ff"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"heck",
|
"heck",
|
||||||
|
@ -263,9 +263,9 @@ checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
|
@ -368,12 +368,6 @@ version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "paste"
|
|
||||||
version = "1.0.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.32"
|
version = "0.3.32"
|
||||||
|
@ -546,7 +540,6 @@ version = "0.15.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cbindgen",
|
"cbindgen",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"paste",
|
|
||||||
"servicepoint",
|
"servicepoint",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,14 @@ description = "C bindings for the servicepoint crate."
|
||||||
homepage = "https://docs.rs/crate/servicepoint_binding_c"
|
homepage = "https://docs.rs/crate/servicepoint_binding_c"
|
||||||
repository = "https://git.berlin.ccc.de/servicepoint/servicepoint"
|
repository = "https://git.berlin.ccc.de/servicepoint/servicepoint"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
links = "servicepoint"
|
||||||
keywords = ["cccb", "cccb-servicepoint", "cbindgen"]
|
keywords = ["cccb", "cccb-servicepoint", "cbindgen"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cbindgen = "0.29.0"
|
cbindgen = "0.28.0"
|
||||||
|
|
||||||
[dependencies.servicepoint]
|
[dependencies.servicepoint]
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
|
@ -24,9 +25,6 @@ default-features = false
|
||||||
version = "0.11.8"
|
version = "0.11.8"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
paste = "1.0.15"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
all_compressions = ["servicepoint/all_compressions"]
|
all_compressions = ["servicepoint/all_compressions"]
|
||||||
default = ["all_compressions", "servicepoint/default", "env_logger"]
|
default = ["all_compressions", "servicepoint/default", "env_logger"]
|
||||||
|
|
58
build.rs
Normal file
58
build.rs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
//! Build script generating the header for the `servicepoint` C library.
|
||||||
|
//!
|
||||||
|
//! When the environment variable `SERVICEPOINT_HEADER_OUT` is set, the header is copied there from
|
||||||
|
//! the out directory. This can be used to use the build script as a command line tool from other
|
||||||
|
//! build tools.
|
||||||
|
|
||||||
|
use std::{env, fs};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
println!("cargo::rerun-if-changed={crate_dir}/src");
|
||||||
|
println!("cargo::rerun-if-changed={crate_dir}/build.rs");
|
||||||
|
println!("cargo::rerun-if-changed={crate_dir}/Cargo.toml");
|
||||||
|
println!("cargo::rerun-if-changed={crate_dir}/Cargo.lock");
|
||||||
|
println!("cargo::rerun-if-changed={crate_dir}/cbindgen.toml");
|
||||||
|
println!("cargo::rerun-if-env-changed=SERVICEPOINT_HEADER_OUT");
|
||||||
|
|
||||||
|
let config =
|
||||||
|
cbindgen::Config::from_file(crate_dir.clone() + "/cbindgen.toml")
|
||||||
|
.unwrap();
|
||||||
|
let output_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let header_file = output_dir.clone() + "/servicepoint.h";
|
||||||
|
|
||||||
|
let bindings = match cbindgen::generate_with_config(crate_dir, config) {
|
||||||
|
Ok(bindings) => bindings,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("cargo:warning=Servicepoint header could not be generated: {e:?}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bindings.write_to_file(&header_file);
|
||||||
|
println!("cargo:include={output_dir}");
|
||||||
|
|
||||||
|
if let Ok(header_out) = env::var("SERVICEPOINT_HEADER_OUT") {
|
||||||
|
let header_copy = header_out + "/servicepoint.h";
|
||||||
|
|
||||||
|
if fs::exists(&header_copy).unwrap_or(false) {
|
||||||
|
// check if content changed to prevent rebuild of dependents if not
|
||||||
|
|
||||||
|
let mut bindings_text = Vec::new();
|
||||||
|
bindings.write(&mut bindings_text);
|
||||||
|
|
||||||
|
match fs::read(&header_copy) {
|
||||||
|
Ok(old_content) if old_content == bindings_text => {
|
||||||
|
println!("cargo:warning=Header did not change, not updating timestamp");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// file does not exist or is different
|
||||||
|
println!("cargo:warning=Copying header to {header_copy}");
|
||||||
|
fs::copy(header_file, &header_copy).unwrap();
|
||||||
|
println!("cargo::rerun-if-changed={header_copy}");
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,8 +30,7 @@ include = ["servicepoint", "std"]
|
||||||
extra_bindings = ["servicepoint", "servicepoint_binding_c"]
|
extra_bindings = ["servicepoint", "servicepoint_binding_c"]
|
||||||
|
|
||||||
[parse.expand]
|
[parse.expand]
|
||||||
crates = ["servicepoint_binding_c", "paste"]
|
features = ["full"]
|
||||||
features = []
|
|
||||||
|
|
||||||
[export]
|
[export]
|
||||||
include = []
|
include = []
|
||||||
|
|
|
@ -3,4 +3,4 @@ set -e
|
||||||
|
|
||||||
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
|
||||||
cbindgen --config $SCRIPT_PATH/cbindgen.toml --crate servicepoint_binding_c --output $SCRIPT_PATH/include/servicepoint.h
|
SERVICEPOINT_HEADER_OUT="$SCRIPT_PATH/include" cargo build --release
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef SERVICEPOINT_BINDINGS_C
|
#ifndef SERVICEPOINT_BINDINGS_C
|
||||||
#define SERVICEPOINT_BINDINGS_C
|
#define SERVICEPOINT_BINDINGS_C
|
||||||
|
|
||||||
/* Generated with cbindgen:0.29.0 */
|
/* Generated with cbindgen:0.28.0 */
|
||||||
|
|
||||||
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
||||||
|
|
||||||
|
@ -640,34 +640,24 @@ extern "C" {
|
||||||
void init_env_logger(void);
|
void init_env_logger(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [Bitmap] instance.
|
* Clones a [Bitmap].
|
||||||
*/
|
*/
|
||||||
struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ instance);
|
struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Bitmap::data_ref_mut`].
|
|
||||||
*
|
|
||||||
* Gets an unsafe reference to the data of the [Bitmap] instance.
|
|
||||||
*
|
|
||||||
* The returned memory is valid for the lifetime of the bitmap.
|
|
||||||
*/
|
|
||||||
struct ByteSlice sp_bitmap_data_ref_mut(struct Bitmap */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::Bitmap::fill`].
|
|
||||||
*
|
|
||||||
* Sets the state of all pixels in the [Bitmap].
|
* Sets the state of all pixels in the [Bitmap].
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `bitmap`: instance to write to
|
||||||
* - `value`: the value to set all pixels to
|
* - `value`: the value to set all pixels to
|
||||||
*/
|
*/
|
||||||
void sp_bitmap_fill(struct Bitmap */*notnull*/ instance, bool value);
|
void sp_bitmap_fill(struct Bitmap */*notnull*/ bitmap, bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [Bitmap] instance.
|
* Deallocates a [Bitmap].
|
||||||
*/
|
*/
|
||||||
void sp_bitmap_free(struct Bitmap */*notnull*/ instance);
|
void sp_bitmap_free(struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to convert the BitVec to a Bitmap.
|
* Tries to convert the BitVec to a Bitmap.
|
||||||
|
@ -679,29 +669,30 @@ void sp_bitmap_free(struct Bitmap */*notnull*/ instance);
|
||||||
struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
|
struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Bitmap::get`].
|
* Gets the current value at the specified position in the [Bitmap].
|
||||||
*
|
|
||||||
* Gets the current value at the specified position.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `bitmap`: instance to read from
|
||||||
* - `x` and `y`: position of the cell to read
|
* - `x` and `y`: position of the cell to read
|
||||||
*
|
*
|
||||||
* # Panics
|
* # Panics
|
||||||
*
|
*
|
||||||
* - when accessing `x` or `y` out of bounds
|
* - when accessing `x` or `y` out of bounds
|
||||||
*/
|
*/
|
||||||
bool sp_bitmap_get(struct Bitmap */*notnull*/ instance, size_t x, size_t y);
|
bool sp_bitmap_get(struct Bitmap */*notnull*/ bitmap, size_t x, size_t y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Bitmap::height`].
|
* Gets the height in pixels of the [Bitmap] instance.
|
||||||
*
|
*
|
||||||
* Gets the height in pixels.
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bitmap`: instance to read from
|
||||||
*/
|
*/
|
||||||
size_t sp_bitmap_height(struct Bitmap */*notnull*/ instance);
|
size_t sp_bitmap_height(struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consumes the Bitmap and returns the contained BitVec.
|
* Consumes the Bitmap and returns the contained BitVec
|
||||||
*/
|
*/
|
||||||
BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
|
BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
|
@ -766,12 +757,11 @@ struct Bitmap *sp_bitmap_new(size_t width, size_t height);
|
||||||
struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
|
struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Bitmap::set`].
|
* Sets the value of the specified position in the [Bitmap].
|
||||||
*
|
|
||||||
* Sets the value of the specified position.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `bitmap`: instance to write to
|
||||||
* - `x` and `y`: position of the cell
|
* - `x` and `y`: position of the cell
|
||||||
* - `value`: the value to write to the cell
|
* - `value`: the value to write to the cell
|
||||||
*
|
*
|
||||||
|
@ -779,52 +769,59 @@ struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
|
||||||
*
|
*
|
||||||
* - when accessing `x` or `y` out of bounds
|
* - when accessing `x` or `y` out of bounds
|
||||||
*/
|
*/
|
||||||
void sp_bitmap_set(struct Bitmap */*notnull*/ instance,
|
void sp_bitmap_set(struct Bitmap */*notnull*/ bitmap,
|
||||||
size_t x,
|
size_t x,
|
||||||
size_t y,
|
size_t y,
|
||||||
bool value);
|
bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Bitmap::width`].
|
* Gets an unsafe reference to the data of the [Bitmap] instance.
|
||||||
*
|
*
|
||||||
* Gets the width in pixels.
|
* The returned memory is valid for the lifetime of the bitmap.
|
||||||
*/
|
*/
|
||||||
size_t sp_bitmap_width(struct Bitmap */*notnull*/ instance);
|
struct ByteSlice sp_bitmap_unsafe_data_ref(struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::DisplayBitVec::as_raw_mut_slice`].
|
* Gets the width in pixels of the [Bitmap] instance.
|
||||||
*
|
|
||||||
* Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
|
||||||
*
|
|
||||||
* The returned memory is valid for the lifetime of the bitvec.
|
|
||||||
*/
|
|
||||||
struct ByteSlice sp_bitvec_as_raw_mut_slice(BitVec */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*Clones a [DisplayBitVec] instance.
|
|
||||||
*/
|
|
||||||
BitVec */*notnull*/ sp_bitvec_clone(BitVec */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::DisplayBitVec::fill`].
|
|
||||||
*
|
|
||||||
* Sets the value of all bits.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `bitmap`: instance to read from
|
||||||
|
*
|
||||||
|
* # Panics
|
||||||
|
*
|
||||||
|
* - when `bitmap` is NULL
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
*
|
||||||
|
* The caller has to make sure that:
|
||||||
|
*
|
||||||
|
* - `bitmap` points to a valid [Bitmap]
|
||||||
|
*/
|
||||||
|
size_t sp_bitmap_width(struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a [DisplayBitVec].
|
||||||
|
*/
|
||||||
|
BitVec */*notnull*/ sp_bitvec_clone(BitVec */*notnull*/ bit_vec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of all bits in the [DisplayBitVec].
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
* - `value`: the value to set all bits to
|
* - `value`: the value to set all bits to
|
||||||
*/
|
*/
|
||||||
void sp_bitvec_fill(BitVec */*notnull*/ instance, bool value);
|
void sp_bitvec_fill(BitVec */*notnull*/ bit_vec, bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [DisplayBitVec] instance.
|
* Deallocates a [DisplayBitVec].
|
||||||
*/
|
*/
|
||||||
void sp_bitvec_free(BitVec */*notnull*/ instance);
|
void sp_bitvec_free(BitVec */*notnull*/ bit_vec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::DisplayBitVec::get`].
|
* Gets the value of a bit from the [DisplayBitVec].
|
||||||
*
|
|
||||||
* Gets the value of a bit.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
@ -837,7 +834,7 @@ void sp_bitvec_free(BitVec */*notnull*/ instance);
|
||||||
*
|
*
|
||||||
* - when accessing `index` out of bounds
|
* - when accessing `index` out of bounds
|
||||||
*/
|
*/
|
||||||
bool sp_bitvec_get(BitVec */*notnull*/ instance, size_t index);
|
bool sp_bitvec_get(BitVec */*notnull*/ bit_vec, size_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||||
|
@ -852,18 +849,22 @@ struct Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec,
|
||||||
CompressionCode compression);
|
CompressionCode compression);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::DisplayBitVec::is_empty`].
|
|
||||||
*
|
|
||||||
* Returns true if length is 0.
|
* Returns true if length is 0.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
*/
|
*/
|
||||||
bool sp_bitvec_is_empty(BitVec */*notnull*/ instance);
|
bool sp_bitvec_is_empty(BitVec */*notnull*/ bit_vec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::DisplayBitVec::len`].
|
* Gets the length of the [DisplayBitVec] in bits.
|
||||||
*
|
*
|
||||||
* Gets the length in bits.
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
*/
|
*/
|
||||||
size_t sp_bitvec_len(BitVec */*notnull*/ instance);
|
size_t sp_bitvec_len(BitVec */*notnull*/ bit_vec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
|
* Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
|
||||||
|
@ -888,12 +889,11 @@ BitVec */*notnull*/ sp_bitvec_load(struct ByteSlice data);
|
||||||
BitVec */*notnull*/ sp_bitvec_new(size_t size);
|
BitVec */*notnull*/ sp_bitvec_new(size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::DisplayBitVec::set`].
|
* Sets the value of a bit in the [DisplayBitVec].
|
||||||
*
|
|
||||||
* Sets the value of a bit.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
* - `index`: the bit index to edit
|
* - `index`: the bit index to edit
|
||||||
* - `value`: the value to set the bit to
|
* - `value`: the value to set the bit to
|
||||||
*
|
*
|
||||||
|
@ -901,46 +901,46 @@ BitVec */*notnull*/ sp_bitvec_new(size_t size);
|
||||||
*
|
*
|
||||||
* - when accessing `index` out of bounds
|
* - when accessing `index` out of bounds
|
||||||
*/
|
*/
|
||||||
void sp_bitvec_set(BitVec */*notnull*/ instance, size_t index, bool value);
|
void sp_bitvec_set(BitVec */*notnull*/ bit_vec, size_t index, bool value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [BrightnessGrid] instance.
|
* Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
||||||
*/
|
|
||||||
BrightnessGrid */*notnull*/ sp_brightness_grid_clone(BrightnessGrid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::BrightnessGrid::data_ref_mut`].
|
|
||||||
*
|
*
|
||||||
* Gets an unsafe reference to the data of the instance.
|
* The returned memory is valid for the lifetime of the bitvec.
|
||||||
*
|
|
||||||
* The returned memory is valid for the lifetime of the grid.
|
|
||||||
*/
|
|
||||||
struct ByteSlice sp_brightness_grid_data_ref_mut(BrightnessGrid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::BrightnessGrid::fill`].
|
|
||||||
*
|
|
||||||
* Sets the value of all cells.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `bit_vec`: instance to write to
|
||||||
|
*/
|
||||||
|
struct ByteSlice sp_bitvec_unsafe_data_ref(BitVec */*notnull*/ bit_vec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a [BrightnessGrid].
|
||||||
|
*/
|
||||||
|
BrightnessGrid */*notnull*/ sp_brightness_grid_clone(BrightnessGrid */*notnull*/ grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of all cells in the [BrightnessGrid].
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `brightness_grid`: instance to write to
|
||||||
* - `value`: the value to set all cells to
|
* - `value`: the value to set all cells to
|
||||||
*/
|
*/
|
||||||
void sp_brightness_grid_fill(BrightnessGrid */*notnull*/ instance,
|
void sp_brightness_grid_fill(BrightnessGrid */*notnull*/ brightness_grid,
|
||||||
Brightness value);
|
Brightness value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [BrightnessGrid] instance.
|
* Deallocates a [BrightnessGrid].
|
||||||
*/
|
*/
|
||||||
void sp_brightness_grid_free(BrightnessGrid */*notnull*/ instance);
|
void sp_brightness_grid_free(BrightnessGrid */*notnull*/ brightness_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::BrightnessGrid::get`].
|
|
||||||
*
|
|
||||||
* Gets the current value at the specified position.
|
* Gets the current value at the specified position.
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `brightness_grid`: instance to read from
|
||||||
* - `x` and `y`: position of the cell to read
|
* - `x` and `y`: position of the cell to read
|
||||||
*
|
*
|
||||||
* returns: value at position
|
* returns: value at position
|
||||||
|
@ -948,16 +948,20 @@ void sp_brightness_grid_free(BrightnessGrid */*notnull*/ instance);
|
||||||
* # Panics
|
* # Panics
|
||||||
* - When accessing `x` or `y` out of bounds.
|
* - When accessing `x` or `y` out of bounds.
|
||||||
*/
|
*/
|
||||||
Brightness sp_brightness_grid_get(BrightnessGrid */*notnull*/ instance,
|
Brightness sp_brightness_grid_get(BrightnessGrid */*notnull*/ brightness_grid,
|
||||||
size_t x,
|
size_t x,
|
||||||
size_t y);
|
size_t y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::BrightnessGrid::height`].
|
* Gets the height of the [BrightnessGrid] instance.
|
||||||
*
|
*
|
||||||
* Gets the height of the grid.
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `brightness_grid`: instance to read from
|
||||||
|
*
|
||||||
|
* returns: height
|
||||||
*/
|
*/
|
||||||
size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ instance);
|
size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ brightness_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
||||||
|
@ -1003,12 +1007,11 @@ BrightnessGrid *sp_brightness_grid_load(size_t width,
|
||||||
BrightnessGrid */*notnull*/ sp_brightness_grid_new(size_t width, size_t height);
|
BrightnessGrid */*notnull*/ sp_brightness_grid_new(size_t width, size_t height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::BrightnessGrid::set`].
|
* Sets the value of the specified position in the [BrightnessGrid].
|
||||||
*
|
|
||||||
* Sets the value of the specified position.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `brightness_grid`: instance to write to
|
||||||
* - `x` and `y`: position of the cell
|
* - `x` and `y`: position of the cell
|
||||||
* - `value`: the value to write to the cell
|
* - `value`: the value to write to the cell
|
||||||
*
|
*
|
||||||
|
@ -1018,61 +1021,77 @@ BrightnessGrid */*notnull*/ sp_brightness_grid_new(size_t width, size_t height);
|
||||||
*
|
*
|
||||||
* - When accessing `x` or `y` out of bounds.
|
* - When accessing `x` or `y` out of bounds.
|
||||||
*/
|
*/
|
||||||
void sp_brightness_grid_set(BrightnessGrid */*notnull*/ instance,
|
void sp_brightness_grid_set(BrightnessGrid */*notnull*/ brightness_grid,
|
||||||
size_t x,
|
size_t x,
|
||||||
size_t y,
|
size_t y,
|
||||||
Brightness value);
|
Brightness value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::BrightnessGrid::width`].
|
* Gets an unsafe reference to the data of the [BrightnessGrid] instance.
|
||||||
*
|
*
|
||||||
* Gets the width of the grid.
|
* The returned memory is valid for the lifetime of the brightness grid.
|
||||||
*/
|
|
||||||
size_t sp_brightness_grid_width(BrightnessGrid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*Clones a [CharGrid] instance.
|
|
||||||
*/
|
|
||||||
CharGrid */*notnull*/ sp_char_grid_clone(CharGrid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::CharGrid::fill`].
|
|
||||||
*
|
|
||||||
* Sets the value of all cells in the grid.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
* - `value`: the value to set all cells to
|
* - `brightness_grid`: instance to read from
|
||||||
* - when providing values that cannot be converted to Rust's `char`.
|
|
||||||
*/
|
|
||||||
void sp_char_grid_fill(CharGrid */*notnull*/ instance, uint32_t value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*Deallocates a [CharGrid] instance.
|
|
||||||
*/
|
|
||||||
void sp_char_grid_free(CharGrid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::CharGrid::get`].
|
|
||||||
*
|
*
|
||||||
|
* returns: slice of bytes underlying the `brightness_grid`.
|
||||||
|
*/
|
||||||
|
struct ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid */*notnull*/ brightness_grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the width of the [BrightnessGrid] instance.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `brightness_grid`: instance to read from
|
||||||
|
*
|
||||||
|
* returns: width
|
||||||
|
*/
|
||||||
|
size_t sp_brightness_grid_width(BrightnessGrid */*notnull*/ brightness_grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a [CharGrid].
|
||||||
|
*/
|
||||||
|
CharGrid */*notnull*/ sp_char_grid_clone(CharGrid */*notnull*/ grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of all cells in the [CharGrid].
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `char_grid`: instance to write to
|
||||||
|
* - `value`: the value to set all cells to
|
||||||
|
*/
|
||||||
|
void sp_char_grid_fill(CharGrid */*notnull*/ char_grid, uint32_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a [CharGrid].
|
||||||
|
*/
|
||||||
|
void sp_char_grid_free(CharGrid */*notnull*/ char_grid);
|
||||||
|
|
||||||
|
/**
|
||||||
* Returns the current value at the specified position.
|
* Returns the current value at the specified position.
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `char_grid`: instance to read from
|
||||||
* - `x` and `y`: position of the cell to read
|
* - `x` and `y`: position of the cell to read
|
||||||
*
|
*
|
||||||
* # Panics
|
* # Panics
|
||||||
*
|
*
|
||||||
* - when accessing `x` or `y` out of bounds
|
* - when accessing `x` or `y` out of bounds
|
||||||
*/
|
*/
|
||||||
uint32_t sp_char_grid_get(CharGrid */*notnull*/ instance, size_t x, size_t y);
|
uint32_t sp_char_grid_get(CharGrid */*notnull*/ char_grid, size_t x, size_t y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::CharGrid::height`].
|
* Gets the height of the [CharGrid] instance.
|
||||||
*
|
*
|
||||||
* Gets the height of the grid.
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `char_grid`: instance to read from
|
||||||
*/
|
*/
|
||||||
size_t sp_char_grid_height(CharGrid */*notnull*/ instance);
|
size_t sp_char_grid_height(CharGrid */*notnull*/ char_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
||||||
|
@ -1109,12 +1128,11 @@ CharGrid *sp_char_grid_load(size_t width, size_t height, struct ByteSlice data);
|
||||||
CharGrid */*notnull*/ sp_char_grid_new(size_t width, size_t height);
|
CharGrid */*notnull*/ sp_char_grid_new(size_t width, size_t height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::CharGrid::set`].
|
* Sets the value of the specified position in the [CharGrid].
|
||||||
*
|
|
||||||
* Sets the value of the specified position in the grid.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `char_grid`: instance to write to
|
||||||
* - `x` and `y`: position of the cell
|
* - `x` and `y`: position of the cell
|
||||||
* - `value`: the value to write to the cell
|
* - `value`: the value to write to the cell
|
||||||
*
|
*
|
||||||
|
@ -1123,29 +1141,32 @@ CharGrid */*notnull*/ sp_char_grid_new(size_t width, size_t height);
|
||||||
* # Panics
|
* # Panics
|
||||||
*
|
*
|
||||||
* - when accessing `x` or `y` out of bounds
|
* - when accessing `x` or `y` out of bounds
|
||||||
* - when providing values that cannot be converted to Rust's `char`.
|
|
||||||
*/
|
*/
|
||||||
void sp_char_grid_set(CharGrid */*notnull*/ instance,
|
void sp_char_grid_set(CharGrid */*notnull*/ char_grid,
|
||||||
size_t x,
|
size_t x,
|
||||||
size_t y,
|
size_t y,
|
||||||
uint32_t value);
|
uint32_t value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::CharGrid::width`].
|
* Gets the width of the [CharGrid] instance.
|
||||||
*
|
*
|
||||||
* Gets the width of the grid.
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `char_grid`: instance to read from
|
||||||
*/
|
*/
|
||||||
size_t sp_char_grid_width(CharGrid */*notnull*/ instance);
|
size_t sp_char_grid_width(CharGrid */*notnull*/ char_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [BitmapCommand] instance.
|
* Clones an [BitmapCommand] instance.
|
||||||
|
*
|
||||||
|
* returns: a new [BitmapCommand] instance.
|
||||||
*/
|
*/
|
||||||
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(struct BitmapCommand */*notnull*/ instance);
|
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [BitmapCommand] instance.
|
* Deallocates a [BitmapCommand] instance.
|
||||||
*/
|
*/
|
||||||
void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ instance);
|
void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the provided [Bitmap] into a new [BitmapCommand],
|
* Move the provided [Bitmap] into a new [BitmapCommand],
|
||||||
|
@ -1216,14 +1237,16 @@ void sp_cmd_bitmap_set_origin(struct BitmapCommand */*notnull*/ command,
|
||||||
struct Packet *sp_cmd_bitmap_try_into_packet(struct BitmapCommand */*notnull*/ command);
|
struct Packet *sp_cmd_bitmap_try_into_packet(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [BitVecCommand] instance.
|
* Clones an [BitVecCommand] instance.
|
||||||
|
*
|
||||||
|
* returns: a new [BitVecCommand] instance.
|
||||||
*/
|
*/
|
||||||
struct BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(struct BitVecCommand */*notnull*/ instance);
|
struct BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(struct BitVecCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [BitVecCommand] instance.
|
* Deallocates a [BitVecCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ instance);
|
void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
* Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
||||||
|
@ -1296,14 +1319,13 @@ void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ command,
|
||||||
struct Packet *sp_cmd_bitvec_try_into_packet(struct BitVecCommand */*notnull*/ command);
|
struct Packet *sp_cmd_bitvec_try_into_packet(struct BitVecCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [GlobalBrightnessCommand] instance.
|
* Clones an [GlobalBrightnessCommand] instance.
|
||||||
|
*
|
||||||
|
* returns: a new [GlobalBrightnessCommand] instance.
|
||||||
*/
|
*/
|
||||||
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struct GlobalBrightnessCommand */*notnull*/ instance);
|
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
void sp_cmd_brightness_global_free(struct BitmapCommand */*notnull*/ command);
|
||||||
*Deallocates a [GlobalBrightnessCommand] instance.
|
|
||||||
*/
|
|
||||||
void sp_cmd_brightness_global_free(struct GlobalBrightnessCommand */*notnull*/ instance);
|
|
||||||
|
|
||||||
Brightness sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
|
Brightness sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||||
|
|
||||||
|
@ -1323,14 +1345,16 @@ void sp_cmd_brightness_global_set(struct GlobalBrightnessCommand */*notnull*/ co
|
||||||
Brightness brightness);
|
Brightness brightness);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [BrightnessGridCommand] instance.
|
* Clones an [BrightnessGridCommand] instance.
|
||||||
|
*
|
||||||
|
* returns: a new [BrightnessGridCommand] instance.
|
||||||
*/
|
*/
|
||||||
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(struct BrightnessGridCommand */*notnull*/ instance);
|
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(struct BrightnessGridCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [BrightnessGridCommand] instance.
|
* Deallocates a [BitmapCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_brightness_grid_free(struct BrightnessGridCommand */*notnull*/ instance);
|
void sp_cmd_brightness_grid_free(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
|
* Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
|
||||||
|
@ -1382,14 +1406,16 @@ void sp_cmd_brightness_grid_set_origin(struct BrightnessGridCommand */*notnull*/
|
||||||
size_t origin_y);
|
size_t origin_y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [CharGridCommand] instance.
|
* Clones an [CharGridCommand] instance.
|
||||||
|
*
|
||||||
|
* returns: a new [CharGridCommand] instance.
|
||||||
*/
|
*/
|
||||||
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(struct CharGridCommand */*notnull*/ instance);
|
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(struct CharGridCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [CharGridCommand] instance.
|
* Deallocates a [BitmapCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_char_grid_free(struct CharGridCommand */*notnull*/ instance);
|
void sp_cmd_char_grid_free(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the provided [CharGrid] into a new [CharGridCommand],
|
* Moves the provided [CharGrid] into a new [CharGridCommand],
|
||||||
|
@ -1441,9 +1467,9 @@ void sp_cmd_char_grid_set_origin(struct CharGridCommand */*notnull*/ command,
|
||||||
struct Packet *sp_cmd_char_grid_try_into_packet(struct CharGridCommand */*notnull*/ command);
|
struct Packet *sp_cmd_char_grid_try_into_packet(struct CharGridCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [ClearCommand] instance.
|
* Deallocates a [ClearCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_clear_free(struct ClearCommand */*notnull*/ instance);
|
void sp_cmd_clear_free(struct ClearCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set all pixels to the off state.
|
* Set all pixels to the off state.
|
||||||
|
@ -1455,14 +1481,16 @@ void sp_cmd_clear_free(struct ClearCommand */*notnull*/ instance);
|
||||||
struct ClearCommand */*notnull*/ sp_cmd_clear_new(void);
|
struct ClearCommand */*notnull*/ sp_cmd_clear_new(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [Cp437GridCommand] instance.
|
* Clones an [Cp437GridCommand] instance.
|
||||||
|
*
|
||||||
|
* returns: a new [Cp437GridCommand] instance.
|
||||||
*/
|
*/
|
||||||
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(struct Cp437GridCommand */*notnull*/ instance);
|
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(struct Cp437GridCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [Cp437GridCommand] instance.
|
* Deallocates a [Cp437GridCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_cp437_grid_free(struct Cp437GridCommand */*notnull*/ instance);
|
void sp_cmd_cp437_grid_free(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
|
* Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
|
||||||
|
@ -1525,9 +1553,9 @@ void sp_cmd_cp437_grid_set_origin(struct Cp437GridCommand */*notnull*/ command,
|
||||||
struct Packet *sp_cmd_cp437_grid_try_into_packet(struct Cp437GridCommand */*notnull*/ command);
|
struct Packet *sp_cmd_cp437_grid_try_into_packet(struct Cp437GridCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [FadeOutCommand] instance.
|
* Deallocates a [FadeOutCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_fade_out_free(struct FadeOutCommand */*notnull*/ instance);
|
void sp_cmd_fade_out_free(struct ClearCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A yet-to-be-tested command.
|
* A yet-to-be-tested command.
|
||||||
|
@ -1575,9 +1603,9 @@ struct Packet *sp_cmd_generic_into_packet(struct Command command);
|
||||||
struct Command sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
|
struct Command sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [HardResetCommand] instance.
|
* Deallocates a [HardResetCommand].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_hard_reset_free(struct HardResetCommand */*notnull*/ instance);
|
void sp_cmd_hard_reset_free(struct ClearCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kills the udp daemon on the display, which usually results in a restart.
|
* Kills the udp daemon on the display, which usually results in a restart.
|
||||||
|
@ -1589,50 +1617,49 @@ void sp_cmd_hard_reset_free(struct HardResetCommand */*notnull*/ instance);
|
||||||
struct HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
|
struct HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::data_ref_mut`].
|
* Clones a [Cp437Grid].
|
||||||
*
|
|
||||||
* Gets an unsafe reference to the data of the grid.
|
|
||||||
*
|
|
||||||
* The returned memory is valid for the lifetime of the instance.
|
|
||||||
*/
|
*/
|
||||||
struct ByteSlice sp_cp437_data_ref_mut(Cp437Grid */*notnull*/ instance);
|
Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::fill`].
|
* Sets the value of all cells in the [Cp437Grid].
|
||||||
*
|
|
||||||
* Sets the value of all cells in the grid.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
* - `cp437_grid`: instance to write to
|
* - `cp437_grid`: instance to write to
|
||||||
* - `value`: the value to set all cells to
|
* - `value`: the value to set all cells to
|
||||||
*/
|
*/
|
||||||
void sp_cp437_fill(Cp437Grid */*notnull*/ instance, uint8_t value);
|
void sp_cp437_grid_fill(Cp437Grid */*notnull*/ cp437_grid, uint8_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a [Cp437Grid].
|
||||||
|
*/
|
||||||
|
void sp_cp437_grid_free(Cp437Grid */*notnull*/ cp437_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::get`].
|
|
||||||
*
|
|
||||||
* Gets the current value at the specified position.
|
* Gets the current value at the specified position.
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `cp437_grid`: instance to read from
|
||||||
* - `x` and `y`: position of the cell to read
|
* - `x` and `y`: position of the cell to read
|
||||||
*
|
*
|
||||||
* # Panics
|
* # Panics
|
||||||
*
|
*
|
||||||
* - when accessing `x` or `y` out of bounds
|
* - when accessing `x` or `y` out of bounds
|
||||||
*/
|
*/
|
||||||
uint8_t sp_cp437_get(Cp437Grid */*notnull*/ instance, size_t x, size_t y);
|
uint8_t sp_cp437_grid_get(Cp437Grid */*notnull*/ cp437_grid,
|
||||||
|
size_t x,
|
||||||
|
size_t y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [Cp437Grid] instance.
|
* Gets the height of the [Cp437Grid] instance.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `cp437_grid`: instance to read from
|
||||||
*/
|
*/
|
||||||
Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ instance);
|
size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ cp437_grid);
|
||||||
|
|
||||||
/**
|
|
||||||
*Deallocates a [Cp437Grid] instance.
|
|
||||||
*/
|
|
||||||
void sp_cp437_grid_free(Cp437Grid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
||||||
|
@ -1660,19 +1687,11 @@ Cp437Grid *sp_cp437_grid_load(size_t width,
|
||||||
Cp437Grid */*notnull*/ sp_cp437_grid_new(size_t width, size_t height);
|
Cp437Grid */*notnull*/ sp_cp437_grid_new(size_t width, size_t height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::height`].
|
* Sets the value of the specified position in the [Cp437Grid].
|
||||||
*
|
|
||||||
* Gets the height of the grid.
|
|
||||||
*/
|
|
||||||
size_t sp_cp437_height(Cp437Grid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls [`servicepoint::Cp437Grid::set`].
|
|
||||||
*
|
|
||||||
* Sets the value at the specified position.
|
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # Arguments
|
||||||
*
|
*
|
||||||
|
* - `cp437_grid`: instance to write to
|
||||||
* - `x` and `y`: position of the cell
|
* - `x` and `y`: position of the cell
|
||||||
* - `value`: the value to write to the cell
|
* - `value`: the value to write to the cell
|
||||||
*
|
*
|
||||||
|
@ -1682,27 +1701,38 @@ size_t sp_cp437_height(Cp437Grid */*notnull*/ instance);
|
||||||
*
|
*
|
||||||
* - when accessing `x` or `y` out of bounds
|
* - when accessing `x` or `y` out of bounds
|
||||||
*/
|
*/
|
||||||
void sp_cp437_set(Cp437Grid */*notnull*/ instance,
|
void sp_cp437_grid_set(Cp437Grid */*notnull*/ cp437_grid,
|
||||||
size_t x,
|
size_t x,
|
||||||
size_t y,
|
size_t y,
|
||||||
uint8_t value);
|
uint8_t value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::width`].
|
* Gets an unsafe reference to the data of the [Cp437Grid] instance.
|
||||||
*
|
*
|
||||||
* Gets the width of the grid.
|
* The returned memory is valid for the lifetime of the grid.
|
||||||
*/
|
*/
|
||||||
size_t sp_cp437_width(Cp437Grid */*notnull*/ instance);
|
struct ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid */*notnull*/ cp437_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [Packet] instance.
|
* Gets the width of the [Cp437Grid] instance.
|
||||||
|
*
|
||||||
|
* # Arguments
|
||||||
|
*
|
||||||
|
* - `cp437_grid`: instance to read from
|
||||||
*/
|
*/
|
||||||
struct Packet */*notnull*/ sp_packet_clone(struct Packet */*notnull*/ instance);
|
size_t sp_cp437_grid_width(Cp437Grid */*notnull*/ cp437_grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [Packet] instance.
|
* Clones a [Packet].
|
||||||
|
*
|
||||||
|
* returns: a new [Packet] instance.
|
||||||
*/
|
*/
|
||||||
void sp_packet_free(struct Packet */*notnull*/ instance);
|
struct Packet */*notnull*/ sp_packet_clone(struct Packet */*notnull*/ packet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a [Packet].
|
||||||
|
*/
|
||||||
|
void sp_packet_free(struct Packet */*notnull*/ packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a raw [Packet] from parts.
|
* Creates a raw [Packet] from parts.
|
||||||
|
@ -1762,9 +1792,9 @@ bool sp_u16_to_command_code(uint16_t code,
|
||||||
CommandCode *result);
|
CommandCode *result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Deallocates a [UdpSocket] instance.
|
* Closes and deallocates a [UdpSocket].
|
||||||
*/
|
*/
|
||||||
void sp_udp_free(struct UdpSocket */*notnull*/ instance);
|
void sp_udp_free(struct UdpSocket */*notnull*/ connection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of [UdpSocket].
|
* Creates a new instance of [UdpSocket].
|
||||||
|
|
|
@ -3,24 +3,22 @@
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
BUILD="nix build -L"
|
BUILD="nix build"
|
||||||
|
|
||||||
$BUILD .#servicepoint-binding-c -o result
|
$BUILD .#servicepoint-binding-c
|
||||||
|
|
||||||
$BUILD .#servicepoint-binding-c-stable-release -o result-stable-release
|
$BUILD .#servicepoint-binding-c-stable-release
|
||||||
$BUILD .#servicepoint-binding-c-stable-size -o result-stable-size
|
$BUILD .#servicepoint-binding-c-stable-size
|
||||||
$BUILD .#servicepoint-binding-c-nightly-release -o result-nightly-release
|
$BUILD .#servicepoint-binding-c-nightly-release
|
||||||
$BUILD .#servicepoint-binding-c-nightly-size -o result-nightly-size
|
$BUILD .#servicepoint-binding-c-nightly-size
|
||||||
$BUILD .#servicepoint-binding-c-musl-stable-release -o result-musl-release
|
|
||||||
$BUILD .#servicepoint-binding-c-musl-stable-size -o result-musl-size
|
|
||||||
|
|
||||||
# do not work yet:
|
$BUILD .#servicepoint-binding-c-musl-stable-release
|
||||||
|
$BUILD .#servicepoint-binding-c-musl-stable-size
|
||||||
# $BUILD .#servicepoint-binding-c-musl-nightly-release
|
# $BUILD .#servicepoint-binding-c-musl-nightly-release
|
||||||
# $BUILD .#servicepoint-binding-c-musl-nightly-size
|
# $BUILD .#servicepoint-binding-c-musl-nightly-size
|
||||||
|
|
||||||
$BUILD .#all-examples -o result-examples
|
$BUILD .#all-examples
|
||||||
$BUILD .#all-examples-size -o result-examples-size
|
$BUILD .#all-examples-size
|
||||||
$BUILD .#all-examples-nightly-size -o result-nightly-size
|
$BUILD .#all-examples-musl
|
||||||
$BUILD .#all-examples-musl -o result-examples-musl
|
$BUILD .#all-examples-musl-static
|
||||||
$BUILD .#all-examples-musl-static -o result-examples-musl-static
|
$BUILD .#all-examples-musl-static-size
|
||||||
$BUILD .#all-examples-musl-static-size -o result-examples-musl-static-size
|
|
||||||
|
|
155
packages.nix
155
packages.nix
|
@ -11,13 +11,9 @@ let
|
||||||
{
|
{
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
pkgs,
|
pkgs,
|
||||||
buildType ? "release",
|
|
||||||
buildNoDefaultFeatures ? false,
|
|
||||||
cargoBuildFlags ? [ ],
|
|
||||||
nativeBuildInputs ? []
|
|
||||||
}:
|
}:
|
||||||
rustPlatform.buildRustPackage (finalAttrs: {
|
rustPlatform.buildRustPackage (finalAttrs: {
|
||||||
inherit version buildType cargoBuildFlags;
|
inherit version;
|
||||||
|
|
||||||
pname = "servicepoint-binding-c";
|
pname = "servicepoint-binding-c";
|
||||||
src = lib.filter {
|
src = lib.filter {
|
||||||
|
@ -39,7 +35,7 @@ let
|
||||||
license = lib.licenses.gpl3Plus;
|
license = lib.licenses.gpl3Plus;
|
||||||
pkgConfigModules = [ "servicepoint" ];
|
pkgConfigModules = [ "servicepoint" ];
|
||||||
};
|
};
|
||||||
nativeBuildInputs = [ pkgs.pkg-config ] ++ nativeBuildInputs;
|
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||||
buildInputs = [ pkgs.xz ];
|
buildInputs = [ pkgs.xz ];
|
||||||
|
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
|
@ -61,14 +57,9 @@ let
|
||||||
name,
|
name,
|
||||||
servicepointBinding,
|
servicepointBinding,
|
||||||
pkgs,
|
pkgs,
|
||||||
EXTRA_CFLAGS ? "",
|
|
||||||
static ? false,
|
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
staticPkgConfigParam = if static then "--static" else "";
|
|
||||||
in
|
|
||||||
pkgs.gccStdenv.mkDerivation {
|
pkgs.gccStdenv.mkDerivation {
|
||||||
inherit version EXTRA_CFLAGS;
|
inherit version;
|
||||||
pname = "servicepoint-c-example-${name}";
|
pname = "servicepoint-c-example-${name}";
|
||||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
|
@ -80,12 +71,19 @@ let
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
$CC ${name}.c ${if static then "-static" else ""} $CFLAGS $EXTRA_CFLAGS \
|
$CC ${name}.c $CFLAGS $EXTRA_CFLAGS $(pkg-config --libs --cflags servicepoint) $(pkg-config --libs --cflags liblzma) -o $out/bin/${name}
|
||||||
$(pkg-config --libs --cflags ${staticPkgConfigParam} servicepoint) \
|
|
||||||
$(pkg-config --libs --cflags ${staticPkgConfigParam} liblzma) \
|
|
||||||
-o $out/bin/${name}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
rustPlatform-stable = pkgs.rustPlatform;
|
||||||
|
rustPlatform-unstable = pkgs.makeRustPlatform {
|
||||||
|
cargo = fenix.minimal.cargo;
|
||||||
|
rustc = fenix.minimal.rustc;
|
||||||
|
};
|
||||||
|
rustPlatform-musl-stable = pkgs.pkgsMusl.rustPlatform;
|
||||||
|
rustPlatform-musl-unstable = pkgs.pkgsMusl.makeRustPlatform {
|
||||||
|
cargo = fenix.minimal.cargo;
|
||||||
|
rustc = fenix.minimal.rustc;
|
||||||
|
};
|
||||||
examples = [
|
examples = [
|
||||||
"announce"
|
"announce"
|
||||||
"brightness_tester"
|
"brightness_tester"
|
||||||
|
@ -94,12 +92,6 @@ let
|
||||||
"random_stuff"
|
"random_stuff"
|
||||||
"wiping_clear"
|
"wiping_clear"
|
||||||
];
|
];
|
||||||
mkAllExamples =
|
|
||||||
suffix:
|
|
||||||
pkgs.symlinkJoin {
|
|
||||||
name = "servicepoint-all-examples";
|
|
||||||
paths = builtins.map (e: selfPkgs."${e}${suffix}") examples;
|
|
||||||
};
|
|
||||||
size-cflags = [
|
size-cflags = [
|
||||||
"-Oz"
|
"-Oz"
|
||||||
"-fwrapv"
|
"-fwrapv"
|
||||||
|
@ -120,58 +112,54 @@ let
|
||||||
"-Wl,--gc-sections"
|
"-Wl,--gc-sections"
|
||||||
"-Wl,--exclude-libs,ALL"
|
"-Wl,--exclude-libs,ALL"
|
||||||
];
|
];
|
||||||
rustPlatform-stable = pkgs.rustPlatform;
|
servicepoint-stable-size-args = {
|
||||||
rustPlatform-nightly = pkgs.makeRustPlatform fenix.complete;
|
|
||||||
rustPlatform-musl-stable = pkgs.pkgsMusl.rustPlatform;
|
|
||||||
rustPlatform-musl-nightly = pkgs.pkgsMusl.makeRustPlatform fenix.complete;
|
|
||||||
stable-release-args = {
|
|
||||||
inherit pkgs;
|
|
||||||
rustPlatform = rustPlatform-stable;
|
|
||||||
};
|
|
||||||
nightly-release-args = {
|
|
||||||
inherit pkgs;
|
|
||||||
rustPlatform = rustPlatform-nightly;
|
|
||||||
};
|
|
||||||
musl-stable-release-args = {
|
|
||||||
pkgs = pkgs.pkgsMusl;
|
|
||||||
rustPlatform = rustPlatform-musl-stable;
|
|
||||||
};
|
|
||||||
musl-nightly-release-args = {
|
|
||||||
pkgs = pkgs.pkgsMusl;
|
|
||||||
rustPlatform = rustPlatform-musl-nightly;
|
|
||||||
};
|
|
||||||
stable-size-args = {
|
|
||||||
buildType = "size_optimized";
|
buildType = "size_optimized";
|
||||||
buildNoDefaultFeatures = true;
|
buildNoDefaultFeatures = true;
|
||||||
};
|
};
|
||||||
nightly-size-args = {
|
servicepoint-unstable-size-args = {
|
||||||
cargoBuildFlags = [
|
# TODO: do these override the nix flags?
|
||||||
"-Zbuild-std=core,std,alloc,proc_macro,panic_abort"
|
CARGOFLAGS = ''-Zbuild-std="core,std,alloc,proc_macro,panic_abort" -Zbuild-std-features="panic_immediate_abort"'';
|
||||||
"-Zbuild-std-features=panic_immediate_abort"
|
|
||||||
];
|
|
||||||
# TODO: remove hard-coded target
|
|
||||||
nativeBuildInputs = [fenix.targets."x86_64-unknown-linux-gnu".latest.rust-std];
|
|
||||||
# TODO: those override the nix flags
|
# TODO: those override the nix flags
|
||||||
# NIX_CFLAGS_COMPILE = builtins.toString ["-Oz" "-fwrapv" "-fomit-frame-pointer" "-fno-stack-protector" "-fno-unroll-loops" "-fno-unwind-tables" "-fno-asynchronous-unwind-tables" "-fmerge-all-constants" "-fvisibility=hidden" "-Bsymbolic" "-fno-ident" "-fno-exceptions" "-ffunction-sections" "-fdata-sections"];
|
# NIX_CFLAGS_COMPILE = builtins.toString ["-Oz" "-fwrapv" "-fomit-frame-pointer" "-fno-stack-protector" "-fno-unroll-loops" "-fno-unwind-tables" "-fno-asynchronous-unwind-tables" "-fmerge-all-constants" "-fvisibility=hidden" "-Bsymbolic" "-fno-ident" "-fno-exceptions" "-ffunction-sections" "-fdata-sections"];
|
||||||
# NIX_CFLAGS_LINK = builtins.toString ["Wl,-z,norelro" "-Wl,--hash-style=gnu" "-Wl,--gc-sections" "-Wl,--exclude-libs,ALL"];
|
# NIX_CFLAGS_LINK = builtins.toString ["Wl,-z,norelro" "-Wl,--hash-style=gnu" "-Wl,--gc-sections" "-Wl,--exclude-libs,ALL"];
|
||||||
};
|
};
|
||||||
|
mkAllExamples =
|
||||||
|
suffix:
|
||||||
|
pkgs.symlinkJoin {
|
||||||
|
name = "servicepoint-all-examples";
|
||||||
|
paths = builtins.map (e: selfPkgs."${e}${suffix}") examples;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
servicepoint-binding-c-stable-release = mkServicepoint stable-release-args;
|
servicepoint-binding-c-stable-release = mkServicepoint {
|
||||||
servicepoint-binding-c-nightly-release = mkServicepoint nightly-release-args;
|
inherit pkgs;
|
||||||
servicepoint-binding-c-musl-stable-release = mkServicepoint musl-stable-release-args;
|
rustPlatform = rustPlatform-stable;
|
||||||
servicepoint-binding-c-musl-nightly-release = mkServicepoint musl-nightly-release-args;
|
};
|
||||||
|
servicepoint-binding-c-nightly-release = mkServicepoint {
|
||||||
|
inherit pkgs;
|
||||||
|
rustPlatform = rustPlatform-unstable;
|
||||||
|
};
|
||||||
|
servicepoint-binding-c-musl-stable-release = mkServicepoint {
|
||||||
|
pkgs = pkgs.pkgsMusl;
|
||||||
|
rustPlatform = rustPlatform-musl-stable;
|
||||||
|
};
|
||||||
|
servicepoint-binding-c-musl-nightly-release = mkServicepoint {
|
||||||
|
pkgs = pkgs.pkgsMusl;
|
||||||
|
rustPlatform = rustPlatform-musl-unstable;
|
||||||
|
};
|
||||||
|
|
||||||
servicepoint-binding-c-stable-size = mkServicepoint (stable-release-args // stable-size-args);
|
servicepoint-binding-c-stable-size =
|
||||||
servicepoint-binding-c-nightly-size = mkServicepoint (
|
servicepoint-binding-c-stable-release // servicepoint-stable-size-args;
|
||||||
nightly-release-args // stable-size-args // nightly-size-args
|
servicepoint-binding-c-nightly-size =
|
||||||
);
|
servicepoint-binding-c-nightly-release
|
||||||
servicepoint-binding-c-musl-stable-size = mkServicepoint (
|
// servicepoint-stable-size-args
|
||||||
musl-stable-release-args // stable-size-args
|
// servicepoint-unstable-size-args;
|
||||||
);
|
servicepoint-binding-c-musl-stable-size =
|
||||||
servicepoint-binding-c-musl-nightly-size = mkServicepoint (
|
servicepoint-binding-c-musl-stable-release // servicepoint-stable-size-args;
|
||||||
musl-nightly-release-args // stable-size-args // nightly-size-args
|
servicepoint-binding-c-musl-nightly-size =
|
||||||
);
|
servicepoint-binding-c-musl-nightly-release
|
||||||
|
// servicepoint-stable-size-args
|
||||||
|
// servicepoint-unstable-size-args;
|
||||||
|
|
||||||
# default variants
|
# default variants
|
||||||
servicepoint-binding-c = servicepoint-binding-c-stable-release;
|
servicepoint-binding-c = servicepoint-binding-c-stable-release;
|
||||||
|
@ -179,7 +167,6 @@ rec {
|
||||||
|
|
||||||
all-examples = mkAllExamples "";
|
all-examples = mkAllExamples "";
|
||||||
all-examples-size = mkAllExamples "-size";
|
all-examples-size = mkAllExamples "-size";
|
||||||
all-examples-nightly-size = mkAllExamples "-nightly-size";
|
|
||||||
# TODO: musl targets do not work on darwin
|
# TODO: musl targets do not work on darwin
|
||||||
all-examples-musl = mkAllExamples "-musl";
|
all-examples-musl = mkAllExamples "-musl";
|
||||||
all-examples-musl-static = mkAllExamples "-musl-static";
|
all-examples-musl-static = mkAllExamples "-musl-static";
|
||||||
|
@ -193,28 +180,27 @@ rec {
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c;
|
servicepointBinding = selfPkgs.servicepoint-binding-c;
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
# construct another pakage per example, but optimized for size with stable rust
|
# construct another pakage per example, but optimized for size with unstable rust
|
||||||
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-size") value) (
|
// (lib.mapAttrs'
|
||||||
lib.genAttrs examples (
|
(
|
||||||
name:
|
name: value:
|
||||||
mkExample {
|
lib.nameValuePair ("${name}-size") (
|
||||||
inherit name pkgs;
|
value
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c-stable-size;
|
// {
|
||||||
EXTRA_CFLAGS = builtins.toString size-cflags;
|
EXTRA_CFLAGS = builtins.toString size-cflags;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
# construct another pakage per example, but optimized for size with unstable rust
|
(
|
||||||
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-unstable-size") value) (
|
|
||||||
lib.genAttrs examples (
|
lib.genAttrs examples (
|
||||||
name:
|
name:
|
||||||
mkExample {
|
mkExample {
|
||||||
inherit name pkgs;
|
inherit name pkgs;
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
|
servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
|
||||||
EXTRA_CFLAGS = builtins.toString size-cflags;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
|
)
|
||||||
# construct another pakage per example, but with musl
|
# construct another pakage per example, but with musl
|
||||||
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl") value) (
|
// (lib.mapAttrs' (name: value: lib.nameValuePair ("${name}-musl") value) (
|
||||||
lib.genAttrs examples (
|
lib.genAttrs examples (
|
||||||
|
@ -222,7 +208,7 @@ rec {
|
||||||
mkExample {
|
mkExample {
|
||||||
inherit name;
|
inherit name;
|
||||||
pkgs = pkgs.pkgsMusl;
|
pkgs = pkgs.pkgsMusl;
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c-musl-stable-release;
|
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
@ -233,8 +219,10 @@ rec {
|
||||||
mkExample {
|
mkExample {
|
||||||
inherit name;
|
inherit name;
|
||||||
pkgs = pkgs.pkgsMusl;
|
pkgs = pkgs.pkgsMusl;
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c-musl-stable-release;
|
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
|
||||||
static = true;
|
}
|
||||||
|
// {
|
||||||
|
EXTRA_CFLAGS = "-static";
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
@ -245,9 +233,10 @@ rec {
|
||||||
mkExample {
|
mkExample {
|
||||||
inherit name;
|
inherit name;
|
||||||
pkgs = pkgs.pkgsMusl;
|
pkgs = pkgs.pkgsMusl;
|
||||||
servicepointBinding = selfPkgs.servicepoint-binding-c-musl-stable-size;
|
servicepointBinding = selfPkgs.servicepoint-binding-c-musl;
|
||||||
static = true;
|
}
|
||||||
EXTRA_CFLAGS = builtins.toString size-cflags;
|
// {
|
||||||
|
EXTRA_CFLAGS = "-static" + builtins.toString size-cflags;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{
|
use crate::mem::{
|
||||||
macros::{wrap_clone, wrap_free},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
|
||||||
};
|
};
|
||||||
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin, Packet};
|
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin, Packet};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
@ -45,8 +44,21 @@ pub unsafe extern "C" fn sp_cmd_bitmap_try_into_packet(
|
||||||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(BitmapCommand, sp_cmd_bitmap);
|
/// Clones an [BitmapCommand] instance.
|
||||||
wrap_free!(BitmapCommand, sp_cmd_bitmap);
|
///
|
||||||
|
/// returns: a new [BitmapCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_bitmap_clone(
|
||||||
|
command: NonNull<BitmapCommand>,
|
||||||
|
) -> NonNull<BitmapCommand> {
|
||||||
|
unsafe { heap_clone(command) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [BitmapCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_bitmap_free(command: NonNull<BitmapCommand>) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a pointer to the provided `BitmapCommand`.
|
/// Returns a pointer to the provided `BitmapCommand`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{
|
use crate::mem::{
|
||||||
macros::{wrap_clone, wrap_free},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
|
||||||
};
|
};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
|
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
|
||||||
|
@ -45,8 +44,21 @@ pub unsafe extern "C" fn sp_cmd_bitvec_try_into_packet(
|
||||||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(BitVecCommand, sp_cmd_bitvec);
|
/// Clones an [BitVecCommand] instance.
|
||||||
wrap_free!(BitVecCommand, sp_cmd_bitvec);
|
///
|
||||||
|
/// returns: a new [BitVecCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_bitvec_clone(
|
||||||
|
command: NonNull<BitVecCommand>,
|
||||||
|
) -> NonNull<BitVecCommand> {
|
||||||
|
unsafe { heap_clone(command) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [BitVecCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_bitvec_free(command: NonNull<BitVecCommand>) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::{
|
use crate::mem::{
|
||||||
macros::{wrap_clone, wrap_free},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
};
|
||||||
|
use servicepoint::{
|
||||||
|
BitmapCommand, BrightnessGrid, BrightnessGridCommand, Origin, Packet,
|
||||||
};
|
};
|
||||||
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin, Packet};
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Set the brightness of individual tiles in a rectangular area of the display.
|
/// Set the brightness of individual tiles in a rectangular area of the display.
|
||||||
|
@ -41,8 +42,23 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_into_packet(
|
||||||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(BrightnessGridCommand, sp_cmd_brightness_grid);
|
/// Clones an [BrightnessGridCommand] instance.
|
||||||
wrap_free!(BrightnessGridCommand, sp_cmd_brightness_grid);
|
///
|
||||||
|
/// returns: a new [BrightnessGridCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_brightness_grid_clone(
|
||||||
|
command: NonNull<BrightnessGridCommand>,
|
||||||
|
) -> NonNull<BrightnessGridCommand> {
|
||||||
|
unsafe { heap_clone(command) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [BitmapCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_brightness_grid_free(
|
||||||
|
command: NonNull<BitmapCommand>,
|
||||||
|
) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
|
/// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{macros::wrap_free, mem::heap_move_nonnull};
|
use crate::mem::{heap_drop, heap_move_nonnull};
|
||||||
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
|
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
|
@ -12,7 +12,11 @@ pub unsafe extern "C" fn sp_cmd_clear_new() -> NonNull<ClearCommand> {
|
||||||
heap_move_nonnull(ClearCommand)
|
heap_move_nonnull(ClearCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_free!(ClearCommand, sp_cmd_clear);
|
/// Deallocates a [ClearCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_clear_free(command: NonNull<ClearCommand>) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Kills the udp daemon on the display, which usually results in a restart.
|
/// Kills the udp daemon on the display, which usually results in a restart.
|
||||||
///
|
///
|
||||||
|
@ -24,7 +28,13 @@ pub unsafe extern "C" fn sp_cmd_hard_reset_new() -> NonNull<HardResetCommand> {
|
||||||
heap_move_nonnull(HardResetCommand)
|
heap_move_nonnull(HardResetCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_free!(HardResetCommand, sp_cmd_hard_reset);
|
/// Deallocates a [HardResetCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_hard_reset_free(
|
||||||
|
command: NonNull<ClearCommand>,
|
||||||
|
) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// A yet-to-be-tested command.
|
/// A yet-to-be-tested command.
|
||||||
///
|
///
|
||||||
|
@ -34,4 +44,8 @@ pub unsafe extern "C" fn sp_cmd_fade_out_new() -> NonNull<FadeOutCommand> {
|
||||||
heap_move_nonnull(FadeOutCommand)
|
heap_move_nonnull(FadeOutCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_free!(FadeOutCommand, sp_cmd_fade_out);
|
/// Deallocates a [FadeOutCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_fade_out_free(command: NonNull<ClearCommand>) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::{
|
use crate::mem::{
|
||||||
macros::{wrap_clone, wrap_free},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
|
||||||
};
|
};
|
||||||
use servicepoint::{CharGrid, CharGridCommand, Origin, Packet};
|
use servicepoint::{BitmapCommand, CharGrid, CharGridCommand, Origin, Packet};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Show UTF-8 encoded text on the screen.
|
/// Show UTF-8 encoded text on the screen.
|
||||||
|
@ -41,8 +40,23 @@ pub unsafe extern "C" fn sp_cmd_char_grid_try_into_packet(
|
||||||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(CharGridCommand, sp_cmd_char_grid);
|
/// Clones an [CharGridCommand] instance.
|
||||||
wrap_free!(CharGridCommand, sp_cmd_char_grid);
|
///
|
||||||
|
/// returns: a new [CharGridCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_char_grid_clone(
|
||||||
|
command: NonNull<CharGridCommand>,
|
||||||
|
) -> NonNull<CharGridCommand> {
|
||||||
|
unsafe { heap_clone(command) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [BitmapCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_char_grid_free(
|
||||||
|
command: NonNull<BitmapCommand>,
|
||||||
|
) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Moves the provided [CharGrid] to be contained in the [CharGridCommand].
|
/// Moves the provided [CharGrid] to be contained in the [CharGridCommand].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::{
|
use crate::mem::{
|
||||||
macros::{wrap_clone, wrap_free},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
};
|
||||||
|
use servicepoint::{
|
||||||
|
BitmapCommand, Cp437Grid, Cp437GridCommand, Origin, Packet,
|
||||||
};
|
};
|
||||||
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin, Packet};
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Show text on the screen.
|
/// Show text on the screen.
|
||||||
|
@ -41,8 +42,23 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_try_into_packet(
|
||||||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(Cp437GridCommand, sp_cmd_cp437_grid);
|
/// Clones an [Cp437GridCommand] instance.
|
||||||
wrap_free!(Cp437GridCommand, sp_cmd_cp437_grid);
|
///
|
||||||
|
/// returns: a new [Cp437GridCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_cp437_grid_clone(
|
||||||
|
command: NonNull<Cp437GridCommand>,
|
||||||
|
) -> NonNull<Cp437GridCommand> {
|
||||||
|
unsafe { heap_clone(command) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [Cp437GridCommand].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_cp437_grid_free(
|
||||||
|
command: NonNull<BitmapCommand>,
|
||||||
|
) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Moves the provided bitmap into the provided command.
|
/// Moves the provided bitmap into the provided command.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use crate::{
|
use crate::mem::{heap_clone, heap_drop, heap_move_nonnull, heap_remove};
|
||||||
macros::{wrap_clone, wrap_free},
|
use servicepoint::{
|
||||||
mem::{heap_move_nonnull, heap_remove},
|
BitmapCommand, Brightness, GlobalBrightnessCommand, Packet,
|
||||||
};
|
};
|
||||||
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Set the brightness of all tiles to the same value.
|
/// Set the brightness of all tiles to the same value.
|
||||||
|
@ -22,8 +21,22 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_into_packet(
|
||||||
heap_move_nonnull(unsafe { heap_remove(command) }.into())
|
heap_move_nonnull(unsafe { heap_remove(command) }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(GlobalBrightnessCommand, sp_cmd_brightness_global);
|
/// Clones an [GlobalBrightnessCommand] instance.
|
||||||
wrap_free!(GlobalBrightnessCommand, sp_cmd_brightness_global);
|
///
|
||||||
|
/// returns: a new [GlobalBrightnessCommand] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_brightness_global_clone(
|
||||||
|
command: NonNull<GlobalBrightnessCommand>,
|
||||||
|
) -> NonNull<GlobalBrightnessCommand> {
|
||||||
|
unsafe { heap_clone(command) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cmd_brightness_global_free(
|
||||||
|
command: NonNull<BitmapCommand>,
|
||||||
|
) {
|
||||||
|
unsafe { heap_drop(command) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Moves the provided bitmap to be contained in the command.
|
/// Moves the provided bitmap to be contained in the command.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free, wrap_method},
|
mem::{
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some,
|
||||||
|
heap_remove,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
|
Bitmap, BitmapCommand, CompressionCode, DataRef, DisplayBitVec, Grid,
|
||||||
|
@ -80,70 +82,112 @@ pub unsafe extern "C" fn sp_bitmap_from_bitvec(
|
||||||
heap_move_ok(Bitmap::from_bitvec(width, bitvec))
|
heap_move_ok(Bitmap::from_bitvec(width, bitvec))
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(Bitmap, sp_bitmap);
|
/// Clones a [Bitmap].
|
||||||
wrap_free!(Bitmap, sp_bitmap);
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitmap_clone(
|
||||||
|
bitmap: NonNull<Bitmap>,
|
||||||
|
) -> NonNull<Bitmap> {
|
||||||
|
unsafe { heap_clone(bitmap) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Deallocates a [Bitmap].
|
||||||
sp_bitmap :: Bitmap;
|
#[no_mangle]
|
||||||
/// Gets the current value at the specified position.
|
pub unsafe extern "C" fn sp_bitmap_free(bitmap: NonNull<Bitmap>) {
|
||||||
///
|
unsafe { heap_drop(bitmap) }
|
||||||
/// # Arguments
|
}
|
||||||
///
|
|
||||||
/// - `x` and `y`: position of the cell to read
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when accessing `x` or `y` out of bounds
|
|
||||||
ref fn get(x: usize, y: usize) -> bool;
|
|
||||||
);
|
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the current value at the specified position in the [Bitmap].
|
||||||
sp_bitmap :: Bitmap;
|
///
|
||||||
/// Sets the value of the specified position.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `bitmap`: instance to read from
|
||||||
///
|
/// - `x` and `y`: position of the cell to read
|
||||||
/// - `x` and `y`: position of the cell
|
///
|
||||||
/// - `value`: the value to write to the cell
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
#[no_mangle]
|
||||||
/// - when accessing `x` or `y` out of bounds
|
pub unsafe extern "C" fn sp_bitmap_get(
|
||||||
mut fn set(x: usize, y: usize, value: bool);
|
bitmap: NonNull<Bitmap>,
|
||||||
);
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
) -> bool {
|
||||||
|
unsafe { bitmap.as_ref().get(x, y) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of the specified position in the [Bitmap].
|
||||||
sp_bitmap :: Bitmap;
|
///
|
||||||
/// Sets the state of all pixels in the [Bitmap].
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `bitmap`: instance to write to
|
||||||
///
|
/// - `x` and `y`: position of the cell
|
||||||
/// - `value`: the value to set all pixels to
|
/// - `value`: the value to write to the cell
|
||||||
mut fn fill(value: bool);
|
///
|
||||||
);
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when accessing `x` or `y` out of bounds
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitmap_set(
|
||||||
|
bitmap: NonNull<Bitmap>,
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
value: bool,
|
||||||
|
) {
|
||||||
|
unsafe { (*bitmap.as_ptr()).set(x, y, value) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the state of all pixels in the [Bitmap].
|
||||||
sp_bitmap :: Bitmap;
|
///
|
||||||
/// Gets the width in pixels.
|
/// # Arguments
|
||||||
ref fn width() -> usize;
|
///
|
||||||
);
|
/// - `bitmap`: instance to write to
|
||||||
|
/// - `value`: the value to set all pixels to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitmap_fill(bitmap: NonNull<Bitmap>, value: bool) {
|
||||||
|
unsafe { (*bitmap.as_ptr()).fill(value) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the width in pixels of the [Bitmap] instance.
|
||||||
sp_bitmap :: Bitmap;
|
///
|
||||||
/// Gets the height in pixels.
|
/// # Arguments
|
||||||
ref fn height() -> usize;
|
///
|
||||||
);
|
/// - `bitmap`: instance to read from
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when `bitmap` is NULL
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// The caller has to make sure that:
|
||||||
|
///
|
||||||
|
/// - `bitmap` points to a valid [Bitmap]
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitmap_width(bitmap: NonNull<Bitmap>) -> usize {
|
||||||
|
unsafe { bitmap.as_ref().width() }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the height in pixels of the [Bitmap] instance.
|
||||||
sp_bitmap :: Bitmap;
|
///
|
||||||
/// Gets an unsafe reference to the data of the [Bitmap] instance.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// The returned memory is valid for the lifetime of the bitmap.
|
/// - `bitmap`: instance to read from
|
||||||
mut fn data_ref_mut() -> ByteSlice;
|
#[no_mangle]
|
||||||
|slice| unsafe { ByteSlice::from_slice(slice) };
|
pub unsafe extern "C" fn sp_bitmap_height(bitmap: NonNull<Bitmap>) -> usize {
|
||||||
);
|
unsafe { bitmap.as_ref().height() }
|
||||||
|
}
|
||||||
|
|
||||||
/// Consumes the Bitmap and returns the contained BitVec.
|
/// Gets an unsafe reference to the data of the [Bitmap] instance.
|
||||||
|
///
|
||||||
|
/// The returned memory is valid for the lifetime of the bitmap.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitmap_unsafe_data_ref(
|
||||||
|
mut bitmap: NonNull<Bitmap>,
|
||||||
|
) -> ByteSlice {
|
||||||
|
unsafe { ByteSlice::from_slice(bitmap.as_mut().data_ref_mut()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Consumes the Bitmap and returns the contained BitVec
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_bitmap_into_bitvec(
|
pub unsafe extern "C" fn sp_bitmap_into_bitvec(
|
||||||
bitmap: NonNull<Bitmap>,
|
bitmap: NonNull<Bitmap>,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free, wrap_method},
|
mem::{
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
|
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Packet,
|
||||||
|
@ -35,72 +36,111 @@ pub unsafe extern "C" fn sp_bitvec_load(
|
||||||
heap_move_nonnull(DisplayBitVec::from_slice(data))
|
heap_move_nonnull(DisplayBitVec::from_slice(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(DisplayBitVec, sp_bitvec);
|
/// Clones a [DisplayBitVec].
|
||||||
wrap_free!(DisplayBitVec, sp_bitvec);
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_clone(
|
||||||
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
) -> NonNull<DisplayBitVec> {
|
||||||
|
unsafe { heap_clone(bit_vec) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Deallocates a [DisplayBitVec].
|
||||||
sp_bitvec :: DisplayBitVec;
|
#[no_mangle]
|
||||||
/// Gets the value of a bit.
|
pub unsafe extern "C" fn sp_bitvec_free(bit_vec: NonNull<DisplayBitVec>) {
|
||||||
///
|
unsafe { heap_drop(bit_vec) }
|
||||||
/// # Arguments
|
}
|
||||||
///
|
|
||||||
/// - `bit_vec`: instance to read from
|
|
||||||
/// - `index`: the bit index to read
|
|
||||||
///
|
|
||||||
/// returns: value of the bit
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when accessing `index` out of bounds
|
|
||||||
ref fn get(index: usize) -> bool;
|
|
||||||
|result| result.map(|x| *x).unwrap_or(false);
|
|
||||||
);
|
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the value of a bit from the [DisplayBitVec].
|
||||||
sp_bitvec :: DisplayBitVec;
|
///
|
||||||
/// Sets the value of a bit.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `bit_vec`: instance to read from
|
||||||
///
|
/// - `index`: the bit index to read
|
||||||
/// - `index`: the bit index to edit
|
///
|
||||||
/// - `value`: the value to set the bit to
|
/// returns: value of the bit
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// - when accessing `index` out of bounds
|
/// - when accessing `index` out of bounds
|
||||||
mut fn set(index: usize, value: bool);
|
#[no_mangle]
|
||||||
);
|
pub unsafe extern "C" fn sp_bitvec_get(
|
||||||
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
index: usize,
|
||||||
|
) -> bool {
|
||||||
|
unsafe { *bit_vec.as_ref().get(index).unwrap() }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of a bit in the [DisplayBitVec].
|
||||||
sp_bitvec :: DisplayBitVec;
|
///
|
||||||
/// Sets the value of all bits.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `bit_vec`: instance to write to
|
||||||
///
|
/// - `index`: the bit index to edit
|
||||||
/// - `value`: the value to set all bits to
|
/// - `value`: the value to set the bit to
|
||||||
mut fn fill(value: bool);
|
///
|
||||||
);
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when accessing `index` out of bounds
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_set(
|
||||||
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
index: usize,
|
||||||
|
value: bool,
|
||||||
|
) {
|
||||||
|
unsafe { (*bit_vec.as_ptr()).set(index, value) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of all bits in the [DisplayBitVec].
|
||||||
sp_bitvec :: DisplayBitVec;
|
///
|
||||||
/// Gets the length in bits.
|
/// # Arguments
|
||||||
ref fn len() -> usize;
|
///
|
||||||
);
|
/// - `bit_vec`: instance to write to
|
||||||
|
/// - `value`: the value to set all bits to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_fill(
|
||||||
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
value: bool,
|
||||||
|
) {
|
||||||
|
unsafe { (*bit_vec.as_ptr()).fill(value) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the length of the [DisplayBitVec] in bits.
|
||||||
sp_bitvec :: DisplayBitVec;
|
///
|
||||||
/// Returns true if length is 0.
|
/// # Arguments
|
||||||
ref fn is_empty() -> bool;
|
///
|
||||||
);
|
/// - `bit_vec`: instance to write to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_len(
|
||||||
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { bit_vec.as_ref().len() }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Returns true if length is 0.
|
||||||
sp_bitvec :: DisplayBitVec;
|
///
|
||||||
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// The returned memory is valid for the lifetime of the bitvec.
|
/// - `bit_vec`: instance to write to
|
||||||
mut fn as_raw_mut_slice() -> ByteSlice;
|
#[no_mangle]
|
||||||
|slice| unsafe { ByteSlice::from_slice(slice) };
|
pub unsafe extern "C" fn sp_bitvec_is_empty(
|
||||||
);
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
) -> bool {
|
||||||
|
unsafe { bit_vec.as_ref().is_empty() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an unsafe reference to the data of the [DisplayBitVec] instance.
|
||||||
|
///
|
||||||
|
/// The returned memory is valid for the lifetime of the bitvec.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `bit_vec`: instance to write to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
|
||||||
|
bit_vec: NonNull<DisplayBitVec>,
|
||||||
|
) -> ByteSlice {
|
||||||
|
unsafe { ByteSlice::from_slice((*bit_vec.as_ptr()).as_raw_mut_slice()) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
/// Creates a [BitVecCommand] and immediately turns that into a [Packet].
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free, wrap_method},
|
mem::{
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some,
|
||||||
|
heap_remove,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
|
Brightness, BrightnessGrid, BrightnessGridCommand, ByteGrid, DataRef, Grid,
|
||||||
Origin, Packet,
|
Origin, Packet,
|
||||||
};
|
};
|
||||||
use std::{mem::transmute, ptr::NonNull};
|
use std::mem::transmute;
|
||||||
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Creates a new [BrightnessGrid] with the specified dimensions.
|
/// Creates a new [BrightnessGrid] with the specified dimensions.
|
||||||
///
|
///
|
||||||
|
@ -52,76 +55,128 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(BrightnessGrid, sp_brightness_grid);
|
/// Clones a [BrightnessGrid].
|
||||||
wrap_free!(BrightnessGrid, sp_brightness_grid);
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_brightness_grid_clone(
|
||||||
|
grid: NonNull<BrightnessGrid>,
|
||||||
|
) -> NonNull<BrightnessGrid> {
|
||||||
|
unsafe { heap_clone(grid) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Deallocates a [BrightnessGrid].
|
||||||
sp_brightness_grid :: BrightnessGrid;
|
#[no_mangle]
|
||||||
/// Gets the current value at the specified position.
|
pub unsafe extern "C" fn sp_brightness_grid_free(
|
||||||
///
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
/// # Arguments
|
) {
|
||||||
///
|
unsafe { heap_drop(brightness_grid) }
|
||||||
/// - `x` and `y`: position of the cell to read
|
}
|
||||||
///
|
|
||||||
/// returns: value at position
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
/// - When accessing `x` or `y` out of bounds.
|
|
||||||
ref fn get(x: usize, y: usize) -> Brightness;
|
|
||||||
);
|
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the current value at the specified position.
|
||||||
sp_brightness_grid :: BrightnessGrid;
|
///
|
||||||
/// Sets the value of the specified position.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `brightness_grid`: instance to read from
|
||||||
///
|
/// - `x` and `y`: position of the cell to read
|
||||||
/// - `x` and `y`: position of the cell
|
///
|
||||||
/// - `value`: the value to write to the cell
|
/// returns: value at position
|
||||||
///
|
///
|
||||||
/// returns: old value of the cell
|
/// # Panics
|
||||||
///
|
/// - When accessing `x` or `y` out of bounds.
|
||||||
/// # Panics
|
#[no_mangle]
|
||||||
///
|
pub unsafe extern "C" fn sp_brightness_grid_get(
|
||||||
/// - When accessing `x` or `y` out of bounds.
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
mut fn set(x: usize, y: usize, value: Brightness);
|
x: usize,
|
||||||
);
|
y: usize,
|
||||||
|
) -> Brightness {
|
||||||
|
unsafe { brightness_grid.as_ref().get(x, y) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of the specified position in the [BrightnessGrid].
|
||||||
sp_brightness_grid :: BrightnessGrid;
|
///
|
||||||
/// Sets the value of all cells.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `brightness_grid`: instance to write to
|
||||||
///
|
/// - `x` and `y`: position of the cell
|
||||||
/// - `value`: the value to set all cells to
|
/// - `value`: the value to write to the cell
|
||||||
mut fn fill(value: Brightness);
|
///
|
||||||
);
|
/// returns: old value of the cell
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - When accessing `x` or `y` out of bounds.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_brightness_grid_set(
|
||||||
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
value: Brightness,
|
||||||
|
) {
|
||||||
|
unsafe { (*brightness_grid.as_ptr()).set(x, y, value) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of all cells in the [BrightnessGrid].
|
||||||
sp_brightness_grid :: BrightnessGrid;
|
///
|
||||||
/// Gets the width of the grid.
|
/// # Arguments
|
||||||
ref fn width() -> usize;
|
///
|
||||||
);
|
/// - `brightness_grid`: instance to write to
|
||||||
|
/// - `value`: the value to set all cells to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_brightness_grid_fill(
|
||||||
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
|
value: Brightness,
|
||||||
|
) {
|
||||||
|
unsafe { (*brightness_grid.as_ptr()).fill(value) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the width of the [BrightnessGrid] instance.
|
||||||
sp_brightness_grid :: BrightnessGrid;
|
///
|
||||||
/// Gets the height of the grid.
|
/// # Arguments
|
||||||
ref fn height() -> usize;
|
///
|
||||||
);
|
/// - `brightness_grid`: instance to read from
|
||||||
|
///
|
||||||
|
/// returns: width
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_brightness_grid_width(
|
||||||
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { brightness_grid.as_ref().width() }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the height of the [BrightnessGrid] instance.
|
||||||
sp_brightness_grid :: BrightnessGrid;
|
///
|
||||||
/// Gets an unsafe reference to the data of the instance.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// The returned memory is valid for the lifetime of the grid.
|
/// - `brightness_grid`: instance to read from
|
||||||
mut fn data_ref_mut() -> ByteSlice;
|
///
|
||||||
|br_slice| unsafe {
|
/// returns: height
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_brightness_grid_height(
|
||||||
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { brightness_grid.as_ref().height() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an unsafe reference to the data of the [BrightnessGrid] instance.
|
||||||
|
///
|
||||||
|
/// The returned memory is valid for the lifetime of the brightness grid.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `brightness_grid`: instance to read from
|
||||||
|
///
|
||||||
|
/// returns: slice of bytes underlying the `brightness_grid`.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref(
|
||||||
|
brightness_grid: NonNull<BrightnessGrid>,
|
||||||
|
) -> ByteSlice {
|
||||||
//noinspection RsAssertEqual
|
//noinspection RsAssertEqual
|
||||||
const _: () = assert!(size_of::<Brightness>() == 1);
|
const _: () = assert!(size_of::<Brightness>() == 1);
|
||||||
|
|
||||||
ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(br_slice))
|
let data = unsafe { (*brightness_grid.as_ptr()).data_ref_mut() };
|
||||||
};
|
unsafe {
|
||||||
);
|
ByteSlice::from_slice(transmute::<&mut [Brightness], &mut [u8]>(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
/// Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free, wrap_method},
|
mem::{
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
use servicepoint::{CharGrid, CharGridCommand, Grid, Origin, Packet};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
@ -39,66 +40,99 @@ pub unsafe extern "C" fn sp_char_grid_load(
|
||||||
heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec()))
|
heap_move_ok(CharGrid::load_utf8(width, height, data.to_vec()))
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(CharGrid, sp_char_grid);
|
/// Clones a [CharGrid].
|
||||||
wrap_free!(CharGrid, sp_char_grid);
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_char_grid_clone(
|
||||||
|
grid: NonNull<CharGrid>,
|
||||||
|
) -> NonNull<CharGrid> {
|
||||||
|
unsafe { heap_clone(grid) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Deallocates a [CharGrid].
|
||||||
sp_char_grid :: CharGrid;
|
#[no_mangle]
|
||||||
/// Returns the current value at the specified position.
|
pub unsafe extern "C" fn sp_char_grid_free(char_grid: NonNull<CharGrid>) {
|
||||||
///
|
unsafe { heap_drop(char_grid) }
|
||||||
/// # Arguments
|
}
|
||||||
///
|
|
||||||
/// - `x` and `y`: position of the cell to read
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when accessing `x` or `y` out of bounds
|
|
||||||
ref fn get(x: usize, y: usize) -> u32;
|
|
||||||
| char | char as u32
|
|
||||||
);
|
|
||||||
|
|
||||||
wrap_method!(
|
/// Returns the current value at the specified position.
|
||||||
sp_char_grid :: CharGrid;
|
///
|
||||||
/// Sets the value of the specified position in the grid.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `char_grid`: instance to read from
|
||||||
///
|
/// - `x` and `y`: position of the cell to read
|
||||||
/// - `x` and `y`: position of the cell
|
///
|
||||||
/// - `value`: the value to write to the cell
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// returns: old value of the cell
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
#[no_mangle]
|
||||||
/// # Panics
|
pub unsafe extern "C" fn sp_char_grid_get(
|
||||||
///
|
char_grid: NonNull<CharGrid>,
|
||||||
/// - when accessing `x` or `y` out of bounds
|
x: usize,
|
||||||
/// - when providing values that cannot be converted to Rust's `char`.
|
y: usize,
|
||||||
mut fn set(x: usize, y: usize, value: u32);
|
) -> u32 {
|
||||||
let value = char::from_u32(value).unwrap();
|
unsafe { char_grid.as_ref().get(x, y) as u32 }
|
||||||
);
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of the specified position in the [CharGrid].
|
||||||
sp_char_grid :: CharGrid;
|
///
|
||||||
/// Sets the value of all cells in the grid.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `char_grid`: instance to write to
|
||||||
///
|
/// - `x` and `y`: position of the cell
|
||||||
/// - `value`: the value to set all cells to
|
/// - `value`: the value to write to the cell
|
||||||
/// - when providing values that cannot be converted to Rust's `char`.
|
///
|
||||||
mut fn fill(value: u32);
|
/// returns: old value of the cell
|
||||||
let value = char::from_u32(value).unwrap();
|
///
|
||||||
);
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when accessing `x` or `y` out of bounds
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_char_grid_set(
|
||||||
|
char_grid: NonNull<CharGrid>,
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
value: u32,
|
||||||
|
) {
|
||||||
|
unsafe { (*char_grid.as_ptr()).set(x, y, char::from_u32(value).unwrap()) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of all cells in the [CharGrid].
|
||||||
sp_char_grid :: CharGrid;
|
///
|
||||||
/// Gets the width of the grid.
|
/// # Arguments
|
||||||
ref fn width() -> usize;
|
///
|
||||||
);
|
/// - `char_grid`: instance to write to
|
||||||
|
/// - `value`: the value to set all cells to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_char_grid_fill(
|
||||||
|
char_grid: NonNull<CharGrid>,
|
||||||
|
value: u32,
|
||||||
|
) {
|
||||||
|
unsafe { (*char_grid.as_ptr()).fill(char::from_u32(value).unwrap()) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the width of the [CharGrid] instance.
|
||||||
sp_char_grid :: CharGrid;
|
///
|
||||||
/// Gets the height of the grid.
|
/// # Arguments
|
||||||
ref fn height() -> usize;
|
///
|
||||||
);
|
/// - `char_grid`: instance to read from
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_char_grid_width(
|
||||||
|
char_grid: NonNull<CharGrid>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { char_grid.as_ref().width() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the height of the [CharGrid] instance.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// - `char_grid`: instance to read from
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_char_grid_height(
|
||||||
|
char_grid: NonNull<CharGrid>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { char_grid.as_ref().height() }
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
/// Creates a [CharGridCommand] and immediately turns that into a [Packet].
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free, wrap_method},
|
mem::{
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_move_some, heap_remove},
|
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_move_some,
|
||||||
|
heap_remove,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
|
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
|
||||||
|
@ -30,71 +32,109 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
|
||||||
heap_move_some(Cp437Grid::load(width, height, data))
|
heap_move_some(Cp437Grid::load(width, height, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(Cp437Grid, sp_cp437_grid);
|
/// Clones a [Cp437Grid].
|
||||||
wrap_free!(Cp437Grid, sp_cp437_grid);
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cp437_grid_clone(
|
||||||
|
grid: NonNull<Cp437Grid>,
|
||||||
|
) -> NonNull<Cp437Grid> {
|
||||||
|
unsafe { heap_clone(grid) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Deallocates a [Cp437Grid].
|
||||||
sp_cp437 :: Cp437Grid;
|
#[no_mangle]
|
||||||
/// Gets the current value at the specified position.
|
pub unsafe extern "C" fn sp_cp437_grid_free(cp437_grid: NonNull<Cp437Grid>) {
|
||||||
///
|
unsafe { heap_drop(cp437_grid) }
|
||||||
/// # Arguments
|
}
|
||||||
///
|
|
||||||
/// - `x` and `y`: position of the cell to read
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// - when accessing `x` or `y` out of bounds
|
|
||||||
ref fn get(x: usize, y: usize) -> u8;
|
|
||||||
);
|
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the current value at the specified position.
|
||||||
sp_cp437 :: Cp437Grid;
|
///
|
||||||
/// Sets the value at the specified position.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `cp437_grid`: instance to read from
|
||||||
///
|
/// - `x` and `y`: position of the cell to read
|
||||||
/// - `x` and `y`: position of the cell
|
///
|
||||||
/// - `value`: the value to write to the cell
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// returns: old value of the cell
|
/// - when accessing `x` or `y` out of bounds
|
||||||
///
|
#[no_mangle]
|
||||||
/// # Panics
|
pub unsafe extern "C" fn sp_cp437_grid_get(
|
||||||
///
|
cp437_grid: NonNull<Cp437Grid>,
|
||||||
/// - when accessing `x` or `y` out of bounds
|
x: usize,
|
||||||
mut fn set(x: usize, y: usize, value: u8);
|
y: usize,
|
||||||
);
|
) -> u8 {
|
||||||
|
unsafe { cp437_grid.as_ref().get(x, y) }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of the specified position in the [Cp437Grid].
|
||||||
sp_cp437 :: Cp437Grid;
|
///
|
||||||
/// Sets the value of all cells in the grid.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// - `cp437_grid`: instance to write to
|
||||||
///
|
/// - `x` and `y`: position of the cell
|
||||||
/// - `cp437_grid`: instance to write to
|
/// - `value`: the value to write to the cell
|
||||||
/// - `value`: the value to set all cells to
|
///
|
||||||
mut fn fill(value: u8);
|
/// returns: old value of the cell
|
||||||
);
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// - when accessing `x` or `y` out of bounds
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cp437_grid_set(
|
||||||
|
cp437_grid: NonNull<Cp437Grid>,
|
||||||
|
x: usize,
|
||||||
|
y: usize,
|
||||||
|
value: u8,
|
||||||
|
) {
|
||||||
|
unsafe { (*cp437_grid.as_ptr()).set(x, y, value) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Sets the value of all cells in the [Cp437Grid].
|
||||||
sp_cp437 :: Cp437Grid;
|
///
|
||||||
/// Gets the width of the grid.
|
/// # Arguments
|
||||||
ref fn width() -> usize;
|
///
|
||||||
);
|
/// - `cp437_grid`: instance to write to
|
||||||
|
/// - `value`: the value to set all cells to
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cp437_grid_fill(
|
||||||
|
cp437_grid: NonNull<Cp437Grid>,
|
||||||
|
value: u8,
|
||||||
|
) {
|
||||||
|
unsafe { (*cp437_grid.as_ptr()).fill(value) };
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the width of the [Cp437Grid] instance.
|
||||||
sp_cp437 :: Cp437Grid;
|
///
|
||||||
/// Gets the height of the grid.
|
/// # Arguments
|
||||||
ref fn height() -> usize;
|
///
|
||||||
);
|
/// - `cp437_grid`: instance to read from
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cp437_grid_width(
|
||||||
|
cp437_grid: NonNull<Cp437Grid>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { cp437_grid.as_ref().width() }
|
||||||
|
}
|
||||||
|
|
||||||
wrap_method!(
|
/// Gets the height of the [Cp437Grid] instance.
|
||||||
sp_cp437 :: Cp437Grid;
|
///
|
||||||
/// Gets an unsafe reference to the data of the grid.
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// The returned memory is valid for the lifetime of the instance.
|
/// - `cp437_grid`: instance to read from
|
||||||
mut fn data_ref_mut() -> ByteSlice;
|
#[no_mangle]
|
||||||
| slice | unsafe { ByteSlice::from_slice(slice) };
|
pub unsafe extern "C" fn sp_cp437_grid_height(
|
||||||
);
|
cp437_grid: NonNull<Cp437Grid>,
|
||||||
|
) -> usize {
|
||||||
|
unsafe { cp437_grid.as_ref().height() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an unsafe reference to the data of the [Cp437Grid] instance.
|
||||||
|
///
|
||||||
|
/// The returned memory is valid for the lifetime of the grid.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
|
||||||
|
cp437_grid: NonNull<Cp437Grid>,
|
||||||
|
) -> ByteSlice {
|
||||||
|
unsafe { ByteSlice::from_slice((*cp437_grid.as_ptr()).data_ref_mut()) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
/// Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
|
||||||
///
|
///
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
/// Functions related to [servicepoint::Bitmap], [servicepoint::CharGrid] and friends.
|
/// Functions related to [servicepoint::Bitmap], [servicepoint::CharGrid] and friends.
|
||||||
pub mod containers;
|
pub mod containers;
|
||||||
mod macros;
|
|
||||||
pub(crate) mod mem;
|
pub(crate) mod mem;
|
||||||
/// Functions related to [Packet].
|
/// Functions related to [Packet].
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
macro_rules! wrap_free {
|
|
||||||
($typ:ty, $prefix:ident) => {
|
|
||||||
paste::paste! {
|
|
||||||
#[doc = concat!("Deallocates a [", stringify!($typ), "] instance.")]
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn [<$prefix _free>](instance: NonNull<$typ>) {
|
|
||||||
unsafe { $crate::mem::heap_drop(instance) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! wrap_clone {
|
|
||||||
($typ:ty, $prefix:ident) => {
|
|
||||||
paste::paste! {
|
|
||||||
#[doc = concat!("Clones a [", stringify!($typ), "] instance.")]
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn [<$prefix _clone>](instance: NonNull<$typ>) -> NonNull<$typ> {
|
|
||||||
unsafe { $crate::mem::heap_clone(instance) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! nonnull_as_ref {
|
|
||||||
($ident:ident) => {
|
|
||||||
$ident.as_ref()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! nonnull_as_mut {
|
|
||||||
($ident:ident) => {
|
|
||||||
&mut *$ident.as_ptr()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// meta required on purpose, because otherwise the added documentation would suppress warnings
|
|
||||||
macro_rules! wrap_method {
|
|
||||||
(
|
|
||||||
$prefix:ident :: $object_type:ty;
|
|
||||||
$(#[$meta:meta])+
|
|
||||||
$ref_or_mut:ident fn $function:ident($($param_name:ident: $param_type:ty),*)
|
|
||||||
$(-> $return_type:ty$(; |$it:ident | $return_expr:expr)?)?
|
|
||||||
$(; let $param_let_name:ident = $param_let_expr:expr)*
|
|
||||||
$(;)?
|
|
||||||
) => {
|
|
||||||
paste::paste! {
|
|
||||||
#[doc = concat!(" Calls [`servicepoint::", stringify!($object_type),
|
|
||||||
"::", stringify!($function), "`].")]
|
|
||||||
#[doc = ""]
|
|
||||||
$(#[$meta])*
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn [<$prefix _ $function>](
|
|
||||||
instance: NonNull<$object_type>,
|
|
||||||
$($param_name: $param_type),*
|
|
||||||
) $(-> $return_type)? {
|
|
||||||
let instance = unsafe {$crate::macros:: [< nonnull_as_ $ref_or_mut >] !(instance)};
|
|
||||||
$(let $param_let_name = $param_let_expr;)*
|
|
||||||
#[allow(
|
|
||||||
unused_variables,
|
|
||||||
reason = "This variable may not be used depending on macro variables" )]
|
|
||||||
let result = instance.$function($($param_name),*);
|
|
||||||
$(
|
|
||||||
$(
|
|
||||||
let $it = result;
|
|
||||||
let result = $return_expr;
|
|
||||||
)?
|
|
||||||
return result;
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use {
|
|
||||||
nonnull_as_mut, nonnull_as_ref, wrap_clone, wrap_free, wrap_method,
|
|
||||||
};
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free},
|
mem::{heap_clone, heap_drop, heap_move_nonnull, heap_move_ok},
|
||||||
mem::{heap_move_nonnull, heap_move_ok},
|
|
||||||
};
|
};
|
||||||
use servicepoint::{CommandCode, Header, Packet};
|
use servicepoint::{CommandCode, Header, Packet};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
@ -91,8 +90,21 @@ pub unsafe extern "C" fn sp_packet_serialize_to(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(Packet, sp_packet);
|
/// Clones a [Packet].
|
||||||
wrap_free!(Packet, sp_packet);
|
///
|
||||||
|
/// returns: a new [Packet] instance.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_packet_clone(
|
||||||
|
packet: NonNull<Packet>,
|
||||||
|
) -> NonNull<Packet> {
|
||||||
|
unsafe { heap_clone(packet) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deallocates a [Packet].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_packet_free(packet: NonNull<Packet>) {
|
||||||
|
unsafe { heap_drop(packet) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts u16 into [CommandCode].
|
/// Converts u16 into [CommandCode].
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::{CommandTag, SPCommand},
|
commands::{CommandTag, SPCommand},
|
||||||
macros::wrap_free,
|
mem::{heap_drop, heap_move_ok, heap_remove},
|
||||||
mem::{heap_move_ok, heap_remove},
|
|
||||||
};
|
};
|
||||||
use servicepoint::{Header, Packet, UdpSocketExt};
|
use servicepoint::{Header, Packet, UdpSocketExt};
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -144,4 +143,8 @@ pub unsafe extern "C" fn sp_udp_send_header(
|
||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_free!(UdpSocket, sp_udp);
|
/// Closes and deallocates a [UdpSocket].
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn sp_udp_free(connection: NonNull<UdpSocket>) {
|
||||||
|
unsafe { heap_drop(connection) }
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue