spi.h
Go to the documentation of this file.
1 /*
2  * KubOS HAL
3  * Copyright (C) 2016 Kubos Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
27 #if (defined YOTTA_CFG_HARDWARE_SPI) && (YOTTA_CFG_HARDWARE_SPI_COUNT > 0)
28 #ifndef K_SPI_H
29 #define K_SPI_H
30 
31 #include "FreeRTOS.h"
32 #include "semphr.h"
33 
46 #ifndef K_NUM_SPI
47 #define K_NUM_SPI YOTTA_CFG_HARDWARE_SPI_COUNT
48 #endif
49 
64 #define DEFAULT_SPI YOTTA_CFG_HARDWARE_SPI_DEFAULTS_BUS
65 
69 typedef enum {
70 #ifdef YOTTA_CFG_HARDWARE_SPI_SPI1
71  K_SPI1 = 0,
72 #endif
73 #ifdef YOTTA_CFG_HARDWARE_SPI_SPI2
75 #endif
76 #ifdef YOTTA_CFG_HARDWARE_SPI_SPI3
78 #endif
79 } KSPINum;
80 
84 typedef enum {
87 } SPIRole;
88 
92 typedef enum {
96 } SPIDirection;
97 
101 typedef enum {
104 } SPIDataSize;
105 
109 typedef enum {
113 
117 typedef enum {
120 } SPIClockPhase;
121 
125 typedef enum {
128 } SPIFirstBit;
129 
133 typedef enum {
137 } KSPIStatus;
138 
142 typedef struct {
149  uint32_t speed;
150 } KSPIConf;
151 
155 typedef struct {
158  SemaphoreHandle_t spi_lock;
159 } KSPI;
160 
166 void k_spi_init(KSPINum spi, KSPIConf * conf);
167 
172 void k_spi_terminate(KSPINum spi);
173 
186 KSPIStatus k_spi_write(KSPINum spi, uint8_t * buffer, uint32_t len);
187 
200 KSPIStatus k_spi_read(KSPINum spi, uint8_t * buffer, uint32_t len);
201 
215 KSPIStatus k_spi_write_read(KSPINum spi, uint8_t * txBuffer, uint8_t * rxBuffer, uint32_t len);
216 
222 KSPI * kprv_spi_get(KSPINum spi);
223 
234 KSPIStatus kprv_spi_write(KSPINum spi, uint8_t * buffer, uint32_t len);
235 
246 KSPIStatus kprv_spi_read(KSPINum spi, uint8_t * buffer, uint32_t len);
247 
259 KSPIStatus kprv_spi_write_read(KSPINum spi, uint8_t * txBuffer, uint8_t * rxBuffer, uint32_t len);
260 
261 void kprv_spi_dev_init(KSPINum spi);
262 
264 
265 #endif
266 #endif
267 
268 /* @} */
KSPI * kprv_spi_get(KSPINum spi)
Fetches spi bus data structure.
Definition: spi.h:74
KSPIStatus kprv_spi_read(KSPINum spi, uint8_t *buffer, uint32_t len)
Low level hal spi read.
SPIRole role
Definition: spi.h:143
Definition: spi.h:126
Spi configuration structure.
Definition: spi.h:142
KSPIStatus k_spi_write(KSPINum spi, uint8_t *buffer, uint32_t len)
Write data over spi bus.
SPIClockPhase clock_phase
Definition: spi.h:146
Definition: spi.h:94
KSPINum
Available spi buses.
Definition: spi.h:69
SPIDirection
Spi direction mode.
Definition: spi.h:92
void k_spi_init(KSPINum spi, KSPIConf *conf)
Setup and enable spi bus.
Definition: spi.h:119
Definition: spi.h:103
Definition: spi.h:127
KSPIStatus k_spi_read(KSPINum spi, uint8_t *buffer, uint32_t len)
Read data over spi bus.
SPIDataSize
Spi data size.
Definition: spi.h:101
Definition: spi.h:93
void kprv_spi_dev_init(KSPINum spi)
Definition: spi.h:77
SPIDataSize data_size
Definition: spi.h:145
Definition: spi.h:111
Definition: spi.h:102
SPIDirection direction
Definition: spi.h:144
SPIClockPhase
Spi clock phase.
Definition: spi.h:117
SemaphoreHandle_t spi_lock
Definition: spi.h:158
Definition: spi.h:71
Definition: spi.h:110
KSPIStatus
Spi status values.
Definition: spi.h:133
KSPINum bus_num
Definition: spi.h:157
SPIClockPolarity
Spi clock polarity.
Definition: spi.h:109
Spi bus data structure.
Definition: spi.h:155
uint32_t speed
Definition: spi.h:149
Definition: spi.h:95
Definition: spi.h:135
KSPIStatus kprv_spi_write_read(KSPINum spi, uint8_t *txBuffer, uint8_t *rxBuffer, uint32_t len)
Low level spi write & read.
KSPIStatus kprv_spi_write(KSPINum spi, uint8_t *buffer, uint32_t len)
Low level hal spi write.
SPIClockPolarity clock_polarity
Definition: spi.h:147
Definition: spi.h:134
KSPIStatus k_spi_write_read(KSPINum spi, uint8_t *txBuffer, uint8_t *rxBuffer, uint32_t len)
Write and read data over spi bus.
SPIFirstBit first_bit
Definition: spi.h:148
SPIFirstBit
Spi first bit order/endianess.
Definition: spi.h:125
Definition: spi.h:136
SPIRole
Expected role of spi bus.
Definition: spi.h:84
Definition: spi.h:86
KSPIConf config
Definition: spi.h:156
void kprv_spi_dev_terminate(KSPINum spi)
Definition: spi.h:118
Definition: spi.h:85
void k_spi_terminate(KSPINum spi)
Terminate spi bus.