Skip to content

Commit

Permalink
display: restore old viewtech display support
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Feb 20, 2024
1 parent 590d313 commit e874876
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/firmware/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if(NOT "PROJECT_TARGET_USB_OVER_SERIAL_HOST" IN_LIST PROJECT_TARGET_DEFINES)
target_sources(application
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/io/buttons/Buttons.cpp
${CMAKE_CURRENT_LIST_DIR}/io/touchscreen/model/viewtech/Viewtech.cpp
${CMAKE_CURRENT_LIST_DIR}/io/touchscreen/model/Builder.cpp
${CMAKE_CURRENT_LIST_DIR}/io/touchscreen/model/nextion/Nextion.cpp
${CMAKE_CURRENT_LIST_DIR}/io/touchscreen/Touchscreen.cpp
Expand Down
1 change: 1 addition & 0 deletions src/firmware/application/io/touchscreen/Touchscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace io
enum class model_t : uint8_t
{
NEXTION,
VIEWTECH,
AMOUNT
};

Expand Down
1 change: 1 addition & 0 deletions src/firmware/application/io/touchscreen/model/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using namespace io;

TouchscreenModelBuilder::TouchscreenModelBuilder(Touchscreen::HWA& hwa)
: _nextion(hwa)
, _viewtech(hwa)
{}

uint8_t Touchscreen::Model::_rxBuffer[Touchscreen::Model::BUFFER_SIZE];
Expand Down
4 changes: 3 additions & 1 deletion src/firmware/application/io/touchscreen/model/Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ limitations under the License.
#ifdef PROJECT_TARGET_SUPPORT_TOUCHSCREEN

#include "nextion/Nextion.h"
#include "viewtech/Viewtech.h"

namespace io
{
Expand All @@ -32,7 +33,8 @@ namespace io
TouchscreenModelBuilder(Touchscreen::HWA& hwa);

private:
Nextion _nextion;
Nextion _nextion;
Viewtech _viewtech;
};
} // namespace io
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains code support for Viewtech SDWe displays. Currently tested displays:

* SDWe101T09T (1024x600, 10", resistive touchscreen)
181 changes: 181 additions & 0 deletions src/firmware/application/io/touchscreen/model/viewtech/Viewtech.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
Copyright 2015-2022 Igor Petrovic
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifdef PROJECT_TARGET_SUPPORT_TOUCHSCREEN

#include "Viewtech.h"
#include "core/MCU.h"
#include "core/util/Util.h"

using namespace io;

Viewtech::Viewtech(io::Touchscreen::HWA& hwa)
: _hwa(hwa)
{
io::Touchscreen::registerModel(io::Touchscreen::model_t::VIEWTECH, this);
}

bool Viewtech::init()
{
Touchscreen::Model::_bufferCount = 0;

if (_hwa.init())
{
// add slight delay to ensure display can receive commands after power on
core::mcu::timing::waitMs(3000);

return true;
}

return false;
}

bool Viewtech::deInit()
{
return _hwa.deInit();
}

bool Viewtech::setScreen(size_t screenID)
{
screenID &= 0xFF;

_hwa.write(0xA5);
_hwa.write(0x5A);
_hwa.write(0x04);
_hwa.write(0x80);
_hwa.write(0x03);
_hwa.write(0x00);
_hwa.write(screenID);

return true;
}

Touchscreen::tsEvent_t Viewtech::update(Touchscreen::tsData_t& data)
{
auto event = Touchscreen::tsEvent_t::NONE;
uint8_t value = 0;

while (_hwa.read(value))
{
Touchscreen::Model::_rxBuffer[Touchscreen::Model::_bufferCount++] = value;
}

// assumption - only one response is received at the time
// if parsing fails, wipe the buffer
if (Touchscreen::Model::_bufferCount)
{
// verify header first
if (Touchscreen::Model::_rxBuffer[0] == 0xA5)
{
if (Touchscreen::Model::_bufferCount > 1)
{
if (Touchscreen::Model::_rxBuffer[1] == 0x5A)
{
if (Touchscreen::Model::_bufferCount > 2)
{
// byte at index 2 holds response length, without first two bytes and without byte at index 2
if (Touchscreen::Model::_bufferCount >= static_cast<size_t>(3 + Touchscreen::Model::_rxBuffer[2]))
{
uint32_t response = Touchscreen::Model::_rxBuffer[2];
response <<= 8;
response |= Touchscreen::Model::_rxBuffer[3];
response <<= 8;
response |= Touchscreen::Model::_rxBuffer[4];
response <<= 8;
response |= Touchscreen::Model::_rxBuffer[5];

switch (response)
{
case static_cast<uint32_t>(response_t::BUTTON_STATE_CHANGE):
{
data.buttonState = Touchscreen::Model::_rxBuffer[6];
data.buttonID = Touchscreen::Model::_rxBuffer[7];

event = Touchscreen::tsEvent_t::BUTTON;
}
break;

default:
break;
}

Touchscreen::Model::_bufferCount = 0;
}
}
}
else
{
// header invalid - ignore the rest of the message
Touchscreen::Model::_bufferCount = 0;
}
}
}
else
{
// header invalid - ignore the rest of the message
Touchscreen::Model::_bufferCount = 0;
}
}

return event;
}

void Viewtech::setIconState(Touchscreen::icon_t& icon, bool state)
{
// header
_hwa.write(0xA5);
_hwa.write(0x5A);

// request size
_hwa.write(0x05);

// write variable
_hwa.write(0x82);

// icon address - for viewtech displays, address is stored in xPos element
_hwa.write(core::util::MSB_U16(icon.xPos));
_hwa.write(core::util::LSB_U16(icon.xPos));

// value to set - 2 bytes are used, higher is always 0
// inverted logic for setting state - 0 means on state, 1 is off
_hwa.write(0x00);
_hwa.write(state ? 0x00 : 0x01);
}

bool Viewtech::setBrightness(Touchscreen::brightness_t brightness)
{
// header
_hwa.write(0xA5);
_hwa.write(0x5A);

// request size
_hwa.write(0x03);

// register write
_hwa.write(0x80);

// brightness settting
_hwa.write(0x01);

// brightness value
_hwa.write(BRIGHTNESS_MAPPING[static_cast<uint8_t>(brightness)]);

return true;
}

#endif
55 changes: 55 additions & 0 deletions src/firmware/application/io/touchscreen/model/viewtech/Viewtech.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2015-2022 Igor Petrovic
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include <inttypes.h>
#include "application/io/touchscreen/Touchscreen.h"
#include "core/util/RingBuffer.h"

class Viewtech : public io::Touchscreen::Model
{
public:
Viewtech(io::Touchscreen::HWA& hwa);

bool init() override;
bool deInit() override;
bool setScreen(size_t screenID) override;
io::Touchscreen::tsEvent_t update(io::Touchscreen::tsData_t& data) override;
void setIconState(io::Touchscreen::icon_t& icon, bool state) override;
bool setBrightness(io::Touchscreen::brightness_t brightness) override;

private:
enum class response_t : uint32_t
{
BUTTON_STATE_CHANGE = 0x05820002
};

io::Touchscreen::HWA& _hwa;

// there are 7 levels of brighness - scale them to available range (0-64)
static constexpr uint8_t BRIGHTNESS_MAPPING[7] = {
6,
16,
32,
48,
51,
58,
64
};
};
1 change: 1 addition & 0 deletions src/firmware/application/io/touchscreen/stub/Touchscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace io
enum class model_t : uint8_t
{
NEXTION,
VIEWTECH,
AMOUNT
};

Expand Down
1 change: 1 addition & 0 deletions tests/src/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(NOT "PROJECT_TARGET_USB_OVER_SERIAL_HOST" IN_LIST PROJECT_TARGET_DEFINES)
${PROJECT_ROOT}/src/firmware/application/io/touchscreen/Touchscreen.cpp
${PROJECT_ROOT}/src/firmware/application/io/touchscreen/model/Builder.cpp
${PROJECT_ROOT}/src/firmware/application/io/touchscreen/model/nextion/Nextion.cpp
${PROJECT_ROOT}/src/firmware/application/io/touchscreen/model/viewtech/Viewtech.cpp
)

target_compile_definitions(system
Expand Down

0 comments on commit e874876

Please sign in to comment.