Post Reply 
monic part 1: connecting the display
06-12-2020, 03:03 AM (This post was last modified: 12-27-2022 12:08 AM by F-73P.)
Post: #1
monic part 1: connecting the display
Next: monic part 2: connecting the keypad

This is the first in a series of threads about the monic calculator.

This thread shows how to connect the display. The instructions have been divided across four messages because the number of images per message is limited to 10.

1) Getting started

The calculator is comprised of the following parts:

i.MX RT1010 Evaluation Kit with Cortex-M7 500 MHz microcontroller ("EVK")
3.5" 320x480 colour display (“display”)
• 4x4 matrix keypad (“keypad”) and 2 push buttons
• Breadboard, 0.1” jumper cables and wire connectors.

Install the MCUXpresso IDE (“IDE”) and i.MX RT1010 SDK on your computer. The IDE is a free Eclipse-based development environment for NXP Cortex-M microcontrollers. See Getting Started with i.MX RT1010 Evaluation Kit for step by step instructions on how to install the IDE and i.MX RT1010 SDK on your computer.

2) Connecting the display

Insert the display into the breadboard and connect it to the EVK using the following connections:

[Image: 49994069373_1ca350b9d1_z.jpg]

[Image: 49994049423_c2e55dd809_z.jpg]

[Image: 49994049738_e690127ce0_z.jpg]

[Image: 49994567036_5410827ca6_z.jpg]

[Image: 49994050513_68cdc540d4_z.jpg]

The C language combines all the power of assembly language with all the ease-of-use of assembly language
Find all posts by this user
Quote this message in a reply
06-12-2020, 03:06 AM (This post was last modified: 06-12-2020 03:14 AM by F-73P.)
Post: #2
RE: monic part 1: connecting the display
3) Writing to the display

Create a new folder on your computer (e.g. “monic”), then open the IDE, select “monic” as your Workspace and press “Launch”:

[Image: 49994593306_b61e1b7b5b_z.jpg]

Close the “Welcome” screen, then select “New project…” in the bottom left hand corner:

[Image: 49994593266_6155cb0e00_z.jpg]

Select the “evkmimxrt1010” board, then press “Next”:

[Image: 49994847237_93afd7f0ec_z.jpg]

Enter the project name in the top left hand corner (e.g. “monic 1.0”) then press “Finish”:

[Image: 49994847052_29609836a2_z.jpg]

[Image: 49994592956_4133302b30_z.jpg]

Delete all of the code in monic 1.0.c and replace it with the following:

Code:

//monic 1.0

//includes

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MIMXRT1011.h"
#include "fsl_debug_console.h"

#include "header/display.h"

//variables

int16_t xCoordinate;
int16_t yCoordinate;
uint16_t fontColour;

int width;
int height;

uint8_t const *fontData;
uint32_t const *fontOffset;

int16_t xCoordinateCursor;
int16_t yCoordinateCursor;

uint8_t size;

extern uint8_t AdafruitClassicData[];

//functions

void initDisp(void);
void setRotation(uint8_t);
void fillScreen(uint16_t);
void printString(char*);

void delay1ms(void);
void delayms(unsigned int);

int main(void) {

#ifdef FIXED_WIDTH_FONT
    fontData = AdafruitClassicData;
    size = 4;
#else
    //fontData = fontVW_1data;           //variable-width font data
    //fontOffset = fontVW_1Offset;
#endif

    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    SysTick->CTRL = 0;                                                         //disable SysTick

    initDisp();
    setRotation(3);
    fillScreen(BLACK);

    fontColour = BLUE;
    xCoordinate = 130;
    yCoordinate = 140;
    printString("monic 1.0");

    while (1) {
    }
}

void delay1ms(void) {
    SysTick->VAL = 0;
    SysTick->CTRL = 5;

    while((SysTick->CTRL & 0x00010000) == 0);

    SysTick->CTRL = 0;
}

void delayms(unsigned int max) {
    unsigned int i;

    SysTick->LOAD = 0x0007A120;                                                //reload value for 1ms

    for (i=0; i<max; i++) delay1ms();
}

Right click the “source” folder (on the left hand side of the screen), select “New->Folder” and enter the folder name “display”, then press “Finish”. Similarly, in the “source” folder create a new folder named “header”:

[Image: 49994846777_b6d5e09727_z.jpg]

Right click the newly created “display” folder, select “New->Source File” and enter the source file name “font5x7.c”, then press “Finish”:

[Image: 49994592726_22937e0beb_z.jpg]

Similarly, create the source files “GLCD.c” and “HX8357D.c” in the “display” folder:

[Image: 49994592626_ce52937b14_z.jpg]

Now right click the “header” folder, select “New->Source File” and enter the header file name “display.h”, then press “Finish”:

[Image: 49994592561_6016b1d566_z.jpg]

We now delete all of the code in each of the files “font5x7.c”, “GLCD.c”, “HX8357D.c” and “display.h” and replace as follows:

Replace the code in “font5x7.c” with:

Code:

//Adafruit "classic" 5x7 font

/*Copyright (c) 2013 Adafruit Industries.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.*/

//includes

#include <stdint.h>

//variables

