0:09
hello and welcome to controller Tech
0:12
this is the second video in the SDM 32
0:15
fsmc series connecting the LCD in
0:17
parallel mode and today we will add the
0:20
touch to our display in the previous
0:23
video we saw how to interface the LCD
0:25
using the fsmc peripheral and this video
0:28
will be the continuation of the previous
0:31
one actually I thought about making a
0:33
single video about adding touch and lvgl
0:36
to the display but the video was getting
0:38
too long so this video will just explain
0:42
how to add the touch interface to the
0:44
display and we will cover the lvgl in
0:48
video I am using the f412 discovery
0:51
board the LCD comes preattached to the
0:55
board here is the schematic of the LCD
0:58
connected to the board
1:01
we have covered the top half of this in
1:02
the previous video The Touch related
1:05
section is here towards the bottom the
1:08
touch controller is connected via the
1:10
i2c you can see the data pin is
1:12
connected to the I2 C1 data pin and the
1:15
clock pin is connected to the I2 C1
1:18
clock pin there is also an interrupt pin
1:21
where the interrupt is generated
1:23
whenever the touch is
1:25
detected we will not use the interrupt
1:28
so let's not worry about this pin the
1:31
touch reset pin is connected to the pin
1:33
pf12 we will use this pin to reset the
1:37
controller we will continue editing the
1:42
itself here is the project we worked
1:46
video Let's Open the cube MX to
1:50
controller now enable the I2 C1 for the
1:54
controller here the pin pv6 and pv7 got
1:58
selected these are the same pins which
2:02
schematic I am leaving the i2c
2:05
parameters to the default mode with the
2:09
khz now we will add the touch reset pin
2:12
so let's set the pin pf12 as the
2:15
output we will rename it to the CTP
2:19
reset that is all the configuration we
2:22
need click save to generate the
2:25
project let's add the touch library to
2:27
our project first the display uses the
2:31
ft6 by 06 touch controller and we can
2:34
find the library in the SDM 32 Cube
2:39
itself here you can see the folder for
2:43
06 let's copy these files to our desktop
2:50
first now let's copy these to the
2:53
project so copy the C file to the source
2:55
directory and head a file to the include
3:02
just like we defined the lcdi functions
3:05
in a separate file we need to define the
3:09
also so let's create a new header file
3:12
in the include directory and I am naming
3:17
touch. create a new source file in the
3:20
source directory and name it LCD touch.
3:23
C let's take a look at the ft6 by 06
3:27
source file once we are not using the
3:31
driver structure so let's comment it out
3:35
here inside the initialization function
3:37
you can see another function to
3:41
IO here is another touch IO read
3:44
function which we need to
3:46
Define we can find them all in the ft6
3:49
by 06 header file let's include the LCD
4:00
here you can see all the io functions
4:04
Define let's copy them in the LCD touch
4:07
header file but make sure to remove the
4:09
extern from them now we will write the
4:12
code for these functions in the LCD
4:14
touch source file let's start with the
4:17
initialization function first just like
4:21
we initialized the LCD here also we will
4:24
first reset the touch reset pin and then
4:27
after some delay set the pin again
4:31
the next is the touch IO right function
4:34
which will be used to send the data to
4:37
the touch controller since the
4:39
controller uses the i2c let's first
4:42
Define the i2c handle type def as the
4:45
external variable now we will call the
4:48
function Holly 2 cm right to write the
4:51
data to the register the device address
4:54
will be passed from the function
4:55
parameter the memory address is the
4:57
register memory address size is 1 by
5:00
long the data here is the value
5:02
parameter data size is 1 bite and let's
5:05
set the time out to 100
5:08
milliseconds next we have the touch iio
5:10
function to read the data from the
5:13
register here we will call the function
5:15
Holly 2cm read to read the data from the
5:19
register let's first Define a variable
5:22
where the data will be
5:24
stored the parameters will mostly be the
5:28
same in the data parameter we will pass
5:31
the address of the variable we defined
5:33
and we are reading one bite of data
5:36
after the data is read return the data
5:40
next we have the function to read
5:43
bytes we will call the same function I
5:46
to see mem but this time the data
5:49
parameter will be the buffer from the
5:51
parameter and the size of the data will
5:54
parameter this function Returns the
5:57
whole status so we will just return the
6:03
value the last function we have is for
6:06
delay here we will just call the
6:09
function hall delay and pass the
6:16
function that is all we need to do let's
6:19
write the main function now in the main
6:22
file include the ft6 by 06 head of
6:28
file in the main function initialize the
6:33
06 here we need to input the device
6:36
address but we don't have
6:38
one actually I couldn't find the device
6:41
address in the ft6 by 06 data sheet also
6:45
but you can still find the address in
6:49
org here you can find the device
6:52
addresses for almost all the i2c
6:55
devices just search for ft6 by 06 X you
7:01
can see the device address is 38 hex but
7:04
this is the 7 bit address the whole
7:07
Library uses the 8 Bits address so we
7:10
need to shift this address to the left
7:12
by one place this makes our slave
7:17
hex next we will call the function TS
7:21
start and pass the same address
7:31
let me call this fill function in the
7:33
main section so that we have some color
7:36
in the background now let's comment out
7:39
these functions in the while loop
7:41
instead we will call the function to
7:47
touch this function returns Z 1 or two
7:52
based on the number of touches being
7:54
detected basically if it detects the
7:56
touch this function will return anything
7:59
other than zero and if it does we will
8:02
call the function get XY to get the
8:05
coordinates the parameters of this
8:07
function are the pointers to the X and Y
8:09
coordinates so we will pass the
8:11
addresses of the raw X and raw y
8:14
variables let's give a delay of 100
8:17
milliseconds between each call to the
8:19
function we need to Define these
8:22
variables so let's define them here
8:34
let's build the project once we got some
8:38
errors let me comment out this part as
8:41
we are not using the driver structure or
8:44
right the project builds fine now so
8:47
let's Flash and debug it here I have
8:51
added the variables in the live
8:54
expression let's run the debugger now
8:58
here you can see the screen is filled
9:00
with red color now I am touching this
9:03
corner and you can see the X and Y
9:05
coordinates with respect to it this is
9:08
basically the start of the
9:10
screen now I am touching towards the
9:15
X here you can see the x coordinate is
9:18
239 while the Y is pretty much the same
9:23
next point is the extreme y but X should
9:26
small and finally I am touching the X X
9:31
extremes now I am moving my finger
9:34
diagonally and you can see that both
9:38
symmetrically so the touch is working
9:41
fine we don't need to use the interrupts
9:44
both lvgl and touch gfx do not use it
9:48
instead they do this reading
9:49
continuously just like what we did here
9:53
in the next video we will add the lvgl
9:55
to this project and create a simple
10:01
today I hope you understood how to
10:04
implement the touch to the fsmc display
10:08
you can download the code from the link
10:11
description leave comments in case of
10:14
any doubt keep watching and have a nice