/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/

/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   Device Printer Class                                                */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define UX_SOURCE_CODE


/* Include necessary system files.  */

#include "ux_api.h"
#include "ux_device_class_printer.h"
#include "ux_device_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_device_class_printer_soft_reset                 PORTABLE C      */
/*                                                           6.2.0        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function Perform Soft Reset on the Printer class.              */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    printer                               Address of printer class      */
/*                                            instance                    */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _ux_device_stack_transfer_all_request_abort                         */
/*                                          Abort transfers on endpoint   */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Device Printer Class                                                */
/*                                                                        */
/**************************************************************************/
VOID _ux_device_class_printer_soft_reset(UX_DEVICE_CLASS_PRINTER *printer)
{

UX_SLAVE_ENDPOINT                       *endpoint;

    /* Stop OUT.  */
    endpoint = printer -> ux_device_class_printer_endpoint_out;
    _ux_device_stack_transfer_all_request_abort(endpoint, UX_ENDPOINT_RESET);
#if defined(UX_DEVICE_STANDALONE)
    printer -> ux_device_class_printer_write_state = UX_STATE_RESET;
#endif

    /* Stop IN (optional).  */
    endpoint = printer -> ux_device_class_printer_endpoint_in;
    if (endpoint != UX_NULL)
    {
        _ux_device_stack_transfer_all_request_abort(endpoint, UX_ENDPOINT_RESET);
#if defined(UX_DEVICE_STANDALONE)
        printer -> ux_device_class_printer_read_state = UX_STATE_RESET;
#endif
    }
}
