Skip to content

Commit

Permalink
Mirror GC9A01
Browse files Browse the repository at this point in the history
  • Loading branch information
TekuSP committed Dec 26, 2023
1 parent be15642 commit 33a0dec
Showing 1 changed file with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Full datasheet at https://www.waveshare.com/w/upload/5/5e/GC9A01A.pdf
struct DisplayDriver g_DisplayDriver;

Check warning on line 21 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:21:22 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'g_DisplayDriver' is non-const and globally accessible, consider making it const

Check warning on line 21 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:21:22 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'g_DisplayDriver' is non-const and globally accessible, consider making it const
extern DisplayInterface g_DisplayInterface;

Check warning on line 22 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:22:25 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'g_DisplayInterface' is non-const and globally accessible, consider making it const

Check warning on line 22 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:22:25 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'g_DisplayInterface' is non-const and globally accessible, consider making it const
extern DisplayInterfaceConfig g_DisplayInterfaceConfig;

Check warning on line 23 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:23:31 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'g_DisplayInterfaceConfig' is non-const and globally accessible, consider making it const

Check warning on line 23 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:23:31 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'g_DisplayInterfaceConfig' is non-const and globally accessible, consider making it const
CLR_UINT8 orientationByte;

Check warning on line 24 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:24:11 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'orientationByte' is non-const and globally accessible, consider making it const

Check warning on line 24 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:24:11 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'orientationByte' is non-const and globally accessible, consider making it const

enum GC9A01_CMD : CLR_UINT8
{
Expand Down Expand Up @@ -86,7 +87,9 @@ enum GC9A01_MEMORY_ACCESS_CTRL : CLR_UINT8
Portrait = 0x18,
Portrait180 = 0x28,
Landscape = 0x48,
Landscape180 = 0x88
Landscape180 = 0x88,
MirrorX = 0x40,
MirrorY = 0x80
};

void DisplayDriver::SetupDisplayAttributes()

Check warning on line 95 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:95:21 [readability-convert-member-functions-to-static]

method 'SetupDisplayAttributes' can be made static

Check warning on line 95 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:95:21 [readability-convert-member-functions-to-static]

method 'SetupDisplayAttributes' can be made static
Expand All @@ -104,25 +107,29 @@ void DisplayDriver::SetupDisplayAttributes()
bool DisplayDriver::Initialize()

Check warning on line 107 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:107:21 [modernize-use-trailing-return-type]

use a trailing return type for this function

Check warning on line 107 in src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp

View workflow job for this annotation

GitHub Actions / linter-checks

src/nanoFramework.Graphics/Graphics/Displays/GC9A01_MELLOW_240x240_SPI.cpp:107:21 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
SetupDisplayAttributes();
g_DisplayInterface.SendCommand(1, GC9A01_CMD::InnerRegisterEnable2);
g_DisplayInterface.SendCommand(1, 0xfe, 0);
g_DisplayInterface.SendCommand(1, 0xef, 0);
g_DisplayInterface.SendCommand(2, 0xEB, 0x14);
g_DisplayInterface.SendCommand(1, GC9A01_CMD::InnerRegisterEnable1);
g_DisplayInterface.SendCommand(1, GC9A01_CMD::InnerRegisterEnable2);
g_DisplayInterface.SendCommand(2, 0xEB, 0x14);
g_DisplayInterface.SendCommand(2, 0x84, 0x40);
g_DisplayInterface.SendCommand(2, 0x84, 0x60);
g_DisplayInterface.SendCommand(2, 0x85, 0xFF);
g_DisplayInterface.SendCommand(2, 0x86, 0xFF);
g_DisplayInterface.SendCommand(2, 0x87, 0xFF);
g_DisplayInterface.SendCommand(2, 0x8E, 0xFF);
g_DisplayInterface.SendCommand(2, 0x8F, 0xFF);
g_DisplayInterface.SendCommand(2, 0x88, 0x0A);
g_DisplayInterface.SendCommand(2, 0x89, 0x21);
g_DisplayInterface.SendCommand(2, 0x89, 0x23);
g_DisplayInterface.SendCommand(2, 0x8A, 0x00);
g_DisplayInterface.SendCommand(2, 0x8B, 0x80);
g_DisplayInterface.SendCommand(2, 0x8C, 0x01);
g_DisplayInterface.SendCommand(2, 0x8D, 0x01);
g_DisplayInterface.SendCommand(2, 0x8E, 0xFF);
g_DisplayInterface.SendCommand(2, 0x8F, 0xFF);

