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 |
Referenced by ui_display_clr_screen(), ui_display_draw_textbox(), and ui_usb_message_reception().
#define DISPLAY_FIRST_LINE_Y 22 |
Referenced by ui_display_clr_screen(), ui_display_draw_textbox(), and ui_usb_message_reception().
#define DISPLAY_MAX_LINES 12 |
Display Values.
Referenced by ui_usb_message_reception().
#define DISPLAY_PWM_CHANNEL_ID AVR32_PWM_ENA_CHID6 |
Referenced by tft_bl_init(), ui_pwm_update(), and ui_usb_message_reception().
#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 |
Referenced by ui_pwm_led_init(), ui_pwm_update(), and ui_usb_message_reception().
#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 |
Referenced by ui_pwm_led_init(), ui_pwm_update(), and ui_usb_message_reception().
#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.
pbutton |
References ui_button_state_toggle.
Referenced by ui_usb_sof_event().
ISR | ( | display_rtc_irq | , |
DISPLAY_RTC_IRQ_GROUP | , | ||
DISPLAY_RTC_IRQ_PRIORITY | |||
) |
References rtc_clear_interrupt(), and ui_display_draw_dot().
ISR | ( | touch_button_isr | , |
AVR32_EIC_IRQ_GROUP | , | ||
BUTTON_INTERRUPT_LEVEL | |||
) |
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.
References AOA_READ_ERROR, AOA_READ_SUCCESS, AOA_READ_TIMEOUT, read_complete_flag, UHD_TRANS_ABORTED, UHD_TRANS_CRC, UHD_TRANS_DISCONNECT, UHD_TRANS_DT_MISMATCH, UHD_TRANS_NOERROR, UHD_TRANS_NOTRESPONDING, UHD_TRANS_PIDFAILURE, UHD_TRANS_STALL, and UHD_TRANS_TIMEOUT.
Referenced by ui_usb_sof_event().
|
static |
Initializes backlight.
References backlight_strength, DISPLAY_PWM_CHANNEL_ID, DISPLAY_PWM_FUNCTION, DISPLAY_PWM_PIN, gpio_enable_module_pin(), pwm_channel_init(), PWM_MODE_LEFT_ALIGNED, PWM_POLARITY_HIGH, pwm_start_channels(), PWM_UPDATE_DUTY, and ui_pwm_update().
Referenced by ui_display_enable().
|
static |
Initializes and enables buttons.
References BUTTON_INTERRUPT_LEVEL, Disable_global_interrupt, eic_options_t::eic_async, eic_options_t::eic_edge, EIC_EDGE_RISING_EDGE, eic_enable_interrupt_lines(), eic_enable_lines(), eic_init(), eic_options_t::eic_line, eic_options_t::eic_mode, EIC_MODE_EDGE_TRIGGERED, EIC_SYNCH_MODE, Enable_global_interrupt, gpio_enable_module_pin(), irq_register_handler, QT1081_EIC_EXTINT_FUNCTION, QT1081_EIC_EXTINT_INT, QT1081_EIC_EXTINT_IRQ, QT1081_EIC_EXTINT_PIN, and ui_button_state_toggle.
Referenced by ui_init().
|
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 |
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 |
Draws an empty textbox.
References BLACK, BLUE, DISPLAY_FIRST_LINE_X, DISPLAY_FIRST_LINE_Y, et024006_DrawFilledRect(), et024006_DrawHorizLine(), et024006_DrawVertLine(), ET024006_HEIGHT, et024006_PrintString(), ET024006_WIDTH, FONT8x16, and WHITE.
Referenced by ui_usb_enum_event().
|
static |
Initializes and enables Display.
References delay_init, et024006_Init(), sysclk_get_cpu_hz(), sysclk_get_hsb_hz(), tft_bl_init(), ui_display_init_rtc(), and ui_display_welcome_msg().
Referenced by ui_init().
|
static |
Initializes the RTC used to display the help message.
References DISPLAY_RTC_IRQ, DISPLAY_RTC_IRQ_PRIORITY, irq_register_handler, rtc_enable(), rtc_enable_interrupt(), rtc_enable_wake_up(), rtc_init(), RTC_OSC_RC, RTC_PSEL_RC_1_76HZ, and rtc_set_top_value().
Referenced by ui_display_enable(), and ui_usb_connection_event().
|
static |
Displays Start Message called when there's no Device plugged in.
References BLUE, et024006_DrawFilledRect(), ET024006_HEIGHT, et024006_PrintString(), et024006_PutPixmap(), ET024006_WIDTH, FONT8x16, pic_cellphone, pic_usb_connector, and WHITE.
Referenced by ui_display_enable(), and ui_usb_connection_event().
void ui_init | ( | void | ) |
Initializes the user interface.
References AOA_READ_TIMEOUT, LED0, LED1, LED2, LED3, LED_Off(), read_complete_flag, ui_buttons_enable(), ui_display_enable(), ui_pwm_init(), and ui_pwm_led_init().
Referenced by main().
|
static |
void ui_pwm_led_init | ( | uint8_t | lednum | ) |
Initializes the specified LED.
lednum |
References gpio_enable_module_pin(), LED1, LED2, led2_pwm, LED2_PWM_CHANNEL_ID, LED2_PWM_FUNCTION, LED2_PWM_PIN, LED3, led3_pwm, LED3_PWM_CHANNEL_ID, LED3_PWM_FUNCTION, LED3_PWM_PIN, pwm_channel_init(), PWM_MODE_LEFT_ALIGNED, PWM_POLARITY_LOW, pwm_start_channels(), and PWM_UPDATE_DUTY.
Referenced by ui_init().
void ui_pwm_update | ( | uint8_t | channum, |
uint8_t | brightness | ||
) |
updates the specified LED
channum | Number of the PWM Channel |
brightness | 0 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.
dev | Pointer on USB device information |
b_present | true, 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.
dev | Pointer on USB device information |
status | Status 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_message_reception | ( | void | ) |
Processing of a Message from the Android device.
References BLUE, DISPLAY_FIRST_LINE_X, DISPLAY_FIRST_LINE_Y, DISPLAY_MAX_LINES, DISPLAY_PWM_CHANNEL_ID, et024006_PrintString(), FONT8x16, LED1, LED2_PWM_CHANNEL_ID, LED3_PWM_CHANNEL_ID, LED_Off(), LED_On(), MESSAGE_DTA_SIMPLE_DISPLAY_BACKLIGHT, MESSAGE_DTA_SIMPLE_LED, MESSAGE_DTA_STRING_BASIC, ui_display_clr_screen(), ui_msg, and ui_pwm_update().
Referenced by ui_usb_sof_event().
void ui_usb_mode_change | ( | bool | b_host_mode | ) |
void ui_usb_sof_event | ( | void | ) |
Notify that a SOF has been sent (each 1 ms)
References AOA_READ_ONGOING, AOA_READ_SUCCESS, button_changed(), MESSAGE_ATD_SIMPLE_SWITCH, read_complete(), read_complete_flag, uhi_aoa_read(), uhi_aoa_write(), ui_button_state, ui_button_state_toggle, ui_enum_status, ui_msg, and ui_usb_message_reception().
void ui_usb_vbus_change | ( | bool | b_vbus_present | ) |
Notify that a Vbus is changed Available only in USB hardware with Vbus monitoring.
b_vbus_present | true, 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 |
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 |
Referenced by ui_pwm_led_init(), and ui_pwm_update().
avr32_pwm_channel_t led3_pwm |
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().
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().
|
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().