Skip to content

Commit

Permalink
Fix System.Device GpioPin.Read (#1898)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Apr 29, 2021
1 parent 7d63995 commit 900cae7
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,34 @@ HRESULT Library_sys_dev_gpio_native_System_Device_Gpio_GpioPin::Read___SystemDev
CLR_RT_StackFrame &stack)
{
NANOCLR_HEADER();
{
bool pinValue;

CLR_RT_HeapBlock *pThis = stack.This();
FAULT_ON_NULL(pThis);
CLR_RT_TypeDef_Index gpioPinTypeDef;
CLR_RT_HeapBlock *hbObj;
bool pinValue;

if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0)
{
NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED);
}
CLR_RT_HeapBlock &top = stack.PushValue();

NANOCLR_CHECK_HRESULT(Read(pThis, pinValue));
CLR_RT_HeapBlock *pThis = stack.This();
FAULT_ON_NULL(pThis);

stack.SetResult_I4(pinValue);
if (pThis[FIELD___disposedValue].NumericByRef().u1 != 0)
{
NANOCLR_SET_AND_LEAVE(CLR_E_OBJECT_DISPOSED);
}

NANOCLR_CHECK_HRESULT(Read(pThis, pinValue));

// find <GpioPin> type definition, don't bother checking the result as it exists for sure
g_CLR_RT_TypeSystem.FindTypeDef("GpioPin", "System.Device.Gpio", gpioPinTypeDef);

// create an instance of <GpioPin>
NANOCLR_CHECK_HRESULT(g_CLR_RT_ExecutionEngine.NewObjectFromIndex(top, gpioPinTypeDef));

// dereference the object in order to reach its fields
hbObj = top.Dereference();

hbObj[Library_sys_dev_gpio_native_System_Device_Gpio_PinValue::FIELD___value].NumericByRef().u1 = pinValue;

NANOCLR_NOCLEANUP();
}

Expand Down

0 comments on commit 900cae7

Please sign in to comment.