mXT143E Xplained paint demo application
Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <stdio.h>
Macros | |
#define | MAXTOUCH_TWI_ADDRESS 0x4a |
Address of the mXT143E on TWI bus. More... | |
#define | MULTI_COLOR_INCREMENT 4 |
Color increment/decrement amount when in multi-color mode; larger values will cause the colors to cycle faster. More... | |
#define | NUM_PALLET_COLORS (sizeof(pallet_colors) / sizeof(pallet_colors[0])) |
Number of colors in the pallet (computed automatically from number of entries in the pallet_colors[] array) More... | |
#define | PALLET_COLOR_WIDTH (gfx_get_width() / NUM_PALLET_COLORS) |
Width of each color entry in the pallet on the display. More... | |
#define | PALLET_HEIGHT 22 |
Height of the pallet on the display. More... | |
Functions | |
static void | draw_paint_pallet (void) |
Draws the color pallet to the display. More... | |
static void | draw_pallet_labels (const bool clearing_display) |
Draws the special function pallet entry text labels. More... | |
static gfx_color_t | get_next_rainbow_color (void) |
Compute the next rainbow color for multi-color drawing mode. More... | |
int | main (void) |
Main application loop. More... | |
static void | mxt_handler (struct mxt_device *device) |
Handle maXTouch messages. More... | |
static void | mxt_init (struct mxt_device *device) |
Set maXTouch configuration. More... | |
static void | update_pallet_selection (void) |
Updates the color pallet to the display. More... | |
Variables | |
const gfx_color_t | pallet_colors [] |
Color pallet for the application; add or remove colors here to update the pallet in the application. More... | |
uint8_t | selected_pallet_color = 0 |
Pallet index of the currently selected color by the user. More... | |
#define MAXTOUCH_TWI_ADDRESS 0x4a |
Address of the mXT143E on TWI bus.
Referenced by mxt_init().
#define MULTI_COLOR_INCREMENT 4 |
Color increment/decrement amount when in multi-color mode; larger values will cause the colors to cycle faster.
Referenced by get_next_rainbow_color().
#define NUM_PALLET_COLORS (sizeof(pallet_colors) / sizeof(pallet_colors[0])) |
Number of colors in the pallet (computed automatically from number of entries in the pallet_colors[] array)
Referenced by draw_paint_pallet(), draw_pallet_labels(), and mxt_handler().
#define PALLET_COLOR_WIDTH (gfx_get_width() / NUM_PALLET_COLORS) |
Width of each color entry in the pallet on the display.
Referenced by draw_paint_pallet(), draw_pallet_labels(), mxt_handler(), and update_pallet_selection().
#define PALLET_HEIGHT 22 |
Height of the pallet on the display.
Referenced by draw_paint_pallet(), draw_pallet_labels(), main(), mxt_handler(), and update_pallet_selection().
|
static |
Draws the color pallet to the display.
This function draws the paint pallet to the display, including the special function entries (such as display clear) and the selection box.
References draw_pallet_labels(), GFX_COLOR_GRAY, gfx_draw_filled_rect, gfx_draw_horizontal_line, gfx_get_height(), gfx_get_width(), NUM_PALLET_COLORS, PALLET_COLOR_WIDTH, pallet_colors, PALLET_HEIGHT, and update_pallet_selection().
Referenced by main().
|
static |
Draws the special function pallet entry text labels.
This function draws the special function pallet entry text labels to the appropriate positions on the display.
clearing_display | True if the display is currently being cleared |
References GFX_COLOR_RED, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, gfx_draw_string_aligned(), gfx_get_height(), NUM_PALLET_COLORS, PALLET_COLOR_WIDTH, PALLET_HEIGHT, sysfont, TEXT_ALIGN_LEFT, and TEXT_POS_CENTER.
Referenced by draw_paint_pallet(), and mxt_handler().
|
static |
Compute the next rainbow color for multi-color drawing mode.
This function handles the color mixing algorithm needed to produce a sequence of colors in the RGB spectrum. Each time it is called, the next color in the sequence is returned.
References GFX_COLOR, and MULTI_COLOR_INCREMENT.
Referenced by mxt_handler().
int main | ( | void | ) |
Main application loop.
This is the main application function, which runs all the initialization code, clears the display and enters a loop in which it continuously polls for new messages from the maXTouch device. If one or more messages are pending, the maXTouch message handler is invoked.
References board_init(), draw_paint_pallet(), GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, gfx_draw_string_aligned(), gfx_get_height(), gfx_get_width(), gfx_init, mxt_handler(), mxt_init(), mxt_is_message_pending(), PALLET_HEIGHT, sysclk_init(), sysfont, TEXT_ALIGN_LEFT, and TEXT_POS_CENTER.
|
static |
Handle maXTouch messages.
This function handles the maXTouch messages, triggering the drawing of squares around new or moved touches, and removing the squares around released touches.
device | Pointer to mxt_device struct |
References draw_pallet_labels(), get_next_rainbow_color(), GFX_COLOR_BLACK, gfx_draw_filled_circle, gfx_draw_filled_rect, gfx_get_height(), gfx_get_width(), gfx_set_clipping(), GFX_WHOLE, mxt_is_message_pending(), MXT_MOVE_EVENT, MXT_PRESS_EVENT, mxt_read_touch_event(), MXT_RELEASE_EVENT, NUM_PALLET_COLORS, PALLET_COLOR_WIDTH, pallet_colors, PALLET_HEIGHT, selected_pallet_color, mxt_touch_event::size, mxt_touch_event::status, STATUS_OK, update_pallet_selection(), mxt_touch_event::x, and mxt_touch_event::y.
Referenced by main().
|
static |
Set maXTouch configuration.
This function writes a set of predefined, optimal maXTouch configuration data to the mXT143E Xplained.
device | Pointer to mxt_device struct |
References Assert, delay_ms, MAXTOUCH_TWI_ADDRESS, MXT_GEN_ACQUISITIONCONFIG_T8, MXT_GEN_COMMANDPROCESSOR_CALIBRATE, MXT_GEN_COMMANDPROCESSOR_RESET, MXT_GEN_COMMANDPROCESSOR_T6, MXT_GEN_POWERCONFIG_T7, mxt_get_object_address(), mxt_init_device(), MXT_PROCG_TOUCHSUPPRESSION_T48, MXT_RESET_TIME, MXT_TOUCH_MULTITOUCHSCREEN_T9, mxt_write_config_object(), mxt_write_config_reg(), twi_options_t::speed, status, STATUS_OK, twi_master_setup(), and UNUSED.
Referenced by main().
|
static |
Updates the color pallet to the display.
This function should be called whenever a new color is selected on the pallet. It will then move the selection box to the newly chosen color.
References GFX_COLOR_GRAY, gfx_draw_rect, gfx_get_height(), PALLET_COLOR_WIDTH, pallet_colors, PALLET_HEIGHT, and selected_pallet_color.
Referenced by draw_paint_pallet(), and mxt_handler().
const gfx_color_t pallet_colors[] |
Color pallet for the application; add or remove colors here to update the pallet in the application.
Referenced by draw_paint_pallet(), mxt_handler(), and update_pallet_selection().
uint8_t selected_pallet_color = 0 |
Pallet index of the currently selected color by the user.
Referenced by mxt_handler(), and update_pallet_selection().