// C# binding for PWM output services in libsimpleio.so
// Copyright (C)2017-2023, Philip Munts dba Munts Technologies.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
using System.Runtime.InteropServices;
namespace IO.Bindings
{
public static partial class libsimpleio
{
///
/// Configure the PWM output as active low (inverted).
///
/// Not all platforms support active low (inverted) PWM
/// outputs.
public const int PWM_POLARITY_ACTIVELOW = 0;
///
/// Configure the PWM output as active high (normal).
///
public const int PWM_POLARITY_ACTIVEHIGH = 1;
///
/// Configure a Linux PWM output device.
///
/// Chip number.
/// Channel number.
/// Pulse period in microseconds.
/// Initial on time in microseconds.
/// On many platforms two more more PWM outputs may share the same
/// clock generator, so configuring different PWM pulse periods may not be
/// possible.
/// PWM output polarity (0 for active low/inverted or 1
/// for active high/normal).
/// Not all platforms support active low (inverted) PWM outputs.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void PWM_configure(int chip, int channel,
int period, int ontime, int polarity, out int error);
///
/// Open a Linux PWM output device.
///
/// Chip number.
/// Channel number.
/// File descriptor.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void PWM_open(int chip, int channel, out int fd,
out int error);
///
/// Close a Linux PWM output device.
///
/// File descriptor.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void PWM_close(int fd, out int error);
///
/// Set a Linux PWM output device duty cycle.
///
/// File descriptor.
/// On time in microseconds.
/// Error code. Zero upon success or an errno
/// value upon failure.
[DllImport("simpleio")]
public static extern void PWM_write(int fd, int ontime, out int error);
}
}