luat_gtfont.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "luat_base.h"
  2. #include "luat_spi.h"
  3. #ifndef u8
  4. #define u8 uint8_t
  5. #endif
  6. #define LUAT_GT_DEBUG 0
  7. #define LUAT_LOG_TAG "gt"
  8. #include "luat_log.h"
  9. luat_spi_device_t* gt_spi_dev = NULL;
  10. unsigned long r_dat_bat(unsigned long address,unsigned long DataLen,unsigned char *pBuff) {
  11. if (gt_spi_dev == NULL)
  12. return 0;
  13. char send_buf[4] = {
  14. 0x03,
  15. (u8)((address)>>16),
  16. (u8)((address)>>8),
  17. (u8)(address)
  18. };
  19. luat_spi_device_transfer(gt_spi_dev, send_buf, 4, (char *)pBuff, DataLen);
  20. #if LUAT_GT_DEBUG
  21. LLOGD("r_dat_bat addr %08X len %d pBuff %X", address, DataLen,*pBuff);
  22. for(int i = 0; i < DataLen;i++){
  23. LLOGD("pBuff[%d]:0x%02X",i,pBuff[i]);
  24. }
  25. #endif
  26. return pBuff[0];
  27. }
  28. unsigned char CheckID(unsigned char CMD, unsigned long address,unsigned long byte_long,unsigned char *p_arr) {
  29. #if LUAT_GT_DEBUG
  30. LLOGD("CheckID CMD %02X addr %08X len %d p_arr %X", CMD, address, byte_long,*p_arr);
  31. #endif
  32. if (gt_spi_dev == NULL)
  33. return 0;
  34. char send_buf[4] = {
  35. CMD,
  36. (u8)((address)>>16),
  37. (u8)((address)>>8),
  38. (u8)(address)
  39. };
  40. luat_spi_device_transfer(gt_spi_dev, send_buf, 4, (char *)p_arr, byte_long);
  41. // return p_arr[0];
  42. return 1;
  43. }
  44. unsigned char gt_read_data(unsigned char* sendbuf , unsigned char sendlen , unsigned char* receivebuf, unsigned int receivelen)
  45. {
  46. if (gt_spi_dev == NULL)
  47. return 0;
  48. luat_spi_device_transfer(gt_spi_dev, (const char *)sendbuf, sendlen,(char *)receivebuf, receivelen);
  49. #if LUAT_GT_DEBUG
  50. LLOGD("gt_read_data sendlen:%d receivelen:%d",sendlen,receivelen);
  51. for(int i = 0; i < sendlen;i++){
  52. LLOGD("sendbuf[%d]:0x%02X",i,sendbuf[i]);
  53. }
  54. for(int i = 0; i < receivelen;i++){
  55. LLOGD("receivebuf[%d]:0x%02X",i,receivebuf[i]);
  56. }
  57. #endif
  58. return 1;
  59. }