Microchip® Advanced Software Framework

ads7843.c File Reference

API driver for component ADS7843.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include "ads7843.h"
#include "conf_ads7843.h"
#include "board.h"
#include "ioport.h"
#include "pio_handler.h"
#include "pio.h"
#include "spi_master.h"
#include "conf_spi_master.h"

Macros

#define ADS7843_BUFSIZE   3
 
#define ADS7843_SPI_BAUDRATE   1000000
 Frequence rate for sending one bit. More...
 
#define ADS7843_TIMEOUT   5000000
 
#define ADS_CTRL_DFR   (1 << 2)
 SER/DFR. More...
 
#define ADS_CTRL_EIGHT_BITS_MOD   (1 << 3)
 Mode. More...
 
#define ADS_CTRL_PD0   (1 << 0)
 PD0. More...
 
#define ADS_CTRL_PD1   (1 << 1)
 PD1. More...
 
#define ADS_CTRL_START   (1 << 7)
 Start Bit. More...
 
#define ADS_CTRL_SWITCH_SHIFT   4
 Address setting. More...
 
#define CMD_ENABLE_PENIRQ   ((1 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START)
 Enable penIRQ. More...
 
#define CMD_X_POSITION
 Get Y position command. More...
 
#define CMD_Y_POSITION
 Get X position command. More...
 
#define DELAY_BEFORE_SPCK   200
 2us min (tCSS) <=> 200/100 000 000 = 2us More...
 
#define DELAY_BETWEEN_CONS_COM   0xf
 5us min (tCSH) <=> (32 * 15) / (100 000 000) = 5us More...
 

Functions

void ads7843_disable_interrupt (void)
 Disable interrupts on touch event. More...
 
void ads7843_enable_interrupt (void)
 Enable interrupts on touch event. More...
 
void ads7843_get_raw_point (uint32_t *p_x, uint32_t *p_y)
 Get the touch raw coordinates. More...
 
uint32_t ads7843_init (void)
 Initialize the SPI communication with the ADS7843 controller. More...
 
uint32_t ads7843_is_pressed (void)
 Return the touch screen status, pressed or not. More...
 
static uint32_t ads7843_send_cmd (uint8_t uc_cmd)
 Send a command to the ADS7843 touch controller. More...
 
void ads7843_set_handler (void(*p_handler)(uint32_t, uint32_t))
 Set the touch interrupt handler. More...
 

#define ADS7843_BUFSIZE   3

Referenced by ads7843_send_cmd().

#define ADS7843_SPI_BAUDRATE   1000000

Frequence rate for sending one bit.

Referenced by ads7843_init().

#define ADS7843_TIMEOUT   5000000
#define ADS_CTRL_DFR   (1 << 2)

SER/DFR.

#define ADS_CTRL_EIGHT_BITS_MOD   (1 << 3)

Mode.

#define ADS_CTRL_PD0   (1 << 0)

PD0.

#define ADS_CTRL_PD1   (1 << 1)

PD1.

#define ADS_CTRL_START   (1 << 7)

Start Bit.

#define ADS_CTRL_SWITCH_SHIFT   4

Address setting.

#define CMD_ENABLE_PENIRQ   ((1 << ADS_CTRL_SWITCH_SHIFT) | ADS_CTRL_START)

Enable penIRQ.

Referenced by ads7843_get_raw_point(), and ads7843_init().

#define CMD_X_POSITION
Value:
#define ADS_CTRL_START
Start Bit.
Definition: ads7843.c:55
#define ADS_CTRL_SWITCH_SHIFT
Address setting.
Definition: ads7843.c:57
#define ADS_CTRL_PD1
PD1.
Definition: ads7843.c:49
#define ADS_CTRL_PD0
PD0.
Definition: ads7843.c:47

Get Y position command.

Referenced by ads7843_get_raw_point().

#define CMD_Y_POSITION
Value:
#define ADS_CTRL_START
Start Bit.
Definition: ads7843.c:55
#define ADS_CTRL_SWITCH_SHIFT
Address setting.
Definition: ads7843.c:57
#define ADS_CTRL_PD1
PD1.
Definition: ads7843.c:49
#define ADS_CTRL_PD0
PD0.
Definition: ads7843.c:47

Get X position command.

Referenced by ads7843_get_raw_point().

#define DELAY_BEFORE_SPCK   200

2us min (tCSS) <=> 200/100 000 000 = 2us

#define DELAY_BETWEEN_CONS_COM   0xf

5us min (tCSH) <=> (32 * 15) / (100 000 000) = 5us

static uint32_t ads7843_send_cmd ( uint8_t  uc_cmd)
static

Send a command to the ADS7843 touch controller.

Parameters
uc_cmdcommand to send.
Returns
Command result.

(volatile declaration needed for code optimisation by compiler)

References ADS7843_BUFSIZE, data, SPI_ERROR_TIMEOUT, spi_is_rx_full(), spi_is_tx_ready(), spi_read_single(), SPI_TIMEOUT, and spi_write_single().

Referenced by ads7843_get_raw_point(), and ads7843_init().