g_DisplayInterface.SendCommand(3, GC9A01_CMD::DisplayFunctionControl, 0x00, 0x20);
g_DisplayInterface.SendCommand(2, 0x8D, 0x03);
g_DisplayInterface.SendCommand(5, 0x90, 0x08, 0x08, 0x08, 0x08);
g_DisplayInterface.SendCommand(4, 0xff, 0x60, 0x01, 0x04);
g_DisplayInterface.SendCommand(2, 0XC3, 0x13);
g_DisplayInterface.SendCommand(2, 0XC4, 0x13);
g_DisplayInterface.SendCommand(2, 0XC9, 0x30);
g_DisplayInterface.SendCommand(2, 0xbe, 0x11);
g_DisplayInterface.SendCommand(3, 0xe1, 0x10, 0x0e);
g_DisplayInterface.SendCommand(4, 0xdf, 0x21, 0x0c, 0x02);

g_DisplayInterface.SendCommand(2, GC9A01_CMD::PixelFormatSet, GC9A01_PIXEL_FORMAT::Pixel16Bit);
g_DisplayInterface.SendCommand(5, 0x90, 0x08, 0x08, 0x08, 0x08);
Expand All @@ -145,6 +152,8 @@ bool DisplayDriver::Initialize()
g_DisplayInterface.SendCommand(10, 0x70, 0x07, 0x07, 0x04, 0x0E, 0x0F, 0x09, 0x07, 0x08, 0x03);
g_DisplayInterface.SendCommand(2, GC9A01_CMD::FrameRate, 0x34);
g_DisplayInterface.SendCommand(1, 0xE8, 0x34); // 4 dot inversion
g_DisplayInterface.SendCommand(9 ,0x60, 0x38, 0x0b, 0x6D, 0x6D, 0x39, 0xf0, 0x6D, 0x6D),
g_DisplayInterface.SendCommand(9, 0x61, 0x38, 0xf4, 0x6D, 0x6D, 0x38, 0xf7, 0x6D, 0x6D),
g_DisplayInterface.SendCommand(13, 0x62, 0x18, 0x0D, 0x71, 0xED, 0x70, 0x70, 0x18, 0x0F, 0x71, 0xEF, 0x70, 0x70);
g_DisplayInterface.SendCommand(13, 0x63, 0x18, 0x11, 0x71, 0xF1, 0x70, 0x70, 0x18, 0x13, 0x71, 0xF3, 0x70, 0x70);
g_DisplayInterface.SendCommand(8, 0x64, 0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07);
Expand All @@ -158,9 +167,7 @@ bool DisplayDriver::Initialize()
g_DisplayInterface.SendCommand(1, GC9A01_CMD::SleepOut);
OS_DELAY(120);
g_DisplayInterface.SendCommand(1, GC9A01_CMD::DisplayOn);
OS_DELAY(20);


OS_DELAY(20);
return true;
}

Expand Down Expand Up @@ -246,7 +253,7 @@ void DisplayDriver::SetDefaultOrientation()

bool DisplayDriver::ChangeOrientation(DisplayOrientation orientation)
{
CLR_UINT8 orientationByte = GC9A01_MEMORY_ACCESS_CTRL::Portrait;

switch (orientation)
{
case DisplayOrientation::DisplayOrientation_Portrait:
Expand All @@ -262,11 +269,25 @@ bool DisplayDriver::ChangeOrientation(DisplayOrientation orientation)
orientationByte = GC9A01_MEMORY_ACCESS_CTRL::Portrait180;
break;
}

if (true)
{
orientationByte = orientationByte | GC9A01_MEMORY_ACCESS_CTRL::MirrorX;
}
else
{
orientationByte = orientationByte & ~GC9A01_MEMORY_ACCESS_CTRL::MirrorX;
}
if (false)
{
orientationByte = orientationByte | GC9A01_MEMORY_ACCESS_CTRL::MirrorY;
}
else
{
orientationByte = orientationByte & ~GC9A01_MEMORY_ACCESS_CTRL::MirrorY;
}
g_DisplayInterface.SendCommand(2, GC9A01_CMD::MemoryAccessControl, orientationByte);
return true;
}

CLR_UINT32 DisplayDriver::PixelsPerWord()
{
return (32 / Attributes.BitsPerPixel);
Expand Down

0 comments on commit 33a0dec

Please sign in to comment.