Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions ManagedDrivers/Ili9488/Ili9488.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

namespace nanoFramework.UI.GraphicDrivers
{
/// <summary>
/// Managed driver for Ili9488.
/// </summary>
public static class Ili9488
{
private static GraphicDriver _driver;

// Those enums are left like this to match the native side
private enum ILI9488_CMD
{
NOP = 0x00,
SOFTWARE_RESET = 0x01,
POWER_STATE = 0x10,
Sleep_Out = 0x11,
Noron = 0x13,
Invert_On = 0x21,
Invert_Off = 0x20,
Gamma_Set = 0x26,
Display_OFF = 0x28,
Display_ON = 0x29,
Column_Address_Set = 0x2A,
Page_Address_Set = 0x2B,
Memory_Write = 0x2C,
Colour_Set = 0x2D,
Memory_Read = 0x2E,
Partial_Area = 0x30,
Memory_Access_Control = 0x36,
Pixel_Format_Set = 0x3A,
Memory_Write_Continue = 0x3C,
Write_Display_Brightness = 0x51,
Interface_Signal_Control = 0xB0,
Frame_Rate_Control_Normal = 0xB1,
Inversion_Control = 0xB4,
Display_Function_Control = 0xB6,
Entry_Mode_Set = 0xB7,
Power_Control_1 = 0xC0,
Power_Control_2 = 0xC1,
VCOM_Control_1 = 0xC5,
VCOM_Control_2 = 0xC7,
External_Command = 0xC8,
Power_Control_A = 0xCB,
Power_Control_B = 0xCF,
Positive_Gamma_Correction = 0xE0,
Negative_Gamma_Correction = 0XE1,
Driver_Timing_Control_A = 0xE8,
Driver_Timing_Control_B = 0xEA,
Set_Image_Function = 0xE9,
Power_On_Sequence = 0xED,
Enable_3G = 0xF2,
Interface_Control = 0xF6,
Pump_Ratio_Control = 0xF7
};

private enum ILI9488_Orientation
{
/// <summary>
/// Sets the Horizontal Refresh, 0=Left-Right and 1=Right-Left
/// </summary>
MADCTL_MH = 0x04,

/// <summary>
/// Sets the Vertical Refresh, 0=Top-Bottom and 1=Bottom-Top
/// </summary>
MADCTL_ML = 0x10,

/// <summary>
/// Sets the Row/Column Swap, 0=Normal and 1=Swapped
/// </summary>
MADCTL_MV = 0x20,

/// <summary>
/// Sets the Column Order, 0=Left-Right and 1=Right-Left
/// </summary>
MADCTL_MX = 0x40,

/// <summary>
/// Sets the Row Order, 0=Top-Bottom and 1=Bottom-Top
/// </summary>
MADCTL_MY = 0x80,

/// <summary>
/// Blue-Green-Red pixel order
/// </summary>
MADCTL_BGR = 0x08,

/// <summary>
/// Red-Green-Blue pixel order
/// </summary>
MADCTL_RGB = 0x00
};

/// <summary>
/// Default width. Use to override the one you'll pass in the screen and add it to the driver.
/// </summary>
public static uint Width { get; } = 480;
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/// <summary>
/// Default height. Use to override the one you'll pass in the screen and add it to the driver.
/// </summary>
public static uint Height { get; } = 320;

/// <summary>
/// Gets the graphic driver for the Ili9488 display.
/// </summary>
public static GraphicDriver GraphicDriver
{
get
{
if (_driver == null)
{
_driver = new GraphicDriver()
{
MemoryWrite = (byte)ILI9488_CMD.Memory_Write,
SetColumnAddress = (byte)ILI9488_CMD.Column_Address_Set,
SetRowAddress = (byte)ILI9488_CMD.Page_Address_Set,
InitializationSequence = new byte[]
{
(byte)GraphicDriverCommandType.Command, 3, (byte)ILI9488_CMD.Power_Control_1, 0x17, 0x15,
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Power_Control_2, 0x41,
(byte)GraphicDriverCommandType.Command, 4, (byte)ILI9488_CMD.VCOM_Control_1, 0x00, 0x12, 0x80,
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Pixel_Format_Set, 0x66, // 18-bit. Native generic driver supports 18-bit transfers via conversion to RGB666
(byte)GraphicDriverCommandType.Command, 16, (byte)ILI9488_CMD.Positive_Gamma_Correction, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F,
(byte)GraphicDriverCommandType.Command, 16, (byte)ILI9488_CMD.Negative_Gamma_Correction, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F,
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Interface_Signal_Control, 0x80,
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Frame_Rate_Control_Normal, 0xA0,
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Inversion_Control, 0x02,
(byte)GraphicDriverCommandType.Command, 4, (byte)ILI9488_CMD.Display_Function_Control, 0x02, 0x02, 0x3B,
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Set_Image_Function, 0x00,
(byte)GraphicDriverCommandType.Command, 5, (byte)ILI9488_CMD.Pump_Ratio_Control, 0xA9, 0x51, 0x2C, 0x82,
(byte)GraphicDriverCommandType.Command, 1, (byte)ILI9488_CMD.Sleep_Out,
(byte)GraphicDriverCommandType.Sleep, 12, // Sleep 120 ms
(byte)GraphicDriverCommandType.Command, 1, (byte)ILI9488_CMD.Display_ON,
(byte)GraphicDriverCommandType.Sleep, 20, // Sleep 200 ms
(byte)GraphicDriverCommandType.Command, 1, (byte)ILI9488_CMD.NOP,
(byte)GraphicDriverCommandType.Sleep, 2 // Sleep 20 ms
},
OrientationLandscape = new byte[]
{
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control,
(byte)(
ILI9488_Orientation.MADCTL_MX |
ILI9488_Orientation.MADCTL_MY |
ILI9488_Orientation.MADCTL_MV |
ILI9488_Orientation.MADCTL_RGB
),
},
OrientationLandscape180 = new byte[]
{
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control,
(byte)(
ILI9488_Orientation.MADCTL_MV |
ILI9488_Orientation.MADCTL_RGB
),
},
OrientationPortrait = new byte[]
{
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control,
(byte)(
ILI9488_Orientation.MADCTL_MX |
ILI9488_Orientation.MADCTL_RGB
),
},
OrientationPortrait180 = new byte[]
{
(byte)GraphicDriverCommandType.Command, 2, (byte)ILI9488_CMD.Memory_Access_Control,
(byte)(
ILI9488_Orientation.MADCTL_MY |
ILI9488_Orientation.MADCTL_RGB
),
},
Comment on lines +145 to +178

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All orientation command sequences hardcode MADCTL_RGB. The PR description mentions the default is RGB but that it “can be overridden to BGR”; with the current implementation, consumers can only do that by manually editing the returned byte arrays, and the MADCTL enum is private so they can’t reuse the named constant. Consider exposing an explicit/public way to get an alternate BGR-configured GraphicDriver (or a switch/parameter) so the advertised override is straightforward and less error-prone.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed "can be overridden to BGR" in PR description. This is now streamlined with other drivers.

Suggest a refactoring in a different PR to allow defining drivers and reusing enums and constants

PowerModeNormal = new byte[]
{
(byte)GraphicDriverCommandType.Command, 3, (byte)ILI9488_CMD.POWER_STATE, 0x00, 0x00,
},
PowerModeSleep = new byte[]
{
(byte)GraphicDriverCommandType.Command, 3, (byte)ILI9488_CMD.POWER_STATE, 0x00, 0x01,
},
DefaultOrientation = DisplayOrientation.Landscape,
Brightness = (byte)ILI9488_CMD.Write_Display_Brightness,
SetWindowType = SetWindowType.X16bitsY16Bit,
BitsPerPixel = 18
};
}

return _driver;
}
}
}
}
15 changes: 15 additions & 0 deletions ManagedDrivers/Ili9488/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("nanoFramework.Graphics.Ili9488")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyProduct("nanoFramework.Graphics.Ili9488")]
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2026")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
65 changes: 65 additions & 0 deletions ManagedDrivers/Ili9488/nanoFramework.Graphics.Ili9488.nfproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing here the nbgv props and targets. Also in the reference in the packages.lock file.
I can see these are missing on the other drivers too. I'm submitting a PR with a fix for those.

@mikmog mikmog Apr 9, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are editing feel free to include this pr, Otherwise I'll do it

<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.props" Condition="Exists('..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.props')" />
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>1349bd64-2f76-4c99-9e3a-bf8851663c61</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>nanoFramework.UI.GraphicDrivers</RootNamespace>
<AssemblyName>nanoFramework.Graphics.Ili9488</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\nanoFramework.Graphics.Ili9488.xml</DocumentationFile>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<DelaySign>false</DelaySign>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="Ili9488.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\nanoFramework.Graphics.Core\nanoFramework.Graphics.Core.nfproj" />
<ProjectReference Include="..\..\nanoFramework.Graphics\nanoFramework.Graphics.nfproj" />
</ItemGroup>
<ItemGroup>
<Content Include="packages.lock.json" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib, Version=1.17.11.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.17.11\lib\mscorlib.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.props'))" />
<Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.targets'))" />
</Target>
<Import Project="..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\packages\Nerdbank.GitVersioning.3.10.85\build\Nerdbank.GitVersioning.targets')" />
</Project>
5 changes: 5 additions & 0 deletions ManagedDrivers/Ili9488/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.17.11" targetFramework="netnano1.0" />
<package id="Nerdbank.GitVersioning" version="3.10.85" developmentDependency="true" targetFramework="netnano1.0" />
</packages>
19 changes: 19 additions & 0 deletions ManagedDrivers/Ili9488/packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": 1,
"dependencies": {
".NETnanoFramework,Version=v1.0": {
"nanoFramework.CoreLibrary": {
"type": "Direct",
"requested": "[1.17.11, 1.17.11]",
"resolved": "1.17.11",
"contentHash": "HezzAc0o2XrSGf85xSeD/6xsO6ohF9hX6/iMQ1IZS6Zw6umr4WfAN2Jv0BrPxkaYwzEegJxxZujkHoUIAqtOMw=="
},
"Nerdbank.GitVersioning": {
"type": "Direct",
"requested": "[3.10.85, 3.10.85]",
"resolved": "3.10.85",
"contentHash": "smhqiTAbnI/6NRn+k7m+a65qKY7nREbnFqFgqxiw3JS8kXiBUOxdCxIZFP9TOpCsoh46DbMlBlcd+dWQYAVVCA=="
}
}
}
}
4 changes: 4 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ jobs:
- template: azure-pipelines-templates/class-lib-package.yml@templates
parameters:
nugetPackageName: 'nanoFramework.Graphics.Ili9342'

- template: azure-pipelines-templates/class-lib-package.yml@templates
parameters:
nugetPackageName: 'nanoFramework.Graphics.Ili9488'

- template: azure-pipelines-templates/class-lib-package.yml@templates
parameters:
Expand Down
51 changes: 51 additions & 0 deletions nanoFramework.Graphics.Ili9488.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>nanoFramework.Graphics.Ili9488</id>
<version>$version$</version>
<title>nanoFramework.Graphics.Ili9488</title>
<authors>nanoframework</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE.md</license>
<releaseNotes>
</releaseNotes>
<developmentDependency>false</developmentDependency>
<readme>docs\README.md</readme>
<projectUrl>https://github.com/nanoframework/nanoFramework.Graphics</projectUrl>
<icon>images\nf-logo.png</icon>
<repository type="git" url="https://github.com/nanoframework/nanoFramework.Graphics" commit="$commit$" />
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
<description>This package includes the nanoFramework.Graphics assembly for .NET nanoFramework C# projects.
It does embed a managed driver Ili9488. It is aimed to be used for images built with Generic Graphics driver.
This package requires a target with nanoFramework.Graphics v$nativeVersion$ (checksum $checksum$).</description>
<tags>nanoFramework C# csharp netmf netnf nanoFramework.Graphics Ili9488</tags>
<dependencies>
<dependency id="nanoFramework.CoreLibrary" version="1.17.11" />
<dependency id="nanoFramework.ResourceManager" version="1.2.13" />
<dependency id="nanoFramework.Runtime.Events" version="1.11.6" />
<dependency id="nanoFramework.Runtime.Native" version="1.6.6" />
<dependency id="nanoFramework.System.Collections" version="1.5.18" />
</dependencies>
</metadata>
<files>
<file src="nanoFramework.Graphics.Core\bin\Release\nanoFramework.Graphics.Core.dll" target="lib\nanoFramework.Graphics.Core.dll" />
<file src="nanoFramework.Graphics.Core\bin\Release\nanoFramework.Graphics.Core.pdb" target="lib\nanoFramework.Graphics.Core.pdb" />
<file src="nanoFramework.Graphics.Core\bin\Release\nanoFramework.Graphics.Core.pdbx" target="lib\nanoFramework.Graphics.Core.pdbx" />
<file src="nanoFramework.Graphics.Core\bin\Release\nanoFramework.Graphics.Core.pe" target="lib\nanoFramework.Graphics.Core.pe" />
<file src="nanoFramework.Graphics.Core\bin\Release\nanoFramework.Graphics.Core.xml" target="lib\nanoFramework.Graphics.Core.xml" />
<file src="nanoFramework.Graphics\bin\Release\nanoFramework.Graphics.dll" target="lib\nanoFramework.Graphics.dll" />
<file src="nanoFramework.Graphics\bin\Release\nanoFramework.Graphics.pdb" target="lib\nanoFramework.Graphics.pdb" />
<file src="nanoFramework.Graphics\bin\Release\nanoFramework.Graphics.pdbx" target="lib\nanoFramework.Graphics.pdbx" />
<file src="nanoFramework.Graphics\bin\Release\nanoFramework.Graphics.pe" target="lib\nanoFramework.Graphics.pe" />
<file src="nanoFramework.Graphics\bin\Release\nanoFramework.Graphics.xml" target="lib\nanoFramework.Graphics.xml" />
<file src="ManagedDrivers\Ili9488\bin\Release\nanoFramework.Graphics.Ili9488.dll" target="lib\nanoFramework.Graphics.Ili9488.dll" />
<file src="ManagedDrivers\Ili9488\bin\Release\nanoFramework.Graphics.Ili9488.pdb" target="lib\nanoFramework.Graphics.Ili9488.pdb" />
<file src="ManagedDrivers\Ili9488\bin\Release\nanoFramework.Graphics.Ili9488.pdbx" target="lib\nanoFramework.Graphics.Ili9488.pdbx" />
<file src="ManagedDrivers\Ili9488\bin\Release\nanoFramework.Graphics.Ili9488.pe" target="lib\nanoFramework.Graphics.Ili9488.pe" />
<file src="ManagedDrivers\Ili9488\bin\Release\nanoFramework.Graphics.Ili9488.xml" target="lib\nanoFramework.Graphics.Ili9488.xml" />
<file src="assets\readme.txt" target="" />
<file src="README.md" target="docs\" />
<file src="assets\nf-logo.png" target="images" />
<file src="LICENSE.md" target="" />
</files>
</package>
Loading