re-export constants from base lib
This commit is contained in:
parent
35cb42df48
commit
24ff341f9d
|
@ -25,6 +25,7 @@ sort_by = "Name"
|
||||||
[parse]
|
[parse]
|
||||||
parse_deps = true
|
parse_deps = true
|
||||||
include = ["servicepoint"]
|
include = ["servicepoint"]
|
||||||
|
extra_bindings = ["servicepoint"]
|
||||||
|
|
||||||
[parse.expand]
|
[parse.expand]
|
||||||
features = ["full"]
|
features = ["full"]
|
||||||
|
|
|
@ -6,13 +6,13 @@ int main(void) {
|
||||||
if (connection == NULL)
|
if (connection == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
Bitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT);
|
Bitmap *pixels = sp_bitmap_new(PIXEL_WIDTH, PIXEL_HEIGHT);
|
||||||
if (pixels == NULL)
|
if (pixels == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
sp_bitmap_fill(pixels, true);
|
sp_bitmap_fill(pixels, true);
|
||||||
|
|
||||||
Command *command = sp_command_bitmap_linear_win(0, 0, pixels, SP_COMPRESSION_CODE_UNCOMPRESSED);
|
Command *command = sp_command_bitmap_linear_win(0, 0, pixels, COMPRESSION_CODE_UNCOMPRESSED);
|
||||||
if (command == NULL)
|
if (command == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,35 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pixel count on whole screen
|
||||||
|
*/
|
||||||
|
#define PIXEL_COUNT (PIXEL_WIDTH * PIXEL_HEIGHT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display height in pixels
|
||||||
|
*
|
||||||
|
* # Examples
|
||||||
|
*
|
||||||
|
* ```rust
|
||||||
|
* # use servicepoint::{PIXEL_HEIGHT, PIXEL_WIDTH, Bitmap};
|
||||||
|
* let grid = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
#define PIXEL_HEIGHT (TILE_HEIGHT * TILE_SIZE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display width in pixels
|
||||||
|
*
|
||||||
|
* # Examples
|
||||||
|
*
|
||||||
|
* ```rust
|
||||||
|
* # use servicepoint::{PIXEL_HEIGHT, PIXEL_WIDTH, Bitmap};
|
||||||
|
* let grid = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
#define PIXEL_WIDTH (TILE_WIDTH * TILE_SIZE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count of possible brightness values
|
* Count of possible brightness values
|
||||||
*/
|
*/
|
||||||
|
@ -23,40 +52,60 @@
|
||||||
*/
|
*/
|
||||||
#define SP_BRIGHTNESS_MIN 0
|
#define SP_BRIGHTNESS_MIN 0
|
||||||
|
|
||||||
/**
|
|
||||||
* pixel count on whole screen
|
|
||||||
*/
|
|
||||||
#define SP_PIXEL_COUNT (SP_PIXEL_WIDTH * SP_PIXEL_HEIGHT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display height in pixels
|
|
||||||
*/
|
|
||||||
#define SP_PIXEL_HEIGHT (SP_TILE_HEIGHT * SP_TILE_SIZE)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display width in pixels
|
|
||||||
*/
|
|
||||||
#define SP_PIXEL_WIDTH (SP_TILE_WIDTH * SP_TILE_SIZE)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display tile count in the y-direction
|
* Display tile count in the y-direction
|
||||||
|
*
|
||||||
|
* # Examples
|
||||||
|
*
|
||||||
|
* ```rust
|
||||||
|
* # use servicepoint::{Cp437Grid, TILE_HEIGHT, TILE_WIDTH};
|
||||||
|
* let grid = Cp437Grid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
#define SP_TILE_HEIGHT 20
|
#define TILE_HEIGHT 20
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* size of a single tile in one dimension
|
* size of a single tile in one dimension
|
||||||
*/
|
*/
|
||||||
#define SP_TILE_SIZE 8
|
#define TILE_SIZE 8
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display tile count in the x-direction
|
* Display tile count in the x-direction
|
||||||
|
*
|
||||||
|
* # Examples
|
||||||
|
*
|
||||||
|
* ```rust
|
||||||
|
* # use servicepoint::{Cp437Grid, TILE_HEIGHT, TILE_WIDTH};
|
||||||
|
* let grid = Cp437Grid::new(TILE_WIDTH, TILE_HEIGHT);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
#define SP_TILE_WIDTH 56
|
#define TILE_WIDTH 56
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the kind of compression to use.
|
* Specifies the kind of compression to use. Availability depends on features.
|
||||||
|
*
|
||||||
|
* # Examples
|
||||||
|
*
|
||||||
|
* ```rust
|
||||||
|
* # use servicepoint::*;
|
||||||
|
* // create command without payload compression
|
||||||
|
* # let pixels = Bitmap::max_sized();
|
||||||
|
* _ = BitmapCommand {
|
||||||
|
* origin: Origin::ZERO,
|
||||||
|
* bitmap: pixels,
|
||||||
|
* compression: CompressionCode::Uncompressed
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* // create command with payload compressed with lzma and appropriate header flags
|
||||||
|
* # let pixels = Bitmap::max_sized();
|
||||||
|
* _ = BitmapCommand {
|
||||||
|
* origin: Origin::ZERO,
|
||||||
|
* bitmap: pixels,
|
||||||
|
* compression: CompressionCode::Lzma
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
enum SPCompressionCode
|
enum CompressionCode
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
: uint16_t
|
: uint16_t
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
@ -64,26 +113,26 @@ enum SPCompressionCode
|
||||||
/**
|
/**
|
||||||
* no compression
|
* no compression
|
||||||
*/
|
*/
|
||||||
SP_COMPRESSION_CODE_UNCOMPRESSED = 0,
|
COMPRESSION_CODE_UNCOMPRESSED = 0,
|
||||||
/**
|
/**
|
||||||
* compress using flate2 with zlib header
|
* compress using flate2 with zlib header
|
||||||
*/
|
*/
|
||||||
SP_COMPRESSION_CODE_ZLIB = 26490,
|
COMPRESSION_CODE_ZLIB = 26490,
|
||||||
/**
|
/**
|
||||||
* compress using bzip2
|
* compress using bzip2
|
||||||
*/
|
*/
|
||||||
SP_COMPRESSION_CODE_BZIP2 = 25210,
|
COMPRESSION_CODE_BZIP2 = 25210,
|
||||||
/**
|
/**
|
||||||
* compress using lzma
|
* compress using lzma
|
||||||
*/
|
*/
|
||||||
SP_COMPRESSION_CODE_LZMA = 27770,
|
COMPRESSION_CODE_LZMA = 27770,
|
||||||
/**
|
/**
|
||||||
* compress using Zstandard
|
* compress using Zstandard
|
||||||
*/
|
*/
|
||||||
SP_COMPRESSION_CODE_ZSTD = 31347,
|
COMPRESSION_CODE_ZSTD = 31347,
|
||||||
};
|
};
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
typedef uint16_t SPCompressionCode;
|
typedef uint16_t CompressionCode;
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1173,7 +1222,7 @@ size_t sp_char_grid_width(const CharGrid *char_grid);
|
||||||
*/
|
*/
|
||||||
Command *sp_command_bitmap_linear(size_t offset,
|
Command *sp_command_bitmap_linear(size_t offset,
|
||||||
SPBitVec *bit_vec,
|
SPBitVec *bit_vec,
|
||||||
SPCompressionCode compression);
|
CompressionCode compression);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set pixel data according to an and-mask starting at the offset.
|
* Set pixel data according to an and-mask starting at the offset.
|
||||||
|
@ -1204,7 +1253,7 @@ Command *sp_command_bitmap_linear(size_t offset,
|
||||||
*/
|
*/
|
||||||
Command *sp_command_bitmap_linear_and(size_t offset,
|
Command *sp_command_bitmap_linear_and(size_t offset,
|
||||||
SPBitVec *bit_vec,
|
SPBitVec *bit_vec,
|
||||||
SPCompressionCode compression);
|
CompressionCode compression);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set pixel data according to an or-mask starting at the offset.
|
* Set pixel data according to an or-mask starting at the offset.
|
||||||
|
@ -1235,7 +1284,7 @@ Command *sp_command_bitmap_linear_and(size_t offset,
|
||||||
*/
|
*/
|
||||||
Command *sp_command_bitmap_linear_or(size_t offset,
|
Command *sp_command_bitmap_linear_or(size_t offset,
|
||||||
SPBitVec *bit_vec,
|
SPBitVec *bit_vec,
|
||||||
SPCompressionCode compression);
|
CompressionCode compression);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a window of pixels to the specified values.
|
* Sets a window of pixels to the specified values.
|
||||||
|
@ -1262,7 +1311,7 @@ Command *sp_command_bitmap_linear_or(size_t offset,
|
||||||
Command *sp_command_bitmap_linear_win(size_t x,
|
Command *sp_command_bitmap_linear_win(size_t x,
|
||||||
size_t y,
|
size_t y,
|
||||||
Bitmap *bitmap,
|
Bitmap *bitmap,
|
||||||
SPCompressionCode compression);
|
CompressionCode compression);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set pixel data according to a xor-mask starting at the offset.
|
* Set pixel data according to a xor-mask starting at the offset.
|
||||||
|
@ -1293,7 +1342,7 @@ Command *sp_command_bitmap_linear_win(size_t x,
|
||||||
*/
|
*/
|
||||||
Command *sp_command_bitmap_linear_xor(size_t offset,
|
Command *sp_command_bitmap_linear_xor(size_t offset,
|
||||||
SPBitVec *bit_vec,
|
SPBitVec *bit_vec,
|
||||||
SPCompressionCode compression);
|
CompressionCode compression);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the brightness of all tiles to the same value.
|
* Set the brightness of all tiles to the same value.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
/// Represents a span of memory (`&mut [u8]` ) as a struct usable by C code.
|
/// Represents a span of memory (`&mut [u8]` ) as a struct usable by C code.
|
||||||
///
|
///
|
||||||
/// You should not create an instance of this type in your C code.
|
/// You should not create an instance of this type in your C code.
|
||||||
|
@ -16,6 +15,7 @@ use std::ptr::NonNull;
|
||||||
/// the function returning this type.
|
/// the function returning this type.
|
||||||
/// - an instance of this created from C is never passed to a consuming function, as the rust code
|
/// - an instance of this created from C is never passed to a consuming function, as the rust code
|
||||||
/// will try to free the memory of a potentially separate allocator.
|
/// will try to free the memory of a potentially separate allocator.
|
||||||
|
#[repr(C)]
|
||||||
pub struct SPByteSlice {
|
pub struct SPByteSlice {
|
||||||
/// The start address of the memory
|
/// The start address of the memory
|
||||||
pub start: NonNull<u8>,
|
pub start: NonNull<u8>,
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//!
|
//!
|
||||||
//! prefix `sp_command_`
|
//! prefix `sp_command_`
|
||||||
|
|
||||||
use crate::{SPBitVec, SPCompressionCode};
|
use crate::{SPBitVec};
|
||||||
use servicepoint::{BinaryOperation, BrightnessGrid, CharGrid, Cp437Grid, GlobalBrightnessCommand, Packet, TypedCommand};
|
use servicepoint::{BinaryOperation, BrightnessGrid, CharGrid, CompressionCode, Cp437Grid, GlobalBrightnessCommand, Packet, TypedCommand};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// A low-level display command.
|
/// A low-level display command.
|
||||||
|
@ -225,7 +225,7 @@ pub unsafe extern "C" fn sp_command_char_brightness(
|
||||||
pub unsafe extern "C" fn sp_command_bitmap_linear(
|
pub unsafe extern "C" fn sp_command_bitmap_linear(
|
||||||
offset: usize,
|
offset: usize,
|
||||||
bit_vec: *mut SPBitVec,
|
bit_vec: *mut SPBitVec,
|
||||||
compression: SPCompressionCode,
|
compression: CompressionCode,
|
||||||
) -> *mut TypedCommand {
|
) -> *mut TypedCommand {
|
||||||
unsafe {
|
unsafe {
|
||||||
sp_command_bitmap_linear_internal(
|
sp_command_bitmap_linear_internal(
|
||||||
|
@ -266,7 +266,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
|
||||||
pub unsafe extern "C" fn sp_command_bitmap_linear_and(
|
pub unsafe extern "C" fn sp_command_bitmap_linear_and(
|
||||||
offset: usize,
|
offset: usize,
|
||||||
bit_vec: *mut SPBitVec,
|
bit_vec: *mut SPBitVec,
|
||||||
compression: SPCompressionCode,
|
compression: CompressionCode,
|
||||||
) -> *mut TypedCommand {
|
) -> *mut TypedCommand {
|
||||||
unsafe {
|
unsafe {
|
||||||
sp_command_bitmap_linear_internal(
|
sp_command_bitmap_linear_internal(
|
||||||
|
@ -307,7 +307,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
|
||||||
pub unsafe extern "C" fn sp_command_bitmap_linear_or(
|
pub unsafe extern "C" fn sp_command_bitmap_linear_or(
|
||||||
offset: usize,
|
offset: usize,
|
||||||
bit_vec: *mut SPBitVec,
|
bit_vec: *mut SPBitVec,
|
||||||
compression: SPCompressionCode,
|
compression: CompressionCode,
|
||||||
) -> *mut TypedCommand {
|
) -> *mut TypedCommand {
|
||||||
unsafe {
|
unsafe {
|
||||||
sp_command_bitmap_linear_internal(
|
sp_command_bitmap_linear_internal(
|
||||||
|
@ -348,7 +348,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
|
||||||
pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
|
pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
|
||||||
offset: usize,
|
offset: usize,
|
||||||
bit_vec: *mut SPBitVec,
|
bit_vec: *mut SPBitVec,
|
||||||
compression: SPCompressionCode,
|
compression: CompressionCode,
|
||||||
) -> *mut TypedCommand {
|
) -> *mut TypedCommand {
|
||||||
unsafe {
|
unsafe {
|
||||||
sp_command_bitmap_linear_internal(
|
sp_command_bitmap_linear_internal(
|
||||||
|
@ -364,7 +364,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
|
||||||
unsafe fn sp_command_bitmap_linear_internal(
|
unsafe fn sp_command_bitmap_linear_internal(
|
||||||
offset: usize,
|
offset: usize,
|
||||||
bit_vec: *mut SPBitVec,
|
bit_vec: *mut SPBitVec,
|
||||||
compression: SPCompressionCode,
|
compression: CompressionCode,
|
||||||
operation: BinaryOperation,
|
operation: BinaryOperation,
|
||||||
) -> *mut TypedCommand {
|
) -> *mut TypedCommand {
|
||||||
assert!(!bit_vec.is_null());
|
assert!(!bit_vec.is_null());
|
||||||
|
@ -480,7 +480,7 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
|
||||||
x: usize,
|
x: usize,
|
||||||
y: usize,
|
y: usize,
|
||||||
bitmap: *mut servicepoint::Bitmap,
|
bitmap: *mut servicepoint::Bitmap,
|
||||||
compression: SPCompressionCode,
|
compression: CompressionCode,
|
||||||
) -> *mut TypedCommand {
|
) -> *mut TypedCommand {
|
||||||
assert!(!bitmap.is_null());
|
assert!(!bitmap.is_null());
|
||||||
let bitmap = unsafe { *Box::from_raw(bitmap) };
|
let bitmap = unsafe { *Box::from_raw(bitmap) };
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
//! re-exported constants for use in C
|
|
||||||
|
|
||||||
use servicepoint::CompressionCode;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
/// size of a single tile in one dimension
|
|
||||||
pub const SP_TILE_SIZE: usize = 8;
|
|
||||||
|
|
||||||
/// Display tile count in the x-direction
|
|
||||||
pub const SP_TILE_WIDTH: usize = 56;
|
|
||||||
|
|
||||||
/// Display tile count in the y-direction
|
|
||||||
pub const SP_TILE_HEIGHT: usize = 20;
|
|
||||||
|
|
||||||
/// Display width in pixels
|
|
||||||
pub const SP_PIXEL_WIDTH: usize = SP_TILE_WIDTH * SP_TILE_SIZE;
|
|
||||||
|
|
||||||
/// Display height in pixels
|
|
||||||
pub const SP_PIXEL_HEIGHT: usize = SP_TILE_HEIGHT * SP_TILE_SIZE;
|
|
||||||
|
|
||||||
/// pixel count on whole screen
|
|
||||||
pub const SP_PIXEL_COUNT: usize = SP_PIXEL_WIDTH * SP_PIXEL_HEIGHT;
|
|
||||||
|
|
||||||
/// Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
|
|
||||||
pub const SP_FRAME_PACING_MS: u128 = Duration::from_millis(30).as_millis();
|
|
||||||
|
|
||||||
/// Specifies the kind of compression to use.
|
|
||||||
#[repr(u16)]
|
|
||||||
pub enum SPCompressionCode {
|
|
||||||
/// no compression
|
|
||||||
Uncompressed = 0x0,
|
|
||||||
/// compress using flate2 with zlib header
|
|
||||||
Zlib = 0x677a,
|
|
||||||
/// compress using bzip2
|
|
||||||
Bzip2 = 0x627a,
|
|
||||||
/// compress using lzma
|
|
||||||
Lzma = 0x6c7a,
|
|
||||||
/// compress using Zstandard
|
|
||||||
Zstd = 0x7a73,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<SPCompressionCode> for CompressionCode {
|
|
||||||
type Error = ();
|
|
||||||
|
|
||||||
fn try_from(value: SPCompressionCode) -> Result<Self, Self::Error> {
|
|
||||||
CompressionCode::try_from(value as u16).map_err(|_| ())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -32,7 +32,6 @@ pub use crate::byte_slice::*;
|
||||||
pub use crate::char_grid::*;
|
pub use crate::char_grid::*;
|
||||||
pub use crate::command::*;
|
pub use crate::command::*;
|
||||||
pub use crate::connection::*;
|
pub use crate::connection::*;
|
||||||
pub use crate::constants::*;
|
|
||||||
pub use crate::cp437_grid::*;
|
pub use crate::cp437_grid::*;
|
||||||
pub use crate::packet::*;
|
pub use crate::packet::*;
|
||||||
|
|
||||||
|
@ -43,6 +42,11 @@ mod byte_slice;
|
||||||
mod char_grid;
|
mod char_grid;
|
||||||
mod command;
|
mod command;
|
||||||
mod connection;
|
mod connection;
|
||||||
mod constants;
|
|
||||||
mod cp437_grid;
|
mod cp437_grid;
|
||||||
mod packet;
|
mod packet;
|
||||||
|
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
/// Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
|
||||||
|
pub const SP_FRAME_PACING_MS: u128 = Duration::from_millis(30).as_millis();
|
||||||
|
|
Loading…
Reference in a new issue