board_common.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "esp_err.h"
  3. #include "driver/i2c_master.h"
  4. #include <stdbool.h>
  5. #include "board_utils.h"
  6. typedef void *board_res_handle_t;
  7. typedef enum {
  8. NULL_RESOURCE = 0,
  9. BOARD_I2C_DAC_ID, ///< I2C master bus used by the DAC
  10. BOARD_I2C_TOUCH_ID, ///< I2C master bus shared by touch controller
  11. BOARD_I2C_DISP_ID, ///< I2C master bus used by the display
  12. BOARD_SPI_ETH_ID, ///< SPI host used by the Ethernet controller
  13. BOARD_SPI_DISP_ID, ///< SPI host used by the display
  14. } board_res_id_t;
  15. /**
  16. * @brief Initialize board-specific hardware
  17. *
  18. * This function is called early during startup to initialize any
  19. * board-specific peripherals such as DACs, GPIOs, power management, etc.
  20. *
  21. * @return ESP_OK on success, or an error code on failure
  22. */
  23. esp_err_t iot_board_init(void);
  24. /**
  25. * @brief Deinitialize board-specific hardware
  26. *
  27. * This function is called during shutdown to clean up board-specific
  28. * resources.
  29. *
  30. * @return ESP_OK on success, or an error code on failure
  31. */
  32. esp_err_t iot_board_deinit(void);
  33. /**
  34. * @brief Check if board is initialized
  35. *
  36. * @return true if board is initialized, false otherwise
  37. */
  38. bool iot_board_is_init(void);
  39. /**
  40. * @brief Get a handle to a board resource
  41. *
  42. * @param id Resource identifier (from board_res_id_t)
  43. * @return Handle to the resource, or NULL if not available
  44. */
  45. board_res_handle_t iot_board_get_handle(int id);
  46. /**
  47. * @brief Get board information string
  48. *
  49. * @return Board name string (never NULL)
  50. */
  51. const char *iot_board_get_info(void);
  52. /**
  53. * @brief Complete deferred initialization of board resources that require LVGL.
  54. *
  55. * Must be called after display_init() completes. If no deferred init is
  56. * pending, this is a no-op.
  57. */
  58. void iot_board_init_lvgl_resources(void);
  59. /**
  60. * @brief Power the board off.
  61. *
  62. * On boards with a software power latch (e.g. Waveshare ESP32-S3-Touch-LCD-1.54
  63. * with a battery), this releases the latch and cuts power. The default
  64. * implementation falls back to deep sleep on boards without a latch.
  65. */
  66. void board_power_off(void);
  67. /**
  68. * @brief Read battery state.
  69. *
  70. * @param[out] percent Battery charge 0..100 (may be NULL).
  71. * @param[out] charging True if the battery is currently charging (may be NULL).
  72. * @return true if the board has a battery and the reading is valid, false
  73. * otherwise (the default for boards without a battery monitor).
  74. */
  75. bool board_battery_read(int *percent, bool *charging);