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

Work on Devices.Gpio #418

Merged
merged 1 commit into from
Aug 9, 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
@@ -1,10 +1,8 @@
//-----------------------------------------------------------------------------
//
// ** DO NOT EDIT THIS FILE! **
// This file was generated by a tool
// re-running the tool will overwrite this file.
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
//-----------------------------------------------------------------------------


#include "windows_devices_gpio_native.h"
Expand Down Expand Up @@ -45,10 +43,7 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeIsDriveModeSupported___BOOLEAN__U1,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeRead___WindowsDevicesGpioGpioPinValue__I4,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeWrite___VOID__I4__U1,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__I4__U1,
NULL,
NULL,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::get_DebounceTimeout___mscorlibSystemTimeSpan,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::set_DebounceTimeout___VOID__mscorlibSystemTimeSpan,
Expand All @@ -57,16 +52,35 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
NULL,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::Read___WindowsDevicesGpioGpioPinValue,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::Write___VOID__WindowsDevicesGpioGpioPinValue,
NULL,
NULL,
NULL,
NULL,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::DisposeNative___VOID,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeIsDriveModeSupported___BOOLEAN__WindowsDevicesGpioGpioPinDriveMode,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeSetDriveMode___VOID__WindowsDevicesGpioGpioPinDriveMode,
Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::NativeInit___BOOLEAN__I4,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};

const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_Windows_Devices_Gpio =
{
"Windows.Devices.Gpio",
0x6F1F070E,
0xE793D87B,
method_lookup
};

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//-----------------------------------------------------------------------------
//
// ** DO NOT EDIT THIS FILE! **
// This file was generated by a tool
// re-running the tool will overwrite this file.
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
//-----------------------------------------------------------------------------


#ifndef _WINDOWS_DEVICES_GPIO_NATIVE_H_
Expand Down Expand Up @@ -64,17 +62,50 @@ struct Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioController

struct Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin
{
static const int FIELD___pinNumber = 1;
static const int FIELD___driveMode = 2;
static const int FIELD___disposedValue = 3;

NANOCLR_NATIVE_DECLARE(NativeIsDriveModeSupported___BOOLEAN__U1);
NANOCLR_NATIVE_DECLARE(NativeRead___WindowsDevicesGpioGpioPinValue__I4);
NANOCLR_NATIVE_DECLARE(NativeWrite___VOID__I4__U1);
NANOCLR_NATIVE_DECLARE(NativeSetDriveMode___VOID__I4__U1);
static const int FIELD_STATIC__s_eventListener = 0;

static const int FIELD___syncLock = 1;
static const int FIELD___pinNumber = 2;
static const int FIELD___driveMode = 3;
static const int FIELD___callbacks = 4;
static const int FIELD___disposedValue = 5;

NANOCLR_NATIVE_DECLARE(get_DebounceTimeout___mscorlibSystemTimeSpan);
NANOCLR_NATIVE_DECLARE(set_DebounceTimeout___VOID__mscorlibSystemTimeSpan);
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);

//--//

};

struct Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPinEvent
{
static const int FIELD__PinNumber = 3;
static const int FIELD__Edge = 4;


//--//

};

struct Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPinEventListener
{
static const int FIELD___pinMap = 1;


//--//

};

