u8g2_periphery.c 1.7 KB

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