| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

platform_drivers.h
Go to the documentation of this file.
1 /***************************************************************************//**
2 * @file platform_drivers.h
3 * @brief Header file of Generic Platform Drivers.
4 * @author DBogdan (dragos.bogdan@analog.com)
5 ********************************************************************************
6 * Copyright 2017(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39
40 #ifndef PLATFORM_DRIVERS_H_
41 #define PLATFORM_DRIVERS_H_
42
43 // Our platform driver needs to be C-compatible to work with the drivers
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #include <stdint.h>
49
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53
54 #define SUCCESS 0
55 #define FAILURE -1
56
57 #define SPI_CPHA 0x01
58 #define SPI_CPOL 0x02
59
60 #define GPIO_OUT 0x01
61 #define GPIO_IN 0x00
62
63 #define GPIO_HIGH 0x01
64 #define GPIO_LOW 0x00
65
66 #define MUX_I2C 0
67 #define MUX_SPI 1
68
69 /******************************************************************************/
70 /*************************** Types Declarations *******************************/
71 /******************************************************************************/
72
73 typedef enum i2c_type{
74 GENERIC_I2C
75 } i2c_type;
76
77 typedef struct i2c_init_param{
78 i2c_type type;
79 uint32_t id;
80 uint32_t max_speed_hz;
81 uint8_t slave_address;
82 } i2c_init_param;
83
84 typedef struct i2c_desc{
85 i2c_type type;
86 uint32_t id;
87 uint32_t max_speed_hz;
88 uint8_t slave_address;
89 } i2c_desc;
90
91 typedef enum spi_type{
92 GENERIC_SPI
93 } spi_type;
94
95 // typedef enum {
96 // SPI_MODE_0 = (0 | 0),
97 // SPI_MODE_1 = (0 | SPI_CPHA),
98 // SPI_MODE_2 = (SPI_CPOL | 0),
99 // SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)
100 // } spi_mode;
101
102
103
104 typedef struct spi_init_param{
105 spi_type type;
106 uint32_t id;
107 uint32_t max_speed_hz;
108 uint8_t mode; // spi_mode mode;
109 uint8_t chip_select;
110 } spi_init_param;
111
112 typedef struct {
113 spi_type type;
114 uint32_t id;
115 uint32_t max_speed_hz;
116 uint8_t mode; // spi_mode mode;
117 uint8_t chip_select;
118 } spi_desc;
119
120 typedef enum {
121 GENERIC_GPIO
122 } gpio_type;
123
124 typedef struct {
125 gpio_type type;
126 uint32_t id;
127 uint8_t number;
128 } gpio_desc;
129
130 /******************************************************************************/
131 /************************ Functions Declarations ******************************/
132 /******************************************************************************/
133
134 /* Initialize the I2C communication peripheral. */
135 int32_t i2c_init(i2c_desc **desc,
136 const struct i2c_init_param *param);
137
138 /* Free the resources allocated by i2c_init(). */
139 int32_t i2c_remove(i2c_desc *desc);
140
141 /* Write data to a slave device. */
142 int32_t i2c_write(i2c_desc *desc,
143 uint8_t *data,
144 uint8_t bytes_number,
145 uint8_t stop_bit);
146
147 /* Read data from a slave device. */
148 int32_t i2c_read(i2c_desc *desc,
149 uint8_t *data,
150 uint8_t bytes_number,
151 uint8_t stop_bit);
152
153 /* Initialize the SPI communication peripheral. */
154 int32_t spi_init(spi_desc **desc,
155 const struct spi_init_param *param);
156
157 /* Free the resources allocated by spi_init() */
158 int32_t spi_remove(spi_desc *desc);
159
160 /* Write and read data to/from SPI. */
161 int32_t spi_write_and_read(spi_desc *desc,
162 uint8_t *data,
163 uint8_t bytes_number);
164
165 /* Obtain the GPIO decriptor. */
166 int32_t gpio_get(gpio_desc **desc,
167 uint8_t gpio_number);
168
169 /* Free the resources allocated by gpio_get() */
170 int32_t gpio_remove(gpio_desc *desc);
171
172 /* Enable the input direction of the specified GPIO. */
173 int32_t gpio_direction_input(gpio_desc *desc);
174
175 /* Enable the output direction of the specified GPIO. */
176 int32_t gpio_direction_output(gpio_desc *desc,
177 uint8_t value);
178
179 /* Get the direction of the specified GPIO. */
180 int32_t gpio_get_direction(gpio_desc *desc,
181 uint8_t *direction);
182
183 /* Set the value of the specified GPIO. */
184 int32_t gpio_set_value(gpio_desc *desc,
185 uint8_t value);
186
187 /* Get the value of the specified GPIO. */
188 int32_t gpio_get_value(gpio_desc *desc,
189 uint8_t *value);
190
191 /* Generate miliseconds delay. */
192 void mdelay(uint32_t msecs);
193
194 /*************************
195 * Linduino I2C functions for ADI use
196 * These functions are wrappers around the Arduino Wire library
197 **/
198
199 void quikeval_set_mux(uint8_t mux);
200
201 /*! Connects and initializes I2C */
202 void Wire_Connect();
203
204 /*! Write I2C */
205 uint8_t Wire_Write(unsigned char address, unsigned char* data, unsigned char length, unsigned char stop);
206
207 /*! Read I2C */
208 uint8_t Wire_Read(unsigned char address, unsigned char* data, unsigned char length, unsigned char stop);
209
210 /*************************
211 * Linduino SPI functions for ADI use:
212 * These functions are derived from functions in LT_SPI and modified
213 * to work on ADI parts. They are copied here so we don't have to
214 * depend on the LT_SPI library to avoid naming conflicts.
215 */
216
217 /*! Enable SPI, matches spi_enable */
218 //void Lin_SPI_Enable(uint8_t spi_clock_divider);
219
220 /*! Initialize SPI, matches spi_init */
221 //void Lin_SPI_Init();
222
223 /*! Connect to SPI, matches quikeval_spi_connect */
224 //void Lin_SPI_Connect();
225
226 void uartTX(char *buf);
227
228 #ifdef __cplusplus // Closing extern c
229 }
230 #endif
231
232 #endif // PLATFORM_DRIVERS_H_
i2c_desc
Definition: platform_drivers.h:84
mdelay
void mdelay(uint32_t msecs)
Generate miliseconds delay.
Definition: platform_drivers.cpp:374
spi_init
int32_t spi_init(spi_desc **desc, const struct spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: platform_drivers.cpp:147
i2c_remove
int32_t i2c_remove(i2c_desc *desc)
Free the resources allocated by i2c_init().
Definition: platform_drivers.cpp:89
spi_desc::chip_select
uint8_t chip_select
Definition: platform_drivers.h:117
gpio_desc
Definition: platform_drivers.h:124
gpio_get_value
int32_t gpio_get_value(gpio_desc *desc, uint8_t *value)
Get the value of the specified GPIO.
Definition: platform_drivers.cpp:360
i2c_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: platform_drivers.h:80
i2c_init_param
Definition: platform_drivers.h:77
gpio_set_value
int32_t gpio_set_value(gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: platform_drivers.cpp:344
spi_init_param
struct spi_init_param spi_init_param
spi_desc::max_speed_hz
uint32_t max_speed_hz
Definition: platform_drivers.h:115
spi_init_param
Definition: platform_drivers.h:104
GENERIC_GPIO
Definition: platform_drivers.h:121
i2c_desc
struct i2c_desc i2c_desc
spi_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: platform_drivers.h:107
i2c_init_param::slave_address
uint8_t slave_address
Definition: platform_drivers.h:81
gpio_type
gpio_type
Definition: platform_drivers.h:120
Wire_Connect
void Wire_Connect()
Connects and initializes I2C.
Definition: platform_drivers.cpp:390
gpio_direction_input
int32_t gpio_direction_input(gpio_desc *desc)
Enable the input direction of the specified GPIO.
Definition: platform_drivers.cpp:290
address
static uint8_t address
Definition: DC2091A.ino:83
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
spi_desc::type
spi_type type
Definition: platform_drivers.h:113
spi_init_param::mode
uint8_t mode
Definition: platform_drivers.h:108
i2c_desc::slave_address
uint8_t slave_address
Definition: platform_drivers.h:88
gpio_desc::id
uint32_t id
Definition: platform_drivers.h:126
i2c_init_param::type
i2c_type type
Definition: platform_drivers.h:78
spi_init_param::type
spi_type type
Definition: platform_drivers.h:105
i2c_desc::type
i2c_type type
Definition: platform_drivers.h:85
gpio_direction_output
int32_t gpio_direction_output(gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: platform_drivers.cpp:305
i2c_read
int32_t i2c_read(i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
Read data from a slave device.
Definition: platform_drivers.cpp:122
i2c_init_param::id
uint32_t id
Definition: platform_drivers.h:79
Wire_Read
uint8_t Wire_Read(unsigned char address, unsigned char *data, unsigned char length, unsigned char stop)
Read I2C.
Definition: platform_drivers.cpp:436
spi_init_param::id
uint32_t id
Definition: platform_drivers.h:106
stop
static float stop
Definition: Audio_Spectrum_Analyzer.ino:19
i2c_write
int32_t i2c_write(i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
Write data to a slave device.
Definition: platform_drivers.cpp:104
i2c_desc::max_speed_hz
uint32_t max_speed_hz
Definition: platform_drivers.h:87
gpio_desc::type
gpio_type type
Definition: platform_drivers.h:125
gpio_get
int32_t gpio_get(gpio_desc **desc, uint8_t gpio_number)
Obtain the GPIO decriptor.
Definition: platform_drivers.cpp:258
quikeval_set_mux
void quikeval_set_mux(uint8_t mux)
Sets the Linduino MUX that selects SPI or I2C for the quikeval port.
Definition: platform_drivers.cpp:465
gpio_desc::number
uint8_t number
Definition: platform_drivers.h:127
GENERIC_SPI
Definition: platform_drivers.h:92
gpio_get_direction
int32_t gpio_get_direction(gpio_desc *desc, uint8_t *direction)
Get the direction of the specified GPIO.
Definition: platform_drivers.cpp:322
Wire_Write
uint8_t Wire_Write(unsigned char address, unsigned char *data, unsigned char length, unsigned char stop)
Write I2C.
Definition: platform_drivers.cpp:406
GENERIC_I2C
Definition: platform_drivers.h:74
uartTX
void uartTX(char *buf)
Enable SPI, matches spi_enable.
Definition: platform_drivers.cpp:483
spi_desc
Definition: platform_drivers.h:112
spi_write_and_read
int32_t spi_write_and_read(spi_desc *desc, uint8_t *data, uint8_t bytes_number)
Write and read data to/from SPI.
Definition: platform_drivers.cpp:200
spi_remove
int32_t spi_remove(spi_desc *desc)
Free the resources allocated by spi_init().
Definition: platform_drivers.cpp:186
gpio_remove
int32_t gpio_remove(gpio_desc *desc)
Free the resources allocated by gpio_get().
Definition: platform_drivers.cpp:276
spi_init_param::chip_select
uint8_t chip_select
Definition: platform_drivers.h:109
spi_desc::mode
uint8_t mode
Definition: platform_drivers.h:116
i2c_type
i2c_type
Definition: platform_drivers.h:73
i2c_init
int32_t i2c_init(i2c_desc **desc, const struct i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: platform_drivers.cpp:60
i2c_init_param
struct i2c_init_param i2c_init_param
i2c_desc::id
uint32_t id
Definition: platform_drivers.h:86
spi_desc::id
uint32_t id
Definition: platform_drivers.h:114
spi_type
spi_type
Definition: platform_drivers.h:91