1
0
Fork 0
mirror of synced 2025-07-03 11:56:56 +02:00

Sync Triple-A libraries.

This commit is contained in:
Mika Tuupola 2011-12-17 19:08:52 +02:00
parent fdf5f06cd8
commit 391a0e6cc2
10 changed files with 374 additions and 760 deletions

27
tpic6b595_spi/spi/spi.c Normal file
View file

@ -0,0 +1,27 @@
/*
* spi.c
*
* Copyright 2011 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
#include "pins/digital.h"
#include "spi/spi.h"
void spi_init(void) {
pin_mode(SPI_SCLK, OUTPUT);
pin_mode(SPI_MOSI, OUTPUT);
pin_mode(SPI_SS, OUTPUT); /* Must be output in Master mode. */
spi_set_msb();
spi_set_master();
spi_enable();
}
uint8_t spi_transfer(volatile uint8_t data) {
SPDR = data;
loop_until_bit_is_set(SPSR, SPIF);
return SPDR;
}

42
tpic6b595_spi/spi/spi.h Normal file
View file

@ -0,0 +1,42 @@
/*
* spi.h
*
* http://www.atmel.com/dyn/resources/prod_documents/doc2585.pdf
*
* Copyright 2011 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
/* http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf */
#if defined(__AVR_ATmega168__) \
|| defined(__AVR_ATmega168P__) \
|| defined(__AVR_ATmega328__) \
|| defined (__AVR_ATmega328P__)
#define SPI_SS PB2 /* Slave Select. PORTB2 LATCH RCK*/
#define SPI_SCLK PB5 /* Serial clock. PORTB5 CLOCK */
#define SPI_MOSI PB3 /* Master Out Slave In. PORTB3 DATA*/
#define SPI_MISO PB4 /* Master In Slave Out PORTB4 */
/* http://www.pjrc.com/teensy/atmega32u4.pdf */
#elif defined (__AVR_ATmega32U4__)
#define SPI_SS B0
#define SPI_SCLK B1
#define SPI_MOSI B2
#define SPI_MISO B3
#endif
#define spi_set_lsb() SPCR |= _BV(DORD)
#define spi_set_msb() SPCR &= ~(_BV(DORD))
#define spi_set_master() SPCR |= _BV(MSTR)
#define spi_set_slave() SPCR &= ~(_BV(MSTR))
#define spi_enable() SPCR |= _BV(SPE)
#define spi_disable() SPCR &= ~(_BV(SPE));
uint8_t spi_transfer(volatile uint8_t data);
void spi_init(void);