u8g2_periphery.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <u8g2.h>
  2. #include <assert.h>
  3. #include <furi-hal.h>
  4. #include <stm32wbxx_ll_utils.h>
  5. static FuriHalSpiDevice* u8g2_periphery_display = NULL;
  6. uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
  7. switch(msg) {
  8. case U8X8_MSG_GPIO_AND_DELAY_INIT:
  9. /* HAL initialization contains all what we need so we can skip this part. */
  10. break;
  11. case U8X8_MSG_DELAY_MILLI:
  12. LL_mDelay(arg_int);
  13. break;
  14. case U8X8_MSG_DELAY_10MICRO:
  15. LL_mDelay(1);
  16. break;
  17. case U8X8_MSG_DELAY_100NANO:
  18. asm("nop");
  19. break;
  20. case U8X8_MSG_GPIO_RESET:
  21. hal_gpio_write(&gpio_display_rst, arg_int);
  22. break;
  23. default:
  24. return 0;
  25. }
  26. return 1;
  27. }
  28. uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
  29. switch(msg) {
  30. case U8X8_MSG_BYTE_SEND:
  31. furi_hal_spi_bus_tx(u8g2_periphery_display->bus, (uint8_t*)arg_ptr, arg_int, 10000);
  32. break;
  33. case U8X8_MSG_BYTE_SET_DC:
  34. hal_gpio_write(&gpio_display_di, arg_int);
  35. break;
  36. case U8X8_MSG_BYTE_INIT:
  37. break;
  38. case U8X8_MSG_BYTE_START_TRANSFER:
  39. assert(u8g2_periphery_display == NULL);
  40. u8g2_periphery_display =
  41. (FuriHalSpiDevice*)furi_hal_spi_device_get(FuriHalSpiDeviceIdDisplay);
  42. hal_gpio_write(u8g2_periphery_display->chip_select, false);
  43. break;
  44. case U8X8_MSG_BYTE_END_TRANSFER:
  45. assert(u8g2_periphery_display);
  46. hal_gpio_write(u8g2_periphery_display->chip_select, true);
  47. furi_hal_spi_device_return(u8g2_periphery_display);
  48. u8g2_periphery_display = NULL;
  49. break;
  50. default:
  51. return 0;
  52. }
  53. return 1;
  54. }