mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 01:13:40 +00:00
ft6336: add support for ft6336
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
// Package ft6336 provides a driver for the FT6336 I2C Self-Capacitive touch
|
||||
// panel controller.
|
||||
//
|
||||
// Datasheet: https://focuslcds.com/content/FT6236.pdf
|
||||
//
|
||||
package ft6336
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/touch"
|
||||
)
|
||||
|
||||
// Device wraps FT6336 I2C Self-Capacitive touch
|
||||
type Device struct {
|
||||
bus drivers.I2C
|
||||
buf []byte
|
||||
Address uint8
|
||||
intPin machine.Pin
|
||||
}
|
||||
|
||||
// New returns FT6336 device for the provided I2C bus using default address.
|
||||
func New(i2c drivers.I2C, intPin machine.Pin) *Device {
|
||||
return &Device{
|
||||
bus: i2c,
|
||||
buf: make([]byte, 11),
|
||||
Address: Address,
|
||||
intPin: intPin,
|
||||
}
|
||||
}
|
||||
|
||||
// Config contains settings for FT6636.
|
||||
type Config struct {
|
||||
}
|
||||
|
||||
// Configure the FT6336 device.
|
||||
func (d *Device) Configure(config Config) error {
|
||||
d.write1Byte(0xA4, 0x00)
|
||||
d.intPin.Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetGMode sets interrupt mode.
|
||||
// 0x00 : Interrupt Polling mode
|
||||
// 0x01 : Interrupt Trigger mode (default)
|
||||
func (d *Device) SetGMode(v uint8) {
|
||||
d.write1Byte(RegGMode, v)
|
||||
}
|
||||
|
||||
// GetGMode gets interrupt mode.
|
||||
func (d *Device) GetGMode() uint8 {
|
||||
return d.read8bit(RegGMode)
|
||||
}
|
||||
|
||||
// SetPeriodActive sets report rate in Active mode.
|
||||
func (d *Device) SetPeriodActive(v uint8) {
|
||||
d.write1Byte(RegPeriodActive, v)
|
||||
}
|
||||
|
||||
// GetPeriodActive gets report rate in Active mode.
|
||||
func (d *Device) GetPeriodActive() uint8 {
|
||||
return d.read8bit(RegPeriodActive)
|
||||
}
|
||||
|
||||
// GetFirmwareID gets firmware version.
|
||||
func (d *Device) GetFirmwareID() uint8 {
|
||||
return d.read8bit(RegFirmid)
|
||||
}
|
||||
|
||||
// Read reads the registers.
|
||||
func (d *Device) Read() []byte {
|
||||
d.bus.Tx(uint16(d.Address), []byte{0x02}, d.buf[:])
|
||||
return d.buf[:]
|
||||
}
|
||||
|
||||
// ReadTouchPoint reads a single touch.Point from the device. The maximum value
|
||||
// for each touch.Point is 0xFFFF.
|
||||
func (d *Device) ReadTouchPoint() touch.Point {
|
||||
d.Read()
|
||||
z := 0xFFFFF
|
||||
if d.buf[0] == 0 {
|
||||
z = 0
|
||||
}
|
||||
|
||||
//Scale X&Y to 16 bit for consistency across touch drivers
|
||||
return touch.Point{
|
||||
X: (int(d.buf[1]&0x0F)<<8 + int(d.buf[2])) * ((1 << 16) / 320),
|
||||
Y: (int(d.buf[3]&0x0F)<<8 + int(d.buf[4])) * ((1 << 16) / 270),
|
||||
Z: z,
|
||||
}
|
||||
}
|
||||
|
||||
// Touched returns if touched or not.
|
||||
func (d *Device) Touched() bool {
|
||||
p := d.ReadTouchPoint()
|
||||
return p.Z > 0
|
||||
}
|
||||
|
||||
func (d *Device) write1Byte(reg, data uint8) {
|
||||
d.bus.WriteRegister(d.Address, reg, []byte{data})
|
||||
}
|
||||
|
||||
func (d *Device) read8bit(reg uint8) uint8 {
|
||||
d.bus.ReadRegister(d.Address, reg, d.buf[:1])
|
||||
return d.buf[0]
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package ft6336
|
||||
|
||||
// 0x00 DEV_MODE
|
||||
// 0x01 GEST_ID
|
||||
// 0x02 TD_STATUS
|
||||
// 0x03 P1_XH
|
||||
// 0x04 P1_XL
|
||||
// 0x05 P1_YH
|
||||
// 0x06 P1_YL
|
||||
// 0x07 P1_WEIGHT
|
||||
// 0x08 P1_MISC
|
||||
// 0x09 P2_XH
|
||||
// 0x0A P2_XL
|
||||
// 0x0B P2_YH
|
||||
// 0x0C P2_YL
|
||||
// 0x0D P2_WEIGHT
|
||||
// 0x0E P2_MISC
|
||||
// 0x80 TH_GROUP
|
||||
// 0x85 TH_DIFF
|
||||
// 0x86 CTRL
|
||||
// 0x87 TIMEENTERMONITOR
|
||||
// 0x88 PERIODACTIVE
|
||||
// 0x89 PERIODMONITOR
|
||||
// 0x91 RADIAN_VALUE
|
||||
// 0x92 OFFSET_LEFT_RIGHT
|
||||
// 0x93 OFFSET_UP_D
|
||||
// 0x94 DISTANCE_LE
|
||||
// 0x95 DISTANCE_UP
|
||||
// 0x96 DISTANCE_ZO
|
||||
// ...
|
||||
// 0xA1 LIB_VER_H
|
||||
// 0xA2 LIB_VER_L
|
||||
// 0xA3 CIPHER
|
||||
// 0xA4 G_MODE
|
||||
// 0xA5 PWR_MODE
|
||||
// 0xA6 FIRMID
|
||||
// 0xA8 FOCALTECH_ID
|
||||
// ...
|
||||
// 0xAF RELEASE_CODE_ID
|
||||
// ...
|
||||
// 0xBC STATE
|
||||
|
||||
const (
|
||||
Address = 0x38
|
||||
|
||||
RegPeriodActive = 0x88
|
||||
RegGMode = 0xA4
|
||||
RegFirmid = 0xA6
|
||||
)
|
||||
Reference in New Issue
Block a user