@@ -53,6 +53,28 @@ typedef struct spi_s spi_t;
53
53
54
54
#endif
55
55
56
+ /**
57
+ * Describes the capabilities of a SPI peripherals
58
+ */
59
+ typedef struct {
60
+ /** Minimum frequency supported must be set by target device and it will be assessed during
61
+ * testing.
62
+ */
63
+ uint32_t minimum_frequency ;
64
+ /** Maximum frequency supported must be set by target device and it will be assessed during
65
+ * testing.
66
+ */
67
+ uint32_t maximum_frequency ;
68
+ /** Each bit represents the corresponding word length. lsb => 1bit, msb => 32bit. */
69
+ uint32_t word_length ;
70
+ uint16_t slave_delay_between_symbols_ns ; /**< specifies required number of ns between transmission of successive symbols in slave mode. */
71
+ uint8_t clk_modes ; /**< specifies supported modes from spi_mode_t. Each bit represents the corresponding mode. */
72
+ bool support_slave_mode ; /**< If true, the device can handle SPI slave mode using hardware management on the specified ssel pin. */
73
+ bool hw_cs_handle ; /**< If true, in SPI master mode Chip Select can be handled by hardware. */
74
+ bool async_mode ; /**< If true, in async mode is supported. */
75
+
76
+ } spi_capabilities_t ;
77
+
56
78
#ifdef __cplusplus
57
79
extern "C" {
58
80
#endif
@@ -63,6 +85,11 @@ extern "C" {
63
85
* # Defined behavior
64
86
* * ::spi_init initializes the spi_t control structure
65
87
* * ::spi_init configures the pins used by SPI
88
+ * * ::spi_get_capabilities() fills the given `spi_capabilities_t` instance
89
+ * * ::spi_get_capabilities() should consider the `ssel` pin when evaluation the `support_slave_mode` and `hw_cs_handle` capability
90
+ * * ::spi_get_capabilities(): if the given `ssel` pin cannot be managed by hardware, `support_slave_mode` and `hw_cs_handle` should be false
91
+ * * At least a symbol width of 8bit must be supported
92
+ * * The supported frequency range must include the range [0.2..2] MHz
66
93
* * ::spi_free returns the pins owned by the SPI object to their reset state
67
94
* * ::spi_format sets the number of bits per frame
68
95
* * ::spi_format configures clock polarity and phase
@@ -125,6 +152,11 @@ extern "C" {
125
152
SPIName spi_get_peripheral_name (PinName mosi , PinName miso , PinName mclk );
126
153
#endif
127
154
155
+ /**
156
+ * Fills the given spi_capabilities_t structure with the capabilities of the given peripheral.
157
+ */
158
+ void spi_get_capabilities (PinName ssel , bool slave , spi_capabilities_t * cap );
159
+
128
160
/** Initialize the SPI peripheral
129
161
*
130
162
* Configures the pins used by SPI, sets a default format and frequency, and enables the peripheral
0 commit comments