const uint8_t AdafruitClassicData[] =
{
    0x00, 0x00, 0x00, 0x00, 0x00,  //0
    0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
    0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
    0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
    0x18, 0x3C, 0x7E, 0x3C, 0x18,
    0x1C, 0x57, 0x7D, 0x57, 0x1C,
    0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
    0x00, 0x18, 0x3C, 0x18, 0x00,
    0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
    0x00, 0x18, 0x24, 0x18, 0x00,
    0xFF, 0xE7, 0xDB, 0xE7, 0xFF,  //10
    0x30, 0x48, 0x3A, 0x06, 0x0E,
    0x26, 0x29, 0x79, 0x29, 0x26,
    0x40, 0x7F, 0x05, 0x05, 0x07,
    0x40, 0x7F, 0x05, 0x25, 0x3F,
    0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
    0x7F, 0x3E, 0x1C, 0x1C, 0x08,
    0x08, 0x1C, 0x1C, 0x3E, 0x7F,
    0x14, 0x22, 0x7F, 0x22, 0x14,
    0x5F, 0x5F, 0x00, 0x5F, 0x5F,
    0x06, 0x09, 0x7F, 0x01, 0x7F,  //20
    0x00, 0x66, 0x89, 0x95, 0x6A,
    0x60, 0x60, 0x60, 0x60, 0x60,
    0x94, 0xA2, 0xFF, 0xA2, 0x94,
    0x08, 0x04, 0x7E, 0x04, 0x08,
    0x10, 0x20, 0x7E, 0x20, 0x10,
    0x08, 0x08, 0x2A, 0x1C, 0x08,
    0x08, 0x1C, 0x2A, 0x08, 0x08,
    0x1E, 0x10, 0x10, 0x10, 0x10,
    0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
    0x30, 0x38, 0x3E, 0x38, 0x30,  //30
    0x06, 0x0E, 0x3E, 0x0E, 0x06,
    0x00, 0x00, 0x00, 0x00, 0x00,  //32 - " "
    0x00, 0x00, 0x5F, 0x00, 0x00,  //33 - "!"
    0x00, 0x07, 0x00, 0x07, 0x00,
    0x14, 0x7F, 0x14, 0x7F, 0x14,
    0x24, 0x2A, 0x7F, 0x2A, 0x12,
    0x23, 0x13, 0x08, 0x64, 0x62,
    0x36, 0x49, 0x56, 0x20, 0x50,
    0x00, 0x08, 0x07, 0x03, 0x00,
    0x00, 0x1C, 0x22, 0x41, 0x00,  //40
    0x00, 0x41, 0x22, 0x1C, 0x00,
    0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
    0x08, 0x08, 0x3E, 0x08, 0x08,
    0x00, 0x80, 0x70, 0x30, 0x00,
    0x08, 0x08, 0x08, 0x08, 0x08,
    0x00, 0x00, 0x60, 0x60, 0x00,
    0x20, 0x10, 0x08, 0x04, 0x02,
    0x3E, 0x51, 0x49, 0x45, 0x3E,
    0x00, 0x42, 0x7F, 0x40, 0x00,
    0x72, 0x49, 0x49, 0x49, 0x46,  //50
    0x21, 0x41, 0x49, 0x4D, 0x33,
    0x18, 0x14, 0x12, 0x7F, 0x10,
    0x27, 0x45, 0x45, 0x45, 0x39,
    0x3C, 0x4A, 0x49, 0x49, 0x31,
    0x41, 0x21, 0x11, 0x09, 0x07,
    0x36, 0x49, 0x49, 0x49, 0x36,
    0x46, 0x49, 0x49, 0x29, 0x1E,
    0x00, 0x00, 0x14, 0x00, 0x00,
    0x00, 0x40, 0x34, 0x00, 0x00,
    0x00, 0x08, 0x14, 0x22, 0x41,  //60
    0x14, 0x14, 0x14, 0x14, 0x14,
    0x00, 0x41, 0x22, 0x14, 0x08,
    0x02, 0x01, 0x59, 0x09, 0x06,
    0x3E, 0x41, 0x5D, 0x59, 0x4E,
    0x7C, 0x12, 0x11, 0x12, 0x7C,  //65 - "A"
    0x7F, 0x49, 0x49, 0x49, 0x36,
    0x3E, 0x41, 0x41, 0x41, 0x22,
    0x7F, 0x41, 0x41, 0x41, 0x3E,
    0x7F, 0x49, 0x49, 0x49, 0x41,
    0x7F, 0x09, 0x09, 0x09, 0x01, //70
    0x3E, 0x41, 0x41, 0x51, 0x73,
    0x7F, 0x08, 0x08, 0x08, 0x7F,
    0x00, 0x41, 0x7F, 0x41, 0x00,
    0x20, 0x40, 0x41, 0x3F, 0x01,
    0x7F, 0x08, 0x14, 0x22, 0x41,
    0x7F, 0x40, 0x40, 0x40, 0x40,
    0x7F, 0x02, 0x1C, 0x02, 0x7F,
    0x7F, 0x04, 0x08, 0x10, 0x7F,
    0x3E, 0x41, 0x41, 0x41, 0x3E,
    0x7F, 0x09, 0x09, 0x09, 0x06, //80
    0x3E, 0x41, 0x51, 0x21, 0x5E,
    0x7F, 0x09, 0x19, 0x29, 0x46,
    0x26, 0x49, 0x49, 0x49, 0x32,
    0x03, 0x01, 0x7F, 0x01, 0x03,
    0x3F, 0x40, 0x40, 0x40, 0x3F,
    0x1F, 0x20, 0x40, 0x20, 0x1F,
    0x3F, 0x40, 0x38, 0x40, 0x3F,
    0x63, 0x14, 0x08, 0x14, 0x63,
    0x03, 0x04, 0x78, 0x04, 0x03,
    0x61, 0x59, 0x49, 0x4D, 0x43, //90
    0x00, 0x7F, 0x41, 0x41, 0x41,
    0x02, 0x04, 0x08, 0x10, 0x20,
    0x00, 0x41, 0x41, 0x41, 0x7F,
    0x04, 0x02, 0x01, 0x02, 0x04,
    0x40, 0x40, 0x40, 0x40, 0x40,
    0x00, 0x03, 0x07, 0x08, 0x00,
    0x20, 0x54, 0x54, 0x78, 0x40,
    0x7F, 0x28, 0x44, 0x44, 0x38,
    0x38, 0x44, 0x44, 0x44, 0x28,
    0x38, 0x44, 0x44, 0x28, 0x7F, //100
    0x38, 0x54, 0x54, 0x54, 0x18,
    0x00, 0x08, 0x7E, 0x09, 0x02,
    0x18, 0xA4, 0xA4, 0x9C, 0x78,
    0x7F, 0x08, 0x04, 0x04, 0x78,
    0x00, 0x44, 0x7D, 0x40, 0x00,
    0x20, 0x40, 0x40, 0x3D, 0x00,
    0x7F, 0x10, 0x28, 0x44, 0x00,
    0x00, 0x41, 0x7F, 0x40, 0x00,
    0x7C, 0x04, 0x78, 0x04, 0x78,
    0x7C, 0x08, 0x04, 0x04, 0x78, //110
    0x38, 0x44, 0x44, 0x44, 0x38,
    0xFC, 0x18, 0x24, 0x24, 0x18,
    0x18, 0x24, 0x24, 0x18, 0xFC,
    0x7C, 0x08, 0x04, 0x04, 0x08,
    0x48, 0x54, 0x54, 0x54, 0x24,
    0x04, 0x04, 0x3F, 0x44, 0x24,
    0x3C, 0x40, 0x40, 0x20, 0x7C,
    0x1C, 0x20, 0x40, 0x20, 0x1C,
    0x3C, 0x40, 0x30, 0x40, 0x3C,
    0x44, 0x28, 0x10, 0x28, 0x44, //120
    0x4C, 0x90, 0x90, 0x90, 0x7C,
    0x44, 0x64, 0x54, 0x4C, 0x44,
    0x00, 0x08, 0x36, 0x41, 0x00,
    0x00, 0x00, 0x7F, 0x00, 0x00, //124 "|"
    0x00, 0x41, 0x36, 0x08, 0x00,
    0x02, 0x01, 0x02, 0x04, 0x02,
    0x3C, 0x26, 0x23, 0x26, 0x3C,
    0x1E, 0xA1, 0xA1, 0x61, 0x12,
    0x3A, 0x40, 0x40, 0x20, 0x7A,
    0x38, 0x54, 0x54, 0x55, 0x59,
    0x21, 0x55, 0x55, 0x79, 0x41,
    0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
    0x21, 0x55, 0x54, 0x78, 0x40,
    0x20, 0x54, 0x55, 0x79, 0x40,
    0x0C, 0x1E, 0x52, 0x72, 0x12,
    0x39, 0x55, 0x55, 0x55, 0x59,
    0x39, 0x54, 0x54, 0x54, 0x59,
    0x39, 0x55, 0x54, 0x54, 0x58,
    0x00, 0x00, 0x45, 0x7C, 0x41,
    0x00, 0x02, 0x45, 0x7D, 0x42,
    0x00, 0x01, 0x45, 0x7C, 0x40,
    0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
    0xF0, 0x28, 0x25, 0x28, 0xF0,
    0x7C, 0x54, 0x55, 0x45, 0x00,
    0x20, 0x54, 0x54, 0x7C, 0x54,
    0x7C, 0x0A, 0x09, 0x7F, 0x49,
    0x32, 0x49, 0x49, 0x49, 0x32,
    0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
    0x32, 0x4A, 0x48, 0x48, 0x30,
    0x3A, 0x41, 0x41, 0x21, 0x7A,
    0x3A, 0x42, 0x40, 0x20, 0x78,
    0x00, 0x9D, 0xA0, 0xA0, 0x7D,
    0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
    0x3D, 0x40, 0x40, 0x40, 0x3D,
    0x3C, 0x24, 0xFF, 0x24, 0x24,
    0x48, 0x7E, 0x49, 0x43, 0x66,
    0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
    0xFF, 0x09, 0x29, 0xF6, 0x20,
    0xC0, 0x88, 0x7E, 0x09, 0x03,
    0x20, 0x54, 0x54, 0x79, 0x41,
    0x00, 0x00, 0x44, 0x7D, 0x41,
    0x30, 0x48, 0x48, 0x4A, 0x32,
    0x38, 0x40, 0x40, 0x22, 0x7A,
    0x00, 0x7A, 0x0A, 0x0A, 0x72,
    0x7D, 0x0D, 0x19, 0x31, 0x7D,
    0x26, 0x29, 0x29, 0x2F, 0x28,
    0x26, 0x29, 0x29, 0x29, 0x26,
    0x30, 0x48, 0x4D, 0x40, 0x20,
    0x38, 0x08, 0x08, 0x08, 0x08,
    0x08, 0x08, 0x08, 0x08, 0x38,
    0x2F, 0x10, 0xC8, 0xAC, 0xBA,
    0x2F, 0x10, 0x28, 0x34, 0xFA,
    0x00, 0x00, 0x7B, 0x00, 0x00,
    0x08, 0x14, 0x2A, 0x14, 0x22,
    0x22, 0x14, 0x2A, 0x14, 0x08,
    0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
    0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
    0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
    0x00, 0x00, 0x00, 0xFF, 0x00,
    0x10, 0x10, 0x10, 0xFF, 0x00,
    0x14, 0x14, 0x14, 0xFF, 0x00,
    0x10, 0x10, 0xFF, 0x00, 0xFF,
    0x10, 0x10, 0xF0, 0x10, 0xF0,
    0x14, 0x14, 0x14, 0xFC, 0x00,
    0x14, 0x14, 0xF7, 0x00, 0xFF,
    0x00, 0x00, 0xFF, 0x00, 0xFF,
    0x14, 0x14, 0xF4, 0x04, 0xFC,
    0x14, 0x14, 0x17, 0x10, 0x1F,
    0x10, 0x10, 0x1F, 0x10, 0x1F,
    0x14, 0x14, 0x14, 0x1F, 0x00,
    0x10, 0x10, 0x10, 0xF0, 0x00,
    0x00, 0x00, 0x00, 0x1F, 0x10,
    0x10, 0x10, 0x10, 0x1F, 0x10,
    0x10, 0x10, 0x10, 0xF0, 0x10,
    0x00, 0x00, 0x00, 0xFF, 0x10,
    0x10, 0x10, 0x10, 0x10, 0x10,
    0x10, 0x10, 0x10, 0xFF, 0x10,
    0x00, 0x00, 0x00, 0xFF, 0x14,
    0x00, 0x00, 0xFF, 0x00, 0xFF,
    0x00, 0x00, 0x1F, 0x10, 0x17,
    0x00, 0x00, 0xFC, 0x04, 0xF4,
    0x14, 0x14, 0x17, 0x10, 0x17,
    0x14, 0x14, 0xF4, 0x04, 0xF4,
    0x00, 0x00, 0xFF, 0x00, 0xF7,
    0x14, 0x14, 0x14, 0x14, 0x14,
    0x14, 0x14, 0xF7, 0x00, 0xF7,
    0x14, 0x14, 0x14, 0x17, 0x14,
    0x10, 0x10, 0x1F, 0x10, 0x1F,
    0x14, 0x14, 0x14, 0xF4, 0x14,
    0x10, 0x10, 0xF0, 0x10, 0xF0,
    0x00, 0x00, 0x1F, 0x10, 0x1F,
    0x00, 0x00, 0x00, 0x1F, 0x14,
    0x00, 0x00, 0x00, 0xFC, 0x14,
    0x00, 0x00, 0xF0, 0x10, 0xF0,
    0x10, 0x10, 0xFF, 0x10, 0xFF,
    0x14, 0x14, 0x14, 0xFF, 0x14,
    0x10, 0x10, 0x10, 0x1F, 0x00,
    0x00, 0x00, 0x00, 0xF0, 0x10,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
    0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
    0xFF, 0xFF, 0xFF, 0x00, 0x00,
    0x00, 0x00, 0x00, 0xFF, 0xFF,
    0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
    0x38, 0x44, 0x44, 0x38, 0x44,
    0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
    0x7E, 0x02, 0x02, 0x06, 0x06,
    0x02, 0x7E, 0x02, 0x7E, 0x02,
    0x63, 0x55, 0x49, 0x41, 0x63,
    0x38, 0x44, 0x44, 0x3C, 0x04,
    0x40, 0x7E, 0x20, 0x1E, 0x20,
    0x06, 0x02, 0x7E, 0x02, 0x02,
    0x99, 0xA5, 0xE7, 0xA5, 0x99,
    0x1C, 0x2A, 0x49, 0x2A, 0x1C,
    0x4C, 0x72, 0x01, 0x72, 0x4C,
    0x30, 0x4A, 0x4D, 0x4D, 0x30,
    0x30, 0x48, 0x78, 0x48, 0x30,
    0xBC, 0x62, 0x5A, 0x46, 0x3D,
    0x3E, 0x49, 0x49, 0x49, 0x00,
    0x7E, 0x01, 0x01, 0x01, 0x7E,
    0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
    0x44, 0x44, 0x5F, 0x44, 0x44,
    0x40, 0x51, 0x4A, 0x44, 0x40,
    0x40, 0x44, 0x4A, 0x51, 0x40,
    0x00, 0x00, 0xFF, 0x01, 0x03,
    0xE0, 0x80, 0xFF, 0x00, 0x00,
    0x08, 0x08, 0x6B, 0x6B, 0x08,
    0x36, 0x12, 0x36, 0x24, 0x36,
    0x06, 0x0F, 0x09, 0x0F, 0x06,
    0x00, 0x00, 0x18, 0x18, 0x00,
    0x00, 0x00, 0x10, 0x10, 0x00,
    0x30, 0x40, 0xFF, 0x01, 0x01,
    0x00, 0x1F, 0x01, 0x01, 0x1E,
    0x00, 0x19, 0x1D, 0x17, 0x12,
    0x00, 0x3C, 0x3C, 0x3C, 0x3C,
    0x24, 0x12, 0x24, 0x48, 0x24  // #255 "approx"
};

