Skip to content

Commit 63f4682

Browse files
committed
Stuff 'n' things
1 parent 2ec1822 commit 63f4682

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2020 Tara Keeling
2+
//
3+
// This software is released under the MIT License.
4+
// https://opensource.org/licenses/MIT
5+
#include <Arduino.h>
6+
#include <SPI.h>
7+
#include <Adafruit_GFX.h>
8+
#include <Adafruit_ST7789.h>
9+
10+
#include <subpixie.h>
11+
12+
// Uncomment the line below if your display uses a BGR subpixel order.
13+
// A good way of telling is if the text looks awful.
14+
// #include <subpixie_bgr.h>
15+
16+
static const int Pin_CS = -1;
17+
static const int Pin_DC = PD3;
18+
static const int Pin_RST = PD2;
19+
20+
Adafruit_ST7789 LCD = Adafruit_ST7789( Pin_CS, Pin_DC, Pin_RST );
21+
22+
// Wrapper around Adafruit's setAddrWindow
23+
void Adafruit_SetAddressWindow( int x0, int y0, int x1, int y1 ) {
24+
// Since Adafruit's setAddrWindow expects a width and height for the 3rd and 4th parameter
25+
// calculate it from the screen space coordinates given by subpixie.
26+
LCD.setAddrWindow( x0, y0, ( x1 - x0 ), ( y1 - y0 ) );
27+
}
28+
29+
// Wrapper around Adafruit's writePixels
30+
void Adafruit_WritePixels( uint16_t* Buffer, size_t Count ) {
31+
LCD.startWrite( );
32+
LCD.writePixels( Buffer, Count, true, false );
33+
LCD.endWrite( );
34+
}
35+
36+
Subpixie Sub = Subpixie( 240, 240, &Font_8x8, true, Adafruit_SetAddressWindow, Adafruit_WritePixels );
37+
38+
void setup( void ) {
39+
SPI.begin( );
40+
LCD.init( 240, 240, 3 );
41+
}
42+
43+
void loop( void ) {
44+
LCD.fillScreen( 0 );
45+
LCD.setTextColor( 0xFFFF );
46+
47+
LCD.println( "Adafruit 6x8" );
48+
Sub.println( );
49+
Sub.println( "Subpixie 8x8(W)" );
50+
51+
Sub.SetFont( &Font_8x8, false );
52+
Sub.println( "Subpixie 8x8" );
53+
54+
Sub.SetFont( &Font_6x8, true );
55+
Sub.println( "Subpixie 6x8(W)" );
56+
57+
Sub.SetFont( &Font_6x8, false );
58+
Sub.println( "Subpixie 6x8" );
59+
60+
while ( true ) {
61+
}
62+
}

subpixie.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const uint8_t* Subpixie::GetGlyphPtr( const uint8_t Char ) {
4848
return Ptr + ( ( c * RoundedWidth * _Font->Height ) );
4949
}
5050

51-
void Subpixie::DrawGlyph( const uint8_t Char, int x, int y ) {
51+
void Subpixie::DrawGlyph( const uint8_t Char, int x, int y, bool Inverse ) {
5252
if ( Char != CachedGlyph ) {
53-
_Font->Decode( GetGlyphPtr( Char ), GlyphCache, _Wide, _Inverse );
53+
_Font->Decode( GetGlyphPtr( Char ), GlyphCache, _Wide, Inverse );
5454
CachedGlyph = Char;
5555
}
5656

@@ -89,7 +89,7 @@ size_t Subpixie::write( const uint8_t Data ) {
8989
break;
9090
}
9191
default: {
92-
DrawGlyph( Data, PrintX, PrintY );
92+
DrawGlyph( Data, PrintX, PrintY, _Inverse );
9393

9494
PrintX+= GlyphWidth;
9595
break;

subpixie.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#define RGB565( r, g, b ) ( uint16_t ) ( ( r << 11 ) | ( g << 5 ) | ( b ) )
1919

20+
#define Glyph_Cache_Buffer_Size 8 * 8
21+
2022
/**
2123
* @brief Procedure to set the render window of the target LCD
2224
*
@@ -54,8 +56,16 @@ typedef struct {
5456
} Subpixie_Fontdef;
5557

5658
class Subpixie : public Print {
59+
protected:
60+
int _DisplayWidth = 0; /**< Width of target display */
61+
int _DisplayHeight = 0; /**< Height of target display */
62+
63+
int GlyphSize = 0; /**< Size in bytes of decoded character glyphs */
64+
int GlyphWidth = 0; /**< Width in pixels of decoded subpixel font */
65+
int GlyphHeight = 0; /**< Height of characters in font */
66+
5767
private:
58-
uint16_t GlyphCache[ 6 * 8 ]; /**< Space for decoded glyph data */
68+
uint16_t GlyphCache[ Glyph_Cache_Buffer_Size ]; /**< Space for decoded glyph data */
5969

6070
SetAddressWindowProc _SetAddressWindow; /**< Callback to function to set the render window of the target LCD */
6171
WritePixelsProc _WritePixels; /**< Callback to function to write pixels to the target LCD */
@@ -64,13 +74,6 @@ class Subpixie : public Print {
6474

6575
uint8_t CachedGlyph; /**< Value of last decoded character */
6676

67-
int _DisplayWidth = 0; /**< Width of target display */
68-
int _DisplayHeight = 0; /**< Height of target display */
69-
70-
int GlyphSize = 0; /**< Size in bytes of decoded character glyphs */
71-
int GlyphWidth = 0; /**< Width in pixels of decoded subpixel font */
72-
int GlyphHeight = 0; /**< Height of characters in font */
73-
7477
bool _Inverse; /**< If true, render fonts with the colour inverted */
7578
bool _Wide; /**< If true, render fonts twice as wide */
7679

@@ -135,8 +138,9 @@ class Subpixie : public Print {
135138
* @param Char Character to draw
136139
* @param x x
137140
* @param y y
141+
* @param Inverse Draw character with the colours inverted
138142
*/
139-
void DrawGlyph( const uint8_t Char, int x, int y );
143+
void DrawGlyph( const uint8_t Char, int x, int y, bool Inverse );
140144

141145
void SetInverse( bool Inverse );
142146

0 commit comments

Comments
 (0)