Compare commits
3 commits
9756ef39b7
...
75e2df41fe
Author | SHA1 | Date | |
---|---|---|---|
![]() |
75e2df41fe | ||
![]() |
8296773779 | ||
![]() |
514c0304b8 |
|
@ -12,7 +12,7 @@ void enable_all_pixels(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void make_brightness_pattern(BrightnessGrid *grid) {
|
void make_brightness_pattern(BrightnessGrid *grid) {
|
||||||
ByteSlice slice = sp_brightness_grid_unsafe_data_ref(grid);
|
ByteSlice slice = sp_brightness_grid_data_ref_mut(grid);
|
||||||
for (size_t index = 0; index < slice.length; index++) {
|
for (size_t index = 0; index < slice.length; index++) {
|
||||||
slice.start[index] = (uint8_t)(index % ((size_t) Brightness_MAX));
|
slice.start[index] = (uint8_t)(index % ((size_t) Brightness_MAX));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1166,9 +1166,9 @@ struct BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(struct Bitmap */*not
|
||||||
struct Bitmap */*notnull*/ sp_cmd_bitmap_get(struct BitmapCommand */*notnull*/ command);
|
struct Bitmap */*notnull*/ sp_cmd_bitmap_get(struct BitmapCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the compression kind of the [BitmapCommand].
|
*Gets the value of field `compression` of the [`servicepoint::BitmapCommand`].
|
||||||
*/
|
*/
|
||||||
CompressionCode sp_cmd_bitmap_get_compression(struct BitmapCommand */*notnull*/ command);
|
CompressionCode sp_cmd_bitmap_get_compression(struct BitmapCommand */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the origin field of the [BitmapCommand].
|
* Reads the origin field of the [BitmapCommand].
|
||||||
|
@ -1196,10 +1196,10 @@ void sp_cmd_bitmap_set(struct BitmapCommand */*notnull*/ command,
|
||||||
struct Bitmap */*notnull*/ bitmap);
|
struct Bitmap */*notnull*/ bitmap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites the compression kind of the [BitmapCommand].
|
*Sets the value of field `compression` of the [`servicepoint::BitmapCommand`].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_bitmap_set_compression(struct BitmapCommand */*notnull*/ command,
|
void sp_cmd_bitmap_set_compression(struct BitmapCommand */*notnull*/ instance,
|
||||||
CompressionCode compression);
|
CompressionCode value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites the origin field of the [BitmapCommand].
|
* Overwrites the origin field of the [BitmapCommand].
|
||||||
|
@ -1231,19 +1231,19 @@ void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ instance);
|
||||||
BitVec *sp_cmd_bitvec_get(struct BitVecCommand */*notnull*/ command);
|
BitVec *sp_cmd_bitvec_get(struct BitVecCommand */*notnull*/ command);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the compression kind of the [BitVecCommand].
|
*Gets the value of field `compression` of the [`servicepoint::BitVecCommand`].
|
||||||
*/
|
*/
|
||||||
CompressionCode sp_cmd_bitvec_get_compression(struct BitVecCommand */*notnull*/ command);
|
CompressionCode sp_cmd_bitvec_get_compression(struct BitVecCommand */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the offset field of the [BitVecCommand].
|
*Gets the value of field `offset` of the [`servicepoint::BitVecCommand`].
|
||||||
*/
|
*/
|
||||||
Offset sp_cmd_bitvec_get_offset(struct BitVecCommand */*notnull*/ command);
|
Offset sp_cmd_bitvec_get_offset(struct BitVecCommand */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the [BinaryOperation] of the command.
|
*Gets the value of field `operation` of the [`servicepoint::BitVecCommand`].
|
||||||
*/
|
*/
|
||||||
BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ command);
|
BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set pixel data starting at the pixel offset on screen.
|
* Set pixel data starting at the pixel offset on screen.
|
||||||
|
@ -1271,22 +1271,22 @@ void sp_cmd_bitvec_set(struct BitVecCommand */*notnull*/ command,
|
||||||
BitVec */*notnull*/ bitvec);
|
BitVec */*notnull*/ bitvec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites the compression kind of the [BitVecCommand].
|
*Sets the value of field `compression` of the [`servicepoint::BitVecCommand`].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_bitvec_set_compression(struct BitVecCommand */*notnull*/ command,
|
void sp_cmd_bitvec_set_compression(struct BitVecCommand */*notnull*/ instance,
|
||||||
CompressionCode compression);
|
CompressionCode value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites the offset field of the [BitVecCommand].
|
*Sets the value of field `offset` of the [`servicepoint::BitVecCommand`].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_bitvec_set_offset(struct BitVecCommand */*notnull*/ command,
|
void sp_cmd_bitvec_set_offset(struct BitVecCommand */*notnull*/ instance,
|
||||||
Offset offset);
|
Offset value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites the [BinaryOperation] of the command.
|
*Sets the value of field `operation` of the [`servicepoint::BitVecCommand`].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ command,
|
void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ instance,
|
||||||
BinaryOperation operation);
|
BinaryOperation value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to turn a [BitVecCommand] into a [Packet].
|
* Tries to turn a [BitVecCommand] into a [Packet].
|
||||||
|
@ -1305,7 +1305,10 @@ struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struc
|
||||||
*/
|
*/
|
||||||
void sp_cmd_brightness_global_free(struct GlobalBrightnessCommand */*notnull*/ instance);
|
void sp_cmd_brightness_global_free(struct GlobalBrightnessCommand */*notnull*/ instance);
|
||||||
|
|
||||||
Brightness sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
|
/**
|
||||||
|
*Gets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`].
|
||||||
|
*/
|
||||||
|
Brightness sp_cmd_brightness_global_get_brightness(struct GlobalBrightnessCommand */*notnull*/ instance);
|
||||||
|
|
||||||
struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
|
struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||||
|
|
||||||
|
@ -1317,10 +1320,10 @@ struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBri
|
||||||
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness);
|
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the provided bitmap to be contained in the command.
|
*Sets the value of field `brightness` of the [`servicepoint::GlobalBrightnessCommand`].
|
||||||
*/
|
*/
|
||||||
void sp_cmd_brightness_global_set(struct GlobalBrightnessCommand */*notnull*/ command,
|
void sp_cmd_brightness_global_set_brightness(struct GlobalBrightnessCommand */*notnull*/ instance,
|
||||||
Brightness brightness);
|
Brightness value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [BrightnessGridCommand] instance.
|
*Clones a [BrightnessGridCommand] instance.
|
||||||
|
@ -1588,6 +1591,11 @@ 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Clones a [Cp437Grid] instance.
|
||||||
|
*/
|
||||||
|
Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::data_ref_mut`].
|
* Calls [`servicepoint::Cp437Grid::data_ref_mut`].
|
||||||
*
|
*
|
||||||
|
@ -1595,7 +1603,7 @@ struct HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
|
||||||
*
|
*
|
||||||
* The returned memory is valid for the lifetime of the instance.
|
* The returned memory is valid for the lifetime of the instance.
|
||||||
*/
|
*/
|
||||||
struct ByteSlice sp_cp437_data_ref_mut(Cp437Grid */*notnull*/ instance);
|
struct ByteSlice sp_cp437_grid_data_ref_mut(Cp437Grid */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::fill`].
|
* Calls [`servicepoint::Cp437Grid::fill`].
|
||||||
|
@ -1607,7 +1615,12 @@ struct ByteSlice sp_cp437_data_ref_mut(Cp437Grid */*notnull*/ instance);
|
||||||
* - `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*/ instance, uint8_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Deallocates a [Cp437Grid] instance.
|
||||||
|
*/
|
||||||
|
void sp_cp437_grid_free(Cp437Grid */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::get`].
|
* Calls [`servicepoint::Cp437Grid::get`].
|
||||||
|
@ -1622,17 +1635,14 @@ void sp_cp437_fill(Cp437Grid */*notnull*/ instance, uint8_t value);
|
||||||
*
|
*
|
||||||
* - 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*/ instance, size_t x, size_t y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [Cp437Grid] instance.
|
* Calls [`servicepoint::Cp437Grid::height`].
|
||||||
|
*
|
||||||
|
* Gets the height of the grid.
|
||||||
*/
|
*/
|
||||||
Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ instance);
|
size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
|
||||||
*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].
|
||||||
|
@ -1659,13 +1669,6 @@ 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`].
|
|
||||||
*
|
|
||||||
* Gets the height of the grid.
|
|
||||||
*/
|
|
||||||
size_t sp_cp437_height(Cp437Grid */*notnull*/ instance);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls [`servicepoint::Cp437Grid::set`].
|
* Calls [`servicepoint::Cp437Grid::set`].
|
||||||
*
|
*
|
||||||
|
@ -1682,7 +1685,7 @@ 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*/ instance,
|
||||||
size_t x,
|
size_t x,
|
||||||
size_t y,
|
size_t y,
|
||||||
uint8_t value);
|
uint8_t value);
|
||||||
|
@ -1692,7 +1695,7 @@ void sp_cp437_set(Cp437Grid */*notnull*/ instance,
|
||||||
*
|
*
|
||||||
* Gets the width of the grid.
|
* Gets the width of the grid.
|
||||||
*/
|
*/
|
||||||
size_t sp_cp437_width(Cp437Grid */*notnull*/ instance);
|
size_t sp_cp437_grid_width(Cp437Grid */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Clones a [Packet] instance.
|
*Clones a [Packet] instance.
|
||||||
|
@ -1712,12 +1715,17 @@ void sp_packet_free(struct Packet */*notnull*/ instance);
|
||||||
struct Packet */*notnull*/ sp_packet_from_parts(struct Header header,
|
struct Packet */*notnull*/ sp_packet_from_parts(struct Header header,
|
||||||
struct ByteSlice payload);
|
struct ByteSlice payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Gets the value of field `header` of the [`servicepoint::Packet`].
|
||||||
|
*/
|
||||||
|
struct Header sp_packet_get_header(struct Packet */*notnull*/ instance);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the header field of the provided packet.
|
* Returns a pointer to the header field of the provided packet.
|
||||||
*
|
*
|
||||||
* The returned header can be changed and will be valid for the lifetime of the packet.
|
* The returned header can be changed and will be valid for the lifetime of the packet.
|
||||||
*/
|
*/
|
||||||
struct Header */*notnull*/ sp_packet_get_header(struct Packet */*notnull*/ packet);
|
struct Header */*notnull*/ sp_packet_get_header_mut(struct Packet */*notnull*/ packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the current payload of the provided packet.
|
* Returns a pointer to the current payload of the provided packet.
|
||||||
|
@ -1738,6 +1746,12 @@ struct ByteSlice sp_packet_get_payload(struct Packet */*notnull*/ packet);
|
||||||
void sp_packet_serialize_to(struct Packet */*notnull*/ packet,
|
void sp_packet_serialize_to(struct Packet */*notnull*/ packet,
|
||||||
struct ByteSlice buffer);
|
struct ByteSlice buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Sets the value of field `header` of the [`servicepoint::Packet`].
|
||||||
|
*/
|
||||||
|
void sp_packet_set_header(struct Packet */*notnull*/ instance,
|
||||||
|
struct Header value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the payload of the provided packet to the provided data.
|
* Sets the payload of the provided packet to the provided data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
macros::{wrap_clone, wrap_free},
|
macros::{wrap_clone, wrap_fields, wrap_free},
|
||||||
mem::{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};
|
||||||
|
@ -45,8 +45,24 @@ 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);
|
wrap_clone!(sp_cmd_bitmap::BitmapCommand);
|
||||||
wrap_free!(BitmapCommand, sp_cmd_bitmap);
|
wrap_free!(sp_cmd_bitmap::BitmapCommand);
|
||||||
|
|
||||||
|
wrap_fields!(
|
||||||
|
sp_cmd_bitmap::BitmapCommand;
|
||||||
|
//prop bitmap: NonNull<Bitmap> {
|
||||||
|
// get() {
|
||||||
|
// return NonNull::from(bitmap);
|
||||||
|
// };
|
||||||
|
// set(value) {
|
||||||
|
// return unsafe { heap_remove(value) };
|
||||||
|
// };
|
||||||
|
//};
|
||||||
|
prop compression: CompressionCode {
|
||||||
|
get();
|
||||||
|
set(value);
|
||||||
|
};
|
||||||
|
);
|
||||||
|
|
||||||
/// Returns a pointer to the provided `BitmapCommand`.
|
/// Returns a pointer to the provided `BitmapCommand`.
|
||||||
///
|
///
|
||||||
|
@ -97,22 +113,3 @@ pub unsafe extern "C" fn sp_cmd_bitmap_set_origin(
|
||||||
command.as_mut().origin = Origin::new(origin_x, origin_y);
|
command.as_mut().origin = Origin::new(origin_x, origin_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overwrites the compression kind of the [BitmapCommand].
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitmap_set_compression(
|
|
||||||
mut command: NonNull<BitmapCommand>,
|
|
||||||
compression: CompressionCode,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
command.as_mut().compression = compression;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reads the compression kind of the [BitmapCommand].
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitmap_get_compression(
|
|
||||||
command: NonNull<BitmapCommand>,
|
|
||||||
) -> CompressionCode {
|
|
||||||
unsafe { command.as_ref().compression }
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
macros::{wrap_clone, wrap_free},
|
macros::{wrap_clone, wrap_fields, wrap_free},
|
||||||
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
||||||
};
|
};
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
|
@ -45,8 +45,24 @@ 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);
|
wrap_clone!(sp_cmd_bitvec::BitVecCommand);
|
||||||
wrap_free!(BitVecCommand, sp_cmd_bitvec);
|
wrap_free!(sp_cmd_bitvec::BitVecCommand);
|
||||||
|
|
||||||
|
wrap_fields!(
|
||||||
|
sp_cmd_bitvec::BitVecCommand;
|
||||||
|
prop offset: Offset {
|
||||||
|
get();
|
||||||
|
set(value);
|
||||||
|
};
|
||||||
|
prop operation: BinaryOperation {
|
||||||
|
get();
|
||||||
|
set(value);
|
||||||
|
};
|
||||||
|
prop compression: CompressionCode {
|
||||||
|
get();
|
||||||
|
set(value);
|
||||||
|
};
|
||||||
|
);
|
||||||
|
|
||||||
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
/// Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -66,60 +82,3 @@ pub unsafe extern "C" fn sp_cmd_bitvec_set(
|
||||||
command.as_mut().bitvec = heap_remove(bitvec);
|
command.as_mut().bitvec = heap_remove(bitvec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads the offset field of the [BitVecCommand].
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_offset(
|
|
||||||
command: NonNull<BitVecCommand>,
|
|
||||||
) -> Offset {
|
|
||||||
unsafe { command.as_ref().offset }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Overwrites the offset field of the [BitVecCommand].
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitvec_set_offset(
|
|
||||||
mut command: NonNull<BitVecCommand>,
|
|
||||||
offset: Offset,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
command.as_mut().offset = offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the [BinaryOperation] of the command.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_operation(
|
|
||||||
command: NonNull<BitVecCommand>,
|
|
||||||
) -> BinaryOperation {
|
|
||||||
unsafe { command.as_ref().operation }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Overwrites the [BinaryOperation] of the command.
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitvec_set_operation(
|
|
||||||
mut command: NonNull<BitVecCommand>,
|
|
||||||
operation: BinaryOperation,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
command.as_mut().operation = operation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Overwrites the compression kind of the [BitVecCommand].
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitvec_set_compression(
|
|
||||||
mut command: NonNull<BitVecCommand>,
|
|
||||||
compression: CompressionCode,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
command.as_mut().compression = compression;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reads the compression kind of the [BitVecCommand].
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_compression(
|
|
||||||
command: NonNull<BitVecCommand>,
|
|
||||||
) -> CompressionCode {
|
|
||||||
unsafe { command.as_ref().compression }
|
|
||||||
}
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ 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);
|
wrap_clone!(sp_cmd_brightness_grid::BrightnessGridCommand);
|
||||||
wrap_free!(BrightnessGridCommand, sp_cmd_brightness_grid);
|
wrap_free!(sp_cmd_brightness_grid::BrightnessGridCommand);
|
||||||
|
|
||||||
/// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
|
/// Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -12,7 +12,7 @@ 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);
|
wrap_free!(sp_cmd_clear::ClearCommand);
|
||||||
|
|
||||||
/// 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 +24,7 @@ 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);
|
wrap_free!(sp_cmd_hard_reset::HardResetCommand);
|
||||||
|
|
||||||
/// A yet-to-be-tested command.
|
/// A yet-to-be-tested command.
|
||||||
///
|
///
|
||||||
|
@ -34,4 +34,4 @@ 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);
|
wrap_free!(sp_cmd_fade_out::FadeOutCommand);
|
||||||
|
|
|
@ -41,8 +41,8 @@ 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);
|
wrap_clone!(sp_cmd_char_grid::CharGridCommand);
|
||||||
wrap_free!(CharGridCommand, sp_cmd_char_grid);
|
wrap_free!(sp_cmd_char_grid::CharGridCommand);
|
||||||
|
|
||||||
/// Moves the provided [CharGrid] to be contained in the [CharGridCommand].
|
/// Moves the provided [CharGrid] to be contained in the [CharGridCommand].
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -41,8 +41,8 @@ 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);
|
wrap_clone!(sp_cmd_cp437_grid::Cp437GridCommand);
|
||||||
wrap_free!(Cp437GridCommand, sp_cmd_cp437_grid);
|
wrap_free!(sp_cmd_cp437_grid::Cp437GridCommand);
|
||||||
|
|
||||||
/// Moves the provided bitmap into the provided command.
|
/// Moves the provided bitmap into the provided command.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
macros::{wrap_clone, wrap_free},
|
macros::{wrap_clone, wrap_fields, wrap_free},
|
||||||
mem::{heap_move_nonnull, heap_remove},
|
mem::{heap_move_nonnull, heap_remove},
|
||||||
};
|
};
|
||||||
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
|
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
|
||||||
|
@ -22,23 +22,13 @@ 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);
|
wrap_clone!(sp_cmd_brightness_global::GlobalBrightnessCommand);
|
||||||
wrap_free!(GlobalBrightnessCommand, sp_cmd_brightness_global);
|
wrap_free!(sp_cmd_brightness_global::GlobalBrightnessCommand);
|
||||||
|
|
||||||
/// Moves the provided bitmap to be contained in the command.
|
wrap_fields!(
|
||||||
#[no_mangle]
|
sp_cmd_brightness_global::GlobalBrightnessCommand;
|
||||||
pub unsafe extern "C" fn sp_cmd_brightness_global_set(
|
prop brightness: Brightness {
|
||||||
mut command: NonNull<GlobalBrightnessCommand>,
|
get();
|
||||||
brightness: Brightness,
|
set(value);
|
||||||
) {
|
};
|
||||||
unsafe {
|
);
|
||||||
command.as_mut().brightness = brightness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn sp_cmd_brightness_global_get(
|
|
||||||
mut command: NonNull<GlobalBrightnessCommand>,
|
|
||||||
) -> Brightness {
|
|
||||||
unsafe { command.as_mut().brightness }
|
|
||||||
}
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ 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);
|
wrap_clone!(sp_bitmap::Bitmap);
|
||||||
wrap_free!(Bitmap, sp_bitmap);
|
wrap_free!(sp_bitmap::Bitmap);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_bitmap::Bitmap;
|
sp_bitmap::Bitmap;
|
||||||
|
|
|
@ -35,8 +35,8 @@ 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);
|
wrap_clone!(sp_bitvec::DisplayBitVec);
|
||||||
wrap_free!(DisplayBitVec, sp_bitvec);
|
wrap_free!(sp_bitvec::DisplayBitVec);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_bitvec::DisplayBitVec;
|
sp_bitvec::DisplayBitVec;
|
||||||
|
|
|
@ -52,8 +52,8 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(BrightnessGrid, sp_brightness_grid);
|
wrap_clone!(sp_brightness_grid::BrightnessGrid);
|
||||||
wrap_free!(BrightnessGrid, sp_brightness_grid);
|
wrap_free!(sp_brightness_grid::BrightnessGrid);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_brightness_grid::BrightnessGrid;
|
sp_brightness_grid::BrightnessGrid;
|
||||||
|
|
|
@ -39,8 +39,8 @@ 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);
|
wrap_clone!(sp_char_grid::CharGrid);
|
||||||
wrap_free!(CharGrid, sp_char_grid);
|
wrap_free!(sp_char_grid::CharGrid);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_char_grid::CharGrid;
|
sp_char_grid::CharGrid;
|
||||||
|
|
|
@ -30,11 +30,11 @@ 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);
|
wrap_clone!(sp_cp437_grid::Cp437Grid);
|
||||||
wrap_free!(Cp437Grid, sp_cp437_grid);
|
wrap_free!(sp_cp437_grid::Cp437Grid);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_cp437 :: Cp437Grid;
|
sp_cp437_grid::Cp437Grid;
|
||||||
/// Gets the current value at the specified position.
|
/// Gets the current value at the specified position.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -48,7 +48,7 @@ wrap_method!(
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_cp437 :: Cp437Grid;
|
sp_cp437_grid::Cp437Grid;
|
||||||
/// Sets the value at the specified position.
|
/// Sets the value at the specified position.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -65,7 +65,7 @@ wrap_method!(
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_cp437 :: Cp437Grid;
|
sp_cp437_grid::Cp437Grid;
|
||||||
/// Sets the value of all cells in the grid.
|
/// Sets the value of all cells in the grid.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -76,19 +76,19 @@ wrap_method!(
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_cp437 :: Cp437Grid;
|
sp_cp437_grid::Cp437Grid;
|
||||||
/// Gets the width of the grid.
|
/// Gets the width of the grid.
|
||||||
ref fn width() -> usize;
|
ref fn width() -> usize;
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_cp437 :: Cp437Grid;
|
sp_cp437_grid::Cp437Grid;
|
||||||
/// Gets the height of the grid.
|
/// Gets the height of the grid.
|
||||||
ref fn height() -> usize;
|
ref fn height() -> usize;
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_method!(
|
wrap_method!(
|
||||||
sp_cp437 :: Cp437Grid;
|
sp_cp437_grid::Cp437Grid;
|
||||||
/// Gets an unsafe reference to the data of the grid.
|
/// Gets an unsafe reference to the data of the grid.
|
||||||
///
|
///
|
||||||
/// The returned memory is valid for the lifetime of the instance.
|
/// The returned memory is valid for the lifetime of the instance.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
macro_rules! wrap_free {
|
macro_rules! wrap_free {
|
||||||
($typ:ty, $prefix:ident) => {
|
($prefix:ident :: $typ:ty) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
#[doc = concat!("Deallocates a [", stringify!($typ), "] instance.")]
|
#[doc = concat!("Deallocates a [", stringify!($typ), "] instance.")]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -11,7 +11,7 @@ macro_rules! wrap_free {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wrap_clone {
|
macro_rules! wrap_clone {
|
||||||
($typ:ty, $prefix:ident) => {
|
($prefix:ident :: $typ:ty) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
#[doc = concat!("Clones a [", stringify!($typ), "] instance.")]
|
#[doc = concat!("Clones a [", stringify!($typ), "] instance.")]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -72,6 +72,75 @@ macro_rules! wrap_method {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use {
|
macro_rules! wrap_fields {
|
||||||
nonnull_as_mut, nonnull_as_ref, wrap_clone, wrap_free, wrap_method,
|
(
|
||||||
|
$prefix:ident :: $object_type:ty;
|
||||||
|
$(
|
||||||
|
prop $prop_name:ident : $prop_type:ty {
|
||||||
|
$(
|
||||||
|
get() $({
|
||||||
|
$(#[$get_meta:meta])*
|
||||||
|
$(return $get_expr:expr;)?
|
||||||
|
})?;
|
||||||
|
)?
|
||||||
|
$(
|
||||||
|
set($value:ident)
|
||||||
|
$({
|
||||||
|
$(#[$set_meta:meta])*
|
||||||
|
$(return $set_expr:expr;)?
|
||||||
|
})?;
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
)+
|
||||||
|
) => {
|
||||||
|
paste::paste! {
|
||||||
|
$(
|
||||||
|
$(
|
||||||
|
#[doc = concat!("Gets the value of field `", stringify!($prop_name),
|
||||||
|
"` of the [`servicepoint::",stringify!($object_type),"`].")]
|
||||||
|
$($(
|
||||||
|
#[doc = ""]
|
||||||
|
#[$get_meta]
|
||||||
|
)*)?
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn [<$prefix _ get _ $prop_name>](
|
||||||
|
instance: NonNull<$object_type>
|
||||||
|
) -> $prop_type {
|
||||||
|
let instance = unsafe { $crate::macros::nonnull_as_ref!(instance) };
|
||||||
|
let $prop_name = instance.$prop_name;
|
||||||
|
$($(
|
||||||
|
let $prop_name = $get_expr;
|
||||||
|
)?)?
|
||||||
|
return $prop_name;
|
||||||
|
}
|
||||||
|
)?
|
||||||
|
|
||||||
|
$(
|
||||||
|
#[doc = concat!("Sets the value of field `", stringify!($prop_name),
|
||||||
|
"` of the [`servicepoint::",stringify!($object_type),"`].")]
|
||||||
|
$($(
|
||||||
|
#[doc = ""]
|
||||||
|
#[$set_meta]
|
||||||
|
)*)?
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn [<$prefix _ set _ $prop_name>](
|
||||||
|
instance: NonNull<$object_type>,
|
||||||
|
value: $prop_type,
|
||||||
|
) {
|
||||||
|
let instance = unsafe { $crate::macros::nonnull_as_mut!(instance) };
|
||||||
|
$($(
|
||||||
|
let $value = value;
|
||||||
|
let value = $set_expr;
|
||||||
|
)?)?
|
||||||
|
instance.$prop_name = value;
|
||||||
|
}
|
||||||
|
)?
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) use {
|
||||||
|
nonnull_as_mut, nonnull_as_ref, wrap_clone, wrap_fields, wrap_free,
|
||||||
|
wrap_method,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
containers::ByteSlice,
|
containers::ByteSlice,
|
||||||
macros::{wrap_clone, wrap_free},
|
macros::{wrap_clone, wrap_fields, wrap_free},
|
||||||
mem::{heap_move_nonnull, heap_move_ok},
|
mem::{heap_move_nonnull, heap_move_ok},
|
||||||
};
|
};
|
||||||
use servicepoint::{CommandCode, Header, Packet};
|
use servicepoint::{CommandCode, Header, Packet};
|
||||||
|
@ -36,7 +36,7 @@ pub unsafe extern "C" fn sp_packet_from_parts(
|
||||||
///
|
///
|
||||||
/// The returned header can be changed and will be valid for the lifetime of the packet.
|
/// The returned header can be changed and will be valid for the lifetime of the packet.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_packet_get_header(
|
pub unsafe extern "C" fn sp_packet_get_header_mut(
|
||||||
packet: NonNull<Packet>,
|
packet: NonNull<Packet>,
|
||||||
) -> NonNull<Header> {
|
) -> NonNull<Header> {
|
||||||
NonNull::from(unsafe { &mut (*packet.as_ptr()).header })
|
NonNull::from(unsafe { &mut (*packet.as_ptr()).header })
|
||||||
|
@ -91,8 +91,16 @@ pub unsafe extern "C" fn sp_packet_serialize_to(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_clone!(Packet, sp_packet);
|
wrap_clone!(sp_packet::Packet);
|
||||||
wrap_free!(Packet, sp_packet);
|
wrap_free!(sp_packet::Packet);
|
||||||
|
|
||||||
|
wrap_fields!(
|
||||||
|
sp_packet::Packet;
|
||||||
|
prop header: Header {
|
||||||
|
get();
|
||||||
|
set(value);
|
||||||
|
};
|
||||||
|
);
|
||||||
|
|
||||||
/// Converts u16 into [CommandCode].
|
/// Converts u16 into [CommandCode].
|
||||||
///
|
///
|
||||||
|
|
|
@ -144,4 +144,4 @@ pub unsafe extern "C" fn sp_udp_send_header(
|
||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap_free!(UdpSocket, sp_udp);
|
wrap_free!(sp_udp::UdpSocket);
|
||||||
|
|
Loading…
Reference in a new issue