Skip to content

Commit

Permalink
Doc added
Browse files Browse the repository at this point in the history
  • Loading branch information
Srg213 committed Oct 3, 2022
1 parent 9659de7 commit 54ec04e
Show file tree
Hide file tree
Showing 10 changed files with 716 additions and 787 deletions.
17 changes: 11 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ name = "ft6x06"
version = "0.1.0"
edition = "2021"
authors = ["Shantanu Gaikwad"]
categories = ["embedded", "no-std"]
description = "A platform agnostic driver for the FT6x06 type touch screen driver used on STM32F413 board."
categories = ["embedded", "no-std", "hardware-support"]
description = "A platform agnostic driver for the FT6x06 type touch panel controller used on STM32F4 series board."
license = "MIT OR Apache-2.0"
repository = "https://github.com/Srg213/ft6x06"
keywords = [
"embedded-hal-driver",
"embedded-hal",
"FT6x06",
"touchscreen",
]
readme = "README.md"

[dependencies]
embedded-hal = "0.2.7"
Expand Down Expand Up @@ -42,10 +51,6 @@ name = "touch"
[[example]]
name = "multi_touch"

[[example]]
name = "gesture_control"
required-features = ["fsmc_lcd"]

[[example]]
name = "interface"
required-features = ["fsmc_lcd"]
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# FT6x06 driver

FT6x06 is Self-Capacitive Touch Panel Controller used on many boards manufactured by ST.
The FT6x06 Series ICs are single-chip capacitive touch panel controller ICs with a built-in 8 bit enhanced Micro-controller unit
(MCU).They adopt the self-capacitance technology, which supports single point and gesture touch. In conjunction with a
self-capacitive touch panel. This is built on top of embedded-hal and implements blocking::I2C module. The examples are built using

The FT6x06 series ICs include FT6206 /FT6306.

This repo also contains examples for FT6206 IC built on top of abstraction layer for STM32F4 devices-stm32f4xx-hal for the boards
STM32F412 and STM32F413 boards. Documentation of touchscreen controllers on this boards is not well written. I initially forked ft5336
repo written in rust and modified it to fit to ft6x06.
Other parts of this driver have been reverse-engineered from the code written in C by STMicroelectronics,
31 changes: 31 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());

// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
}
183 changes: 90 additions & 93 deletions examples/display_touch.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
// #![deny(warnings)]
#![no_main]
#![no_std]

#![allow(unused_variables)]

use cortex_m;
use cortex_m_rt::entry;
use rtt_target::{rprintln, rtt_init_print};
use stm32f4xx_hal::{
fsmc_lcd::{ FsmcLcd, LcdPins, Timing},
pac,
prelude::*,
rcc::{ Rcc},
};
#[cfg(feature = "stm32f412")]
use stm32f4xx_hal::fsmc_lcd::ChipSelect1;
#[cfg(feature = "stm32f413")]
use stm32f4xx_hal::fsmc_lcd::ChipSelect3;
use stm32f4xx_hal::{
fsmc_lcd::{FsmcLcd, LcdPins, Timing},
pac,
prelude::*,
rcc::Rcc,
};

use embedded_graphics::{
pixelcolor::Rgb565,
prelude::*,
primitives::{Circle, PrimitiveStyle},
primitives::{Circle, PrimitiveStyle},
};

#[cfg(feature = "stm32f412")]
use stm32f4xx_hal::i2c::I2c;
#[cfg(feature = "stm32f413")]
use stm32f4xx_hal::fmpi2c::FMPI2c;
#[cfg(feature = "stm32f412")]
use stm32f4xx_hal::i2c::I2c;

#[allow(unused_imports)]
use panic_semihosting;

use st7789::*;
use ft6x06;
use st7789::*;


