1212
1313#include " m5_unit_component/types.hpp"
1414#include " m5_unit_component/adapter.hpp"
15+ #if defined(ESP_PLATFORM)
16+ #include < driver/uart.h> // for uart_port_t
17+ #include < driver/spi_master.h> // for spi_device_handle_t
18+ #endif
19+ #if defined(ESP_PLATFORM) && __has_include(<driver/i2c_master.h>)
20+ #include < driver/i2c_master.h> // for i2c_master_bus_handle_t
21+ #elif defined(ESP_PLATFORM)
22+ #include < driver/i2c.h> // for i2c_port_t / gpio_num_t
23+ #endif
1524#include < cstdint>
1625#include < vector>
1726#include < algorithm>
1827#include < iterator>
1928#include < type_traits>
2029#include < memory>
2130
31+ #if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
2232class TwoWire ;
2333class HardwareSerial ;
2434class SPIClass ;
2535struct SPISettings ;
36+ #endif
2637
2738namespace m5 {
2839class I2C_Class ;
@@ -287,12 +298,32 @@ class Component {
287298
288299 // /@name Assign(I2C)
289300 // /@{
301+ #if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
290302 /* !
291303 @brief Assign TwoWire as the communication bus
292304 @param wire TwoWire to be used
293305 @return True if successful
294306 */
295307 virtual bool assign (TwoWire& wire);
308+ #endif
309+ #if defined(DOXYGEN_PROCESS) || (defined(ESP_PLATFORM) && __has_include(<driver/i2c_master.h>))
310+ /* !
311+ @brief Assign I2C master bus (ESP-IDF native driver)
312+ @param bus ESP-IDF I2C master bus handle
313+ @return True if successful
314+ */
315+ virtual bool assign (i2c_master_bus_handle_t bus);
316+ #endif
317+ #if defined(DOXYGEN_PROCESS) || (defined(ESP_PLATFORM) && !__has_include(<driver/i2c_master.h>))
318+ /* !
319+ @brief Assign I2C (ESP-IDF legacy driver, pre-installed port)
320+ @param port I2C port (the driver must be installed beforehand via i2c_param_config / i2c_driver_install)
321+ @param sda SDA GPIO
322+ @param scl SCL GPIO
323+ @return True if successful
324+ */
325+ virtual bool assign (const i2c_port_t port, const gpio_num_t sda, const gpio_num_t scl);
326+ #endif
296327 /* !
297328 @brief Assign I2C_Class as the communication bus
298329 @param i2c I2C_Class to be used (e.g. M5.In_I2C)
@@ -314,23 +345,46 @@ class Component {
314345
315346 // /@name Assign(UART)
316347 // /@{
348+ #if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
317349 /* !
318350 @brief Assign HardwareSerial as the communication bus
319351 @param serial HardwareSerial to be used
320352 @return True if successful
321353 */
322354 virtual bool assign (HardwareSerial& serial);
355+ #endif
356+ #if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
357+ /* !
358+ @brief Assign UART (ESP-IDF native driver, pre-installed port)
359+ @param uart_num UART port number (the driver must be installed beforehand via
360+ uart_driver_install / uart_param_config / uart_set_pin)
361+ @return True if successful
362+ */
363+ virtual bool assign (const uart_port_t uart_num);
364+ #endif
323365 // /@}
324366
325367 // /@name Assign(SPI)
326368 // /@{
369+ #if defined(ARDUINO) || defined(DOXYGEN_PROCESS)
327370 /* !
328371 @brief Assign SPIClass as the communication bus
329372 @param spi SPIClass to be used
330373 @param settings SPI settings to be applied
331374 @return True if successful
332375 */
333376 virtual bool assign (SPIClass& spi, const SPISettings& settings);
377+ #endif
378+ #if defined(ESP_PLATFORM) || defined(DOXYGEN_PROCESS)
379+ /* !
380+ @brief Assign SPI device handle (ESP-IDF native driver, borrowed)
381+ @param handle ESP-IDF SPI device handle (create with spics_io_num = -1; init bus with SPI_DMA_DISABLED)
382+ @param cs CS GPIO controlled manually by this library. If `GPIO_NUM_NC` (default), uses `address()` as the CS pin
383+ (same convention as Arduino SPI)
384+ @return True if successful
385+ */
386+ virtual bool assign (spi_device_handle_t handle, const gpio_num_t cs = GPIO_NUM_NC );
387+ #endif
334388 // /@}
335389
336390 // /@name Assign(M5HAL)
0 commit comments