/ * @brief * Initialize all memory card related hardware and register the device to * kernel * * @details * * @note * * @return * Error code ******************************************************************************/
| 1193 | * Error code |
| 1194 | ******************************************************************************/ |
| 1195 | rt_err_t efm_spiSd_init(void) |
| 1196 | { |
| 1197 | struct efm32_usart_device_t *usart; |
| 1198 | |
| 1199 | do |
| 1200 | { |
| 1201 | /* Find SPI device */ |
| 1202 | spi = rt_device_find(SPISD_USING_DEVICE_NAME); |
| 1203 | if (spi == RT_NULL) |
| 1204 | { |
| 1205 | sdcard_debug("SPISD: Can't find device %s!\n", |
| 1206 | SPISD_USING_DEVICE_NAME); |
| 1207 | break; |
| 1208 | } |
| 1209 | sdcard_debug("SPISD: Find device %s\n", SPISD_USING_DEVICE_NAME); |
| 1210 | |
| 1211 | /* Config chip slect pin */ |
| 1212 | usart = (struct efm32_usart_device_t *)(spi->user_data); |
| 1213 | if (!(usart->state & USART_STATE_AUTOCS)) |
| 1214 | { |
| 1215 | GPIO_PinModeSet(SD_CS_PORT, SD_CS_PIN, gpioModePushPull, 1); |
| 1216 | sdAutoCs = false; |
| 1217 | } |
| 1218 | |
| 1219 | /* Register SPI SD device */ |
| 1220 | sd_device.type = RT_Device_Class_MTD; |
| 1221 | sd_device.init = rt_spiSd_init; |
| 1222 | sd_device.open = rt_spiSd_open; |
| 1223 | sd_device.close = rt_spiSd_close; |
| 1224 | sd_device.read = rt_spiSd_read; |
| 1225 | sd_device.write = rt_spiSd_write; |
| 1226 | sd_device.control = rt_spiSd_control; |
| 1227 | sd_device.user_data = RT_NULL; |
| 1228 | rt_device_register( |
| 1229 | &sd_device, |
| 1230 | SPISD_DEVICE_NAME, |
| 1231 | RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE); |
| 1232 | |
| 1233 | sdcard_debug("SPISD: HW init OK, card type %x\n", sdType); |
| 1234 | return RT_EOK; |
| 1235 | } while (0); |
| 1236 | |
| 1237 | /* Release buffer */ |
| 1238 | rt_kprintf("SPISD: HW init failed!\n"); |
| 1239 | return -RT_ERROR; |
| 1240 | } |
| 1241 | |
| 1242 | /***************************************************************************//** |
| 1243 | * @brief |
no test coverage detected