Replace the code in “GLCD.c” with:

Code:

//Port of Adafruit code to i.MX RT1010

/*Copyright (c) 2013 Adafruit Industries.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.*/

//includes

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>

#include "../header/display.h"

//variables

extern int width;
extern int height;

extern uint8_t const *fontData;
extern uint32_t const *fontOffset;

extern int16_t xCoordinate;
extern int16_t yCoordinate;

extern int16_t xCoordinateCursor;
extern int16_t yCoordinateCursor;

extern uint16_t fontColour;

extern uint8_t size;

//functions

void fillScreen(uint16_t);
void setAddrWindow(int, int, int, int);
void flood(uint16_t, uint32_t);
void drawLine(int16_t, int16_t, int16_t, int16_t, uint16_t);
void drawFastVLine(int16_t, int16_t, int16_t, uint16_t);
void drawFastHLine(int16_t, int16_t, int16_t, uint16_t);
void writeLine(int16_t, int16_t, int16_t, int16_t, uint16_t);
void drawPixel(int16_t, int16_t, uint16_t);
void drawRect(int16_t, int16_t, int16_t, int16_t, uint16_t);
void fillRect(int16_t, int16_t, int16_t, int16_t, uint16_t);
void setLR(void);
void fillCircle(int16_t, int16_t, int16_t, uint16_t);
void fillCircleHelper(int16_t, int16_t, int16_t, uint8_t, int16_t, uint16_t);
void drawCircle(int16_t, int16_t, int16_t, uint16_t);
void drawTriangle(int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t);
uint16_t colour565(uint8_t r, uint8_t g, uint8_t b);
void fillTriangle(int16_t, int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t);
void drawRoundRect(int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t);
void drawCircleHelper(int16_t, int16_t, int16_t, uint8_t, uint16_t);
void fillRoundRect(int16_t, int16_t, int16_t, int16_t, int16_t, uint16_t);

void printCharacter(char);
void printCharacterFW(char);
void printCharacterVW(char);

void printString(char*);
void printStringFW(char*);
void printStringVW(char*);

void printStringRight(char*);
void printStringRightFW(char*);
void printStringRightVW(char*);

void printCharactercmdL(char);
void printCharactercmdLFW(char);
void printCharactercmdLVW(char);

void printStringcmdL(char*);
void printStringcmdLFW(char*);
void printStringcmdLVW(char*);

///////////////////////////////////////////////////////////////////////////////

void fillScreen(uint16_t colour) {
    setAddrWindow(0, 0, width - 1, height - 1);
    flood(colour, (long)TFTWIDTH * (long)TFTHEIGHT);
}

void testLines(uint16_t colour) {
  int           x1, y1, x2, y2,
                w = width,
                h = height;

  fillScreen(BLACK);

  x1 = y1 = 0;
  y2 = h - 1;
  for(x2=0; x2<w; x2+=6) drawLine(x1, y1, x2, y2, colour);
  x2 = w - 1;
  for(y2=0; y2<h; y2+=6) drawLine(x1, y1, x2, y2, colour);

  fillScreen(BLACK);

  x1 = w - 1;
  y1 = 0;
  y2 = h - 1;
  for(x2=0; x2<w; x2+=6) drawLine(x1, y1, x2, y2, colour);
  x2 = 0;
  for(y2=0; y2<h; y2+=6) drawLine(x1, y1, x2, y2, colour);

  fillScreen(BLACK);

  x1 = 0;
  y1 = h - 1;
  y2 = 0;
  for(x2=0; x2<w; x2+=6) drawLine(x1, y1, x2, y2, colour);
  x2 = w - 1;
  for(y2=0; y2<h; y2+=6) drawLine(x1, y1, x2, y2, colour);

  fillScreen(BLACK);

  x1 = w - 1;
  y1 = h - 1;
  y2 = 0;
  for(x2=0; x2<w; x2+=6) drawLine(x1, y1, x2, y2, colour);
  x2 = 0;
  for(y2=0; y2<h; y2+=6) drawLine(x1, y1, x2, y2, colour);
}

void testFastLines(uint16_t colour1, uint16_t colour2) {
  int x, y, w = width, h = height;

  fillScreen(BLACK);
  for(y=0; y<h; y+=5) drawFastHLine(0, y, w, colour1);
  for(x=0; x<w; x+=5) drawFastVLine(x, 0, h, colour2);
}

void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour) {
    if(x0 == x1){
        if(y0 > y1) _swap_int16_t(y0, y1);
        drawFastVLine(x0, y0, y1 - y0 + 1, colour);
    } else if(y0 == y1){
        if(x0 > x1) _swap_int16_t(x0, x1);
        drawFastHLine(x0, y0, x1 - x0 + 1, colour);
    } else {
        writeLine(x0, y0, x1, y1, colour);
    }
}

void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour) {

    int16_t steep = abs(y1 - y0) > abs(x1 - x0);
    if (steep) {
        _swap_int16_t(x0, y0);
        _swap_int16_t(x1, y1);
    }

    if (x0 > x1) {
        _swap_int16_t(x0, x1);
        _swap_int16_t(y0, y1);
    }

    int16_t dx, dy;
    dx = x1 - x0;
    dy = abs(y1 - y0);

    int16_t err = dx / 2;
    int16_t ystep;

    if (y0 < y1) {
        ystep = 1;
    } else {
        ystep = -1;
    }

    for (; x0<=x1; x0++) {
        if (steep) {
            drawPixel(y0, x0, colour);
        } else {
            drawPixel(x0, y0, colour);
        }
        err -= dy;
        if (err < 0) {
            y0 += ystep;
            err += dx;
        }
    }
}

void testRects(uint16_t colour) {
    int n, i, i2, cx = width/2, cy = height/2;

    fillScreen(BLACK);
    n = min(width, height);
    for(i=2; i<n; i+=6) {
        i2 = i/2;
        drawRect(cx-i2, cy-i2, i, i, colour);
    }
}

void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t colour) {
    drawFastHLine(x, y, w, colour);
    drawFastHLine(x, y+h-1, w, colour);
    drawFastVLine(x, y, h, colour);
    drawFastVLine(x+w-1, y, h, colour);
}

void testFilledRects(uint16_t colour1, uint16_t colour2) {
    int n, i, i2, cx = width/2 - 1, cy = height/2 - 1;

    fillScreen(BLACK);
    n = min(width, height);
    for(i=n; i>0; i-=6) {
        i2 = i/2;
        fillRect(cx-i2, cy-i2, i, i, colour1);
        drawRect(cx-i2, cy-i2, i, i, colour2);
    }
}

void fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h, uint16_t fillcolour) {
    int16_t  x2, y2;

    // Initial off-screen clipping
    if( (w <= 0) || (h <= 0) || (x1 >= width) || (y1 >= height) || ((x2 = x1+w-1) < 0) || ((y2  = y1+h-1) < 0)) return;
    if(x1 < 0) {                                                               //Clip left
        w += x1;
        x1 = 0;
    }
    if(y1 < 0) {                                                               //Clip top
        h += y1;
        y1 = 0;
    }
    if(x2 >= width) {                                                          //Clip right
        x2 = width - 1;
        w  = x2 - x1 + 1;
    }
    if(y2 >= height) {                                                         //Clip bottom
        y2 = height - 1;
        h  = y2 - y1 + 1;
    }

    setAddrWindow(x1, y1, x2, y2);
    flood(fillcolour, (uint32_t)w * (uint32_t)h);
    setLR();
}

void testFilledCircles(uint8_t radius, uint16_t colour) {

    int x, y, w = width, h = height, r2 = radius * 2;

    fillScreen(BLACK);

    for(x=radius; x<w; x+=r2) {
        for(y=radius; y<h; y+=r2) {
            fillCircle(x, y, radius, colour);
        }
    }
}

void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t colour) {
    drawFastVLine(x0, y0-r, 2*r+1, colour);
    fillCircleHelper(x0, y0, r, 3, 0, colour);
}

void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t corners, int16_t delta, uint16_t colour) {

    int16_t f = 1 - r;
    int16_t ddF_x = 1;
    int16_t ddF_y = -2 * r;
    int16_t x = 0;
    int16_t y = r;
    int16_t px = x;
    int16_t py = y;

    delta++; // Avoid some +1's in the loop

    while(x < y) {
        if (f >= 0) {
            y--;
            ddF_y += 2;
            f += ddF_y;
        }
        x++;
        ddF_x += 2;
        f += ddF_x;
        // These checks avoid double-drawing certain lines, important
        // for the SSD1306 library which has an INVERT drawing mode.
        if(x < (y + 1)) {
            if(corners & 1) drawFastVLine(x0+x, y0-y, 2*y+delta, colour);
            if(corners & 2) drawFastVLine(x0-x, y0-y, 2*y+delta, colour);
        }
        if(y != py) {
            if(corners & 1) drawFastVLine(x0+py, y0-px, 2*px+delta, colour);
            if(corners & 2) drawFastVLine(x0-py, y0-px, 2*px+delta, colour);
            py = y;
        }
        px = x;
    }
}

void testCircles(uint8_t radius, uint16_t colour) {

    int x, y, r2 = radius * 2, w = width + radius, h = height + radius;

    // Screen is not cleared for this one -- this is
    // intentional and does not affect the reported time.

    for(x=0; x<w; x+=r2) {
        for(y=0; y<h; y+=r2) {
            drawCircle(x, y, radius, colour);
        }
    }
}

void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t colour) {

    int16_t f = 1 - r;
    int16_t ddF_x = 1;
    int16_t ddF_y = -2 * r;
    int16_t x = 0;
    int16_t y = r;

    drawPixel(x0, y0+r, colour);
    drawPixel(x0, y0-r, colour);
    drawPixel(x0+r, y0, colour);
    drawPixel(x0-r, y0, colour);

    while (x<y) {
        if (f >= 0) {
            y--;
            ddF_y += 2;
            f += ddF_y;
        }
        x++;
        ddF_x += 2;
        f += ddF_x;

        drawPixel(x0 + x, y0 + y, colour);
        drawPixel(x0 - x, y0 + y, colour);
        drawPixel(x0 + x, y0 - y, colour);
        drawPixel(x0 - x, y0 - y, colour);
        drawPixel(x0 + y, y0 + x, colour);
        drawPixel(x0 - y, y0 + x, colour);
        drawPixel(x0 + y, y0 - x, colour);
        drawPixel(x0 - y, y0 - x, colour);
    }
}

void testTriangles(void) {

    int n, i, cx = width / 2 - 1, cy = height/ 2 - 1;

    fillScreen(BLACK);
    n = min(cx, cy);
    for(i=0; i<n; i+=5) {
        drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, colour565(0, 0, i));
    }
}

void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t colour) {
    drawLine(x0, y0, x1, y1, colour);
    drawLine(x1, y1, x2, y2, colour);
    drawLine(x2, y2, x0, y0, colour);
}

uint16_t colour565(uint8_t r, uint8_t g, uint8_t b) {
    //return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
    return ((0xF8 - r) << 8);
    //return ((0xF8 - r) << 8) | 0x001F;
}

void testFilledTriangles(void) {

    int i, cx = width / 2 - 1, cy = height / 2 - 1;

    fillScreen(BLACK);
    for(i=min(cx,cy); i>10; i-=5) {
        fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, colour565(0, i, i));
        drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, colour565(i, i, 0));
    }
}

void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t colour) {

    int16_t a, b, y, last;

    // Sort coordinates by Y order (y2 >= y1 >= y0)
    if (y0 > y1) {
        _swap_int16_t(y0, y1); _swap_int16_t(x0, x1);
    }
    if (y1 > y2) {
        _swap_int16_t(y2, y1); _swap_int16_t(x2, x1);
    }
    if (y0 > y1) {
        _swap_int16_t(y0, y1); _swap_int16_t(x0, x1);
    }


    if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
        a = b = x0;
        if(x1 < a)      a = x1;
        else if(x1 > b) b = x1;
        if(x2 < a)      a = x2;
        else if(x2 > b) b = x2;
        drawFastHLine(a, y0, b-a+1, colour);
        return;
    }

    int16_t
    dx01 = x1 - x0,
    dy01 = y1 - y0,
    dx02 = x2 - x0,
    dy02 = y2 - y0,
    dx12 = x2 - x1,
    dy12 = y2 - y1;
    int32_t
    sa   = 0,
    sb   = 0;

    // For upper part of triangle, find scanline crossings for segments
    // 0-1 and 0-2.  If y1=y2 (flat-bottomed triangle), the scanline y1
    // is included here (and second loop will be skipped, avoiding a /0
    // error there), otherwise scanline y1 is skipped here and handled
    // in the second loop...which also avoids a /0 error here if y0=y1
    // (flat-topped triangle).
    if(y1 == y2) last = y1;   // Include y1 scanline
    else         last = y1-1; // Skip it

    for(y=y0; y<=last; y++) {
        a   = x0 + sa / dy01;
        b   = x0 + sb / dy02;
        sa += dx01;
        sb += dx02;
        /* longhand:
        a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
        b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
         */
        if(a > b) _swap_int16_t(a,b);
        drawFastHLine(a, y, b-a+1, colour);
    }

    // For lower part of triangle, find scanline crossings for segments
    // 0-2 and 1-2.  This loop is skipped if y1=y2.
    sa = (int32_t)dx12 * (y - y1);
    sb = (int32_t)dx02 * (y - y0);
    for(; y<=y2; y++) {
        a   = x1 + sa / dy12;
        b   = x0 + sb / dy02;
        sa += dx12;
        sb += dx02;
        /* longhand:
        a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
        b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
         */
        if(a > b) _swap_int16_t(a,b);
        drawFastHLine(a, y, b-a+1, colour);
    }
}

void testRoundRects(void) {

    int w, i, i2, cx = width / 2 - 1, cy = height / 2 - 1;

    fillScreen(BLACK);
    w = min(width, height);

    for(i=0; i<w; i+=6) {
        i2 = i / 2;
        drawRoundRect(cx-i2, cy-i2, i, i, i/8, colour565(i, 0, 0));
    }
}

void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t colour) {
    int16_t max_radius = ((w < h) ? w : h) / 2; // 1/2 minor axis
    if(r > max_radius) r = max_radius;
    // smarter version

    drawFastHLine(x+r, y, w-2*r, colour); // Top
    drawFastHLine(x+r, y+h-1, w-2*r, colour); // Bottom
    drawFastVLine(x, y+r, h-2*r, colour); // Left
    drawFastVLine(x+w-1, y+r, h-2*r, colour); // Right
    // draw four corners
    drawCircleHelper(x+r, y+r, r, 1, colour);
    drawCircleHelper(x+w-r-1, y+r, r, 2, colour);
    drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, colour);
    drawCircleHelper(x+r, y+h-r-1, r, 8, colour);
}

void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t colour) {
    int16_t f = 1 - r;
    int16_t ddF_x = 1;
    int16_t ddF_y = -2 * r;
    int16_t x = 0;
    int16_t y = r;

    while (x<y) {
        if (f >= 0) {
            y--;
            ddF_y += 2;
            f += ddF_y;
        }
        x++;
        ddF_x += 2;
        f += ddF_x;
        if (cornername & 0x4) {
            drawPixel(x0 + x, y0 + y, colour);
            drawPixel(x0 + y, y0 + x, colour);
        }
        if (cornername & 0x2) {
            drawPixel(x0 + x, y0 - y, colour);
            drawPixel(x0 + y, y0 - x, colour);
        }
        if (cornername & 0x8) {
            drawPixel(x0 - y, y0 + x, colour);
            drawPixel(x0 - x, y0 + y, colour);
        }
        if (cornername & 0x1) {
            drawPixel(x0 - y, y0 - x, colour);
            drawPixel(x0 - x, y0 - y, colour);
        }
    }
}

void testFilledRoundRects(void) {

    int i, i2, cx = width / 2 - 1, cy = height / 2 - 1;

    fillScreen(BLACK);

    for(i=min(width, height); i>20; i-=6) {
        i2 = i / 2;
        fillRoundRect(cx-i2, cy-i2, i, i, i/8, colour565(0, i, 0));
    }
}

