Solaris Software
Toggle main menu visibility
Loading...
Searching...
No Matches
spi.c
Go to the documentation of this file.
1
/**
2
* @file spi.c
3
* @brief HAL SPI functions implementation. Calls the function pointer and returns the result.
4
*/
5
6
7
/* ----------------------------------------------------------------
8
* INCLUDES
9
* ---------------------------------------------------------------- */
10
#include "
spp/core/returnTypes.h
"
11
#include "
spp/hal/hal.h
"
12
#include "
spp/hal/spi/spi.h
"
13
14
15
/* ----------------------------------------------------------------
16
* PUBLIC FUNCTIONS
17
* ---------------------------------------------------------------- */
18
19
SPP_RetVal_t
SPP_HAL_SPI_busInit
(
void
)
20
{
21
SPP_RetVal_t
ret =
K_SPP_OK
;
22
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
23
if
((p_port == NULL) || (p_port->
spi
.
spiBusInit
== NULL))
24
{
25
ret =
K_SPP_ERROR_NULL_POINTER
;
26
}
27
else
28
{
29
ret = p_port->
spi
.
spiBusInit
();
30
if
(ret !=
K_SPP_OK
)
31
{
32
ret =
K_SPP_ERROR
;
33
}
34
}
35
36
return
ret;
37
}
38
39
void
*
SPP_HAL_SPI_getHandle
(
spp_uint8_t
deviceIdx)
40
{
41
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
42
if
((p_port == NULL) || (p_port->
spi
.
spiGetHandle
== NULL))
43
{
44
return
NULL;
45
}
46
return
p_port->
spi
.
spiGetHandle
(deviceIdx);
47
}
48
49
SPP_RetVal_t
SPP_HAL_SPI_deviceInit
(
void
*p_handle)
50
{
51
SPP_RetVal_t
ret =
K_SPP_ERROR
;
52
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
53
if
((p_port == NULL) || (p_port->
spi
.
spiDeviceInit
== NULL))
54
{
55
ret =
K_SPP_ERROR_NULL_POINTER
;
56
}
57
else
58
{
59
ret = p_port->
spi
.
spiDeviceInit
(p_handle);
60
if
(ret !=
K_SPP_OK
)
61
{
62
ret =
K_SPP_ERROR
;
63
}
64
}
65
66
return
ret;
67
}
68
69
SPP_RetVal_t
SPP_HAL_SPI_deviceSetSpeed
(
void
*p_handle,
spp_uint32_t
speedHz)
70
{
71
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
72
if
((p_port == NULL) || (p_port->
spi
.
spiDeviceSetSpeed
== NULL))
73
{
74
return
K_SPP_ERROR_NULL_POINTER
;
75
}
76
return
p_port->
spi
.
spiDeviceSetSpeed
(p_handle, speedHz);
77
}
78
79
SPP_RetVal_t
SPP_HAL_SPI_transmit
(
void
*p_handle,
spp_uint8_t
*p_data,
spp_uint8_t
length)
80
{
81
SPP_RetVal_t
ret =
K_SPP_ERROR
;
82
83
const
SPP_HalPort_t
*p_port =
SPP_HAL_getPort
();
84
if
((p_port == NULL) || (p_port->
spi
.
spiTransmit
== NULL))
85
{
86
ret =
K_SPP_ERROR_NULL_POINTER
;
87
}
88
else
89
{
90
ret = p_port->
spi
.
spiTransmit
(p_handle, p_data, length);
91
if
(ret !=
K_SPP_OK
)
92
{
93
ret =
K_SPP_ERROR
;
94
}
95
}
96
return
ret;
97
}
SPP_HAL_getPort
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
hal.h
This file contains the structs that contain all the pointers to the functions that are used by the SP...
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
K_SPP_OK
@ K_SPP_OK
Definition
returnTypes.h:25
K_SPP_ERROR
@ K_SPP_ERROR
Definition
returnTypes.h:26
K_SPP_ERROR_NULL_POINTER
@ K_SPP_ERROR_NULL_POINTER
Definition
returnTypes.h:30
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
spi.h
SPP SPI HAL API — dispatches through the registered HAL port.
SPP_HALSpi_t::spiDeviceInit
SPP_RetVal_t(*) spiDeviceInit(void *p_handle)
Initialise a specific SPI device.
Definition
hal.h:51
SPP_HALSpi_t::spiBusInit
SPP_RetVal_t(*) spiBusInit(void)
Initialise the SPI bus.
Definition
hal.h:30
SPP_HALSpi_t::spiTransmit
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_HALSpi_t::spiDeviceSetSpeed
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
SPP_HALSpi_t::spiGetHandle
void *(*) spiGetHandle(spp_uint8_t deviceIdx)
Obtain the handle for the next SPI device slot.
Definition
hal.h:42
SPP_HalPort_t
Ports struct that contains all the pointers to the Ports functions.
Definition
hal.h:215
SPP_HalPort_t::spi
SPP_HALSpi_t spi
Definition
hal.h:216
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.c
Generated by
1.18.0