u8g2_esp32_hal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef U8G2_ESP32_HAL_H
  2. #define U8G2_ESP32_HAL_H
  3. /*
  4. * u8g2_esp32_hal.h
  5. *
  6. * Created on: Feb 12, 2017
  7. * Author: kolban
  8. */
  9. #ifndef U8G2_ESP32_HAL_H_
  10. #define U8G2_ESP32_HAL_H_
  11. #include "u8g2.h"
  12. #include "driver/gpio.h"
  13. #include "driver/i2c_master.h"
  14. #include "driver/spi_master.h"
  15. #define U8G2_ESP32_HAL_UNDEFINED GPIO_NUM_NC
  16. #if SOC_I2C_NUM > 1
  17. #define I2C_MASTER_NUM I2C_NUM_1 // I2C port number for master dev
  18. #else
  19. #define I2C_MASTER_NUM I2C_NUM_0 // I2C port number for master dev
  20. #endif
  21. #define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master do not need buffer
  22. #define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master do not need buffer
  23. #define I2C_MASTER_FREQ_HZ 100000 // I2C master clock frequency
  24. #define ACK_CHECK_EN 0x1 // I2C master will check ack from slave
  25. #define ACK_CHECK_DIS 0x0 // I2C master will not check ack from slave
  26. /** @public
  27. * HAL configuration structure.
  28. */
  29. typedef struct {
  30. union {
  31. /* SPI settings. */
  32. struct {
  33. /* GPIO num for clock. */
  34. gpio_num_t clk;
  35. /* GPIO num for SPI mosi. */
  36. gpio_num_t mosi;
  37. /* GPIO num for SPI slave/chip select. */
  38. gpio_num_t cs;
  39. } spi;
  40. /* I2C settings. */
  41. struct {
  42. /* GPIO num for I2C data. */
  43. gpio_num_t sda;
  44. /* GPIO num for I2C clock. */
  45. gpio_num_t scl;
  46. } i2c;
  47. } bus;
  48. /* GPIO num for reset. */
  49. gpio_num_t reset;
  50. /* GPIO num for DC. */
  51. gpio_num_t dc;
  52. } u8g2_esp32_hal_t;
  53. /**
  54. * Construct a default HAL configuration with all fields undefined.
  55. */
  56. // clang-format off
  57. #define U8G2_ESP32_HAL_DEFAULT \
  58. {.bus = {.spi = {.clk = U8G2_ESP32_HAL_UNDEFINED, \
  59. .mosi = U8G2_ESP32_HAL_UNDEFINED, \
  60. .cs = U8G2_ESP32_HAL_UNDEFINED}}, \
  61. .reset = U8G2_ESP32_HAL_UNDEFINED, \
  62. .dc = U8G2_ESP32_HAL_UNDEFINED}
  63. // clang-format on
  64. /**
  65. * Initialize the HAL with the given configuration.
  66. *
  67. * @see u8g2_esp32_hal_t
  68. * @see U8G2_ESP32_HAL_DEFAULT
  69. */
  70. void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param);
  71. /**
  72. * Supply a pre-initialised I2C master bus handle.
  73. * When set, u8g2_esp32_i2c_byte_cb will skip creating its own bus and use
  74. * this one instead. Must be called after u8g2_esp32_hal_init().
  75. */
  76. void u8g2_esp32_hal_set_i2c_bus(i2c_master_bus_handle_t bus);
  77. /**
  78. * Supply a pre-initialised SPI host.
  79. * When set, u8g2_esp32_spi_byte_cb will skip calling spi_bus_initialize()
  80. * and will call spi_bus_add_device() on the provided host instead.
  81. * Must be called after u8g2_esp32_hal_init().
  82. */
  83. void u8g2_esp32_hal_set_spi_host(spi_host_device_t host);
  84. uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int,
  85. void *arg_ptr);
  86. uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int,
  87. void *arg_ptr);
  88. uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int,
  89. void *arg_ptr);
  90. #endif /* U8G2_ESP32_HAL_H_ */
  91. #endif