Solaris Software
Toggle main menu visibility
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
"
10
#include "
spp/core/returnTypes.h
"
11
12
/* ----------------------------------------------------------------
13
* SPI configuration types
14
* ---------------------------------------------------------------- */
15
16
/**
17
* @brief SPI clock phase/polarity mode.
18
*/
19
typedef
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. */
24
}
SPP_SpiMode_t
;
25
26
/**
27
* @brief SPI duplex mode.
28
*/
29
typedef
enum
30
{
31
K_SPP_SPI_FULL_DUPLEX
= 0U,
/**< Simultaneous TX and RX. */
32
K_SPP_SPI_HALF_DUPLEX
= 1U
/**< Shared TX/RX line. */
33
}
SPP_SpiDuplex_t
;
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
*/
41
typedef
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. */
52
}
SPP_SpiInitCfg_t
;
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
*/
65
SPP_RetVal_t
SPP_HAL_SPI_busInit
(
void
);
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
*/
74
void
*
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
*/
83
SPP_RetVal_t
SPP_HAL_SPI_deviceInit
(
void
*p_handle);
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
*/
94
SPP_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
*/
108
SPP_RetVal_t
SPP_HAL_SPI_deviceSetSpeed
(
void
*p_handle,
spp_uint32_t
speedHz);
109
110
#endif
/* SPP_HAL_SPI_H */
returnTypes.h
Standard return-value type used across all SPP modules.
SPP_RetVal_t
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition
returnTypes.h:24
SPP_HAL_SPI_deviceSetSpeed
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
SPP_HAL_SPI_getHandle
void * SPP_HAL_SPI_getHandle(spp_uint8_t deviceIdx)
Obtain the SPI device handle for the given device index.
Definition
spi.c:39
SPP_HAL_SPI_deviceInit
SPP_RetVal_t SPP_HAL_SPI_deviceInit(void *p_handle)
Initialise a specific SPI device.
Definition
spi.c:49
SPP_HAL_SPI_transmit
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_HAL_SPI_busInit
SPP_RetVal_t SPP_HAL_SPI_busInit(void)
Initialise the SPI bus.
Definition
spi.c:19
SPP_SpiDuplex_t
SPP_SpiDuplex_t
SPI duplex mode.
Definition
spi.h:30
K_SPP_SPI_FULL_DUPLEX
@ K_SPP_SPI_FULL_DUPLEX
Definition
spi.h:31
K_SPP_SPI_HALF_DUPLEX
@ K_SPP_SPI_HALF_DUPLEX
Definition
spi.h:32
SPP_SpiMode_t
SPP_SpiMode_t
SPI clock phase/polarity mode.
Definition
spi.h:20
K_SPP_SPI_MODE3
@ K_SPP_SPI_MODE3
Definition
spi.h:23
K_SPP_SPI_MODE1
@ K_SPP_SPI_MODE1
Definition
spi.h:22
K_SPP_SPI_MODE0
@ K_SPP_SPI_MODE0
Definition
spi.h:21
SPP_SpiInitCfg_t
SPI bus and device initialisation configuration.
Definition
spi.h:42
SPP_SpiInitCfg_t::busId
int busId
Definition
spi.h:43
SPP_SpiInitCfg_t::pinSclk
int pinSclk
Definition
spi.h:46
SPP_SpiInitCfg_t::queueSize
unsigned int queueSize
Definition
spi.h:51
SPP_SpiInitCfg_t::mode
SPP_SpiMode_t mode
Definition
spi.h:49
SPP_SpiInitCfg_t::pinMosi
int pinMosi
Definition
spi.h:45
SPP_SpiInitCfg_t::duplex
SPP_SpiDuplex_t duplex
Definition
spi.h:50
SPP_SpiInitCfg_t::maxHz
unsigned int maxHz
Definition
spi.h:48
SPP_SpiInitCfg_t::pinMiso
int pinMiso
Definition
spi.h:44
SPP_SpiInitCfg_t::pinCs
int pinCs
Definition
spi.h:47
types.h
Portable integer types and SPI/storage configuration types for SPP.
spp_uint32_t
uint32_t spp_uint32_t
Definition
types.h:31
spp_uint8_t
uint8_t spp_uint8_t
Definition
types.h:27
solaris-v2
spp
hal
spi
spi.h
Generated by
1.18.0