Permalink
Browse files

Initial support for Wiring Pi version 2

(tested with 2.0.7)

This commit doesn't differ too much from the version 1 support, except
for the addition of wpi:setup_phys/0 and building with
wiringPiDev (for the LCD library).

Ought to fix #5.
  • Loading branch information...
1 parent 8894d9b commit 3fc91d2394dc43f8d19d6d6f6c14d65c09df951f @klajo committed Jun 19, 2013
Showing with 19 additions and 1 deletion.
  1. +7 −0 c_src/wpi.c
  2. +1 −1 rebar.config
  3. +11 −0 src/wpi.erl
View
7 c_src/wpi.c
@@ -66,6 +66,12 @@ setup_gpio_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
}
static ERL_NIF_TERM
+setup_phys_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+ return mk_setup_return_val(env, wiringPiSetupPhys());
+}
+
+static ERL_NIF_TERM
setup_sys_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
return mk_setup_return_val(env, wiringPiSetupSys());
@@ -463,6 +469,7 @@ static ErlNifFunc nif_funcs[] =
// setup
{"setup_nif", 0, setup_nif},
{"setup_gpio_nif", 0, setup_gpio_nif},
+ {"setup_phys_nif", 0, setup_phys_nif},
{"setup_sys_nif", 0, setup_sys_nif},
// the basics: pins and stuff
{"pin_mode_nif", 2, pin_mode_nif},
View
2 rebar.config
@@ -1 +1 @@
-{port_env, [{"LDFLAGS", "$LDFLAGS -lwiringPi -lpthread"}]}.
+{port_env, [{"LDFLAGS", "$LDFLAGS -lwiringPi -lwiringPiDev -lpthread"}]}.
View
11 src/wpi.erl
@@ -36,6 +36,7 @@
%% setup
-export([setup/0]).
-export([setup_gpio/0]).
+-export([setup_phys/0]).
-export([setup_sys/0]).
%% the basics: pins and stuff
@@ -135,6 +136,15 @@ setup() ->
setup_gpio() ->
setup_gpio_nif().
+-spec(setup_phys() -> ok | {error, term()}).
+%% @doc Identical to {@link setup/0}, however it allows the calling
+%% programs to use the physical pin numbers on the P1 connector only.
+%%
+%% As for {@link setup/0}, this function needs to be called with root
+%% priviliges.
+setup_phys() ->
+ setup_phys_nif().
+
-spec(setup_sys() -> ok | {error, term()}).
%% @doc This initialises wiringPi but uses the /sys/class/gpio
%% interface rather than accessing the hardware directly. This can be
@@ -158,6 +168,7 @@ setup_sys() ->
setup_nif() -> ?nif_stub.
setup_gpio_nif() -> ?nif_stub.
+setup_phys_nif() -> ?nif_stub.
setup_sys_nif() -> ?nif_stub.
%% The basics: pins and stuff

0 comments on commit 3fc91d2

Please sign in to comment.