Skip to content

Commit 060752f

Browse files
authored
Merge pull request #39 from makermelissa/master
Added file for 1.8 inch TFT Shield
2 parents f1171f9 + bf78e7d commit 060752f

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
*.mpy
2+
.idea
13
__pycache__
24
_build
35
*.pyc
46
.env
57
build*
68
bundles
9+
*.DS_Store
10+
.eggs
11+
dist
12+
**/*.egg-info

adafruit_seesaw/tftshield18.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2018 Dean Miller for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods
23+
24+
from collections import namedtuple
25+
import board
26+
from micropython import const
27+
from adafruit_seesaw.seesaw import Seesaw
28+
29+
__version__ = "0.0.0-auto.0"
30+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"
31+
32+
_TIMER_BASE = const(0x08)
33+
_TIMER_PWM = const(0x01)
34+
_TIMER_FREQ = const(0x02)
35+
36+
_TFTSHIELD_RESET_PIN = const(3)
37+
38+
_BUTTON_UP = const(5)
39+
_BUTTON_DOWN = const(8)
40+
_BUTTON_LEFT = const(6)
41+
_BUTTON_RIGHT = const(9)
42+
_BUTTON_SELECT = const(7)
43+
_BUTTON_A = const(10)
44+
_BUTTON_B = const(11)
45+
_BUTTON_C = const(14)
46+
47+
Buttons = namedtuple("Buttons", "right down left up select a b c")
48+
49+
class TFTShield18(Seesaw):
50+
51+
_BACKLIGHT_ON = b"\xFF\xFF"
52+
_BACKLIGHT_OFF = b"\x00\x00"
53+
54+
_button_mask = ((1 << _BUTTON_RIGHT) |
55+
(1 << _BUTTON_DOWN) |
56+
(1 << _BUTTON_LEFT) |
57+
(1 << _BUTTON_UP) |
58+
(1 << _BUTTON_SELECT) |
59+
(1 << _BUTTON_A) |
60+
(1 << _BUTTON_B) |
61+
(1 << _BUTTON_C))
62+
63+
def __init__(self, i2c_bus=board.I2C(), addr=0x2E):
64+
super(TFTShield18, self).__init__(i2c_bus, addr)
65+
self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT)
66+
self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP)
67+
68+
def set_backlight(self, value):
69+
"""
70+
Set the backlight on
71+
"""
72+
if not isinstance(value, bool):
73+
raise ValueError("Value must be of boolean type")
74+
command = self._BACKLIGHT_ON if value else self._BACKLIGHT_OFF
75+
self.write(_TIMER_BASE, _TIMER_PWM, b"\x00" + command)
76+
77+
def set_backlight_freq(self, freq):
78+
"""
79+
Set the backlight frequency of the TFT Display
80+
"""
81+
if not isinstance(freq, int):
82+
raise ValueError("Value must be of integer type")
83+
value = b"\x00" + bytearray((freq >> 8) & 0xFF, freq & 0xFF)
84+
self.write(_TIMER_BASE, _TIMER_FREQ, value)
85+
86+
def tft_reset(self, rst=True):
87+
"""
88+
Reset the TFT Display
89+
"""
90+
self.digital_write(_TFTSHIELD_RESET_PIN, rst)
91+
92+
@property
93+
def buttons(self):
94+
"""
95+
Return a set of buttons with current push values
96+
"""
97+
button_values = self.digital_read_bulk(self._button_mask)
98+
return Buttons(*[not button_values & (1 << button) for button in
99+
(_BUTTON_RIGHT, _BUTTON_DOWN, _BUTTON_LEFT, _BUTTON_UP,
100+
_BUTTON_SELECT, _BUTTON_A, _BUTTON_B, _BUTTON_C)])

0 commit comments

Comments
 (0)