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
4 changes: 3 additions & 1 deletion devices/ePaper/Drivers/IePaperDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public interface IEPaperDisplay : IDisposable
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to be able to cancel the waiting time.</param>
/// <returns>True if it returns before the <see cref="CancellationToken"/> expires, false otherwise.</returns>
/// <remarks>If cancellationToken is null, this method will block until the busy pin is low.</remarks>
/// <remarks>
/// Busy-pin polarity is controller-specific; implementations block until the device is ready for new commands.
/// </remarks>
bool WaitReady(CancellationToken cancellationToken = default);

/// <summary>
Expand Down
10 changes: 2 additions & 8 deletions devices/ePaper/Drivers/JD796xx/Gdew0154m09.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ public class Gdew0154m09 : Jd79653A
/// If you can't guarantee 5KB to be available to the driver then enable paging by setting <paramref name="enableFramePaging"/> to true.
/// A page uses about 1KB (5KB / PagesPerFrame).
/// </remarks>
public Gdew0154m09(
SpiDevice spiDevice,
int resetPin,
int busyPin,
int dataCommandPin,
GpioController gpioController = null,
bool enableFramePaging = false,
bool shouldDispose = true) : base(spiDevice, resetPin, busyPin, dataCommandPin, 200, 200, gpioController, enableFramePaging, shouldDispose)
public Gdew0154m09(SpiDevice spiDevice, int resetPin, int busyPin, int dataCommandPin, GpioController gpioController = null, bool enableFramePaging = false, bool shouldDispose = true)
: base(spiDevice, resetPin, busyPin, dataCommandPin, 200, 200, gpioController, enableFramePaging, shouldDispose)
{
}

Expand Down
16 changes: 2 additions & 14 deletions devices/ePaper/Drivers/JD796xx/JD79653A.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ public abstract class Jd79653A : IEPaperDisplay
/// <param name="shouldDispose">True to dispose the Gpio Controller.</param>
/// <exception cref="ArgumentNullException"><paramref name="spiDevice"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException">Display width and height can't be less than 0 or greater than 200.</exception>
protected Jd79653A(
SpiDevice spiDevice,
int resetPin,
int busyPin,
int dataCommandPin,
int width,
int height,
GpioController gpioController = null,
bool enableFramePaging = false,
bool shouldDispose = true)
protected Jd79653A(SpiDevice spiDevice, int resetPin, int busyPin, int dataCommandPin, int width, int height, GpioController gpioController = null, bool enableFramePaging = false, bool shouldDispose = true)
{
_spiDevice = spiDevice ?? throw new ArgumentNullException(nameof(spiDevice));
_gpioController = gpioController ?? new GpioController();
Expand All @@ -75,7 +66,7 @@ protected Jd79653A(
Height = height;
PagedFrameDrawEnabled = enableFramePaging;

_whiteBuffer = new byte[Width * Height];
_whiteBuffer = new byte[(Width * Height) / 8];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Round up the packed buffer size.

Line 69 uses floor division, so geometries whose total pixel count is not divisible by 8 will allocate one byte too few and truncate the final partial byte during upload. Use ceiling division here instead.

Proposed fix
-            _whiteBuffer = new byte[(Width * Height) / 8];
+            _whiteBuffer = new byte[((Width * Height) + 7) / 8];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_whiteBuffer = new byte[(Width * Height) / 8];
_whiteBuffer = new byte[((Width * Height) + 7) / 8];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@devices/ePaper/Drivers/JD796xx/JD79653A.cs` at line 69, The buffer allocation
for _whiteBuffer in JD79653A.cs uses floor division and can underrun when
Width*Height isn't divisible by 8; change the allocation to use ceiling division
so partial final bytes are included (e.g., compute packedSize = (Width * Height
+ 7) / 8 or use an equivalent Math.Ceiling-based expression) and replace the
current new byte[(Width * Height) / 8] with new byte[packedSize]; ensure the
same fix is applied for any similar _blackBuffer or packed-buffer allocations in
the class.

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.

why this change?

for (int i = 0; i < _whiteBuffer.Length; i++)
{
_whiteBuffer[i] = 0xff;
Expand Down Expand Up @@ -224,9 +215,6 @@ public void DirectDrawBuffer(params byte[] buffer)
SendData(_whiteBuffer);
SendCommand((byte)Command.DataStartTransmission2);
SendData(buffer);
WaitMs(5);

PerformFullRefresh();
}

/// <summary>
Expand Down
42 changes: 42 additions & 0 deletions devices/ePaper/Drivers/LcmEn2r13/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2024 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.

namespace Iot.Device.EPaper.Drivers.LcmEn2r13
{
/// <summary>
/// Commands used by the LCMEN2R13 display driver.
/// </summary>
internal enum Command : byte
{
PanelSetting = 0x00,
PowerSetting = 0x01,
PowerOff = 0x02,
PowerOn = 0x04,
BoosterSoftStart = 0x06,
DeepSleep = 0x07,
WritePreviousImage = 0x10,
DisplayRefresh = 0x12,
WriteCurrentImage = 0x13,
TemperatureSensorControl = 0x18,
WriteLutVcom = 0x20,
WriteLutWhiteToWhite = 0x21,
WriteLutBlackToWhite = 0x22,
WriteLutWhiteToBlack = 0x23,
WriteLutBlackToBlack = 0x24,
PLLControl = 0x30,
BorderWaveform = 0x3C,
SetXAddressRange = 0x44,
SetYAddressRange = 0x45,
SetXAddressCounter = 0x4E,
SetYAddressCounter = 0x4F,
VcomAndDataIntervalSetting = 0x50,
TconSetting = 0x60,
ResolutionSetting = 0x61,
VcmDcSetting = 0x82,
PartialWindow = 0x90,
PartialIn = 0x91,
PartialOut = 0x92,
CascadeSetting = 0xE0,
ForceTemperature = 0xE5,
}
}
Loading