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 Performs SPI register transactions.
55 *
56 * The ESP32 port uses the MSB of the command byte to distinguish
57 * reads from writes and processes the buffer accordingly.
58 *
59 * @param p_handle SPI device handle.
60 * @param p_data Transmission buffer, also used for received data on reads.
61 * @param length Buffer length in bytes.
62 * @return K_SPP_OK on success, error code otherwise.
63 */
64 SPP_RetVal_t (*spiTransmit)(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length);
65
66 /**
67 * @brief Remove and re-add a SPI device with a new clock speed.
68 *
69 * Intended for devices that require a lower speed during initialisation
70 * and a higher speed for normal operation (e.g. SD cards).
71 *
72 * @param[in] p_handle Handle returned by @c spiGetHandle.
73 * @param[in] speedHz New clock frequency in Hz.
74 *
75 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
76 */
77 SPP_RetVal_t (*spiDeviceSetSpeed)(void *p_handle, spp_uint32_t speedHz);
78
79 /**
80 * @brief Performs a raw full-duplex SPI transaction.
81 * @param p_handle SPI device handle.
82 * @param p_data Transmission and reception buffer.
83 * @param length Number of bytes to transfer.
84 * @return K_SPP_OK on success, error code otherwise.
85 */
86 SPP_RetVal_t (*spiTransmitRaw)(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length);
87
88
90
91/**
92* @brief UART port struct that contains all the pointers to the UART functions
93*/
94typedef struct
95{
96 /**
97 * @brief Initialise the UART port.
98 *
99 * @return K_SPP_OK on success.
100 */
102
103 /**
104 * @brief Transmits data through the UART port.
105 * @param p_data Pointer to the data to transmit.
106 * @param len Number of bytes to transmit.
107 * @return K_SPP_OK on success, error code otherwise.
108 */
109 SPP_RetVal_t (*uartTransmit)(const void *p_data, spp_uint32_t len);
110
111 /**
112 * @brief Reads data from the UART.
113 *
114 * @param[out] p_data Pointer to the buffer where received data will be stored.
115 * @param[in] len Number of bytes to read.
116 * @param[out] p_readBytes Pointer to the variable where the number of bytes read will be stored.
117 *
118 * @return K_SPP_OK on success, error code otherwise.
119 */
120
121 SPP_RetVal_t (*uartRead)(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes);
122
124
125/**
126* @brief GPIO struct that contains all the pointers to the GPIO functions
127*/
128typedef struct
129{
130 /**
131 * @brief Configure a GPIO pin as an interrupt input.
132 *
133 * @param[in] pin GPIO pin number.
134 * @param[in] intrType Platform-specific interrupt trigger type.
135 * @param[in] pull Pull resistor: 0 = none, 1 = pull-up, 2 = pull-down.
136 *
137 * @return K_SPP_OK on success.
138 */
140
141 /**
142 * @brief Register an ISR handler for a GPIO pin.
143 *
144 * @param[in] pin GPIO pin number.
145 * @param[in] p_isrCtx Pointer to @ref SPP_GpioIsrCtx_t for this pin.
146 *
147 * @return K_SPP_OK on success.
148 */
150
151 /**
152 * @brief Reads the logic level of a GPIO pin.
153 * @param pin GPIO pin number.
154 * @return Current logic level (0 or 1).
155 */
157
158 /**
159 * @brief Configures a GPIO as output and sets its logic level.
160 * @param pin GPIO pin number.
161 * @param level Logic level to set.
162 * @return K_SPP_OK on success, error code otherwise.
163 */
165
167
168
169/**
170 * @brief Storage struct that contains all the pointers to the storage functions
171 */
172typedef struct
173{
174 /**
175 * @brief Initialize the storage device.
176 *
177 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
178 */
180
181 /**
182 * @brief Write consecutive blocks to the storage device.
183 *
184 * @param[in] p_buffer Data to write.
185 * @param[in] first_block First logical block to write.
186 * @param[in] count Number of blocks to write.
187 *
188 * @return K_SPP_OK on success, K_SPP_ERROR on failure.
189 */
190 SPP_RetVal_t (*storageWrite)(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count);
191
193
194
195/**
196* @brief Time struct that contains all the pointers to the Time functions
197*/
198typedef struct
199{
200 /**
201 * @brief Return the current hardware time in milliseconds.
202 *
203 * Used to timestamp packets.
204 *
205 * @return Elapsed time in ms.
206 */
208
209 /**
210 * @brief Return the current hardware time in microseconds.
211 *
212 * Used to timestamp packets.
213 *
214 * @return Elapsed time in us.
215 */
217
218 /**
219 * @brief Block for the requested number of milliseconds.
220 *
221 * Used during sensor initialisation sequences that require a fixed delay.
222 * On baremetal targets this is a busy-wait; on RTOS targets it may yield.
223 *
224 * @param[in] ms Number of milliseconds to delay.
225 */
228
229
230/**
231* @brief Ports struct that contains all the pointers to the Ports functions
232*/
242
243
244/* ----------------------------------------------------------------
245 * PUBLIC FUNCTIONS
246 * ---------------------------------------------------------------- */
247
248/**
249* @brief This functions initializes the ports struct and initializes all the peripherals.
250*/
251SPP_RetVal_t SPP_HAL_init(void *p_halPorts);
252
253/**
254 * @brief Returns the registered HAL port.
255 * @return Pointer to the HAL port, or NULL if not initialized.
256 */
257const SPP_HalPort_t *SPP_HAL_getPort(void);
258
259#endif /* SPP_HAL_PORT_H */
const SPP_HalPort_t * SPP_HAL_getPort(void)
Returns the registered HAL port.
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:129
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:139
spp_uint16_t(*) gpioRead(spp_uint32_t pin)
Reads the logic level of a GPIO pin.
Definition hal.h:156
SPP_RetVal_t(*) gpioWrite(spp_uint32_t pin, spp_uint8_t level)
Configures a GPIO as output and sets its logic level.
Definition hal.h:164
SPP_RetVal_t(*) gpioRegisterIsr(spp_uint32_t pin, void *p_isrCtx)
Register an ISR handler for a GPIO pin.
Definition hal.h:149
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(*) spiTransmitRaw(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
Performs a raw full-duplex SPI transaction.
Definition hal.h:86
SPP_RetVal_t(*) spiTransmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
Performs SPI register transactions.
Definition hal.h:64
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:77
Storage struct that contains all the pointers to the storage functions.
Definition hal.h:173
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:190
SPP_RetVal_t(*) storageInit(void)
Initialize the storage device.
Definition hal.h:179
Time struct that contains all the pointers to the Time functions.
Definition hal.h:199
spp_uint32_t(*) getTimeUs(void)
Return the current hardware time in microseconds.
Definition hal.h:216
spp_uint32_t(*) getTimeMs(void)
Return the current hardware time in milliseconds.
Definition hal.h:207
void(*) delayMs(spp_uint32_t ms)
Block for the requested number of milliseconds.
Definition hal.h:226
UART port struct that contains all the pointers to the UART functions.
Definition hal.h:95
SPP_RetVal_t(*) uartTransmit(const void *p_data, spp_uint32_t len)
Transmits data through the UART port.
Definition hal.h:109
SPP_RetVal_t(*) uartPortInit(void)
Initialise the UART port.
Definition hal.h:101
SPP_RetVal_t(*) uartRead(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
Reads data from the UART.
Definition hal.h:121
Ports struct that contains all the pointers to the Ports functions.
Definition hal.h:234
SPP_HALStorage_t storage
Definition hal.h:237
SPP_HALTime_t time
Definition hal.h:238
SPP_HALGpio_t gpio
Definition hal.h:236
SPP_HALSpi_t spi
Definition hal.h:235
SPP_HALUart_t uart
Definition hal.h:239
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