📄 vs1001.c
字号:
/*-----------------------------------------------------------------------*/
/* MMC/SDC (in SPI mode) control module (C)ChaN, 2006 */
/*-----------------------------------------------------------------------*/
/* Only rcvr_spi(), xmit_spi(), disk_timerproc(), disk_initialize () and */
/* some macros are platform dependent. */
/*-----------------------------------------------------------------------*/
#include <mega128.h>
#include <delay.h>
#include <stdio.h>
#include <string.h>
#include "integer.h"
#include "types.h"
#include "vs1001.h"
#include "main.h"
#define SPI_LOW() SPSR=0x00;
#define SPI_HIGH() SPSR=0x01;
//#define VS1053
#ifdef VS1053
unsigned char WriteByte(unsigned char data)
{
SPDR = data;
while(!(SPSR & 0x80)); // Wait Queue off
return SPDR;
}
#else
unsigned char WriteByte(unsigned char data)
{
unsigned char Counter;
for(Counter = 0; Counter < 8; ++Counter)
{
NOP();
VS_SCK=0;
if ((data & 128))
VS_SI=1;
else VS_SI=0;
VS_SCK=1;
NOP();
data <<= 1; //shift data left to 1
if(VS_SO)
data |= 1;
}
return data;
}
#endif
//*************************************
// void VS1001_Write(unsigned char Address,int Count,unsigned int *pData)
//*************************************
void vs_write(unsigned char addr, unsigned int data)
{
while(!(DREQ));
SPI_LOW();
delay_us(10);
ENABLE_XCS(); // select VS1011 via Chip Select
WriteByte(VS_WRITE); // send write opcode
WriteByte(addr); // send address
WriteByte(data >> 8); // send MSB
WriteByte(data); // send LSB
DISABLE_XCS(); // deselect VS1011 via Chip Select
delay_us(10);
SPI_HIGH();
while(!(DREQ));
}
//*************************************
// void VS1001_Read(unsigned char Address,int Count,unsigned int *pData)
//*************************************
unsigned int vs_read(unsigned char addr)
{
unsigned int tempdata = 0;
while(!(DREQ));
SPI_LOW();
delay_us(10);
ENABLE_XCS(); // select VS1011 via Chip Select
WriteByte(VS_READ); // send read opcode
WriteByte(addr); // send address
tempdata = WriteByte(0); // send zero dummy to receive one byte and MSB was sent first
tempdata <<= 8;
tempdata += WriteByte(0); // send zero dummy to receive one byte
DISABLE_XCS(); // deselect VS1011 via Chip Select
delay_us(10);
SPI_HIGH();
while(!(DREQ));
return tempdata; // return data word
}
//*************************************
// void VS1001_Stream(unsigned char Data,unsigned char Qte)
//*************************************
void vs_stream(unsigned char *Data, unsigned char Qte)
{
ENABLE_XDCS();//BSYNC=0;
while(Qte--) WriteByte(*Data++);
DISABLE_XDCS();//BSYNC=1;
}
//*************************************
// void VS1001Init(void)
//*************************************
void vs_init(unsigned char HardReset)
{
unsigned int ClockF;
#ifdef VS1053
unsigned int SC_Mult;
unsigned int SC_Add;
unsigned int SC_Freq;
//囗嚯钽梓眍 蜞犭桷
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -