1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-30 11:24:12 +01:00
Arduino/hardware/arduino/sam/libraries/SPI/SPI.h

70 lines
1.8 KiB
C
Raw Normal View History

2011-06-21 00:03:22 +02:00
/*
* Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
* SPI Master library for arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#ifndef _SPI_H_INCLUDED
#define _SPI_H_INCLUDED
#include "variant.h"
2011-06-21 00:03:22 +02:00
#include <stdio.h>
2012-04-24 18:43:33 +02:00
#define SPI_MODE0 0x02
#define SPI_MODE1 0x00
#define SPI_MODE2 0x03
#define SPI_MODE3 0x01
2011-06-21 00:03:22 +02:00
2012-05-18 01:30:54 +02:00
enum SPITransferMode {
SPI_CONTINUE,
SPI_LAST
};
2011-12-02 16:29:50 +01:00
class SPIClass {
public:
2012-05-18 01:30:54 +02:00
SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void));
2011-06-21 00:03:22 +02:00
2012-06-09 15:02:51 +02:00
byte transfer(uint8_t _data, SPITransferMode _mode = SPI_LAST) { return transfer(BOARD_SPI_DEFAULT_SS, _data, _mode); }
2012-05-18 01:30:54 +02:00
byte transfer(byte _channel, uint8_t _data, SPITransferMode _mode = SPI_LAST);
2011-06-21 00:03:22 +02:00
2011-12-02 16:29:50 +01:00
// SPI Configuration methods
2011-06-21 00:03:22 +02:00
2011-12-02 16:29:50 +01:00
void attachInterrupt(void);
void detachInterrupt(void);
2011-06-21 00:03:22 +02:00
2012-06-09 15:02:51 +02:00
void begin(void);
2011-12-02 16:29:50 +01:00
void end(void);
2011-06-21 00:03:22 +02:00
// Attach/Detach pin to/from SPI controller
void begin(uint8_t _pin);
void end(uint8_t _pin);
// These methods sets a parameter on a single pin
void setBitOrder(uint8_t _pin, BitOrder);
void setDataMode(uint8_t _pin, uint8_t);
void setClockDivider(uint8_t _pin, uint8_t);
// These methods sets the same parameters but on default pin BOARD_SPI_DEFAULT_SS
void setBitOrder(BitOrder _order) { setBitOrder(BOARD_SPI_DEFAULT_SS, _order); };
2012-06-09 15:02:51 +02:00
void setDataMode(uint8_t _mode) { setDataMode(BOARD_SPI_DEFAULT_SS, _mode); };
void setClockDivider(uint8_t _div) { setClockDivider(BOARD_SPI_DEFAULT_SS, _div); };
2011-12-02 16:29:50 +01:00
private:
Spi *spi;
uint32_t id;
BitOrder bitOrder[SPI_CHANNELS_NUM];
uint32_t divider[SPI_CHANNELS_NUM];
uint32_t mode[SPI_CHANNELS_NUM];
void (*initCb)(void);
2011-12-02 16:29:50 +01:00
};
#if SPI_INTERFACES_COUNT > 0
2012-05-18 01:30:54 +02:00
extern SPIClass SPI;
2011-12-02 16:29:50 +01:00
#endif
2011-06-21 00:03:22 +02:00
#endif