mirror of
https://github.com/co-dan/ocaml-wiringpi/
synced 2025-12-16 14:03:51 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db822ab65f |
16
.gitignore
vendored
16
.gitignore
vendored
@@ -1,12 +1,4 @@
|
|||||||
*.mllib
|
/_build/
|
||||||
*.mldylib
|
/_opam/
|
||||||
*.clib
|
.merlin
|
||||||
META
|
*.install
|
||||||
Makefile
|
|
||||||
configure
|
|
||||||
_tags
|
|
||||||
setup.ml
|
|
||||||
setup.data
|
|
||||||
setup.log
|
|
||||||
myocamlbuild.ml
|
|
||||||
_build/
|
|
||||||
|
|||||||
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
|
||||||
20
_oasis
20
_oasis
@@ -1,20 +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, Gpio3
|
|
||||||
CSources: WiringPi_stubs.c
|
|
||||||
CCLib: -lwiringPi
|
|
||||||
|
|
||||||
Executable "wpi-button-example"
|
|
||||||
Path: examples/
|
|
||||||
BuildTools: ocamlbuild
|
|
||||||
MainIs: button.ml
|
|
||||||
BuildDepends: WiringPi,unix
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
open Gpio3
|
|
||||||
|
|
||||||
(* Set up the pins the following way: *)
|
|
||||||
(* pin 3 (pull-up) -> btn -> resistor -> gnd *)
|
|
||||||
|
|
||||||
let setup () =
|
|
||||||
Gpio3.setup ();
|
|
||||||
pin_mode GPIO3 IN;
|
|
||||||
pull_up_dn_control GPIO3 UP
|
|
||||||
|
|
||||||
let rec loop () =
|
|
||||||
(match digital_read GPIO3 with
|
|
||||||
| LOW -> print_endline "-- LOW"
|
|
||||||
| HIGH -> print_endline "++ HIGH");
|
|
||||||
Unix.sleepf 0.5;
|
|
||||||
loop ()
|
|
||||||
|
|
||||||
|
|
||||||
let _ =
|
|
||||||
setup ();
|
|
||||||
loop ();
|
|
||||||
|
|
||||||
2
pkg/pkg.ml
Normal file
2
pkg/pkg.ml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#use "topfind"
|
||||||
|
#require "topkg-jbuilder.auto"
|
||||||
95
src/Gpio3.ml
95
src/Gpio3.ml
@@ -1,95 +0,0 @@
|
|||||||
(** Typed interface for WiritngPi.
|
|
||||||
Missing:
|
|
||||||
- modes PWM_OUTPUT and GPIO_GLOCK
|
|
||||||
- pwm_write
|
|
||||||
- digital_write_byte
|
|
||||||
- analog_read
|
|
||||||
- analog_write
|
|
||||||
- delay, delay_microseconds (?)
|
|
||||||
*)
|
|
||||||
open WiringPi
|
|
||||||
|
|
||||||
let setup () = ignore (setup_gpio ())
|
|
||||||
|
|
||||||
type pin =
|
|
||||||
(* 3V3 | 5V *)
|
|
||||||
GPIO2 | (* 5V *)
|
|
||||||
GPIO3 | (* GND *)
|
|
||||||
GPIO4 | GPIO14
|
|
||||||
(* GND *) | GPIO15 |
|
|
||||||
GPIO17 | GPIO18 |
|
|
||||||
GPIO27 | (* GND *)
|
|
||||||
GPIO22 | GPIO23
|
|
||||||
(* 3V3 *) | GPIO24 |
|
|
||||||
GPIO10 | (* GND *)
|
|
||||||
GPIO9 | GPIO25 |
|
|
||||||
GPIO11 | GPIO8
|
|
||||||
(* GND *) | GPIO7 |
|
|
||||||
GPIO0 | GPIO1 |
|
|
||||||
GPIO5 | (* GND *)
|
|
||||||
GPIO6 | GPIO12 |
|
|
||||||
GPIO13 | (* GND *)
|
|
||||||
GPIO19 | GPIO16 |
|
|
||||||
GPIO26 | GPIO20
|
|
||||||
|
|
||||||
let int_of_pin = function
|
|
||||||
| GPIO2 -> 2
|
|
||||||
| GPIO3 -> 3
|
|
||||||
| GPIO4 -> 4
|
|
||||||
| GPIO14 -> 14
|
|
||||||
| GPIO15 -> 15
|
|
||||||
| GPIO17 -> 17
|
|
||||||
| GPIO18 -> 18
|
|
||||||
| GPIO27 -> 27
|
|
||||||
| GPIO22 -> 22
|
|
||||||
| GPIO23 -> 23
|
|
||||||
| GPIO24 -> 24
|
|
||||||
| GPIO10 -> 10
|
|
||||||
| GPIO9 -> 9
|
|
||||||
| GPIO25 -> 25
|
|
||||||
| GPIO11 -> 11
|
|
||||||
| GPIO8 -> 8
|
|
||||||
| GPIO7 -> 7
|
|
||||||
| GPIO0 -> 0
|
|
||||||
| GPIO1 -> 1
|
|
||||||
| GPIO5 -> 5
|
|
||||||
| GPIO6 -> 6
|
|
||||||
| GPIO12 -> 12
|
|
||||||
| GPIO13 -> 13
|
|
||||||
| GPIO19 -> 19
|
|
||||||
| GPIO16 -> 16
|
|
||||||
| GPIO26 -> 26
|
|
||||||
| GPIO20 -> 20
|
|
||||||
|
|
||||||
(* What is not supported: PWM_OUTPUT and GPIO_GLOCK *)
|
|
||||||
type mode = IN | OUT
|
|
||||||
|
|
||||||
(** [pin_mode] sets the mode of the pin to either input or output
|
|
||||||
(other modes not supported at this moment). *)
|
|
||||||
let pin_mode (p : pin) (m : mode) =
|
|
||||||
match m with
|
|
||||||
| IN -> WiringPi.pin_mode (int_of_pin p) 0
|
|
||||||
| OUT -> WiringPi.pin_mode (int_of_pin p) 1
|
|
||||||
|
|
||||||
type pin_updn = UP | DOWN | OFF
|
|
||||||
|
|
||||||
(** [pull_up_dn_control] sets the pull-up or pull-down resistor mode on
|
|
||||||
the given pin, which should be set as an input. *)
|
|
||||||
let pull_up_dn_control (p : pin) = function
|
|
||||||
| UP -> WiringPi.pull_up_dn_control (int_of_pin p) 2
|
|
||||||
| DOWN -> WiringPi.pull_up_dn_control (int_of_pin p) 1
|
|
||||||
| OFF -> WiringPi.pull_up_dn_control (int_of_pin p) 0
|
|
||||||
|
|
||||||
type pin_value = LOW | HIGH
|
|
||||||
|
|
||||||
(** [digital_write] the value HIGH or LOW to the given pin which must
|
|
||||||
have been previously set as an output. *)
|
|
||||||
let digital_write (p : pin) (v : pin_value) =
|
|
||||||
match v with
|
|
||||||
| LOW -> WiringPi.digital_write (int_of_pin p) 0
|
|
||||||
| HIGH -> WiringPi.digital_write (int_of_pin p) 1
|
|
||||||
|
|
||||||
let digital_read (p : pin) : pin_value =
|
|
||||||
match WiringPi.digital_read (int_of_pin p) with
|
|
||||||
| 0 -> LOW
|
|
||||||
| _ -> HIGH
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
(** broadcom numbers *)
|
|
||||||
val setup : unit -> unit
|
|
||||||
|
|
||||||
type pin =
|
|
||||||
(* 3V3 | 5V *)
|
|
||||||
GPIO2 | (* 5V *)
|
|
||||||
GPIO3 | (* GND *)
|
|
||||||
GPIO4 | GPIO14
|
|
||||||
(* GND *) | GPIO15 |
|
|
||||||
GPIO17 | GPIO18 |
|
|
||||||
GPIO27 | (* GND *)
|
|
||||||
GPIO22 | GPIO23
|
|
||||||
(* 3V3 *) | GPIO24 |
|
|
||||||
GPIO10 | (* GND *)
|
|
||||||
GPIO9 | GPIO25 |
|
|
||||||
GPIO11 | GPIO8
|
|
||||||
(* GND *) | GPIO7 |
|
|
||||||
GPIO0 | GPIO1 |
|
|
||||||
GPIO5 | (* GND *)
|
|
||||||
GPIO6 | GPIO12 |
|
|
||||||
GPIO13 | (* GND *)
|
|
||||||
GPIO19 | GPIO16 |
|
|
||||||
GPIO26 | GPIO20
|
|
||||||
|
|
||||||
type pin_value = LOW | HIGH
|
|
||||||
|
|
||||||
type mode = IN | OUT
|
|
||||||
type pin_updn = UP | DOWN | OFF
|
|
||||||
|
|
||||||
val pin_mode : pin -> mode -> unit
|
|
||||||
val pull_up_dn_control : pin -> pin_updn -> unit
|
|
||||||
val digital_write : pin -> pin_value -> unit
|
|
||||||
val digital_read : pin -> pin_value
|
|
||||||
@@ -45,7 +45,7 @@ value ocamlwiring_pin_mode(value pin, value mode)
|
|||||||
value ocamlwiring_pull_up_dn_control(value pin, value pud)
|
value ocamlwiring_pull_up_dn_control(value pin, value pud)
|
||||||
{
|
{
|
||||||
CAMLparam2(pin, pud);
|
CAMLparam2(pin, pud);
|
||||||
pullUpDnControl(Int_val(pin), Int_val(pud));
|
pullUpDnControl(Int_val(pin), Int_val(pin));
|
||||||
CAMLreturn(Val_unit);
|
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