/// A simple example to connect to the FT6x06 crate and access it for
/// x and y positions of touch points. There are a lot of commented-out
/// calls to items in the library, but they're a bit pointless. I couldn't
/// get the gesture stuff to work - I couldn't even get an I2C register change
/// to take place. I didn't try for the other functions like Events.
///
/// It works for me - if you get more working, please send a PR.
/// My approach to Results is also a bit ad-hoc.
/// A simple example to connect to the FT6x06 crate and get the touch coordinates.
/// This example uses embedded-graphics to draw a small circle around the touch area.
#[entry]
fn main() -> ! {
rtt_init_print!();
Expand All @@ -56,56 +48,54 @@ fn main() -> ! {

let clocks = rcc.cfgr.sysclk(100.MHz()).freeze();
let mut delay = cp.SYST.delay(&clocks);
let gpiob = p.GPIOB.split();
let gpioc = p.GPIOC.split();

let gpiob = p.GPIOB.split();
let gpioc = p.GPIOC.split();
let gpiod = p.GPIOD.split();
let gpioe = p.GPIOE.split();
let gpiof = p.GPIOF.split();
let gpiog = p.GPIOG.split();
let lcd_pins = LcdPins {
data: (
gpiod.pd14.into_alternate(),
gpiod.pd15.into_alternate(),
gpiod.pd0.into_alternate(),
gpiod.pd1.into_alternate(),
gpioe.pe7.into_alternate(),
gpioe.pe8.into_alternate(),
gpioe.pe9.into_alternate(),
gpioe.pe10.into_alternate(),
gpioe.pe11.into_alternate(),
gpioe.pe12.into_alternate(),
gpioe.pe13.into_alternate(),
gpioe.pe14.into_alternate(),
gpioe.pe15.into_alternate(),
gpiod.pd8.into_alternate(),
gpiod.pd9.into_alternate(),
gpiod.pd10.into_alternate(),
),
address: gpiof.pf0.into_alternate(),
read_enable: gpiod.pd4.into_alternate(),
write_enable: gpiod.pd5.into_alternate(),
#[cfg(feature = "stm32f413")]
chip_select: ChipSelect3(gpiog.pg10.into_alternate()),
#[cfg(feature = "stm32f412")]
chip_select: ChipSelect1(gpiod.pd7.into_alternate()),

let lcd_pins = LcdPins {
data: (
gpiod.pd14.into_alternate(),
gpiod.pd15.into_alternate(),
gpiod.pd0.into_alternate(),
gpiod.pd1.into_alternate(),
gpioe.pe7.into_alternate(),
gpioe.pe8.into_alternate(),
gpioe.pe9.into_alternate(),
gpioe.pe10.into_alternate(),
gpioe.pe11.into_alternate(),
gpioe.pe12.into_alternate(),
gpioe.pe13.into_alternate(),
gpioe.pe14.into_alternate(),
gpioe.pe15.into_alternate(),
gpiod.pd8.into_alternate(),
gpiod.pd9.into_alternate(),
gpiod.pd10.into_alternate(),
),
address: gpiof.pf0.into_alternate(),
read_enable: gpiod.pd4.into_alternate(),
write_enable: gpiod.pd5.into_alternate(),
#[cfg(feature = "stm32f413")]
chip_select: ChipSelect3(gpiog.pg10.into_alternate()),
#[cfg(feature = "stm32f412")]
chip_select: ChipSelect1(gpiod.pd7.into_alternate()),
};

// Setup the RESET pin
// Setup the RESET pin
#[cfg(feature = "stm32f413")]
let rst = gpiob.pb13.into_push_pull_output();
// Enable backlight
#[cfg(feature = "stm32f413")]
let rst = gpiob.pb13.into_push_pull_output();
// Enable backlight
#[cfg(feature = "stm32f413")]
let mut backlight_control = gpioe.pe5.into_push_pull_output();


#[cfg(feature = "stm32f412")]
let rst = gpiod.pd11.into_push_pull_output();
#[cfg(feature = "stm32f412")]
let mut backlight_control = gpiof.pf5.into_push_pull_output();


let mut backlight_control = gpioe.pe5.into_push_pull_output();

#[cfg(feature = "stm32f412")]
let rst = gpiod.pd11.into_push_pull_output();
#[cfg(feature = "stm32f412")]
let mut backlight_control = gpiof.pf5.into_push_pull_output();

backlight_control.set_high();
// We're not using the "tearing" signal from the display
let mut _te = gpiob.pb14.into_floating_input();
Expand All @@ -124,10 +114,9 @@ fn main() -> ! {
disp.init(&mut delay).unwrap();
rprintln!("{}", disp.orientation() as u8);
disp.clear(Rgb565::BLACK).unwrap();


//Intializing the i2c bus for touchscreen


//Intializing the i2c bus for touchscreen

rprintln!("Connecting to I2c");

#[cfg(feature = "stm32f412")]
Expand All @@ -142,7 +131,7 @@ fn main() -> ! {
&clocks,
)
};

#[cfg(feature = "stm32f413")]
let mut i2c = {
FMPI2c::new(
Expand All @@ -154,18 +143,17 @@ fn main() -> ! {
400.kHz(),
)
};

//ft6x06 driver

let mut touch = ft6x06::Ft6X06::new(&i2c, 0x38, &mut delay).unwrap();
let tsc = touch.ts_calibration(&mut i2c);
match tsc {
Err(e) => rprintln!("Error {} from ts_calibration", e),
Ok(u) => rprintln!("ts_calibration returned {}", u),
}
let mut touch = ft6x06::Ft6X06::new(&i2c, 0x38).unwrap();

let tsc = touch.ts_calibration(&mut i2c, &mut delay);
match tsc {
Err(e) => rprintln!("Error {} from ts_calibration", e),
Ok(u) => rprintln!("ts_calibration returned {}", u),
}
rprintln!("If nothing happens - touch the screen!");
// for _i in 0..3000 {
loop {
let t = touch.detect_touch(&mut i2c);
let mut num: u8 = 0;
Expand All @@ -181,22 +169,31 @@ fn main() -> ! {

if num > 0 {
let t = touch.get_touch(&mut i2c, 1);

match t {
Err(_e) => rprintln!("Error fetching touch data"),
Ok(n) => { rprintln!(
"Touch: {:>3}x{:>3} - weight: {:>3} misc: {}",
n.x,
n.y,
n.weight,
n.misc
);
// Circle with 1 pixel wide white stroke with top-left point at (10, 20) with a diameter of 3
Circle::new(Point::new(<u16 as Into<i32>>::into(n.y), 240 - <u16 as Into<i32>>::into(n.x)), 20)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
.draw(&mut disp).unwrap();
}
}
}
}
Ok(n) => {
rprintln!(
"Touch: {:>3}x{:>3} - weight: {:>3} misc: {}",
n.x,
n.y,
n.weight,
n.misc
);
// Circle with 1 pixel wide white stroke with top-left point at (10, 20) with a diameter of 3
Circle::new(
Point::new(
// The coordinates are flipped.
<u16 as Into<i32>>::into(n.y),
240 - <u16 as Into<i32>>::into(n.x),
),
20,
)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
.draw(&mut disp)
.unwrap();
}
}
}
}
}
Loading

0 comments on commit 54ec04e

Please sign in to comment.