# glcd_touch_ads7843

Library for touch screen using an ADS7843 or XPT24046 controller.

Author | Rob Jansen, Copyright © 2022..2022, all rights reserved.
Adapted-by |
Compiler | 2.5r6

Description

    Library for touch screen controllers. Both ADS7843 as well as
                 XPT2406 controllers are supported which are compatible.

Sources

    Texas Instruments ADS7843 Touch Screen Controller
             SBAS090B – SEPTEMBER 2000 – REVISED MAY 2002

Notes

    This library supports the control of the touch screen via 4-wire SPI
           It uses its own software SPI since the clocking of data is done on
           different edges.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const byte ADS7843_ROTATE_90_DEGREES = 1`
- `const byte ADS7843_ROTATE_180_DEGREES = 2`
- `const byte _ADS7843_COMMAND_READ_Y = 0x90`
- `const word _ADS7843_ERROR_RANGE = 50`
- `const word _ADS7843_X_RANGE = ADS7843_X_TOP_LEFT - ADS7843_X_BOTTOM_RIGHT`
- `const word _ADS7843_XY_MAX = 0x0FFF`
- `const word _ADS7843_XY_MIN = 0x0000`
- `const byte ADS7843_ROTATE_270_DEGREES = 3`
- `const byte _ADS7843_COMMAND_READ_X = 0xD0`
- `const byte ADS7843_ROTATE_0_DEGREES = 0`
- `const word _ADS7843_Y_RANGE = ADS7843_Y_TOP_LEFT - ADS7843_Y_BOTTOM_RIGHT`
- `var byte _ads7843_screen_rotation`

### Procedures

- `ads7843_set_screen_orientation(byte in orientation)`
- `ads7843_init()`

Private

- `_ads7843_spi_sw'put(byte in data)`

### Functions

- `ads7843_get_touch_coordinate_raw(word out x, word out y) return bit`
- `ads7843_get_touch_coordinate(word out touch_x, word out touch_y) return bit`

Private

- `_ads7843_read_adc(byte in command) return word`
- `_ads7843_spi_sw'get() return byte`

## API details

### Global variables/contants

- `const byte ADS7843_ROTATE_90_DEGREES = 1`

  No documentation found

- `const byte ADS7843_ROTATE_180_DEGREES = 2`

  No documentation found

- `const byte _ADS7843_COMMAND_READ_Y = 0x90`

      Power down mode with interrupt enabled.

- `const word _ADS7843_ERROR_RANGE = 50`

      Error margin used to prevent incorrect reading of the toch screen.

- `const word _ADS7843_X_RANGE = ADS7843_X_TOP_LEFT - ADS7843_X_BOTTOM_RIGHT`

      Touch screen ranges based on the corners of the touch screen.

- `const word _ADS7843_XY_MAX = 0x0FFF`

  No documentation found

- `const word _ADS7843_XY_MIN = 0x0000`

      Touch screen min and max values, 12 bits.

- `const byte ADS7843_ROTATE_270_DEGREES = 3`

  No documentation found

- `const byte _ADS7843_COMMAND_READ_X = 0xD0`

      Commands for reading X and Y coordinate

- `const byte ADS7843_ROTATE_0_DEGREES = 0`

      Touch screen rotation defintions in degrees. This should be used if the screen
      is rotated. The touch screen has to match the screen rotation.

- `const word _ADS7843_Y_RANGE = ADS7843_Y_TOP_LEFT - ADS7843_Y_BOTTOM_RIGHT`

  No documentation found

- `var byte _ads7843_screen_rotation`

      Touch screen orientation must match the screen orientation.

### Procedures

- `ads7843_set_screen_orientation(byte in orientation)`

      Set the touch screen orientation using the screen rotation constants. The
      orientation of the touch screen must match the orientation of the display.

- `ads7843_init()`

      Initialize the ADS7843 library.The interrupt output will be enabled.

Private

- `_ads7843_spi_sw'put(byte in data)`

      Pseudo variable to write the SPI data. Data is clocked out on raising edge.

### Functions

- `ads7843_get_touch_coordinate_raw(word out x, word out y) return bit`

      Read the x and y coordinate of the touch screen and return TRUE when the
      coordinates are within a certain error margin. The screen does not have to
      be touched. X and Y are returned as touch screen values.

- `ads7843_get_touch_coordinate(word out touch_x, word out touch_y) return bit`

      Get the x and y coordinate where the screen was touched and returns TRUE
      when the screen was touched. X and y are returned in touch screen values.

Private

- `_ads7843_read_adc(byte in command) return word`

      Read the value of the given touch ADC and return the value.

- `_ads7843_spi_sw'get() return byte`

      Pseudo variable to read the SPI data. Data is clocked in on falling edge.

## Related samples

Here are the list of samples which use this library:

16f18857 | 16f18857_touch_interrupt_ads7843.jal
16f18857 | 16f18857_touch_ads7843.jal