-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathchardevice.h
125 lines (109 loc) · 3.68 KB
/
chardevice.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// chardevice.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2018-2024 R. Stange <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _display_chardevice_h
#define _display_chardevice_h
#include <circle/device.h>
#include <circle/i2cmaster.h>
#include <circle/spinlock.h>
#include <circle/types.h>
#define CHAR_MAX_COLUMNS 40
#define CHAR_MAX_ROWS 10
// ESCAPE SEQUENCES
//
// \E[B Cursor down one line
// \E[H Cursor home
// \E[A Cursor up one line
// \E[%d;%dH Cursor move to row %1 and column %2 (starting at 1)
// ^H Cursor left one character
// \E[D Cursor left one character
// \E[C Cursor right one character
// ^M Carriage return
// \E[J Clear to end of screen
// \E[K Clear to end of line
// \E[%dX Erase %1 characters starting at cursor
// ^J Carriage return/linefeed
// ^I Move to next hardware tab
// \E[?25h Normal cursor visible
// \E[?25l Cursor invisible
// \Ed+ Start autopage mode
// \Ed* End autopage mode
//
// ^X = Control character
// \E = Escape (\x1b)
// %d = Numerical parameter (ASCII)
class CCharDevice : public CDevice /// character based display driver
{
public:
/// \param nColumns Display size in number of columns (max. 40)
/// \param nRows Display size in number of rows (max. 4)
CCharDevice (unsigned nColumns, unsigned nRows);
~CCharDevice (void);
/// \return Operation successful?
boolean Initialize (void);
/// \return Display size in number of columns
unsigned GetColumns (void) const;
/// \return Display size in number of rows
unsigned GetRows (void) const;
/// \brief Write characters to the display
/// \note Supports several escape sequences (see above).
/// \param pBuffer Pointer to the characters to be written
/// \param nCount Number of characters to be written
/// \return Number of written characters
int Write (const void *pBuffer, size_t nCount);
private:
void Write (char chChar);
void CarriageReturn (void);
void ClearDisplayEnd (void);
void ClearLineEnd (void);
void CursorDown (void);
void CursorHome (void);
void CursorLeft (void);
void CursorMove (unsigned nRow, unsigned nColumn);
void CursorRight (void);
void CursorUp (void);
void DisplayChar (char chChar);
void EraseChars (unsigned nCount);
void NewLine (void);
void SetAutoPageMode (boolean bEnable);
void SetCursorMode (boolean bVisible);
void Tabulator (void);
void Scroll (void);
void SetChar (unsigned nPosX, unsigned nPosY, char chChar);
void SetCursor (void);
/// Device specific routines to be provided by derived classes for each device
virtual void DevClearCursor (void) = 0;
virtual void DevSetCursor (unsigned nCursorX, unsigned nCursorY) = 0;
virtual void DevSetCursorMode (boolean bVisible) = 0;
virtual void DevSetChar (unsigned nPosX, unsigned nPosY, char chChar) = 0;
virtual void DevUpdateDisplay (void) = 0;
private:
unsigned m_nColumns;
unsigned m_nRows;
unsigned m_nState;
unsigned m_nCursorX;
unsigned m_nCursorY;
boolean m_bCursorOn;
unsigned m_nParam1;
unsigned m_nParam2;
boolean m_bAutoPage;
char m_Buffer[CHAR_MAX_ROWS][CHAR_MAX_COLUMNS];
CSpinLock m_SpinLock;
};
#endif