SAMV71 Xplained Ultra Software Package 1.5

ui.c

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