MCPcopy Create free account
hub / github.com/TailsmanDesign/PocketMage_PDA / USB_INIT

Function USB_INIT

Code/PocketMage_V3/src/OS_APPS/USB.cpp:112–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112void USB_INIT() {
113 usb_is_shutting_down = false;
114
115 // Switch USB contol to ESP
116 PowerSystem.setUSBControlESP();
117
118 // OPEN USB FILE TRANSFER
119 OLED().oledWord("Initializing USB");
120 pocketmage::setCpuSpeed(240);
121 delay(50);
122
123 disableTimeout = true;
124
125 if (mscEnabled) return;
126
127 ESP_LOGI(TAG, "Unmounting SD_MMC for USB MSC...");
128
129 SD_MMC.end(); // unmount FS before raw access
130 delay(200); // Give the card hardware a moment to settle state
131
132 // Configure SDMMC host and slot manually
133 sdmmc_host_t host = SDMMC_HOST_DEFAULT();
134 host.max_freq_khz = SDMMC_FREQ_DEFAULT; // Force 20MHz for stability
135
136 sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
137 slot_config.clk = (gpio_num_t)SD_CLK;
138 slot_config.cmd = (gpio_num_t)SD_CMD;
139 slot_config.d0 = (gpio_num_t)SD_D0;
140 slot_config.d1 = (gpio_num_t)0;
141 slot_config.d2 = (gpio_num_t)0;
142 slot_config.d3 = (gpio_num_t)0;
143 slot_config.width = 1; // or 4 for 4-bit mode
144
145 // CRITICAL FIX: Force internal pull-ups to prevent ESP_ERR_TIMEOUT
146 slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
147
148 // Initialize host
149 esp_err_t err = sdmmc_host_init();
150 if (err != ESP_OK) {
151 ESP_LOGE(TAG, "Host init failed %s\n", esp_err_to_name(err));
152 OLED().sysMessage("Host init failed: " + String(esp_err_to_name(err)),2000);
153 return;
154 }
155
156 err = sdmmc_host_init_slot(SDMMC_HOST_SLOT_1, &slot_config);
157 if (err != ESP_OK) {
158 ESP_LOGE(TAG, "Slot init failed: %s\n", esp_err_to_name(err));
159 OLED().sysMessage("Slot init failed: " + String(esp_err_to_name(err)),2000);
160 sdmmc_host_deinit();
161 return;
162 }
163
164 // Allocate card object and mount
165 card = (sdmmc_card_t*)malloc(sizeof(sdmmc_card_t));
166 if (!card) {
167 ESP_LOGE(TAG, "Failed to allocate card struct\n", esp_err_to_name(err));
168 OLED().sysMessage("Failed malloc: " + String(esp_err_to_name(err)),2000);
169 sdmmc_host_deinit();

Callers 2

updateKeypressMethod · 0.85
commandSelectFunction · 0.85

Calls 8

setCpuSpeedFunction · 0.85
StringClass · 0.85
setUSBControlESPMethod · 0.80
oledWordMethod · 0.80
endMethod · 0.80
sysMessageMethod · 0.80
setKeyboardStateMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected