mirror of
https://github.com/co-dan/ocaml-wiringpi/
synced 2025-12-15 13:33:51 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db822ab65f | ||
|
|
cdac97b364 | ||
|
|
9cd950b00c | ||
|
|
7545734cb3 |
16
.gitignore
vendored
16
.gitignore
vendored
@@ -1,12 +1,4 @@
|
||||
*.mllib
|
||||
*.mldylib
|
||||
*.clib
|
||||
META
|
||||
Makefile
|
||||
configure
|
||||
_tags
|
||||
setup.ml
|
||||
setup.data
|
||||
setup.log
|
||||
myocamlbuild.ml
|
||||
_build/
|
||||
/_build/
|
||||
/_opam/
|
||||
.merlin
|
||||
*.install
|
||||
|
||||
11
Makefile
Normal file
11
Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
.PHONY: all
|
||||
all:
|
||||
jbuilder build --dev
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
jbuilder clean
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
jbuilder runtest --force
|
||||
15
_oasis
15
_oasis
@@ -1,15 +0,0 @@
|
||||
OASISFormat: 0.4
|
||||
Name: WiringPi
|
||||
Version: 0.0.1
|
||||
Synopsis: Binding to the WiringPi library for hardware access
|
||||
Authors: Tobias Bora, Marek Kubica
|
||||
License: LGPL-3 with OCaml linking exception
|
||||
Plugins: META (0.4), DevFiles (0.4)
|
||||
|
||||
Library "WiringPi"
|
||||
Path: src/
|
||||
BuildTools: ocamlbuild
|
||||
Modules: WiringPi
|
||||
CSources: WiringPi_stubs.c
|
||||
CCLib: -lwiringPi
|
||||
|
||||
2
pkg/pkg.ml
Normal file
2
pkg/pkg.ml
Normal file
@@ -0,0 +1,2 @@
|
||||
#use "topfind"
|
||||
#require "topkg-jbuilder.auto"
|
||||
@@ -1,55 +1,55 @@
|
||||
(** This module is useful to communicate with the GPIO ports of a Raspberry Pi.
|
||||
It uses the WiringPi library: http://wiringpi.com/ **)
|
||||
|
||||
(* Test function *)
|
||||
external test_hello_world : unit -> unit = "caml_hello"
|
||||
|
||||
(* Use it at the very beginning to choose the numeroting mode *)
|
||||
external setup : unit -> int = "caml_wiringPiSetup"
|
||||
external setupGio : unit -> int = "caml_wiringPiSetupGpio"
|
||||
external setupPhys : unit -> int = "caml_wiringPiSetupPhys"
|
||||
external setupSys : unit -> int = "caml_wiringPiSetupSys"
|
||||
external setup: unit -> int = "ocamlwiring_setup"
|
||||
external setup_gpio: unit -> int = "ocamlwiring_setup_gpio"
|
||||
external setup_phys: unit -> int = "ocamlwiring_setup_phys"
|
||||
external setup_sys: unit -> int = "ocamlwiring_setup_sys"
|
||||
|
||||
(* ########## Write on the device ########## *)
|
||||
(* This sets the mode of a pin to either INPUT (= 0), OUTPUT (= 1),
|
||||
* PWM_OUTPUT (= 2) or GPIO_CLOCK (= 3).
|
||||
* Note that only wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only
|
||||
* wiringPi pin 7 (BCM_GPIO 4) supports CLOCK output modes. *)
|
||||
external pinMode : int -> int -> unit = "caml_pinMode"
|
||||
|
||||
external pin_mode: int -> int -> unit = "ocamlwiring_pin_mode"
|
||||
|
||||
(* This sets the pull-up or pull-down resistor mode on the given pin, which
|
||||
* should be set as an input. *)
|
||||
external pullUpDnControl : int -> int -> unit = "caml_pullUpDnControl"
|
||||
|
||||
external pull_up_dn_control: int -> int -> unit = "ocamlwiring_pull_up_dn_control"
|
||||
|
||||
(* Writes the value HIGH or LOW (1 or 0) to the given pin which must have
|
||||
* been previously set as an output. *)
|
||||
external digitalWrite : int -> int -> unit = "caml_digitalWrite"
|
||||
|
||||
external digital_write: int -> int -> unit = "ocamlwiring_digital_write"
|
||||
|
||||
(* Writes the value to the PWM register for the given pin.
|
||||
* The Raspberry Pi has one on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12) and
|
||||
* the range is 0-1024. Other PWM devices may have other PWM ranges *)
|
||||
external pwmWrite : int -> int -> unit = "caml_pwmWrite"
|
||||
external pwm_write: int -> int -> unit = "ocamlwiring_pwm_write"
|
||||
|
||||
(* This function returns the value read at the given pin. It will be HIGH
|
||||
* or LOW (1 or 0) depending on the logic level at the pin. *)
|
||||
external digitalRead : int -> int = "caml_digitalRead"
|
||||
external digitalWriteByte : int -> unit = "caml_digitalWriteByte"
|
||||
external digital_read: int -> int = "ocamlwiring_digital_read"
|
||||
external digital_write_byte: int -> unit = "ocamlwiring_digital_write_byte"
|
||||
|
||||
external analog_read: int -> int = "ocamlwiring_analog_read"
|
||||
external analog_write: int -> int -> unit = "ocamlwiring_analog_write"
|
||||
|
||||
|
||||
|
||||
(* ########## Timing ########## *)
|
||||
(* Use it to wait a few ms or µs. If you want to wait for several
|
||||
secondes, use Unix.sleep. *)
|
||||
(* wait n ms *)
|
||||
external delay : int -> unit = "caml_delay"
|
||||
external delay: int -> unit = "ocamlwiring_delay"
|
||||
(* wait n µs *)
|
||||
external delayMicroseconds : int -> unit = "caml_delayMicroseconds"
|
||||
|
||||
external delay_microseconds: int -> unit = "ocamlwiring_delay_microseconds"
|
||||
|
||||
(* This returns a number representing the number if ms/µs since your program
|
||||
* called one of the wiringPiSetup functions. *)
|
||||
external millis : unit -> int = "caml_millis"
|
||||
external micros : unit -> int = "caml_micros"
|
||||
external millis : unit -> int = "ocamlwiring_millis"
|
||||
external micros : unit -> int = "ocamlwiring_micros"
|
||||
|
||||
|
||||
|
||||
(* ################# Name of pins : ################# *)
|
||||
(* +----------+-Rev2-+------+--------+------+-------+ *)
|
||||
(* | wiringPi | GPIO | Phys | Name | Mode | Value | *)
|
||||
|
||||
@@ -9,32 +9,25 @@
|
||||
#include <wiringPi.h>
|
||||
#include <wiringShift.h>
|
||||
|
||||
value caml_hello(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
printf("Hello world!\n");
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
value caml_wiringPiSetup(value unit)
|
||||
value ocamlwiring_setup(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
CAMLreturn(Val_int(wiringPiSetup()));
|
||||
}
|
||||
|
||||
value caml_wiringPiSetupGpio(value unit)
|
||||
value ocamlwiring_setup_gpio(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
CAMLreturn(Val_int(wiringPiSetupGpio()));
|
||||
}
|
||||
|
||||
value caml_wiringPiSetupPhys(value unit)
|
||||
value ocamlwiring_setup_phys(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
CAMLreturn(Val_int(wiringPiSetupPhys()));
|
||||
}
|
||||
|
||||
value caml_wiringPiSetupSys(value unit)
|
||||
value ocamlwiring_setup_sys(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
CAMLreturn(Val_int(wiringPiSetupSys()));
|
||||
@@ -42,45 +35,56 @@ value caml_wiringPiSetupSys(value unit)
|
||||
|
||||
// Core functions
|
||||
|
||||
value caml_pinMode(value pin, value mode)
|
||||
value ocamlwiring_pin_mode(value pin, value mode)
|
||||
{
|
||||
CAMLparam2(pin, mode);
|
||||
pinMode(Int_val(pin), Int_val(mode));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
value caml_pullUpDnControl(value pin, value pud)
|
||||
value ocamlwiring_pull_up_dn_control(value pin, value pud)
|
||||
{
|
||||
CAMLparam2(pin, pud);
|
||||
pullUpDnControl(Int_val(pin), Int_val(pin));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
value caml_digitalWrite(value pin, value value_p)
|
||||
value ocamlwiring_digital_write(value pin, value value_p)
|
||||
{
|
||||
CAMLparam2(pin, value_p);
|
||||
digitalWrite(Int_val(pin), Int_val(value_p));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
value caml_pwmWrite(value pin, value value_p)
|
||||
value ocamlwiring_pwm_write(value pin, value value_p)
|
||||
{
|
||||
CAMLparam2(pin, value_p);
|
||||
pwmWrite(Int_val(pin), Int_val(value_p));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
value caml_digitalRead(value pin)
|
||||
value ocamlwiring_digital_read(value pin)
|
||||
{
|
||||
CAMLparam1(pin);
|
||||
CAMLreturn(Val_int(digitalRead(Int_val(pin))));
|
||||
}
|
||||
|
||||
// AnalogRead and AnalogWrite needs to be added (module must be added)
|
||||
value ocamlwiring_analog_read(value pin)
|
||||
{
|
||||
CAMLparam1(pin);
|
||||
CAMLreturn(Val_int(analogRead(Int_val(pin))));
|
||||
}
|
||||
|
||||
value ocamlwiring_analog_write(value pin, value value_p)
|
||||
{
|
||||
CAMLparam2(pin, value_p);
|
||||
analogWrite(Int_val(pin), Int_val(value_p));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
// Raspberry Pi Specifics
|
||||
|
||||
value caml_digitalWriteByte(value value_p)
|
||||
value ocamlwiring_digital_write_byte(value value_p)
|
||||
{
|
||||
CAMLparam1(value_p);
|
||||
digitalWriteByte(Int_val(value_p));
|
||||
@@ -95,7 +99,7 @@ value caml_digitalWriteByte(value value_p)
|
||||
|
||||
/* This returns a number representing the number if milliseconds since your
|
||||
* program called one of the wiringPiSetup functions. */
|
||||
value caml_millis(value unit)
|
||||
value ocamlwiring_millis(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
CAMLreturn(Val_int(millis()));
|
||||
@@ -103,7 +107,7 @@ value caml_millis(value unit)
|
||||
|
||||
/* This returns a number representing the number of microseconds since your
|
||||
* program called one of the wiringPiSetup functions. */
|
||||
value caml_micros(value unit)
|
||||
value ocamlwiring_micros(value unit)
|
||||
{
|
||||
CAMLparam1(unit);
|
||||
CAMLreturn(Val_int(micros()));
|
||||
@@ -111,10 +115,10 @@ value caml_micros(value unit)
|
||||
|
||||
/* This causes program execution to pause for at least howLong milliseconds.
|
||||
* Due to the multi-tasking nature of Linux it could be longer. */
|
||||
value caml_delay(value howLong)
|
||||
value ocamlwiring_delay(value how_long)
|
||||
{
|
||||
CAMLparam1(howLong);
|
||||
delay(Int_val(howLong));
|
||||
CAMLparam1(how_long);
|
||||
delay(Int_val(how_long));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
@@ -125,9 +129,9 @@ value caml_delay(value howLong)
|
||||
* nanosleep() function – You may need to consider the implications of very
|
||||
* short delays on the overall performance of the system, especially if using
|
||||
* threads. */
|
||||
value caml_delayMicroseconds(value howLong)
|
||||
value ocamlwiring_delay_microseconds(value how_long)
|
||||
{
|
||||
CAMLparam1(howLong);
|
||||
delayMicroseconds(Int_val(howLong));
|
||||
CAMLparam1(how_long);
|
||||
delayMicroseconds(Int_val(how_long));
|
||||
CAMLreturn(Val_unit);
|
||||
}
|
||||
|
||||
3
src/jbuild
Normal file
3
src/jbuild
Normal file
@@ -0,0 +1,3 @@
|
||||
(library
|
||||
((name wiringpi)
|
||||
(public_name wiringpi)))
|
||||
10
wiringpi.descr
Normal file
10
wiringpi.descr
Normal file
@@ -0,0 +1,10 @@
|
||||
WiringPi for OCaml, low level Raspberry Pi hardware access
|
||||
WiringPi is a library that allows easy, Arduino-like access to hardware
|
||||
functionality (GPIO pins mostly) of the Raspberry Pi minicomputer. That library
|
||||
is written in C so what this package does is to provide a simple interface to
|
||||
use the C library from OCaml. The API is unchanged (even the capitalization) to
|
||||
provide an interface which is as similar as possible to the code that it is
|
||||
based upon.
|
||||
|
||||
Please note that you need to install the WiringPi library first, as it is not
|
||||
included in this package. Otherwise compilation will fail.
|
||||
16
wiringpi.opam
Normal file
16
wiringpi.opam
Normal file
@@ -0,0 +1,16 @@
|
||||
opam-version: "1.2"
|
||||
maintainer: "marek@xivilization.net"
|
||||
homepage: "https://github.com/Leonidas-from-XIV/ocaml-wiringpi"
|
||||
license: "LGPL-3 with OCaml linking exception"
|
||||
build: ["jbuilder" "build" "-p" name "-j" jobs]
|
||||
depends: [
|
||||
"jbuilder" {build}
|
||||
]
|
||||
post-messages: [
|
||||
"
|
||||
This package requires WiringPi development files installed.
|
||||
Tentative instructions : https://gist.githubusercontent.com/Leonidas-from-XIV/a1a7315ac01f7fbee3f0/raw
|
||||
"
|
||||
{failure}
|
||||
]
|
||||
available: os = "linux"
|
||||
Reference in New Issue
Block a user