Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Microchip/PIC32MX320F128H/Common/Communication.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Communication.h
3 * @brief Header file of Communication Driver for PIC32MX320F128H
4 Processor.
5 * @author DBogdan ([email protected])
6 ********************************************************************************
7 * Copyright 2013(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************/
41 #ifndef __COMMUNICATION_H__
42 #define __COMMUNICATION_H__
43
44 /******************************************************************************/
45 /***************************** Include Files **********************************/
46 /******************************************************************************/
47 #include <xc.h>
48
49 /******************************************************************************/
50 /**************************** GPIO Definitions ********************************/
51 /******************************************************************************/
52 #define SPI_CS_PIN_OUT TRISGbits.TRISG9 = 0;
53 #define SPI_CS_LOW LATGbits.LATG9 = 0;
54 #define SPI_CS_HIGH LATGbits.LATG9 = 1;
55
56 #define SPI_MISO PORTGbits.RG7
57
58 #define GPIO1_PIN_OUT TRISDbits.TRISD8 = 0;
59 #define GPIO1_PIN_IN TRISDbits.TRISD8 = 1;
60 #define GPIO1_LOW LATDbits.LATD8 = 0;
61 #define GPIO1_HIGH LATDbits.LATD8 = 1;
62 #define GPIO1_STATE PORTDbits.RD8
63
64 #define GPIO2_PIN_OUT TRISBbits.TRISB5 = 0;
65 #define GPIO2_PIN_IN TRISBbits.TRISB5 = 1;
66 #define GPIO2_LOW LATBbits.LATB5 = 0;
67 #define GPIO2_HIGH LATBbits.LATB5 = 1;
68 #define GPIO2_STATE PORTBbits.RB5
69
70 #define GPIO3_PIN_OUT TRISBbits.TRISB4 = 0;
71 #define GPIO3_PIN_IN TRISBbits.TRISB4 = 1;
72 #define GPIO3_LOW LATBbits.LATB4 = 0;
73 #define GPIO3_HIGH LATBbits.LATB4 = 1;
74 #define GPIO3_STATE PORTBbits.RB4
75
76 #define GPIO4_PIN_OUT TRISBbits.TRISB3 = 0;
77 #define GPIO4_PIN_IN TRISBbits.TRISB3 = 1;
78 #define GPIO4_LOW LATBbits.LATB3 = 0;
79 #define GPIO4_HIGH LATBbits.LATB3 = 1;
80 #define GPIO4_STATE PORTBbits.RB3
81
82 /******************************************************************************/
83 /************************ Functions Declarations ******************************/
84 /******************************************************************************/
85 /*!< Initializes the SPI communication peripheral. */
86 unsigned char SPI_Init(unsigned char lsbFirst,
87 unsigned long clockFreq,
88 unsigned char clockPol,
89 unsigned char clockEdg);
90
91 /*!< Writes data to SPI. */
92 unsigned char SPI_Write(unsigned char slaveDeviceId,
93 unsigned char* data,
94 unsigned char bytesNumber);
95
96 /*!< Reads data from SPI. */
97 unsigned char SPI_Read(unsigned char slaveDeviceId,
98 unsigned char* data,
99 unsigned char bytesNumber);
100
101 /*!< Initializes the I2C communication peripheral. */
102 unsigned char I2C_Init(unsigned long clockFreq);
103
104 /*!< Writes data to a slave device. */
105 unsigned char I2C_Write(unsigned char slaveAddress,
106 unsigned char* dataBuffer,
107 unsigned char bytesNumber,
108 unsigned char stopBit);
109
110 /*!< Reads data from a slave device. */
111 unsigned char I2C_Read(unsigned char slaveAddress,
112 unsigned char* dataBuffer,
113 unsigned char bytesNumber,
114 unsigned char stopBit);
115
116 /*!< Initializes the UART communication peripheral. */
117 char UART_Init(unsigned long baudRate);
118
119 /*!< Writes one character to UART. */
120 void UART_WriteChar(char data);
121
122 /*!< Reads one character from UART. */
123 void UART_ReadChar(char* data);
124
125 #endif /*__COMMUNICATION_H__*/