u8g2_periphery.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "u8g2/u8g2.h"
  2. #include "flipper.h"
  3. extern SPI_HandleTypeDef hspi1;
  4. // TODO: fix log
  5. #ifdef DEBUG
  6. #undef DEBUG
  7. #endif
  8. uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
  9. switch(msg) {
  10. //Initialize SPI peripheral
  11. case U8X8_MSG_GPIO_AND_DELAY_INIT:
  12. /* HAL initialization contains all what we need so we can skip this part. */
  13. break;
  14. //Function which implements a delay, arg_int contains the amount of ms
  15. case U8X8_MSG_DELAY_MILLI:
  16. osDelay(arg_int);
  17. break;
  18. //Function which delays 10us
  19. case U8X8_MSG_DELAY_10MICRO:
  20. delay_us(10);
  21. break;
  22. //Function which delays 100ns
  23. case U8X8_MSG_DELAY_100NANO:
  24. asm("nop");
  25. break;
  26. // Function to define the logic level of the RESET line
  27. case U8X8_MSG_GPIO_RESET:
  28. #ifdef DEBUG
  29. fuprintf(log, "[u8g2] rst %d\n", arg_int);
  30. #endif
  31. // TODO change it to FuriRecord pin
  32. HAL_GPIO_WritePin(
  33. DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
  34. break;
  35. default:
  36. #ifdef DEBUG
  37. fufuprintf(log, "[u8g2] unknown io %d\n", msg);
  38. #endif
  39. return 0; //A message was received which is not implemented, return 0 to indicate an error
  40. }
  41. return 1; // command processed successfully.
  42. }
  43. uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
  44. switch(msg) {
  45. case U8X8_MSG_BYTE_SEND:
  46. #ifdef DEBUG
  47. fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]);
  48. #endif
  49. // TODO change it to FuriRecord SPI
  50. HAL_SPI_Transmit(&hspi1, (uint8_t*)arg_ptr, arg_int, 10000);
  51. break;
  52. case U8X8_MSG_BYTE_SET_DC:
  53. #ifdef DEBUG
  54. fuprintf(log, "[u8g2] dc %d\n", arg_int);
  55. #endif
  56. // TODO change it to FuriRecord pin
  57. HAL_GPIO_WritePin(
  58. DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
  59. break;
  60. case U8X8_MSG_BYTE_INIT:
  61. #ifdef DEBUG
  62. fuprintf(log, "[u8g2] init\n");
  63. #endif
  64. // TODO change it to FuriRecord pin
  65. HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
  66. break;
  67. case U8X8_MSG_BYTE_START_TRANSFER:
  68. #ifdef DEBUG
  69. fuprintf(log, "[u8g2] start\n");
  70. #endif
  71. // TODO change it to FuriRecord pin
  72. HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
  73. asm("nop");
  74. break;
  75. case U8X8_MSG_BYTE_END_TRANSFER:
  76. #ifdef DEBUG
  77. fuprintf(log, "[u8g2] end\n");
  78. #endif
  79. asm("nop");
  80. // TODO change it to FuriRecord pin
  81. HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET);
  82. break;
  83. default:
  84. #ifdef DEBUG
  85. fuprintf(log, "[u8g2] unknown xfer %d\n", msg);
  86. #endif
  87. return 0;
  88. }
  89. return 1;
  90. }