2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * @brief C++ API to System Packet Interface
34 * This file defines the SPI C++ interface for libmraa
36 * @snippet Spi-pot.cpp Interesting
41 * Initialise SPI object using the board mapping to set muxes
43 * @param bus to use, as listed in the platform definition, normally 0
46 m_spi = mraa_spi_init(bus);
55 * Set the SPI device mode. see spidev0-3
57 * @param mode the mode. See Linux spidev doc
58 * @return Result of operation
60 mraa_result_t mode(unsigned short mode) {
61 return mraa_spi_mode(m_spi, mode);
64 * Set the SPI device operating clock frequency
66 * @param hz the frequency to set in hz
67 * @return Result of operation
69 mraa_result_t frequency(int hz) {
70 return mraa_spi_frequency(m_spi, hz);
73 * Write single byte to the SPI device
75 * @param data the byte to send
76 * @return data received on the miso line
78 unsigned char write(uint8_t data) {
79 return (unsigned char) mraa_spi_write(m_spi, data);
82 * Write buffer of bytes to SPI device
84 * @param data buffer to send
85 * @param length size of buffer to send
86 * @return char* data received on the miso line. Same length as passed in
88 unsigned char* write(uint8_t* data, int length) {
89 return (unsigned char*) mraa_spi_write_buf(m_spi, data, length);
92 * Change the SPI lsb mode
94 * @param lsb Use least significant bit transmission - 0 for msbi
95 * @return Result of operation
97 mraa_result_t lsbmode(bool lsb) {
98 return mraa_spi_lsbmode(m_spi, (mraa_boolean_t) lsb);
101 * Set bits per mode on transaction, default is 8
103 * @param bits bits per word
104 * @return Result of operation
106 mraa_result_t bitPerWord(unsigned int bits) {
107 return mraa_spi_bit_per_word(m_spi, bits);
110 mraa_spi_context m_spi;