Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pl-semiotics committed Jan 2, 2021
0 parents commit 75de1a9
Show file tree
Hide file tree
Showing 11 changed files with 1,329 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*~
\#*\#
.\#*
build
result
result-*

340 changes: 340 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.PHONY: all clean

CFLAGS += -DREMARKABLE_VERSION=$(REMARKABLE_VERSION)

all: build/librM-input-devices.so build/librM-input-devices-standalone.a build/rM-mk-uinput build/rM-mk-uinput-standalone
clean:
rm -rf build

build:
mkdir -p build
build/%.o: %.c | build
$(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS)
build/%.a: | build
$(AR) cr $@ $^
build/%.so: | build
$(CC) -shared -z defs -o $@ $^ $(LDFLAGS)

build/uinput.bin: | build
$(OBJCOPY) -I binary -O elf32-littlearm -B arm $(UINPUT_KO) $@

build/rM-input-devices.o: rM-input-devices.h
build/rM-input-devices-standalone.o: build/rM-input-devices.o input-devices-standalone.ld build/uinput.bin
$(LD) -Tinput-devices-standalone.ld -i -o $@ build/rM-input-devices.o

build/rM-mk-uinput.o: rM-input-devices.h

build/librM-input-devices-standalone.a: build/rM-input-devices-standalone.o

build/librM-input-devices.so: build/rM-input-devices.o
build/librM-input-devices.so: private override LDFLAGS += -ludev -lpthread

build/rM-mk-uinput: build/rM-mk-uinput.o build/librM-input-devices.so | build
$(CC) $(CFLAGS) -o $@ $< -Lbuild -lrM-input-devices
build/rM-mk-uinput-standalone: build/rM-mk-uinput.o build/librM-input-devices-standalone.a
$(CC) $(CFLAGS) -o $@ $< -Lbuild -lrM-input-devices-standalone -ludev -lpthread
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Introduction

This library provides a simple API for receiving and sending
digitizer/touch/keyboard events on the [reMarkable
tablets](https://remarkable.com). Currently, the main consumer is
[rM-vnc-server](https://github.com/pl-semiotics/rM-vnc-server). It
also supports using uinput to emulate the presence of such devices,
which may be useful in virtualized environments.

# Building

The supported way to build this is via the
[Nix](https://nixos.org/nix) package manager, through the
[nix-remarkable](https://github.com/pl-semiotics/nix-remarkable)
expressions. To build just this project via `nix build` from this
repo, download it into the `pkgs/` directory of `nix-remarkable`.

For any other system, the [Makefile](./Makefile) should provide some
guidance; please set `REMARKABLE_VERSION` to one or two (depending on
which version you are building for), and, if interested in the
standalone (statically linked, with a bundled uinput kernel module)
version of the library, provide the path to appropriate kernel module
in the `UINPUT_KO` environment variable.

Prebuilt binaries are available in the [Releases
tab](https://github.com/pl-semiotics/rM-input-devices/releases).

# Usage

For the library, see [rM-input-devices.h](./rM-input-devices.h) for
the interface. A simple executable `rM-mk-uinput` (which takes no
arguments and does nothing but create uinput devices for any missing
input devices) is also provided.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import ../.. {}).rmPkgs.rM-input-devices
18 changes: 18 additions & 0 deletions derivation.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ stdenv, lib, linuxHeaders, linuxPackages, targetPlatform }:

stdenv.mkDerivation {
pname = "rM-input-devices";
version = "0.0.1";
src = lib.cleanSource ./.;
buildInputs = [ linuxHeaders ];
REMARKABLE_VERSION = targetPlatform.platform.rmVersion;
UINPUT_KO = "${linuxPackages.kernel}/lib/modules/${linuxPackages.kernel.modDirVersion}/kernel/drivers/input/misc/uinput.ko";
outputs = [ "out" "dev" ];
installPhase = ''
mkdir -p $out/bin
cp build/rM-mk-uinput{,-standalone} $out/bin
mkdir -p $dev/include $dev/lib
cp rM-input-devices.h $dev/include
cp build/librM-input-devices{.so,-standalone.a} $dev/lib
'';
}
8 changes: 8 additions & 0 deletions input-devices-standalone.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SECTIONS
{
.uinput_ko : {
uinput_ko_begin = . ;
build/uinput.bin(.data)
uinput_ko_end = . ;
}
}
54 changes: 54 additions & 0 deletions private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "rM-input-devices.h"

#include <pthread.h>


struct fd_list {
int fd;
struct fd_list *next;
};

#define N_SLOTS 32
struct wacom_data {
pthread_mutex_t mutex;
int pen_down; int touch_down;
int abs_x; int abs_y; int abs_pressure;
int drop_until_syn;
void *userdata;
uint coord_kind;
};
struct touch_data {
pthread_mutex_t mutex;
int slots[N_SLOTS]; /* keep track of the tracking id for each slot */
int abs_x[N_SLOTS];
int abs_y[N_SLOTS];
int current_slot;
/* the kernel currently uses (mt->trkid++ & TRKID_MAX) to get a new
* tracking id, so we just stay a few thousand ids ahead of the
* kernel */
#define TRKID_MAX 0xffff
#define KERN_TRKID_OFFSET 4096
uint next_trkid;
int drop_until_syn;
void *userdata;
uint coord_kind;
};
struct key_data {
pthread_mutex_t mutex;
void *userdata;
};

struct rM_input_devices_priv {
struct fd_list* extra_wacom_fds;
struct fd_list* extra_touch_fds;
struct fd_list* extra_key_fds;
handle_wacom_event_t hwe;
handle_touch_event_t hte;
handle_key_event_t hke;
pthread_mutex_t input_thread_mutex;
int input_thread_running;
pthread_t input_thread;
struct wacom_data wd;
struct touch_data td;
struct key_data kd;
};
Loading

0 comments on commit 75de1a9

Please sign in to comment.