Solaris Software
Loading...
Searching...
No Matches
hal.h
Go to the documentation of this file.
1/**
2 * @file hal.h
3 * @brief This file contains the structs that contain all the pointers to the functions that are used by the SPP library.
4 * The structs are used to abstract the hardware and to make the code more portable.
5 * It also contains the public functions needed to initialize all these structs.
6 */
7
8#ifndef SPP_HAL_PORT_H
9#define SPP_HAL_PORT_H
10
11#include "spp/core/types.h"
13
14/* ----------------------------------------------------------------
15 * STRUCTS
16 * ---------------------------------------------------------------- */
17
18/**
19* @brief SPI bus struct that contains all the pointers to the SPI functions
20*/
21typedef struct
22{
23 /**
24 * @brief Initialise the SPI bus.
25 *
26 * May be called multiple times; subsequent calls must be no-ops.
27 *
28 * @return K_SPP_OK on success.
29 */
31
32 /**
33 * @brief Obtain the handle for the next SPI device slot.
34 *
35 * Devices are numbered sequentially starting from 0. The port
36 * determines which physical device each index maps to.
37 *
38 * @param[in] deviceIdx Zero-based device index.
39 *
40 * @return Opaque device handle, or NULL if the index is out of range.
41 */
42 void *(*spiGetHandle)(spp_uint8_t deviceIdx);
43
44 /**
45 * @brief Initialise a specific SPI device.
46 *
47 * @param[in] p_handle Handle returned by @c spiGetHandle.
48 *
49 * @return K_SPP_OK on success, K_SPP_ERROR_NULL_POINTER if handle is NULL.
50 */
51 SPP_RetVal_t (*spiDeviceInit)(void *p_handle);
52
53 /**
54 * @brief Perform a full-duplex SPI transaction.
55 *
56 * The buffer @p p_data is used for both TX and RX. The port inspects
57 * the MSB of the first byte to determine read (1) vs write (0).
58 *
59 * @param[in,out] p_handle SPI device handle.
60 * @param[in,out] p_data TX data in, RX data out.
61 * @param[in] length Number of bytes in the transaction.
62 *
63 * @return K_SPP_OK on success, K_SPP_ERROR_ON_SPI_TRANSACTION on failure.
64 */
65 SPP_RetVal_t (*spiTransmit)(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length);
66
67 /**
68 * @brief Remove and re-add a SPI device with a new clock speed.
69 *
70 * Intended for devices that require a lower speed during initialisation
71 * and a higher speed for normal operation (e.g. SD cards).
72 *
73 * @param[in] p_handle Handle returned by @c spiGetHandle.
74 * @param[in] speedHz New clock frequency in Hz.
75 *
76 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
77 */
78 SPP_RetVal_t (*spiDeviceSetSpeed)(void *p_handle, spp_uint32_t speedHz);
79
81
82/**
83* @brief UART port struct that contains all the pointers to the UART functions
84*/
85typedef struct
86{
87 /**
88 * @brief Initialise the UART port.
89 *
90 * @param[in] p_cfg Pointer to UART init configuration.
91 *
92 * @return K_SPP_OK on success.
93 */
95
96 /**
97 * @brief Perform an UART transaction.
98 *
99 * @param[in,out] p_handle SPI device handle.
100 * @param[in,out] p_data TX data in, RX data out.
101 * @param[in] length Number of bytes in the transaction.
102 *
103 * @return K_SPP_OK on success, K_SPP_ERROR_ON_SPI_TRANSACTION on failure.
104 */
105 SPP_RetVal_t (*uartTransmit)(const void *p_data, spp_uint32_t len);
106
107 /**
108 * @brief Reads data from the ESP32 UART.
109 *
110 * @param[out] p_data Pointer to the buffer where received data will be stored.
111 * @param[in] len Number of bytes to read.
112 * @param[out] p_readBytes Pointer to the variable where the number of bytes read will be stored.
113 */
114
115 SPP_RetVal_t (*uartRead)(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes);
116
118
119/**
120* @brief GPIO struct that contains all the pointers to the GPIO functions
121*/
122typedef struct
123{
124 /**
125 * @brief Configure a GPIO pin as an interrupt input.
126 *
127 * @param[in] pin GPIO pin number.
128 * @param[in] intrType Platform-specific interrupt trigger type.
129 * @param[in] pull Pull resistor: 0 = none, 1 = pull-up, 2 = pull-down.
130 *
131 * @return K_SPP_OK on success.
132 */
134
135 /**
136 * @brief Register an ISR handler for a GPIO pin.
137 *
138 * @param[in] pin GPIO pin number.
139 * @param[in] p_isrCtx Pointer to @ref SPP_GpioIsrCtx_t for this pin.
140 *
141 * @return K_SPP_OK on success.
142 */
145
146
147/**
148 * @brief Storage struct that contains all the pointers to the storage functions
149 */
150typedef struct
151{
152 /**
153 * @brief Initialize the storage device.
154 *
155 * @param[in,out] p_handle Hardware-specific storage context.
156 *
157 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
158 */
160
161 /**
162 * @brief Write consecutive blocks to the storage device.
163 *
164 * @param[in,out] p_handle Hardware-specific storage context.
165 * @param[in] p_buffer Data to write.
166 * @param[in] first_block First logical block to write.
167 * @param[in] count Number of blocks to write.
168 *
169 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
170 */
171 SPP_RetVal_t (*storageWrite)(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count);
172
174
175
176/**
177* @brief Time struct that contains all the pointers to the Time functions
178*/
179typedef struct
180{
181 /**
182 * @brief Return the current hardware time in milliseconds.
183 *
184 * Used to timestamp packets. Must be monotonically non-decreasing.
185 *
186 * @return Elapsed time in ms.
187 */
189
190 /**
191 * @brief Return the current hardware time in microseconds.
192 *
193 * Used to timestamp packets. Must be monotonically non-decreasing.
194 *
195 * @return Elapsed time in us.
196 */
198
199 /**
200 * @brief Block for the requested number of milliseconds.
201 *
202 * Used during sensor initialisation sequences that require a fixed delay.
203 * On baremetal targets this is a busy-wait; on RTOS targets it may yield.
204 *
205 * @param[in] ms Number of milliseconds to delay.
206 */
209
210
211/**
212* @brief Ports struct that contains all the pointers to the Ports functions
213*/
223
224
225/* ----------------------------------------------------------------
226 * PUBLIC FUNCTIONS
227 * ---------------------------------------------------------------- */
228
229/**
230* @brief This functions initializes the ports struct and initializes all the peripherals.
231*/
232SPP_RetVal_t SPP_HAL_init(void *p_halPorts);
233
234/**
235* @brief This function is used to get the pointers to the functions that are used by the SPP library.
236* The structs are used to abstract the hardware and to make the code more portable.
237* It also contains the public functions needed to initialize all these structs.
238*
239* @param[in] p_ports Pointer to the ports struct that will be initialized.
240* @return NULL if the pointer to the ports struct is NULL.
241* @return Pointer to the ports struct, if it has beeen initialized.
242 */
243const SPP_HalPort_t *SPP_HAL_getPort(void);
244
245
246#endif /* SPP_HAL_PORT_H */
const SPP_HalPort_t * SPP_HAL_getPort(void)
This function is used to get the pointers to the functions that are used by the SPP library....
Definition hal.c:52
SPP_RetVal_t SPP_HAL_init(void *p_halPorts)
This functions initializes the ports struct and initializes all the peripherals.
Definition hal.c:26
Standard return-value type used across all SPP modules.
SPP_RetVal_t
Unified return type for all SPP API functions.
Definition returnTypes.h:24
GPIO struct that contains all the pointers to the GPIO functions.
Definition hal.h:123
SPP_RetVal_t(*) gpioConfigInterrupt(spp_uint32_t pin, spp_uint32_t intrType, spp_uint32_t pull)
Configure a GPIO pin as an interrupt input.
Definition hal.h:133
SPP_RetVal_t(*) gpioRegisterIsr(spp_uint32_t pin, void *p_isrCtx)
Register an ISR handler for a GPIO pin.
Definition hal.h:143
SPI bus struct that contains all the pointers to the SPI functions.
Definition hal.h:22
SPP_RetVal_t(*) spiDeviceInit(void *p_handle)
Initialise a specific SPI device.
Definition hal.h:51
SPP_RetVal_t(*) spiBusInit(void)
Initialise the SPI bus.
Definition hal.h:30
SPP_RetVal_t(*) spiTransmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
Perform a full-duplex SPI transaction.
Definition hal.h:65
SPP_RetVal_t(*) spiDeviceSetSpeed(void *p_handle, spp_uint32_t speedHz)
Remove and re-add a SPI device with a new clock speed.
Definition hal.h:78
Storage struct that contains all the pointers to the storage functions.
Definition hal.h:151
SPP_RetVal_t(*) storageWrite(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count)
Write consecutive blocks to the storage device.
Definition hal.h:171
SPP_RetVal_t(*) storageInit(void)
Initialize the storage device.
Definition hal.h:159
Time struct that contains all the pointers to the Time functions.
Definition hal.h:180
spp_uint32_t(*) getTimeUs(void)
Return the current hardware time in microseconds.
Definition hal.h:197
spp_uint32_t(*) getTimeMs(void)
Return the current hardware time in milliseconds.
Definition hal.h:188
void(*) delayMs(spp_uint32_t ms)
Block for the requested number of milliseconds.
Definition hal.h:207
UART port struct that contains all the pointers to the UART functions.
Definition hal.h:86
SPP_RetVal_t(*) uartTransmit(const void *p_data, spp_uint32_t len)
Perform an UART transaction.
Definition hal.h:105
SPP_RetVal_t(*) uartPortInit(void)
Initialise the UART port.
Definition hal.h:94
SPP_RetVal_t(*) uartRead(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
Reads data from the ESP32 UART.
Definition hal.h:115
Ports struct that contains all the pointers to the Ports functions.
Definition hal.h:215
SPP_HALStorage_t storage
Definition hal.h:218
SPP_HALTime_t time
Definition hal.h:219
SPP_HALGpio_t gpio
Definition hal.h:217
SPP_HALSpi_t spi
Definition hal.h:216
SPP_HALUart_t uart
Definition hal.h:220
Portable integer types and SPI/storage configuration types for SPP.
uint16_t spp_uint16_t
Definition types.h:29
uint32_t spp_uint32_t
Definition types.h:31
uint8_t spp_uint8_t
Definition types.h:27