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 |
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 |
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 | |||
) |
References rtc_clear_interrupt(), and ui_display_draw_dot().
ISR | ( | button_rtc_irq | , |
BUTTON_RTC_IRQ_GROUP | , | ||
BUTTON_RTC_IRQ_PRIORITY | |||
) |
References rtc_clear_interrupt(), and ui_buttons_read().
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 and enables the adc.
References adc_configure(), adc_enable(), EXAMPLE_ADC_LIGHT_CHANNEL, EXAMPLE_ADC_LIGHT_FUNCTION, EXAMPLE_ADC_LIGHT_PIN, EXAMPLE_ADC_POTENTIOMETER_CHANNEL, EXAMPLE_ADC_POTENTIOMETER_FUNCTION, EXAMPLE_ADC_POTENTIOMETER_PIN, EXAMPLE_ADC_TEMPERATURE_CHANNEL, EXAMPLE_ADC_TEMPERATURE_FUNCTION, EXAMPLE_ADC_TEMPERATURE_PIN, and gpio_enable_module().
Referenced by ui_init().
void ui_adc_read | ( | void | ) |
Reads the value from the light sensor.
References adc_get_value(), adc_start(), EXAMPLE_ADC_LIGHT_CHANNEL, EXAMPLE_ADC_POTENTIOMETER_CHANNEL, EXAMPLE_ADC_TEMPERATURE_CHANNEL, MESSAGE_ATD_SENSOR_LIGHT, uhi_aoa_write(), and ui_msg.
Referenced by ui_usb_sof_event().
|
static |
Initializes and enables Timer for Buttons.
References BUTTON_RTC_IRQ, BUTTON_RTC_IRQ_PRIORITY, irq_register_handler, rtc_enable(), rtc_enable_interrupt(), rtc_init(), RTC_OSC_32KHZ, and rtc_set_top_value().
Referenced by ui_usb_enum_event().
|
static |
Initializes and enables buttons.
Initializes QT60168 resources: GPIO and SPI.
References gpio_enable_module(), qt60168_init(), QT60168_SPI, QT60168_SPI_BITS, QT60168_SPI_MASTER_SPEED, QT60168_SPI_MISO_FUNCTION, QT60168_SPI_MISO_PIN, QT60168_SPI_MOSI_FUNCTION, QT60168_SPI_MOSI_PIN, QT60168_SPI_NCPS, QT60168_SPI_NPCS0_FUNCTION, QT60168_SPI_NPCS0_PIN, QT60168_SPI_SCK_FUNCTION, QT60168_SPI_SCK_PIN, spi_options_t::reg, spi_enable(), spi_initMaster(), spi_selectionMode(), spi_setupChipReg(), and sysclk_get_cpu_hz().
Referenced by ui_init().
void ui_buttons_read | ( | void | ) |
Reads all buttons from the external Touch chip.
References BUTTON_FOUR, BUTTON_ONE, BUTTON_THREE, BUTTON_TWO, qt60168_is_key_pressed(), QT60168_TOUCH_SENSOR_BUTTON_0, QT60168_TOUCH_SENSOR_BUTTON_1, QT60168_TOUCH_SENSOR_BUTTON_2, QT60168_TOUCH_SENSOR_BUTTON_3, and ui_button_state_changed.
Referenced by ISR().
|
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 BLACK, delay_init, et024006_DrawFilledRect(), ET024006_HEIGHT, et024006_Init(), ET024006_WIDTH, ET024006DHU_BL_PIN, gpio_set_gpio_pin(), sysclk_get_cpu_hz(), sysclk_get_hsb_hz(), 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_32KHZ, RTC_PSEL_32KHZ_1HZ, 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_adc_init(), ui_buttons_enable(), ui_display_enable(), and ui_pwm_led_init().
Referenced by main().
void ui_pwm_led_init | ( | uint8_t | lednum | ) |
Initializes the specified LED.
lednum |
References tc_waveform_opt_t::acpa, tc_waveform_opt_t::acpc, tc_waveform_opt_t::bcpb, tc_waveform_opt_t::bcpc, tc_waveform_opt_t::channel, LED0, LED1, sysclk_enable_peripheral_clock(), TC_CLOCK_SOURCE_TC5, TC_EVT_EFFECT_CLEAR, TC_EVT_EFFECT_NOOP, TC_EVT_EFFECT_SET, tc_init_waveform(), TC_SEL_NO_EDGE, tc_start(), TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, tc_write_ra(), tc_write_rb(), and tc_write_rc().
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 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.
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_button_rtc_init(), 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, et024006_PrintString(), FONT8x16, LED0, LED1, LED2, 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, MESSAGE_ATD_SIMPLE_SWITCH, read_complete(), read_complete_flag, uhi_aoa_read(), uhi_aoa_write(), ui_adc_read(), ui_button_state, ui_button_state_changed, 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.
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().
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().
|
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().