SAMV71 Xplained Ultra Software Package 1.3

ui.c

00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2015, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 /**
00030  * \defgroup UI User Interface
00031  *
00032  * Human interface on SAM V71 Xplained Ultra board.:
00033  * - SAM V71 USART used USART2 on J505 connector
00034  * - Led 0 is continuously on when a device is connected
00035  * - Led 0 blinks when USB host has checked and enabled CDC interface
00036  *   - The blink is slow (1s) with low speed device
00037  *   - The blink is normal (0.5s) with full speed device
00038  *   - The blink is fast (0.25s) with high speed device
00039  * - Led 1 is on during data transfer between CDC and UART
00040  */
00041 #include "board.h"
00042 #include "ui.h"
00043 #include "conf_usb_host.h"
00044 
00045 /**
00046  * \name Main user interface functions
00047  * @{
00048  */
00049 void ui_init(void)
00050 {
00051     /* Initialize LEDs */
00052     LED_Configure( LED_YELLOW0 ) ;
00053     LED_Configure( LED_YELLOW1 ) ;
00054 }
00055 
00056 void ui_usb_mode_change(bool b_host_mode)
00057 {
00058     (void)b_host_mode;
00059     ui_init();
00060 }
00061 /*! @} */
00062 
00063 /**
00064  * \name Host mode user interface functions
00065  * @{
00066  */
00067 
00068 /*! Status of device enumeration */
00069 static USBH_enum_status_t ui_enum_status=UHC_ENUM_DISCONNECT;
00070 /*! Blink frequency depending on device speed */
00071 static uint16_t ui_device_speed_blink;
00072 
00073 void ui_usb_vbus_change(bool b_vbus_present)
00074 {
00075     if (b_vbus_present) {
00076         //LED_On(LED3_GPIO);
00077     } else {
00078         //LED_Off(LED3_GPIO);
00079     }
00080 }
00081 
00082 void ui_usb_vbus_error(void)
00083 {
00084 }
00085 
00086 void ui_usb_connection_event(USBH_device_t *dev, bool b_present)
00087 {
00088     UNUSED(dev);
00089     if (b_present) {
00090         LED_Set(LED_YELLOW0);
00091     } else {
00092         LED_Clear(LED_YELLOW0);
00093         ui_enum_status = UHC_ENUM_DISCONNECT;
00094     }
00095 }
00096 
00097 void ui_usb_enum_event(USBH_device_t *dev, USBH_enum_status_t status)
00098 {
00099     ui_enum_status = status;
00100     switch (dev->speed) {
00101     case UHD_SPEED_HIGH:
00102         ui_device_speed_blink = 250;
00103         break;
00104     case UHD_SPEED_FULL:
00105         ui_device_speed_blink = 500;
00106         break;
00107     case UHD_SPEED_LOW:
00108     default:
00109         ui_device_speed_blink = 1000;
00110         break;
00111     }
00112     if (ui_enum_status == UHC_ENUM_SUCCESS) {
00113         /* USB Device CDC connected
00114            Open and configure UART and USB CDC ports */
00115         CDCLineCoding cfg = {
00116             .dwDTERate   = (115200),
00117             .bCharFormat = CDCLineCoding_ONESTOPBIT,
00118             .bParityType = CDCLineCoding_NOPARITY,
00119             .bDataBits   = 8,
00120         };
00121         TRACE_INFO("USART OPEN");
00122         uart_open();
00123         uart_config(&cfg);
00124         uhi_cdc_open(0, &cfg);
00125     }
00126 }
00127 
00128 void ui_usb_wakeup_event(void)
00129 {
00130 }
00131 
00132 void ui_usb_sof_event(void)
00133 {
00134     static uint16_t counter_sof = 0;
00135 
00136     if (ui_enum_status == UHC_ENUM_SUCCESS) {
00137         /* Display device enumerated and in active mode */
00138         if (++counter_sof > ui_device_speed_blink) {
00139             counter_sof = 0;
00140             LED_Toggle(LED_YELLOW0);
00141         }
00142     }
00143 }
00144 
00145 void ui_com_rx_start(void)
00146 {
00147     LED_Set(LED_YELLOW1);
00148 }
00149 
00150 void ui_com_rx_stop(void)
00151 {
00152     LED_Clear(LED_YELLOW1);
00153 }
00154 
00155 void ui_com_tx_start(void)
00156 {
00157     LED_Set(LED_YELLOW1);
00158 }
00159 
00160 void ui_com_tx_stop(void)
00161 {
00162     LED_Clear(LED_YELLOW1);
00163 }
00164 
00165 void ui_com_error(void)
00166 {
00167 }
00168 
00169 void ui_com_overflow(void)
00170 {
00171 }
00172 
00173 /*! @} */
00174 
00175 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines