Question: Complete the implementation of the setup and process functions. Download and use this SDK which contains functions that will be used throughout this exercise: https://www.dropbox.com/s/5dgvvu4siezucx9/sdk.zip?dl=0

Complete the implementation of the setup and process functions.

Download and use this SDK which contains functions that will be used throughout this exercise:https://www.dropbox.com/s/5dgvvu4siezucx9/sdk.zip?dl=0

View a demo version to get the idea: https://www.dropbox.com/s/ola1q5wuyxvh030/CrossHairDemo.hex?dl=0

Complete the implementation of the setup and process functions. Download and use

Do not use the following functions: draw_line, show_screen, draw_pixel.

Ensure that drawing is restricted to the pixel bank and columns which intersect the cross hair.

Complete using the following code:

#include

#include

#include

#include

#include

#include

#include "lcd_model.h"

// Helper functions.

void draw_test_pattern(void);

void refresh_bank(int bank);

void refresh_col(int col);

void xor_bank(int bank, uint8_t bit_pattern);

void xor_col(int col, uint8_t bit_pattern);

void setup( void ) {

set_clock_speed(CPU_8MHz);

// (a) Enable input from the Left, Right, Up, and Down switches

// of the joystick.

// (b) Initialise the LCD display using the default contrast setting.

// Do not change the following instruction.

draw_test_pattern();

}

// (c) Declare a pair of global variables of type int called

// cx and cy which will store the horizontal and vertical position

// of the center of the cross hair. Initially place the cross-hair at

// (LCD_X / 2, LCD_Y / 2). AMS uses these variables to set up tests.

void process( void ) {

// variables (cx, cy), calculate the bank (cursor row) in which

// the horizontal stroke of the cross-hair is currently drawn.

// (e) Assuming that the cross-hair is about to move, we must

// restore the parts of the image obscured by the horizontal and

// vertical strokes. Call refresh_bank, passing bank as argument, to

// restore the pixels covered by the horizontal stroke. Call refresh_col

// with cx as argument to restore the pixels covered by the vertical stroke.

// (f) Determine if the Up joystick switch is closed.

// If the switch is closed and the cross-hair is not already

// in the top row of pixels, move it up one pixel.

// (g) OTHERWISE, determine if the Down joystick switch

// is closed. If it is, and the cross-hair is not already in the

// bottom row of pixels, move it down one pixel.

// (h) OTHERWISE, determine if the Left joystick switch

// is closed. If it is, and the cross-hair is not already in the

// left-most row of pixels, move it left one pixel.

// (i) OTHERWISE, determine if the Right joystick switch

// is closed. If it is, and the cross-hair is not already in the

// right-most row of pixels, move it right one pixel.

// (j) Using the formula in Topic 8 lecture notes, and the

// variables (cx, cy), calculate the updated bank (cursor row) in

// which the horizontal stroke of the cross-hair will be drawn and

// the pixel position within the bank that will be covered. Store

// the bank in variable new_bank, and store the pixel position in

// variable pixel_pos.

// (k) Invert the pixels in the display covered by the

// horizontal stroke of the cross-hair. Create an 8-bit mask which has

// zeros at every position except pixel_pos, and a 1 at pixel_pos.

// Call xor_bank to invert the pixels, sending new_bank and the

// bit mask as arguments.

// (l) Invert the pixels in the display covered by the

// vertical stroke of the cross-hair. Create an 8-bit mask which has

// ones at every position. Call xor_col to invert the pixels in column

// cx. The second argument will be an 8-bit mask with a 1 in every

// bit position.

}

// Draw a test pattern to the Teensy.

