Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Devces.Gpio native code for 1.0.0.22 #470

Merged
merged 1 commit into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@

static const CLR_RT_MethodHandler method_lookup[] =
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController::get_PinCount___I4,
NULL,
NULL,
Expand All @@ -53,7 +29,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Write___VOID__WindowsDevicesGpioGpioPinValue,
NULL,
NULL,
NULL,
NULL,
Expand All @@ -63,6 +39,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebounceTimeout___VOID,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue,
NULL,
NULL,
NULL,
Expand All @@ -82,6 +59,6 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio =
{
"Windows.Devices.Gpio",
0x98B43CD1,
0xA7570E44,
method_lookup
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,6 @@
#include <nanoCLR_Checks.h>


struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCount
{
static const int FIELD__Count = 1;
static const int FIELD__RelativeTime = 2;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter
{
static const int FIELD___Polarity = 1;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeReader
{
static const int FIELD___capacity = 1;
static const int FIELD___isOverflowed = 2;
static const int FIELD___isStarted = 3;
static const int FIELD___length = 4;
static const int FIELD___polarity = 5;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeRecord
{
static const int FIELD__Edge = 1;
static const int FIELD__RelativeTime = 2;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController
{
static const int FIELD_STATIC__s_instance = 0;
Expand All @@ -74,15 +32,16 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin
static const int FIELD___driveMode = 3;
static const int FIELD___debounceTimeout = 4;
static const int FIELD___callbacks = 5;
static const int FIELD___disposedValue = 6;
static const int FIELD___lastOutputValue = 6;
static const int FIELD___disposedValue = 7;

NANOCLR_NATIVE_DECLARE(Read___WindowsDevicesGpioGpioPinValue);
NANOCLR_NATIVE_DECLARE(Write___VOID__WindowsDevicesGpioGpioPinValue);
NANOCLR_NATIVE_DECLARE(DisposeNative___VOID);
NANOCLR_NATIVE_DECLARE(NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode);
NANOCLR_NATIVE_DECLARE(NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode);
NANOCLR_NATIVE_DECLARE(NativeInit___BOOLEAN__I4);
NANOCLR_NATIVE_DECLARE(NativeSetDebounceTimeout___VOID);
NANOCLR_NATIVE_DECLARE(WriteNative___VOID__WindowsDevicesGpioGpioPinValue);

//--//

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,47 +166,6 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___Windows
NANOCLR_NOCLEANUP();
}

HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Write___VOID__WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();
{
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);

// check if object has been disposed
if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0)
{
NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED);
}

int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4;
GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[ FIELD___driveMode ].NumericByRefConst().s4;

GpioPinValue state = (GpioPinValue)stack.Arg1().NumericByRef().s4;

// sanity check for drive mode set to output so we don't mess up writing to an input pin
if ((driveMode == GpioPinDriveMode_Output) ||
(driveMode == GpioPinDriveMode_OutputOpenDrain) ||
(driveMode == GpioPinDriveMode_OutputOpenDrainPullUp) ||
(driveMode == GpioPinDriveMode_OutputOpenSource) ||
(driveMode == GpioPinDriveMode_OutputOpenSourcePullDown))
{
if (state == GpioPinValue_Low)
{
palClearPad(GPIO_PORT(pinNumber), pinNumber % 16);
}
else
{
palSetPad(GPIO_PORT(pinNumber), pinNumber % 16);
}
}
else
{
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}
}
NANOCLR_NOCLEANUP();
}

HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();
Expand Down Expand Up @@ -279,6 +238,16 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDrive
// it's better cast this this to the appropriate enum
GpioPinDriveMode driveMode = (GpioPinDriveMode)stack.Arg1().NumericByRef().s4;

// check if drive mode is input
bool driveModeIsInput = false;

if( driveMode == GpioPinDriveMode_Input ||
driveMode == GpioPinDriveMode_InputPullDown ||
driveMode == GpioPinDriveMode_InputPullUp)
{
driveModeIsInput = true;
}

// flag to signal that interrupts need to be setup
bool setupInterrupt = false;

Expand All @@ -289,7 +258,7 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDrive
// the EXT driver can only handle 16 interrupts and each channel can serve only one port
// ex: channel 0 can be triggered by pad 0 on port A, B, C.... but EXCLUSIVELY by ONLY ONE of those
// see MCU programming manual for details (External interrupt/event controller (EXTI))
if(extInterruptsConfiguration.channels[pad].mode != 0 && callbacksRegistered)
if(extInterruptsConfiguration.channels[pad].mode != 0 && callbacksRegistered && driveModeIsInput)
{
// channel for this pad is already taken
// TODO: probably better to have a dedicated exception here, this one is too generic...
Expand Down Expand Up @@ -337,6 +306,12 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDrive
break;
}

// if drive mode is output, read the pad to update the managed field _lastOutputValue
if(!driveModeIsInput)
{
pThis[ FIELD___lastOutputValue ].NumericByRef().s4 = palReadPad(port, pad);
}

if(callbacksRegistered && setupInterrupt)
{
// there are callbacks registered and...
Expand Down Expand Up @@ -385,3 +360,44 @@ HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebou

NANOCLR_NOCLEANUP();
}

HRESULT Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue( CLR_RT_StackFrame& stack )
{
NANOCLR_HEADER();
{
CLR_RT_HeapBlock* pThis = stack.This(); FAULT_ON_NULL(pThis);

// check if object has been disposed
if(pThis[ Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue ].NumericByRef().u1 != 0)
{
NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED);
}

int16_t pinNumber = pThis[ FIELD___pinNumber ].NumericByRefConst().s4;
GpioPinDriveMode driveMode = (GpioPinDriveMode)pThis[ FIELD___driveMode ].NumericByRefConst().s4;

GpioPinValue state = (GpioPinValue)stack.Arg1().NumericByRef().s4;

// sanity check for drive mode set to output so we don't mess up writing to an input pin
if ((driveMode == GpioPinDriveMode_Output) ||
(driveMode == GpioPinDriveMode_OutputOpenDrain) ||
(driveMode == GpioPinDriveMode_OutputOpenDrainPullUp) ||
(driveMode == GpioPinDriveMode_OutputOpenSource) ||
(driveMode == GpioPinDriveMode_OutputOpenSourcePullDown))
{
if (state == GpioPinValue_Low)
{
palClearPad(GPIO_PORT(pinNumber), pinNumber % 16);
}
else
{
palSetPad(GPIO_PORT(pinNumber), pinNumber % 16);
}
}
else
{
NANOCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
}
}
NANOCLR_NOCLEANUP();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@

static const CLR_RT_MethodHandler method_lookup[] =
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController::get_PinCount___I4,
NULL,
NULL,
Expand All @@ -53,7 +29,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::Write___VOID__WindowsDevicesGpioGpioPinValue,
NULL,
NULL,
NULL,
NULL,
Expand All @@ -63,6 +39,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDebounceTimeout___VOID,
Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin::WriteNative___VOID__WindowsDevicesGpioGpioPinValue,
NULL,
NULL,
NULL,
Expand All @@ -82,6 +59,6 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio =
{
"Windows.Devices.Gpio",
0x98B43CD1,
0xA7570E44,
method_lookup
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,6 @@
#include "stdafx.h"


struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCount
{
static const int FIELD__Count = 1;
static const int FIELD__RelativeTime = 2;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeCounter
{
static const int FIELD___Polarity = 1;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeReader
{
static const int FIELD___capacity = 1;
static const int FIELD___isOverflowed = 2;
static const int FIELD___isStarted = 3;
static const int FIELD___length = 4;
static const int FIELD___polarity = 5;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioChangeRecord
{
static const int FIELD__Edge = 1;
static const int FIELD__RelativeTime = 2;


//--//

};

struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioController
{
static const int FIELD_STATIC__s_instance = 0;
Expand All @@ -72,15 +30,16 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPin
static const int FIELD___driveMode = 3;
static const int FIELD___debounceTimeout = 4;
static const int FIELD___callbacks = 5;
static const int FIELD___disposedValue = 6;
static const int FIELD___lastOutputValue = 6;
static const int FIELD___disposedValue = 7;

NANOCLR_NATIVE_DECLARE(Read___WindowsDevicesGpioGpioPinValue);
NANOCLR_NATIVE_DECLARE(Write___VOID__WindowsDevicesGpioGpioPinValue);
NANOCLR_NATIVE_DECLARE(DisposeNative___VOID);
NANOCLR_NATIVE_DECLARE(NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode);
NANOCLR_NATIVE_DECLARE(NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode);
NANOCLR_NATIVE_DECLARE(NativeInit___BOOLEAN__I4);
NANOCLR_NATIVE_DECLARE(NativeSetDebounceTimeout___VOID);
NANOCLR_NATIVE_DECLARE(WriteNative___VOID__WindowsDevicesGpioGpioPinValue);

//--//

Expand Down Expand Up @@ -114,6 +73,7 @@ struct Library_win_dev_gpio_native_Windows_Devices_Gpio_GpioPinValueChangedEvent

};


extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio;

#endif //_WIN_DEV_GPIO_NATIVE_H_
Loading