-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Monochrome implementation of ST7586S display
This panel is 4-level grayscale, but this color mode isn't supported by modm yet.
- Loading branch information
1 parent
364bf3f
commit 8aaee52
Showing
10 changed files
with
475 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2021, Tomasz Wasilczyk | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <modm/board.hpp> | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
auto& display = Board::display; | ||
|
||
display.setCursor(115, 54); | ||
display.setFont(modm::font::Ubuntu_36); | ||
display << "Hello World"; | ||
display.drawRoundedRectangle({100, 48}, 184, 40, 10); | ||
|
||
display.update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<library> | ||
<extends>modm:srxe</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/srxe/display</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2021, Tomasz Wasilczyk | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "board.hpp" | ||
|
||
namespace Board { | ||
|
||
Display display; | ||
|
||
} // namespace Board |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2021, Tomasz Wasilczyk | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
#define MODM_ST7586S_HPP | ||
|
||
#include <modm/ui/display/monochrome_graphic_display_horizontal.hpp> | ||
|
||
#include "st7586s_protocol.hpp" | ||
|
||
namespace modm | ||
{ | ||
|
||
template <typename SPI, typename CS, typename RST, typename DC, int Width = 384, int Height = 160> | ||
// TODO: this controller has pixels packed by 3, not 8 per byte | ||
class St7586s : public MonochromeGraphicDisplayHorizontal<Width, Height> | ||
{ | ||
using Command = impl::st7586s::Command; | ||
static constexpr uint8_t pixelsPerByte = 3; | ||
|
||
void sendCommand(Command cmd, const void *data = nullptr, size_t len = 0); | ||
template <typename Data> | ||
void sendCommand(Command cmd, Data data) { | ||
sendCommand(cmd, &data, sizeof(data)); | ||
} | ||
|
||
void setClipping(uint16_t x, uint16_t y, uint16_t w, uint16_t h); | ||
|
||
public: | ||
void initialize(); | ||
virtual void update() override; | ||
}; | ||
|
||
} // namespace modm | ||
|
||
#include "st7586s_impl.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2021, Tomasz Wasilczyk | ||
# | ||
# This file is part of the modm project. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
# ----------------------------------------------------------------------------- | ||
|
||
|
||
def init(module): | ||
module.name = ":driver:st7586s" | ||
module.description = "ST7586S 4-level grayscale LCD controller" | ||
|
||
def prepare(module, options): | ||
module.depends( | ||
":architecture:delay", | ||
":ui:display") | ||
return True | ||
|
||
def build(env): | ||
env.outbasepath = "modm/src/modm/driver/display" | ||
env.copy("st7586s.hpp") | ||
env.copy("st7586s_impl.hpp") | ||
env.copy("st7586s_protocol.hpp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright (c) 2021, Tomasz Wasilczyk | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
#ifndef MODM_ST7586S_HPP | ||
#error "Do not include this file directly. Include st7586s.hpp instead." | ||
#endif | ||
|
||
#include <modm/architecture/interface/assert.hpp> | ||
#include <modm/architecture/interface/gpio.hpp> | ||
|
||
namespace modm | ||
{ | ||
|
||
template <typename SPI, typename CS, typename RST, typename DC, int Width, int Height> | ||
void | ||
St7586s<SPI, CS, RST, DC, Width, Height>::sendCommand(Command cmd, const void *data, size_t len) | ||
{ | ||
CS::reset(); | ||
DC::reset(); // command mode | ||
SPI::transferBlocking(static_cast<uint8_t>(cmd)); | ||
DC::set(); // data mode | ||
if (len > 0) { | ||
SPI::transferBlocking(reinterpret_cast<const uint8_t*>(data), nullptr, len); | ||
} | ||
CS::set(); | ||
// exit with data mode on | ||
} | ||
|
||
template <typename SPI, typename CS, typename RST, typename DC, int Width, int Height> | ||
void | ||
St7586s<SPI, CS, RST, DC, Width, Height>::initialize() | ||
{ | ||
namespace payload = impl::st7586s::payload; | ||
|
||
// Configure GPIO | ||
RST::reset(); | ||
RST::setOutput(); | ||
CS::set(); | ||
CS::setOutput(); | ||
DC::setOutput(); | ||
|
||
// Reset display | ||
modm::delay_us(10); | ||
RST::set(); | ||
modm::delay_ms(120); | ||
|
||
// Power ON operation flow (see datasheet) | ||
sendCommand(Command::SleepOff); | ||
sendCommand(Command::DisplayOff); | ||
modm::delay_ms(50); // t_{ON-V2} | ||
sendCommand(Command::SetVop, payload::SetVop(13.52f)); | ||
sendCommand(Command::SetBias, payload::SetBias::Ratio_1_11); | ||
sendCommand(Command::SetBooster, payload::SetBooster::x8); | ||
sendCommand(Command::AnalogControl, payload::AnalogControl::Enable); | ||
sendCommand<payload::NLineInversion_t>(Command::NLineInversion, | ||
payload::LineInversionType_t(payload::LineInversionType::FrameInversion)); | ||
sendCommand(Command::DisplayModeMono); // TODO: grayscale | ||
sendCommand(Command::EnableDdram, payload::EnableDdram::Enable); | ||
sendCommand(Command::ScanDirection, payload::DisplayControl::ComInc | ||
| payload::DisplayControl::SegInc); | ||
sendCommand(Command::DisplayDuty, uint8_t(Height - 1)); | ||
sendCommand(Command::InverseOff); | ||
setClipping(0, 0, Width, Height); | ||
update(); // clear the display | ||
sendCommand(Command::DisplayOn); | ||
} | ||
|
||
template <typename SPI, typename CS, typename RST, typename DC, int Width, int Height> | ||
void | ||
St7586s<SPI, CS, RST, DC, Width, Height>::setClipping(uint16_t x, uint16_t y, uint16_t w, uint16_t h) | ||
{ | ||
namespace payload = impl::st7586s::payload; | ||
|
||
modm_assert(x < Width, "st4586s.sc.x", "x >= Width", x); | ||
modm_assert(x + w <= Width, "st4586s.sc.xw", "x + w >= Width", x + w); | ||
modm_assert(y < Height, "st4586s.sc.y", "y >= Height", y); | ||
modm_assert(y + h <= Height, "st4586s.sc.yh", "y + h >= Height", y + h); | ||
modm_assert((x % pixelsPerByte) == 0, "st4586s.sc.x%", "x is not a multiply of PBB", x); | ||
modm_assert((w % pixelsPerByte) == 0, "st4586s.sc.w%", "w is not a multiply of PBB", w); | ||
|
||
const payload::SetColumnRow columnRange(x / pixelsPerByte, (x + w) / pixelsPerByte - 1); | ||
sendCommand(Command::SetColumn, columnRange); | ||
|
||
const payload::SetColumnRow rowRange(y, y + h - 1); | ||
sendCommand(Command::SetRow, rowRange); | ||
} | ||
|
||
template <typename SPI, typename CS, typename RST, typename DC, int Width, int Height> | ||
void | ||
St7586s<SPI, CS, RST, DC, Width, Height>::update() | ||
{ | ||
sendCommand(Command::WriteDisplayData); | ||
CS::reset(); | ||
// TODO: support windows other than full screen (then make setClipping public) | ||
// TODO: transfer the whole memory area, not individual pixels | ||
for (uint16_t y = 0; y < Height; y++) { | ||
const uint8_t* row = this->buffer[y]; | ||
uint16_t currentByte = 0; | ||
uint8_t validBits = 0; | ||
for (uint16_t x = 0; x + 2 < Width; x += 3) { | ||
if (validBits < 3) { | ||
currentByte |= (*row++) << validBits; | ||
validBits += 8; | ||
} | ||
|
||
uint8_t cell = 0; | ||
if (currentByte & 0b001) cell |= (0b11 << 6); | ||
if (currentByte & 0b010) cell |= (0b11 << 3); | ||
if (currentByte & 0b100) cell |= (0b11 << 0); | ||
validBits -= 3; | ||
currentByte >>= 3; | ||
|
||
SPI::transferBlocking(cell); | ||
} | ||
} | ||
CS::set(); | ||
} | ||
|
||
} // namespace modm |
Oops, something went wrong.