Microchip® Advanced Software Framework

ui.c File Reference

User Interface.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include "conf_qt60168.h"
#include <qt60168.h>
#include <et024006dhu.h>
#include "ui.h"
#include "usb_connector.h"
#include "cellphone.h"

Macros

#define AOA_READ_ERROR   0x03
 Read Error. More...
 
#define AOA_READ_ONGOING   0x00
 Read ongoing. More...
 
#define AOA_READ_SUCCESS   0x01
 Read completed successfully. More...
 
#define AOA_READ_TIMEOUT   0x02
 Read timed out. More...
 
#define BUTTON_RTC_IRQ   AVR32_RTC_IRQ
 IRQ line of RTC module is used. More...
 
#define BUTTON_RTC_IRQ_GROUP   AVR32_RTC_IRQ_GROUP
 IRQ group for RTC. More...
 
#define BUTTON_RTC_IRQ_PRIORITY   1
 Interrupt priority 1 is used for RTC in this example. More...
 
#define DISPLAY_FIRST_LINE_X   12
 
#define DISPLAY_FIRST_LINE_Y   22
 
#define DISPLAY_MAX_LINES   12
 Defines for Display. More...
 
#define DISPLAY_RTC_IRQ   AVR32_RTC_IRQ
 IRQ line of RTC module is used. More...
 
#define DISPLAY_RTC_IRQ_GROUP   AVR32_RTC_IRQ_GROUP
 IRQ group for RTC. More...
 
#define DISPLAY_RTC_IRQ_PRIORITY   1
 Interrupt priority 1 is used for RTC in this example. More...
 
Buttons
#define BUTTON_ONE   0x01
 
#define BUTTON_TWO   0x02
 
#define BUTTON_THREE   0x03
 
#define BUTTON_FOUR   0x04
 

Functions

void read_complete (usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered)
 Called when Bulk IN Transfer is finished. More...
 
void ui_usb_message_reception (void)
 Processing of a Message from the Android device. More...
 
Display functions
static void ui_display_enable (void)
 Initializes and enables Display. More...
 
static void ui_display_welcome_msg (void)
 Displays Start Message called when there's no Device plugged in. More...
 
void ui_display_draw_dot (void)
 Creates help animation to plug in the device. More...
 
static void ui_display_init_rtc (void)
 Initializes the RTC used to display the help message. More...
 
static void ui_display_disable_rtc (void)
 Disables the RTC used to display the help message. More...
 
static void ui_display_draw_textbox (void)
 Draws an empty textbox. More...
 
static void ui_display_clr_screen (void)
 Clears the rectangle in which messages from the Android device will be displayed. More...
 
 ISR (display_rtc_irq, DISPLAY_RTC_IRQ_GROUP, DISPLAY_RTC_IRQ_PRIORITY)
 
PWM functions
void ui_pwm_led_init (uint8_t lednum)
 Initializes the specified LED. More...
 
void ui_pwm_update (uint8_t channum, uint8_t brightness)
 updates the specified LED More...
 
Button defines and functions
static void ui_buttons_enable (void)
 Initializes and enables buttons. More...
 
void ui_buttons_read (void)
 Reads all buttons from the external Touch chip. More...
 
static void ui_button_rtc_init (void)
 Initializes and enables Timer for Buttons. More...
 
 ISR (button_rtc_irq, BUTTON_RTC_IRQ_GROUP, BUTTON_RTC_IRQ_PRIORITY)
 
Main user interface functions
void ui_init (void)
 Initializes the user interface. More...
 
void ui_usb_mode_change (bool b_host_mode)
 Notify that the USB mode is switched automatically. This is only possible when the ID pin is available. More...
 

Variables

uint8_t read_complete_flag
 Indicates the status of a read from the Android device. More...
 
static bool ui_aoa_plug = false
 
volatile bool ui_button_state [5]
 Stores the state of the buttons. More...
 
volatile uint8_t ui_button_state_changed
 Stores if a button needs to be updated. More...
 
COMPILER_WORD_ALIGNED uint8_t ui_msg [512]
 Stores the last message from/to the Android device. More...
 

Host mode user interface functions

static uhc_enum_status_t ui_enum_status = UHC_ENUM_DISCONNECT
 Status of device enumeration. More...
 
void ui_usb_vbus_change (bool b_vbus_present)
 Notify that a Vbus is changed Available only in USB hardware with Vbus monitoring. More...
 
void ui_usb_vbus_error (void)
 Notify that a Vbus error has occurred Available only in USB hardware with Vbus monitoring. More...
 
