Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-spi.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <stdint.h>
22 #include <stdbool.h>
23 
24 #include <sol-common-buildopts.h>
25 #include <sol-macros.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
52 struct sol_spi;
53 typedef struct sol_spi sol_spi;
54 
75 };
76 
80 #define SOL_SPI_DATA_BITS_DEFAULT 8
81 
89 typedef struct sol_spi_config {
90 #ifndef SOL_NO_API_VERSION
91 #define SOL_SPI_CONFIG_API_VERSION (1)
92  uint16_t api_version;
93 #endif
94  unsigned int chip_select;
96  uint32_t frequency;
97  uint8_t bits_per_word;
99 
111 enum sol_spi_mode sol_spi_mode_from_str(const char *spi_mode)
112 #ifndef DOXYGEN_RUN
114 #endif
115  ;
116 
128 const char *sol_spi_mode_to_str(enum sol_spi_mode spi_mode)
129 #ifndef DOXYGEN_RUN
130  SOL_ATTR_WARN_UNUSED_RESULT
131 #endif
132  ;
133 
154 int sol_spi_transfer(struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, size_t count, void (*transfer_cb)(void *cb_data, struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, ssize_t status), const void *cb_data);
155 
161 void sol_spi_close(struct sol_spi *spi);
162 
173 struct sol_spi *sol_spi_open(unsigned int bus, const struct sol_spi_config *config);
174 
179 #ifdef __cplusplus
180 }
181 #endif
void sol_spi_close(struct sol_spi *spi)
Close an SPI bus.
struct sol_spi_config sol_spi_config
SPI configuration struct.
CPOL = 1 and CPHA = 0.
Definition: sol-spi.h:74
CPOL = 0 and CPHA = 1.
Definition: sol-spi.h:73
enum sol_spi_mode sol_spi_mode_from_str(const char *spi_mode)
Converts a string SPI mode name to sol_spi_mode.
struct sol_spi * sol_spi_open(unsigned int bus, const struct sol_spi_config *config)
Open an SPI bus.
CPOL = 0 and CPHA = 0.
Definition: sol-spi.h:72
Definition: sol-spi.h:71
SPI configuration struct.
Definition: sol-spi.h:89
These are common Soletta macros.
const char * sol_spi_mode_to_str(enum sol_spi_mode spi_mode)
Converts sol_spi_mode to a string name.
enum sol_spi_mode mode
The SPI operation mode.
Definition: sol-spi.h:95
#define SOL_ATTR_WARN_UNUSED_RESULT
Causes a warning to be emitted if a caller of the function with this attribute does not use its retur...
Definition: sol-macros.h:187
uint16_t api_version
The API version.
Definition: sol-spi.h:92
unsigned int chip_select
Also know as slave select.
Definition: sol-spi.h:94
sol_spi_mode
SPI Transfer Modes.
Definition: sol-spi.h:70
uint32_t frequency
Clock frequency in Hz.
Definition: sol-spi.h:96
struct sol_spi sol_spi
A handle to a SPI bus.
Definition: sol-spi.h:53
uint8_t bits_per_word
Number of bits per word.
Definition: sol-spi.h:97
int sol_spi_transfer(struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, size_t count, void(*transfer_cb)(void *cb_data, struct sol_spi *spi, const uint8_t *tx, uint8_t *rx, ssize_t status), const void *cb_data)
Perform a SPI asynchronous transfer.