struct Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPinValueChangedEventArgs
{
static const int FIELD___edge = 1;


//--//

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
//-----------------------------------------------------------------------------
//
// ** WARNING! **
// This file was generated automatically by a tool.
// Re-running the tool will overwrite this file.
// You should copy this file to a custom location
// before adding any customization in the copy to
// prevent loss of your changes when the tool is
// re-run.
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
//-----------------------------------------------------------------------------


#include "windows_devices_gpio_native.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
//-----------------------------------------------------------------------------
//
// ** WARNING! **
// This file was generated automatically by a tool.
// Re-running the tool will overwrite this file.
// You should copy this file to a custom location
// before adding any customization in the copy to
// prevent loss of your changes when the tool is
// re-run.
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
//-----------------------------------------------------------------------------


#ifndef _WINDOWS_DEVICES_GPIO_NATIVE_WINDOWS_DEVICES_GPIO_GPIOCONTROLLER_H_
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
//-----------------------------------------------------------------------------
//
// ** DO NOT EDIT THIS FILE! **
// This file was generated by a tool
// re-running the tool will overwrite this file.
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
//-----------------------------------------------------------------------------


#include "windows_devices_gpio_native.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
//-----------------------------------------------------------------------------
//
// ** WARNING! **
// This file was generated automatically by a tool.
// Re-running the tool will overwrite this file.
// You should copy this file to a custom location
// before adding any customization in the copy to
// prevent loss of your changes when the tool is
// re-run.
// Copyright (c) 2017 The nanoFramework project contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
//-----------------------------------------------------------------------------


#include <ch.h>
#include <hal.h>
#include <cmsis_os.h>


#include "windows_devices_gpio_native.h"
#include "windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin.h"

///////////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH Windows.Devices.Gpio.GpioPinDriveMode (in managed code) !!! //
///////////////////////////////////////////////////////////////////////////////////////

enum GpioPinDriveMode
{
GpioPinDriveMode_Input = 0,
GpioPinDriveMode_InputPullDown,
GpioPinDriveMode_InputPullUp,
GpioPinDriveMode_Output,
GpioPinDriveMode_OutputOpenDrain,
GpioPinDriveMode_OutputOpenDrainPullUp,
GpioPinDriveMode_OutputOpenSource,
GpioPinDriveMode_OutputOpenSourcePullDown,
};

///////////////////////////////////////////////////////////////////////////////////
// !!! KEEP IN SYNC WITH Windows.Devices.Gpio.GpioPinValue (in managed code) !!! //
///////////////////////////////////////////////////////////////////////////////////

enum GpioPinValue
{
GpioPinValue_Low = 0,
GpioPinValue_High,
};

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////


using namespace Windows::Devices::Gpio;

stm32_gpio_t* gpioPort[] = { GPIOA, GPIOB
Expand Down Expand Up @@ -51,52 +76,121 @@ stm32_gpio_t* gpioPort[] = { GPIOA, GPIOB

#define GPIO_PORT(pin) (gpioPort[pin/16])

bool GpioPin::NativeIsDriveModeSupported( CLR_RT_HeapBlock* pMngObj, unsigned char param0, HRESULT &hr )

void IsrProcedure( GPIO_PIN pin, bool pinState, void* context )
{
return param0 < 5;
// TODO check if we need this here
// ASSERT_IRQ_MUST_BE_OFF();
PostManagedEvent( EVENT_GPIO, 0, pin, pinState );
}

signed int GpioPin::get_DebounceTimeout( CLR_RT_HeapBlock* pMngObj, HRESULT &hr )
{
signed int retVal = 0;
return retVal;
}

void GpioPin::set_DebounceTimeout( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
{
}

signed int GpioPin::Read( CLR_RT_HeapBlock* pMngObj, HRESULT &hr )
{
// check if this pin has been disposed
bool disposed = Interop_Marshal_GetField_bool( pMngObj, (unsigned int)Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue );

if (disposed != 0)
{
// managed object has been disposed
hr = CLR_E_OBJECT_DISPOSED;
return -1;
}

signed int pinNumber = Interop_Marshal_GetField_INT32( pMngObj, (unsigned int)Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___pinNumber );

return palReadPad(GPIO_PORT(pinNumber), pinNumber % 16);
}

void GpioPin::Write( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
{
// check if this pin has been disposed
bool disposed = Interop_Marshal_GetField_bool( pMngObj, Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue );

if (disposed != 0)
{
// managed object has been disposed
hr = CLR_E_OBJECT_DISPOSED;
return;
}

signed int pinNumber = Interop_Marshal_GetField_INT32( pMngObj, Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___pinNumber );

signed int driveMode = Interop_Marshal_GetField_INT32( pMngObj, Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___driveMode );

// sanity check for drive mode to output so we don't mess up with writing to an input pin
// TODO should consider the other output variantions too???
if (driveMode == GpioPinDriveMode_Output)
{
if (param0 == 0)
{
palClearPad(GPIO_PORT(pinNumber), pinNumber % 16);
}
else
{
palSetPad(GPIO_PORT(pinNumber), pinNumber % 16);
}
}
}

signed int GpioPin::NativeRead( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
void GpioPin::DisposeNative( CLR_RT_HeapBlock* pMngObj, HRESULT &hr )
{
return palReadPad(GPIO_PORT(param0), param0 % 16);
}

void GpioPin::NativeWrite( CLR_RT_HeapBlock* pMngObj, signed int param0, unsigned char param1, HRESULT &hr )
bool GpioPin::NativeIsDriveModeSupported( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
{
if (param1 == 0) palClearPad(GPIO_PORT(param0), param0 % 16);
else palSetPad(GPIO_PORT(param0), param0 % 16);
return param0 < 5;
}

void GpioPin::NativeSetDriveMode( CLR_RT_HeapBlock* pMngObj, signed int param0, unsigned char param1, HRESULT &hr )
void GpioPin::NativeSetDriveMode( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
{
switch (param1)
// check if this pin has been disposed
bool disposed = Interop_Marshal_GetField_bool( pMngObj, Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___disposedValue );

if (disposed != 0)
{
case 0 : palSetPadMode(GPIO_PORT(param0), param0 % 16, PAL_MODE_INPUT);
// managed object has been disposed
hr = CLR_E_OBJECT_DISPOSED;
return;
}

signed int pinNumber = Interop_Marshal_GetField_INT32( pMngObj, Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___pinNumber );

switch (param0)
{
case 0 : palSetPadMode(GPIO_PORT(pinNumber), pinNumber % 16, PAL_MODE_INPUT);
break;
case 1 : palSetPadMode(GPIO_PORT(param0), param0 % 16, PAL_MODE_INPUT_PULLDOWN);
case 1 : palSetPadMode(GPIO_PORT(pinNumber), pinNumber % 16, PAL_MODE_INPUT_PULLDOWN);
break;
case 2 : palSetPadMode(GPIO_PORT(param0), param0 % 16, PAL_MODE_INPUT_PULLUP);
case 2 : palSetPadMode(GPIO_PORT(pinNumber), pinNumber % 16, PAL_MODE_INPUT_PULLUP);
break;
case 3 : palSetPadMode(GPIO_PORT(param0), param0 % 16, PAL_MODE_OUTPUT_PUSHPULL);
case 3 : palSetPadMode(GPIO_PORT(pinNumber), pinNumber % 16, PAL_MODE_OUTPUT_PUSHPULL);
break;
case 4 : palSetPadMode(GPIO_PORT(param0), param0 % 16, PAL_MODE_OUTPUT_OPENDRAIN);
case 4 : palSetPadMode(GPIO_PORT(pinNumber), pinNumber % 16, PAL_MODE_OUTPUT_OPENDRAIN);
break;
default : palSetPadMode(GPIO_PORT(param0), param0 % 16, PAL_MODE_INPUT_PULLDOWN);
default : palSetPadMode(GPIO_PORT(pinNumber), pinNumber % 16, PAL_MODE_INPUT_PULLDOWN);
break;
}
}

signed int GpioPin::get_DebounceTimeout( CLR_RT_HeapBlock* pMngObj, HRESULT &hr )
bool GpioPin::NativeInit( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
{
signed int retVal = 0;
return retVal;
}
signed int pinNumber = Interop_Marshal_GetField_INT32( pMngObj, Library_windows_devices_gpio_native_Windows_Devices_Gpio_GpioPin::FIELD___pinNumber );

void GpioPin::set_DebounceTimeout( CLR_RT_HeapBlock* pMngObj, signed int param0, HRESULT &hr )
{
}
// TODO is probably a good idea keep track of the used pins, so we can check that here
// TODO is probably a good idea to check if this pin exists

void GpioPin::DisposeNative( CLR_RT_HeapBlock* pMngObj, HRESULT &hr )
{
}
// TODO initialize the pin INT

// all good
return true;
}
Loading