void ui_usb_connection_event (uhc_device_t *dev, bool b_present)
 Notify that a USB device has been connected or disconnected. More...
 
void ui_usb_enum_event (uhc_device_t *dev, uhc_enum_status_t status)
 Notify the end of a USB device enumeration process. More...
 
void ui_uhi_aoa_change (uhc_device_t *dev, bool b_plug)
 
void ui_usb_wakeup_event (void)
 Notify that a USB device or the host woke up the USB line. More...
 
void ui_usb_sof_event (void)
 Notify that a SOF has been sent (each 1 ms) More...
 

ADC channels function

#define EXAMPLE_ADC_TEMPERATURE_CHANNEL   0
 
#define EXAMPLE_ADC_TEMPERATURE_PIN   AVR32_ADC_AD_0_PIN
 
#define EXAMPLE_ADC_TEMPERATURE_FUNCTION   AVR32_ADC_AD_0_FUNCTION
 
#define EXAMPLE_ADC_LIGHT_CHANNEL   2
 
#define EXAMPLE_ADC_LIGHT_PIN   AVR32_ADC_AD_2_PIN
 
#define EXAMPLE_ADC_LIGHT_FUNCTION   AVR32_ADC_AD_2_FUNCTION
 
#define EXAMPLE_ADC_POTENTIOMETER_CHANNEL   1
 
#define EXAMPLE_ADC_POTENTIOMETER_PIN   AVR32_ADC_AD_1_PIN
 
#define EXAMPLE_ADC_POTENTIOMETER_FUNCTION   AVR32_ADC_AD_1_FUNCTION
 
static void ui_adc_init (void)
 Initializes and enables the adc. More...
 
void ui_adc_read (void)
 Reads the value from the light sensor. More...
 

#define AOA_READ_ERROR   0x03

Read Error.

Referenced by read_complete().

#define AOA_READ_ONGOING   0x00

Read ongoing.

Referenced by ui_usb_sof_event().

#define AOA_READ_SUCCESS   0x01

Read completed successfully.

Referenced by read_complete(), and ui_usb_sof_event().

#define AOA_READ_TIMEOUT   0x02

Read timed out.

Referenced by read_complete(), and ui_init().

#define BUTTON_FOUR   0x04

Referenced by ui_buttons_read().

#define BUTTON_ONE   0x01

Referenced by ui_buttons_read().

#define BUTTON_RTC_IRQ   AVR32_RTC_IRQ

IRQ line of RTC module is used.

Referenced by ui_button_rtc_init().

#define BUTTON_RTC_IRQ_GROUP   AVR32_RTC_IRQ_GROUP

IRQ group for RTC.

#define BUTTON_RTC_IRQ_PRIORITY   1

Interrupt priority 1 is used for RTC in this example.

Referenced by ui_button_rtc_init().

#define BUTTON_THREE   0x03

Referenced by ui_buttons_read().

#define BUTTON_TWO   0x02

Referenced by ui_buttons_read().

#define DISPLAY_FIRST_LINE_X   12
#define DISPLAY_FIRST_LINE_Y   22
#define DISPLAY_MAX_LINES   12

Defines for Display.

Referenced by ui_usb_message_reception().

#define DISPLAY_RTC_IRQ   AVR32_RTC_IRQ

IRQ line of RTC module is used.

Referenced by ui_display_init_rtc().

#define DISPLAY_RTC_IRQ_GROUP   AVR32_RTC_IRQ_GROUP

IRQ group for RTC.

#define DISPLAY_RTC_IRQ_PRIORITY   1

Interrupt priority 1 is used for RTC in this example.

Referenced by ui_display_init_rtc().

#define EXAMPLE_ADC_LIGHT_CHANNEL   2

Referenced by ui_adc_init(), and ui_adc_read().

#define EXAMPLE_ADC_LIGHT_FUNCTION   AVR32_ADC_AD_2_FUNCTION

Referenced by ui_adc_init().

#define EXAMPLE_ADC_LIGHT_PIN   AVR32_ADC_AD_2_PIN

Referenced by ui_adc_init().

#define EXAMPLE_ADC_POTENTIOMETER_CHANNEL   1

Referenced by ui_adc_init(), and ui_adc_read().

#define EXAMPLE_ADC_POTENTIOMETER_FUNCTION   AVR32_ADC_AD_1_FUNCTION

Referenced by ui_adc_init().

#define EXAMPLE_ADC_POTENTIOMETER_PIN   AVR32_ADC_AD_1_PIN

Referenced by ui_adc_init().

#define EXAMPLE_ADC_TEMPERATURE_CHANNEL   0

Referenced by ui_adc_init(), and ui_adc_read().

#define EXAMPLE_ADC_TEMPERATURE_FUNCTION   AVR32_ADC_AD_0_FUNCTION

Referenced by ui_adc_init().

#define EXAMPLE_ADC_TEMPERATURE_PIN   AVR32_ADC_AD_0_PIN

Referenced by ui_adc_init().

ISR ( display_rtc_irq  ,
DISPLAY_RTC_IRQ_GROUP  ,
DISPLAY_RTC_IRQ_PRIORITY   
)
ISR ( button_rtc_irq  ,
BUTTON_RTC_IRQ_GROUP  ,
BUTTON_RTC_IRQ_PRIORITY   
)
static void ui_button_rtc_init ( void  )
static
static void ui_display_clr_screen ( void  )
static

Clears the rectangle in which messages from the Android device will be displayed.

References BLACK, DISPLAY_FIRST_LINE_X, DISPLAY_FIRST_LINE_Y, et024006_DrawFilledRect(), ET024006_HEIGHT, and ET024006_WIDTH.

Referenced by ui_usb_message_reception().

static void ui_display_disable_rtc ( void  )
static

Disables the RTC used to display the help message.

References rtc_disable(), and rtc_disable_interrupt().

Referenced by ui_usb_enum_event().

void ui_display_draw_dot ( void  )

Creates help animation to plug in the device.

References BLACK, et024006_DrawFilledRect(), and WHITE.

Referenced by ISR().

static void ui_display_init_rtc ( void  )
static
static void ui_display_welcome_msg ( void  )
static
void ui_init ( void  )
void ui_pwm_update ( uint8_t  channum,
uint8_t  brightness 
)

updates the specified LED

Parameters
channumNumber of the PWM Channel
brightness0 to 255

References gpio_enable_module_pin(), LED0, LED1, LED_Off(), tc_start(), tc_stop(), tc_write_ra(), and tc_write_rb().

Referenced by ui_usb_message_reception().

void ui_uhi_aoa_change ( uhc_device_t *  dev,
bool  b_plug 
)

References ui_aoa_plug.

void ui_usb_connection_event ( uhc_device_t *  dev,
bool  b_present 
)

Notify that a USB device has been connected or disconnected.

Parameters
devPointer on USB device information
b_presenttrue, if the device has been connected

References uhi_aoa_uninstall(), ui_display_init_rtc(), ui_display_welcome_msg(), and ui_enum_status.

void ui_usb_enum_event ( uhc_device_t *  dev,
uhc_enum_status_t  status 
)

Notify the end of a USB device enumeration process.

Parameters
devPointer on USB device information
statusStatus of the USB enumeration

References BLACK, BLUE, et024006_DrawFilledRect(), ET024006_HEIGHT, et024006_PrintString(), ET024006_WIDTH, FONT8x16, ui_button_rtc_init(), ui_display_disable_rtc(), ui_display_draw_textbox(), ui_enum_status, and WHITE.

void ui_usb_mode_change ( bool  b_host_mode)

Notify that the USB mode is switched automatically. This is only possible when the ID pin is available.

Parameters
b_host_modetrue, if the host mode has been selected

References LED3, LED_Off(), and LED_On().

void ui_usb_vbus_change ( bool  b_vbus_present)

Notify that a Vbus is changed Available only in USB hardware with Vbus monitoring.

Parameters
b_vbus_presenttrue, if Vbus is high.
void ui_usb_vbus_error ( void  )

Notify that a Vbus error has occurred Available only in USB hardware with Vbus monitoring.

void ui_usb_wakeup_event ( void  )

Notify that a USB device or the host woke up the USB line.

uint8_t read_complete_flag

Indicates the status of a read from the Android device.

Referenced by read_complete(), ui_init(), and ui_usb_sof_event().

bool ui_aoa_plug = false
static

Referenced by ui_uhi_aoa_change().

volatile bool ui_button_state[5]

Stores the state of the buttons.

Referenced by ui_usb_sof_event().

volatile uint8_t ui_button_state_changed

Stores if a button needs to be updated.

Referenced by ui_buttons_read(), and ui_usb_sof_event().

uhc_enum_status_t ui_enum_status = UHC_ENUM_DISCONNECT
static

Status of device enumeration.

Referenced by ui_usb_connection_event(), ui_usb_enum_event(), and ui_usb_sof_event().

COMPILER_WORD_ALIGNED uint8_t ui_msg[512]

Stores the last message from/to the Android device.

Referenced by ui_adc_read(), ui_usb_message_reception(), and ui_usb_sof_event().