Microchip® Advanced Software Framework

ui.c File Reference

User Interface.

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

#include <asf.h>
#include <et024006dhu.h>
#include <qt1081.h>
#include "usb_connector.h"
#include "cellphone.h"
#include "ui.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 DISPLAY_FIRST_LINE_X   12
 
#define DISPLAY_FIRST_LINE_Y   22
 
#define DISPLAY_MAX_LINES   12
 Display Values. More...
 
#define DISPLAY_PWM_CHANNEL_ID   AVR32_PWM_ENA_CHID6
 
#define DISPLAY_PWM_FUNCTION   AVR32_PWM_6_FUNCTION
 
#define DISPLAY_PWM_PIN   AVR32_PWM_6_PIN
 
#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...
 
#define LED2_PWM_CHANNEL_ID   AVR32_PWM_ENA_CHID4
 
#define LED2_PWM_FUNCTION   AVR32_PWM_4_0_FUNCTION
 
#define LED2_PWM_PIN   AVR32_PWM_4_0_PIN
 Definitions for PWM Settings. More...
 
#define LED3_PWM_CHANNEL_ID   AVR32_PWM_ENA_CHID5
 
#define LED3_PWM_FUNCTION   AVR32_PWM_5_0_FUNCTION
 
#define LED3_PWM_PIN   AVR32_PWM_5_0_PIN
 

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 tft_bl_init (void)
 Initializes backlight. 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)
 
Main user interface functions
void ui_init (void)
 Initializes the user interface. More...
 
void ui_uhi_aoa_change (uhc_device_t *dev, bool b_plug)
 
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 operation from the Android device. More...
 
static bool ui_aoa_plug = false
 Notify the presence of a USB Android device. More...
 
bool ui_button_state [5]
 Stores the state of the buttons. More...
 
volatile uint8_t ui_button_state_toggle [5]
 Stores if a button needs to be updated. More...
 
COMPILER_WORD_ALIGNED uint8_t ui_msg [64]
 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_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...
 

PWM functions

avr32_pwm_channel_t led2_pwm
 
avr32_pwm_channel_t led3_pwm
 
avr32_pwm_channel_t backlight_strength
 
static void ui_pwm_init (void)
 Initializes the PWM module. More...
 
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

#define is_touch_up()   is_touch_sensor_0()
 
#define is_touch_down()   is_touch_sensor_1()
 
#define is_touch_right()   is_touch_sensor_2()
 
#define is_touch_left()   is_touch_sensor_3()
 
#define is_touch_center()   is_touch_sensor_4()
 
#define BUTTON_INTERRUPT_LEVEL   1
 
eic_options_t eic_options [2]
 Structure holding the configuration parameters of the EIC module. More...
 
static void ui_buttons_enable (void)
 Initializes and enables buttons. More...
 
bool button_changed (uint8_t pbutton)
 Reports if the specified button has changed its state. More...
 
 ISR (touch_button_isr, AVR32_EIC_IRQ_GROUP, BUTTON_INTERRUPT_LEVEL)
 

#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_INTERRUPT_LEVEL   1

Referenced by ui_buttons_enable().

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

Display Values.

Referenced by ui_usb_message_reception().

#define DISPLAY_PWM_CHANNEL_ID   AVR32_PWM_ENA_CHID6
#define DISPLAY_PWM_FUNCTION   AVR32_PWM_6_FUNCTION

Referenced by tft_bl_init().

#define DISPLAY_PWM_PIN   AVR32_PWM_6_PIN

Referenced by tft_bl_init().

#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 is_touch_center ( )    is_touch_sensor_4()

Referenced by ISR().

#define is_touch_down ( )    is_touch_sensor_1()

Referenced by ISR().

#define is_touch_left ( )    is_touch_sensor_3()

Referenced by ISR().

#define is_touch_right ( )    is_touch_sensor_2()

Referenced by ISR().

#define is_touch_up ( )    is_touch_sensor_0()

Referenced by ISR().

#define LED2_PWM_CHANNEL_ID   AVR32_PWM_ENA_CHID4
#define LED2_PWM_FUNCTION   AVR32_PWM_4_0_FUNCTION

Referenced by ui_pwm_led_init().

#define LED2_PWM_PIN   AVR32_PWM_4_0_PIN

Definitions for PWM Settings.

Referenced by ui_pwm_led_init().

#define LED3_PWM_CHANNEL_ID   AVR32_PWM_ENA_CHID5
#define LED3_PWM_FUNCTION   AVR32_PWM_5_0_FUNCTION

Referenced by ui_pwm_led_init().

#define LED3_PWM_PIN   AVR32_PWM_5_0_PIN

Referenced by ui_pwm_led_init().

bool button_changed ( uint8_t  pbutton)

Reports if the specified button has changed its state.

Parameters
pbutton

References ui_button_state_toggle.

Referenced by ui_usb_sof_event().

ISR ( display_rtc_irq  ,
DISPLAY_RTC_IRQ_GROUP  ,
DISPLAY_RTC_IRQ_PRIORITY   
)
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_enable ( void  )
static
static void ui_display_init_rtc ( void  )
static
static void ui_display_welcome_msg ( void  )
static
void ui_init ( void  )
static void ui_pwm_init ( void  )
static

Initializes the PWM module.

References pwm_opt_t::diva, and pwm_init().

Referenced by ui_init().

void ui_pwm_update ( uint8_t  channum,
uint8_t  brightness 
)

updates the specified LED

Parameters
channumNumber of the PWM Channel
brightness0 to 255

References backlight_strength, DISPLAY_PWM_CHANNEL_ID, led2_pwm, LED2_PWM_CHANNEL_ID, led3_pwm, LED3_PWM_CHANNEL_ID, pwm_sync_update_channel(), and PWM_UPDATE_DUTY.

Referenced by tft_bl_init(), and 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_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 LED0, 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.

avr32_pwm_channel_t backlight_strength
Initial value:
= {
.cdty = 255,
.cprd = 255
}

Referenced by tft_bl_init(), and ui_pwm_update().

eic_options_t eic_options[2]

Structure holding the configuration parameters of the EIC module.

avr32_pwm_channel_t led2_pwm
Initial value:
= {
.cdty = 0,
.cprd = 255
}

Referenced by ui_pwm_led_init(), and ui_pwm_update().

avr32_pwm_channel_t led3_pwm
Initial value:
= {
.cdty = 0,
.cprd = 255
}

Referenced by ui_pwm_led_init(), and ui_pwm_update().

uint8_t read_complete_flag

Indicates the status of a read operation from the Android device.

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

bool ui_aoa_plug = false
static

Notify the presence of a USB Android device.

Referenced by ui_uhi_aoa_change().

bool ui_button_state[5]

Stores the state of the buttons.

Referenced by ui_usb_sof_event().

volatile uint8_t ui_button_state_toggle[5]

Stores if a button needs to be updated.

Referenced by button_changed(), ISR(), ui_buttons_enable(), 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[64]

Stores the last message from/to the Android device.

Referenced by ui_usb_message_reception(), and ui_usb_sof_event().