📄 lpc_spi.h
字号:
#ifndef __LPC_SPI_H
#define __LPC_SPI_H
/***********************************************************************
* BU MMS China, Philips Semiconductor Software Support
* Embest info&Tech Co. Software Support
*---------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. Everybody can use it as
* it is opened and without copyright. We will not take any law responsibility
* for any problem produced by using this software.
*---------------------------------------------------------------------------
* File name: LPC_SPI.h
* Description: Define SPI structure and relative micro
*
* History:
* 1. Date: Nov 20, 2004
* Author: Shawn Zhang
* Description: Create
*
* $Revision: 1.0 $
**********************************************************************/
#include "LPC_Base.h"
#include "LPC_Type.h"
#include "LPC_SysControl.h"
/* The micro are configurable */
#define SPI_RXBUFSIZE 64
/*
SPI max speed: 7.5Mbits/s
SPI bus speed = Fpclk / SPCCR
*/
#define SPI_MAXSPEED 7500000
#define SPCCR_MINVALUE 8
/* SPI Status Type */
#define SPSR_ABRT 0x8 // Slave abort
#define SPSR_MODF 0x10 // Mode fault
#define SPSR_ROVR 0x20 // Read overrun
#define SPSR_WCOL 0x40 // Write collision
#define SPSR_SPIF 0x80 // SPI transfer complete flag
#define SPI_BUF_OVERFLOW_ERR 0x4
/* Device number */
typedef enum {
SPI0 = 0,
SPI1
} LPC_SPI_Channel_t;
/* Clock phase control */
typedef enum {
SCK_FIRSTEDGE = 0,
SCK_SECONDEDGE
} LPC_SPI_CPHA_t;
/* Clock polarity control */
typedef enum {
SCK_HIGH = 0,
SCK_LOW
} LPC_SPI_CPOL_t;
/* LSB First controls */
typedef enum {
MSB = 0, // bit 1 first
LSB // bit 0 first
} LPC_SPI_LSBF_t;
/* Master mode select */
typedef enum {
SPI_SLAVE = 0,
SPI_MASTER
} LPC_SPI_Mode_t;
typedef struct {
char RxBuf[SPI_RXBUFSIZE];
char* pTxBuf;
int RxHeadPoint;
int RxTailPoint;
volatile int RxCount;
volatile int TxCount;
volatile int status;
}LPC_SPI_Buffer_t;
typedef struct {
LPC_SPI_Mode_t Mode;
lpc_uint32 BusSpeed;
LPC_SPI_CPHA_t CPHA;
LPC_SPI_CPOL_t CPOL;
LPC_SPI_LSBF_t LSBF;
bool IntEnable;
void (* Fnpr)(void *);
void * FnprArg;
LPC_SPI_Buffer_t SPIBuffer;
} LPC_SPI_Config_t;
/* Declare functions */
int SPI_Init (LPC_SPI_Channel_t DevNum, LPC_SPI_Mode_t Mode, lpc_uint32 BusSpeed,
LPC_SPI_CPHA_t CPHA, LPC_SPI_CPOL_t CPOL, LPC_SPI_LSBF_t LSBF,
bool IntEnable, void (* Fnpr)(void *), void * FnprArg);
int SPI_Write(LPC_SPI_Channel_t DevNum, char* Buf, int Size);
char SPI_Read (LPC_SPI_Channel_t DevNum);
char SPI_GetStatus(LPC_SPI_Channel_t DevNum);
void SPI0_ISR (void);
void SPI1_ISR (void);
extern SPI0_VectISR (void);
extern SPI1_VectISR (void);
#endif // __LPC_SPI_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -