dev_spi.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * Copyright (c) 2006-2025 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-11-23 Bernard Add extern "C"
  9. * 2020-06-13 armink fix the 3 wires issue
  10. * 2022-09-01 liYony fix api rt_spi_sendrecv16 about MSB and LSB bug
  11. */
  12. #ifndef __DEV_SPI_H__
  13. #define __DEV_SPI_H__
  14. #include <stdlib.h>
  15. #include <rtthread.h>
  16. #include <drivers/dev_pin.h>
  17. #include <drivers/core/driver.h>
  18. /**
  19. * @defgroup group_drivers_spi SPI
  20. * @brief SPI driver api
  21. * @ingroup group_device_driver
  22. *
  23. * <b>Example</b>
  24. * @code {.c}
  25. * #include <rtthread.h>
  26. * #include <rtdevice.h>
  27. *
  28. * #define W25Q_SPI_DEVICE_NAME "qspi10"
  29. *
  30. * static void spi_w25q_sample(int argc, char *argv[])
  31. * {
  32. * struct rt_spi_device *spi_dev_w25q;
  33. * char name[RT_NAME_MAX];
  34. * rt_uint8_t w25x_read_id = 0x90;
  35. * rt_uint8_t id[5] = {0};
  36. *
  37. * if (argc == 2)
  38. * {
  39. * rt_strncpy(name, argv[1], RT_NAME_MAX);
  40. * }
  41. * else
  42. * {
  43. * rt_strncpy(name, W25Q_SPI_DEVICE_NAME, RT_NAME_MAX);
  44. * }
  45. *
  46. * // 查找 spi 设备获取设备句柄
  47. * spi_dev_w25q = (struct rt_spi_device *)rt_device_find(name);
  48. * if (!spi_dev_w25q)
  49. * {
  50. * rt_kprintf("spi sample run failed! can't find %s device!\n", name);
  51. * }
  52. * else
  53. * {
  54. * // 方式1:使用 rt_spi_send_then_recv()发送命令读取ID
  55. * rt_spi_send_then_recv(spi_dev_w25q, &w25x_read_id, 1, id, 5);
  56. * rt_kprintf("use rt_spi_send_then_recv() read w25q ID is:%x%x\n", id[3], id[4]);
  57. *
  58. * // 方式2:使用 rt_spi_transfer_message()发送命令读取ID
  59. * struct rt_spi_message msg1, msg2;
  60. *
  61. * msg1.send_buf = &w25x_read_id;
  62. * msg1.recv_buf = RT_NULL;
  63. * msg1.length = 1;
  64. * msg1.cs_take = 1;
  65. * msg1.cs_release = 0;
  66. * msg1.next = &msg2;
  67. *
  68. * msg2.send_buf = RT_NULL;
  69. * msg2.recv_buf = id;
  70. * msg2.length = 5;
  71. * msg2.cs_take = 0;
  72. * msg2.cs_release = 1;
  73. * msg2.next = RT_NULL;
  74. *
  75. * rt_spi_transfer_message(spi_dev_w25q, &msg1);
  76. * rt_kprintf("use rt_spi_transfer_message() read w25q ID is:%x%x\n", id[3], id[4]);
  77. *
  78. * }
  79. * }
  80. * // 导出到 msh 命令列表中
  81. * MSH_CMD_EXPORT(spi_w25q_sample, spi w25q sample);
  82. * @endcode
  83. */
  84. /*!
  85. * @addtogroup group_drivers_spi
  86. * @{
  87. */
  88. #ifdef __cplusplus
  89. extern "C"{
  90. #endif
  91. /**
  92. * At CPOL=0 the base value of the clock is zero
  93. * - For CPHA=0, data are captured on the clock's rising edge (low->high transition)
  94. * and data are propagated on a falling edge (high->low clock transition).
  95. * - For CPHA=1, data are captured on the clock's falling edge and data are
  96. * propagated on a rising edge.
  97. * At CPOL=1 the base value of the clock is one (inversion of CPOL=0)
  98. * - For CPHA=0, data are captured on clock's falling edge and data are propagated
  99. * on a rising edge.
  100. * - For CPHA=1, data are captured on clock's rising edge and data are propagated
  101. * on a falling edge.
  102. */
  103. #define RT_SPI_CPHA (1<<0) /*!< bit[0]:CPHA, clock phase */
  104. #define RT_SPI_CPOL (1<<1) /*!< bit[1]:CPOL, clock polarity */
  105. #define RT_SPI_LSB (0<<2) /*!< bit[2]: 0-LSB */
  106. #define RT_SPI_MSB (1<<2) /*!< bit[2]: 1-MSB */
  107. #define RT_SPI_MASTER (0<<3) /*!< SPI master device */
  108. #define RT_SPI_SLAVE (1<<3) /*!< SPI slave device */
  109. #define RT_SPI_CS_HIGH (1<<4) /*!< Chipselect active high */
  110. #define RT_SPI_NO_CS (1<<5) /*!< No chipselect */
  111. #define RT_SPI_3WIRE (1<<6) /*!< SI/SO pin shared */
  112. #define RT_SPI_READY (1<<7) /*!< Slave pulls low to pause */
  113. #define RT_SPI_MODE_MASK (RT_SPI_CPHA | RT_SPI_CPOL | RT_SPI_MSB | RT_SPI_SLAVE | RT_SPI_CS_HIGH | RT_SPI_NO_CS | RT_SPI_3WIRE | RT_SPI_READY)
  114. #define RT_SPI_MODE_0 (0 | 0) /*!< CPOL = 0, CPHA = 0 */
  115. #define RT_SPI_MODE_1 (0 | RT_SPI_CPHA) /*!< CPOL = 0, CPHA = 1 */
  116. #define RT_SPI_MODE_2 (RT_SPI_CPOL | 0) /*!< CPOL = 1, CPHA = 0 */
  117. #define RT_SPI_MODE_3 (RT_SPI_CPOL | RT_SPI_CPHA) /*!< CPOL = 1, CPHA = 1 */
  118. #define RT_SPI_BUS_MODE_SPI (1<<0)
  119. #define RT_SPI_BUS_MODE_QSPI (1<<1)
  120. #define RT_SPI_CS_CNT_MAX 16
  121. /**
  122. * @brief SPI message structure
  123. */
  124. struct rt_spi_message
  125. {
  126. const void *send_buf;
  127. void *recv_buf;
  128. rt_size_t length;
  129. struct rt_spi_message *next;
  130. unsigned cs_take : 1;
  131. unsigned cs_release : 1;
  132. };
  133. /**
  134. * @brief SPI configuration structure
  135. */
  136. struct rt_spi_configuration
  137. {
  138. rt_uint8_t mode;
  139. rt_uint8_t data_width;
  140. #ifdef RT_USING_DM
  141. rt_uint8_t data_width_tx;
  142. rt_uint8_t data_width_rx;
  143. #else
  144. rt_uint16_t reserved;
  145. #endif
  146. rt_uint32_t max_hz;
  147. };
  148. struct rt_spi_ops;
  149. /**
  150. * @brief SPI bus structure
  151. */
  152. struct rt_spi_bus
  153. {
  154. struct rt_device parent;
  155. rt_uint8_t mode;
  156. const struct rt_spi_ops *ops;
  157. #ifdef RT_USING_DM
  158. rt_base_t cs_pins[RT_SPI_CS_CNT_MAX];
  159. rt_uint8_t cs_active_vals[RT_SPI_CS_CNT_MAX];
  160. rt_bool_t slave;
  161. int num_chipselect;
  162. #endif /* RT_USING_DM */
  163. struct rt_mutex lock;
  164. struct rt_spi_device *owner;
  165. };
  166. /**
  167. * @brief SPI operators
  168. */
  169. struct rt_spi_ops
  170. {
  171. rt_err_t (*configure)(struct rt_spi_device *device, struct rt_spi_configuration *configuration);
  172. rt_ssize_t (*xfer)(struct rt_spi_device *device, struct rt_spi_message *message);
  173. };
  174. #ifdef RT_USING_DM
  175. /**
  176. * @brief SPI delay info
  177. */
  178. struct rt_spi_delay
  179. {
  180. #define RT_SPI_DELAY_UNIT_USECS 0
  181. #define RT_SPI_DELAY_UNIT_NSECS 1
  182. #define RT_SPI_DELAY_UNIT_SCK 2
  183. rt_uint16_t value;
  184. rt_uint8_t unit;
  185. };
  186. #endif /* RT_USING_DM */
  187. /**
  188. * @brief SPI Virtual BUS, one device must connected to a virtual BUS
  189. */
  190. struct rt_spi_device
  191. {
  192. struct rt_device parent;
  193. struct rt_spi_bus *bus;
  194. #ifdef RT_USING_DM
  195. const char *name;
  196. const struct rt_spi_device_id *id;
  197. const struct rt_ofw_node_id *ofw_id;
  198. rt_uint8_t chip_select[RT_SPI_CS_CNT_MAX];
  199. struct rt_spi_delay cs_setup;
  200. struct rt_spi_delay cs_hold;
  201. struct rt_spi_delay cs_inactive;
  202. #endif
  203. struct rt_spi_configuration config;
  204. rt_base_t cs_pin;
  205. void *user_data;
  206. };
  207. /**
  208. * @brief QSPI message structure
  209. */
  210. struct rt_qspi_message
  211. {
  212. struct rt_spi_message parent;
  213. /* instruction stage */
  214. struct
  215. {
  216. rt_uint8_t content;
  217. rt_uint8_t qspi_lines;
  218. } instruction;
  219. /* address and alternate_bytes stage */
  220. struct
  221. {
  222. rt_uint32_t content;
  223. rt_uint8_t size;
  224. rt_uint8_t qspi_lines;
  225. } address, alternate_bytes;
  226. /* dummy_cycles stage */
  227. rt_uint32_t dummy_cycles;
  228. /* number of lines in qspi data stage, the other configuration items are in parent */
  229. rt_uint8_t qspi_data_lines;
  230. };
  231. /**
  232. * @brief QSPI configuration structure
  233. */
  234. struct rt_qspi_configuration
  235. {
  236. struct rt_spi_configuration parent;
  237. /* The size of medium */
  238. rt_uint32_t medium_size;
  239. /* double data rate mode */
  240. rt_uint8_t ddr_mode;
  241. /* the data lines max width which QSPI bus supported, such as 1, 2, 4 */
  242. rt_uint8_t qspi_dl_width ;
  243. };
  244. /**
  245. * @brief QSPI operators
  246. */
  247. struct rt_qspi_device
  248. {
  249. struct rt_spi_device parent;
  250. struct rt_qspi_configuration config;
  251. void (*enter_qspi_mode)(struct rt_qspi_device *device);
  252. void (*exit_qspi_mode)(struct rt_qspi_device *device);
  253. };
  254. #define SPI_DEVICE(dev) ((struct rt_spi_device *)(dev))
  255. #ifdef RT_USING_DM
  256. struct rt_spi_device_id
  257. {
  258. char name[20];
  259. void *data;
  260. };
  261. struct rt_spi_driver
  262. {
  263. struct rt_driver parent;
  264. const struct rt_spi_device_id *ids;
  265. const struct rt_ofw_node_id *ofw_ids;
  266. rt_err_t (*probe)(struct rt_spi_device *device);
  267. rt_err_t (*remove)(struct rt_spi_device *device);
  268. rt_err_t (*shutdown)(struct rt_spi_device *device);
  269. };
  270. rt_err_t rt_spi_driver_register(struct rt_spi_driver *driver);
  271. rt_err_t rt_spi_device_register(struct rt_spi_device *device);
  272. #define RT_SPI_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, spi, BUILIN)
  273. rt_inline const void *rt_spi_device_id_data(struct rt_spi_device *device)
  274. {
  275. return device->id ? device->id->data : (device->ofw_id ? device->ofw_id->data : RT_NULL);
  276. }
  277. #endif /* RT_USING_DM */
  278. /**
  279. * @brief register a SPI bus
  280. *
  281. * @param bus the SPI bus
  282. * @param name the name of SPI bus
  283. * @param ops the operations of SPI bus
  284. *
  285. * @return rt_err_t error code
  286. */
  287. rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
  288. const char *name,
  289. const struct rt_spi_ops *ops);
  290. /**
  291. * @brief attach a device on SPI bus
  292. *
  293. * @param device the SPI device
  294. * @param name the name of SPI device
  295. * @param bus_name the name of SPI bus
  296. * @param user_data the user data of SPI device
  297. *
  298. * @return rt_err_t error code
  299. */
  300. rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
  301. const char *name,
  302. const char *bus_name,
  303. void *user_data);
  304. /**
  305. * @brief Detach a device from the SPI bus.
  306. *
  307. * This function serves as the high-level API to detach a SPI device from its bus.
  308. * It unregisters the device from the device framework and ensures all associated
  309. * resources, such as the chip select pin, are properly released by calling
  310. * the underlying implementation.
  311. *
  312. * @param device The SPI device to be detached.
  313. *
  314. * @return rt_err_t The result of the operation. RT_EOK on success, otherwise an error code.
  315. */
  316. rt_err_t rt_spi_bus_detach_device(struct rt_spi_device *device);
  317. /**
  318. * @brief attach a device on SPI bus with CS pin
  319. *
  320. * @param device the SPI device
  321. * @param name the name of SPI device
  322. * @param bus_name the name of SPI bus
  323. * @param cs_pin the CS pin of SPI device
  324. * @param user_data the user data of SPI device
  325. *
  326. * @return rt_err_t error code
  327. */
  328. rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device,
  329. const char *name,
  330. const char *bus_name,
  331. rt_base_t cs_pin,
  332. void *user_data);
  333. /**
  334. * @brief Detach a device from the SPI bus and release its CS pin.
  335. *
  336. * This function provides the low-level implementation for detaching a device
  337. * from the SPI bus. It specifically handles the operations for the chip select (CS)
  338. * pin, resetting it to input mode to release it. This function is typically
  339. * called by the higher-level rt_spi_bus_detach_device() and should not be
  340. * called directly by the user application.
  341. *
  342. * @param device The SPI device to be detached.
  343. *
  344. * @return rt_err_t The result of the operation. RT_EOK on success, otherwise an error code.
  345. */
  346. rt_err_t rt_spi_bus_detach_device_cspin(struct rt_spi_device *device);
  347. /**
  348. * @brief Reconfigure the SPI bus for the specified device.
  349. *
  350. * @param device: Pointer to the SPI device attached to the SPI bus.
  351. * @retval RT_EOK if the SPI device was successfully released and the bus was configured.
  352. * RT_EBUSY if the SPI bus is currently in use; the new configuration will take effect once the device releases the bus.
  353. * Other return values indicate failure to configure the SPI bus due to various reasons.
  354. * @note If the configuration of the SPI device has been updated and requires bus re-initialization,
  355. * call this function directly. This function will reconfigure the SPI bus for the specified device.
  356. * If this is the first time to initialize the SPI device, please call rt_spi_configure or rt_qspi_configure.
  357. * This function is used to reconfigure the SPI bus when the SPI device is already in use.
  358. * For further details, refer to:
  359. * https://github.com/RT-Thread/rt-thread/pull/8528
  360. */
  361. rt_err_t rt_spi_bus_configure(struct rt_spi_device *device);
  362. /**
  363. * @brief This function takes SPI bus.
  364. *
  365. * @param device the SPI device attached to SPI bus
  366. *
  367. * @return RT_EOK on taken SPI bus successfully. others on taken SPI bus failed.
  368. */
  369. rt_err_t rt_spi_take_bus(struct rt_spi_device *device);
  370. /**
  371. * @brief This function releases SPI bus.
  372. *
  373. * @param device the SPI device attached to SPI bus
  374. *
  375. * @return RT_EOK on release SPI bus successfully.
  376. */
  377. rt_err_t rt_spi_release_bus(struct rt_spi_device *device);
  378. /**
  379. * @brief This function take SPI device (takes CS of SPI device).
  380. *
  381. * @param device the SPI device attached to SPI bus
  382. *
  383. * @return RT_EOK on release SPI bus successfully. others on taken SPI bus failed.
  384. */
  385. rt_err_t rt_spi_take(struct rt_spi_device *device);
  386. /**
  387. * @brief This function releases SPI device (releases CS of SPI device).
  388. *
  389. * @param device the SPI device attached to SPI bus
  390. *
  391. * @return RT_EOK on release SPI device successfully.
  392. */
  393. rt_err_t rt_spi_release(struct rt_spi_device *device);
  394. /**
  395. * @brief This function can set configuration on SPI device.
  396. *
  397. * @param device: the SPI device attached to SPI bus
  398. * @param cfg: the configuration pointer.
  399. *
  400. * @retval RT_EOK on release SPI device successfully.
  401. * RT_EBUSY is not an error condition and the configuration will take effect once the device has the bus
  402. * others on taken SPI bus failed.
  403. */
  404. rt_err_t rt_spi_configure(struct rt_spi_device *device,
  405. struct rt_spi_configuration *cfg);
  406. /**
  407. * @brief This function can send data then receive data from SPI device.
  408. *
  409. * @param device the SPI device attached to SPI bus
  410. * @param send_buf the buffer to be transmitted to SPI device.
  411. * @param send_length the number of data to be transmitted.
  412. * @param recv_buf the buffer to be recivied from SPI device.
  413. * @param recv_length the data to be recivied.
  414. *
  415. * @return rt_err_t error code
  416. */
  417. rt_err_t rt_spi_send_then_recv(struct rt_spi_device *device,
  418. const void *send_buf,
  419. rt_size_t send_length,
  420. void *recv_buf,
  421. rt_size_t recv_length);
  422. /**
  423. * @brief This function can send data then send data from SPI device.
  424. *
  425. * @param device the SPI device attached to SPI bus
  426. * @param send_buf1 the buffer to be transmitted to SPI device.
  427. * @param send_length1 the number of data to be transmitted.
  428. * @param send_buf2 the buffer to be transmitted to SPI device.
  429. * @param send_length2 the number of data to be transmitted.
  430. *
  431. * @return the status of transmit.
  432. */
  433. rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
  434. const void *send_buf1,
  435. rt_size_t send_length1,
  436. const void *send_buf2,
  437. rt_size_t send_length2);
  438. /**
  439. * @brief This function transmits data to SPI device.
  440. *
  441. * @param device the SPI device attached to SPI bus
  442. * @param send_buf the buffer to be transmitted to SPI device.
  443. * @param recv_buf the buffer to save received data from SPI device.
  444. * @param length the length of transmitted data.
  445. *
  446. * @return the actual length of transmitted.
  447. */
  448. rt_ssize_t rt_spi_transfer(struct rt_spi_device *device,
  449. const void *send_buf,
  450. void *recv_buf,
  451. rt_size_t length);
  452. /**
  453. * @brief The SPI device transmits 8 bytes of data
  454. *
  455. * @param device the SPI device attached to SPI bus
  456. * @param senddata send data buffer
  457. * @param recvdata receive data buffer
  458. *
  459. * @return rt_err_t error code
  460. */
  461. rt_err_t rt_spi_sendrecv8(struct rt_spi_device *device,
  462. rt_uint8_t senddata,
  463. rt_uint8_t *recvdata);
  464. /**
  465. * @brief The SPI device transmits 16 bytes of data
  466. *
  467. * @param device the SPI device attached to SPI bus
  468. * @param senddata send data buffer
  469. * @param recvdata receive data buffer
  470. *
  471. * @return rt_err_t error code
  472. */
  473. rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device,
  474. rt_uint16_t senddata,
  475. rt_uint16_t *recvdata);
  476. /**
  477. * @brief This function transfers a message list to the SPI device.
  478. *
  479. * @param device the SPI device attached to SPI bus
  480. * @param message the message list to be transmitted to SPI device
  481. *
  482. * @return RT_NULL if transmits message list successfully,
  483. * SPI message which be transmitted failed.
  484. */
  485. struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
  486. struct rt_spi_message *message);
  487. /**
  488. * @brief This function receives data from SPI device.
  489. *
  490. * @param device the SPI device attached to SPI bus
  491. * @param recv_buf the buffer to be recivied from SPI device.
  492. * @param length the data to be recivied.
  493. *
  494. * @return the actual length of received.
  495. */
  496. rt_inline rt_size_t rt_spi_recv(struct rt_spi_device *device,
  497. void *recv_buf,
  498. rt_size_t length)
  499. {
  500. return rt_spi_transfer(device, RT_NULL, recv_buf, length);
  501. }
  502. /**
  503. * @brief This function sends data to SPI device.
  504. *
  505. * @param device the SPI device attached to SPI bus
  506. * @param send_buf the buffer to be transmitted to SPI device.
  507. * @param length the number of data to be transmitted.
  508. *
  509. * @return the actual length of send.
  510. */
  511. rt_inline rt_size_t rt_spi_send(struct rt_spi_device *device,
  512. const void *send_buf,
  513. rt_size_t length)
  514. {
  515. return rt_spi_transfer(device, send_buf, RT_NULL, length);
  516. }
  517. /**
  518. * @brief This function appends a message to the SPI message list.
  519. *
  520. * @param list the SPI message list header.
  521. * @param message the message pointer to be appended to the message list.
  522. */
  523. rt_inline void rt_spi_message_append(struct rt_spi_message *list,
  524. struct rt_spi_message *message)
  525. {
  526. RT_ASSERT(list != RT_NULL);
  527. if (message == RT_NULL)
  528. return; /* not append */
  529. while (list->next != RT_NULL)
  530. {
  531. list = list->next;
  532. }
  533. list->next = message;
  534. message->next = RT_NULL;
  535. }
  536. /**
  537. * @brief This function can set configuration on QSPI device.
  538. *
  539. * @param device the QSPI device attached to QSPI bus.
  540. * @param cfg the configuration pointer.
  541. *
  542. * @return the actual length of transmitted.
  543. */
  544. rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configuration *cfg);
  545. /**
  546. * @brief This function can register a SPI bus for QSPI mode.
  547. *
  548. * @param bus the SPI bus for QSPI mode.
  549. * @param name The name of the spi bus.
  550. * @param ops the SPI bus instance to be registered.
  551. *
  552. * @return the actual length of transmitted.
  553. */
  554. rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const struct rt_spi_ops *ops);
  555. /**
  556. * @brief This function transmits data to QSPI device.
  557. *
  558. * @param device the QSPI device attached to QSPI bus.
  559. * @param message the message pointer.
  560. *
  561. * @return the actual length of transmitted.
  562. */
  563. rt_ssize_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message);
  564. /**
  565. * @brief This function can send data then receive data from QSPI device
  566. *
  567. * @param device the QSPI device attached to QSPI bus.
  568. * @param send_buf the buffer to be transmitted to QSPI device.
  569. * @param send_length the number of data to be transmitted.
  570. * @param recv_buf the buffer to be recivied from QSPI device.
  571. * @param recv_length the data to be recivied.
  572. *
  573. * @return the status of transmit.
  574. */
  575. rt_ssize_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length,void *recv_buf, rt_size_t recv_length);
  576. /**
  577. * @brief This function can send data to QSPI device
  578. *
  579. * @param device the QSPI device attached to QSPI bus.
  580. * @param send_buf the buffer to be transmitted to QSPI device.
  581. * @param length the number of data to be transmitted.
  582. *
  583. * @return the status of transmit.
  584. */
  585. rt_ssize_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length);
  586. #ifdef __cplusplus
  587. }
  588. #endif
  589. /*! @}*/
  590. #endif