2727 https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2828
2929"""
30+ import time
31+
3032try :
3133 from typing import Optional
3234 import busio
4143
4244
4345class Character_LCD_I2C (Character_LCD_Mono ):
44- # pylint: disable=too-few-public-methods, too-many-arguments
46+ # pylint: disable=too-few-public-methods
4547 """Character LCD connected to I2C/SPI backpack using its I2C connection.
4648 This is a subclass of `Character_LCD_Mono` and implements all the same
4749 functions and functionality.
@@ -57,6 +59,7 @@ class Character_LCD_I2C(Character_LCD_Mono):
5759 lcd = Character_LCD_I2C(i2c, 16, 2)
5860 """
5961
62+ # pylint: disable=too-many-positional-arguments
6063 def __init__ (
6164 self ,
6265 i2c : busio .I2C ,
@@ -71,18 +74,51 @@ def __init__(
7174 """
7275
7376 if address :
74- mcp = MCP23008 (i2c , address = address )
77+ self . mcp = MCP23008 (i2c , address = address )
7578 else :
76- mcp = MCP23008 (i2c )
79+ self . mcp = MCP23008 (i2c )
7780 super ().__init__ (
78- mcp .get_pin (1 ),
79- mcp .get_pin (2 ),
80- mcp .get_pin (3 ),
81- mcp .get_pin (4 ),
82- mcp .get_pin (5 ),
83- mcp .get_pin (6 ),
81+ self . mcp .get_pin (1 ), # reset
82+ self . mcp .get_pin (2 ), # enable
83+ self . mcp .get_pin (3 ), # data line 4
84+ self . mcp .get_pin (4 ), # data line 5
85+ self . mcp .get_pin (5 ), # data line 6
86+ self . mcp .get_pin (6 ), # data line 7
8487 columns ,
8588 lines ,
86- backlight_pin = mcp .get_pin (7 ),
89+ backlight_pin = self . mcp .get_pin (7 ),
8790 backlight_inverted = backlight_inverted ,
8891 )
92+
93+ def _write8 (self , value : int , char_mode : bool = False ) -> None :
94+ # Sends 8b ``value`` in ``char_mode``.
95+ # :param value: bytes
96+ # :param char_mode: character/data mode selector. False (default) for
97+ # data only, True for character bits.
98+ # one ms delay to prevent writing too quickly.
99+ time .sleep (0.001 )
100+
101+ # bits are, MSB (7) to LSB (0)
102+ # backlight: bit 7
103+ # data line 7: bit 6
104+ # data line 6: bit 5
105+ # data line 5: bit 4
106+ # data line 4: bit 3
107+ # enable: bit 2
108+ # reset: bit 1
109+ # (unused): bit 0
110+
111+ reset_bit = int (char_mode ) << 1
112+ backlight_bit = int (self .backlight ^ self .backlight_inverted ) << 7
113+
114+ # Write char_mode and upper 4 bits of data, shifted to the correct position.
115+ self .mcp .gpio = reset_bit | backlight_bit | ((value & 0xF0 ) >> 1 )
116+
117+ # do command
118+ self ._pulse_enable ()
119+
120+ # Write char_mode and lower 4 bits of data, shifted to the correct position.
121+ self .mcp .gpio = reset_bit | backlight_bit | ((value & 0x0F ) << 3 )
122+
123+ # do command
124+ self ._pulse_enable ()
0 commit comments