--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
+
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class Adc
+ {
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_adc_open")]
+ internal static extern ErrorCode Open(int device, int channel, out IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_adc_close")]
+ internal static extern ErrorCode Close(IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_adc_read")]
+ internal static extern ErrorCode Read(IntPtr handle, out uint value);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
+
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class Gpio
+ {
+ public enum Direction
+ {
+ In = 0,
+ OutHigh,
+ OutLow
+ }
+
+ public enum EdgeType
+ {
+ None = 0,
+ Rising,
+ Falling,
+ Both
+ }
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void InterruptedEventCallback(IntPtr handle, ErrorCode error, IntPtr data);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_open")]
+ internal static extern ErrorCode Open(int pin, out IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_close")]
+ internal static extern ErrorCode Close(IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_set_direction")]
+ internal static extern ErrorCode SetDirection(IntPtr handle, Direction direction);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_write")]
+ internal static extern ErrorCode Write(IntPtr handle, uint value);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_read")]
+ internal static extern ErrorCode Read(IntPtr handle, out uint value);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_set_edge_mode")]
+ internal static extern ErrorCode SetEdgeMode(IntPtr handle, EdgeType type);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_set_interrupted_cb")]
+ internal static extern ErrorCode SetInterruptedCb(IntPtr handle, InterruptedEventCallback callback, IntPtr data);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_gpio_unset_interrupted_cb")]
+ internal static extern ErrorCode UnsetInterruptedCb(IntPtr handle);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class I2c
+ {
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_open")]
+ internal static extern ErrorCode Open(int bus, int address, out IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_close")]
+ internal static extern ErrorCode Close(IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_read")]
+ internal static extern ErrorCode Read(IntPtr handle, byte[] value, uint size);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_write")]
+ internal static extern ErrorCode Write(IntPtr handle, byte[] value, uint size);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_read_register_byte")]
+ internal static extern ErrorCode ReadRegisterByte(IntPtr handle, byte register, out byte data);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_write_register_byte")]
+ internal static extern ErrorCode WriteRegisterByte(IntPtr handle, byte register, byte data);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_read_register_word")]
+ internal static extern ErrorCode ReadRegisterWord(IntPtr handle, byte register, out ushort data);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_i2c_write_register_word")]
+ internal static extern ErrorCode WriteRegisterWord(IntPtr handle, byte register, ushort data);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string Peripherial = "libcapi-system-peripheral-io.so.0.1.0";
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class Pwm
+ {
+ public enum Polarity
+ {
+ ActiveHigh = 0,
+ ActiveLow
+ }
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_pwm_open")]
+ internal static extern ErrorCode Open(int chip, int pin, out IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_pwm_close")]
+ internal static extern ErrorCode Close(IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_pwm_set_period")]
+ internal static extern ErrorCode SetPeriod(IntPtr handle, uint period);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_pwm_set_duty_cycle")]
+ internal static extern ErrorCode SetDutyCycle(IntPtr handle, uint dutyCycle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_pwm_set_polarity")]
+ internal static extern ErrorCode SetPolarity(IntPtr handle, Polarity polarity);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_pwm_set_enabled")]
+ internal static extern ErrorCode SetEnabled(IntPtr handle, bool enabled);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class Spi
+ {
+ public enum Mode
+ {
+ Mode0 = 0,
+ Mode1,
+ Mode2,
+ Mode3
+ }
+
+ public enum BitOrder
+ {
+ Msb = 0,
+ Lsb
+ }
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_open")]
+ internal static extern ErrorCode Open(int bus, int chipSelectNumber, out IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_close")]
+ internal static extern ErrorCode Close(IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_set_mode")]
+ internal static extern ErrorCode SetMode(IntPtr handle, Mode mode);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_set_bit_order")]
+ internal static extern ErrorCode SetBitOrder(IntPtr handle, BitOrder order);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_set_bits_per_word")]
+ internal static extern ErrorCode SetBitsPerWord(IntPtr handle, byte bits);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_set_frequency")]
+ internal static extern ErrorCode SetFrequency(IntPtr handle, uint frequency);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_read")]
+ internal static extern ErrorCode Read(IntPtr handle, byte[] data, uint size);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_write")]
+ internal static extern ErrorCode Write(IntPtr handle, byte[] data, uint size);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_spi_transfer", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern ErrorCode Transfer(IntPtr handle, byte[] txdata, byte[] rxdata, uint size);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class Uart
+ {
+ public enum BaudRate
+ {
+ Rate0 = 0,
+ Rate50,
+ Rate75,
+ Rate110,
+ Rate134,
+ Rate150,
+ Rate200,
+ Rate300,
+ Rate600,
+ Rate1200,
+ Rate1800,
+ Rate2400,
+ Rate4800,
+ Rate9600,
+ Rate19200,
+ Rate38400,
+ Rate57600,
+ Rate115200,
+ Rate230400
+ }
+
+ public enum ByteSize
+ {
+ Size5Bit = 0,
+ Size6Bit,
+ Size7Bit,
+ Size8Bit
+ }
+
+ public enum Parity
+ {
+ None = 0,
+ Even,
+ Odd
+ }
+
+ public enum StopBits
+ {
+ Bits1Bit = 0,
+ Bits2Bit
+ }
+
+ public enum HardwareFlowControl
+ {
+ None = 0,
+ AutoRtscts
+ }
+
+ public enum SoftwareFlowControl
+ {
+ None = 0,
+ XonXoff,
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
+
+internal static partial class Interop
+{
+ internal static partial class Peripheral
+ {
+ internal static partial class Uart
+ {
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_open")]
+ internal static extern ErrorCode Open(int port, out IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_close")]
+ internal static extern ErrorCode Close(IntPtr handle);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_set_baud_rate")]
+ internal static extern ErrorCode SetBaudRate(IntPtr handle, BaudRate rate);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_set_byte_size")]
+ internal static extern ErrorCode SetByteSize(IntPtr handle, ByteSize size);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_set_parity")]
+ internal static extern ErrorCode SetParity(IntPtr handle, Parity parity);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_set_stop_bits")]
+ internal static extern ErrorCode SetStopBits(IntPtr handle, StopBits bits);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_set_flow_control")]
+ internal static extern ErrorCode SetFlowControl(
+ IntPtr handle,
+ SoftwareFlowControl softwareFlowControl,
+ HardwareFlowControl hardwareFlowControl);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_read")]
+ internal static extern ErrorCode Read(IntPtr handle, byte[] data, uint size);
+
+ [DllImport(Libraries.Peripherial, EntryPoint = "peripheral_uart_write")]
+ internal static extern ErrorCode Write(IntPtr handle, byte[] data, uint size);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ <SupportedProfiles>mobile,wearable</SupportedProfiles>
+</PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\src\Tizen\Tizen.csproj" />
+ </ItemGroup>
+
+</Project>
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.136
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Peripheral", "Tizen.Peripheral.csproj", "{5F19BF50-D2E2-4602-81AB-F6677A0EF88D}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csproj", "{9FFD6275-D54A-4F6B-9066-619F82D8B2C6}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{6F685D6D-FD89-4F05-AC1B-BBB8473B5F5F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5F19BF50-D2E2-4602-81AB-F6677A0EF88D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5F19BF50-D2E2-4602-81AB-F6677A0EF88D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5F19BF50-D2E2-4602-81AB-F6677A0EF88D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5F19BF50-D2E2-4602-81AB-F6677A0EF88D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9FFD6275-D54A-4F6B-9066-619F82D8B2C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9FFD6275-D54A-4F6B-9066-619F82D8B2C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9FFD6275-D54A-4F6B-9066-619F82D8B2C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9FFD6275-D54A-4F6B-9066-619F82D8B2C6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6F685D6D-FD89-4F05-AC1B-BBB8473B5F5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6F685D6D-FD89-4F05-AC1B-BBB8473B5F5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6F685D6D-FD89-4F05-AC1B-BBB8473B5F5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6F685D6D-FD89-4F05-AC1B-BBB8473B5F5F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using NativeAdc = Interop.Peripheral.Adc;
+
+namespace Tizen.Peripheral
+{
+ /// <summary>
+ /// The class allows applications to use the platform ADC peripheral.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
+ public class Adc : IDisposable
+ {
+ /// <summary>
+ /// Native handle to ADC.
+ /// </summary>
+ private IntPtr _handle;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Opens the ADC pin.
+ /// </summary>
+ /// <param name="device">The ADC device number.</param>
+ /// <param name="channel">The ADC channel number to control.</param>
+ public Adc(int device, int channel)
+ {
+ var ret = NativeAdc.Open(device, channel, out IntPtr handle);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _handle= handle;
+ }
+
+ /// <summary>
+ /// Closes the ADC pin.
+ /// </summary>
+ ~Adc()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Gets the current value of the ADC pin.
+ /// </summary>
+ public uint ReadValue()
+ {
+ var ret = NativeAdc.Read(_handle, out uint adcValue);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ return adcValue;
+ }
+
+ /// <summary>
+ /// Closes the ADC pin.
+ /// </summary>
+ public void Close() => Dispose();
+
+ /// <summary>
+ /// Disposes the ADC pin.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Disposes the ADC pin.
+ /// </summary>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ NativeAdc.Close(_handle);
+ _disposed = true;
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using Tizen.Internals.Errors;
+
+namespace Tizen.Peripheral
+{
+ /// <summary>
+ /// The class that represents the exception which will be thrown when the application can not control the peripherial.
+ /// </summary>
+ internal static class ExceptionFactory
+ {
+ internal static Exception CreateException(ErrorCode errorCode)
+ {
+ Log.Error("Peripheral", $"Error {errorCode}");
+
+ switch (errorCode)
+ {
+ case ErrorCode.IoError:
+ return new InvalidOperationException("I/O Error occured");
+
+ case ErrorCode.NoSuchDevice:
+ return new InvalidOperationException("No such device");
+
+ case ErrorCode.TryAgain:
+ return new InvalidOperationException("Try again");
+
+ case ErrorCode.OutOfMemory:
+ return new Exception("Out of memory");
+
+ case ErrorCode.PermissionDenied:
+ return new UnauthorizedAccessException("Permission denied");
+
+ case ErrorCode.ResourceBusy:
+ return new InvalidOperationException("Resource is busy");
+
+ case ErrorCode.InvalidParameter:
+ return new ArgumentException("Invalid parameters provided");
+
+ case ErrorCode.NotSupported:
+ return new InvalidOperationException("I/O Error occured");
+
+ case ErrorCode.Unknown:
+ return new InvalidOperationException("Unknown exception");
+
+ default:
+ return new Exception("");
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using Tizen.Internals.Errors;
+using NativeGpio = Interop.Peripheral.Gpio;
+
+namespace Tizen.Peripheral.Gpio
+{
+ /// <summary>
+ /// Enumeration of GPIO direction options.
+ /// </summary>
+ public enum GpioPinDriveMode
+ {
+ /// <summary>
+ /// Input Mode.
+ /// </summary>
+ Input,
+
+ /// <summary>
+ /// Output mode with high value.
+ /// </summary>
+ OutputInitiallyLow,
+
+ /// <summary>
+ /// Output mode with low value.
+ /// </summary>
+ OutputInitiallyHigh,
+ }
+
+ /// <summary>
+ /// Enumeration of GPIO values.
+ /// </summary>
+ public enum GpioPinValue
+ {
+ /// <summary>
+ /// Low value.
+ /// </summary>
+ Low = 0,
+
+ /// <summary>
+ /// High value.
+ /// </summary>
+ High
+ }
+
+ /// <summary>
+ /// Enumeration of edge types for the GPIO interrupt.
+ /// </summary>
+ public enum GpioChangePolarity
+ {
+ /// <summary>
+ /// No interrupt on GPIO.
+ /// </summary>
+ None = 0,
+
+ /// <summary>
+ /// Interrupt on rising only.
+ /// </summary>
+ Rising,
+
+ /// <summary>
+ /// Interrupt on falling only.
+ /// </summary>
+ Falling,
+
+ /// <summary>
+ /// Interrupt on rising and falling.
+ /// </summary>
+ Both
+ }
+
+ /// <summary>
+ /// The class allows applications to use the platform Digital Pins as Input/Output.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
+ public class Gpio : IDisposable
+ {
+
+ private GpioChangePolarity _polarityType;
+ private NativeGpio.InterruptedEventCallback _interruptedEventCallback;
+
+ /// <summary>
+ /// Native handle to Gpio.
+ /// </summary>
+ private IntPtr _handle;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Invoked when Gpio pin was interrupted.
+ /// </summary>
+ public event EventHandler<PinUpdatedEventArgs> ValueChanged;
+
+ /// <summary>
+ /// Opens a GPIO pin.
+ /// </summary>
+ /// <param name="pinNumber">The GPIO pin number.</param>
+ /// <param name="mode">GPIO direction.</param>
+ public Gpio(int pinNumber, GpioPinDriveMode mode)
+ {
+ var ret = NativeGpio.Open(pinNumber, out IntPtr handle);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _handle = handle;
+ PinNumber = pinNumber;
+ try
+ {
+ switch (mode)
+ {
+ case GpioPinDriveMode.Input:
+ ret = NativeGpio.SetEdgeMode(handle, NativeGpio.EdgeType.Both);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ ret = NativeGpio.SetDirection(handle, NativeGpio.Direction.In);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ SetIntteruptedCallback();
+ break;
+ case GpioPinDriveMode.OutputInitiallyLow:
+ ret = NativeGpio.SetDirection(handle, NativeGpio.Direction.OutLow);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ break;
+ case GpioPinDriveMode.OutputInitiallyHigh:
+ ret = NativeGpio.SetDirection(handle, NativeGpio.Direction.OutHigh);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ break;
+ }
+ } catch(Exception e) {
+ Dispose();
+ throw;
+ }
+ }
+
+
+ /// <summary>
+ /// Closes the GPIO pin.
+ /// </summary>
+ ~Gpio()
+ {
+ Dispose(false);
+ }
+
+ private void SetIntteruptedCallback()
+ {
+ _interruptedEventCallback = OnInterrupted;
+ var ret = NativeGpio.SetInterruptedCb(_handle, _interruptedEventCallback, IntPtr.Zero);
+ if (ret != ErrorCode.None)
+ {
+ throw ExceptionFactory.CreateException(ret);
+ }
+ }
+
+ private void OnInterrupted(IntPtr handle, ErrorCode error, IntPtr data)
+ {
+ ValueChanged?.Invoke(this, new PinUpdatedEventArgs(PinNumber, Read()));
+ }
+
+ /// <summary>
+ /// Closes a GPIO pin.
+ /// </summary>
+ public void Close() => Dispose();
+
+ /// <summary>
+ /// Disposes GPIO.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Disposes GPIO.
+ /// </summary>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ NativeGpio.UnsetInterruptedCb(_handle);
+ NativeGpio.Close(_handle);
+ _disposed = true;
+ }
+
+ /// <summary>
+ /// GPIO pin number.
+ /// </summary>
+ public int PinNumber { get; }
+
+ /// <summary>
+ /// Gets pin value.
+ /// </summary>
+ /// <returns>Pin value</returns>
+ public GpioPinValue Read()
+ {
+ var ret = NativeGpio.Read(_handle, out uint value);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ return value == 1 ? GpioPinValue.High : GpioPinValue.Low;
+ }
+
+ /// <summary>
+ /// Sets pin value.
+ /// </summary>
+ public void Write(GpioPinValue value)
+ {
+ var ret = NativeGpio.Write(_handle, value == GpioPinValue.High ? 1 : (uint)0);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Sets or gets the GPIO edge mode.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public GpioChangePolarity Polarity
+ {
+ get => _polarityType;
+ set
+ {
+ var ret = NativeGpio.SetEdgeMode(_handle, (NativeGpio.EdgeType)value);
+ if (ret != ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _polarityType = value;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using NativeI2c = Interop.Peripheral.I2c;
+
+namespace Tizen.Peripheral
+{
+ /// <summary>
+ /// The class allows applications to communicate via i2c platform's bus.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
+ public class I2c : IDisposable
+ {
+ /// <summary>
+ /// Native handle to I2c.
+ /// </summary>
+ private IntPtr _handle;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Opens the connection to the I2C slave device.
+ /// </summary>
+ /// <param name="bus">The I2C bus number that the slave device is connected.</param>
+ /// <param name="address">The address of the slave device.</param>
+ public I2c(int bus, int address)
+ {
+ var ret = NativeI2c.Open(bus, address, out IntPtr handle);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _handle = handle;
+ }
+
+ /// <summary>
+ /// Closes the connection to the I2C slave device.
+ /// </summary>
+ ~I2c()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Closes the connection to the I2C slave device.
+ /// </summary>
+ public void Close() => Dispose();
+
+ /// <summary>
+ /// Disposes the I2c.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Disposes the I2c.
+ /// </summary>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ NativeI2c.Close(_handle);
+ _disposed = true;
+ }
+
+ /// <summary>
+ /// Reads the bytes data from the I2C slave device.
+ /// </summary>
+ /// <param name="dataOut">The output byte array.</param>
+ public void Read(byte[] dataOut)
+ {
+ var length = Convert.ToUInt32(dataOut.Length);
+ var ret = NativeI2c.Read(_handle, dataOut, length);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Writes the bytes data to the I2C slave device.
+ /// </summary>
+ /// <param name="data"></param>
+ public void Write(byte[] data)
+ {
+ var length = Convert.ToUInt32(data.Length);
+ var ret = NativeI2c.Write(_handle, data, length);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Reads single byte data from the register of the I2C slave device.
+ /// </summary>
+ /// <param name="register">The register address of the I2C slave device to read.</param>
+ /// <returns>The single byte data.</returns>
+ public byte ReadRegisterByte(byte register)
+ {
+ var ret = NativeI2c.ReadRegisterByte(_handle, register, out byte data);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ return data;
+ }
+
+ /// <summary>
+ /// Writes single byte data to the register of the I2C slave device.
+ /// </summary>
+ /// <param name="register">The register address of the I2C slave device to write.</param>
+ /// <param name="data">The single byte data to write.</param>
+ public void WriteRegisterByte(byte register, byte data)
+ {
+ var ret = NativeI2c.WriteRegisterByte(_handle, register, data);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Reads word data from the register of the I2C slave device.
+ /// </summary>
+ /// <param name="register">The register address of the I2C slave device to read.</param>
+ /// <returns>The word (2 bytes) data.</returns>
+ public ushort ReadRegisterWord(byte register)
+ {
+ var ret = NativeI2c.ReadRegisterWord(_handle, register, out ushort data);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ return data;
+ }
+
+ /// <summary>
+ /// Writes word data to the register of the I2C slave device.
+ /// </summary>
+ /// <param name="register">The register address of the I2C slave device to write.</param>
+ /// <param name="data">The word (2 bytes) data to write.</param>
+ public void WriteRegisterWord(byte register, ushort data)
+ {
+ var ret = NativeI2c.WriteRegisterWord(_handle, register, data);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+
+namespace Tizen.Peripheral.Gpio
+{
+ /// <summary>
+ /// This custom class extend from EventArgs to obtain Gpio object Input Pin update.
+ /// </summary>
+ public class PinUpdatedEventArgs : EventArgs
+ {
+ internal PinUpdatedEventArgs(int pinNumber, GpioPinValue pinValue)
+ {
+ PinNumber = pinNumber;
+ PinValue = pinValue;
+ }
+
+ /// <summary>
+ /// Gets the Input Pin number which state has changed.
+ /// </summary>
+ public int PinNumber { get; }
+
+ /// <summary>
+ /// Gets the current state of the Input Pin.
+ /// </summary>
+ public GpioPinValue PinValue { get; }
+
+ /// <inheritdoc/>
+ public override string ToString()
+ {
+ return $"Pin number {PinNumber} has changed its value to {PinValue}";
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using NativePwm = Interop.Peripheral.Pwm;
+
+namespace Tizen.Peripheral.Pwm
+{
+ /// <summary>
+ /// Enumeration for PWM polarity.
+ /// </summary>
+ public enum PwmPulsePolarity
+ {
+ /// <summary>
+ /// PWM signal start in the active high state.
+ /// </summary>
+ ActiveHigh = 0,
+
+ /// <summary>
+ /// PWM signal start in the active low state.
+ /// </summary>
+ ActiveLow
+ }
+
+ /// <summary>
+ /// The class allows applications to use the platform PWM peripheral.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
+ public class Pwm : IDisposable
+ {
+
+ //TODO provide default values.
+ private uint _period;
+ private uint _dutyCycle;
+ private PwmPulsePolarity _polarity;
+ private bool _enabled;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Native handle to PWM.
+ /// </summary>
+ private IntPtr _handle;
+
+ /// <summary>
+ /// Opens the PWM pin.
+ /// </summary>
+ /// <param name="chip">The PWM chip number.</param>
+ /// <param name="pin">The PWM pin (channel) number to control.</param>
+ public Pwm(int chip, int pin)
+ {
+ var ret = NativePwm.Open(chip, pin, out IntPtr handle);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _handle = handle;
+ }
+
+ /// <summary>
+ /// Closes the PWM pin.
+ /// </summary>
+ ~Pwm()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Closes the PWM pin.
+ /// </summary>
+ public void Close() => Dispose();
+
+ /// <summary>
+ /// Disposes the PWM.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Disposes the PWM.
+ /// </summary>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ NativePwm.Close(_handle);
+ _disposed = true;
+ }
+
+ /// <summary>
+ /// Sets or gets period of the PWM pin.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public uint Period
+ {
+ get => _period;
+ set
+ {
+ var ret = NativePwm.SetPeriod(_handle, value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _period = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets duty cycle of the PWM pin.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public uint DutyCycle
+ {
+ get => _dutyCycle;
+ set
+ {
+ var ret = NativePwm.SetDutyCycle(_handle, value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _dutyCycle = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets polarity of the PWM pin.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public PwmPulsePolarity Polarity
+ {
+ get => _polarity;
+ set
+ {
+ var ret = NativePwm.SetPolarity(_handle, (NativePwm.Polarity)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _polarity = value;
+ }
+ }
+
+ /// <summary>
+ /// Enables or disables the PWM pin.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public bool Enabled
+ {
+ get => _enabled;
+ set
+ {
+ var ret = NativePwm.SetEnabled(_handle, value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _enabled = value;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using NativeSpi = Interop.Peripheral.Spi;
+
+namespace Tizen.Peripheral.Spi
+{
+ /// <summary>
+ /// Enumeration of SPI transfer modes.
+ /// </summary>
+ public enum SpiMode
+ {
+ /// <summary>
+ /// CPOL = 0, CPHa = 0 Mode.
+ /// </summary>
+ Mode0 = 0,
+
+ /// <summary>
+ /// CPOL = 0, CPHa = 1 Mode.
+ /// </summary>
+ Mode1,
+
+ /// <summary>
+ /// CPOL = 1, CPHa = 0 Mode.
+ /// </summary>
+ Mode2,
+
+ /// <summary>
+ /// CPOL = 1, CPHa = 1 Mode.
+ /// </summary>
+ Mode3
+ }
+
+ /// <summary>
+ /// Enumeration of bit orders.
+ /// </summary>
+ /// <remarks>
+ /// Currently only LSB order is supported!
+ /// </remarks>
+ public enum BitOrder
+ {
+ /// <summary>
+ /// Use most siginificant bit first.
+ /// </summary>
+ MSB = 0,
+
+ /// <summary>
+ /// Use least siginificant bit first.
+ /// </summary>
+ LSB
+ }
+
+ /// <summary>
+ /// The class allows applications to communicate via SPI platform's bus.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
+ public class Spi : IDisposable
+ {
+
+ //TODO Provide default values.
+ private SpiMode _transferMode;
+ private BitOrder _bitOrder;
+ private byte _bitsPerWord;
+ private uint _frequency;
+
+ /// <summary>
+ /// Native handle to Spi.
+ /// </summary>
+ private IntPtr _handle;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Opens a SPI slave device.
+ /// </summary>
+ /// <param name="bus">The SPI bus number.</param>
+ /// <param name="chip">The SPI chip select number.</param>
+ public Spi(int bus, int chip)
+ {
+ var ret = NativeSpi.Open(bus, chip, out IntPtr handle);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _handle = handle;
+ }
+
+ /// <summary>
+ /// Closes the SPI slave device.
+ /// </summary>
+ ~Spi()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Closes the SPI slave device.
+ /// </summary>
+ public void Close() => Dispose();
+
+ /// <summary>
+ /// Disposes the Spi.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Disposes the Spi.
+ /// </summary>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ NativeSpi.Close(_handle);
+ _disposed = true;
+ }
+
+ /// <summary>
+ /// Reads the bytes data from the SPI slave device.
+ /// </summary>
+ /// <param name="buffer">The Data buffer.</param>
+ public void Read(byte[] buffer)
+ {
+ var length = Convert.ToUInt32(buffer.Length);
+ var ret = NativeSpi.Read(_handle, buffer, length);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Writes the bytes data to the SPI slave device.
+ /// </summary>
+ /// <param name="data">The data buffer to write.</param>
+ public void Write(byte[] data)
+ {
+ var length = Convert.ToUInt32(data.Length);
+ var ret = NativeSpi.Write(_handle, data, length);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Exchanges the bytes data to the SPI slave device.
+ /// writeBuffer.Length and readBuffer.Length must be equal.
+ /// </summary>
+ /// <param name="writeBuffer">Array containing data to write to the device.</param>
+ /// <param name="readBuffer">Array containing data read from the dievice.</param>
+ public void TransferSequential(byte[] writeBuffer, byte[] readBuffer)
+ {
+ if (writeBuffer.Length != readBuffer.Length)
+ throw new Exception("writeBuffer.Length is not equal to readBuffer.Length");
+
+ var buffersLength = Convert.ToUInt32(writeBuffer.Length);
+
+ var ret = NativeSpi.Transfer(_handle, writeBuffer, readBuffer, buffersLength);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ /// <summary>
+ /// Sets or gets the SPI transfer mode.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public SpiMode Mode
+ {
+ get => _transferMode;
+ set
+ {
+ var ret = NativeSpi.SetMode(_handle, (NativeSpi.Mode)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _transferMode = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets the SPI bit order.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public BitOrder BitOrder
+ {
+ get => _bitOrder;
+ set
+ {
+ var ret = NativeSpi.SetBitOrder(_handle, (NativeSpi.BitOrder)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _bitOrder = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets the number of bits per word.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public byte BitsPerWord
+ {
+ get => _bitsPerWord;
+ set
+ {
+ var ret = NativeSpi.SetBitsPerWord(_handle, value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _bitsPerWord = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets the frequency of the SPI bus.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public uint ClockFrequency
+ {
+ get => _frequency;
+ set
+ {
+ var ret = NativeSpi.SetFrequency(_handle, value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _frequency = value;
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using NativeUart = Interop.Peripheral.Uart;
+
+namespace Tizen.Peripheral.Uart
+{
+ /// <summary>
+ /// Enumeration for baud rate.
+ /// </summary>
+ public enum BaudRate
+ {
+ /// <summary>The number of signal in one second is 0.</summary>
+ Rate0 = 0,
+
+ /// <summary>The number of signal in one second is 50.</summary>
+ Rate50,
+
+ /// <summary>The number of signal in one second is 75.</summary>
+ Rate75,
+
+ /// <summary>The number of signal in one second is 110.</summary>
+ Rate110,
+
+ /// <summary>The number of signal in one second is 134.</summary>
+ Rate134,
+
+ /// <summary>The number of signal in one second is 150.</summary>
+ Rate150,
+
+ /// <summary>The number of signal in one second is 200.</summary>
+ Rate200,
+
+ /// <summary>The number of signal in one second is 300.</summary>
+ Rate300,
+
+ /// <summary>The number of signal in one second is 600.</summary>
+ Rate600,
+
+ /// <summary>The number of signal in one second is 1200.</summary>
+ Rate1200,
+
+ /// <summary>The number of signal in one second is 1800.</summary>
+ Rate1800,
+
+ /// <summary>The number of signal in one second is 2400.</summary>
+ Rate2400,
+
+ /// <summary>The number of signal in one second is 4800.</summary>
+ Rate4800,
+
+ /// <summary>The number of signal in one second is 9600.</summary>
+ Rate9600,
+
+ /// <summary>The number of signal in one second is 19200.</summary>
+ Rate19200,
+
+ /// <summary>The number of signal in one second is 38400.</summary>
+ Rate38400,
+
+ /// <summary>The number of signal in one second is 57600.</summary>
+ Rate57600,
+
+ /// <summary>The number of signal in one second is 115200.</summary>
+ Rate115200,
+
+ /// <summary>The number of signal in one second is 230400.</summary>
+ Rate230400
+ }
+
+ /// <summary>
+ /// Enumeration for byte size.
+ /// </summary>
+ public enum DataBits
+ {
+ /// <summary>5 data bits.</summary>
+ Size5Bit = 0,
+
+ /// <summary>6 data bits.</summary>
+ Size6Bit,
+
+ /// <summary>7 data bits.</summary>
+ Size7Bit,
+
+ /// <summary>8 data bits.</summary>
+ Size8Bit
+ }
+
+ /// <summary>
+ /// Enumeration for parity bit.
+ /// </summary>
+ public enum Parity
+ {
+ /// <summary>No parity is used.</summary>
+ None = 0,
+
+ /// <summary>Even parity is used.</summary>
+ Even,
+
+ /// <summary>Odd parity is used.</summary>
+ Odd
+ }
+
+ /// <summary>
+ /// Enumeration for stop bits.
+ /// </summary>
+ public enum StopBits
+ {
+ /// <summary>One stop bit.</summary>
+ One = 0,
+
+ /// <summary>Two stop bits.</summary>
+ Two
+ }
+
+ /// <summary>
+ /// Enumeration for hardware flow control.
+ /// </summary>
+ public enum HardwareFlowControl
+ {
+ /// <summary>No hardware flow control.</summary>
+ None = 0,
+
+ /// <summary>Automatic RTS/CTS hardware flow control.</summary>
+ AutoRtsCts
+ }
+
+ /// <summary>
+ /// Enumeration for software flow control.
+ /// </summary>
+ public enum SoftwareFlowControl
+ {
+ /// <summary>No software flow control.</summary>
+ None = 0,
+
+ /// <summary>XON/XOFF software flow control.</summary>
+ XonXoff,
+ }
+
+ /// <summary>
+ /// The class allows applications to communicate via UART platform's bus.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/peripheralio</privilege>
+ public class Uart : IDisposable
+ {
+ private BaudRate _baudRate;
+ private DataBits _dataBits;
+ private Parity _parity;
+ private StopBits _stopBits;
+ private HardwareFlowControl _hardwareFlowControl;
+ private SoftwareFlowControl _softwareFlowControl;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Native handle to I2c.
+ /// </summary>
+ private IntPtr _handle;
+
+ /// <summary>
+ /// Opens the UART slave device.
+ /// </summary>
+ /// <param name="port">The UART port number that the slave device is connected.</param>
+ public Uart(int port)
+ {
+ var ret = NativeUart.Open(port, out IntPtr handle);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _handle = handle;
+ }
+
+ /// <summary>
+ /// Closes the UART slave device.
+ /// </summary>
+ ~Uart()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Closes the UART slave device.
+ /// </summary>
+ public void Close() => Dispose();
+
+ /// <summary>
+ /// Disposes Uart object.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Disposes Uart object.
+ /// </summary>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ NativeUart.Close(_handle);
+ _disposed = true;
+ }
+
+ /// <summary>
+ /// Reads the bytes data from the UART slave device.
+ /// </summary>
+ /// <param name="buffer">The output byte array.</param>
+ /// <param name="offset">The offset in buffer at which to write the bytes.</param>
+ /// <param name="count">The number of bytes to read.</param>
+ /// <returns>The number of bytes read.</returns>
+ public int Read(byte[] buffer, int offset, int count)
+ {
+ if (count > buffer.Length - offset)
+ throw new Exception("Can not read more bytes than the buffer can hold.");
+ byte[] tmpBuffer = new byte[count];
+ var length = Convert.ToUInt32(count);
+ var ret = NativeUart.Read(_handle, tmpBuffer, length);
+ if (ret < Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ Array.Copy(tmpBuffer, 0, buffer, offset, (int)ret);
+ return (int)ret;
+ }
+
+ /// <summary>
+ /// Writes the bytes data to the UART slave device.
+ /// </summary>
+ /// <param name="buffer">The byte array that contains the data to write to the device.</param>
+ /// <param name="offset">The offset in buffer at which to begin copying bytes.</param>
+ /// <param name="count">The number of bytes to write</param>
+ public int Write(byte[] buffer, int offset, int count)
+ {
+ if (count > buffer.Length - offset)
+ throw new Exception("Can not write more bytes than the buffer holds.");
+ byte[] tmpBuffer = new byte[count];
+ Array.Copy(buffer, offset, tmpBuffer, 0, count);
+ var length = Convert.ToUInt32(count);
+ var ret = NativeUart.Write(_handle, tmpBuffer, length);
+ if (ret < Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+ return (int)ret;
+ }
+
+ /// <summary>
+ /// Sets or gets baud rate of the UART slave device.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public BaudRate BaudRate
+ {
+ get => _baudRate;
+ set
+ {
+ var ret = NativeUart.SetBaudRate(_handle, (NativeUart.BaudRate)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _baudRate = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets byte size of the UART slave device.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public DataBits DataBits
+ {
+ get => _dataBits;
+ set
+ {
+ var ret = NativeUart.SetByteSize(_handle, (NativeUart.ByteSize)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _dataBits = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets parity bit of the UART slave device.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public Parity Parity
+ {
+ get => _parity;
+ set
+ {
+ var ret = NativeUart.SetParity(_handle, (NativeUart.Parity)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _parity = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets stop bits of the UART slave device.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public StopBits StopBits
+ {
+ get => _stopBits;
+ set
+ {
+ var ret = NativeUart.SetStopBits(_handle, (NativeUart.StopBits)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _stopBits = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets hardware flow control of the UART slave device.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public HardwareFlowControl HardwareFlowControl
+ {
+ get => _hardwareFlowControl;
+ set
+ {
+ var ret = NativeUart.SetFlowControl(_handle, (NativeUart.SoftwareFlowControl)_softwareFlowControl, (NativeUart.HardwareFlowControl)value);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _hardwareFlowControl = value;
+ }
+ }
+
+ /// <summary>
+ /// Sets or gets software flow control of the UART slave device.
+ /// </summary>
+ /// <remarks>Get value is initialized after successful Set call.</remarks>
+ public SoftwareFlowControl SoftwareFlowControl
+ {
+ get => _softwareFlowControl;
+ set
+ {
+ var ret = NativeUart.SetFlowControl(_handle, (NativeUart.SoftwareFlowControl)value, (NativeUart.HardwareFlowControl)_hardwareFlowControl);
+ if (ret != Internals.Errors.ErrorCode.None)
+ throw ExceptionFactory.CreateException(ret);
+
+ _softwareFlowControl = value;
+ }
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tizen.NUI
+{
+ internal static partial class Interop
+ {
+ internal static partial class VertexBuffer
+ {
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_SWIGUpcast")]
+ public static extern global::System.IntPtr VertexBuffer_SWIGUpcast(global::System.IntPtr jarg1);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_New")]
+ public static extern global::System.IntPtr VertexBuffer_New(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_VertexBuffer__SWIG_0")]
+ public static extern global::System.IntPtr new_VertexBuffer__SWIG_0();
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_VertexBuffer")]
+ public static extern void delete_VertexBuffer(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_VertexBuffer__SWIG_1")]
+ public static extern global::System.IntPtr new_VertexBuffer__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_DownCast")]
+ public static extern global::System.IntPtr VertexBuffer_DownCast(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_Assign")]
+ public static extern global::System.IntPtr VertexBuffer_Assign(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_SetData")]
+ public static extern void VertexBuffer_SetData(global::System.Runtime.InteropServices.HandleRef jarg1, System.IntPtr jarg2, uint jarg3);
+
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VertexBuffer_GetSize")]
+ public static extern uint VertexBuffer_GetSize(global::System.Runtime.InteropServices.HandleRef jarg1);
+ }
+ }
+}
\ No newline at end of file
}
/// <summary>
+ /// Adds a VertexBuffer to be used as source of geometry vertices.
+ /// </summary>
+ /// <param name="vertexBuffer">VertexBuffer to be used as source of geometry vertices.</param>
+ /// <returns>Index of the newly added buffer.</returns>
+ /// <since_tizen> 8 </since_tizen>
+ public uint AddVertexBuffer(VertexBuffer vertexBuffer)
+ {
+ uint ret = Interop.Geometry.Geometry_AddVertexBuffer(swigCPtr, VertexBuffer.getCPtr(vertexBuffer));
+ if (NDalicPINVOKE.SWIGPendingException.Pending)
+ throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
+
+ /// <summary>
/// Retrieves the number of vertex buffers that have been added to this geometry.
/// </summary>
/// <returns>Number of vertex buffers that have been added to this geometry.</returns>
Interop.Geometry.delete_Geometry(swigCPtr);
}
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * Copyright(c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+
+namespace Tizen.NUI
+{
+ /// <summary>
+ /// VertexBuffer is a handle to an object that contains a buffer of structured data.<br />
+ /// VertexBuffers can be used to provide data to Geometry objects.
+ /// </summary>
+ /// <since_tizen> 8 </since_tizen>
+ public class VertexBuffer : BaseHandle
+ {
+
+ /// <summary>
+ /// Creates a VertexBuffer.
+ /// </summary>
+ /// <param name="bufferFormat">The map of names and types that describes the components of the buffer.</param>
+ /// <since_tizen> 8 </since_tizen>
+ public VertexBuffer(PropertyMap bufferFormat) : this(Interop.VertexBuffer.VertexBuffer_New(PropertyMap.getCPtr(bufferFormat)), true)
+ {
+ if (NDalicPINVOKE.SWIGPendingException.Pending)
+ throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ internal VertexBuffer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VertexBuffer.VertexBuffer_SWIGUpcast(cPtr), cMemoryOwn)
+ {
+ }
+
+ /// <summary>
+ /// Updates the whole buffer information.<br />
+ /// This function expects an array of structures with the same format that was given in the construction.
+ /// </summary>
+ /// <param name="vertices">The vertex data that will be copied to the buffer.</param>
+ /// <since_tizen> 8 </since_tizen>
+
+ public void SetData<VertexType>(VertexType[] vertices) where VertexType : struct
+ {
+ int structSize = Marshal.SizeOf<VertexType>();
+ global::System.IntPtr buffer = Marshal.AllocHGlobal(structSize * vertices.Length);
+
+ for (int i = 0; i < vertices.Length; i++)
+ {
+ Marshal.StructureToPtr(vertices[i], buffer + i * structSize, true);
+ }
+
+ Interop.VertexBuffer.VertexBuffer_SetData(swigCPtr, buffer, (uint)vertices.Length);
+ if (NDalicPINVOKE.SWIGPendingException.Pending)
+ throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ }
+
+ /// <summary>
+ /// Gets the number of elements in the buffer.
+ /// </summary>
+ /// <returns>Number of elements in the buffer.</returns>
+ /// <since_tizen> 8 </since_tizen>
+ public uint GetSize()
+ {
+ uint ret = Interop.VertexBuffer.VertexBuffer_GetSize(swigCPtr);
+ if (NDalicPINVOKE.SWIGPendingException.Pending)
+ throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+ return ret;
+ }
+
+ internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VertexBuffer obj)
+ {
+ return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
+ }
+
+ /// This will not be public opened.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
+ {
+ Interop.VertexBuffer.delete_VertexBuffer(swigCPtr);
+ }
+ }
+}