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  * - Led 0 is continuously on when a device is connected
00034  * - Led 0 blinks when the device is enumerated and USB in idle mode
00035  *   - The blink is slow (1s) with low speed device
00036  *   - The blink is normal (0.5s) with full speed device
00037  *   - The blink is fast (0.25s) with high speed device
00038  * - Led 1 is on when a read or write access is on going
00039  * - Led 1 is on when a LUN test is success
00040  * - Led 1 blinks when a LUN test is unsuccess
00041  */
00042 
00043 #include "board.h"
00044 #include "ui.h"
00045 #include "ctrl_access.h"
00046 #include "uhi_msc_mem.h"
00047 
00048 /* Wakeup pin is RIGHT CLICK (fast wakeup 14) */
00049 #define  RESUME_PMC_FSTT (PMC_FSMR_FSTT14)
00050 #define  RESUME_PIN      (GPIO_PUSH_BUTTON_2)
00051 #define  RESUME_PIO      (PIN_PUSHBUTTON_2_PIO)
00052 #define  RESUME_PIO_ID   (PIN_PUSHBUTTON_2_ID)
00053 #define  RESUME_PIO_MASK (PIN_PUSHBUTTON_2_MASK)
00054 #define  RESUME_PIO_ATTR (PIN_PUSHBUTTON_2_ATTR)
00055 
00056 
00057 static void ui_disable_asynchronous_interrupt(void);
00058 
00059 /**
00060  * \brief Disables interrupt pin change
00061  */
00062 static void ui_disable_asynchronous_interrupt(void)
00063 {
00064     /* Disable interrupt for button pin */
00065     //pio_disable_pin_interrupt(GPIO_PUSH_BUTTON_2);
00066     //pio_get_interrupt_status(PIOB);
00067     /* Enable fastwakeup for button pin */
00068     //pmc_clr_fast_startup_input(PMC_FSMR_FSTT14);
00069 }
00070 
00071 /*! @} */
00072 
00073 /**
00074  * \name Main user interface functions
00075  * @{
00076  */
00077 void ui_init(void)
00078 {
00079     /* Enable PIO clock for button inputs */
00080     //pmc_enable_periph_clk(ID_PIOB);
00081     //pmc_enable_periph_clk(ID_PIOE);
00082     /* Set handler for wakeup */
00083     //pio_handler_set(RESUME_PIO, RESUME_PIO_ID, RESUME_PIO_MASK,
00084     //  RESUME_PIO_ATTR, ui_wakeup_handler);
00085     /* Enable IRQ for button (PIOB) */
00086     //NVIC_EnableIRQ((IRQn_Type)RESUME_PIO_ID);
00087     /* Enable interrupt for button pin */
00088     //pio_get_interrupt_status(RESUME_PIO);
00089     //pio_configure_pin(RESUME_PIN, RESUME_PIO_ATTR);
00090     //pio_enable_pin_interrupt(RESUME_PIN);
00091     /* Enable fastwakeup for button pin */
00092     //pmc_set_fast_startup_input(RESUME_PMC_FSTT);
00093     /* Initialize LEDs */
00094     LED_Configure(LED_YELLOW0);
00095     LED_Clear(LED_YELLOW0);
00096 #if 2 == LED_NUM
00097     LED_Configure(LED_YELLOW1);
00098     LED_Clear(LED_YELLOW1);
00099 #endif
00100 
00101 }
00102 
00103 void ui_usb_mode_change(bool b_host_mode)
00104 {
00105     UNUSED(b_host_mode);
00106     ui_init();
00107 }
00108 
00109 /*! @} */
00110 
00111 /**
00112  * \name Host mode user interface functions
00113  * @{
00114  */
00115 
00116 /*! Status of device enumeration */
00117 static USBH_enum_status_t ui_enum_status = UHC_ENUM_DISCONNECT;
00118 /*! Blink frequency depending on device speed */
00119 static uint16_t ui_device_speed_blink;
00120 /*! Status of the MSC test */
00121 static bool ui_test_done;
00122 /*! Result of the MSC test */
00123 static bool ui_test_result;
00124 
00125 void ui_usb_vbus_change(bool b_vbus_present)
00126 {
00127     b_vbus_present = b_vbus_present;
00128     /*if (b_vbus_present) {
00129         //LED_Set(LED3_GPIO);
00130     } else {
00131         //LED_Clear(LED3_GPIO);
00132     }*/
00133 }
00134 
00135 void ui_usb_vbus_error(void)
00136 {
00137 }
00138 
00139 void ui_usb_connection_event(USBH_device_t *dev, bool b_present)
00140 {
00141     UNUSED(dev);
00142 
00143     if (b_present)
00144         LED_Set(LED_YELLOW0);
00145     else {
00146         LED_Clear(LED_YELLOW0);
00147         ui_enum_status = UHC_ENUM_DISCONNECT;
00148     }
00149 }
00150 
00151 void ui_usb_enum_event(USBH_device_t *dev, USBH_enum_status_t status)
00152 {
00153     UNUSED(dev);
00154     ui_enum_status = status;
00155 
00156     switch (dev->speed) {
00157     case UHD_SPEED_HIGH:
00158         ui_device_speed_blink = 250;
00159         break;
00160 
00161     case UHD_SPEED_FULL:
00162         ui_device_speed_blink = 500;
00163         break;
00164 
00165     case UHD_SPEED_LOW:
00166     default:
00167         ui_device_speed_blink = 1000;
00168         break;
00169     }
00170 
00171     ui_test_done = false;
00172 }
00173 
00174 void ui_usb_wakeup_event(void)
00175 {
00176     ui_disable_asynchronous_interrupt();
00177 }
00178 
00179 void ui_usb_sof_event(void)
00180 {
00181     static uint16_t counter_sof = 0;
00182 
00183     if (ui_enum_status == UHC_ENUM_SUCCESS) {
00184         /* Display device enumerated and in active mode */
00185         if (++counter_sof > ui_device_speed_blink) {
00186             counter_sof = 0;
00187             LED_Toggle(LED_YELLOW0);
00188 
00189             if (ui_test_done && !ui_test_result) {
00190                 /* Test fail then blink led */
00191 #if 2 == LED_NUM
00192                 LED_Toggle(LED_YELLOW1);
00193 #endif
00194             }
00195         }
00196     }
00197 }
00198 
00199 void ui_test_flag_reset(void)
00200 {
00201     ui_test_done = false;
00202     LED_Clear(LED_YELLOW0);
00203 }
00204 
00205 void ui_test_finish(bool b_success)
00206 {
00207     ui_test_done = true;
00208     ui_test_result = b_success;
00209 
00210     if (b_success) {
00211 #if 2 == LED_NUM
00212         LED_Set(LED_YELLOW1);
00213 #endif
00214     }
00215 }
00216 
00217 /*! @} */
00218 
00219 /*! \name Callback to show the MSC read and write access
00220  *  @{ */
00221 void ui_start_read(void)
00222 {
00223 #if 2 == LED_NUM
00224     LED_Set(LED_YELLOW1);
00225 #endif
00226 }
00227 
00228 void ui_stop_read(void)
00229 {
00230 #if 2 == LED_NUM
00231     LED_Clear(LED_YELLOW1);
00232 #endif
00233 }
00234 
00235 void ui_start_write(void)
00236 {
00237 #if 2 == LED_NUM
00238     LED_Set(LED_YELLOW1);
00239 #endif
00240 }
00241 
00242 void ui_stop_write(void)
00243 {
00244 #if 2 == LED_NUM
00245     LED_Clear(LED_YELLOW1);
00246 #endif
00247 }
00248 
00249 /*! @} */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines