Skip to content

Added file for 1.8 inch TFT Shield #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
*.mpy
.idea
__pycache__
_build
*.pyc
.env
build*
bundles
*.DS_Store
.eggs
dist
**/*.egg-info
100 changes: 100 additions & 0 deletions adafruit_seesaw/tftshield18.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Dean Miller for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods

from collections import namedtuple
import board
from micropython import const
from adafruit_seesaw.seesaw import Seesaw

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git"

_TIMER_BASE = const(0x08)
_TIMER_PWM = const(0x01)
_TIMER_FREQ = const(0x02)

_TFTSHIELD_RESET_PIN = const(3)

_BUTTON_UP = const(5)
_BUTTON_DOWN = const(8)
_BUTTON_LEFT = const(6)
_BUTTON_RIGHT = const(9)
_BUTTON_SELECT = const(7)
_BUTTON_A = const(10)
_BUTTON_B = const(11)
_BUTTON_C = const(14)

Buttons = namedtuple("Buttons", "right down left up select a b c")

class TFTShield18(Seesaw):

_BACKLIGHT_ON = b"\xFF\xFF"
_BACKLIGHT_OFF = b"\x00\x00"

_button_mask = ((1 << _BUTTON_RIGHT) |
(1 << _BUTTON_DOWN) |
(1 << _BUTTON_LEFT) |
(1 << _BUTTON_UP) |
(1 << _BUTTON_SELECT) |
(1 << _BUTTON_A) |
(1 << _BUTTON_B) |
(1 << _BUTTON_C))

def __init__(self, i2c_bus=board.I2C(), addr=0x2E):
super(TFTShield18, self).__init__(i2c_bus, addr)
self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT)
self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP)

def set_backlight(self, value):
"""
Set the backlight on
"""
if not isinstance(value, bool):
raise ValueError("Value must be of boolean type")
command = self._BACKLIGHT_ON if value else self._BACKLIGHT_OFF
self.write(_TIMER_BASE, _TIMER_PWM, b"\x00" + command)

def set_backlight_freq(self, freq):
"""
Set the backlight frequency of the TFT Display
"""
if not isinstance(freq, int):
raise ValueError("Value must be of integer type")
value = b"\x00" + bytearray((freq >> 8) & 0xFF, freq & 0xFF)
self.write(_TIMER_BASE, _TIMER_FREQ, value)

def tft_reset(self, rst=True):
"""
Reset the TFT Display
"""
self.digital_write(_TFTSHIELD_RESET_PIN, rst)

@property
def buttons(self):
"""
Return a set of buttons with current push values
"""
button_values = self.digital_read_bulk(self._button_mask)
return Buttons(*[not button_values & (1 << button) for button in
(_BUTTON_RIGHT, _BUTTON_DOWN, _BUTTON_LEFT, _BUTTON_UP,
_BUTTON_SELECT, _BUTTON_A, _BUTTON_B, _BUTTON_C)])