| 50 | }; |
| 51 | |
| 52 | static error_t start(Device* device) { |
| 53 | LOG_I(TAG, "start %s", device->name); |
| 54 | |
| 55 | auto* parent = device_get_parent(device); |
| 56 | if (device_get_type(parent) != &SPI_CONTROLLER_TYPE) { |
| 57 | LOG_E(TAG, "Parent device is not an SPI controller"); |
| 58 | return ERROR_INVALID_STATE; |
| 59 | } |
| 60 | |
| 61 | auto* data = new (std::nothrow) Esp32SdspiInternal(); |
| 62 | if (!data) return ERROR_OUT_OF_MEMORY; |
| 63 | |
| 64 | data->lock(); |
| 65 | device_set_driver_data(device, data); |
| 66 | |
| 67 | auto* config = GET_CONFIG(device); |
| 68 | |
| 69 | bool pins_ok = |
| 70 | acquire_pin_or_set_null(config->pin_cd, &data->pin_cd_descriptor) && |
| 71 | acquire_pin_or_set_null(config->pin_wp, &data->pin_wp_descriptor) && |
| 72 | acquire_pin_or_set_null(config->pin_int, &data->pin_int_descriptor); |
| 73 | |
| 74 | if (!pins_ok) { |
| 75 | LOG_E(TAG, "Failed to acquire one or more pins"); |
| 76 | data->cleanup_pins(); |
| 77 | device_set_driver_data(device, nullptr); |
| 78 | data->unlock(); |
| 79 | delete data; |
| 80 | return ERROR_RESOURCE; |
| 81 | } |
| 82 | |
| 83 | GpioPinSpec cs_pin_spec; |
| 84 | if (esp32_spi_get_cs_pin(device, &cs_pin_spec) != ERROR_NONE) { |
| 85 | LOG_E(TAG, "Failed to get CS pin from parent SPI controller"); |
| 86 | data->cleanup_pins(); |
| 87 | device_set_driver_data(device, nullptr); |
| 88 | data->unlock(); |
| 89 | delete data; |
| 90 | return ERROR_RESOURCE; |
| 91 | } |
| 92 | |
| 93 | auto* spi_config = static_cast<const Esp32SpiConfig*>(parent->config); |
| 94 | |
| 95 | // Lower all CS pins |
| 96 | esp32_spi_deselect_all_cs(parent); |
| 97 | // Manually set the CS pin fo |
| 98 | gpio_set_direction(static_cast<gpio_num_t>(cs_pin_spec.pin), GPIO_MODE_OUTPUT); |
| 99 | gpio_set_level(static_cast<gpio_num_t>(cs_pin_spec.pin), 255); |
| 100 | |
| 101 | data->fs_handle = esp32_sdspi_fs_alloc(config, spi_config->host, cs_pin_spec.pin, "/sdcard"); |
| 102 | if (!data->fs_handle) { |
| 103 | data->cleanup_pins(); |
| 104 | device_set_driver_data(device, nullptr); |
| 105 | data->unlock(); |
| 106 | delete data; |
| 107 | return ERROR_OUT_OF_MEMORY; |
| 108 | } |
| 109 |
nothing calls this directly
no test coverage detected