add first specific commands
This commit is contained in:
		
							parent
							
								
									84adf166a9
								
							
						
					
					
						commit
						373725c648
					
				
					 7 changed files with 360 additions and 66 deletions
				
			
		
							
								
								
									
										110
									
								
								src/commands/bitmap_command.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								src/commands/bitmap_command.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,110 @@
 | 
			
		|||
use crate::{heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    Bitmap, BitmapCommand, CompressionCode, Origin, Packet, TypedCommand,
 | 
			
		||||
};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
 | 
			
		||||
/// Sets a window of pixels to the specified values.
 | 
			
		||||
///
 | 
			
		||||
/// The passed [Bitmap] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [BitmapCommand] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_new(
 | 
			
		||||
    bitmap: NonNull<Bitmap>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) -> NonNull<BitmapCommand> {
 | 
			
		||||
    heap_move_nonnull(BitmapCommand {
 | 
			
		||||
        bitmap: unsafe { heap_remove(bitmap) },
 | 
			
		||||
        origin: Origin::new(origin_x, origin_y),
 | 
			
		||||
        compression,
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_from_bitmap(
 | 
			
		||||
    bitmap: NonNull<Bitmap>,
 | 
			
		||||
) -> NonNull<BitmapCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(bitmap) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_into_typed(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) -> NonNull<TypedCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(command) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_into_packet(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) -> *mut Packet {
 | 
			
		||||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Returns a pointer to the provided `BitmapCommand`.
 | 
			
		||||
///
 | 
			
		||||
/// # Safety
 | 
			
		||||
///
 | 
			
		||||
/// - The returned bitmap inherits the lifetime of the command in which it is contained.
 | 
			
		||||
/// - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_get(
 | 
			
		||||
    mut command: NonNull<BitmapCommand>,
 | 
			
		||||
) -> NonNull<Bitmap> {
 | 
			
		||||
    unsafe { NonNull::from(&mut (command.as_mut().bitmap)) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Moves the provided bitmap to be contained in the command.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_set(
 | 
			
		||||
    mut command: NonNull<BitmapCommand>,
 | 
			
		||||
    bitmap: NonNull<Bitmap>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().bitmap = heap_remove(bitmap);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_get_origin(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
    origin_x: NonNull<usize>,
 | 
			
		||||
    origin_y: NonNull<usize>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        let origin = &command.as_ref().origin;
 | 
			
		||||
        *origin_x.as_ptr() = origin.x;
 | 
			
		||||
        *origin_y.as_ptr() = origin.y;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_set_origin(
 | 
			
		||||
    mut command: NonNull<BitmapCommand>,
 | 
			
		||||
    origin_x: usize,
 | 
			
		||||
    origin_y: usize,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().origin = Origin::new(origin_x, origin_y);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_set_compression(
 | 
			
		||||
    mut command: NonNull<BitmapCommand>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().compression = compression;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitmap_get_compression(
 | 
			
		||||
    command: NonNull<BitmapCommand>,
 | 
			
		||||
) -> CompressionCode {
 | 
			
		||||
    unsafe { command.as_ref().compression }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										115
									
								
								src/commands/bitvec_command.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								src/commands/bitvec_command.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,115 @@
 | 
			
		|||
use crate::{heap_move_nonnull, heap_move_ok, heap_remove};
 | 
			
		||||
use servicepoint::{
 | 
			
		||||
    BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
 | 
			
		||||
    Packet, TypedCommand,
 | 
			
		||||
};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
 | 
			
		||||
/// Set pixel data starting at the pixel offset on screen.
 | 
			
		||||
///
 | 
			
		||||
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
 | 
			
		||||
/// once the starting row is full, overwriting will continue on column 0.
 | 
			
		||||
///
 | 
			
		||||
/// The [`BinaryOperation`] will be applied on the display comparing old and sent bit.
 | 
			
		||||
///
 | 
			
		||||
/// `new_bit = old_bit op sent_bit`
 | 
			
		||||
///
 | 
			
		||||
/// For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels.
 | 
			
		||||
///
 | 
			
		||||
/// The contained [`DisplayBitVec`] is always uncompressed.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_new(
 | 
			
		||||
    bitvec: NonNull<DisplayBitVec>,
 | 
			
		||||
    offset: usize,
 | 
			
		||||
    operation: BinaryOperation,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) -> NonNull<BitVecCommand> {
 | 
			
		||||
    heap_move_nonnull(BitVecCommand {
 | 
			
		||||
        bitvec: unsafe { heap_remove(bitvec) },
 | 
			
		||||
        offset,
 | 
			
		||||
        operation,
 | 
			
		||||
        compression,
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_into_typed(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> NonNull<TypedCommand> {
 | 
			
		||||
    heap_move_nonnull(unsafe { heap_remove(command) }.into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_into_packet(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> *mut Packet {
 | 
			
		||||
    heap_move_ok(unsafe { heap_remove(command) }.try_into())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_get(
 | 
			
		||||
    mut command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> *mut DisplayBitVec {
 | 
			
		||||
    &mut unsafe { command.as_mut() }.bitvec
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Moves the provided bitmap to be contained in the command.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_set(
 | 
			
		||||
    mut command: NonNull<BitVecCommand>,
 | 
			
		||||
    bitvec: NonNull<DisplayBitVec>,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().bitvec = heap_remove(bitvec);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_offset(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> Offset {
 | 
			
		||||
    unsafe { command.as_ref().offset }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_set_offset(
 | 
			
		||||
    mut command: NonNull<BitVecCommand>,
 | 
			
		||||
    offset: Offset,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().offset = offset;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_operation(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> BinaryOperation {
 | 
			
		||||
    unsafe { command.as_ref().operation.clone() } // TODO remove clone
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_set_operation(
 | 
			
		||||
    mut command: NonNull<BitVecCommand>,
 | 
			
		||||
    operation: BinaryOperation,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().operation = operation;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_set_compression(
 | 
			
		||||
    mut command: NonNull<BitVecCommand>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        command.as_mut().compression = compression;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_cmd_bitvec_get_compression(
 | 
			
		||||
    command: NonNull<BitVecCommand>,
 | 
			
		||||
) -> CompressionCode {
 | 
			
		||||
    unsafe { command.as_ref().compression }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2
									
								
								src/commands/mod.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/commands/mod.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
mod bitmap_command;
 | 
			
		||||
mod bitvec_command;
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue