Skip to content

Commit

Permalink
- Added reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
teeminus committed Feb 4, 2021
1 parent f3448fb commit 290f78c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
1 change: 1 addition & 0 deletions include/St7920Emulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class St7920Emulator {
public:
St7920Emulator(void (*fClearDisplay)(void), void (*fDrawByte)(uint8_t, uint8_t, uint8_t));
void parseSerialData(uint8_t ui8Data);
void reset(bool bClearDisplay);

private:
enum St7920SyncByteType {
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ST7920Emulator",
"version": "1.0.1",
"version": "1.1",
"description": "Platform independent emulator library that parses ST7920 serial data and prints to external displays by invoking user supplied draw functions.",
"keywords": "ST7920, display, screen",
"repository":
Expand Down
77 changes: 44 additions & 33 deletions src/St7920Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,9 @@
St7920Emulator::St7920Emulator(void (*fClearDisplay)(void), void (*fDrawByte)(uint8_t, uint8_t, uint8_t)) :
fClearDisplay_(fClearDisplay),
fDrawByte_(fDrawByte)
{
// Init enums
lastCommand_ = CT_None;
dataTarget_ = DT_None;
syncByteType_ = SBT_None;

// Init byte decoding
ui8DataNibbleIdx_ = 0;
ui8DataByte_ = 0;

// Init variables set by commands
ui8EnableVerticalScroll_ = 0;
ui8ExtendedMode_ = 0;
ui8GraphicMode_ = 0;
ui8AddressX_ = 0;
ui8AddressY_ = 0;

// Init rams
for (uint8_t i = 0; i < 64; ++i) {
for (uint8_t j = 0; j < 2; ++j) {
pCgRam_[i][j] = 0;
}
}
for (uint8_t i = 0; i < 4; ++i) {
for (uint8_t j = 0; j < 32; ++j) {
pDdRam_[i][j] = 0;
}
}
for (uint8_t i = 0; i < 64; ++i) {
for (uint8_t j = 0; j < 16; ++j) {
pGdRam_[i][j] = 0;
}
}
{
// Reset everything
reset(true);
}

void St7920Emulator::parseCommandByte() {
Expand Down Expand Up @@ -355,6 +325,47 @@ uint8_t St7920Emulator::parseSyncByte(uint8_t ui8Data) {
return 0;
}

void St7920Emulator::reset(bool bClearDisplay) {
// Init enums
lastCommand_ = CT_None;
dataTarget_ = DT_None;
syncByteType_ = SBT_None;

// Init byte decoding
ui8DataNibbleIdx_ = 0;
ui8DataByte_ = 0;

// Init variables set by commands
ui8EnableVerticalScroll_ = 0;
ui8ExtendedMode_ = 0;
ui8GraphicMode_ = 0;
ui8AddressX_ = 0;
ui8AddressY_ = 0;

// Init rams
for (uint8_t i = 0; i < 64; ++i) {
for (uint8_t j = 0; j < 2; ++j) {
pCgRam_[i][j] = 0;
}
}
for (uint8_t i = 0; i < 4; ++i) {
for (uint8_t j = 0; j < 32; ++j) {
pDdRam_[i][j] = 0;
}
}
for (uint8_t i = 0; i < 64; ++i) {
for (uint8_t j = 0; j < 16; ++j) {
pGdRam_[i][j] = 0;
}
}

// Check if we shall clear the display area
if (bClearDisplay) {
// Clear display
fClearDisplay_();
}
}

void St7920Emulator::showByte(uint8_t x, uint8_t y) {
// Get DDRAM byte
uint8_t ui8DdRam;
Expand Down

0 comments on commit 290f78c

Please sign in to comment.