i2c_config ICACHE_FLASH_ATTR *tc_init(uint8 *address, i2c_status *status) { i2c_config *config = NULL; *status = I2C_OK; if (*address == 0) { *address = MOD_TC_MK2_DEFAULT_ADDR; } config = i2c_find_config(*address, MOD_TC_MK2_ID); // Check if there is device at address if (i2c_check_device(*address) != I2C_OK) { *status = I2C_DEVICE_NOT_FOUND; return config; } uint8 id; // Check if device is MOD-TC-MK2 if (i2c_read_id(*address, &id) != I2C_OK) { *status = I2C_COMMUNICATION_FAILED; return config; } if (id != MOD_TC_MK2_ID) { *status = I2C_DEVICE_ID_DONT_MATCH; return config; } if (config == NULL) { config = i2c_add_config(*address, MOD_TC_MK2_ID, (void *)os_zalloc(sizeof(tc_config_data))); } return config; }
i2c_config ICACHE_FLASH_ATTR *io2_init(uint8 *address, i2c_status *status) { i2c_config *config = NULL; *status = I2C_OK; if (*address == 0) { *address = MOD_IO2_DEFAULT_ADDR; } config = i2c_find_config(*address, MOD_IO2_ID); // Check if there is device at address if (i2c_check_device(*address) != I2C_OK) { *status = I2C_DEVICE_NOT_FOUND; return config; } uint8 id; // Check if device is MOD-IO2 if (i2c_read_id(*address, &id) != I2C_OK) { *status = I2C_COMMUNICATION_FAILED; return config; } if (id != MOD_IO2_ID) { *status = I2C_DEVICE_ID_DONT_MATCH; return config; } // Set GPIO direction // GPIO bit 7654 3210 // 0001 1011 [0 - out, 1 - in] *status = io2_set_execute(*address, 0x01, 0x1B); if (*status != I2C_OK) { return config; } // Set GPIO pull up *status = io2_set_execute(*address, 0x04, 0x18); if (*status != I2C_OK) { return config; } if (config == NULL) { config = i2c_add_config(*address, MOD_IO2_ID, (void *)os_zalloc(sizeof(io2_config_data))); } return config; }
i2c_config ICACHE_FLASH_ATTR *robko_init(uint8 *address, i2c_status *status) { i2c_config *config = NULL; *status = I2C_OK; if (*address == 0) { *address = ROBKO_DEFAULT_ADDR; } config = i2c_find_config(*address, ROBKO_ID); i2c_master_stop(); // Check if there is device at address if (i2c_check_device(*address) != I2C_OK) { *status = I2C_DEVICE_NOT_FOUND; return config; } uint8 id; // Check if device is ROBKO if (i2c_read_id(*address, &id) != I2C_OK) { *status = I2C_COMMUNICATION_FAILED; return config; } if (id != ROBKO_ID) { #if ROBKO_DEBUG debug("ROBKO: ID do not match [0x%02X] \n", id); #endif *status = I2C_DEVICE_ID_DONT_MATCH; return config; } if (config == NULL) { config = i2c_add_config(*address, ROBKO_ID, (void *)os_zalloc(sizeof(robko_config_data))); } return config; }