lcmComm_dgus.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * lcmComm_dgus.c
  3. *
  4. * Created on : 2020-10-20
  5. * Update on : 2022-03-01
  6. * Author : Folus Wen, Eason Yang
  7. * Version : V0.27
  8. *
  9. */
  10. #include "lcmComm_dgus.h"
  11. //#define isDebugPrint
  12. //=======================================
  13. // Basic routine
  14. //=======================================
  15. void displayMessageDgus(uint8_t *data, uint16_t len, uint8_t isRX)
  16. {
  17. uint8_t output[8192];
  18. memset(output, 0x00, ARRAY_SIZE(output));
  19. sprintf((char*)output, "%s", (isRX?"RX: ":"TX: "));
  20. for(uint16_t idx = 0;idx<len;idx++)
  21. {
  22. sprintf((char*)output, "%s%02x ", output, data[idx]);
  23. }
  24. //printf("%s\n", output);
  25. }
  26. //=======================================
  27. // Call function (Transmit message into LCD)
  28. //=======================================
  29. int transceiverDgus(int32_t fd, uint8_t *tx, uint16_t tx_len, uint8_t *rx, uint16_t rx_len)
  30. {
  31. int result = FAIL;
  32. int len;
  33. tcflush(fd,TCIOFLUSH);
  34. displayMessageDgus(tx, tx_len, NO);
  35. if(write(fd, tx, tx_len) >= ARRAY_SIZE(tx))
  36. {
  37. usleep(100);
  38. len = read(fd, rx, rx_len);
  39. if(len > 0)
  40. {
  41. if((rx[0] == CMD_ACK_VALUE_1) && (rx[1] == CMD_ACK_VALUE_2))
  42. {
  43. displayMessageDgus(rx, len, YES);
  44. result = PASS;
  45. }
  46. }
  47. }
  48. else
  49. {}
  50. return result;
  51. }
  52. //=======================================
  53. // Call function (Write register value function)
  54. //=======================================
  55. int8_t lcdRegisterWrite(int32_t fd, uint16_t address, uint8_t *data, uint8_t dataLen)
  56. {
  57. int8_t result = FAIL;
  58. uint8_t tx[5 + dataLen];
  59. uint8_t rx[128];
  60. memset(tx, 0x00, sizeof(tx));
  61. memset(rx, 0x00, sizeof(rx));
  62. tx[0] = CMD_HEADER_1;
  63. tx[1] = CMD_HEADER_2;
  64. tx[2] = (2 + dataLen);
  65. tx[3] = CMD_REG_WRITE;
  66. tx[4] = (address & 0xff);
  67. memcpy(&tx[5], data, dataLen);
  68. if(fd > 0)
  69. {
  70. if(transceiverDgus(fd, tx, ARRAY_SIZE(tx), rx, ARRAY_SIZE(rx)) == PASS)
  71. {
  72. result = PASS;
  73. }
  74. else
  75. {}
  76. }
  77. else
  78. {}
  79. return result;
  80. }