⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmic_connectivity.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    return rc;
}


/*!
 * Explicitly complete the USB OTG Host Negotiation Protocol (HNP) process.
 * This just involves disconnecting the pull-up resistor on D+ for the "A"
 * device and turning on the pull-up resistor on D+ for the "B" device.
 *
 * Note that this function should only be called after a suitable time has
 * elapsed after calling pmic_convity_usb_otg_begin_hnp().
 *
 * @param       handle          device handle from open() call
 * @param       deviceType      the USB device type (either A or B)
 *
 * @return      PMIC_SUCCESS    if the HNP was successfully ended
 */
PMIC_STATUS PmicConvityUsbOtgEndHnp(
    const PMIC_CONVITY_HANDLE          handle,
    const PMIC_CONVITY_USB_DEVICE_TYPE deviceType)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.usbOtgType = deviceType;
 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_ENDHNP, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}


/*!
 * Set the USB On-The-Go (OTG) configuration.
 *
 * @param       handle          device handle from open() call
 * @param       cfg             desired USB OTG configuration
 *
 * @return      PMIC_SUCCESS    if the OTG configuration was successfully set
 */
PMIC_STATUS PmicConvityUsbOtgSetConfig(
    const PMIC_CONVITY_HANDLE         handle,
    const PMIC_CONVITY_USB_OTG_CONFIG cfg)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.usbOtgCfg = cfg;
 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_SETCFG, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);

		if (rc == PMIC_SUCCESS)
		{
			if ((cfg & USB_VBUS_CURRENT_LIMIT_HIGH) ||
				(cfg & USB_VBUS_CURRENT_LIMIT_LOW))
			{
				/* Make sure that the VBUS current limit state is
				 * correctly set to either USB_VBUS_CURRENT_LIMIT_HIGH
				 * or USB_VBUS_CURRENT_LIMIT_LOW but never both at the
				 * same time.
				 *
				 * We guarantee this by first clearing both of the
				 * status bits and then resetting the correct one.
				 */
				convity.usbOtgCfg = (PMIC_CONVITY_USB_OTG_CONFIG)
					(convity.usbOtgCfg & (~(USB_VBUS_CURRENT_LIMIT_HIGH |
									   USB_VBUS_CURRENT_LIMIT_LOW)));

			}
			convity.usbOtgCfg = (PMIC_CONVITY_USB_OTG_CONFIG) (convity.usbOtgCfg | cfg);
		}
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Clears the USB On-The-Go (OTG) configuration. Multiple configuration settings
 * may be OR'd together in a single call. However, selecting conflicting
 * settings (e.g., multiple VBUS current limits) will result in undefined
 * behavior.
 *
 * @param[in]   handle          Device handle from open() call.
 * @param[in]   cfg             USB OTG configuration settings to be cleared.
 *
 * @retval      PMIC_SUCCESS         If the OTG configuration was successfully
 *                                   cleared.
 * @retval      PMIC_ERROR           If the handle is invalid.
 * @retval      PMIC_NOT_SUPPORTED   If the desired USB OTG configuration is
 *                                   not supported by the PMIC hardware.
 */
PMIC_STATUS PmicConvityUsbOtgClearConfig(
    const PMIC_CONVITY_HANDLE handle,
    const PMIC_CONVITY_USB_OTG_CONFIG cfg)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.usbOtgCfg = cfg;
 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_CLRCFG, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);

		if (rc == PMIC_SUCCESS)
		{
			convity.usbOtgCfg = (PMIC_CONVITY_USB_OTG_CONFIG)(convity.usbOtgCfg & (~cfg));
		}
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Get the current USB On-The-Go (OTG) configuration.
 *
 * @param       handle          device handle from open() call
 * @param       cfg             the current USB OTG configuration
 *
 * @return      PMIC_SUCCESS    if the OTG configuration was successfully
 *                              retrieved
 */
