gmouse_lld_ADS7843_board.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * This file is subject to the terms of the GFX License. If a copy of
  3. * the license was not distributed with this file, you can obtain one at:
  4. *
  5. * http://ugfx.io/license.html
  6. */
  7. #ifndef _GINPUT_LLD_MOUSE_BOARD_H
  8. #define _GINPUT_LLD_MOUSE_BOARD_H
  9. // Resolution and Accuracy Settings
  10. #define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 2
  11. #define GMOUSE_ADS7843_PEN_CLICK_ERROR 2
  12. #define GMOUSE_ADS7843_PEN_MOVE_ERROR 2
  13. #define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 20
  14. #define GMOUSE_ADS7843_FINGER_CLICK_ERROR 4
  15. #define GMOUSE_ADS7843_FINGER_MOVE_ERROR 4
  16. // How much extra data to allocate at the end of the GMouse structure for the board's use
  17. #define GMOUSE_ADS7843_BOARD_DATA_SIZE 0
  18. static const SPIConfig spicfg = {
  19. 0,
  20. GPIOB,
  21. 7, // CS
  22. /* SPI_CR1_BR_2 |*/ SPI_CR1_BR_1 | SPI_CR1_BR_0,
  23. };
  24. static gBool init_board(GMouse* m, unsigned driverinstance)
  25. {
  26. (void)m;
  27. // Only one touch interface on this board
  28. if (driverinstance)
  29. return gFalse;
  30. // Set the GPIO modes
  31. palSetPadMode(GPIOB, 6, PAL_MODE_INPUT_PULLUP); // IRQ
  32. palSetPadMode(GPIOC, 6, PAL_MODE_INPUT); // BUSY
  33. // Start the SPI peripheral
  34. spiStart(&SPID1, &spicfg);
  35. return gTrue;
  36. }
  37. static GFXINLINE gBool getpin_pressed(GMouse* m)
  38. {
  39. (void) m;
  40. return (!palReadPad(GPIOB, 6));
  41. }
  42. static GFXINLINE void aquire_bus(GMouse* m)
  43. {
  44. (void) m;
  45. spiAcquireBus(&SPID1);
  46. palClearPad(GPIOB, 7);
  47. }
  48. static GFXINLINE void release_bus(GMouse* m)
  49. {
  50. (void) m;
  51. palSetPad(GPIOB, 7);
  52. spiReleaseBus(&SPID1);
  53. }
  54. static GFXINLINE gU16 read_value(GMouse* m, gU16 port)
  55. {
  56. static gU8 txbuf[3] = {0};
  57. static gU8 rxbuf[3] = {0};
  58. gU16 ret;
  59. (void) m;
  60. txbuf[0] = port;
  61. spiExchange(&SPID1, 3, txbuf, rxbuf);
  62. ret = (rxbuf[1] << 5) | (rxbuf[2] >> 3);
  63. return ret;
  64. }
  65. #endif /* _GINPUT_LLD_MOUSE_BOARD_H */