text: /*
   * MikroSDK - MikroE Software Development Kit
   * Copyright© 2020 MikroElektronika d.o.o.
   * 
   * Permission is hereby granted, free of charge, to any person 
   * obtaining a copy of this software and associated documentation 
   * files (the "Software"), to deal in the Software without restriction, 
   * including without limitation the rights to use, copy, modify, merge, 
   * publish, distribute, sublicense, and/or sell copies of the Software, 
   * and to permit persons to whom the Software is furnished to do so, 
   * subject to the following conditions:
   * 
   * The above copyright notice and this permission notice shall be 
   * included in all copies or substantial portions of the Software.
   * 
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
   * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
   * OR OTHER DEALINGS IN THE SOFTWARE. 
   */
  
  /*!
   * \file
   *
   * \brief This file contains API for USB UART 3 Click driver.
   *
   * \addtogroup usbuart3 USB UART 3 Click Driver
   * @{
   */
  // ----------------------------------------------------------------------------
  
  #ifndef USBUART3_H
  #define USBUART3_H
  
  #include "drv_digital_out.h"
  #include "drv_digital_in.h"
  #include "drv_uart.h"
  
  // -------------------------------------------------------------- PUBLIC MACROS 
  /**
   * \defgroup macros Macros
   * \{
   */
  
  /**
   * \defgroup map_mikrobus MikroBUS
   * \{
   */
  #define USBUART3_MAP_MIKROBUS( cfg, mikrobus ) \
    cfg.tx_pin  = MIKROBUS( mikrobus, MIKROBUS_TX ); \
    cfg.rx_pin  = MIKROBUS( mikrobus, MIKROBUS_RX ); \
    cfg.sus = MIKROBUS( mikrobus, MIKROBUS_AN ); \
    cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
    cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
    cfg.wup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
    cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
  /** \} */
  
  /**
   * \defgroup error_code Error Code
   * \{
   */
  #define USBUART3_RETVAL  uint8_t
  
  #define USBUART3_OK           0x00
  #define USBUART3_INIT_ERROR   0xFF
  /** \} */
  
  /**
   * \defgroup driver Driver define
   * \{
   */
  #define DRV_RX_BUFFER_SIZE 500
  /** \} */
  
  /** \} */ // End group macro 
  // --------------------------------------------------------------- PUBLIC TYPES
  /**
   * \defgroup type Types
   * \{
   */
  /**
   * @brief Click ctx object definition.
   */
  typedef struct
  {
      // Output pins 
  
      digital_out_t rst;
      digital_out_t cts;
      digital_out_t wup;
  
      // Input pins 
  
      digital_in_t sus;
      digital_in_t rts;
      
      // Modules 
  
      uart_t uart;
  
      char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
      char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
  
  } usbuart3_t;
  
  /**
   * @brief Click configuration structure definition.
   */
  typedef struct
  {
      // Communication gpio pins 
  
      pin_name_t rx_pin;
      pin_name_t tx_pin;
      
      // Additional gpio pins 
  
      pin_name_t sus;
      pin_name_t rst;
      pin_name_t cts;
      pin_name_t wup;
      pin_name_t rts;
  
      // static variable 
  
      uint32_t          baud_rate;     // Clock speed.
      bool              uart_blocking;
      uart_data_bits_t  data_bit;      // Data bits.
      uart_parity_t     parity_bit;    // Parity bit.  
      uart_stop_bits_t  stop_bit;      // Stop bits.    
  
  } usbuart3_cfg_t;
  
  /**
   * @brief Error type 
   */
  typedef uint8_t usbuart3_error_t;
  
  /** \} */ // End types group
  // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
  
  /**
   * \defgroup public_function Public function
   * \{
   */
   
  #ifdef __cplusplus
  extern "C"{
  #endif
  
  /**
   * @brief Config Object Initialization function.
   *
   * @param cfg  Click configuration structure.
   *
   * @description This function initializes click configuration structure to init state.
   * @note All used pins will be set to unconnected state.
   */
  void usbuart3_cfg_setup ( usbuart3_cfg_t *cfg );
  
  /**
   * @brief Initialization function.
   * @param usbuart3 Click object.
   * @param cfg Click configuration structure.
   * 
   * @description This function initializes all necessary pins and peripherals used for this click.
   */
  USBUART3_RETVAL usbuart3_init ( usbuart3_t *ctx, usbuart3_cfg_t *cfg );
  
  /**
   * @brief Generic write function.
   * @param usbuart3 Click object.
   * @param data_buf Data buffer for sends.
   * @param len Number of bytes for sends.
   */
  void usbuart3_generic_write ( usbuart3_t *ctx, char *data_buf, uint16_t len );
  
  /**
   * @brief Generic read function.
   * @param usbuart3 Click object.
   * @param data_buf Data buffer for read data.
   * @param max_len The maximum length of data that can be read.
   * @return Number of reads data.
   */
  int32_t usbuart3_generic_read ( usbuart3_t *ctx, char *data_buf, uint16_t max_len );
  
  /**
   * @brief Function for reset
   *
   * @param ctx          Click object.
   *
   * @description This function is reset
   */
  void usbuart3_reset ( usbuart3_t *ctx );
  
  /**
   * @brief Set device mode
   *
   * @param ctx          Click object.
   *
   * @return SUS (USB suspend) pin state
   */
  uint8_t usbuart3_get_susp ( usbuart3_t *ctx );
  
  
  #ifdef __cplusplus
  }
  #endif
  #endif  // _USBUART3_H_
  
  /** \} */ // End public_function group
  /// \}    // End click Driver group  
  /*! @} */
  // ------------------------------------------------------------------------- END
  