void draw_test_pattern(void) {

int x0 = LCD_X / 2;

int y0 = LCD_Y / 2;

LCD_CMD(lcd_set_x_addr, 0);

LCD_CMD(lcd_set_y_addr, 0);

for ( int bank = 0; bank

for ( int x = 0; x

uint8_t byte_to_write = 0;

for ( int bit_pos = 0; bit_pos

int y = 8 * bank + bit_pos;

double dx = (x - x0) / 2.0;

double dy = (y - y0);

if ( dx * dx + dy * dy

}

LCD_DATA(byte_to_write);

// Stash a copy in the screen buffer for later.

screen_buffer[bank*LCD_X + x] = byte_to_write;

}

}

}

// Helper function to transfer a bank of pixel data from the screen

// buffer to the LCD.

void refresh_bank(int bank) {

if ( bank = LCD_Y / 8 ) return;

LCD_CMD(lcd_set_x_addr, 0);

LCD_CMD(lcd_set_y_addr, bank);

for ( int col = 0; col

LCD_DATA(screen_buffer[bank * LCD_X + col]);

}

}

// Helper function to transfer a one-pixel wide column of pixel data

// from the screen buffer to the LCD.

void refresh_col(int col) {

if ( col = LCD_X ) return;

LCD_CMD(lcd_set_function, lcd_addr_vertical);

LCD_CMD(lcd_set_x_addr, col);

LCD_CMD(lcd_set_y_addr, 0);

for ( int bank = 0; bank

LCD_DATA(screen_buffer[bank * LCD_X + col]);

}

LCD_CMD(lcd_set_function, lcd_addr_horizontal);

}

// Helper function to XOR a bank of pixel data from the screen

// buffer with a bit pattern and send it to the LCD.

void xor_bank(int bank, uint8_t bit_pattern) {

if ( bank = LCD_Y / 8 ) return;

LCD_CMD(lcd_set_x_addr, 0);

LCD_CMD(lcd_set_y_addr, bank);

for ( int col = 0; col

LCD_DATA(screen_buffer[bank * LCD_X + col] ^ bit_pattern);

}

}

// Helper function to transfer a one-pixel wide column of pixel data

// from the screen buffer to the LCD.

void xor_col(int col, uint8_t bit_pattern) {

if ( col = LCD_X ) return;

LCD_CMD(lcd_set_function, lcd_addr_vertical);

LCD_CMD(lcd_set_x_addr, col);

LCD_CMD(lcd_set_y_addr, 0);

for ( int bank = 0; bank

LCD_DATA(screen_buffer[bank * LCD_X + col] ^ bit_pattern);

}

LCD_CMD(lcd_set_function, lcd_addr_horizontal);

}

int main(void) {

setup();

for ( ;; ) {

process();

_delay_ms(33);

}

return 0;

}

In this exercise you will implement a movable cross-hair (reticle) which is displayed directly to the Teensy LCD. The reticle moves independently over an image displayed in the screen buffer, and has no effect on the contents of the screen buffer Briefly, the programming task is as follows: In setup: Set your Teensy up to receive input from the four directions supported by the joystick Turn on the LCD display using the default contrast level o Call a helper function to display a test pattern Global variabls A pair of integer variables are used to track the location of the aiming point of the reticle In process: o We assume that the reticle is visible, so it alters the appearance of the underlying image. The first thing to do is to restore the affected parts of the image. This is done by calling two helper methods, refresh_bank and refresh_col, which copy pixel data from the screen buffer to the display. If any of the four joystick direction switches is closed, the aiming point should move, provided it does not leave the visible area of the display. The move is recorded by updating the global position variables. After the move, the reticle must be combined with pxels obtained from the screen buffer to update the view. This 1s done by calling helper methods xor bank and xor_col o complete the program, follow the instructions detailed in the in-line comments in the skeleton code below. Notes It is OK to assume that the LCD has been restored to the basic instruction set before your process function is called. This is the normal behaviour of lcd_init. In this exercise you will implement a movable cross-hair (reticle) which is displayed directly to the Teensy LCD. The reticle moves independently over an image displayed in the screen buffer, and has no effect on the contents of the screen buffer Briefly, the programming task is as follows: In setup: Set your Teensy up to receive input from the four directions supported by the joystick Turn on the LCD display using the default contrast level o Call a helper function to display a test pattern Global variabls A pair of integer variables are used to track the location of the aiming point of the reticle In process: o We assume that the reticle is visible, so it alters the appearance of the underlying image. The first thing to do is to restore the affected parts of the image. This is done by calling two helper methods, refresh_bank and refresh_col, which copy pixel data from the screen buffer to the display. If any of the four joystick direction switches is closed, the aiming point should move, provided it does not leave the visible area of the display. The move is recorded by updating the global position variables. After the move, the reticle must be combined with pxels obtained from the screen buffer to update the view. This 1s done by calling helper methods xor bank and xor_col o complete the program, follow the instructions detailed in the in-line comments in the skeleton code below. Notes It is OK to assume that the LCD has been restored to the basic instruction set before your process function is called. This is the normal behaviour of lcd_init

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!