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{
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;
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{
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;
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 {
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_
void mdelay(uint32_t msecs)
Generate miliseconds delay.
int32_t spi_init(spi_desc **desc, const struct spi_init_param *param)
Initialize the SPI communication peripheral.
int32_t i2c_remove(i2c_desc *desc)
Free the resources allocated by i2c_init().
uint8_t chip_select
int32_t gpio_get_value(gpio_desc *desc, uint8_t *value)
Get the value of the specified GPIO.
uint32_t max_speed_hz
int32_t gpio_set_value(gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
struct spi_init_param spi_init_param
uint32_t max_speed_hz
struct i2c_desc i2c_desc
gpio_type
void Wire_Connect()
Connects and initializes I2C.
int32_t gpio_direction_input(gpio_desc *desc)
Enable the input direction of the specified GPIO.
static uint8_t address
Definition: DC2091A.ino:83
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
spi_type type
uint8_t slave_address
i2c_type type
int32_t gpio_direction_output(gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
int32_t i2c_read(i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
Read data from a slave device.
uint8_t Wire_Read(unsigned char address, unsigned char *data, unsigned char length, unsigned char stop)
Read I2C.
static float stop
int32_t i2c_write(i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
Write data to a slave device.
uint32_t max_speed_hz
gpio_type type
int32_t gpio_get(gpio_desc **desc, uint8_t gpio_number)
Obtain the GPIO decriptor.
void quikeval_set_mux(uint8_t mux)
Sets the Linduino MUX that selects SPI or I2C for the quikeval port.
uint8_t number
int32_t gpio_get_direction(gpio_desc *desc, uint8_t *direction)
Get the direction of the specified GPIO.
uint8_t Wire_Write(unsigned char address, unsigned char *data, unsigned char length, unsigned char stop)
Write I2C.
void uartTX(char *buf)
Enable SPI, matches spi_enable.
int32_t spi_write_and_read(spi_desc *desc, uint8_t *data, uint8_t bytes_number)
Write and read data to/from SPI.
int32_t spi_remove(spi_desc *desc)
Free the resources allocated by spi_init().
int32_t gpio_remove(gpio_desc *desc)
Free the resources allocated by gpio_get().
uint8_t mode
i2c_type
int32_t i2c_init(i2c_desc **desc, const struct i2c_init_param *param)
Initialize the I2C communication peripheral.
struct i2c_init_param i2c_init_param
uint32_t id
uint32_t id
spi_type