/* ** =================================================================== ** Method : BitsIoLdd4_GetDir (component BitsIO_LDD) ** ** Description : ** Returns the selected direction. ** Parameters : ** NAME - DESCRIPTION ** * DeviceDataPtr - Device data structure ** pointer returned by <Init> method. ** Returns : ** --- - Possible values: ** <false> - Input ** <true> - Output ** =================================================================== */ bool BitsIoLdd4_GetDir(LDD_TDeviceData *DeviceDataPtr) { (void)DeviceDataPtr; /* Parameter is not used, suppress unused argument warning */ /* Return the direction of the bits in the mask */ if ((GPIO_PDD_GetPortDirection(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PIN_ALLOC_0_MASK) != 0U) return (bool)TRUE; else return (bool)FALSE; }
/* ===================================================================*/ bool BitIoLdd4_GetVal(LDD_TDeviceData *DeviceDataPtr) { uint32_t PortData; /* Port data masked according to the bit used */ (void)DeviceDataPtr; /* Parameter is not used, suppress unused argument warning */ if ((GPIO_PDD_GetPortDirection(BitIoLdd4_MODULE_BASE_ADDRESS) & BitIoLdd4_PORT_MASK) == 0U) { /* Port is configured as input */ PortData = GPIO_PDD_GetPortDataInput(BitIoLdd4_MODULE_BASE_ADDRESS) & BitIoLdd4_PORT_MASK; } else { /* Port is configured as output */ PortData = GPIO_PDD_GetPortDataOutput(BitIoLdd4_MODULE_BASE_ADDRESS) & BitIoLdd4_PORT_MASK; } return (PortData != 0U) ? (bool)TRUE : (bool)FALSE; }
/* ** =================================================================== ** Method : BitsIoLdd4_GetVal (component BitsIO_LDD) ** ** Description : ** Returns the value of the Input/Output component. If the ** direction is [input] then reads the input value of the pins ** and returns it. If the direction is [output] then returns ** the last written value (see <Safe mode> property for ** limitations). ** Parameters : ** NAME - DESCRIPTION ** * DeviceDataPtr - Device data structure ** pointer returned by <Init> method. ** Returns : ** --- - Input value ** =================================================================== */ dword BitsIoLdd4_GetVal(LDD_TDeviceData *DeviceDataPtr) { dword portData; (void)DeviceDataPtr; /* Parameter is not used, suppress unused argument warning */ if ((GPIO_PDD_GetPortDirection(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PORT_MASK) != 0U) { /* port is configured as output */ portData = GPIO_PDD_GetPortDataOutput(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PORT_MASK; } else { /* port is configured as input */ portData = GPIO_PDD_GetPortDataInput(BitsIoLdd4_MODULE_BASE_ADDRESS) & BitsIoLdd4_PORT_MASK; } return portData >> BitsIoLdd4_PIN_ALLOC_0_INDEX; /* Return port data shifted with the offset of the first allocated pin*/ }
/* ** =================================================================== ** Method : BitsIoLdd4_GetBit (component BitsIO_LDD) ** ** Description : ** Returns the value of the specified bit/pin of the ** Input/Output component. If the direction is [input] then it ** reads the input value of the pin and returns it. If the ** direction is [output] then it returns the last written value ** (see <Safe mode> property for limitations). ** Parameters : ** NAME - DESCRIPTION ** * DeviceDataPtr - Device data structure ** pointer returned by <Init> method. ** Bit - Bit/pin number to read ** * BitVal - The returned value: ** <false> - logical "0" (Low level) ** <true> - logical "1" (High level) ** Returns : ** --- - Error code, possible values: ** ERR_OK - OK ** ERR_PARAM_MASK - Invalid pin index ** ERR_VALUE - Invalid output parameter ** =================================================================== */ LDD_TError BitsIoLdd4_GetBit(LDD_TDeviceData *DeviceDataPtr, byte Bit, bool *BitVal) { uint32_t mask = 0; uint32_t portVal; (void)DeviceDataPtr; /* Parameter is not used, suppress unused argument warning */ /* Bit number value - this test can be disabled by setting the "Ignore range checking" property to the "yes" value in the "Configuration inspector" */ if (Bit > 3U) { return ERR_PARAM_MASK; } /* Bit value returned - this test can be disabled by setting the "Ignore range checking" property to the "yes" value in the "Configuration inspector" */ if (NULL == BitVal) { return ERR_VALUE; } mask = BitsIoLdd4_PIN_MASK_MAP[Bit]; if ((GPIO_PDD_GetPortDirection(BitsIoLdd4_MODULE_BASE_ADDRESS) & mask) != 0U) { /* Port is configured as output */ portVal = GPIO_PDD_GetPortDataOutput(BitsIoLdd4_MODULE_BASE_ADDRESS); } else { /* Port is configured as input */ portVal = GPIO_PDD_GetPortDataInput(BitsIoLdd4_MODULE_BASE_ADDRESS); } if ((portVal & mask) != 0U) { *BitVal = (bool)TRUE; } else { *BitVal = (bool)FALSE; } return ERR_OK; }