move c binding into separate dir
This commit is contained in:
parent
27a87cc80a
commit
3bf5249d08
5 changed files with 14 additions and 18 deletions
|
|
@ -2,24 +2,21 @@ ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
OUT_DIR := ${ROOT_DIR}/out
|
OUT_DIR := ${ROOT_DIR}/out
|
||||||
|
|
||||||
SP2_DIR := ${ROOT_DIR}/../../servicepoint2
|
SP2_DIR := ${ROOT_DIR}/../../servicepoint2
|
||||||
SP2_INCLUDE := ${SP2_DIR}/include
|
SP2_INCLUDE := ${ROOT_DIR}/../../servicepoint2-binding-c
|
||||||
SP2_TARGET_RELEASE := ${ROOT_DIR}/../../target/release
|
SP2_TARGET_RELEASE := ${ROOT_DIR}/../../target/release
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: build run clean
|
||||||
|
|
||||||
|
build: ${OUT_DIR}/lang_c
|
||||||
|
|
||||||
run: ${OUT_DIR}/lang_c
|
run: ${OUT_DIR}/lang_c
|
||||||
out/lang_c
|
out/lang_c
|
||||||
|
|
||||||
all: ${OUT_DIR}/lang_c
|
|
||||||
|
|
||||||
${OUT_DIR}/lang_c: ${SP2_TARGET_RELEASE} main.c
|
|
||||||
mkdir -p ${OUT_DIR}
|
|
||||||
gcc main.c -I ${SP2_INCLUDE} -L ${SP2_TARGET_RELEASE} -Wl,-Bstatic -lservicepoint2 -Wl,-Bdynamic -o ${OUT_DIR}/lang_c
|
|
||||||
|
|
||||||
${SP2_TARGET_RELEASE}:
|
|
||||||
cd ${SP2_DIR} && cargo build --release --all-features
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r ${SP2_INCLUDE_DIR} || true
|
|
||||||
rm -r ${OUT_DIR} || true
|
rm -r ${OUT_DIR} || true
|
||||||
rm -r ${SP2_TARGET_RELEASE} || true
|
rm -r ${SP2_TARGET_RELEASE} || true
|
||||||
|
|
||||||
|
${OUT_DIR}/lang_c: main.c
|
||||||
|
cd ${SP2_DIR} && cargo build --release --all-features
|
||||||
|
mkdir -p ${OUT_DIR}
|
||||||
|
gcc main.c -I ${SP2_INCLUDE} -L ${SP2_TARGET_RELEASE} -Wl,-Bstatic -lservicepoint2 -Wl,-Bdynamic -o ${OUT_DIR}/lang_c
|
||||||
33
servicepoint2-binding-c/cbindgen.toml
Normal file
33
servicepoint2-binding-c/cbindgen.toml
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
language = "C"
|
||||||
|
include_version = true
|
||||||
|
cpp_compat = true
|
||||||
|
|
||||||
|
############################ Code Style Options ################################
|
||||||
|
|
||||||
|
braces = "SameLine"
|
||||||
|
line_length = 80
|
||||||
|
tab_width = 4
|
||||||
|
documentation = true
|
||||||
|
documentation_style = "auto"
|
||||||
|
documentation_length = "full"
|
||||||
|
line_endings = "LF"
|
||||||
|
|
||||||
|
############################# Codegen Options ##################################
|
||||||
|
|
||||||
|
style = "both"
|
||||||
|
sort_by = "Name"
|
||||||
|
usize_is_size_t = true
|
||||||
|
|
||||||
|
[defines]
|
||||||
|
"feature = compression-gz" = "SP2_FEATURE_compression_gz"
|
||||||
|
"feature = compression-bz" = "SP2_FEATURE_compression_bz"
|
||||||
|
"feature = compression-lz" = "SP2_FEATURE_compression_lz"
|
||||||
|
"feature = compression-zs" = "SP2_FEATURE_compression_zs"
|
||||||
|
#"feature = c-api" = "SP2_FEATURE_c-api"
|
||||||
|
|
||||||
|
[export]
|
||||||
|
prefix = "sp2_"
|
||||||
|
|
||||||
|
[parse.expand]
|
||||||
|
features = ["c-api"]
|
||||||
|
all_features = true
|
||||||
4
servicepoint2-binding-c/generate.sh
Executable file
4
servicepoint2-binding-c/generate.sh
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# if the script crashes here, run `cargo install cbindgen`
|
||||||
|
cbindgen --config cbindgen.toml --clean --output servicepoint2.h ../servicepoint2
|
||||||
372
servicepoint2-binding-c/servicepoint2.h
Normal file
372
servicepoint2-binding-c/servicepoint2.h
Normal file
|
|
@ -0,0 +1,372 @@
|
||||||
|
/* Generated with cbindgen:0.26.0 */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pixel count on whole screen
|
||||||
|
*/
|
||||||
|
#define sp2_PIXEL_COUNT ((size_t)sp2_PIXEL_WIDTH * (size_t)sp2_PIXEL_HEIGHT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* screen height in pixels
|
||||||
|
*/
|
||||||
|
#define sp2_PIXEL_HEIGHT (sp2_TILE_HEIGHT * sp2_TILE_SIZE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* screen width in pixels
|
||||||
|
*/
|
||||||
|
#define sp2_PIXEL_WIDTH (sp2_TILE_WIDTH * sp2_TILE_SIZE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tile count in the y-direction
|
||||||
|
*/
|
||||||
|
#define sp2_TILE_HEIGHT 20
|
||||||
|
|
||||||
|
/**
|
||||||
|
* size of a single tile in one dimension
|
||||||
|
*/
|
||||||
|
#define sp2_TILE_SIZE 8
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tile count in the x-direction
|
||||||
|
*/
|
||||||
|
#define sp2_TILE_WIDTH 56
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the kind of compression to use. Availability depends on features.
|
||||||
|
*/
|
||||||
|
enum sp2_CompressionCode
|
||||||
|
#ifdef __cplusplus
|
||||||
|
: uint16_t
|
||||||
|
#endif // __cplusplus
|
||||||
|
{
|
||||||
|
Uncompressed = 0,
|
||||||
|
#if defined(SP2_FEATURE_compression_gz)
|
||||||
|
Gz = 26490,
|
||||||
|
#endif
|
||||||
|
#if defined(SP2_FEATURE_compression_bz)
|
||||||
|
Bz = 25210,
|
||||||
|
#endif
|
||||||
|
#if defined(SP2_FEATURE_compression_lz)
|
||||||
|
Lz = 27770,
|
||||||
|
#endif
|
||||||
|
#if defined(SP2_FEATURE_compression_zs)
|
||||||
|
Zs = 31347,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
#ifndef __cplusplus
|
||||||
|
typedef uint16_t sp2_CompressionCode;
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A vector of bits
|
||||||
|
*/
|
||||||
|
typedef struct sp2_BitVec sp2_BitVec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A grid of bytes
|
||||||
|
*/
|
||||||
|
typedef struct sp2_ByteGrid sp2_ByteGrid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A command to send to the display.
|
||||||
|
*/
|
||||||
|
typedef struct sp2_Command sp2_Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A connection to the display.
|
||||||
|
*/
|
||||||
|
typedef struct sp2_Connection sp2_Connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A grid of pixels stored in packed bytes.
|
||||||
|
*/
|
||||||
|
typedef struct sp2_PixelGrid sp2_PixelGrid;
|
||||||
|
|
||||||
|
typedef uint16_t sp2_Offset;
|
||||||
|
|
||||||
|
typedef uint8_t sp2_Brightness;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a `BitVec`.
|
||||||
|
* The returned instance has to be freed with `bit_vec_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_BitVec *sp2_bit_vec_clone(const struct sp2_BitVec *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a `BitVec`.
|
||||||
|
*
|
||||||
|
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
||||||
|
*/
|
||||||
|
void sp2_bit_vec_dealloc(struct sp2_BitVec *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of all bits in the `BitVec`.
|
||||||
|
*/
|
||||||
|
void sp2_bit_vec_fill(struct sp2_BitVec *this_, bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of a bit from the `BitVec`.
|
||||||
|
*/
|
||||||
|
bool sp2_bit_vec_get(const struct sp2_BitVec *this_, size_t index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the length of the `BitVec` in bits.
|
||||||
|
*/
|
||||||
|
size_t sp2_bit_vec_len(const struct sp2_BitVec *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a `BitVec` from the provided data.
|
||||||
|
* The returned instance has to be freed with `bit_vec_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_BitVec *sp2_bit_vec_load(const uint8_t *data, size_t data_length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new `BitVec` instance.
|
||||||
|
* The returned instance has to be freed with `bit_vec_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_BitVec *sp2_bit_vec_new(size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a bit in the `BitVec`.
|
||||||
|
*/
|
||||||
|
bool sp2_bit_vec_set(struct sp2_BitVec *this_, size_t index, bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a `ByteGrid`.
|
||||||
|
* The returned instance has to be freed with `byte_grid_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_ByteGrid *sp2_byte_grid_clone(const struct sp2_ByteGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a `ByteGrid`.
|
||||||
|
*
|
||||||
|
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
||||||
|
*/
|
||||||
|
void sp2_byte_grid_dealloc(struct sp2_ByteGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the whole `ByteGrid` with the specified value
|
||||||
|
*/
|
||||||
|
void sp2_byte_grid_fill(struct sp2_ByteGrid *this_, uint8_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current value at the specified position
|
||||||
|
*/
|
||||||
|
uint8_t sp2_byte_grid_get(const struct sp2_ByteGrid *this_, size_t x, size_t y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the height in pixels of the `ByteGrid` instance.
|
||||||
|
*/
|
||||||
|
size_t sp2_byte_grid_height(const struct sp2_PixelGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a `ByteGrid` with the specified dimensions from the provided data.
|
||||||
|
* The returned instance has to be freed with `byte_grid_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_ByteGrid *sp2_byte_grid_load(size_t width,
|
||||||
|
size_t height,
|
||||||
|
const uint8_t *data,
|
||||||
|
size_t data_length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new `ByteGrid` instance.
|
||||||
|
* The returned instance has to be freed with `byte_grid_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_ByteGrid *sp2_byte_grid_new(size_t width, size_t height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current value at the specified position
|
||||||
|
*/
|
||||||
|
void sp2_byte_grid_set(struct sp2_ByteGrid *this_,
|
||||||
|
size_t x,
|
||||||
|
size_t y,
|
||||||
|
uint8_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the width in pixels of the `ByteGrid` instance.
|
||||||
|
*/
|
||||||
|
size_t sp2_byte_grid_width(const struct sp2_PixelGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::BitmapLinear` instance.
|
||||||
|
* The passed `BitVec` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_bitmap_linear(sp2_Offset offset,
|
||||||
|
struct sp2_BitVec *bit_vec,
|
||||||
|
sp2_CompressionCode compression);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::BitmapLinearAnd` instance.
|
||||||
|
* The passed `BitVec` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_bitmap_linear_and(sp2_Offset offset,
|
||||||
|
struct sp2_BitVec *bit_vec,
|
||||||
|
sp2_CompressionCode compression);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::BitmapLinearOr` instance.
|
||||||
|
* The passed `BitVec` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_bitmap_linear_or(sp2_Offset offset,
|
||||||
|
struct sp2_BitVec *bit_vec,
|
||||||
|
sp2_CompressionCode compression);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::BitmapLinearWin` instance.
|
||||||
|
* The passed `PixelGrid` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_bitmap_linear_win(uint16_t x,
|
||||||
|
uint16_t y,
|
||||||
|
struct sp2_PixelGrid *byte_grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::BitmapLinearXor` instance.
|
||||||
|
* The passed `BitVec` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_bitmap_linear_xor(sp2_Offset offset,
|
||||||
|
struct sp2_BitVec *bit_vec,
|
||||||
|
sp2_CompressionCode compression);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::Brightness` instance
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_brightness(sp2_Brightness brightness);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::CharBrightness` instance.
|
||||||
|
* The passed `ByteGrid` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_char_brightness(uint16_t x,
|
||||||
|
uint16_t y,
|
||||||
|
struct sp2_ByteGrid *byte_grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::Clear` instance
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_clear(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a `Command` instance
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_clone(const struct sp2_Command *original);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::Cp437Data` instance.
|
||||||
|
* The passed `ByteGrid` gets deallocated in the process.
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_cp437_data(uint16_t x,
|
||||||
|
uint16_t y,
|
||||||
|
struct sp2_ByteGrid *byte_grid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a `Command`. Note that connection_send does this implicitly, so you only need
|
||||||
|
* to do this if you use the library for parsing commands.
|
||||||
|
*/
|
||||||
|
void sp2_command_dealloc(struct sp2_Command *ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::FadeOut` instance
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_fade_out(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new `Command::HardReset` instance
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_hard_reset(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to load a `Command` from the passed array with the specified length.
|
||||||
|
*
|
||||||
|
* returns: NULL in case of an error, pointer to the allocated command otherwise
|
||||||
|
*/
|
||||||
|
struct sp2_Command *sp2_command_try_load(const uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes and deallocates a connection instance
|
||||||
|
*/
|
||||||
|
void sp2_connection_dealloc(struct sp2_Connection *ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of Connection.
|
||||||
|
* The returned instance has to be deallocated with `connection_dealloc`.
|
||||||
|
*
|
||||||
|
* returns: NULL if connection fails or connected instance
|
||||||
|
*
|
||||||
|
* Panics: bad string encoding
|
||||||
|
*/
|
||||||
|
struct sp2_Connection *sp2_connection_open(const char *host);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the command instance. The instance is consumed / destroyed and cannot be used after this call.
|
||||||
|
*/
|
||||||
|
bool sp2_connection_send(const struct sp2_Connection *connection,
|
||||||
|
struct sp2_Command *command_ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a `PixelGrid`.
|
||||||
|
* The returned instance has to be freed with `pixel_grid_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_PixelGrid *sp2_pixel_grid_clone(const struct sp2_PixelGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deallocates a `PixelGrid`.
|
||||||
|
*
|
||||||
|
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
|
||||||
|
*/
|
||||||
|
void sp2_pixel_grid_dealloc(struct sp2_PixelGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the whole `PixelGrid` with the specified value
|
||||||
|
*/
|
||||||
|
void sp2_pixel_grid_fill(struct sp2_PixelGrid *this_, bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current value at the specified position
|
||||||
|
*/
|
||||||
|
bool sp2_pixel_grid_get(const struct sp2_PixelGrid *this_, size_t x, size_t y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the height in pixels of the `PixelGrid` instance.
|
||||||
|
*/
|
||||||
|
size_t sp2_pixel_grid_height(const struct sp2_PixelGrid *this_);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a `PixelGrid` with the specified dimensions from the provided data.
|
||||||
|
* The returned instance has to be freed with `pixel_grid_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_PixelGrid *sp2_pixel_grid_load(size_t width,
|
||||||
|
size_t height,
|
||||||
|
const uint8_t *data,
|
||||||
|
size_t data_length);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new `PixelGrid` instance.
|
||||||
|
* The returned instance has to be freed with `pixel_grid_dealloc`.
|
||||||
|
*/
|
||||||
|
struct sp2_PixelGrid *sp2_pixel_grid_new(size_t width, size_t height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current value at the specified position
|
||||||
|
*/
|
||||||
|
void sp2_pixel_grid_set(struct sp2_PixelGrid *this_,
|
||||||
|
size_t x,
|
||||||
|
size_t y,
|
||||||
|
bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the width in pixels of the `PixelGrid` instance.
|
||||||
|
*/
|
||||||
|
size_t sp2_pixel_grid_width(const struct sp2_PixelGrid *this_);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
rm -r include || true
|
|
||||||
|
|
||||||
# if the script crashes here, run `cargo install cbindgen`
|
|
||||||
cbindgen --config cbindgen.toml --clean --output include/servicepoint2.h
|
|
||||||
Loading…
Reference in a new issue