Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
spi_functions.h
Go to the documentation of this file.
1 
2 /*
3  * SPI testing utility (using spidev driver)
4  *
5  * Copyright (c) 2007 MontaVista Software, Inc.
6  * Copyright (c) 2007 Anton Vorontsov
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License.
11  *
12  * Cross-compile with cross-gcc -I/path/to/cross-kernel/include
13  *
14  */
15 
16 #ifndef SPI_FUNCTIONS_H
17 #define SPI_FUNCTIONS_H
18 
19 #include <stdint.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <getopt.h>
24 #include <fcntl.h>
25 #include <sys/ioctl.h>
26 #include <linux/types.h>
27 #include <linux/spi/spidev.h>
28 
29 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
30 
31 /* Commands */
32 #define ENCODER_NO_OP 0x00
33 #define ENCODER_RD_POS 0x10
34 #define ENCODER_SET_ZERO_PT 0x70
35 #define ENCODER_EEPROM_WR 0x80
36 #define ENCODER_EEPROM_RD 0x90
37 
46 int spi_init(uint8_t mode, uint32_t speed, uint8_t cs);
47 /* Parameters
48 - mode: 0 .. 3
49 - speed (Hz): 48000000, 24000000, 12000000, 6000000, 3000000, 1500000, 750000, 375000, 187000,, 93700, 46800, 23400, 11700, 5800, 2900, 1500000
50 - cs: 0 or 1 //Chip select
51 returns spi_dev
52 */
53 
58 void spi_end(int spi_dev);
59 
66 int adc_read(int spi_dev, uint8_t ch, uint8_t sgl, short int *data);
67 
72 int dac_write(int spi_dev, uint8_t ch, uint8_t _shdn, unsigned short int data);
73 /* Parameters
74 - ch (channel): 0 or 1
75 - _shdn (shutdown):
76 0 Output buffer disabled, Output is high impedance
77 1 Output Power Down Control bit
78 - data: 0 .. 4095
79 */
80 
85 int spi_trans_bytes(int spi_dev,uint8_t *send, uint8_t *receive,int n);
86 
87 #endif
int spi_trans_bytes(int spi_dev, uint8_t *send, uint8_t *receive, int n)
TRANSFER N BYTES.
int spi_init(uint8_t mode, uint32_t speed, uint8_t cs)
spi Functions to deal communication by SPI protocol
int adc_read(int spi_dev, uint8_t ch, uint8_t sgl, short int *data)
READ DATA FROM A/D CONVERTER MCP3208.
void spi_end(int spi_dev)
TERMINATES SPI DEVICE.
int dac_write(int spi_dev, uint8_t ch, uint8_t _shdn, unsigned short int data)
WRITE DATA TO D/A CONVERTER MCP3922.