Skip to content

Commit e72e343

Browse files
committed
docs: Add documentation for lcd160cr module.
1 parent 43d9f99 commit e72e343

File tree

3 files changed

+378
-0
lines changed

3 files changed

+378
-0
lines changed

docs/library/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ the following libraries.
170170
:maxdepth: 2
171171

172172
pyb.rst
173+
lcd160cr.rst
173174

174175
.. only:: port_wipy
175176

docs/library/lcd160cr.rst

Lines changed: 376 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,376 @@
1+
:mod:`lcd160cr` --- control of LCD160CR display
2+
===============================================
3+
4+
.. module:: lcd160cr
5+
:synopsis: control of LCD160CR display
6+
7+
This module provides control of the MicroPython LCD160CR display.
8+
9+
.. image:: http://micropython.org/resources/LCD160CRv10-persp.jpg
10+
:alt: LCD160CRv1.0 picture
11+
:width: 640px
12+
13+
Further resources are available via the following links:
14+
15+
* `LCD160CRv1.0 reference manual <http://micropython.org/resources/LCD160CRv10-refmanual.pdf>`_ (100KiB PDF)
16+
* `LCD160CRv1.0 schematics <http://micropython.org/resources/LCD160CRv10-schematics.pdf>`_ (1.6MiB PDF)
17+
18+
class LCD160CR
19+
--------------
20+
21+
The LCD160CR class provides an interface to the display. Create an
22+
instance of this class and use its methods to draw to the LCD and get
23+
the status of the touch panel.
24+
25+
For example::
26+
27+
import lcd160cr
28+
29+
lcd = lcd160cr.LCD160CR('X')
30+
lcd.set_orient(lcd160cr.PORTRAIT)
31+
lcd.set_pos(0, 0)
32+
lcd.set_text_color(lcd.rgb(255, 0, 0), lcd.rgb(0, 0, 0))
33+
lcd.set_font(1)
34+
lcd.write('Hello MicroPython!')
35+
print('touch:', lcd.get_touch())
36+
37+
Constructors
38+
------------
39+
40+
.. class:: LCD160CR(connect=None, \*, pwr=None, i2c=None, spi=None, i2c_addr=98)
41+
42+
Construct an LCD160CR object. The parameters are:
43+
44+
- `connect` is a string specifying the physical connection of the LCD
45+
display to the board; valid values are "X", "Y", "XY", "YX".
46+
Use "X" when the display is connected to a pyboard in the X-skin
47+
position, and "Y" when connected in the Y-skin position. "XY"
48+
and "YX" are used when the display is connected to the right or
49+
left side of the pyboard, respectively.
50+
- `pwr` is a Pin object connected to the LCD's power/enabled pin.
51+
- `i2c` is an I2C object connected to the LCD's I2C interface.
52+
- `spi` is an SPI object connected to the LCD's SPI interface.
53+
- `i2c_addr` is the I2C address of the display.
54+
55+
One must specify either a valid `connect` or all of `pwr`, `i2c` and `spi`.
56+
If a valid `connect` is given then any of `pwr`, `i2c` or `spi` which are
57+
not passed as parameters (ie they are `None`) will be created based on the
58+
value of `connect`. This allows to override the default interface to the
59+
display if needed.
60+
61+
The default values are:
62+
63+
- "X" is for the X-skin and uses:
64+
``pwr=Pin("X4")``, ``i2c=I2C("X")``, ``spi=SPI("X")``
65+
- "Y" is for the Y-skin and uses:
66+
``pwr=Pin("Y4")``, ``i2c=I2C("Y")``, ``spi=SPI("Y")``
67+
- "XY" is for the right-side and uses:
68+
``pwr=Pin("X4")``, ``i2c=I2C("Y")``, ``spi=SPI("X")``
69+
- "YX" is for the left-side and uses:
70+
``pwr=Pin("Y4")``, ``i2c=I2C("X")``, ``spi=SPI("Y")``
71+
72+
Static methods
73+
--------------
74+
75+
.. staticmethod:: LCD160CR.rgb(r, g, b)
76+
77+
Return a 16-bit integer representing the given rgb color values. The
78+
16-bit value can be used to set the font color (see
79+
:meth:`LCD160CR.set_text_color`) pen color (see :meth:`LCD160CR.set_pen`)
80+
and draw individual pixels.
81+
82+
.. staticmethod:: LCD160CR.clip_line(data, w, h):
83+
84+
Clip the given line data. This is for internal use.
85+
86+
Instance members
87+
----------------
88+
89+
The following instance members are publicly accessible.
90+
91+
.. data:: LCD160CR.w
92+
.. data:: LCD160CR.h
93+
94+
The width and height of the display, respectively, in pixels. These
95+
members are updated when calling :meth:`LCD160CR.set_orient` and should
96+
be considered read-only.
97+
98+
Setup commands
99+
--------------
100+
101+
.. method:: LCD160CR.set_power(on)
102+
103+
Turn the display on or off, depending on the given value.
104+
105+
.. method:: LCD160CR.set_orient(orient)
106+
107+
Set the orientation of the display. The `orient` parameter can be one
108+
of `PORTRAIT`, `LANDSCAPE`, `PORTRAIT_UPSIDEDOWN`, `LANDSCAPE_UPSIDEDOWN`.
109+
110+
.. method:: LCD160CR.set_brightness(value)
111+
112+
Set the brightness of the display, between 0 and 255.
113+
114+
.. method:: LCD160CR.set_i2c_addr(addr)
115+
116+
Set the I2C address of the display. The `addr` value must have the
117+
lower 2 bits cleared.
118+
119+
.. method:: LCD160CR.set_uart_baudrate(baudrate)
120+
121+
Set the baudrate of the UART interface.
122+
123+
.. method:: LCD160CR.set_startup_deco(value)
124+
125+
Set the start-up decoration of the display. The `value` parameter can be a
126+
logical or of `STARTUP_DECO_NONE`, `STARTUP_DECO_MLOGO`, `STARTUP_DECO_INFO`.
127+
128+
.. method:: LCD160CR.save_to_flash()
129+
130+
Save the following parameters to flash so they persist on restart and power up:
131+
initial decoration, orientation, brightness, UART baud rate, I2C address.
132+
133+
Pixel access methods
134+
--------------------
135+
136+
The following methods manipulate individual pixels on the display.
137+
138+
.. method:: LCD160CR.set_pixel(x, y, c)
139+
140+
Set the specified pixel to the given color. The color should be a 16-bit
141+
integer and can be created by :meth:`LCD160CR.rgb`.
142+
143+
.. method:: LCD160CR.get_pixel(x, y)
144+
145+
Get the 16-bit value of the specified pixel.
146+
147+
.. method:: LCD160CR.get_line(x, y, buf)
148+
149+
Get a line of pixels into the given buffer.
150+
151+
.. method:: LCD160CR.screen_dump(buf)
152+
153+
Dump the entire screen to the given buffer.
154+
155+
.. method:: LCD160CR.screen_load(buf)
156+
157+
Load the entire screen from the given buffer.
158+
159+
Drawing text
160+
------------
161+
162+
To draw text one sets the position, color and font, and then uses
163+
`write` to draw the text.
164+
165+
.. method:: LCD160CR.set_pos(x, y)
166+
167+
Set the position for text output using :meth:`LCD160CR.write`. The position
168+
is the upper-left corner of the text.
169+
170+
.. method:: LCD160CR.set_text_color(fg, bg)
171+
172+
Set the foreground and background color of the text.
173+
174+
.. method:: LCD160CR.set_font(font, scale=0, bold=0, trans=0, scroll=0)
175+
176+
Set the font for the text. Subsequent calls to `write` will use the newly
177+
configured font. The parameters are:
178+
179+
- `font` is the font family to use, valid values are 0, 1, 2, 3.
180+
- `scale` is a scaling value for each character pixel, where the pixels
181+
are drawn as a square with side length equal to `scale + 1`. The value
182+
can be between 0 and 63.
183+
- `bold` controls the number of pixels to overdraw each character pixel,
184+
making a bold effect. The lower 2 bits of `bold` are the number of
185+
pixels to overdraw in the horizontal direction, and the next 2 bits are
186+
for the vertical direction. For example, a `bold` value of 5 will
187+
overdraw 1 pixel in both the horizontal and vertical directions.
188+
- `trans` can be either 0 or 1 and if set to 1 the characters will be
189+
drawn with a transparent background.
190+
- `scroll` can be either 0 or 1 and if set to 1 the display will do a
191+
soft scroll if the text moves to the next line.
192+
193+
.. method:: LCD160CR.write(s)
194+
195+
Write text to the display, using the current position, color and font.
196+
As text is written the position is automatically incremented. The
197+
display supports basic VT100 control codes such as newline and backspace.
198+
199+
Drawing primitive shapes
200+
------------------------
201+
202+
Primitive drawing commands use a foreground and background color set by the
203+
`set_pen` method.
204+
205+
.. method:: LCD160CR.set_pen(line, fill)
206+
207+
Set the line and fill color for primitive shapes.
208+
209+
.. method:: LCD160CR.erase()
210+
211+
Erase the entire display to the pen fill color.
212+
213+
.. method:: LCD160CR.dot(x, y)
214+
215+
Draw a single pixel at the given location using the pen line color.
216+
217+
.. method:: LCD160CR.rect(x, y, w, h)
218+
.. method:: LCD160CR.rect_outline(x, y, w, h)
219+
.. method:: LCD160CR.rect_interior(x, y, w, h)
220+
221+
Draw a rectangle at the given location and size using the pen line
222+
color for the outline, and the pen fill color for the interior.
223+
The `rect` method draws the outline and interior, while the other methods
224+
just draw one or the other.
225+
226+
.. method:: LCD160CR.line(x1, y1, x2, y2)
227+
228+
Draw a line between the given coordinates using the pen line color.
229+
230+
.. method:: LCD160CR.dot_no_clip(x, y)
231+
.. method:: LCD160CR.rect_no_clip(x, y, w, h)
232+
.. method:: LCD160CR.rect_outline_no_clip(x, y, w, h)
233+
.. method:: LCD160CR.rect_interior_no_clip(x, y, w, h)
234+
.. method:: LCD160CR.line_no_clip(x1, y1, x2, y2)
235+
236+
These methods are as above but don't do any clipping on the input
237+
coordinates. They are faster than the clipping versions and can be
238+
used when you know that the coordinates are within the display.
239+
240+
.. method:: LCD160CR.poly_dot(data)
241+
242+
Draw a sequence of dots using the pen line color.
243+
The `data` should be a buffer of bytes, with each successive pair of
244+
bytes corresponding to coordinate pairs (x, y).
245+
246+
.. method:: LCD160CR.poly_line(data)
247+
248+
Similar to :meth:`LCD160CR.poly_dot` but draws lines between the dots.
249+
250+
Touch screen methods
251+
--------------------
252+
253+
.. method:: LCD160CR.touch_config(calib=False, save=False, irq=None)
254+
255+
Configure the touch panel:
256+
257+
- If `calib` is `True` then the call will trigger a touch calibration of
258+
the resistive touch sensor. This requires the user to touch various
259+
parts of the screen.
260+
- If `save` is `True` then the touch parameters will be saved to NVRAM
261+
to persist across reset/power up.
262+
- If `irq` is `True` then the display will be configured to pull the IRQ
263+
line low when a touch force is detected. If `irq` is `False` then this
264+
feature is disabled. If `irq` is `None` (the default value) then no
265+
change is made to this setting.
266+
267+
.. method:: LCD160CR.is_touched()
268+
269+
Returns a boolean: `True` if there is currently a touch force on the screen,
270+
`False` otherwise.
271+
272+
.. method:: LCD160CR.get_touch()
273+
274+
Returns a 3-tuple of: (active, x, y). If there is currently a touch force
275+
on the screen then `active` is 1, otherwise it is 0. The `x` and `y` values
276+
indicate the position of the current or most recent touch.
277+
278+
Advanced commands
279+
-----------------
280+
281+
.. method:: LCD160CR.set_spi_win(x, y, w, h)
282+
283+
Set the window that SPI data is written to.
284+
285+
.. method:: LCD160CR.fast_spi(flush=True)
286+
287+
Ready the display to accept RGB pixel data on the SPI bus, resetting the location
288+
of the first byte to go to the top-left corner of the window set by
289+
:meth:`LCD160CR.set_spi_win`.
290+
The method returns an SPI object which can be used to write the pixel data.
291+
292+
Pixels should be sent as 16-bit RGB values in the 5-6-5 format. The destination
293+
counter will increase as data is sent, and data can be sent in arbitrary sized
294+
chunks. Once the destination counter reaches the end of the window specified by
295+
:meth:`LCD160CR.set_spi_win` it will wrap around to the top-left corner of that window.
296+
297+
.. method:: LCD160CR.show_framebuf(buf)
298+
299+
Show the given buffer on the display. `buf` should be an array of bytes containing
300+
the 16-bit RGB values for the pixels, and they will be written to the area
301+
specified by :meth:`LCD160CR.set_spi_win`, starting from the top-left corner.
302+
303+
.. method:: LCD160CR.set_scroll(on)
304+
305+
Turn scrolling on or off. This controls globally whether any window regions will
306+
scroll.
307+
308+
.. method:: LCD160CR.set_scroll_win(win, x=-1, y=0, w=0, h=0, vec=0, pat=0, fill=0x07e0, color=0)
309+
310+
Configure a window region for scrolling:
311+
312+
- `win` is the window id to configure. There are 0..7 standard windows for
313+
general purpose use. Window 8 is the text scroll window (the ticker).
314+
- `x`, `y`, `w`, `h` specify the location of the window in the display.
315+
- `vec` specifies the direction and speed of scroll: it is a 16-bit value
316+
of the form ``0bF.ddSSSSSSSSSSSS``. `dd` is 0, 1, 2, 3 for +x, +y, -x,
317+
-y scrolling. `F` sets the speed format, with 0 meaning that the window
318+
is shifted `S % 256` pixel every frame, and 1 meaning that the window
319+
is shifted 1 pixel every `S` frames.
320+
- `pat` is a 16-bit pattern mask for the background.
321+
- `fill` is the fill color.
322+
- `color` is the extra color, either of the text or pattern foreground.
323+
324+
.. method:: LCD160CR.set_scroll_win_param(win, param, value)
325+
326+
Set a single parameter of a scrolling window region:
327+
328+
- `win` is the window id, 0..8.
329+
- `param` is the parameter number to configure, 0..7, and corresponds
330+
to the parameters in the `set_scroll_win` method.
331+
- `value` is the value to set.
332+
333+
.. method:: LCD160CR.set_scroll_buf(s)
334+
335+
Set the string for scrolling in window 8. The parameter `s` must be a string
336+
with length 32 or less.
337+
338+
.. method:: LCD160CR.jpeg(buf)
339+
340+
Display a JPEG. `buf` should contain the entire JPEG data.
341+
The origin of the JPEG is set by :meth:`LCD160CR.set_pos`.
342+
343+
.. method:: LCD160CR.jpeg_start(total_len)
344+
.. method:: LCD160CR.jpeg_data(buf)
345+
346+
Display a JPEG with the data split across multiple buffers. There must be
347+
a single call to `jpeg_start` to begin with, specifying the total number of
348+
bytes in the JPEG. Then this number of bytes must be transferred to the
349+
display using one or more calls to the `jpeg_data` command.
350+
351+
.. method:: LCD160CR.feed_wdt()
352+
353+
The first call to this method will start the display's internal watchdog
354+
timer. Subsequent calls will feed the watchdog. The timeout is roughly 30
355+
seconds.
356+
357+
.. method:: LCD160CR.reset()
358+
359+
Reset the display.
360+
361+
Constants
362+
---------
363+
364+
.. data:: lcd160cr.PORTRAIT
365+
.. data:: lcd160cr.LANDSCAPE
366+
.. data:: lcd160cr.PORTRAIT_UPSIDEDOWN
367+
.. data:: lcd160cr.LANDSCAPE_UPSIDEDOWN
368+
369+
orientation of the display, used by :meth:`LCD160CR.set_orient`
370+
371+
.. data:: lcd160cr.STARTUP_DECO_NONE
372+
.. data:: lcd160cr.STARTUP_DECO_MLOGO
373+
.. data:: lcd160cr.STARTUP_DECO_INFO
374+
375+
type of start-up decoration, can be or'd together, used by
376+
:meth:`LCD160CR.set_startup_deco`

docs/pyboard/hardware/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ For the official skin modules:
1313

1414
* `LCD32MKv1.0 schematics <http://micropython.org/resources/LCD32MKv10-schematics.pdf>`_ (194KiB PDF)
1515
* `AMPv1.0 schematics <http://micropython.org/resources/AMPv10-schematics.pdf>`_ (209KiB PDF)
16+
* LCD160CRv1.0: see :mod:`lcd160cr`
1617

1718
Datasheets for the components on the pyboard
1819
============================================

0 commit comments

Comments
 (0)