void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t colour) {
    int16_t max_radius = ((w < h) ? w : h) / 2; // 1/2 minor axis
    if(r > max_radius) r = max_radius;
    // smarter version
    fillRect(x+r, y, w-2*r, h, colour);
    // draw four corners
    fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, colour);
    fillCircleHelper(x+r, y+r, r, 2, h-2*r-1, colour);
}

void printString(char* string) {
#ifdef FIXED_WIDTH_FONT
    printStringFW(string);
#else
    printStringVW(string);
#endif
}

void printStringFW(char* string) {
    while (*(string)) {
        printCharacter(*(string));
        xCoordinate += 6*size;
        string++;
    }
}

void printStringVW(char* string) {
    while (*(string)) {
        printCharacter(*(string));
        xCoordinate += fontData[fontOffset[*string - 32] + 1];
        string++;
    }
}

void printStringRight(char* string) {
#ifdef FIXED_WIDTH_FONT
    printStringRightFW(string);
#else
    printStringRightVW(string);
#endif
}

void printStringRightFW(char* string) {
    signed int i = 0;
    signed int j;

    //find end of string
    while (*string) {
        i++;
    string++;
    }
    string--;

    //print characters in reverse
    for (j = i - 1; j >= 0; j--) {
        xCoordinate -= 5 * size - 1;
        printCharacter(*(string--));
        xCoordinate -= size + 1;
    }
}

void printStringRightVW(char* string) {
    signed int i = 0;
    signed int j;

    //find end of string
    while (*string) {
        i++;
    string++;
    }
    string--;

    //print characters in reverse
    for (j = i - 1; j >= 0; j--) {
        xCoordinate -= fontData[fontOffset[*string - 32] + 1] - 1;
        printCharacter(*(string--));
        xCoordinate--;
    }
}

void printCharacter(char z) {
#ifdef FIXED_WIDTH_FONT
    printCharacterFW(z);
#else
    printCharacterVW(z);
#endif
}

void printCharacterFW(char z) {
    uint8_t i;
    uint8_t j;
    uint8_t line;

    for(i=0; i<5; i++ ) {                                                      //Adafruit "Classic" font = 5 columns
        line = fontData[z * 5 + i];
        for(j=0; j<8; j++, line >>= 1) {
            if(line & 1) {
                if(size == 1)
                    drawPixel(xCoordinate+i, yCoordinate+j, fontColour);
                else
                    fillRect(xCoordinate+i*size, yCoordinate+j*size, size, size, fontColour);
            }
        }
    }
}

void printCharacterVW(char z) {                                                  //print variable-width font

}

void printStringcmdL(char* string) {
#ifdef FIXED_WIDTH_FONT
    printStringcmdLFW(string);
#else
    printStringcmdLVW(string);
#endif
}

void printStringcmdLFW(char* string) {
    while (*(string)) {
        printCharactercmdL(*(string));
        xCoordinateCursor += 6*size;
        string++;
    }
}

void printStringcmdLVW(char* string) {
    while (*(string)) {
        printCharactercmdL(*(string));
        xCoordinateCursor += fontData[fontOffset[*string - 32] + 1];
        string++;
    }
}

void printCharactercmdL(char z) {
#ifdef FIXED_WIDTH_FONT
    printCharactercmdLFW(z);
#else
    printCharactercmdLVW(z);
#endif
}

void printCharactercmdLFW(char z) {
    uint8_t i;
    uint8_t j;
    uint8_t line;

    for(i=0; i<5; i++ ) {                                                      //Adafruit "Classic" font = 5 columns
        line = fontData[z * 5 + i];
        for(j=0; j<8; j++, line >>= 1) {
            if(line & 1) {
                if(size == 1)
                    drawPixel(xCoordinateCursor+i, yCoordinateCursor+j, fontColour);
                else
                    fillRect(xCoordinateCursor+i*size, yCoordinateCursor+j*size, size, size, fontColour);
            }
        }
    }
}

void printCharactercmdLVW(char z) {

}

Replace the code in “HX8357D.c” with:

Code:

//Port of Adafruit code to i.MX RT1010

/*Copyright (c) 2013 Adafruit Industries.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.*/

//includes

#include <stdint.h>
#include <stdbool.h>

#include "board.h"

#include "pin_mux.h"
#include "clock_config.h"

#include "../header/display.h"

//variables

extern int width;
extern int height;

//functions

void writeRegister32(uint8_t, uint32_t);
void writeRegister8(uint8_t, uint8_t);
void setAddrWindow(int, int, int, int);
void flood(uint16_t, uint32_t);
void setLR(void);
void writeRegisterPair(uint8_t, uint8_t, uint16_t);
void displayPortWrite(unsigned int);
void delayms(unsigned int);

///////////////////////////////////////////////////////////////////////////////

void initDisp(void) {
    uint8_t i;

    GPIO_PinWrite(BOARD_INITPINS_WR_26_04_PERIPHERAL, BOARD_INITPINS_WR_26_04_CHANNEL, 1U);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(0x00);
    for (i = 0; i < 3; i++) displayPortWrite(0x00);

    //write to LCD registers

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_SWRESET);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357D_SETC);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0xFF);
    displayPortWrite(0x83);
    displayPortWrite(0x57);

    delayms(250);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_SETRGB);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x00);
    displayPortWrite(0x00);
    displayPortWrite(0x06);
    displayPortWrite(0x06);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357D_SETCOM);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x25);                                                           //-1.52V

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_SETOSC);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x68);                                                           //Normal mode 70Hz, Idle mode 55 Hz

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_SETPANEL);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x05);                                                           //BGR, gate direction swapped

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_SETPWR1);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x00);
    displayPortWrite(0x15);
    displayPortWrite(0x1C);
    displayPortWrite(0x1C);
    displayPortWrite(0x83);
    displayPortWrite(0xAA);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357D_SETSTBA);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x50);
    displayPortWrite(0x50);
    displayPortWrite(0x01);
    displayPortWrite(0x3C);
    displayPortWrite(0x1E);
    displayPortWrite(0x08);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357D_SETCYC);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x02);
    displayPortWrite(0x40);
    displayPortWrite(0x00);
    displayPortWrite(0x2A);
    displayPortWrite(0x2A);
    displayPortWrite(0x0D);
    displayPortWrite(0x78);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_COLMOD);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x55);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_MADCTL);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0xC0);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_TEON);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x00);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_TEARLINE);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(0x00);
    displayPortWrite(0x02);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_SLPOUT);

    delayms(150);

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(HX8357_DISPON);

    delayms(50);
}

void setAddrWindow(int x1,int y1, int x2, int y2) {
    uint32_t t;

    t = x1;
    t <<= 16;
    t |= x2;
    writeRegister32(ILI9341_COLADDRSET, t);                                    // HX8357D uses same registers!
    t = y1;
    t <<= 16;
    t |= y2;
    writeRegister32(ILI9341_PAGEADDRSET, t);                                   // HX8357D uses same registers!
}

void writeRegister8(uint8_t a, uint8_t d) {
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(a);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(d);
}

void writeRegister32(uint8_t r, uint32_t d) {
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(r);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    __asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");

    displayPortWrite(d >> 24);
    __asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");

    displayPortWrite(d >> 16);
    __asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");

    displayPortWrite(d >> 8);
    __asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");__asm volatile ("nop");

    displayPortWrite(d);
}