PMIC_STATUS PmicConvityUsbOtgGetConfig(
    const PMIC_CONVITY_HANDLE          handle,
    PMIC_CONVITY_USB_OTG_CONFIG *const cfg)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)             &&
        (convity.handleState == HANDLE_IN_USE) &&
        (cfg != (PMIC_CONVITY_USB_OTG_CONFIG *)NULL))
    {
        *cfg = convity.usbOtgCfg;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Set the connectivity interface to the selected RS-232 operating
 * configuration. 
 *
 * @param       handle          device handle from open() call
 * @param       cfgInternal     RS-232 transceiver internal connections
 * @param       cfgExternal     RS-232 transceiver external connections
 * @param       txTristated     RS-232 transceiver TX state
 *
 * @return      PMIC_SUCCESS    if the requested mode was set
 */
PMIC_STATUS PmicConvityRs232SetConfig(
    const PMIC_CONVITY_HANDLE         handle,
    const PMIC_CONVITY_RS232_INTERNAL cfgInternal,
    const PMIC_CONVITY_RS232_EXTERNAL cfgExternal,
	const BOOL                        txTristated)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = OP_RS232_SET_CFG;
		param.PARAMS.RS232_CFG.cfgInternal = cfgInternal;
		param.PARAMS.RS232_CFG.cfgExternal = cfgExternal;
		param.PARAMS.RS232_CFG.txTristated = txTristated;

 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_RS232_OP, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);

		if (rc == PMIC_SUCCESS)
		{
			convity.rs232CfgInternal = cfgInternal;
			convity.rs232CfgExternal = cfgExternal;
			convity.rs232TxTristated = txTristated;
		}
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Get the connectivity interface's current RS-232 operating configuration.
 *
 * @param       handle          device handle from open() call
 * @param       cfgInternal     RS-232 transceiver internal connections
 * @param       cfgExternal     RS-232 transceiver external connections
 * @param       txTristated     RS-232 transceiver TX state
 *
 * @return      PMIC_SUCCESS    if the requested mode was retrieved
 */
PMIC_STATUS PmicConvityRs232GetConfig(
    const PMIC_CONVITY_HANDLE          handle,
    PMIC_CONVITY_RS232_INTERNAL *const cfgInternal,
    PMIC_CONVITY_RS232_EXTERNAL *const cfgExternal,
	BOOL                        *const txTristated)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)                           &&
        (convity.handleState == HANDLE_IN_USE)               &&
        (cfgInternal != (PMIC_CONVITY_RS232_INTERNAL *)NULL) &&
        (cfgExternal != (PMIC_CONVITY_RS232_EXTERNAL *)NULL) &&
		(txTristated != (BOOL *)NULL))
    {
        *cfgInternal = convity.rs232CfgInternal;
        *cfgExternal = convity.rs232CfgExternal;
		*txTristated = convity.rs232TxTristated;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}


/*!
 * Set-up the circuitry helping in accessory type identification.
 *
 * @param       handle          device handle from open() call.
 * @param       cfg             detection related circuitry set-up, bit-wise OR allowed.
 *
 * @return      PMIC_SUCCESS    if the requested set-up was done successfully.
 */
PMIC_STATUS PmicConvityCea936SetDetectionConfig(
	const PMIC_CONVITY_HANDLE                   handle, 
	const PMIC_CONVITY_CEA936_DETECTION_CONFIG  cfg)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = OP_CEA936_SET_DETECT;
		param.PARAMS.cea936DetectCfg = cfg;

 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_CEA936_OP, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);

		if (rc == PMIC_SUCCESS)
		{
			convity.cea936DetectCfg = cfg;
		}
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Get the current set-up of circuitry helping in accessory type identification.
 *
 * @param       handle          device handle from open() call
 * @param       cfg             detection related circuitry set-up, bit-wise OR allowed.
 *
 * @return      PMIC_SUCCESS    if the circuitry set-up was successfully
 *                              retrieved
 */
PMIC_STATUS PmicConvityCea936GetDetectionConfig(
	const PMIC_CONVITY_HANDLE                   handle,
	PMIC_CONVITY_CEA936_DETECTION_CONFIG *const cfg)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)                           &&
        (convity.handleState == HANDLE_IN_USE)               &&
        (cfg != (PMIC_CONVITY_CEA936_DETECTION_CONFIG *)NULL))
    {
        *cfg = convity.cea936DetectCfg;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}


/*!
 * Signal the attached device to exit the current CEA-936 operating mode.
 * Returns an error if the current operating mode is not CEA-936.
 *
 * @param       handle          device handle from open() call
 * @param       signal          type of exit signal to be sent
 *
 * @return      PMIC_SUCCESS    if exit signal was sent
 */
PMIC_STATUS PmicConvityCea936ExitSignal(
    const PMIC_CONVITY_HANDLE             handle,
    const PMIC_CONVITY_CEA936_EXIT_SIGNAL signal)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE) &&
		((convity.mode == CEA936_MONO) || (convity.mode == CEA936_STEREO) || 
		(convity.mode == CEA936_TEST_RIGHT) || (convity.mode == CEA936_TEST_LEFT)))
    {
		param.op = OP_CEA936_EXIT;
		param.PARAMS.cea936ExitSignal = signal;

 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_CEA936_OP, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -