コード例 #1
0
ファイル: spi.c プロジェクト: kenzanin/webbotavrclib-1x
 *      Author: Clive Webster
 *
 *  Implement an SPI interface in hardware
 */
#include "spi.h"
#include <avr/io.h>

// Define the implementations of the virtual classes
static void 	__spiHWInit(SPI_ABSTRACT_BUS* spi, boolean master);
static void 	__spiHWOff(SPI_ABSTRACT_BUS* spi);
static void 	__spiHWSetClock(SPI_ABSTRACT_BUS* spi, SPI_CLOCK clock);
static void 	__spiHWSetDataOrder(SPI_ABSTRACT_BUS* spi,SPI_DATA_ORDER order);
static void 	__spiHWSetMode(SPI_ABSTRACT_BUS* spi,SPI_MODE mode);
static uint8_t 	__spiHWSendByte(SPI_ABSTRACT_BUS* spi, uint8_t data);

SPI_CLASS const PROGMEM c_hw_spi = MAKE_SPI_CLASS(&__spiHWInit, &__spiHWOff,&__spiHWSetClock,&__spiHWSetDataOrder, &__spiHWSetMode,&__spiHWSendByte, null, null,null);


#if defined (__AVR_ATmega640__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega1280__) || defined (__AVR_ATmega2560__) || defined (__AVR_ATmega2561__) || defined (__AVR_ATmega128RFA1__)
// Define the SPI pins for ATMega640/ATMega128/ATMega1280/ATMega2560/ATMega2561/ATMega128RFA1
#define SS_PORT PORTB
#define SS_DDR  DDRB
#define SS_PIN  PB0

#define SCK_PORT PORTB
#define SCK_DDR  DDRB
#define SCK_PIN  PB1

#define MOSI_PORT PORTB
#define MOSI_DDR  DDRB
#define MOSI_PIN  PB2
コード例 #2
0
ファイル: spisw.c プロジェクト: bechu/hexapod
#include "../spisw.h"
//#include "pinChange.h"
#include "../timer.h"

// Define the implementations of the virtual classes
static void 	__spiSWInit(SPI_ABSTRACT_BUS* spi, boolean master);
static void 	__spiSWOff(SPI_ABSTRACT_BUS* spi);
static void 	__spiSWSetClock(SPI_ABSTRACT_BUS* spi, SPI_CLOCK clock);
static void 	__spiSWSetDataOrder(SPI_ABSTRACT_BUS* spi,SPI_DATA_ORDER order);
static void 	__spiSWSetMode(SPI_ABSTRACT_BUS* spi,SPI_MODE mode);
static uint8_t 	__spiSWSendByte(SPI_ABSTRACT_BUS* spi, uint8_t data);
static void 	readMany(const SPI_ABSTRACT_DEVICE* device,void* dta, size_t size);
static void 	writeMany(const SPI_ABSTRACT_DEVICE* device,const void* dta, size_t size);
static void	 	select(const SPI_ABSTRACT_DEVICE* device,boolean selected);// Device selection change

const SPI_CLASS PROGMEM c_sw_spi = MAKE_SPI_CLASS(&__spiSWInit, &__spiSWOff,&__spiSWSetClock,&__spiSWSetDataOrder, &__spiSWSetMode,&__spiSWSendByte,&readMany,&writeMany,&select);


// Called under interrupts when the chip select pin has changed
//void slaveListener(const IOPin* io,boolean val, volatile void* data){
//	if(val==FALSE){
//		// Chip IS selected - so read in the next byte
//
//	}
//}



//------------- Private methods - dont call directly -----
static void __spiSWInit(SPI_ABSTRACT_BUS* _spi, boolean master){
	SPI_SW* spi = (SPI_SW*)_spi;