void flood(uint16_t colour, uint32_t len) {
    uint16_t blocks;
    uint8_t  i, hi = colour >> 8, lo = colour;

    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND

    displayPortWrite(HX8357_RAMWR);

    // Write first pixel normally, decrement counter by 1
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(hi);
    displayPortWrite(lo);
    len--;

    blocks = (uint16_t)(len / 64);                                             //64 pixels/block
    if(hi == lo) {
        // High and low bytes are identical.  Leave prior data
        // on the port(s) and just toggle the write strobe.
        while(blocks--) {
            i = 16;                                                            //64 pixels/block/4 pixels/pass
            do {
                displayPortWrite(lo); displayPortWrite(lo); displayPortWrite(lo); displayPortWrite(lo);    //2 bytes/pixel
                displayPortWrite(lo); displayPortWrite(lo); displayPortWrite(lo); displayPortWrite(lo);    //x 4 pixels
            } while(--i);
        }
        // Fill any remaining pixels (1 to 64)
        for(i = (uint8_t)len & 63; i--; ) {
            displayPortWrite(lo);
            displayPortWrite(lo);
        }
    } else {
        while(blocks--) {
            i = 16; // 64 pixels/block / 4 pixels/pass
            do {
                displayPortWrite(hi); displayPortWrite(lo); displayPortWrite(hi); displayPortWrite(lo);
                displayPortWrite(hi); displayPortWrite(lo); displayPortWrite(hi); displayPortWrite(lo);
            } while(--i);
        }
        for(i = (uint8_t)len & 63; i--; ) {
            displayPortWrite(hi);
            displayPortWrite(lo);
        }
    }
}

void drawFastVLine(int16_t x, int16_t y, int16_t length, uint16_t colour) {
    int16_t y2;

    // Initial off-screen clipping
    if((length <= 0) || (x<0) || ( x>= width) || (y>= height) || ((y2 = (y+length-1)) < 0)) return;
    if(y < 0) {                                                                // Clip top
        length += y;
        y = 0;
    }

    if(y2 >= height) {                                                      // Clip bottom
        y2 = height - 1;
        length  = y2 - y + 1;
    }

    setAddrWindow(x, y, x, y2);
    flood(colour, length);
    setLR();
}

void drawFastHLine(int16_t x, int16_t y, int16_t length, uint16_t colour) {
    int16_t x2;

    // Initial off-screen clipping
    if((length <= 0) || (y<0) || (y>= height) || (x>= width) || ((x2 = (x+length-1)) <  0)) return;
    if(x < 0) {                                                                // Clip left
        length += x;
        x = 0;
    }
    if(x2 >= width) {                                                       // Clip right
        x2 = width - 1;
        length = x2 - x + 1;
    }

    setAddrWindow(x, y, x2, y);
    flood(colour, length);
    setLR();
}

void setLR(void) {
    writeRegisterPair(HX8347G_COLADDREND_HI, HX8347G_COLADDREND_LO, width  - 1);
    writeRegisterPair(HX8347G_ROWADDREND_HI, HX8347G_ROWADDREND_LO, height - 1);
}

void writeRegisterPair(uint8_t aH, uint8_t aL, uint16_t d) {
    uint8_t hi = (d) >> 8, lo = (d);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(aH);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(hi);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(aL);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(lo);
}

void drawPixel(int16_t x, int16_t y, uint16_t colour) {

    // Clip
    if((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;

    setAddrWindow(x, y, width-1, height-1);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 0U);                                 //COMMAND
    displayPortWrite(0x2C);
    GPIO_PinWrite(BOARD_INITPINS_CD_26_08_PERIPHERAL, BOARD_INITPINS_CD_26_08_CHANNEL, 1U);                           //DATA
    displayPortWrite(colour >> 8);
    displayPortWrite(colour);
}

void setRotation(uint8_t x) {
    uint8_t t;

    x = (x & 3);

    switch (x) {
    case 0:
    case 2:
        width = TFTWIDTH;
        height = TFTHEIGHT;
        break;
    case 1:
    case 3:
        width = TFTHEIGHT;
        height = TFTWIDTH;
        break;
    }

    //HX8357D uses same registers as 9341 but different values
    switch (x) {
    case 2:
        t = HX8357B_MADCTL_RGB;
        break;
    case 3:
        t = HX8357B_MADCTL_MX | HX8357B_MADCTL_MV | HX8357B_MADCTL_RGB;
        break;
    case 0:
        t = HX8357B_MADCTL_MX | HX8357B_MADCTL_MY | HX8357B_MADCTL_RGB;
        break;
    case 1:
        t = HX8357B_MADCTL_MY | HX8357B_MADCTL_MV | HX8357B_MADCTL_RGB;
        break;
    }
    writeRegister8(ILI9341_MADCTL, t);                                         //MADCTL

    // For 8357, init default full-screen address window:
    setAddrWindow(0, 0, width - 1, height - 1);
}

void displayPortWrite(unsigned int x) {
    uint32_t setBitMask;
    uint32_t clrBitMask;

    setBitMask = ((x & 0x01) << 1) | ((x & 0x02) << (2-1)) | ((x & 0x04) << (15-2)) | ((x & 0x08) << (16-3)) | ((x & 0x10) << (17-4)) | ((x & 0x20) << (18-5)) | ((x & 0x40) << (19-6)) | ((x & 0x80) << (20-7));
    clrBitMask = ((~x & 0x01) << 1) | ((~x & 0x02) << (2-1)) | ((~x & 0x04) << (15-2)) | ((~x & 0x08) << (16-3)) | ((~x & 0x10) << (17-4)) | ((~x & 0x20) << (18-5)) | ((~x & 0x40) << (19-6)) | ((~x & 0x80) << (20-7));

    GPIO_PortSet(GPIO1, setBitMask);
    GPIO_PortClear(GPIO1, clrBitMask);

    GPIO_PinWrite(BOARD_INITPINS_WR_26_04_PERIPHERAL, BOARD_INITPINS_WR_26_04_CHANNEL, 0U);
    GPIO_PinWrite(BOARD_INITPINS_WR_26_04_PERIPHERAL, BOARD_INITPINS_WR_26_04_CHANNEL, 1U);
}

Replace the code in “display.h” with:

Code:

#define FIXED_WIDTH_FONT               //"FIXED_WIDTH_FONT" - IF USING ADAFRUIT "CLASSIC" FONT OR OTHER FIXED WIDTH FONT
                                       //"VARIABLE_WIDTH_FONT" - IF USING VARIABLE WIDTH FONT (USER SUPPLIED)

//defines for LCD

#define HX8347G_COLADDRSTART_HI    0x02
#define HX8347G_COLADDRSTART_LO    0x03
#define HX8347G_COLADDREND_HI      0x04
#define HX8347G_COLADDREND_LO      0x05
#define HX8347G_ROWADDRSTART_HI    0x06
#define HX8347G_ROWADDRSTART_LO    0x07
#define HX8347G_ROWADDREND_HI      0x08
#define HX8347G_ROWADDREND_LO      0x09
#define HX8347G_MEMACCESS          0x16

#define HX8357_NOP     0x00
#define HX8357_SWRESET 0x01
#define HX8357_RDDID   0x04
#define HX8357_RDDST   0x09

#define HX8357B_RDPOWMODE  0x0A
#define HX8357B_RDMADCTL  0x0B
#define HX8357B_RDCOLMOD  0x0C
#define HX8357B_RDDIM  0x0D
#define HX8357B_RDDSDR  0x0F

#define HX8357_SLPIN   0x10
#define HX8357_SLPOUT  0x11
#define HX8357B_PTLON   0x12
#define HX8357B_NORON   0x13

#define HX8357_INVOFF  0x20
#define HX8357_INVON   0x21
#define HX8357_DISPOFF 0x28
#define HX8357_DISPON  0x29

#define HX8357_CASET   0x2A
#define HX8357_PASET   0x2B
#define HX8357_RAMWR   0x2C
#define HX8357_RAMRD   0x2E

#define HX8357B_PTLAR   0x30
#define HX8357_TEON  0x35
#define HX8357_TEARLINE  0x44
#define HX8357_MADCTL  0x36
#define HX8357_COLMOD  0x3A

#define HX8357_SETOSC 0xB0
#define HX8357_SETPWR1 0xB1
#define HX8357B_SETDISPLAY 0xB2
#define HX8357_SETRGB 0xB3
#define HX8357D_SETCOM  0xB6

#define HX8357B_SETDISPMODE  0xB4
#define HX8357D_SETCYC  0xB4
#define HX8357B_SETOTP 0xB7
#define HX8357D_SETC 0xB9

#define HX8357B_SET_PANEL_DRIVING 0xC0
#define HX8357D_SETSTBA 0xC0
#define HX8357B_SETDGC  0xC1
#define HX8357B_SETID  0xC3
#define HX8357B_SETDDB  0xC4
#define HX8357B_SETDISPLAYFRAME 0xC5
#define HX8357B_GAMMASET 0xC8
#define HX8357B_SETCABC  0xC9
#define HX8357_SETPANEL  0xCC

#define HX8357B_SETPOWER 0xD0
#define HX8357B_SETVCOM 0xD1
#define HX8357B_SETPWRNORMAL 0xD2

#define HX8357B_RDID1   0xDA
#define HX8357B_RDID2   0xDB
#define HX8357B_RDID3   0xDC
#define HX8357B_RDID4   0xDD

#define HX8357D_SETGAMMA 0xE0

#define HX8357B_SETGAMMA 0xC8
#define HX8357B_SETPANELRELATED  0xE9

#define HX8357B_MADCTL_MY  0x80
#define HX8357B_MADCTL_MX  0x40
#define HX8357B_MADCTL_MV  0x20
#define HX8357B_MADCTL_ML  0x10
#define HX8357B_MADCTL_RGB 0x00
#define HX8357B_MADCTL_BGR 0x08
#define HX8357B_MADCTL_MH  0x04

#define ILI9341_SOFTRESET          0x01
#define ILI9341_SLEEPIN            0x10
#define ILI9341_SLEEPOUT           0x11
#define ILI9341_NORMALDISP         0x13
#define ILI9341_INVERTOFF          0x20
#define ILI9341_INVERTON           0x21
#define ILI9341_GAMMASET           0x26
#define ILI9341_DISPLAYOFF         0x28
#define ILI9341_DISPLAYON          0x29
#define ILI9341_COLADDRSET         0x2A
#define ILI9341_PAGEADDRSET        0x2B
#define ILI9341_MEMORYWRITE        0x2C
#define ILI9341_PIXELFORMAT        0x3A
#define ILI9341_FRAMECONTROL       0xB1
#define ILI9341_DISPLAYFUNC        0xB6
#define ILI9341_ENTRYMODE          0xB7
#define ILI9341_POWERCONTROL1      0xC0
#define ILI9341_POWERCONTROL2      0xC1
#define ILI9341_VCOMCONTROL1      0xC5
#define ILI9341_VCOMCONTROL2      0xC7
#define ILI9341_MEMCONTROL      0x36
#define ILI9341_MADCTL  0x36

#define ILI9341_MADCTL_MY  0x80
#define ILI9341_MADCTL_MX  0x40
#define ILI9341_MADCTL_MV  0x20
#define ILI9341_MADCTL_ML  0x10
#define ILI9341_MADCTL_RGB 0x00
#define ILI9341_MADCTL_BGR 0x08
#define ILI9341_MADCTL_MH  0x04

//colours

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
//////////////////////COLOURS NOT YET IMPLEMENTED - DEFAULT TO COLOUR SHOWN
#define ORANGE  0xF800 //RED
#define PINK    0xFFE0 //YELLOW
#define INDIGO  0xF81F //MAGENTA
#define AQUA    0x07FF //CYAN
#define BROWN   0x0000 //BLACK

//display dimensions

#define TFTWIDTH   320
#define TFTHEIGHT  480

//macros

#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
#define min(a,b) (((a) < (b)) ? (a) : (b))

The C language combines all the power of assembly language with all the ease-of-use of assembly language
Find all posts by this user
Quote this message in a reply
06-12-2020, 03:08 AM
Post: #3
RE: monic part 1: connecting the display
3) Writing to the display (continued)

The final step before downloading the code to the EVK is to configure the pins on the microcontroller. Press “ConfigTools” at the top of the screen, followed by “Pins” to open the pin configuration tool:

[Image: 49994075513_dc4a1cf3c1_z.jpg]

Then select the “Pins” tab on the left hand side of the screen:

[Image: 49994846517_03a2d161ea_z.jpg]

Scroll down the “Pins” tab to pin number 43 (“GPIO_AD_14”). Select this pin, then select the second option and press “Done”:

[Image: 49994592421_87fc2e5bf5_z.jpg]

This pin will be connected to C/D on the display. Click on the “Identifier” label in the highlighted section at the bottom of the screen and enter “CD_26_08”. Then click on “Direction” and select “Output”:

[Image: 49994592356_b69931a518_z.jpg]

This process is repeated to configure the remaining pins as per the table below:

[Image: 49994069568_836841ac88_z.jpg]

Then press “Update Code” at the top of the screen, followed by “OK”:

[Image: 49996992452_3b4188113f_z.jpg]

Now press the hammer icon at the top of the screen to build the code:

[Image: 49996992672_2d24952639_z.jpg]

We are now ready to download the code to the EVK. Connect the EVK to the computer (close the “AutoPlay” screen if it appears), then select “Debug” to download the code (below “New project…” in the bottom left hand corner):

[Image: 49996230063_8930ea489a_z.jpg]


[Image: 49996749801_c7b7b2dbdb_z.jpg]

The first time “Debug” is selected the IDE carries out a probe search. Press “OK”:

[Image: 49994591996_4e1f45c392_z.jpg]

The C language combines all the power of assembly language with all the ease-of-use of assembly language
Find all posts by this user
Quote this message in a reply
06-12-2020, 03:09 AM (This post was last modified: 12-27-2022 12:08 AM by F-73P.)
Post: #4
RE: monic part 1: connecting the display
3) Writing to the display (continued)

The code is downloaded and the debugger launched. Press “Step Into” (at the top of the screen) twice, then press “Step Over” (next to "Step Into") three times to execute the functions:

[Image: 49996749901_7162b98fc5_z.jpg]

[Image: 49994074738_69603141bd_z.jpg]

Then press “Step Into” once more to execute the “SysTick->CTRL = 0;” instruction. Scroll down and place the mouse in the blue shaded area to the left of the function call “printString(“monic 1.0”);”. Right click and select “Toggle Breakpoint”. Press “Resume” at the top of the screen (green arrow to the left of "Step Into") to execute the code up to the breakpoint. Now press “Step Over”:

[Image: 49994074623_07d92b5b5a_z.jpg]

The text “monic 1.0” is displayed on the screen:

[Image: 49996314803_be896e29f7_z.jpg]

The C language combines all the power of assembly language with all the ease-of-use of assembly language
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)