Solaris Software
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1/**
2 * @file spi.h
3 * @brief SPP SPI HAL API — dispatches through the registered HAL port.
4 */
5
6#ifndef SPP_HAL_SPI_H
7#define SPP_HAL_SPI_H
8
9#include "spp/core/types.h"
11
12/* ----------------------------------------------------------------
13 * SPI configuration types
14 * ---------------------------------------------------------------- */
15
16/**
17 * @brief SPI clock phase/polarity mode.
18 */
19typedef enum
20{
21 K_SPP_SPI_MODE0 = 0U, /**< CPOL=0, CPHA=0. */
22 K_SPP_SPI_MODE1 = 1U, /**< CPOL=0, CPHA=1. */
23 K_SPP_SPI_MODE3 = 3U /**< CPOL=1, CPHA=1. */
25
26/**
27 * @brief SPI duplex mode.
28 */
29typedef enum
30{
31 K_SPP_SPI_FULL_DUPLEX = 0U, /**< Simultaneous TX and RX. */
32 K_SPP_SPI_HALF_DUPLEX = 1U /**< Shared TX/RX line. */
34
35/**
36 * @brief SPI bus and device initialisation configuration.
37 *
38 * Passed to the HAL port's @c spiDeviceInit callback to describe one
39 * physical SPI device.
40 */
41typedef struct
42{
43 int busId; /**< SPI bus / host identifier (platform-defined). */
44 int pinMiso; /**< MISO (CIPO) GPIO number. */
45 int pinMosi; /**< MOSI (COPI) GPIO number. */
46 int pinSclk; /**< Clock GPIO number. */
47 int pinCs; /**< Chip-select GPIO number. */
48 unsigned int maxHz; /**< Maximum SPI clock frequency in Hz. */
49 SPP_SpiMode_t mode; /**< SPI clock mode. */
50 SPP_SpiDuplex_t duplex; /**< Duplex mode. */
51 unsigned int queueSize; /**< Transaction queue depth. */
53
54/* ----------------------------------------------------------------
55 * Public API
56 * ---------------------------------------------------------------- */
57
58/**
59 * @brief Initialise the SPI bus.
60 *
61 * Safe to call multiple times; subsequent calls are no-ops.
62 *
63 * @return K_SPP_OK on success.
64 */
66
67/**
68 * @brief Obtain the SPI device handle for the given device index.
69 *
70 * @param[in] deviceIdx Zero-based device index (0 = first device, etc.).
71 *
72 * @return Opaque handle on success, NULL if index is out of range.
73 */
74void *SPP_HAL_SPI_getHandle(spp_uint8_t deviceIdx);
75
76/**
77 * @brief Initialise a specific SPI device.
78 *
79 * @param[in] p_handle Handle returned by @ref SPP_HAL_SPI_getHandle().
80 *
81 * @return K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if handle is NULL.
82 */
84
85/**
86 * @brief Perform a full-duplex SPI transaction.
87 *
88 * @param[in,out] p_handle SPI device handle.
89 * @param[in,out] p_data TX data in, RX data out (in-place).
90 * @param[in] length Number of bytes in the transaction.
91 *
92 * @return K_SPP_OK on success, K_SPP_ERROR_ON_SPI_TRANSACTION on failure.
93 */
94SPP_RetVal_t SPP_HAL_SPI_transmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length);
95
96/**
97 * @brief Remove and re-add a SPI device with a new clock speed.
98 *
99 * Intended for devices that require a lower speed during initialisation
100 * and a higher speed for normal operation (e.g. SD cards: 400 kHz init,
101 * up to 25 MHz normal operation).
102 *
103 * @param[in] p_handle Handle returned by @ref SPP_HAL_SPI_getHandle().
104 * @param[in] speedHz New clock frequency in Hz.
105 *
106 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
107 */
109
110#endif /* SPP_HAL_SPI_H */
Standard return-value type used across all SPP modules.
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
SPP_RetVal_t SPP_HAL_SPI_deviceSetSpeed(void *p_handle, spp_uint32_t speedHz)
Remove and re-add a SPI device with a new clock speed.
Definition spi.c:69
void * SPP_HAL_SPI_getHandle(spp_uint8_t deviceIdx)
Obtain the SPI device handle for the given device index.
Definition spi.c:39
SPP_RetVal_t SPP_HAL_SPI_deviceInit(void *p_handle)
Initialise a specific SPI device.
Definition spi.c:49
SPP_RetVal_t SPP_HAL_SPI_transmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
Perform a full-duplex SPI transaction.
Definition spi.c:79
SPP_RetVal_t SPP_HAL_SPI_busInit(void)
Initialise the SPI bus.
Definition spi.c:19
SPP_SpiDuplex_t
SPI duplex mode.
Definition spi.h:30
@ K_SPP_SPI_FULL_DUPLEX
Definition spi.h:31
@ K_SPP_SPI_HALF_DUPLEX
Definition spi.h:32
SPP_SpiMode_t
SPI clock phase/polarity mode.
Definition spi.h:20
@ K_SPP_SPI_MODE3
Definition spi.h:23
@ K_SPP_SPI_MODE1
Definition spi.h:22
@ K_SPP_SPI_MODE0
Definition spi.h:21
SPI bus and device initialisation configuration.
Definition spi.h:42
int pinSclk
Definition spi.h:46
unsigned int queueSize
Definition spi.h:51
SPP_SpiMode_t mode
Definition spi.h:49
int pinMosi
Definition spi.h:45
SPP_SpiDuplex_t duplex
Definition spi.h:50
unsigned int maxHz
Definition spi.h:48
int pinMiso
Definition spi.h:44
Portable integer types and SPI/storage configuration types for SPP.
uint32_t spp_uint32_t
Definition types.h:31
uint8_t spp_uint8_t
Definition types.h:27