TizenRT Public API  v2.0 M2
iotbus_spi.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
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,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 
31 #ifndef IOTBUS_SPI_H_
32 #define IOTBUS_SPI_H_
33 
34 #include <stdint.h>
35 #include <sys/types.h>
36 
46 typedef enum {
47  IOTBUS_SPI_MODE0 = 0,
48  IOTBUS_SPI_MODE1,
49  IOTBUS_SPI_MODE2,
50  IOTBUS_SPI_MODE3,
52 
57  char bits_per_word;
58  unsigned int chip_select;
59  unsigned int frequency; // frequency in Hz
60  iotbus_spi_mode_e mode;
61 };
62 
63 struct _iotbus_spi_s;
64 
68 typedef struct _iotbus_spi_wrapper_s *iotbus_spi_context_h;
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
87 iotbus_spi_context_h iotbus_spi_open(unsigned int bus, const struct iotbus_spi_config_s *config);
88 
99 int iotbus_spi_write(iotbus_spi_context_h hnd, uint8_t *txbuf, size_t length);
100 
111 int iotbus_spi_recv(iotbus_spi_context_h hnd, uint8_t *rxbuf, size_t length);
112 
113 #ifdef CONFIG_SPI_EXCHANGE
114 
125 int iotbus_spi_transfer_buf(iotbus_spi_context_h hnd, uint8_t *txbuf, uint8_t *rxbuf, size_t length);
126 #endif
127 
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* IOTBUS_SPI_H_ */
143  // end of SPI group
iotbus_spi_context_h iotbus_spi_open(unsigned int bus, const struct iotbus_spi_config_s *config)
initializes spi_context.
Structure of SPI configuration.
Definition: iotbus_spi.h:56
struct _iotbus_spi_wrapper_s * iotbus_spi_context_h
Pointer definition to the internal struct _iotbus_spi_wrapper_s.
Definition: iotbus_spi.h:68
int iotbus_spi_write(iotbus_spi_context_h hnd, uint8_t *txbuf, size_t length)
writes data over spi bus.
iotbus_spi_mode_e
Enumeration of SPI mode.
Definition: iotbus_spi.h:46
int iotbus_spi_close(iotbus_spi_context_h hnd)
closes spi_context.
int iotbus_spi_recv(iotbus_spi_context_h hnd, uint8_t *rxbuf, size_t length)
reads data over spi bus.