-
Notifications
You must be signed in to change notification settings - Fork 64
/
Adafruit_miniTFTWing.cpp
140 lines (115 loc) · 4.63 KB
/
Adafruit_miniTFTWing.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "Adafruit_miniTFTWing.h"
// These are the default SAMD09 version pins! (for back compatibility)
uint8_t TFTWING_RESET_PIN = 8;
uint8_t TFTWING_BUTTON_UP_PIN = 2;
uint32_t TFTWING_BUTTON_UP = (1UL << TFTWING_BUTTON_UP_PIN);
uint8_t TFTWING_BUTTON_DOWN_PIN = 4;
uint32_t TFTWING_BUTTON_DOWN = (1UL << TFTWING_BUTTON_DOWN_PIN);
uint8_t TFTWING_BUTTON_LEFT_PIN = 3;
uint32_t TFTWING_BUTTON_LEFT = (1UL << TFTWING_BUTTON_LEFT_PIN);
uint8_t TFTWING_BUTTON_RIGHT_PIN = 7;
uint32_t TFTWING_BUTTON_RIGHT = (1UL << TFTWING_BUTTON_RIGHT_PIN);
uint8_t TFTWING_BUTTON_SELECT_PIN = 11;
uint32_t TFTWING_BUTTON_SELECT = (1UL << TFTWING_BUTTON_SELECT_PIN);
uint8_t TFTWING_BUTTON_A_PIN = 10;
uint32_t TFTWING_BUTTON_A = (1UL << TFTWING_BUTTON_A_PIN);
uint8_t TFTWING_BUTTON_B_PIN = 9;
uint32_t TFTWING_BUTTON_B = (1UL << TFTWING_BUTTON_B_PIN);
uint32_t TFTWING_BUTTON_ALL =
(TFTWING_BUTTON_UP | TFTWING_BUTTON_DOWN | TFTWING_BUTTON_LEFT |
TFTWING_BUTTON_RIGHT | TFTWING_BUTTON_SELECT | TFTWING_BUTTON_A |
TFTWING_BUTTON_B);
/**************************************************************************/
/*!
@brief set up the miniTFTWing
@param addr optional address the seesaw chip can be found on
@param Wi optional alternative I2C port to use, e.g. &Wire1 etc. Defaults
to &Wire
@returns true on success, false on error
*/
/**************************************************************************/
bool Adafruit_miniTFTWing::begin(uint8_t addr, TwoWire *Wi) {
if (Wi != NULL) {
Adafruit_seesaw::_i2cbus = Wi;
}
if (!Adafruit_seesaw::begin(addr, -1)) {
return false;
}
if ((getVersion() >> 16) == 3322) {
// check if we have a product ID burned in, if so its the ATtiny816 version!
TFTWING_BUTTON_UP_PIN = 16;
TFTWING_BUTTON_UP = (1UL << TFTWING_BUTTON_UP_PIN);
TFTWING_BUTTON_DOWN_PIN = 13;
TFTWING_BUTTON_DOWN = (1UL << TFTWING_BUTTON_DOWN_PIN);
TFTWING_BUTTON_LEFT_PIN = 12;
TFTWING_BUTTON_LEFT = (1UL << TFTWING_BUTTON_LEFT_PIN);
TFTWING_BUTTON_RIGHT_PIN = 14;
TFTWING_BUTTON_RIGHT = (1UL << TFTWING_BUTTON_RIGHT_PIN);
TFTWING_BUTTON_SELECT_PIN = 15;
TFTWING_BUTTON_SELECT = (1UL << TFTWING_BUTTON_SELECT_PIN);
TFTWING_BUTTON_A_PIN = 11;
TFTWING_BUTTON_A = (1UL << TFTWING_BUTTON_A_PIN);
TFTWING_BUTTON_B_PIN = 10;
TFTWING_BUTTON_B = (1UL << TFTWING_BUTTON_B_PIN);
TFTWING_BUTTON_ALL =
(TFTWING_BUTTON_UP | TFTWING_BUTTON_DOWN | TFTWING_BUTTON_LEFT |
TFTWING_BUTTON_RIGHT | TFTWING_BUTTON_SELECT | TFTWING_BUTTON_A |
TFTWING_BUTTON_B);
TFTWING_RESET_PIN = 6;
}
this->pinMode(TFTWING_RESET_PIN, OUTPUT);
this->pinModeBulk(TFTWING_BUTTON_ALL, INPUT_PULLUP);
return true;
}
/**************************************************************************/
/*!
@brief set the value of the backlight
@param value the backlight value to set NOTE: 0xFFFF is all the way on
0x0000 is off.
*/
/**************************************************************************/
void Adafruit_miniTFTWing::setBacklight(uint16_t value) {
if ((getVersion() >> 16) == 3322) {
// this->analogWrite(7, value);
this->pinMode(7, OUTPUT);
if (value == TFTWING_BACKLIGHT_ON) {
this->digitalWrite(7, LOW);
} else {
this->digitalWrite(7, HIGH);
}
} else {
uint8_t cmd[] = {0x00, (uint8_t)(value >> 8), (uint8_t)value};
this->write(SEESAW_TIMER_BASE, SEESAW_TIMER_PWM, cmd, 3);
}
}
/**************************************************************************/
/*!
@brief set the PWM frequency for the backlight
@param freq the frequency to set the backlight to
*/
/**************************************************************************/
void Adafruit_miniTFTWing::setBacklightFreq(uint16_t freq) {
if ((getVersion() >> 16) == 3322) {
} else {
uint8_t cmd[] = {0x0, (uint8_t)(freq >> 8), (uint8_t)freq};
this->write(SEESAW_TIMER_BASE, SEESAW_TIMER_FREQ, cmd, 3);
}
}
/**************************************************************************/
/*!
@brief reset the TFT screen by setting the value of the reset pin
@param rst the value to set the reset pin to
*/
/**************************************************************************/
void Adafruit_miniTFTWing::tftReset(bool rst) {
this->digitalWrite(TFTWING_RESET_PIN, rst);
}
/**************************************************************************/
/*!
@brief read all buttons on the wing and return as a 32 bit integer
@returns the value of the buttons
*/
/**************************************************************************/
uint32_t Adafruit_miniTFTWing::readButtons() {
return this->digitalReadBulk(TFTWING_BUTTON_ALL);
}