/*********************************************************************//** * @brief Clear Value for bits that have output direction on GPIO port. * @param[in] portNum Port number value, should be in range from 0 to 4 * @param[in] bitValue Value that contains all bits on GPIO to clear, * in range from 0 to 0xFFFFFFFF. * example: value 0x5 to clear bit 0 and bit 1. * @return None * * Note: * - For all bits that has been set as input direction, this function will * not effect. * - For all remaining bits that are not activated in bitValue (value '0') * will not be effected by this function. **********************************************************************/ void GPIO_ClearValue(uint8_t portNum, uint32_t bitValue) { LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum); if (pGPIO != NULL) { pGPIO->FIOCLR = bitValue; } }
/*********************************************************************//** * @brief Set Value for bits that have output direction on GPIO port. * @param[in] portNum Port number value, should be in range from 0 to 4 * @param[in] bitValue Value that contains all bits on GPIO to set, * in range from 0 to 0xFFFFFFFF. * example: value 0x5 to set bit 0 and bit 1. * @return None * * Note: * - For all bits that has been set as input direction, this function will * not effect. * - For all remaining bits that are not activated in bitValue (value '0') * will not be effected by this function. **********************************************************************/ void GPIO_SetValue(uint8_t portNum, uint32_t bitValue) { GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum); if (pGPIO != NULL) { pGPIO->FIOSET = bitValue; } }
/*********************************************************************//** * @brief Read Current state on port pin that have input direction of GPIO * @param[in] portNum Port number to read value, in range from 0 to 4 * @return Current value of GPIO port. * * Note: Return value contain state of each port pin (bit) on that GPIO regardless * its direction is input or output. **********************************************************************/ uint32_t GPIO_ReadValue(uint8_t portNum) { LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum); if (pGPIO != NULL) { return pGPIO->FIOPIN; } return (0); }
/*********************************************************************//** * @brief Set mask value for bits in FIO port * @param[in] portNum Port number, in range from 0 to 4 * @param[in] bitValue Value that contains all bits in to set, * in range from 0 to 0xFFFFFFFF. * @param[in] maskValue Mask value contains state value for each bit: * - 0: not mask. * - 1: mask. * @return None * * Note: * - All remaining bits that are not activated in bitValue (value '0') * will not be effected by this function. * - After executing this function, in mask register, value '0' on each bit * enables an access to the corresponding physical pin via a read or write access, * while value '1' on bit (masked) that corresponding pin will not be changed * with write access and if read, will not be reflected in the updated pin. **********************************************************************/ void FIO_SetMask(uint8_t portNum, uint32_t bitValue, uint8_t maskValue) { GPIO_TypeDef *pFIO = GPIO_GetPointer(portNum); if(pFIO != NULL) { // Mask if (maskValue){ pFIO->FIOMASK |= bitValue; } // Un-mask else { pFIO->FIOMASK &= ~bitValue; } } }
/*********************************************************************//** * @brief Set Direction for GPIO port. * @param[in] portNum Port Number value, should be in range from 0 to 4 * @param[in] bitValue Value that contains all bits to set direction, * in range from 0 to 0xFFFFFFFF. * example: value 0x5 to set direction for bit 0 and bit 1. * @param[in] dir Direction value, should be: * - 0: Input. * - 1: Output. * @return None * * Note: All remaining bits that are not activated in bitValue (value '0') * will not be effected by this function. **********************************************************************/ void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir) { LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum); if (pGPIO != NULL) { // Enable Output if (dir) { pGPIO->FIODIR |= bitValue; } // Enable Input else { pGPIO->FIODIR &= ~bitValue; } } }