Skip to content

Commit 711f708

Browse files
committed
st7735s work in progress
1 parent f4b7d25 commit 711f708

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

ioio/samples/st7735s.bas

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
rem
2+
rem Educational BoosterPack MKII - Color TFT LCD Display
3+
rem
4+
rem The Crystalfontz CFAF128128B-0145T color 128x128-pixel TFT LCD supports display updates up to
5+
rem 20 frames per second (FPS) while only requiring a few lines to control the TFT LCD module through
6+
rem the SPI interface. This module has a color depth of 262K colors and a contrast ratio of 350.
7+
rem
8+
rem https://www.ti.com/tool/BOOSTXL-EDUMKII
9+
rem https://www.ti.com/document-viewer/lit/html/SLAU599B#GUID-3E8385B7-69DD-4133-9660-C9C256762AA8/TITLE-SLAU599SLAU5992619
10+
rem https://www.crystalfontz.com/product/cfaf128128b0145t-graphical-tft-128x128-lcd-display-module
11+
rem https://www.crystalfontz.com/controllers/Sitronix/ST7735S/
12+
rem https://github.com/crystalfontz/CFAF128128B1-0145T
13+
rem https://github.com/crystalfontz/CFAF128128B1-0145T/blob/master/CFAF128128B1-0145T_SPI_Demo_Code/CFAF128128B1-0145T_SPI_Demo_Code.ino
14+
rem
15+
16+
import ioio
17+
18+
const ST7735_SLPOUT 0x11
19+
const ST7735_DISPON 0x29
20+
const ST7735_CASET 0x2A
21+
const ST7735_RASET 0x2B
22+
const ST7735_RAMWR 0x2C
23+
const ST7735_RAMRD 0x2E
24+
const ST7735_MADCTL 0x36
25+
const ST7735_COLMOD 0x3A
26+
const ST7735_FRMCTR1 0xB1
27+
const ST7735_FRMCTR2 0xB2
28+
const ST7735_FRMCTR3 0xB3
29+
const ST7735_INVCTR 0xB4
30+
const ST7735_PWCTR1 0xC0
31+
const ST7735_PWCTR2 0xC1
32+
const ST7735_PWCTR3 0xC2
33+
const ST7735_PWCTR4 0xC3
34+
const ST7735_PWCTR5 0xC4
35+
const ST7735_VMCTR1 0xC5
36+
const ST7735_GAMCTRP1 0xE0
37+
const ST7735_GAMCTRN1 0xE1
38+
39+
rem J2.15 - LCD SPI MOSI
40+
const mosiPin = 2
41+
42+
rem Unused - no data received from lcd
43+
const misoPin = 6
44+
45+
rem J2.13 - LCD SPI chip select CS
46+
rem Low: Controller chip is selected. Communications with host is possible.
47+
rem High: Controller chip is not selected. Host interface signals are ignored by the controller.
48+
const csPin = 3
49+
50+
' J1.7 - LCD SPI clock
51+
const clkPin = 4
52+
53+
' J4.31 - LCD register select pin
54+
const rsPin = 5
55+
56+
rem J4.17 - LCD reset pin
57+
rem Low: Display controller is reset. The RST pin should be pulsed low shortly after power is applied.
58+
rem High: The RST pin should be brought high (VDD) for normal operation.
59+
const rstPin = 7
60+
61+
rem J4.39 - LCD backlight (Pin is multiplexed with the RGB LED red channel pin through the jumper header J5)
62+
rem not implemented
63+
64+
const spi = ioio.openSpiMaster(misoPin, mosiPin, clkPin, csPin)
65+
const rsOut = ioio.openDigitalOutput(rsPin)
66+
const rstOut = ioio.openDigitalOutput(rstPin)
67+
68+
ioio.waitForConnect(10)
69+
70+
sub sendCommand(cmd)
71+
' Select the LCD's command register
72+
rsOut.write(0)
73+
spi.write(cmd)
74+
end
75+
76+
sub sendData(_data)
77+
rsOut.write(1)
78+
spi.write(_data)
79+
end
80+
81+
sub resetDisplay()
82+
rstOut.write(0)
83+
delay 50
84+
rstOut.write(1)
85+
delay 50
86+
end
87+
88+
sub initST7735S()
89+
resetDisplay()
90+
sendCommand(0x01) ' Software reset
91+
delay 150
92+
sendCommand(ST7735_SLPOUT)
93+
delay 255
94+
sendCommand(ST7735_DISPON)
95+
end
96+
97+
sub set_LCD_for_write_at_X_Y(x, y)
98+
rem CASET (2Ah): Column Address Set
99+
rem * The value of XS [15:0] and XE [15:0] are referred when RAMWR
100+
rem command comes.
101+
rem * Each value represents one column line in the Frame Memory.
102+
rem * XS [15:0] always must be equal to or less than XE [15:0]
103+
sendCommand(ST7735_CASET) ' Column address set
104+
rem Write the parameters for the "column address set" command
105+
'sendData(0x00) ' Start MSB = XS[15:8]
106+
'sendData(0x02 + x) ' Start LSB = XS[ 7:0]
107+
'sendData(0x00) ' End MSB = XE[15:8]
108+
'sendData(0x81) ' End LSB = XE[ 7:0]
109+
local _data = [0x00, 0x02 + x, 0x00, 0x81]
110+
sendData(_data)
111+
112+
rem Write the "row address set" command to the LCD
113+
rem RASET (2Bh): Row Address Set
114+
rem * The value of YS [15:0] and YE [15:0] are referred when RAMWR
115+
rem command comes.
116+
rem * Each value represents one row line in the Frame Memory.
117+
rem * YS [15:0] always must be equal to or less than YE [15:0]
118+
sendCommand(ST7735_RASET) ' Row address set
119+
120+
rem Write the parameters for the "row address set" command
121+
'sendData(0x00) ' Start MSB = YS[15:8]
122+
'sendData(0x01 + y) ' Start LSB = YS[ 7:0]
123+
'sendData(0x00) ' End MSB = YE[15:8]
124+
'sendData(0x80) ' End LSB = YE[ 7:0]
125+
_data = [0x00, 0x01 + y, 0x00, 0x80]
126+
sendData(_data)
127+
128+
rem Write the "write data" command to the LCD
129+
rem RAMWR (2Ch): Memory Write
130+
sendCommand(ST7735_RAMWR) ' write data
131+
end
132+
133+
rem Fill display with a given RGB value
134+
sub fill_LCD(r, g, b)
135+
local i, _data
136+
Set_LCD_for_write_at_X_Y(0, 0)
137+
138+
for i = 1 to 21
139+
_data << b
140+
_data << g
141+
_data << r
142+
next
143+
144+
rsOut.write(1)
145+
for i = 0 to (128 * 128) / 21
146+
spi.write(_data)
147+
next i
148+
end
149+
150+
rem/Write the single pixel's worth of data
151+
sub put_Pixel(x, y, r, g, b)
152+
Set_LCD_for_write_at_X_Y(x, y)
153+
sendData([b,g,r])
154+
end
155+
156+
initST7735S()
157+
fill_LCD(1, 212, 31)

0 commit comments

Comments
 (0)