/* * This file is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include "I2CDevice.h" #include #include #include #include "Scheduler.h" using namespace ESP32; #define MHZ (1000U*1000U) #define KHZ (1000U) I2CBusDesc i2c_bus_desc[] = { HAL_ESP32_I2C_BUSES }; I2CBus I2CDeviceManager::businfo[ARRAY_SIZE(i2c_bus_desc)]; I2CDeviceManager::I2CDeviceManager(void) { for (uint8_t i=0; i I2CDeviceManager::get_device(uint8_t bus, uint8_t address, uint32_t bus_clock, bool use_smbus, uint32_t timeout_ms) { if (bus >= ARRAY_SIZE(i2c_bus_desc)) { return AP_HAL::OwnPtr(nullptr); } auto dev = AP_HAL::OwnPtr(new I2CDevice(bus, address, bus_clock, use_smbus, timeout_ms)); return dev; } /* get mask of bus numbers for all configured I2C buses */ uint32_t I2CDeviceManager::get_bus_mask(void) const { return ((1U << ARRAY_SIZE(i2c_bus_desc)) - 1); } /* get mask of bus numbers for all configured internal I2C buses */ uint32_t I2CDeviceManager::get_bus_mask_internal(void) const { uint32_t result = 0; for (size_t i = 0; i < ARRAY_SIZE(i2c_bus_desc); i++) { if (i2c_bus_desc[i].internal) { result |= (1u << i); } } return result; } /* get mask of bus numbers for all configured external I2C buses */ uint32_t I2CDeviceManager::get_bus_mask_external(void) const { return get_bus_mask() & ~get_bus_mask_internal(); }