Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SPIDevice.h
Go to the documentation of this file.
1 /*
2  * SPIDevice.h Created on: 22 May 2014
3  * Copyright (c) 2014 Derek Molloy (www.derekmolloy.ie)
4  * Made available for the book "Exploring BeagleBone"
5  * See: www.exploringbeaglebone.com
6  * Licensed under the EUPL V.1.1
7  *
8  * This Software is provided to You under the terms of the European
9  * Union Public License (the "EUPL") version 1.1 as published by the
10  * European Union. Any use of this Software, other than as authorized
11  * under this License is strictly prohibited (to the extent such use
12  * is covered by a right of the copyright holder of this Software).
13  *
14  * This Software is provided under the License on an "AS IS" basis and
15  * without warranties of any kind concerning the Software, including
16  * without limitation merchantability, fitness for a particular purpose,
17  * absence of defects or errors, accuracy, and non-infringement of
18  * intellectual property rights other than copyright. This disclaimer
19  * of warranty is an essential part of the License and a condition for
20  * the grant of any rights to this Software.
21  *
22  * For more details, see http://www.derekmolloy.ie/
23  */
24 
25 #ifndef SPIDEVICE_H_
26 #define SPIDEVICE_H_
27 #include<string>
28 #include<stdint.h>
29 #include"BusDevice.h"
30 
31 #define SPI_PATH "/dev/spidev"
33 namespace exploringBB{
34 
39 class SPIDevice:public BusDevice {
40 public:
42  enum SPIMODE{
43  MODE0 = 0,
44  MODE1 = 1,
45  MODE2 = 2,
46  MODE3 = 3
47  };
48 
49 private:
50  std::string filename;
51 public:
52  SPIDevice(unsigned int bus, unsigned int device);
53  virtual int open();
54  virtual unsigned char readRegister(unsigned int registerAddress);
55  virtual unsigned char* readRegisters(unsigned int number, unsigned int fromAddress=0);
56  virtual int writeRegister(unsigned int registerAddress, unsigned char value);
57  virtual void debugDumpRegisters(unsigned int number = 0xff);
58  virtual int write(unsigned char value);
59  virtual int write(unsigned char value[], int length);
60  virtual int setSpeed(uint32_t speed);
61  virtual int setMode(SPIDevice::SPIMODE mode);
62  virtual int setBitsPerWord(uint8_t bits);
63  virtual void close();
64  virtual ~SPIDevice();
65  virtual int transfer(unsigned char read[], unsigned char write[], int length);
66 private:
67  SPIMODE mode;
68  uint8_t bits;
69  uint32_t speed;
70  uint16_t delay;
71 };
72 
73 } /* namespace exploringBB */
74 
75 #endif /* SPIDEVICE_H_ */
int write(string path, string filename, string value)
Definition: util.cpp:40
SPIMODE
The SPI Mode.
Definition: SPIDevice.h:42
Generic SPI Device class that can be used to connect to any type of SPI device and read or write to i...
Definition: SPIDevice.h:39
This class is the parent of I2C and SPI devices, so that devices that use both SPI and I2C interfaces...
Definition: BusDevice.h:37
string read(string path, string filename)
Definition: util.cpp:57