Commit 91e34710 by zhanggf

initial

parents
#include "IIC.h"
//frequent 400kHZ
uint32_t T = 0;
//void Delay5us(void)//2.5us
//{
// nop();nop(); nop();nop(); nop();nop(); nop();nop();
// nop();nop(); nop();nop(); nop();nop(); nop();nop();
// //nop();nop(); nop();nop(); nop();nop();
// nop();nop(); nop();nop(); nop();nop(); nop();nop();
// nop();nop(); nop();nop(); nop();nop();
//}
void Delay5us(void)//2.5us
{
nop();nop(); nop();nop(); nop();nop(); nop();nop();
nop();nop(); nop();nop(); nop();nop(); nop();nop();
nop();nop(); nop();nop(); nop();nop(); nop();nop();
nop();nop(); nop();nop(); nop();nop();
}
//i2c pins initial
void HMC5883_InitPin(void)
{
I2C_GPIO->DDR |= (I2C_SCL_PIN)|(I2C_SDA_PIN);
I2C_GPIO->CR1 |= ((I2C_SCL_PIN)|(I2C_SDA_PIN));
I2C_GPIO->CR2 |= (I2C_SCL_PIN)|(I2C_SDA_PIN);
I2C_GPIO->ODR &= ~((I2C_SCL_PIN)|(I2C_SDA_PIN));
SCL_L;
Delay5us();
asm("NOP;");
}
bool HMC5883_Start(void)
{
SDA_H;
SCL_H;
Delay5us();
SDA_L;
Delay5us();
SCL_L;
Delay5us();
return TRUE;
}
void HMC5883_Stop(void)
{
SDA_L;
SCL_H;
Delay5us();
SDA_H;
Delay5us();
SCL_L;
Delay5us();
}
bool HMC5883_WaitACK(void)
{
SDA_H;
SDA_IN;
Delay5us();
SCL_H;
Delay5us();
if(SDA_read){SCL_L;SDA_OUT;return FALSE;}
Delay5us();
SCL_L;
SDA_OUT;
return TRUE;
}
/**************************************
发送应答信号
入口参数:ack (0:ACK 1:NAK)
**************************************/
void HMC5883_SendACK(bool ack)
{
if(ack==TRUE)SDA_H;
else{SDA_L;}
Delay5us();
SCL_H;
Delay5us();
SCL_L;
Delay5us();
}
/*I2C的NoACK函数----------------------------------------*/
void I2C_NoAck(void)
{
SCL_L;
Delay5us();
SDA_H;
Delay5us();
SCL_H;
Delay5us();
SCL_L;
Delay5us();
}
bool HMC5883_SendByte(BYTE dat)
{
BYTE i;
for (i=0; i<8; i++) //8位计数器
{
if(dat&0x80)SDA_H;
else
SDA_L;
Delay5us();
SCL_H;
Delay5us();
SCL_L;
// Delay5us();
dat<<=1;
}
asm("NOP");
if(!HMC5883_WaitACK())return FALSE;
return TRUE;
}
/**************************************
从IIC总线接收一个字节数据
**************************************/
BYTE HMC5883_RecvByte()
{
BYTE i;
BYTE dat = 0;
SDA_H;
SDA_IN;
//使能内部上拉,准备读取数据,
for (i=0; i<8; i++) //8位计数器
{
dat <<= 1;
SCL_H; //拉高时钟线
Delay5us(); //延时
if(SDA_read)dat|=0x01;//读数据
SCL_L; //拉低时钟线
Delay5us(); //延时
}
SDA_OUT;
return dat;
}
bool error_id = FALSE;
uint8_t count1 = 0;
//************************写入单字节数据***************************
bool Single_Write_HMC5883(uchar SlaveAddress,uchar REG_Address,uchar REG_data)
{
uint8_t cnt = 0;
while(cnt++<5)
{
count1++;
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress); //发送设备地址+写信号
HMC5883_SendByte(REG_Address); //内部寄存器地址,请参考中文pdf
error_id=HMC5883_SendByte(REG_data); //内部寄存器数据,请参考中文pdf
HMC5883_Stop();
if(!error_id)break;
}
asm("NOP");
if(cnt>=5)return FALSE;
else
return TRUE;
}
//************************读取内部寄存器*************************
uchar Single_Read_HMC5883(uchar SlaveAddress,uchar REG_Address)
{
uchar REG_data;
asm("NOP;");
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress); //发送设备地址+写信号
HMC5883_SendByte(REG_Address); //发送存储单元地址,从0开始
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress+1); //发送设备地址+读信号
REG_data=HMC5883_RecvByte(); //读出寄存器数据
HMC5883_SendACK(TRUE);
HMC5883_Stop(); //停止信号
return REG_data;
}
//************************读取内部寄存器*************************
/*
uchar Single_Read_HMC5883(uchar SlaveAddress,uchar REG_Address)
{
uchar REG_data;
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress); //发送设备地址+写信号
HMC5883_SendByte(REG_Address); //发送存储单元地址,从0开始
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress+1); //发送设备地址+读信号
REG_data=HMC5883_RecvByte(); //读出寄存器数据
HMC5883_SendACK(TRUE);
HMC5883_Stop(); //停止信号
return REG_data;
}
*/
void Multiple_Read_HMC5883(uchar SlaveAddress,uchar *BUFF)
{ uchar i;
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress); //发送设备地址+写信号
HMC5883_SendByte(0x00); //发送存储单元地址,从0x3开始
HMC5883_Start(); //起始信号
HMC5883_SendByte(SlaveAddress+1); //发送设备地址+读信号
for (i=0; i<6; i++) //连续读取6个地址数据,存储中BUF
{
BUFF[i] = HMC5883_RecvByte(); //BUF[0]存储数据
if (i == 5)
{
HMC5883_SendACK(TRUE); //最后一个数据需要回NOACK
}
else
{
HMC5883_SendACK(FALSE); //回应ACK
}
}
HMC5883_Stop(); //停止信号
}
//初始化HMC5883,根据需要请参考pdf进行修改****
uint8_t hhj = 0;
bool Init_HMC5883()
{
int temp = 0;
HMC5883_InitPin();
temp += Single_Write_HMC5883(SLAVE_ADD,0x0a,0x80);
temp += Single_Write_HMC5883(SLAVE_ADD,0x0a,0x00);
temp += Single_Write_HMC5883(SLAVE_ADD,0x09,0x1d);
temp += Single_Write_HMC5883(SLAVE_ADD,0x0B,0x01);
asm("NOP");
if(temp<4)return FALSE;
else
return TRUE;
}
#ifndef _IIC_H
#define _IIC_H
#include "user.h"
typedef unsigned char BYTE;
typedef unsigned short WORD;
#define uchar unsigned char
#define uint unsigned int
/*ģI2C˿붨*/
#define I2C_GPIO GPIOB
#define I2C_SCL_PIN GPIO_Pin_3
#define I2C_SDA_PIN GPIO_Pin_2
#define SCL_H (I2C_GPIO->ODR |= I2C_SCL_PIN)
#define SCL_L (I2C_GPIO->ODR &= (uint8_t)( ~I2C_SCL_PIN ))
#define SDA_H (I2C_GPIO->ODR |= I2C_SDA_PIN)
#define SDA_L (I2C_GPIO->ODR &= (uint8_t)( ~I2C_SDA_PIN ))
#define SDA_OUT GPIO_Init(I2C_GPIO,I2C_SDA_PIN,GPIO_Mode_Out_PP_High_Fast)//((I2C_GPIO->DDR)|=(uint8_t)(I2C_SDA_PIN))
#define SDA_IN GPIO_Init(I2C_GPIO,I2C_SDA_PIN,GPIO_Mode_In_PU_No_IT)//((I2C_GPIO->DDR)&=(uint8_t)(~I2C_SDA_PIN))
#define SDA_read (I2C_GPIO->IDR & (uint8_t)(I2C_SDA_PIN))
extern uint32_t T;
enum{yes=1,no=0};
void Delay5us(void);
void HMC5883_InitPin(void);
bool HMC5883_Start(void);
void HMC5883_Stop(void);
bool HMC5883_WaitACK(void);
void HMC5883_SendACK(bool ack);
bool HMC5883_SendByte(BYTE dat);
BYTE HMC5883_RecvByte();
bool Single_Write_HMC5883(uchar SlaveAddress,uchar REG_Address,uchar REG_data);
uchar Single_Read_HMC5883(uchar SlaveAddress,uchar REG_Address);
void Multiple_Read_HMC5883(uchar SlaveAddress,uchar *BUFF);
bool Init_HMC5883();
#endif
#include "QMC5883L.h"
enum QMC_STATE
{
qmc_init = 0,
qmc_dec = 1,
qmc_lowpower = 2,
qmc_printf = 3,
IDLE = 4
};
struct QMCSTR QMC5883LStr;
bool tempFlag = FALSE;
bool NoCarDealReportFlag = FALSE;
static void QmcTest(void)
{
static enum QMC_STATE QmcState = IDLE;
static uint8_t buff[MagDataNum][6] = {0},qmc_dec_count = 0;
uint32_t temp[6] = {0},i=0,j=0;
switch(QmcState)
{
case qmc_init:
{
if(Init_HMC5883())
{
QmcState = qmc_dec;
qmc_dec_count = 0;
ge_state = YES;
}
else
{
ge_state = NO;
}
break;
}
case qmc_dec:
{
uint8_t Staus = 0;
Staus = Single_Read_HMC5883(SLAVE_ADD,0x06);
if((Staus==0xff)||((Staus&0x01)==0))
{
return;
}
Multiple_Read_HMC5883(SLAVE_ADD,buff[qmc_dec_count++]);
if(qmc_dec_count>=MagDataNum)
{
QMC5883LStr.DataOkFlag = TRUE;
for(j=0;j<6;j++)
{
for(i=1;i<MagDataNum-1;i++)temp[j] += buff[i][j];
temp[j] = temp[j]/(MagDataNum-2);
}
for(i=0;i<6;i++)QMC5883LStr.QMC_CUR_ROPORT[i] = temp[i];
for(i=0;i<3;i++)
{
QMC5883LStr.QMC_CUR[i] = QMC5883LStr.QMC_CUR_ROPORT[i*2+1];
QMC5883LStr.QMC_CUR[i]<<=8;
QMC5883LStr.QMC_CUR[i] += QMC5883LStr.QMC_CUR_ROPORT[i*2];
}
//if(HC_DEBUG)UsartPrint(QMC5883LStr.QMC_CUR_ROPORT,6);
QmcState = qmc_lowpower;
}
break;
}
case qmc_lowpower:
{
Single_Write_HMC5883(SLAVE_ADD,0x0a,0x80);
SCL_H;
SDA_H;
QmcState = IDLE;
break;
}
case IDLE:
{
if(QMC5883LStr.DataOkFlag==0)QmcState = qmc_init;
break;
}
default :break;
}
}
void QmcDeal(void)
{
QmcTest();
}
////////////////////地磁检测车进入//////////////////////////////////////////
/***
输入:无
功能:地磁检测车进入
输出:无
***/
int geomag_car_in(void)
{
static uint8_t stable_count = 0;
static int tempX,tempY,tempZ,tempStableX,tempStableY,tempStableZ;
tempX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_BASE[0]);
tempY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_BASE[1]);
tempZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_BASE[2]);
tempStableX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_BEFORE[0]);
tempStableY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_BEFORE[1]);
tempStableZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_BEFORE[2]);
if(( tempX > 2*SystemPara.QmcFixPara[2])||(tempZ > 2*SystemPara.QmcFixPara[2]))//已检测到车
{
//前后二次电磁值相比较,若大于阀值,则说明变化明显,有效
if(tempStableX > 0x50||tempStableZ > 0x50)//车未停稳
{
memcpy(QMC5883LStr.QMC_BEFORE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
stable_count = 0;
}
else //车稳了
{
stable_count++;
if(stable_count >= 6)
{
stable_count = 6;
memcpy(QMC5883LStr.QMC_STABLE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
return 1;
}
}
}
return 0;
}
/////////////////////////////地磁检测车离开/////////////////////////////
/***
输入:first_dec:对参数进行清零;next_dec:正常检测
功能:地磁检测车离开
输出:1:车离开;0:车未离开
***/
int geomag_car_out(void)
{
int tempX,tempY,tempZ,tempStableX,tempStableY,tempStableZ;
static uint8_t again_change_count = 0,again_change_count1 = 0;
tempX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_STABLE[0]);
tempY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_STABLE[1]);
tempZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_STABLE[2]);
tempStableX = abs(QMC5883LStr.QMC_CUR[0] - QMC5883LStr.QMC_BEFORE[0]);
tempStableY = abs(QMC5883LStr.QMC_CUR[1] - QMC5883LStr.QMC_BEFORE[1]);
tempStableZ = abs(QMC5883LStr.QMC_CUR[2] - QMC5883LStr.QMC_BEFORE[2]);
if((tempX > 2*SystemPara.QmcFixPara[2])||(tempZ > 2*SystemPara.QmcFixPara[2]))
{
if((tempStableX > 0x50)||(tempStableZ > 0x50))
{
memcpy(QMC5883LStr.QMC_BEFORE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
again_change_count = 0;
}
else
{
again_change_count++;
if(again_change_count>=SystemPara.QmcFixPara[1] )
{
return 1;
}
}
}
return 0;
}
/////////////////////////////地磁自适应////////////////////////////////
/***
功能:地磁自适应
***/
void geomag_self_adaption(void)
{
//set_parking_space_status=0;
//mag_time_count=0;
int mag_x_OPT,mag_y_OPT;
int mag_x_filter = QMC5883LStr.QMC_CUR[0],mag_y_filter = QMC5883LStr.QMC_CUR[2];
int CARON_magX = QMC5883LStr.QMC_BASE[0],CARON_magY = QMC5883LStr.QMC_BASE[2];
mag_x_OPT=abs(mag_x_filter-CARON_magX);
mag_y_OPT=abs(mag_y_filter-CARON_magY);
if(mag_x_OPT>0x90||mag_y_OPT>0x90)
{
if(mag_x_OPT>mag_y_OPT)
{
SystemPara.QmcFixPara[2]= mag_x_OPT/3;
}
else
SystemPara.QmcFixPara[2]= mag_y_OPT/3;
}
else if(SystemPara.QmcFixPara[2]>=45)
{
SystemPara.QmcFixPara[2]=SystemPara.QmcFixPara[2]-0x10;
}
}
//////////////////////////////
/***
功能:有车处理函数
***/
void have_car_send()
{
memcpy(QMC5883LStr.QMC_STABLE,QMC5883LStr.QMC_CUR,3*sizeof(int16_t));
get_photoresistor_ad();
ph_stable_value = VAL_PHOTO;
BeepStart(2,0);
CarRecDataStr.CarState = 1;
CarRecDataStr.CmdSource = 3;
SendData(HAVE_CAR);
}
/***
功能:无车处理函数
***/
void NO_car_deal(void)//无车处理
{
GPIOA->ODR &= ~(1<<5);
no_car_count ++;
if(no_car_count>=10)//无车自动升起只允许尝试5次
{
no_car_count = 10;
return;
}
BeepStart(1,0);
CarAction(0,0,1,1);
// CarRecDataStr.CarState = 0;
// CarRecDataStr.CmdSource = 2;
// SendData(HAVE_CAR);
NoCarDealReportFlag = TRUE;
}
#ifndef _QMC5883L_H
#define _QMC5883L_H
#include "user.h"
enum IIC_ENUM
{
start_error = 0,
send_error = 1,
recive_error = 2,
sucess = 3
};
struct QMCSTR
{
bool DataOkFlag;
uint8_t QMC_DEC_CNT;
uint8_t QMC_CUR_ROPORT[6];
int16_t QMC_BASE[3];
int16_t QMC_BEFORE[3];
int16_t QMC_STABLE[3];
int16_t QMC_CUR[3];
};
static int QMC5883L_Init(void);
static enum IIC_ENUM QMC_Reg_Write(uint8_t slave_add,uint8_t reg_add,uint8_t len,uint8_t* data);
static enum IIC_ENUM QMC_Reg_Read(uint8_t slave_add,uint8_t reg_add,uint8_t len,uint8_t* data);
static bool QMC5883L_init(void);
static void QmcTest(void);
void QmcDeal(void);
#define SLAVE_ADD 0x1A
#define HC_DEBUG 1
#define IIC_TEST_DEBUG 1
#define MagDataNum 6
extern bool tempFlag;
extern bool NoCarDealReportFlag;
extern struct QMCSTR QMC5883LStr;
#endif
#include "SPI.h"
void SpiInit1( void )
{
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
SPI_IO_INIT;
SPI_DeInit(SPI1);
SPI0_DELAY;
SPI_Init(SPI1,SPI_FirstBit_MSB,SPI_BaudRatePrescaler_16,SPI_Mode_Master,SPI_CPOL_Low,SPI_CPHA_1Edge,SPI_Direction_2Lines_FullDuplex,SPI_NSS_Soft,0);
SPI_Cmd(SPI1,ENABLE);
// SPI1->CR2 = 0x01;
// SPI1->CR1 = 0x5C;
// SPI1->CR1 |= 0x40;
}
uint8_t SpiInOut( uint8_t outData )
{
u8 cc=0;
/* Send SPIy data */
//SPI_SendData( SPI1, outData );
SPI1->DR = outData;
while(!(SPI1->SR&0x02));
while(!(SPI1->SR&0x01));
cc= SPI1->DR;//SPI_ReceiveData( SPI1 );
SPI1->SR &= ~0x01;
return cc;
}
uint8_t regTemp=0,dataTemp=0,temp3=0;
uint8_t spi0ReadWrite(uint8_t reg,uint8_t data,enum DataDeal deal)
{
SPI0_SCS_L;
SPI0_DELAY;
dataTemp = data;
regTemp = reg;
if(deal==write)
{
regTemp |= 0x80;
}
else if(deal==read)
{
regTemp &= 0x7F;
dataTemp = 0xff;
}
SpiInOut(regTemp);
temp3 = SpiInOut(dataTemp);
SPI0_SCS_H;
return temp3;
}
uint8_t temp2;
void spiTest(void)
{
if(DelayTime)return;
DelayTime = 1;
temp2 = spi0ReadWrite(REG_LR_VERSION,0xff,read);;//SpiInOut(0xa5);
SPI0_DELAY;
UsartPrint(&temp2,1);
}
#ifndef _SPI_H
#define _SPI_H
#include "user.h"
#define SPI_GPIO1 GPIOD
#define SPI_RESET_PIN GPIO_Pin_4
#define SPI_GPIO2 GPIOB
#define SPI_NSS_PIN GPIO_Pin_4
#define SPI_SCK_PIN GPIO_Pin_5
#define SPI_MOSI_PIN GPIO_Pin_6
#define SPI_MISO_PIN GPIO_Pin_7
#define SPI0_SCS_H {GPIO_WriteBit(GPIOD,GPIO_Pin_7,SET);}
#define SPI0_SCS_L {GPIO_WriteBit(GPIOD,GPIO_Pin_7,RESET);}
//#define SPI0_NSS_H {GPIO_WriteBit(SPI_GPIO2,SPI_NSS_PIN,SET);}
//#define SPI0_NSS_H {GPIO_WriteBit(SPI_GPIO2,SPI_NSS_PIN,SET);}
#define SPI_IO_INIT { GPIO_Init(GPIOD,GPIO_Pin_7,GPIO_Mode_Out_PP_High_Fast);GPIO_WriteBit(GPIOD,GPIO_Pin_7,TRUE);\
GPIO_Init(SPI_GPIO2,SPI_SCK_PIN,GPIO_Mode_Out_PP_High_Fast);\
GPIO_Init(SPI_GPIO2,SPI_MOSI_PIN,GPIO_Mode_Out_PP_High_Fast);\
GPIO_Init(SPI_GPIO2,SPI_MISO_PIN,GPIO_Mode_In_PU_No_IT);\
}
#define SPI0_DELAY {\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");asm("NOP;");\
}
enum DataDeal
{
read=0,
write=1
};
void SpiInit1( void );
uint8_t SpiInOut( uint8_t outData );
uint8_t spi0ReadWrite(uint8_t reg,uint8_t data,enum DataDeal deal);
void spiTest(void);
#endif
#include "bsp.h"
void AdcInit(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_1);
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
ADC_Cmd(ADC1,ENABLE);
ADC_Cmd(ADC1,ENABLE);
ADC_Cmd(ADC1,ENABLE);
ADC_Cmd(ADC1,DISABLE);
}
void bsp_init(void)
{
disableInterrupts();
//bsp_usart_init();
bsp_clk_init();
motor_init();
RtcConfig();
//bsp_time4_init();
if(!LOW_POWER_TEST)bsp_usart_init();
SpiInit1();
bsp_gpio_init();
SoftDelayMs(10);
FixedParaDeal();
SoftDelayMs(10);
AdcInit();
enableInterrupts();
bsp_DelayMS(1000);
BatVolDec(1);
if(1)
enableInterrupts();
if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
else
if(LOW_POWER_TEST)
{
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
//GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_In_FL_No_IT);
//GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_In_FL_No_IT);
CarAction(0,0,1,2);
memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
// GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_Out_PP_High_Fast);
// GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_Out_PP_High_Fast);
GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_In_FL_No_IT);
GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_In_FL_No_IT);
}
if(1){
if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
else
{
CarAction(0,0,1,2);
memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
}
}
BeepStart(2,0);
enableInterrupts();
if(!LOW_POWER_TEST){
if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
else
{
CarAction(0,0,1,2);
memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
}
BeepStart(2,0);
}
// CarRecDataStr.CmdSource = 0;
// SendData(PC_REQ);
}
#include "bsp.h"
void AdcInit(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_1);
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
ADC_Cmd(ADC1,ENABLE);
}
void bsp_init(void)
{
disableInterrupts();
//bsp_usart_init();
bsp_clk_init();
motor_init();
RtcConfig();
//bsp_time4_init();
//if(!LOW_POWER_TEST)bsp_usart_init();
SpiInit1();
bsp_gpio_init();
FixedParaDeal();
AdcInit();
enableInterrupts();
bsp_DelayMS(1000);
BatVolDec(1);
if(1)
{
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
//GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_In_FL_No_IT);
//GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_In_FL_No_IT);
}
if(1){
if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
else
{
CarAction(0,0,1,2);
memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
}
}
BeepStart(2,0);
}
#include "bsp.h"
void AdcInit(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_1);
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
ADC_Cmd(ADC1,ENABLE);
}
void bsp_init(void)
{
disableInterrupts();
bsp_clk_init();
motor_init();
//RtcConfig();
bsp_time4_init();
bsp_usart_init();
SpiInit1();
bsp_gpio_init();
FixedParaDeal();
AdcInit();
enableInterrupts();
if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
else
{
CarAction(0,0,1,2);
memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
}
BeepStart(2,0);
}
#include "bsp.h"
void AdcInit(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_1);
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
ADC_Cmd(ADC1,ENABLE);
ADC_Cmd(ADC1,DISABLE);
}
void bsp_init(void)
{
disableInterrupts();
bsp_clk_init();
motor_init();
RtcConfig();
//bsp_time4_init();
if(!LOW_POWER_TEST)bsp_usart_init();
SpiInit1();
bsp_gpio_init();
FixedParaDeal();
AdcInit();
if(LOW_POWER_TEST)
{
CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
// GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_Out_PP_High_Fast);
// GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_Out_PP_High_Fast);
GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_In_FL_No_IT);
GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_In_FL_No_IT);
// GPIO_Init(GPIOD,GPIO_Pin_7,GPIO_Mode_In_FL_No_IT);
// // GPIO_WriteBit(GPIOD,GPIO_Pin_7,TRUE);
// GPIO_Init(SPI_GPIO2,SPI_SCK_PIN,GPIO_Mode_In_FL_No_IT);\
// GPIO_Init(SPI_GPIO2,SPI_MOSI_PIN,GPIO_Mode_In_FL_No_IT);\
// GPIO_Init(SPI_GPIO2,SPI_MISO_PIN,GPIO_Mode_In_PU_No_IT);
}
enableInterrupts();
// if(!LOW_POWER_TEST){
// if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
// else
// {
// CarAction(0,0,1,2);
// memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
// }
// BeepStart(2,0);
// }
}
#ifndef _BSP_H
#define _BSP_H
#include "stm8l15x.h"
#include "math.h"
#include <stdio.h>
#include "bsp_gpio.h"
#include "bsp_time.h"
#include "bsp_usart.h"
#include "stm8l15x_itc.h"
void bsp_init(void);
#endif
\ No newline at end of file
#include "bsp_gpio.h"
/***************GPIO_init***************/
USERSTR LedStr;
struct BEEP_STR UserBeep;
void bsp_gpio_init(void)
{
GPIO_Init(GPIOA,GPIO_Pin_5,GPIO_Mode_Out_PP_Low_Fast);
//pinʼ
GPIO_Init(LIMIT_GPIO,LIMIT_PIN,GPIO_Mode_In_FL_No_IT);
GPIO_Init(BEEP_GPIO,BEEP_PIN,GPIO_Mode_Out_PP_Low_Slow);
}
void LedTest(void)
{
if(!LEDTEST)return;
if(LedStr.Cnt>0)return;
LedStr.Cnt = 1000;
GPIO_ToggleBits(GPIOA,GPIO_Pin_5);
}
/*
if(time_count4==0)
{
time_count4 = 4000;
}
else if(time_count4<=10)
{
GPIO_WriteBit(GPIOB,GPIO_Pin_3,SET);
}
else
{
GPIO_WriteBit(GPIOB,GPIO_Pin_3,RESET);
}
*/
void bsp_beep_one(void)
{
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,SET);
bsp_DelayMS(50);
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,RESET);
}
void bsp_beep_two(void)
{
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,SET);
bsp_DelayMS(BEEPTIMR);
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,RESET);
bsp_DelayMS(BEEPTIMR*2);
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,SET);
bsp_DelayMS(BEEPTIMR);
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,RESET);
}
void BeepCheck(void)
{
static uint32_t tim_cnt = 0;
if(UserBeep.BeepFlag==1)
{
if(UserBeep.times==0)
{
UserBeep.BeepFlag = 0;
tim_cnt = 0;
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,RESET);
return ;
}
tim_cnt++;
if(UserBeep.Model==0)
{
if(tim_cnt>=10)
{
if(UserBeep.times--);
tim_cnt = 0;
GPIO_ToggleBits(BEEP_GPIO,BEEP_PIN);
}
}
else if(UserBeep.Model==1)
{
if(tim_cnt==50)
{
if(UserBeep.times--);
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,SET);
}
else if(tim_cnt==200)
{
tim_cnt = 0;
if(UserBeep.times--);
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,RESET);
}
}
}
}
void BeepStart(uint32_t times,bool Model)
{
UserBeep.BeepFlag = 1;
UserBeep.Model = Model;
UserBeep.times = 2*times;
}
void BeepStop(void)
{
UserBeep.BeepFlag = 0;
GPIO_WriteBit(BEEP_GPIO,BEEP_PIN,RESET);
}
\ No newline at end of file
#ifndef _BSP_GPIO_H
#define _BSP_GPIO_H
#include "bsp.h"
#include "user.h"
#define BEEP_GPIO GPIOD
#define BEEP_PIN GPIO_Pin_1
struct BEEP_STR
{
bool BeepFlag;
bool Model;//0=εУ1=
uint32_t times;
};
extern struct BEEP_STR UserBeep;
void bsp_gpio_init(void);
void bsp_beep_one(void);
void bsp_beep_two(void);
void LedTest(void);
#define BEEPTIMR 50
void BeepCheck(void);
void BeepStart(uint32_t times,bool Model);
void BeepStop(void);
#endif
\ No newline at end of file
#include "bsp_time.h"
u32 time_count4 = 0;
u16 time_count2 = 0;
u16 DelayMs = 0;
/*************系统时钟***********************/
void bsp_clk_init(void)
{
//#if(1)
// #if AUTO_SWITCH
// CLK->SWCR |= 0x02;
// CLK->SWR = 0x04;
// asm("NOP");
// CLK->CKDIVR = 0x00;
// #else
// CLK->SWR = 0x04;
// while((CLK->ECKCR & 0x02)==0);
// CLK->SWCR |= 0x02;
// while(!(CLK->SCSR & 0x04));
// asm("NOP");
// CLK->CKDIVR = SYSDIV;
// #endif
//#else
// CLK_SYSCLKSourceSwitchCmd(ENABLE);
// CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);
// while(CLK_GetSYSCLKSource()!=CLK_SYSCLKSource_HSE);
// asm("NOP");
// CLK->CKDIVR = 0x00;
//#endif
//CLK->CSSR |= 0x01;
//asm("NOP");
CLK_SYSCLKSourceSwitchCmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
/* 系统时钟分频*/
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI)
{}
}
void bsp_time4_init(void)
{
CLK_PeripheralClockConfig(CLK_Peripheral_TIM4,ENABLE);//CLK->PCKENR1 = 0x04;//使能定时器时钟
TIM4->PSCR = TIMER4_DIV;//预分频
TIM4->CR1 = 0x85;//工作模式
TIM4->IER = 0x01;//定时器中断使能
TIM4->ARR = TIMER4_ARR;//自动重载的值
}
//void bsp_time2_init(void)
//{
// CLK->PCKENR1 = 0x05;//使能定时器时钟
// TIM2->PSCR = 0x0E;//预分频
// TIM2->CR1 = 0x85;//工作模式
// TIM2->IER = 0x01;//定时器中断使能
// TIM2->CNTRH = 0x00;//自动重载的值
// TIM2->CNTRL = 0x00;
// TIM2->ARRH = 0x03;
// TIM2->ARRL = 0xE8;
//
//}
void RtcConfig(void)
{
// CLK_LSICmd(ENABLE);
// while (CLK_GetFlagStatus(CLK_FLAG_LSIRDY) == RESET);
// CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);
// CLK_RTCClockConfig(CLK_RTCCLKSource_LSI, CLK_RTCCLKDiv_1);//38Khz
// RTC_WakeUpCmd(DISABLE);
// RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);//16分频=2.375Khz
// //RTC_SetWakeUpCounter(8);//1s
// RTC_SetWakeUpCounter(2);
// RTC_ITConfig(RTC_IT_WUT, ENABLE);
// RTC_WakeUpCmd(ENABLE);
CLK->ICKCR |= 1<<2;
while((CLK->ICKCR &(1<<3))==0);
CLK->PCKENR2 |= 1<<2;
{
while(CLK->CRTCR & 0x01);
CLK->CRTCR = 0;
while(CLK->CRTCR & 0x01);
CLK->CRTCR = 2<<1;
while(CLK->CRTCR & 0x01);
}
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC->CR2 &= ~(1<<2);
while((RTC->ISR1&(1<<2))==0);
RTC->CR1 = 0<<0;
RTC->WUTRH = 0;
RTC->WUTRL =1;
RTC->CR2 |= (1<<6)|(1<<2);
RTC->WPR = 0xFF;
}
void bsp_delay_ms(u16 ms)
{
time_count4 = ms;
while(1)
{
if(time_count4==0)
{
break;
}
}
}
void bsp_delay_s(u16 s)
{
time_count2 = s;
while(1)
{
if(time_count2==0)
{
break;
}
}
}
void bsp_DelayMS(uint16_t ms)
{
DelayMs = ms;
while(DelayMs);
}
void SoftDelayMs(u32 ms)
{
int i=0,j=0;
while(ms--)
{
for(i=0;i<16;i++)
for(j=0;j<1000;j++)
{
;
}
}
}
\ No newline at end of file
#ifndef _BSP_TIME_H
#define _BSP_TIME_H
#include "bsp.h"
#define SYSDIV 0 //ʱԤƵ
#define TIMER4_DIV 0x07//timer4ԤƵ
#define TMIER4_DELAY 1 //ms
#define TIMER4_ARR (u8)(16000000u/pow(2,SYSDIV)/pow(2,TIMER4_DIV)/(1000/TMIER4_DELAY))
#define AUTO_SWITCH 1
#define Manual_SWITCH 0
extern u32 time_count4;
extern u16 time_count2;
extern u16 DelayMs;
void bsp_clk_init(void);
void bsp_time4_init(void);
void bsp_delay_ms(u16 ms);
void bsp_delay_s(u16 s);
void bsp_DelayMS(uint16_t ms);
void RtcConfig(void);
void SoftDelayMs(u32 ms);
#endif
\ No newline at end of file
#include "bsp_usart.h"
USERSTR UartStr;
struct WIRELESS_INIT wireless_init = WIRELESS_INIT_DEFAULT;
static uint8_t WirelessModuleSet[10] = {0xC1,0xC1,0xC1,0xC0,0x64,0x36,0x25,0x4C,0xCC};
u8 TestData[8] = {0x00,0xF8,0xF8,0x01,0x02,0x03,0x04,0x05};
uint8_t UartRecLen = 0;
uint8_t UartRecBuff[25] = {0};
uint8_t UartTimeOut = 0;
void UartRecDeal(void)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
UartTimeOut = 10;
UartRecBuff[UartRecLen++] = USART_ReceiveData8(USART1);
if(UartRecLen>=25)UartRecLen = 0;
}
int fputc(int ch, FILE *f)//STM8S105,printf函数重定向
{
while (!(USART1->SR&0x80));
USART1->DR=ch;
return ch;
}
void HostPCSend(void)
{
if(UartRecLen&&(UartTimeOut==0)&&(TxModel))
{
SX78Str.SX7xTxFlag = TRUE;
SX78Str.SX7xCmd = CmdTX;
memcpy(SX78Str.SX7xTxStr,UartRecBuff,SX78Str.SX7xTxlen = UartRecLen*sizeof(uint8_t));
memset(UartRecBuff,0,25*sizeof(uint8_t));
UartRecLen = 0;
}
}
void bsp_usart_init(void)
{
//USART_ClockInit(USART1,USART_Clock_Enable,USART_CPOL_Low,USART_CPHA_2Edge,USART_LastBit_Enable);
//CLK->PCKENR1 = 0x25;//使能定时器时钟
CLK_PeripheralClockConfig(CLK_Peripheral_USART1,ENABLE);
GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_3, ENABLE);
GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_2, ENABLE);
//USART_Init(USART1,9600,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,(USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx ));
USART_Init(USART1,19200,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,(USART_Mode_TypeDef)(USART_Mode_Tx |USART_Mode_Rx ));
//USART1->CR2 = 0X80;
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
//USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
}
void UartTest(void)
{
if(!wireless_init.InitFlag)
{
WirelessInit(&wireless_init,WirelessModuleSet,6);
}
else
{
if(UartStr.Cnt>0)return;
UartStr.Cnt = 1000;
UsartPrint(TestData,8);
}
/*
if(!UARTTEST)return;
if(UartStr.Cnt>0)return;
UartStr.Cnt = 4000;
UsartPrint(TestData,5);
*/
}
void UsartPrint(uint8_t *data,uint32_t len)
{
uint32_t i = 0;
while((USART1->SR&0x80)==0);
for(i=0;i<len;i++)
{
USART1->DR = *(data++);
while((USART1->SR&0x40)==0);
}
asm("NOP");
}
static void WirelessInit(struct WIRELESS_INIT *WirelessInitCp,uint8_t *wireless,uint8_t num)
{
if(WirelessInitCp->InitFlag)return;
if(WirelessInitCp->InitDelay)return;
if(UartTimeOut)return;
static int cmd_count = 0,cmd_state=0;
switch(cmd_state)
{
case init_start:
{
WiRELESSINIT;
ConfigMode3;
//nrf_delay_ms(10);
cmd_count = 0;
cmd_state = winit_cmd_send;
UsartPrint(wireless,3);
cmd_state = init_delay;
WirelessInitCp->SendDelay = 50;
break;
}
case init_cmd_send:
{
UsartPrint(wireless+3,num);
cmd_state = init_delay;
WirelessInitCp->SendDelay = 50;
break;
}
case init_delay:
{
if(WirelessInitCp->SendDelay)break;
cmd_state = init_ing;
break;
}
case init_ing:
{
if(strstr((char *)UartRecBuff,(char *)(WirelessModuleSet+3))!=NULL)
{
memset((char *)UartRecBuff,0,25*sizeof(char));
UartRecLen = 0;
cmd_state = init_ok;
break;
}
else
{
if(cmd_count>10)
{
cmd_state = init_error;
break;
}
else
{
cmd_count++;
cmd_state = init_cmd_send;
break;
}
}
}
case init_ok:
{
ConfigMode2;
//nrf_delay_ms(10);
//beep_start(1,2,2);
WirelessInitCp->InitFlag = TRUE;
cmd_state = winit_start;
cmd_count = 0;
USART_Init(USART1,19200,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,(USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx ));
break;
}
case init_error:
{
WirelessInitCp->InitFlag = FALSE;
WirelessInitCp->InitDelay = 1000;
cmd_state = winit_start;
cmd_count = 0;
}
default:break;
}
}
#ifndef _BSP_USART_H
#define _BSP_USART_H
#include "bsp.h"
#define UARTTEST 1
#define WiRELESSINIT {\
GPIO_Init(GPIOD,GPIO_Pin_0,GPIO_Mode_Out_PP_Low_Slow);\
GPIO_Init(GPIOD,GPIO_Pin_1,GPIO_Mode_Out_PP_Low_Slow);\
}
#define ConfigMode1 {\
GPIO_WriteBit(GPIOD,GPIO_Pin_0,RESET);\
GPIO_WriteBit(GPIOD,GPIO_Pin_1,SET);\
}
#define ConfigMode2 {\
GPIO_WriteBit(GPIOD,GPIO_Pin_0,RESET);\
GPIO_WriteBit(GPIOD,GPIO_Pin_1,RESET);\
}
#define ConfigMode3 {\
GPIO_WriteBit(GPIOD,GPIO_Pin_0,SET);\
GPIO_WriteBit(GPIOD,GPIO_Pin_1,SET);\
}
enum
{
winit_start = 0,
winit_cmd_send = 1,
winit_delay = 2,
winit_ing = 3,
winit_ok = 4,
winit_error = 5
};
enum
{
init_start = 0,
init_cmd_send = 1,
init_delay = 2,
init_ing = 3,
init_ok = 4,
init_error = 5
};
struct WIRELESS_INIT
{
bool InitFlag;
uint32_t SendDelay;
uint32_t InitDelay;
};
#define WIRELESS_INIT_DEFAULT {\
FALSE,\
0,\
0\
}
extern struct WIRELESS_INIT wireless_init;
extern uint8_t UartRecLen;
extern uint8_t UartRecBuff[25];
extern uint8_t UartTimeOut;
void bsp_usart_init(void);
void UartTest(void);
void UsartPrint(uint8_t *data,uint32_t len);
void UartRecDeal(void);
void HostPCSend(void);
static void WirelessInit(struct WIRELESS_INIT *WirelessInitCp,uint8_t *wireless,uint8_t num);
#endif
\ No newline at end of file
/**
******************************************************************************
* @file GPIO/GPIO_Toggle/stm8l15x_conf.h
* @author MCD Application Team
* @version V1.5.1
* @date 28-June-2013
* @brief Library configuration file.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_CONF_H
#define __STM8L15x_CONF_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/* Uncomment the line below to enable peripheral header file inclusion */
#include "stm8l15x_adc.h"
#include "stm8l15x_aes.h"
#include "stm8l15x_beep.h"
#include "stm8l15x_clk.h"
#include "stm8l15x_comp.h"
#include "stm8l15x_dac.h"
#include "stm8l15x_dma.h"
#include "stm8l15x_exti.h"
#include "stm8l15x_flash.h"
#include "stm8l15x_gpio.h"
#include "stm8l15x_i2c.h"
#include "stm8l15x_irtim.h"
#include "stm8l15x_itc.h"
#include "stm8l15x_iwdg.h"
#include "stm8l15x_lcd.h"
#include "stm8l15x_pwr.h"
#include "stm8l15x_rst.h"
#include "stm8l15x_rtc.h"
#include "stm8l15x_spi.h"
#include "stm8l15x_syscfg.h"
#include "stm8l15x_tim1.h"
#include "stm8l15x_tim2.h"
#include "stm8l15x_tim3.h"
#include "stm8l15x_tim4.h"
#include "stm8l15x_tim5.h"
#include "stm8l15x_usart.h"
#include "stm8l15x_wfe.h"
#include "stm8l15x_wwdg.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Uncomment the line below to expanse the "assert_param" macro in the
Standard Peripheral Library drivers code */
//#define USE_FULL_ASSERT (1) //LYQ20180624
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval : None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
#endif /* __STM8L15x_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#ifndef __STM8L15x_IT_H
#define __STM8L15x_IT_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
//extern unsigned int ADCdata;
extern u8 RecNum; //接收计数
extern u8 RecBuffer[25];
//extern u8 THR_TIME;
//extern u8 ALARM_BIT; //=1,在立起来时,没有到位
//extern u8 AUX_BIT_SET;
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
#ifdef _COSMIC_
void _stext(void); /* RESET startup routine */
INTERRUPT void NonHandledInterrupt(void);
#endif /* _COSMIC_ */
#ifndef _RAISONANCE_
INTERRUPT void TRAP_IRQHandler(void); /* TRAP */
INTERRUPT void FLASH_IRQHandler(void); /* FLASH EOP/PG_DIS */
INTERRUPT void DMA1_CHANNEL0_1_IRQHandler(void); /* DMA1 Channel0/1*/
INTERRUPT void DMA1_CHANNEL2_3_IRQHandler(void); /*DMA1 Channel2/3*/
INTERRUPT void RTC_CSSLSE_IRQHandler(void); /* RTC /CSS_LSE */
INTERRUPT void EXTIE_F_PVD_IRQHandler(void); /*EXTI PORTE/EXTI PORTF/PVD*/
INTERRUPT void EXTIB_G_IRQHandler(void); /* EXTI PORTB / EXTI PORTG */
INTERRUPT void EXTID_H_IRQHandler(void); /* EXTI PORTD / EXTI PORTH*/
INTERRUPT void EXTI0_IRQHandler(void); /* EXTI PIN0 */
INTERRUPT void EXTI1_IRQHandler(void); /* EXTI PIN1 */
INTERRUPT void EXTI2_IRQHandler(void); /* EXTI PIN2 */
INTERRUPT void EXTI3_IRQHandler(void); /* EXTI PIN3 */
INTERRUPT void EXTI4_IRQHandler(void); /* EXTI PIN4 */
INTERRUPT void EXTI5_IRQHandler(void); /* EXTI PIN5 */
INTERRUPT void EXTI6_IRQHandler(void); /* EXTI PIN6 */
INTERRUPT void EXTI7_IRQHandler(void); /* EXTI PIN7 */
INTERRUPT void LCD_AES_IRQHandler(void); /* LCD /AES */
INTERRUPT void SWITCH_CSS_BREAK_DAC_IRQHandler(void); /* Switch CLK/CSS/TIM1 Break/DAC */
INTERRUPT void ADC1_COMP_IRQHandler(void); /*ADC1/COMP*/
INTERRUPT void TIM2_UPD_OVF_TRG_BRK_USART2_TX_IRQHandler(void); /* TIM2 UPD/OVF/TRG/BRK / USART2 TX */
INTERRUPT void TIM2_CC_USART2_RX_IRQHandler(void); /* TIM2 CAP / USART2 RX */
INTERRUPT void TIM3_UPD_OVF_TRG_BRK_USART3_TX_IRQHandler(void); /* TIM3 UPD/OVF/TRG/BRK /USART3 TX*/
INTERRUPT void TIM3_CC_USART3_RX_IRQHandler(void); /* TIM3 CAP/ USART3 RX */
INTERRUPT void TIM1_UPD_OVF_TRG_COM_IRQHandler(void);/* TIM1 UPD/OVF/TRG/COM */
INTERRUPT void TIM1_CC_IRQHandler(void);/* TIM1 CAP*/
INTERRUPT void TIM4_UPD_OVF_TRG_IRQHandler(void); /* TIM4 UPD/OVF/TRI */
INTERRUPT void SPI1_IRQHandler(void); /* SPI1 */
INTERRUPT void USART1_TX_TIM5_UPD_OVF_TRG_BRK_IRQHandler(void); /* USART1 TX / TIM5 UPD/OVF/TRG/BRK */
INTERRUPT void USART1_RX_TIM5_CC_IRQHandler(void); /* USART1 RX / TIM5 CAP */
INTERRUPT void I2C1_SPI2_IRQHandler(void); /* I2C1 / SPI2 */
#endif /* _RAISONANCE_ */
#endif /* __STM8L15x_IT_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
********************************************************************************
* @file stm8l15x_aes.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the AES firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_AES_H
#define __STM8L15x_AES_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup AES
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup AES_Exported_Types
* @{
*/
/** @defgroup AES_Operation_Mode
* @{
*/
typedef enum
{
AES_Operation_Encryp = (uint8_t)0x00, /*!< AES in Encryption mode */
AES_Operation_KeyDeriv = (uint8_t)0x02, /*!< AES in Key Derivation mode */
AES_Operation_Decryp = (uint8_t)0x04, /*!< AES in Decryption mode */
AES_Operation_KeyDerivAndDecryp = (uint8_t)0x06 /*!< AES in Key Derivation and Decryption mode */
} AES_Operation_TypeDef;
#define IS_AES_MODE(Operation) (((Operation) == AES_Operation_Encryp) || \
((Operation) == AES_Operation_KeyDeriv) || \
((Operation) == AES_Operation_Decryp) || \
((Operation) == AES_Operation_KeyDerivAndDecryp))
/**
* @}
*/
/** @defgroup AES_Flags
* @{
*/
typedef enum
{
AES_FLAG_CCF = (uint8_t)0x01, /*!< Computation Complete Flag */
AES_FLAG_RDERR = (uint8_t)0x02, /*!< Read Error Flag */
AES_FLAG_WRERR = (uint8_t)0x04 /*!< Write Error Flag */
}AES_FLAG_TypeDef;
#define IS_AES_FLAG(Flag) (((Flag) == AES_FLAG_CCF) || \
((Flag) == AES_FLAG_RDERR) || \
((Flag) == AES_FLAG_WRERR))
/**
* @}
*/
/** @defgroup AES_Interrupts
* @{
*/
typedef enum
{
AES_IT_CCIE = (uint16_t)0x20, /*!< Computation Complete interrupt enable */
AES_IT_ERRIE = (uint16_t)0x40 /*!< Error interrupt enable */
}AES_IT_TypeDef;
#define IS_AES_IT(IT) (((IT) == AES_IT_CCIE) || \
((IT) == AES_IT_ERRIE))
/**
* @}
*/
/** @defgroup AES_DMA_Transfer_Direction
* @{
*/
typedef enum
{
AES_DMATransfer_InOut = (uint8_t) 0x80 /*!< DMA requests enabled for input transfer phase
as well as for the output transfer phase */
}
AES_DMATransfer_TypeDef;
#define IS_AES_DMATRANSFER(Transfer) ((Transfer) == AES_DMATransfer_InOut)
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* Function used to set the AES configuration to the default reset state *****/
void AES_DeInit(void);
/* AES Configuration **********************************************************/
void AES_OperationModeConfig(AES_Operation_TypeDef AES_Operation);
void AES_Cmd(FunctionalState NewState);
/* AES Read and Write operations **********************************************/
void AES_WriteSubData(uint8_t Data);
void AES_WriteSubKey(uint8_t Key);
uint8_t AES_ReadSubData(void);
uint8_t AES_ReadSubKey(void);
/* DMA transfers management function ******************************************/
void AES_DMAConfig(AES_DMATransfer_TypeDef AES_DMATransfer, FunctionalState NewState);
/* Interrupts and flags management functions **********************************/
void AES_ITConfig(AES_IT_TypeDef AES_IT, FunctionalState NewState);
FlagStatus AES_GetFlagStatus(AES_FLAG_TypeDef AES_FLAG);
void AES_ClearFlag(AES_FLAG_TypeDef AES_FLAG);
ITStatus AES_GetITStatus(AES_IT_TypeDef AES_IT);
void AES_ClearITPendingBit(AES_IT_TypeDef AES_IT);
#endif /* __STM8L15x_AES_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_beep.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the BEEP firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_BEEP_H
#define __STM8L15x_BEEP_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup BEEP
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup BEEP_Exported_Types
* @{
*/
/** @defgroup BEEP_Frequency
* @{
*/
typedef enum {
BEEP_Frequency_1KHz = (uint8_t)0x00, /*!< Beep signal output frequency 1 KHz */
BEEP_Frequency_2KHz = (uint8_t)0x40, /*!< Beep signal output frequency 2 KHz */
BEEP_Frequency_4KHz = (uint8_t)0x80 /*!< Beep signal output frequency 4 KHz */
} BEEP_Frequency_TypeDef;
#define IS_BEEP_FREQUENCY(FREQ) (((FREQ) == BEEP_Frequency_1KHz) || \
((FREQ) == BEEP_Frequency_2KHz) || \
((FREQ) == BEEP_Frequency_4KHz))
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup BEEP_Exported_Constants
* @{
*/
#define BEEP_CALIBRATION_DEFAULT ((uint8_t)0x01) /*!< Default value when calibration is not done */
#define LSI_FREQUENCY_MIN ((uint32_t)25000) /*!< LSI minimum value in Hertz */
#define LSI_FREQUENCY_MAX ((uint32_t)75000) /*!< LSI maximum value in Hertz */
/**
* @}
*/
/* Exported macros -----------------------------------------------------------*/
/** @defgroup BEEP_Exported_Macros
* @{
*/
#define IS_LSI_FREQUENCY(FREQ) (((FREQ) >= LSI_FREQUENCY_MIN) && ((FREQ) <= LSI_FREQUENCY_MAX))
/**
* @}
*/
/* Exported functions ------------------------------------------------------- */
/* Function used to set the BEEP configuration to the default reset state *****/
void BEEP_DeInit(void);
/* Initialization and Configuration functions *********************************/
void BEEP_Init(BEEP_Frequency_TypeDef BEEP_Frequency);
void BEEP_Cmd(FunctionalState NewState);
/* Low Speed Internal Clock(LSI) Calibration functions functions **************/
void BEEP_LSClockToTIMConnectCmd(FunctionalState NewState);
void BEEP_LSICalibrationConfig(uint32_t LSIFreqHz);
#endif /* __STM8L15x_BEEP_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_comp.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the COMP firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_COMP_H
#define __STM8L15x_COMP_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup COMP
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup COMP_Exported_Types
* @{
*/
/** @defgroup COMP_Selection
* @{
*/
typedef enum
{
COMP_Selection_COMP1 = ((uint8_t)0x01), /*!< Selection of Comparator 1. */
COMP_Selection_COMP2 = ((uint8_t)0x02) /*!< Selection of Comparator 2. */
}COMP_Selection_TypeDef;
#define IS_COMP_ALL_PERIPH(PERIPH) (((PERIPH) == COMP_Selection_COMP1) || \
((PERIPH) == COMP_Selection_COMP2))
/**
* @}
*/
/** @defgroup COMP_Edge
* @{
*/
typedef enum
{
COMP_Edge_Falling = ((uint8_t)0x01), /*!< Falling edge selection. */
COMP_Edge_Rising = ((uint8_t)0x02), /*!< Rising edge selection. */
COMP_Edge_Rising_Falling = ((uint8_t)0x03) /*!< Rising and Falling edge selection. */
}COMP_Edge_TypeDef;
#define IS_COMP_EDGE(EDGE) (((EDGE) == COMP_Edge_Falling) || \
((EDGE) == COMP_Edge_Rising) || \
((EDGE) == COMP_Edge_Rising_Falling))
/**
* @}
*/
/** @defgroup COMP_Inverting_Input_Selection
* @{
*/
typedef enum
{
COMP_InvertingInput_IO = ((uint8_t)0x08), /*!< Input/Output on comparator inverting input enable.*/
COMP_InvertingInput_VREFINT = ((uint8_t)0x10), /*!< VREFINT on comparator inverting input enable. */
COMP_InvertingInput_3_4VREFINT = ((uint8_t)0x18), /*!< 3/4 VREFINT on comparator inverting input enable. */
COMP_InvertingInput_1_2VREFINT = ((uint8_t)0x20), /*!< 1/2 VREFINT on comparator inverting input enable. */
COMP_InvertingInput_1_4VREFINT = ((uint8_t)0x28), /*!< 1/4 VREFINT on comparator inverting input enable. */
COMP_InvertingInput_DAC1 = ((uint8_t)0x30), /*!< DAC1 output on comparator inverting input enable. */
COMP_InvertingInput_DAC2 = ((uint8_t)0x38) /*!< DAC2 output on comparator inverting input enable. */
}COMP_InvertingInput_Typedef;
#define IS_COMP_INVERTING_INPUT(INPUT) (((INPUT) == COMP_InvertingInput_IO) || \
((INPUT) == COMP_InvertingInput_VREFINT) || \
((INPUT) == COMP_InvertingInput_3_4VREFINT) || \
((INPUT) == COMP_InvertingInput_1_2VREFINT) || \
((INPUT) == COMP_InvertingInput_1_4VREFINT) || \
((INPUT) == COMP_InvertingInput_DAC1) || \
((INPUT) == COMP_InvertingInput_DAC2))
/**
* @}
*/
/** @defgroup COMP2_Output_Selection
* @{
*/
typedef enum
{
COMP_OutputSelect_TIM2IC2 = ((uint8_t)0x00), /*!< COMP2 output connected to TIM2 Input Capture 2 */
COMP_OutputSelect_TIM3IC2 = ((uint8_t)0x40), /*!< COMP2 output connected to TIM3 Input Capture 2 */
COMP_OutputSelect_TIM1BRK = ((uint8_t)0x80), /*!< COMP2 output connected to TIM1 Break Input */
COMP_OutputSelect_TIM1OCREFCLR = ((uint8_t)0xC0) /*!< COMP2 output connected to TIM1 OCREF Clear */
}COMP_OutputSelect_Typedef;
#define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OutputSelect_TIM2IC2) || \
((OUTPUT) == COMP_OutputSelect_TIM3IC2) || \
((OUTPUT) == COMP_OutputSelect_TIM1BRK) || \
((OUTPUT) == COMP_OutputSelect_TIM1OCREFCLR))
/**
* @}
*/
/** @defgroup COMP_Speed
* @{
*/
typedef enum
{
COMP_Speed_Slow = ((uint8_t)0x00), /*!< Comparator speed: slow */
COMP_Speed_Fast = ((uint8_t)0x04) /*!< Comparator speed: fast */
}COMP_Speed_TypeDef;
#define IS_COMP_SPEED(SPEED) (((SPEED) == COMP_Speed_Slow) || \
((SPEED) == COMP_Speed_Fast))
/**
* @}
*/
/** @defgroup COMP_Trigger_Group
* @{
*/
typedef enum
{
COMP_TriggerGroup_InvertingInput = ((uint8_t)0x01), /*!< Trigger on comparator 2 inverting input */
COMP_TriggerGroup_NonInvertingInput = ((uint8_t)0x02), /*!< Trigger on comparator 2 non inverting input */
COMP_TriggerGroup_VREFINTOutput = ((uint8_t)0x03), /*!< Trigger on VREFINT output */
COMP_TriggerGroup_DACOutput = ((uint8_t)0x04) /*!< Trigger on DAC output */
}COMP_TriggerGroup_TypeDef;
#define IS_COMP_TRIGGERGROUP(TRIGGERGROUP) (((TRIGGERGROUP) == COMP_TriggerGroup_NonInvertingInput) || \
((TRIGGERGROUP) == COMP_TriggerGroup_InvertingInput) || \
((TRIGGERGROUP) == COMP_TriggerGroup_VREFINTOutput) || \
((TRIGGERGROUP) == COMP_TriggerGroup_DACOutput)
/**
* @}
*/
/** @defgroup COMP_Trigger_Pin
* @{
*/
typedef enum
{
COMP_TriggerPin_0 = ((uint8_t)0x01), /*!< PE5 for the non inverting input Trigger Group
PC3 for the inverting input Trigger Group
PB6 for the DAC output Trigger Group
PC2 for the VREFINT output Trigger Group
*/
COMP_TriggerPin_1 = ((uint8_t)0x02), /*!< PD0 for the non inverting input Trigger Group
PC4 for the inverting input Trigger Group
PB5 for the DAC output Trigger Group
PD7 for the VREFINT output Trigger Group
*/
COMP_TriggerPin_2 = ((uint8_t)0x04) /*!< PD1 for the non inverting input Trigger Group
PC7 for the inverting input Trigger Group
PB4 for the DAC output Trigger Group
PD6 for the VREFINT output Trigger Group */
}COMP_TriggerPin_TypeDef;
#define IS_COMP_TRIGGERPIN(TRIGGERPIN) ((((uint8_t)(TRIGGERPIN) & (uint8_t)0xF8) == (uint8_t) 0x00) && \
((TRIGGERPIN) != (uint8_t)0x00))
/**
* @}
*/
/** @defgroup COMP_Output_Level
* @{
*/
typedef enum
{
COMP_OutputLevel_Low = ((uint8_t)0x00), /*!< Comparator output level is low */
COMP_OutputLevel_High = ((uint8_t)0x01) /*!< Comparator output level is high */
}COMP_OutputLevel_TypeDef;
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/* Function used to set the CLK configuration to the default reset state ******/
void COMP_DeInit(void);
/* Initialization and Configuration functions ****************************/
void COMP_Init(COMP_InvertingInput_Typedef COMP_InvertingInput, COMP_OutputSelect_Typedef COMP_OutputSelect,
COMP_Speed_TypeDef COMP_Speed);
void COMP_VrefintToCOMP1Connect(FunctionalState NewState);
void COMP_EdgeConfig(COMP_Selection_TypeDef COMP_Selection, COMP_Edge_TypeDef COMP_Edge);
COMP_OutputLevel_TypeDef COMP_GetOutputLevel(COMP_Selection_TypeDef COMP_Selection);
/* Window mode control function ***********************************************/
void COMP_WindowCmd(FunctionalState NewState);
/* Internal Reference Voltage (VREFINT) output function ***********************/
void COMP_VrefintOutputCmd(FunctionalState NewState);
/* Comparator channels trigger configuration functions ************************/
void COMP_SchmittTriggerCmd(FunctionalState NewState);
void COMP_TriggerConfig(COMP_TriggerGroup_TypeDef COMP_TriggerGroup,
COMP_TriggerPin_TypeDef COMP_TriggerPin,
FunctionalState NewState);
/* Interrupts and flags management functions **********************************/
void COMP_ITConfig(COMP_Selection_TypeDef COMP_Selection, FunctionalState NewState);
FlagStatus COMP_GetFlagStatus(COMP_Selection_TypeDef COMP_Selection);
void COMP_ClearFlag(COMP_Selection_TypeDef COMP_Selection);
ITStatus COMP_GetITStatus(COMP_Selection_TypeDef COMP_Selection);
void COMP_ClearITPendingBit(COMP_Selection_TypeDef COMP_Selection);
/**
* @}
*/
#endif /* __STM8L15x_COMP_H */
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_exti.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the EXTI firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_EXTI_H
#define __STM8L15x_EXTI_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup EXTI
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @addtogroup EXTI_Exported_Types
* @{
*/
/** @defgroup EXTI_Trigger
* @{
*/
typedef enum
{
EXTI_Trigger_Falling_Low = (uint8_t)0x00, /*!< Interrupt on Falling edge and Low level */
EXTI_Trigger_Rising = (uint8_t)0x01, /*!< Interrupt on Rising edge only */
EXTI_Trigger_Falling = (uint8_t)0x02, /*!< Interrupt on Falling edge only */
EXTI_Trigger_Rising_Falling = (uint8_t)0x03 /*!< Interrupt on Rising and Falling edges */
} EXTI_Trigger_TypeDef;
/**
* @}
*/
/** @defgroup EXTI_Half_Port
*
* @brief EXTI halfPort possible values
* Values are coded as following:
* - Bit 7: 0 => the half port is in EXTI_CONF1 register
* 1 => the half port is in EXTI_CONF2 register
* - Bits[6:0] => the half port selection mask
* @{
*/
typedef enum
{
EXTI_HalfPort_B_LSB = (uint8_t)0x01, /*!< Interrupt selector PB(3:0) */
EXTI_HalfPort_B_MSB = (uint8_t)0x02, /*!< Interrupt selector PB(7:4) */
EXTI_HalfPort_D_LSB = (uint8_t)0x04, /*!< Interrupt selector PD(3:0) */
EXTI_HalfPort_D_MSB = (uint8_t)0x08, /*!< Interrupt selector PD(7:4) */
EXTI_HalfPort_E_LSB = (uint8_t)0x10, /*!< Interrupt selector PE(3:0) */
EXTI_HalfPort_E_MSB = (uint8_t)0x20, /*!< Interrupt selector PE(7:4) */
EXTI_HalfPort_F_LSB = (uint8_t)0x40, /*!< Interrupt selector PF(3:0) */
EXTI_HalfPort_F_MSB = (uint8_t)0x81, /*!< Interrupt selector PF(7:4) */
EXTI_HalfPort_G_LSB = (uint8_t)0x82, /*!< Interrupt selector PG(3:0) */
EXTI_HalfPort_G_MSB = (uint8_t)0x84, /*!< Interrupt selector PG(7:4) */
EXTI_HalfPort_H_LSB = (uint8_t)0x88, /*!< Interrupt selector PH(3:0) */
EXTI_HalfPort_H_MSB = (uint8_t)0x90 /*!< Interrupt selector PH(7:4) */
} EXTI_HalfPort_TypeDef;
/**
* @}
*/
/** @defgroup EXTI_Port
*
* @brief EXTI Port possible values
* Values are coded in 0xXY format where
* X: the register index
* X = 0: EXTI_CR3
* X = 1: EXTI_CR4
* Y: the number of shift to be performed
* @{
*/
typedef enum
{
EXTI_Port_B = (uint8_t)0x00, /*!< GPIO Port B */
EXTI_Port_D = (uint8_t)0x02, /*!< GPIO Port D */
EXTI_Port_E = (uint8_t)0x04, /*!< GPIO Port E */
EXTI_Port_F = (uint8_t)0x06, /*!< GPIO Port F */
EXTI_Port_G = (uint8_t)0x10, /*!< GPIO Port G */
EXTI_Port_H = (uint8_t)0x12 /*!< GPIO Port H */
} EXTI_Port_TypeDef;
/**
* @}
*/
/** @defgroup EXTI_Pin
*
* @brief EXTI PinNum possible values
* Values are coded in 0xXY format where
* X: the register index
* X = 0: EXTI_CR1
* X = 1: EXTI_CR2
* Y: the number of shift to be performed
* @{
*/
typedef enum
{
EXTI_Pin_0 = (uint8_t)0x00, /*!< GPIO Pin 0 */
EXTI_Pin_1 = (uint8_t)0x02, /*!< GPIO Pin 1 */
EXTI_Pin_2 = (uint8_t)0x04, /*!< GPIO Pin 2 */
EXTI_Pin_3 = (uint8_t)0x06, /*!< GPIO Pin 3 */
EXTI_Pin_4 = (uint8_t)0x10, /*!< GPIO Pin 4 */
EXTI_Pin_5 = (uint8_t)0x12, /*!< GPIO Pin 5 */
EXTI_Pin_6 = (uint8_t)0x14, /*!< GPIO Pin 6 */
EXTI_Pin_7 = (uint8_t)0x16 /*!< GPIO Pin 7 */
} EXTI_Pin_TypeDef;
/**
* @}
*/
/** @defgroup EXTI_Interrupts
*
* @brief EXTI IT pending bit possible values
* Values are coded in 0xXY format where
* X: the register index
* X = 00: EXTI_SR1
* X = 01: EXTI_SR2
* Y: the IT pending bit mask
* @{
*/
typedef enum
{
EXTI_IT_Pin0 = (uint16_t)0x0001, /*!< GPIO Pin pos 0 */
EXTI_IT_Pin1 = (uint16_t)0x0002, /*!< GPIO Pin pos 1 */
EXTI_IT_Pin2 = (uint16_t)0x0004, /*!< GPIO Pin pos 2 */
EXTI_IT_Pin3 = (uint16_t)0x0008, /*!< GPIO Pin pos 3 */
EXTI_IT_Pin4 = (uint16_t)0x0010, /*!< GPIO Pin pos 4 */
EXTI_IT_Pin5 = (uint16_t)0x0020, /*!< GPIO Pin pos 5 */
EXTI_IT_Pin6 = (uint16_t)0x0040, /*!< GPIO Pin pos 6 */
EXTI_IT_Pin7 = (uint16_t)0x0080, /*!< GPIO Pin pos 7 */
EXTI_IT_PortB = (uint16_t)0x0101, /*!< GPIO Port B */
EXTI_IT_PortD = (uint16_t)0x0102, /*!< GPIO Port D */
EXTI_IT_PortE = (uint16_t)0x0104, /*!< GPIO Port E */
EXTI_IT_PortF = (uint16_t)0x0108, /*!< GPIO Port F */
EXTI_IT_PortG = (uint16_t)0x0110, /*!< GPIO Port G */
EXTI_IT_PortH = (uint16_t)0x0120 /*!< GPIO Port H */
} EXTI_IT_TypeDef;
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/** @addtogroup EXTI_Exported_Macros
* @{
*/
/**
* @brief Macro used by the assert function to check the different functions parameters.
*/
/**
* @brief Macro used by the assert function in order to check the different values
* of EXTI Sensitivity
*/
#define IS_EXTI_TRIGGER(TRIGGER) \
(((TRIGGER) == EXTI_Trigger_Falling_Low) || \
((TRIGGER) == EXTI_Trigger_Rising) || \
((TRIGGER) == EXTI_Trigger_Falling) || \
((TRIGGER) == EXTI_Trigger_Rising_Falling))
/**
* @brief Macro used by the assert function in order to check the different
* half ports values for configuration.
*/
#define IS_EXTI_HALFPORT(HALFPORT) \
(((HALFPORT) == EXTI_HalfPort_B_LSB) ||\
((HALFPORT) == EXTI_HalfPort_B_MSB) ||\
((HALFPORT) == EXTI_HalfPort_D_LSB) ||\
((HALFPORT) == EXTI_HalfPort_D_MSB) ||\
((HALFPORT) == EXTI_HalfPort_E_LSB) ||\
((HALFPORT) == EXTI_HalfPort_E_MSB) ||\
((HALFPORT) == EXTI_HalfPort_F_LSB) ||\
((HALFPORT) == EXTI_HalfPort_F_MSB) ||\
((HALFPORT) == EXTI_HalfPort_G_LSB) ||\
((HALFPORT) == EXTI_HalfPort_G_MSB) ||\
((HALFPORT) == EXTI_HalfPort_H_LSB) ||\
((HALFPORT) == EXTI_HalfPort_H_MSB))
/**
* @brief Macro used by the assert function in order to check the different Port Number values
*/
#define IS_EXTI_PORT(PORT) (((PORT) == EXTI_Port_B) ||\
((PORT) == EXTI_Port_D) ||\
((PORT) == EXTI_Port_E) ||\
((PORT) == EXTI_Port_F) ||\
((PORT) == EXTI_Port_G) ||\
((PORT) == EXTI_Port_H))
/**
* @brief Macro used by the assert function in order to check the different Pin numbers values
*/
#define IS_EXTI_PINNUM(PINNUM) \
(((PINNUM) == EXTI_Pin_0) ||\
((PINNUM) == EXTI_Pin_1) ||\
((PINNUM) == EXTI_Pin_2) ||\
((PINNUM) == EXTI_Pin_3) ||\
((PINNUM) == EXTI_Pin_4) ||\
((PINNUM) == EXTI_Pin_5) ||\
((PINNUM) == EXTI_Pin_6) ||\
((PINNUM) == EXTI_Pin_7))
/**
* @brief Macro used by the assert function in order to check the different flags values
*/
#define IS_EXTI_ITPENDINGBIT(ITPENDINGBIT) \
(((ITPENDINGBIT) == EXTI_IT_Pin0) ||\
((ITPENDINGBIT) == EXTI_IT_Pin1) ||\
((ITPENDINGBIT) == EXTI_IT_Pin2) ||\
((ITPENDINGBIT) == EXTI_IT_Pin3) ||\
((ITPENDINGBIT) == EXTI_IT_Pin4) ||\
((ITPENDINGBIT) == EXTI_IT_Pin5) ||\
((ITPENDINGBIT) == EXTI_IT_Pin6) ||\
((ITPENDINGBIT) == EXTI_IT_Pin7) ||\
((ITPENDINGBIT) == EXTI_IT_PortB) ||\
((ITPENDINGBIT) == EXTI_IT_PortD) ||\
((ITPENDINGBIT) == EXTI_IT_PortE) ||\
((ITPENDINGBIT) == EXTI_IT_PortF) ||\
((ITPENDINGBIT) == EXTI_IT_PortG) ||\
((ITPENDINGBIT) == EXTI_IT_PortH))
/**
* @}
*/
/* Exported functions ------------------------------------------------------- */
/* EXTI configuration *********************************************************/
void EXTI_DeInit(void);
void EXTI_SetPinSensitivity(EXTI_Pin_TypeDef EXTI_Pin, EXTI_Trigger_TypeDef EXTI_Trigger);
void EXTI_SelectPort(EXTI_Port_TypeDef EXTI_Port);
void EXTI_SetHalfPortSelection(EXTI_HalfPort_TypeDef EXTI_HalfPort, FunctionalState NewState);
void EXTI_SetPortSensitivity(EXTI_Port_TypeDef EXTI_Port, EXTI_Trigger_TypeDef EXTI_Trigger);
EXTI_Trigger_TypeDef EXTI_GetPinSensitivity(EXTI_Pin_TypeDef EXTI_Pin);
EXTI_Trigger_TypeDef EXTI_GetPortSensitivity(EXTI_Port_TypeDef EXTI_Port);
/* EXTI Interrupt status management *******************************************/
ITStatus EXTI_GetITStatus(EXTI_IT_TypeDef EXTI_IT);
void EXTI_ClearITPendingBit(EXTI_IT_TypeDef EXTI_IT);
#endif /* __STM8L15x_EXTI_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_gpio.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the GPIO firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_GPIO_H
#define __STM8L15x_GPIO_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup I2C
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @addtogroup GPIO_Exported_Types
* @{
*/
/**
* @defgroup GPIO_Modes
*
* @brief
*
* Bits definitions:
* - Bit 7: 0 = INPUT mode
* 1 = OUTPUT mode
* 1 = PULL-UP (input) or PUSH-PULL (output)
* - Bit 5: 0 = No external interrupt (input) or No slope control (output)
* 1 = External interrupt (input) or Slow control enabled (output)
* - Bit 4: 0 = Low level (output)
* 1 = High level (output push-pull) or HI-Z (output open-drain)
* @{
*/
typedef enum
{
GPIO_Mode_In_FL_No_IT = (uint8_t)0x00, /*!< Input floating, no external interrupt */
GPIO_Mode_In_PU_No_IT = (uint8_t)0x40, /*!< Input pull-up, no external interrupt */
GPIO_Mode_In_FL_IT = (uint8_t)0x20, /*!< Input floating, external interrupt */
GPIO_Mode_In_PU_IT = (uint8_t)0x60, /*!< Input pull-up, external interrupt */
GPIO_Mode_Out_OD_Low_Fast = (uint8_t)0xA0, /*!< Output open-drain, low level, 10MHz */
GPIO_Mode_Out_PP_Low_Fast = (uint8_t)0xE0, /*!< Output push-pull, low level, 10MHz */
GPIO_Mode_Out_OD_Low_Slow = (uint8_t)0x80, /*!< Output open-drain, low level, 2MHz */
GPIO_Mode_Out_PP_Low_Slow = (uint8_t)0xC0, /*!< Output push-pull, low level, 2MHz */
GPIO_Mode_Out_OD_HiZ_Fast = (uint8_t)0xB0, /*!< Output open-drain, high-impedance level, 10MHz */
GPIO_Mode_Out_PP_High_Fast = (uint8_t)0xF0, /*!< Output push-pull, high level, 10MHz */
GPIO_Mode_Out_OD_HiZ_Slow = (uint8_t)0x90, /*!< Output open-drain, high-impedance level, 2MHz */
GPIO_Mode_Out_PP_High_Slow = (uint8_t)0xD0 /*!< Output push-pull, high level, 2MHz */
}GPIO_Mode_TypeDef;
/**
* @}
*/
/** @defgroup GPIO_Pin
* @{
*/
typedef enum
{
GPIO_Pin_0 = ((uint8_t)0x01), /*!< Pin 0 selected */
GPIO_Pin_1 = ((uint8_t)0x02), /*!< Pin 1 selected */
GPIO_Pin_2 = ((uint8_t)0x04), /*!< Pin 2 selected */
GPIO_Pin_3 = ((uint8_t)0x08), /*!< Pin 3 selected */
GPIO_Pin_4 = ((uint8_t)0x10), /*!< Pin 4 selected */
GPIO_Pin_5 = ((uint8_t)0x20), /*!< Pin 5 selected */
GPIO_Pin_6 = ((uint8_t)0x40), /*!< Pin 6 selected */
GPIO_Pin_7 = ((uint8_t)0x80), /*!< Pin 7 selected */
GPIO_Pin_LNib = ((uint8_t)0x0F), /*!< Low nibble pins selected */
GPIO_Pin_HNib = ((uint8_t)0xF0), /*!< High nibble pins selected */
GPIO_Pin_All = ((uint8_t)0xFF) /*!< All pins selected */
}GPIO_Pin_TypeDef;
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/** @addtogroup GPIO_Exported_Macros
* @{
*/
/**
* @brief Macro used by the assert function to check the different functions parameters.
*/
/**
* @brief Macro used by the assert function in order to check the different
* values of GPIOMode_TypeDef.
*/
#define IS_GPIO_MODE(MODE) \
(((MODE) == GPIO_Mode_In_FL_No_IT) || \
((MODE) == GPIO_Mode_In_PU_No_IT) || \
((MODE) == GPIO_Mode_In_FL_IT) || \
((MODE) == GPIO_Mode_In_PU_IT) || \
((MODE) == GPIO_Mode_Out_OD_Low_Fast) || \
((MODE) == GPIO_Mode_Out_PP_Low_Fast) || \
((MODE) == GPIO_Mode_Out_OD_Low_Slow) || \
((MODE) == GPIO_Mode_Out_PP_Low_Slow) || \
((MODE) == GPIO_Mode_Out_OD_HiZ_Fast) || \
((MODE) == GPIO_Mode_Out_PP_High_Fast) || \
((MODE) == GPIO_Mode_Out_OD_HiZ_Slow) || \
((MODE) == GPIO_Mode_Out_PP_High_Slow))
/**
* @brief Macro used by the assert function in order to check the different
* values of GPIO_Pins.
*/
#define IS_GPIO_PIN(PIN) ((PIN) != (uint8_t)0x00)
/**
* @}
*/
/* Exported functions ------------------------------------------------------- */
/* Initialization and Configuration *******************************************/
void GPIO_DeInit(GPIO_TypeDef* GPIOx);
void GPIO_Init(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode);
void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin, FunctionalState NewState);
/* GPIO Read and Write ********************************************************/
void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t GPIO_PortVal);
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal);
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin);
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin);
void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin);
uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
BitStatus GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
BitStatus GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);
#endif /* __STM8L15x_GPIO_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_irtim.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the IRTIM firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_IRTIM_H
#define __STM8L15x_IRTIM_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup IRTIM
* @{
*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/* IRTIM configuration ********************************************************/
void IRTIM_DeInit(void);
void IRTIM_Cmd(FunctionalState NewState);
void IRTIM_HighSinkODCmd(FunctionalState NewState);
/* IRITM status management ****************************************************/
FunctionalState IRTIM_GetStatus(void);
FunctionalState IRTIM_GetHighSinkODStatus(void);
/**
* @}
*/
#endif /* __STM8L15x_IRTIM_H */
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/*******************************************************************************
* @file stm8l15x_iwdg.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the IWDG
* firmware library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_IWDG_H
#define __STM8L15x_IWDG_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup IWDG
* @{
*/
/* Exported variables ------------------------------------------------------- */
/* Exported constants --------------------------------------------------------*/
/** @defgroup IWDG_Exported_Constants
* @{
*/
/** @defgroup IWDG_KeyRefresh
* @{
*/
#define IWDG_KEY_REFRESH ((uint8_t)0xAA) /*!< This value written in the Key
register prevent the watchdog reset */
/**
* @}
*/
/** @defgroup IWDG_KeyEnable
* @{
*/
#define IWDG_KEY_ENABLE ((uint8_t)0xCC) /*!< This value written in the Key
register start the watchdog counting down*/
/**
* @}
*/
/**
* @}
*/
/* Exported macros -----------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup IWDG_Exported_Types
* @{
*/
/** @defgroup IWDG_WriteAccess
* @{
*/
typedef enum
{
IWDG_WriteAccess_Enable = (uint8_t)0x55,
IWDG_WriteAccess_Disable = (uint8_t)0x00
} IWDG_WriteAccess_TypeDef;
#define IS_IWDG_WRITE_ACCESS_MODE(MODE) (((MODE) == IWDG_WriteAccess_Enable) || \
((MODE) == IWDG_WriteAccess_Disable))
/**
* @}
*/
/** @defgroup IWDG_prescaler
* @{
*/
typedef enum
{
IWDG_Prescaler_4 = (uint8_t)0x00, /*!< Used to set prescaler register to 4 */
IWDG_Prescaler_8 = (uint8_t)0x01, /*!< Used to set prescaler register to 8 */
IWDG_Prescaler_16 = (uint8_t)0x02, /*!< Used to set prescaler register to 16 */
IWDG_Prescaler_32 = (uint8_t)0x03, /*!< Used to set prescaler register to 32 */
IWDG_Prescaler_64 = (uint8_t)0x04, /*!< Used to set prescaler register to 64 */
IWDG_Prescaler_128 = (uint8_t)0x05, /*!< Used to set prescaler register to 128 */
IWDG_Prescaler_256 = (uint8_t)0x06 /*!< Used to set prescaler register to 256 */
} IWDG_Prescaler_TypeDef;
#define IS_IWDG_PRESCALER_VALUE(VALUE) (((VALUE) == IWDG_Prescaler_4) || \
((VALUE) == IWDG_Prescaler_8) || \
((VALUE) == IWDG_Prescaler_16) || \
((VALUE) == IWDG_Prescaler_32) || \
((VALUE) == IWDG_Prescaler_64) || \
((VALUE) == IWDG_Prescaler_128) || \
((VALUE) == IWDG_Prescaler_256))
/**
* @}
*/
/**
* @}
*/
/* Exported functions ------------------------------------------------------- */
/* Prescaler and Counter configuration functions ******************************/
void IWDG_WriteAccessCmd(IWDG_WriteAccess_TypeDef IWDG_WriteAccess);
void IWDG_SetPrescaler(IWDG_Prescaler_TypeDef IWDG_Prescaler);
void IWDG_SetReload(uint8_t IWDG_Reload);
void IWDG_ReloadCounter(void);
/* IWDG activation function ***************************************************/
void IWDG_Enable(void);
#endif /* __STM8L15x_IWDG_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_pwr.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the PWR firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_PWR_H
#define __STM8L15x_PWR_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup PWR
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup PWR_Exported_Types
* @{
*/
/** @defgroup PVD_detection_level
* @{
*/
typedef enum {
PWR_PVDLevel_1V85 = (uint8_t)0x00, /*!< PVD threshold = 1.85 V */
PWR_PVDLevel_2V05 = (uint8_t)0x02, /*!< PVD threshold = 2.05 V */
PWR_PVDLevel_2V26 = (uint8_t)0x04, /*!< PVD threshold = 2.26 V */
PWR_PVDLevel_2V45 = (uint8_t)0x06, /*!< PVD threshold = 2.45 V */
PWR_PVDLevel_2V65 = (uint8_t)0x08, /*!< PVD threshold = 2.65 V */
PWR_PVDLevel_2V85 = (uint8_t)0x0A, /*!< PVD threshold = 2.85 V */
PWR_PVDLevel_3V05 = (uint8_t)0x0C, /*!< PVD threshold = 3.05 V */
PWR_PVDLevel_PVDIn = (uint8_t)0x0E /*!< PVD threshold = PVD_IN input pin */
} PWR_PVDLevel_TypeDef;
#define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_1V85) || \
((LEVEL) == PWR_PVDLevel_2V05) || \
((LEVEL) == PWR_PVDLevel_2V26) || \
((LEVEL) == PWR_PVDLevel_2V45) || \
((LEVEL) == PWR_PVDLevel_2V65) || \
((LEVEL) == PWR_PVDLevel_2V85) || \
((LEVEL) == PWR_PVDLevel_3V05) || \
((LEVEL) == PWR_PVDLevel_PVDIn))
/**
* @}
*/
/** @defgroup PWR_Flag
* @{
*/
typedef enum {
PWR_FLAG_PVDOF = (uint8_t)0x40,/*!< PVD output flag */
PWR_FLAG_PVDIF = (uint8_t)0x20, /*!< PVD Interrupt flag */
PWR_FLAG_VREFINTF = (uint8_t)0x01 /*!< Internal reference voltage status flag */
} PWR_FLAG_TypeDef;
#define IS_PWR_FLAG(FLAG) (((FLAG) == PWR_FLAG_PVDOF) || \
((FLAG) == PWR_FLAG_PVDIF) || \
((FLAG) == PWR_FLAG_VREFINTF))
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* Function used to set the PWR configuration to the default reset state ******/
void PWR_DeInit(void);
/* PVD configuration functions ************************************************/
void PWR_PVDLevelConfig(PWR_PVDLevel_TypeDef PWR_PVDLevel);
void PWR_PVDCmd(FunctionalState NewState);
/* Ultra Low Power mode configuration functions *******************************/
void PWR_FastWakeUpCmd(FunctionalState NewState);
void PWR_UltraLowPowerCmd(FunctionalState NewState);
/* Interrupts and flags management functions **********************************/
void PWR_PVDITConfig(FunctionalState NewState);
ITStatus PWR_PVDGetITStatus(void);
FlagStatus PWR_GetFlagStatus(PWR_FLAG_TypeDef PWR_FLAG);
void PWR_PVDClearFlag(void);
void PWR_PVDClearITPendingBit(void);
#endif /* __STM8L15x_PWR_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file stm8l15x_rst.h
* @author MCD Application Team
* @version V1.6.0
* @date 28-June-2013
* @brief This file contains all the functions prototypes for the RST firmware
* library.
******************************************************************************
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_RST_H
#define __STM8L15x_RST_H
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
/** @addtogroup STM8L15x_StdPeriph_Driver
* @{
*/
/** @addtogroup RST
* @{
*/
/* Exported variables ------------------------------------------------------- */
/* Exported types ------------------------------------------------------------*/
/** @defgroup RST_Exported_Types
* @{
*/
/** @defgroup RST_Flags
* @{
*/
typedef enum {
RST_FLAG_PORF = (uint8_t)0x01, /*!< POR reset flag */
RST_FLAG_SWIMF = (uint8_t)0x08, /*!< SWIM reset flag */
RST_FLAG_ILLOPF = (uint8_t)0x04, /*!< Illegal opcode reset flag */
RST_FLAG_IWDGF = (uint8_t)0x02, /*!< Independent watchdog reset flag */
RST_FLAG_WWDGF = (uint8_t)0x10, /*!< Window watchdog reset flag */
RST_FLAG_BORF = (uint8_t)0x20 /*!< BOR reset flag */
} RST_FLAG_TypeDef;
#define IS_RST_FLAG(FLAG) (((FLAG) == RST_FLAG_PORF) || ((FLAG) == RST_FLAG_BORF) || \
((FLAG) == RST_FLAG_IWDGF) || ((FLAG) == RST_FLAG_ILLOPF) || \
((FLAG) == RST_FLAG_WWDGF) || ((FLAG) == RST_FLAG_SWIMF))
/**
* @}
*/
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
/* Flag management functions **************************************************/
FlagStatus RST_GetFlagStatus(RST_FLAG_TypeDef RST_Flag);
void RST_ClearFlag(RST_FLAG_TypeDef RST_Flag);
/* NRST Pin configuration function ********************************************/
void RST_GPOutputEnable(void);
#endif /* __STM8L15x_RST_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment