Lines Matching +full:spi +full:- +full:cs +full:- +full:cs +full:- +full:delay
4 * SPDX-License-Identifier: Apache-2.0
9 * @brief Public API for SPI drivers and applications
16 * @brief SPI Interface
17 * @defgroup spi_interface SPI Interface
27 #include <zephyr/dt-bindings/spi/spi.h>
39 * @name SPI operational mode
47 /** Get SPI operational mode. */
52 * @name SPI Polarity & Phase Modes
73 * Whatever data is transmitted is looped-back to the receiving buffer of
81 /** Get SPI polarity and phase mode bits. */
88 * @name SPI Transfer modes (host controller dependent)
96 * @name SPI word size
103 /** Get SPI word size (data frame size) in bits. */
106 /** Set SPI word size (data frame size) in bits. */
112 * @name Specific SPI devices control bits
115 /** Requests - if possible - to keep CS asserted after the transaction */
119 * prevent other callers to access the SPI device until spi_release() is
124 /** Active high logic on CS. Usually, and by default, CS logic is active
128 * the CS control to a gpio line through struct spi_cs_control would be
135 * @name SPI MISO lines
153 * @brief SPI Chip Select control structure
155 * This can be used to control a CS line via a GPIO line, instead of
156 * using the controller inner CS logic.
161 * GPIO devicetree specification of CS GPIO.
162 * The device pointer can be set to NULL to fully inhibit CS control if
169 * Delay in microseconds to wait before starting the
170 * transmission and before releasing the CS line.
172 uint32_t delay; member
176 * @brief Get a <tt>struct gpio_dt_spec</tt> for a SPI device's chip select pin
185 * spi@abcd0003 {
186 * compatible = "vnd,spi";
187 * cs-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>,
190 * a: spi-dev-a@0 {
194 * b: spi-dev-b@1 {
209 * @param spi_dev a SPI device node identifier
217 * @brief Get a <tt>struct gpio_dt_spec</tt> for a SPI device's chip select pin
232 * This helper is useful for initializing a device on a SPI bus. It
234 * Here, @p node_id is a node identifier for a SPI device, not a SPI
240 * spi@abcd0001 {
241 * cs-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
242 * spidev: spi-device@0 { ... };
258 * .delay = 2,
262 * @param node_id Devicetree node identifier for a device on a SPI bus
263 * @param delay_ The @p delay field to set in the @p spi_cs_control
269 .delay = (delay_), \
276 * <tt>SPI_CS_CONTROL_INIT(DT_DRV_INST(inst), delay)</tt>.
282 * @param delay_ The @p delay field to set in the @p spi_cs_control
290 * Opaque type to hold the SPI operation flags.
299 * @brief SPI controller configuration structure
309 * - 0: Master or slave.
310 * - 1..3: Polarity, phase and loop mode.
311 * - 4: LSB or MSB first.
312 * - 5..10: Size of a data frame (word) in bits.
313 * - 11: Full/half duplex.
314 * - 12: Hold on the CS line if possible.
315 * - 13: Keep resource locked for the caller.
316 * - 14: Active high CS logic.
317 * - 15: Motorola or TI frame format (optional).
321 * - 16..17: MISO lines (Single/Dual/Quad/Octal).
322 * - 18..31: Reserved for future use.
328 * @brief GPIO chip-select line (optional, must be initialized to zero
331 struct spi_cs_control cs; member
339 * @p cs data from the devicetree.
341 * @param node_id Devicetree node identifier for the SPI device whose
344 * @param delay_ the desired @p delay field in the struct spi_config's
357 .cs = SPI_CS_CONTROL_INIT(node_id, delay_), \
368 * @param delay_ the desired @p delay field in the struct spi_config's
375 * @brief Complete SPI DT information
378 /** SPI bus */
388 * spi_dt_spec</tt> by reading the relevant bus, frequency, slave, and cs
395 * @param node_id Devicetree node identifier for the SPI device whose
398 * @param delay_ the desired @p delay field in the struct spi_config's
415 * @param delay_ the desired @p delay field in the struct spi_config's
430 * can be queried at compile-time to determine whether allocating a constant
433 * @param node_id Devicetree node identifier for the SPI device to query
456 * @brief SPI buffer structure
469 * @brief SPI buffer array structure
479 STATS_SECT_START(spi)
485 STATS_NAME_START(spi)
486 STATS_NAME(spi, rx_bytes)
487 STATS_NAME(spi, tx_bytes)
488 STATS_NAME(spi, transfer_error)
489 STATS_NAME_END(spi);
492 * @brief SPI specific device state which allows for SPI device class specific additions
500 * @brief Get pointer to SPI statistics structure
503 CONTAINER_OF(dev_->state, struct spi_device_state, devstate)->stats
506 * @brief Increment the rx bytes for a SPI device
514 * @brief Increment the tx bytes for a SPI device
522 * @brief Increment the transfer error counter for a SPI device
532 * @brief Define a statically allocated and section assigned SPI device state
539 * @brief Define an SPI device init wrapper function
548 CONTAINER_OF(dev->state, struct spi_device_state, devstate); \
549 stats_init(&state->stats.s_hdr, STATS_SIZE_32, 3, \
550 STATS_NAME_INIT_PARMS(spi)); \
551 stats_register(dev->name, &(state->stats.s_hdr)); \
556 * @brief Like DEVICE_DT_DEFINE() with SPI specifics.
558 * @details Defines a device which implements the SPI API. May
560 * wrapper when needed depending on SPI @kconfig{CONFIG_SPI_STATS}.
600 tx_bytes = tx_bufs->count ? tx_bufs->buffers->len : 0; in spi_transceive_stats()
605 rx_bytes = rx_bufs->count ? rx_bufs->buffers->len : 0; in spi_transceive_stats()
653 * @brief SPI callback for asynchronous transfer requests
655 * @param dev SPI device which is notifying of transfer completion or error
656 * @param result Result code of the transfer request. 0 is success, -errno for failure.
677 * @brief Callback API for submitting work to a SPI device with RTIO
685 * @brief Callback API for unlocking SPI device.
693 * @brief SPI driver API
694 * This is the mandatory API any SPI driver needs to expose.
708 * @brief Check if SPI CS is controlled using a GPIO.
710 * @param config SPI configuration.
711 * @return true If CS is controlled using a GPIO.
712 * @return false If CS is controlled by hardware or any other means.
716 return config->cs.gpio.port != NULL; in spi_cs_is_gpio()
720 * @brief Check if SPI CS in @ref spi_dt_spec is controlled using a GPIO.
722 * @param spec SPI specification from devicetree.
723 * @return true If CS is controlled using a GPIO.
724 * @return false If CS is controlled by hardware or any other means.
728 return spi_cs_is_gpio(&spec->config); in spi_cs_is_gpio_dt()
732 * @brief Validate that SPI bus (and CS gpio if defined) is ready.
734 * @param spec SPI specification from devicetree
736 * @retval true if the SPI bus is ready for use.
737 * @retval false if the SPI bus (or the CS gpio defined) is not ready for use.
742 if (!device_is_ready(spec->bus)) { in spi_is_ready_dt()
745 /* Validate CS gpio port is ready, if it is used */ in spi_is_ready_dt()
747 !gpio_is_ready_dt(&spec->config.cs.gpio)) { in spi_is_ready_dt()
754 * @brief Read/write the specified amount of data from the SPI driver.
760 * Pointer-comparison may be used to detect changes from
769 * @retval -errno Negative errno code on failure.
782 (const struct spi_driver_api *)dev->api; in z_impl_spi_transceive()
785 ret = api->transceive(dev, config, tx_bufs, rx_bufs); in z_impl_spi_transceive()
792 * @brief Read/write data from an SPI bus specified in @p spi_dt_spec.
796 * spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs);
798 * @param spec SPI specification from devicetree
810 return spi_transceive(spec->bus, &spec->config, tx_bufs, rx_bufs); in spi_transceive_dt()
814 * @brief Read the specified amount of data from the SPI driver.
822 * Pointer-comparison may be used to detect changes from
828 * @retval -errno Negative errno code on failure.
838 * @brief Read data from a SPI bus specified in @p spi_dt_spec.
842 * spi_read(spec->bus, &spec->config, rx_bufs);
844 * @param spec SPI specification from devicetree
852 return spi_read(spec->bus, &spec->config, rx_bufs); in spi_read_dt()
856 * @brief Write the specified amount of data from the SPI driver.
864 * Pointer-comparison may be used to detect changes from
869 * @retval -errno Negative errno code on failure.
879 * @brief Write data to a SPI bus specified in @p spi_dt_spec.
883 * spi_write(spec->bus, &spec->config, tx_bufs);
885 * @param spec SPI specification from devicetree
893 return spi_write(spec->bus, &spec->config, tx_bufs); in spi_write_dt()
899 * @brief Read/write the specified amount of data from the SPI driver.
908 * Pointer-comparison may be used to detect changes from
922 * @retval -errno Negative errno code on failure.
932 (const struct spi_driver_api *)dev->api; in spi_transceive_cb()
934 return api->transceive_async(dev, config, tx_bufs, rx_bufs, callback, userdata); in spi_transceive_cb()
944 * @brief Read/write the specified amount of data from the SPI driver.
953 * Pointer-comparison may be used to detect changes from
966 * @retval -errno Negative errno code on failure.
975 (const struct spi_driver_api *)dev->api; in spi_transceive_signal()
978 return api->transceive_async(dev, config, tx_bufs, rx_bufs, cb, sig); in spi_transceive_signal()
982 * @brief Read the specified amount of data from the SPI driver.
993 * Pointer-comparison may be used to detect changes from
1003 * @retval -errno Negative errno code on failure.
1014 * @brief Write the specified amount of data from the SPI driver.
1025 * Pointer-comparison may be used to detect changes from
1034 * @retval -errno Negative errno code on failure.
1052 * @brief Submit a SPI device with a request
1060 const struct spi_dt_spec *dt_spec = (const struct spi_dt_spec *)iodev_sqe->sqe.iodev->data; in spi_iodev_submit()
1061 const struct device *dev = dt_spec->bus; in spi_iodev_submit()
1062 const struct spi_driver_api *api = (const struct spi_driver_api *)dev->api; in spi_iodev_submit()
1064 api->iodev_submit(dt_spec->bus, iodev_sqe); in spi_iodev_submit()
1077 * @param operation_ SPI operational mode
1078 * @param delay_ Chip select delay in microseconds
1086 * @brief Validate that SPI bus (and CS gpio if defined) is ready.
1088 * @param spi_iodev SPI iodev defined with SPI_DT_IODEV_DEFINE
1090 * @retval true if the SPI bus is ready for use.
1091 * @retval false if the SPI bus (or the CS gpio defined) is not ready for use.
1095 struct spi_dt_spec *spec = (struct spi_dt_spec *)spi_iodev->data; in spi_is_ready_iodev()
1103 * @brief Release the SPI device locked on and/or the CS by the current config
1106 * SPI device and/or the CS line that was kept if, and if only,
1110 * This can be used if the caller needs to keep its hand on the SPI
1120 * @retval -errno Negative errno code on failure.
1129 (const struct spi_driver_api *)dev->api; in z_impl_spi_release()
1131 return api->release(dev, config); in z_impl_spi_release()
1135 * @brief Release the SPI device specified in @p spi_dt_spec.
1139 * spi_release(spec->bus, &spec->config);
1141 * @param spec SPI specification from devicetree
1147 return spi_release(spec->bus, &spec->config); in spi_release_dt()
1158 #include <zephyr/syscalls/spi.h>