CAMLprim is not needed, use EOL80

This commit is contained in:
Marek Kubica 2014-07-06 23:25:38 +02:00
parent aecf1b42f7
commit 182bdb8393
2 changed files with 35 additions and 30 deletions

View File

@ -1,5 +1,5 @@
(** This module is useful to communicate with the GPIO ports of a raspberry.
It uses the wiringPi library : http://wiringpi.com/ **)
(** 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"
@ -11,19 +11,27 @@ external setupPhys : unit -> int = "caml_wiringPiSetupPhys"
external setupSys : unit -> int = "caml_wiringPiSetupSys"
(* ########## 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. *)
(* 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"
(* This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input. *)
(* 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"
(* Writes the value HIGH or LOW (1 or 0) to the given pin which must have been previously set as an output. *)
(* 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"
(* 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 *)
(* 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"
(* 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. *)
(* 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"
@ -31,10 +39,13 @@ external digitalWriteByte : int -> unit = "caml_digitalWriteByte"
(* ########## Timing ########## *)
(* Use it to wait a few ms or µs. If you want to wait for several
secondes, use Unix.sleep. *)
external delay : int -> unit = "caml_delay" (* wait n ms *)
external delayMicroseconds : int -> unit = "caml_delayMicroseconds" (* wait n µs *)
(* wait n ms *)
external delay : int -> unit = "caml_delay"
(* wait n µs *)
external delayMicroseconds : int -> unit = "caml_delayMicroseconds"
(* This returns a number representing the number if ms/µs since your program called one of the wiringPiSetup functions. *)
(* 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"

View File

@ -9,35 +9,30 @@
#include <wiringPi.h>
#include <wiringShift.h>
CAMLprim
value caml_hello(value unit) {
CAMLparam1(unit);
printf("Hello world!\n");
CAMLreturn(Val_unit);
}
CAMLprim
value caml_wiringPiSetup(value unit)
{
CAMLparam1(unit);
CAMLreturn(Val_int(wiringPiSetup()));
}
CAMLprim
value caml_wiringPiSetupGpio(value unit)
{
CAMLparam1(unit);
CAMLreturn(Val_int(wiringPiSetupGpio()));
}
CAMLprim
value caml_wiringPiSetupPhys(value unit)
{
CAMLparam1(unit);
CAMLreturn(Val_int(wiringPiSetupPhys()));
}
CAMLprim
value caml_wiringPiSetupSys(value unit)
{
CAMLparam1(unit);
@ -46,7 +41,6 @@ value caml_wiringPiSetupSys(value unit)
// Core functions
CAMLprim
value caml_pinMode(value pin, value mode)
{
CAMLparam2(pin, mode);
@ -54,7 +48,6 @@ value caml_pinMode(value pin, value mode)
CAMLreturn(Val_unit);
}
CAMLprim
value caml_pullUpDnControl(value pin, value pud)
{
CAMLparam2(pin, pud);
@ -62,7 +55,6 @@ value caml_pullUpDnControl(value pin, value pud)
CAMLreturn(Val_unit);
}
CAMLprim
value caml_digitalWrite(value pin, value value_p)
{
CAMLparam2(pin, value_p);
@ -70,7 +62,6 @@ value caml_digitalWrite(value pin, value value_p)
CAMLreturn(Val_unit);
}
CAMLprim
value caml_pwmWrite(value pin, value value_p)
{
CAMLparam2(pin, value_p);
@ -78,7 +69,6 @@ value caml_pwmWrite(value pin, value value_p)
CAMLreturn(Val_unit);
}
CAMLprim
value caml_digitalRead(value pin)
{
CAMLparam1(pin);
@ -89,7 +79,6 @@ value caml_digitalRead(value pin)
// Raspberry Pi Specifics
CAMLprim
value caml_digitalWriteByte(value value_p)
{
CAMLparam1(value_p);
@ -103,24 +92,24 @@ value caml_digitalWriteByte(value value_p)
// Timing
/* This returns a number representing the number if milliseconds since your program called one of the wiringPiSetup functions. */
CAMLprim
/* This returns a number representing the number if milliseconds since your
* program called one of the wiringPiSetup functions. */
value caml_millis(value unit)
{
CAMLparam1(unit);
CAMLreturn(Val_int(millis()));
}
/* This returns a number representing the number of microseconds since your program called one of the wiringPiSetup functions. */
CAMLprim
/* This returns a number representing the number of microseconds since your
* program called one of the wiringPiSetup functions. */
value caml_micros(value unit)
{
CAMLparam1(unit);
CAMLreturn(Val_int(micros()));
}
/* This causes program execution to pause for at least howLong milliseconds. Due to the multi-tasking nature of Linux it could be longer. */
CAMLprim
/* 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)
{
CAMLparam1(howLong);
@ -128,8 +117,13 @@ value caml_delay(value howLong)
CAMLreturn(Val_unit);
}
/* This causes program execution to pause for at least howLong microseconds. Due to the multi-tasking nature of Linux it could be longer. Delays under 100 microseconds are timed using a hard-coded loop continually polling the system time, Delays over 100 microseconds are done using the system nanosleep() function You may need to consider the implications of very short delays on the overall performance of the system, especially if using threads. */
CAMLprim
/* This causes program execution to pause for at least howLong microseconds.
* Due to the multi-tasking nature of Linux it could be longer. Delays under
* 100 microseconds are timed using a hard-coded loop continually polling the
* system time, Delays over 100 microseconds are done using the system
* 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)
{
CAMLparam1(howLong);