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 <csp/arch/csp_semaphore.h>
32 
45 #ifndef K_NUM_SPI
46 #define K_NUM_SPI YOTTA_CFG_HARDWARE_SPI_COUNT
47 #endif
48 
63 #define DEFAULT_SPI YOTTA_CFG_HARDWARE_SPI_DEFAULTS_BUS
64 
68 typedef enum {
70 #ifdef YOTTA_CFG_HARDWARE_SPI_SPI1
72 #endif
73 #ifdef YOTTA_CFG_HARDWARE_SPI_SPI2
75 #endif
76 #ifdef YOTTA_CFG_HARDWARE_SPI_SPI3
78 #endif
79 } KSPINum;
80 
85 typedef enum {
88 } SPIRole;
89 
94 typedef enum {
98 } SPIDirection;
99 
104 typedef enum {
107 } SPIDataSize;
108 
112 typedef enum {
116 
120 typedef enum {
123 } SPIClockPhase;
124 
128 typedef enum {
131 } SPIFirstBit;
132 
136 typedef enum {
143 } KSPIStatus;
144 
148 typedef struct {
196  uint32_t speed;
197 } KSPIConf;
198 
202 typedef struct {
205  csp_mutex_t spi_lock;
206 } KSPI;
207 
213 void k_spi_init(KSPINum spi, KSPIConf * conf);
214 
219 void k_spi_terminate(KSPINum spi);
220 
222 
235 KSPIStatus k_spi_write(KSPINum spi, uint8_t * buffer, uint32_t len);
236 
249 KSPIStatus k_spi_read(KSPINum spi, uint8_t * buffer, uint32_t len);
250 
264 KSPIStatus k_spi_write_read(KSPINum spi, uint8_t * txBuffer, uint8_t * rxBuffer, uint32_t len);
265 
271 KSPI * kprv_spi_get(KSPINum spi);
272 
283 KSPIStatus kprv_spi_write(KSPINum spi, uint8_t * buffer, uint32_t len);
284 
295 KSPIStatus kprv_spi_read(KSPINum spi, uint8_t * buffer, uint32_t len);
296 
308 KSPIStatus kprv_spi_write_read(KSPINum spi, uint8_t * txBuffer, uint8_t * rxBuffer, uint32_t len);
309 
319 
329 
330 #endif
331 #endif
332 
333 /* @} */
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
The role of the SPI bus.
Definition: spi.h:154
csp_mutex_t spi_lock
Definition: spi.h:205
Definition: spi.h:129
Spi configuration structure.
Definition: spi.h:148
Definition: spi.h:141
KSPIStatus k_spi_write(KSPINum spi, uint8_t *buffer, uint32_t len)
Write data over spi bus.
SPIClockPhase clock_phase
The clock phase of the SPI bus.
Definition: spi.h:170
Definition: spi.h:96
Definition: spi.h:139
Definition: spi.h:142
KSPINum
Available spi buses.
Definition: spi.h:68
KSPIConf k_spi_conf_defaults(void)
SPIDirection
Spi direction mode.
Definition: spi.h:94
void k_spi_init(KSPINum spi, KSPIConf *conf)
Setup and enable spi bus.
Definition: spi.h:122
Definition: spi.h:106
Definition: spi.h:130
KSPIStatus k_spi_read(KSPINum spi, uint8_t *buffer, uint32_t len)
Read data over spi bus.
SPIDataSize
Spi data size.
Definition: spi.h:104
Definition: spi.h:95
Definition: spi.h:69
Definition: spi.h:77
SPIDataSize data_size
The amount of data in each transmit/receive of the SPI bus.
Definition: spi.h:164
Definition: spi.h:114
Definition: spi.h:105
SPIDirection direction
The communication mode of the SPI bus.
Definition: spi.h:159
KSPIStatus kprv_spi_dev_init(KSPINum spi)
Low level spi initialization.
SPIClockPhase
Spi clock phase.
Definition: spi.h:120
Definition: spi.h:71
Definition: spi.h:113
KSPIStatus
Spi status values.
Definition: spi.h:136
KSPINum bus_num
Definition: spi.h:204
SPIClockPolarity
Spi clock polarity.
Definition: spi.h:112
Spi bus data structure.
Definition: spi.h:202
uint32_t speed
The baud rate of the SPI bus.
Definition: spi.h:196
KSPIStatus kprv_spi_dev_terminate(KSPINum spi)
Low level spi termination.
Definition: spi.h:97
Definition: spi.h:138
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
The clock polarity of the SPI bus.
Definition: spi.h:177
Definition: spi.h:137
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
The bit ordering of the SPI bus communication.
Definition: spi.h:182
SPIFirstBit
Spi first bit order/endianess.
Definition: spi.h:128
Definition: spi.h:140
SPIRole
Expected role of spi bus.
Definition: spi.h:85
Definition: spi.h:87
KSPIConf config
Definition: spi.h:203
Definition: spi.h:121
Definition: spi.h:86
void k_spi_terminate(KSPINum spi)
Terminate spi bus.