[X9D] Makefile option added: CPUARM

[Sky9x] GVARS Bug in EEPROM
[Sky9x] Mu-law codec added
This commit is contained in:
bsongis
2012-12-10 21:00:02 +00:00
parent 2037f0d8b0
commit 5a2d6cb250
49 changed files with 11057 additions and 361 deletions
+105
View File
@@ -0,0 +1,105 @@
/**
******************************************************************************
* @file Project/Audio/Audio.c
* @author X9D Application Team
* @version V 0.2
* @date 12-JULY-2012
* @brief This file provides drivers foe Audio module.I2S AND GPIO Included.
******************************************************************************
*/
#include "stm32f2xx.h"
#include "Audio.h"
#include "hal.h"
static
void Audio_GPIO_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* EnableI2C GPIO clocks */
RCC_AHB1PeriphClockCmd(CODEC_I2S_GPIO_CLOCK, ENABLE);//GPIOA C
/* CODEC_I2S pins configuration: WS, SCK and SD pins -----------------------------*/
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(CODEC_I2S_WS_GPIO, &GPIO_InitStructure);
/* Connect pins to I2S peripheral */
GPIO_PinAFConfig(CODEC_I2S_WS_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF);
#ifdef CODEC_MCLK_ENABLED
/* CODEC_I2S pins configuration: MCK pin */
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure);
/* Connect pins to I2S peripheral */
GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF);
#endif /* CODEC_MCLK_ENABLED */
/*CODEC_I2S_MUTE & CODEC_I2S_FLT GPIO CONFIG*/
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MUTE;// | CODEC_I2S_FLT;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
GPIO_SetBits(CODEC_I2S_GPIO,CODEC_I2S_MUTE);
// GPIO_SetBits(CODEC_I2S_CTL_GPIO,CODEC_I2S_FLT);
}
void I2S2_Init()
{
I2S_InitTypeDef I2S_InitStructure;
Audio_GPIO_Init();
/*CONFIG the I2S_RCC ,MUST before enabling the I2S APB clock*/
//PLLI2SN 302,PLLI2SR 2,I2SDIV 53,I2SODD 1,FS 44.1KHZ,16bit,Error 0.0011%
RCC_PLLI2SConfig(302,2);
RCC_PLLI2SCmd(ENABLE);
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
/* Enable the CODEC_I2S peripheral clock */
RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
/* CODEC_I2S peripheral configuration */
SPI_I2S_DeInit(CODEC_I2S);
I2S_InitStructure.I2S_AudioFreq = AudioFreq;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;//clk 0 when idle state
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
#ifdef CODEC_MCLK_ENABLED
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
#elif defined(CODEC_MCLK_DISABLED)
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
#else
#error "No selection for the MCLK output has been defined !"
#endif /* CODEC_MCLK_ENABLED */
/* Initialize the I2S peripheral with the structure above */
I2S_Init(CODEC_I2S, &I2S_InitStructure);
I2S_Cmd(CODEC_I2S,ENABLE);
//interrupt
#ifdef CODEC_USE_INT
SPI_I2S_ITConfig(CODEC_I2S,SPI_I2S_IT_TXE,ENABLE);
#elif defined(CODEC_USE_DMA)
#error "DMA is not initialized"
#endif
}
+28
View File
@@ -0,0 +1,28 @@
/**
******************************************************************************
* @file Project/Audio/Audio.h
* @author X9D Application Team
* @version V 0.2
* @date 12-JULY-2011
* @brief Header for Audio.c.
******************************************************************************
*/
#ifndef _AUDIO_H_
#define _AUDIO_H_
#include "stdint.h"
#include "Macro_define.h"
extern const uint16_t AUDIO_SAMPLE[];
//
void I2S2_Init();
typedef struct{
uint32_t size; //number of chars per font
uint16_t *base; //font addr
}A_SAMPLE;
extern A_SAMPLE demo_sample;
#endif
+27
View File
@@ -0,0 +1,27 @@
/**
******************************************************************************
* @file Project/Macro_define.h
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief This file provides Macro defines for testing or working.
* *
******************************************************************************
*/
#ifndef _Macro_Define_H_
#define _Macro_Define_H_
#include "stm32f2xx.h"
#define assert(x) do{ if(!(x)) while(1);}while(0);
#define udelay(x) do{ uint32_t temp; temp=((x+0)<<3); while(--temp);}while(0)
#define delayUsec(x) udelay(x)
#define LCD_TEST
#define AUDIO_TEST
//#define I2C_TEST
//#define ADC_TEST
#endif
+107
View File
@@ -0,0 +1,107 @@
/**
******************************************************************************
* @file Project/adc/adc.c
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief This file provides adc Init and drivers.
* *
******************************************************************************
*/
#include "stm32f2xx.h"
#include "adc.h"
#include "hal.h"
#include "msg_que.h"
#include "stdio.h"
#include "stdlib.h"
#include "item.h"
#define ADC1_DR_ADDRESS ((uint32_t)0x4001204C)
//#define ADC2_DR_ADDRESS ((uint32_t)0x4001214C)
//#define ADC3_DR_ADDRESS ((uint32_t)0x4001224C)
__IO uint16_t ADC1ConvertedValue[10] = {0};
void adc_clk_init()
{
/* Enable peripheral clocks *************************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOADC, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
}
void adc_gpio_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
//AIN state
/* Configure ADC1 Channel5 pin as analog input ******************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void adc_init() //one adc
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef DMA_InitStructure;
adc_clk_init();//enable
adc_gpio_init();//AIN
/* ADC1 regular channel configuration ************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; //
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; //
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;//
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC Common configuration ********************** ***************************/
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//one ADC
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_6Cycles;//6* 1/30M
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;//
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; //60M/2
ADC_CommonInit(&ADC_CommonInitStructure);
/* ADC1 regular channel configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_3Cycles);//
/* DMA2 Stream0 channel0 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ADC1ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream0, ENABLE);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
}
+16
View File
@@ -0,0 +1,16 @@
/**
******************************************************************************
* @file Project/adc/adc.h
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief This file provides adc Init and drivers.
* *
******************************************************************************
*/
#ifndef _ADC_INIT_H_
#define _ADC_INIT_H_
void adc_init();
#endif
+135
View File
@@ -0,0 +1,135 @@
#include "stm32f2xx.h"
#include "hal.h"
#include "buttons.h"
void Buttons_Init() //上拉输入状态
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOC GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBUTTON, ENABLE);
/* GPIO Configuration*/
GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_UP | PIN_BUTTON_ENTER | PIN_BUTTON_DOWN | PIN_TRIM3_UP | PIN_TRIM3_DN
| PIN_TRIM4_UP |PIN_TRIM4_DN | PIN_SW_A_L | PIN_SW_D_L | PIN_SW_F_H | PIN_SW_G_H
| PIN_SW_G_L | PIN_SW_H_L;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_HOME | PIN_ESC | PIN_PAGE;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//复位状态,IN时应该忽略
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_TRIM1_UP | PIN_TRIM1_DN | PIN_TRIM2_UP | PIN_TRIM2_DN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_SW_B_H | PIN_SW_B_L | PIN_SW_C_H | PIN_SW_C_L | PIN_SW_D_H | PIN_SW_E_H | PIN_SW_F_L;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_SW_E_L;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
//short pin_status=0;
//short pin_status1=0;
void detect_buttons()
{
/*short t_pin;short t_pin1;
static short key_down_interval;
key_down_interval++;//计数循环多少次有键按下
t_pin = (~(GPIOC->IDR)) &(PIN_BUTTON_UP | PIN_BUTTON_ENTER | PIN_BUTTON_DOWN);
t_pin1=(~(GPIOB->IDR)) &(PIN_POWER | PIN_BIND);
if( (t_pin1 & PIN_BIND) && (!(pin_status1 & PIN_BIND))&&(!(t_pin1 & PIN_POWER)) )
{
}
if( (t_pin1 & PIN_POWER) && (!(pin_status1 & PIN_POWER)))
{
}
if( (pin_status1 & PIN_BIND) && (pin_status1 & PIN_POWER ))
{
static char t_pin_bind;
t_pin_bind++;//这个变量
if( (t_pin_bind ==39) || (t_pin_bind==69)){
t_pin_bind =40;
//SetIDProc(0,0,0,t_pin_bind);
}
}
if( (t_pin & PIN_BUTTON_UP) && (!(pin_status & PIN_BUTTON_UP )) )
{
}
if( (t_pin & PIN_BUTTON_ENTER) && (!(pin_status & PIN_BUTTON_ENTER )) )
{
}
if( (t_pin & PIN_BUTTON_DOWN) && (!(pin_status & PIN_BUTTON_DOWN )) )
{
}
//////////////////////////////////////////////////////////////////////////////////////
if( (pin_status & PIN_BUTTON_UP))
{
static char t_pin_up;
t_pin_up++;//这个变量
if( (t_pin_up ==9) || (t_pin_up==22)){
t_pin_up =10;
}else if((!(t_pin & PIN_BUTTON_UP)))
{
}
}
if( (pin_status & PIN_BUTTON_ENTER))
{
static char t_pin_enter;
t_pin_enter++;
if( (t_pin_enter ==9) || (t_pin_enter ==22)){
t_pin_enter =10;
}else if((!(t_pin & PIN_BUTTON_ENTER))){
if(t_pin_enter<9)
t_pin_enter =0;
}
}
if( (pin_status & PIN_BUTTON_DOWN))
{
static char t_pin_down;
t_pin_down++;
if( (t_pin_down ==9) || (t_pin_down==22) ){
t_pin_down =10;
}else if((!(t_pin & PIN_BUTTON_DOWN))){
if(t_pin_down<9)
t_pin_down =0;
}
}
pin_status = t_pin;
pin_status1=t_pin1;*/
}
+5
View File
@@ -0,0 +1,5 @@
#ifndef _BUTTONS_H_
#define _BUTTONS_H_
#endif
+255
View File
@@ -0,0 +1,255 @@
#ifndef _HAL_
#define _HAL_
/********************************
GPIOS----所有涉及GPIO的定义
*******************************************/
#define RCC_AHB1Periph_GPIOBUTTON (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
//Button
#define PIN_BUTTON_UP GPIO_Pin_0 //SW3 PE.10
#define PIN_BUTTON_ENTER GPIO_Pin_1 //SW2 PE.11
#define PIN_BUTTON_DOWN GPIO_Pin_2 //SW1 PE.12
#define PIN_HOME GPIO_Pin_11 //SW4 PD.07
#define PIN_ESC GPIO_Pin_12 //SW5 PD.03
#define PIN_PAGE GPIO_Pin_10 //SW6 PD.02
//Trim
#define PIN_TRIM1_UP GPIO_Pin_3 //PC.03
#define PIN_TRIM1_DN GPIO_Pin_2 //PC.02
#define PIN_TRIM2_UP GPIO_Pin_1 //PC.01
#define PIN_TRIM2_DN GPIO_Pin_13 //PC.13
#define PIN_TRIM3_UP GPIO_Pin_4 //PE.04
#define PIN_TRIM3_DN GPIO_Pin_3 //PE.03
#define PIN_TRIM4_UP GPIO_Pin_6 //PE.06
#define PIN_TRIM4_DN GPIO_Pin_5 //PE.05
//Switch
#define PIN_SW_A_L GPIO_Pin_14 //PE.14
#define PIN_SW_B_H GPIO_Pin_3 //PB.03
#define PIN_SW_B_L GPIO_Pin_4 //PB.04
#define PIN_SW_C_H GPIO_Pin_5 //PB.05
#define PIN_SW_C_L GPIO_Pin_6 //PB.06
#define PIN_SW_D_H GPIO_Pin_7 //PB.07
#define PIN_SW_D_L GPIO_Pin_2 //PE.02
#define PIN_SW_E_H GPIO_Pin_0 //PB.00
#define PIN_SW_E_L GPIO_Pin_5 //PA.05
#define PIN_SW_F_H GPIO_Pin_7 //PE.07
#define PIN_SW_F_L GPIO_Pin_1 //PB.01
#define PIN_SW_G_H GPIO_Pin_9 //PE.09
#define PIN_SW_G_L GPIO_Pin_8 //PE.08
#define PIN_SW_H_L GPIO_Pin_13 //PE.13
//ADC---8个
#define PIN_STK_J1 GPIO_Pin_0 //PA.00
#define PIN_STK_J2 GPIO_Pin_1 //PA.01
#define PIN_STK_J3 GPIO_Pin_2 //PA.02
#define PIN_STK_J4 GPIO_Pin_3 //PA.03
#define PIN_SLD_J1 GPIO_Pin_4 //PC.04
#define PIN_SLD_J2 GPIO_Pin_5 //PC.05
#define PIN_FLP_J1 GPIO_Pin_6 //PA.06
#define PIN_FLP_J2 GPIO_Pin_7 //PA.07
#define PIN_MVOLT GPIO_Pin_0 //PC.00
#define RCC_AHB1Periph_GPIOADC RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC
//DAC---1个
#define PIN_AUDIO_DAC GPIO_Pin_4 //PA.04
//Power_OFF Delay and LED
#define PIN_PWR_LED GPIO_Pin_6 //PC.06
#define PIN_PWR_STATUS GPIO_Pin_1 //PD.01
#define PIN_MCU_PWR GPIO_Pin_0 //PD.00
#define RCC_AHB1Periph_GPIOPWR RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD
#define GPIOPWRLED GPIOC
#define GPIOPWR GPIOD
//Smart-Port
#define PIN_SPORT_ON GPIO_Pin_4 //PD.04
#define PIN_SPORT_TX GPIO_Pin_5 //PD.05
#define PIN_SPORT_RX GPIO_Pin_6 //PD.06
//Trainer Port
#define PIN_TR_PPM_IN GPIO_Pin_8 //PC.08
#define PIN_TR_PPM_OUT GPIO_Pin_9 //PC.09
//Cppm
#define RCC_AHB1Periph_GPIOCPPM RCC_AHB1Periph_GPIOA
#define PIN_CPPM_OUT GPIO_Pin_8 //PA.08
#define GPIOCPPM GPIOA
#define GPIO_PinSource_CPPM GPIO_PinSource8
//Heart Beat
#define PIN_HEART_BEAT GPIO_Pin_7 //PC.07
//Update UART----RS232 ---UART3
#define PIN_UPDATE_UART_TX GPIO_Pin_10 //PB.10
#define PIN_UPDATE_UART_RX GPIO_Pin_11 //PB.11
//USB_OTG
#define PIN_FS_VBUS GPIO_Pin_9 //PA.09
#define PIN_FS_ID GPIO_Pin_10 //PA.10
#define PIN_FS_DM GPIO_Pin_11 //PA.11
#define PIN_FS_DP GPIO_Pin_12 //PA.12
//BackLight PB8
#define RCC_AHB1Periph_GPIOBL RCC_AHB1Periph_GPIOB
#define GPIO_Pin_BL GPIO_Pin_8 //PB.08
#define GPIOBL GPIOB
#define GPIO_PinSource_BL GPIO_PinSource8
//LCD GPIOD 10-14 模拟spi
#define RCC_AHB1Periph_LCD RCC_AHB1Periph_GPIOD
#define GPIO_LCD GPIOD
#define PIN_LCD_MOSI GPIO_Pin_10 //PD.10
#define PIN_LCD_CLK GPIO_Pin_11 //PD.11
#define PIN_LCD_NCS GPIO_Pin_14 //PD.14
#define PIN_LCD_A0 GPIO_Pin_13 //PD.13
#define PIN_LCD_RST //GPIO_Pin_12 //pd12 test //RESET occurs when powered up,but should delay before initialize
//Audio----I2S3
//#define CODEC_I2S_ADDRESS 0x4000380C
#define CODEC_I2S SPI3
#define CODEC_I2S_CLK RCC_APB1Periph_SPI3
#define CODEC_I2S_GPIO_AF GPIO_AF_SPI3
#define CODEC_I2S_IRQ SPI3_IRQn
#define CODEC_I2S_GPIO_CLOCK (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC )//| RCC_AHB1Periph_GPIOE)
#define CODEC_I2S_WS_PIN GPIO_Pin_15 //PA.15
#define CODEC_I2S_SCK_PIN GPIO_Pin_10 //PC.10
#define CODEC_I2S_SD_PIN GPIO_Pin_12 //PC.12
#define CODEC_I2S_MCK_PIN GPIO_Pin_6 //DISABLED
#define CODEC_I2S_WS_PINSRC GPIO_PinSource15
#define CODEC_I2S_SCK_PINSRC GPIO_PinSource10
#define CODEC_I2S_SD_PINSRC GPIO_PinSource12
#define CODEC_I2S_MCK_PINSRC GPIO_PinSource6
#define CODEC_I2S_GPIO GPIOC
#define CODEC_I2S_MCK_GPIO GPIOC
#define CODEC_I2S_WS_GPIO GPIOA
#define CODEC_I2S_MUTE GPIO_Pin_11 //PC.11
//#define CODEC_I2S_FLT GPIO_Pin_ //IIR/FIR
//#define CODEC_I2S_MODE GPIO_Pin_ //Connect to GND=I2S_STANDARD
//Eeprom与cat5137
#define I2C_EE_GPIO GPIOE
#define I2C_EE_WP_GPIO GPIOB
#define I2C_EE_GPIO_CLK RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOE
#define I2C_EE_SCL GPIO_Pin_1 //PE1
#define I2C_EE_SDA GPIO_Pin_0 //PE0
#define I2C_EE_WP GPIO_Pin_9 //PB9
//SD卡---spi2
#define SPI_SD SPI2
#define GPIO_AF_SD GPIO_AF_SPI2
#define RCC_AHB1Periph_GPIO_CS RCC_AHB1Periph_GPIOB
#define GPIO_SPI_SD GPIOB
#define GPIO_Pin_SPI_SD_CS GPIO_Pin_12 //PB.12
#define GPIO_Pin_SPI_SD_SCK GPIO_Pin_13 //PB.13
#define GPIO_Pin_SPI_SD_MISO GPIO_Pin_14 //PB.14
#define GPIO_Pin_SPI_SD_MOSI GPIO_Pin_15 //PB.15
#define GPIO_PinSource_CS GPIO_PinSource12
#define GPIO_PinSource_SCK GPIO_PinSource13
#define GPIO_PinSource_MISO GPIO_PinSource14
#define GPIO_PinSource_MOSI GPIO_PinSource15
#define RCC_APBPeriphClockCmd_SPI_SD RCC_APB1PeriphClockCmd
#define RCC_APBPeriph_SPI_SD RCC_APB1Periph_SPI2
#define RCC_AHBxPeriph_GPIO_WP RCC_AHB1Periph_GPIOD
#define RCC_AHBxPeriph_GPIO_CP RCC_AHB1Periph_GPIOD
#define GPIO_Mode_WP GPIO_Mode_OUT//lock?
#define GPIO_Mode_CP GPIO_Mode_IN //
#define GPIO_Pin_WP GPIO_Pin_8 //PD.08
#define GPIO_Pin_CP GPIO_Pin_9 //PD.09
#define GPIO_CTL_SD GPIOD
/*****************************************************************************
**************************************************************************
*******************************************************************************/
//其他接口涉及的可修改的宏定义
/******************************
lcd用
**************************************/
#define HIGHT (64)
#define WIDTH (212)
/*****************************************
Audio----I2S3-----SPI3
***************************************************************/
//#define CODEC_MCLK_ENABLED
#define CODEC_MCLK_DISABLED
#define CODEC_USE_INT
//#define CODEC_USE_DMA
#define AudioFreq I2S_AudioFreq_44k
/*************************************************
模拟I2C---EEPROM and CAT5137共用
********************************************************/
#define EE_M24C08 /* Support the device: M24C08. */
//#define EE_M24C64_32 /* Support the devices: M24C32 and M24C64 */
#define I2C_Speed 200000
#if defined (EE_M24C08)
#define I2C_FLASH_PAGESIZE (16)
#elif defined (EE_M24C64_32)
#define I2C_FLASH_PAGESIZE (32)
#endif
#ifdef EE_M24C64_32
#define EEPROM_HW_ADDRESS 0xA0 /* E0 = E1 = E2 = 0 */
#elif defined (EE_M24C08)
//#define EEPROM_Block0_ADDRESS 0xA0 /* 000*/
#define EEPROM_Block1_ADDRESS 0xA2 /* E3 E2 E1= 001 */
//#define EEPROM_Block2_ADDRESS 0xA4 /* 010 */
//#define EEPROM_Block3_ADDRESS 0xA6 /* 011 */
#endif
#define USE_CAT5137 /*Support the Volume Control*/
#ifdef USE_CAT5137
#define I2C_CAT5137_ADDRESS 0x5C//0101110
#endif
/*****************************************
SD card----SPI2
***************************************************************/
// demo uses a command line option to define this (see Makefile):
// #define STM32_SD_USE_DMA
#ifdef STM32_SD_USE_DMA
// #warning "Information only: using DMA"
#pragma message "*** Using DMA ***"
#endif
/* set to 1 to provide a disk_ioctrl function even if not needed by the FatFs */
#define STM32_SD_DISK_IOCTRL_FORCE (0)
#define CARD_SUPPLY_SWITCHABLE (0) //0,power on not depend any IO
#define SOCKET_WP_CONNECTED (0)
#define SOCKET_CP_CONNECTED (0)
#define SPI_BaudRatePrescaler_SPI_SD SPI_BaudRatePrescaler_4 // - for SPI1 and full-speed APB2: 60MHz/4 =15MHZ < 20MHZ
//selectable
//DMA相关未作修改
#define DMA_Channel_SPI_SD_RX DMA1_Channel2
#define DMA_Channel_SPI_SD_TX DMA1_Channel3
#define DMA_FLAG_SPI_SD_TC_RX DMA1_FLAG_TC2
#define DMA_FLAG_SPI_SD_TC_TX DMA1_FLAG_TC3
/******************************************
***************************************************************/
#endif
+426
View File
@@ -0,0 +1,426 @@
/**
******************************************************************************
* @file Project/ee_drivers/i2c_ee.c
* @author X9D Application Team
* @version V 0.2
* @date 12-JULY-2012
* @brief This file provides a set of functions needed to manage the
* communication between I2C peripheral and I2C M24CXX EEPROM.
CAT5137 added,share the I2C.
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "i2c_ee.h"
#include "hal.h"
#include "Macro_define.h"
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint16_t EEPROM_ADDRESS;
/* Private functions ---------------------------------------------------------*/
/**
* @brief Configure the used I/O ports pin
* @param None
* @retval None
*/
static
void I2C_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIOB->BSRRH =I2C_EE_WP; //PB9
GPIO_InitStructure.GPIO_Pin = I2C_EE_WP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(I2C_EE_WP_GPIO, &GPIO_InitStructure);
/* Configure I2C_EE pins: SCL and SDA */
GPIO_InitStructure.GPIO_Pin = I2C_EE_SCL | I2C_EE_SDA;//PE0,PE1
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(I2C_EE_GPIO, &GPIO_InitStructure);
}
/**
* @brief I2C Configuration
* @param None
* @retval None
*/
//when use harware I2C
void I2C_Configuration(void)
{
}
short I2C_START()
{
SDA_H; I2C_delay();
SCL_H; I2C_delay();
//if(!SDA_read)return 0; //SDA线为低电平则总线忙,退出
SDA_L; I2C_delay();
//if(SDA_read) return 0; //SDA线为高电平则总线出错,退出
SCL_L; I2C_delay();
return 1;
}
void I2C_STOP()
{
SCL_L; I2C_delay();
SDA_L; I2C_delay();
SCL_H; I2C_delay();
SDA_H; I2C_delay();
}
void I2C_ACK()
{
SCL_L; I2C_delay();
SDA_L; I2C_delay();
SCL_H; I2C_delay();
SCL_L; I2C_delay();
}
void I2C_NO_ACK()
{
SCL_L; I2C_delay();
SDA_H; I2C_delay();
SCL_H; I2C_delay();
SCL_L; I2C_delay();
}
short I2C_WAIT_ACK() //返回为:=1有ACK,=0无ACK
{
short i=50;
SCL_L; I2C_delay();
SDA_H; I2C_delay();
SCL_H; I2C_delay();
while(i){
if(SDA_read)
{
I2C_delay();
i--;
}else{
i=2;
break;
}
}
SCL_L; I2C_delay();
return i;
}
void I2C_SEND_DATA(char SendByte)
{
short i=8;
while(i--)
{
SCL_L; I2C_delay();
if(SendByte&0x80)
SDA_H;
else
SDA_L;
SendByte<<=1; I2C_delay();
SCL_H; I2C_delay();
}
SCL_L; I2C_delay();
}
char I2C_READ() //数据从高位到低位//
{
short i=8;
char ReceiveByte=0;
SDA_H;
while(i--)
{
ReceiveByte<<=1;
SCL_L; I2C_delay();
SCL_H; I2C_delay();
if(SDA_read)
{
ReceiveByte|=0x01;
}
}
SCL_L;
return ReceiveByte;
}
void I2C_EE_Init()
{
/* GPIO Periph clock enable */
RCC_AHB1PeriphClockCmd(I2C_EE_GPIO_CLK, ENABLE);
/* GPIO configuration */
I2C_GPIO_Configuration();
#if defined (EE_M24C64_32)
/* Select the EEPROM address according to the state of E0, E1, E2 pins */
EEPROM_ADDRESS = EEPROM_HW_ADDRESS;
#elif defined (EE_M24C08)
/* depending on the EEPROM Address selected in the i2c_ee.h file */
#ifdef EEPROM_Block0_ADDRESS
/* Select the EEPROM Block0 to write on */
EEPROM_ADDRESS = EEPROM_Block0_ADDRESS;
#endif
#ifdef EEPROM_Block1_ADDRESS
/* Select the EEPROM Block1 to write on */
EEPROM_ADDRESS = EEPROM_Block1_ADDRESS;
#endif
#ifdef EEPROM_Block2_ADDRESS
/* Select the EEPROM Block2 to write on */
EEPROM_ADDRESS = EEPROM_Block2_ADDRESS;
#endif
#ifdef EEPROM_Block3_ADDRESS
/* Select the EEPROM Block3 to write on */
EEPROM_ADDRESS = EEPROM_Block3_ADDRESS;
#endif
#endif /* EE_M24C64_32 */
}
/**
* @brief Writes one byte to the I2C EEPROM.
* @param pBuffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* @param WriteAddr : EEPROM's internal address to write to.
* @retval None
*/
void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr)
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
I2C_SEND_DATA((uint8_t)((WriteAddr&0xFF00)>>8) );
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr&0xFF));
I2C_WAIT_ACK();
#endif
I2C_SEND_DATA(*pBuffer);
I2C_WAIT_ACK();
I2C_STOP();
}
/**
* @brief Reads a block of data from the EEPROM.
* @param pBuffer : pointer to the buffer that receives the data read
* from the EEPROM.
* @param ReadAddr : EEPROM's internal address to read from.
* @param NumByteToRead : number of bytes to read from the EEPROM.
* @retval None
*/
void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead)
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS |EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(ReadAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
I2C_SEND_DATA((uint8_t)((ReadAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(ReadAddr & 0x00FF));
I2C_WAIT_ACK();
#endif
I2C_STOP();
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_READ);
I2C_WAIT_ACK();
while(NumByteToRead)
{
if(NumByteToRead ==1){
*pBuffer =I2C_READ();
I2C_NO_ACK();
I2C_STOP();
}else{
*pBuffer =I2C_READ();
I2C_ACK();
pBuffer++;
}
NumByteToRead--;
}
}
/**
* @brief Writes buffer of data to the I2C EEPROM.
* @param pBuffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* @param WriteAddr : EEPROM's internal address to write to.
* @param NumByteToWrite : number of bytes to write to the EEPROM.
* @retval None
*/
//整页的整页写 其他多字节写
void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
{
uint8_t NumOfPage = 0, NumOfSingle = 0, count = 0;
uint16_t Addr = 0;
Addr = WriteAddr % I2C_FLASH_PAGESIZE;
count = I2C_FLASH_PAGESIZE - Addr;
NumOfPage = NumByteToWrite / I2C_FLASH_PAGESIZE;
NumOfSingle = NumByteToWrite % I2C_FLASH_PAGESIZE;
/* If WriteAddr is I2C_FLASH_PAGESIZE aligned */
if(Addr == 0)
{
/* If NumByteToWrite < I2C_FLASH_PAGESIZE */
if(NumOfPage == 0)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
/* If NumByteToWrite > I2C_FLASH_PAGESIZE */
else
{
while(NumOfPage--)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_FLASH_PAGESIZE);
I2C_EE_WaitEepromStandbyState();
WriteAddr += I2C_FLASH_PAGESIZE;
pBuffer += I2C_FLASH_PAGESIZE;
}
if(NumOfSingle!=0)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
}
/* If WriteAddr is not I2C_FLASH_PAGESIZE aligned */
else
{
/* If NumByteToWrite < I2C_FLASH_PAGESIZE */
if(NumOfPage== 0)
{
/* If the number of data to be written is more than the remaining space
in the current page: */
if (NumByteToWrite > count)
{
/* Write the data conained in same page */
I2C_EE_PageWrite(pBuffer, WriteAddr, count);
I2C_EE_WaitEepromStandbyState();
/* Write the remaining data in the following page */
I2C_EE_PageWrite((uint8_t*)(pBuffer + count), (WriteAddr + count), (NumByteToWrite - count));
I2C_EE_WaitEepromStandbyState();
}
else
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
/* If NumByteToWrite > I2C_FLASH_PAGESIZE */
else
{
NumByteToWrite -= count;
NumOfPage = NumByteToWrite / I2C_FLASH_PAGESIZE;
NumOfSingle = NumByteToWrite % I2C_FLASH_PAGESIZE;
if(count != 0)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, count);
I2C_EE_WaitEepromStandbyState();
WriteAddr += count;
pBuffer += count;
}
while(NumOfPage--)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_FLASH_PAGESIZE);
I2C_EE_WaitEepromStandbyState();
WriteAddr += I2C_FLASH_PAGESIZE;
pBuffer += I2C_FLASH_PAGESIZE;
}
if(NumOfSingle != 0)
{
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
}
//I2C_EE_WaitEepromStandbyState();
}
/**
* @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
* @note The number of byte can't exceed the EEPROM page size.
* @param pBuffer : pointer to the buffer containing the data to be
* written to the EEPROM.
* @param WriteAddr : EEPROM's internal address to write to.
* @param NumByteToWrite : number of bytes to write to the EEPROM.
* @retval None
*/
void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite)
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
I2C_SEND_DATA((uint8_t)((WriteAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr & 0x00FF));
I2C_WAIT_ACK();
#endif /* EE_M24C08 */
/* While there is data to be written */
while(NumByteToWrite--)
{
I2C_SEND_DATA(*pBuffer);
I2C_WAIT_ACK();
pBuffer++;
}
I2C_STOP();
}
/**
* @brief Wait for EEPROM Standby state
* @param None
* @retval None
*/
void I2C_EE_WaitEepromStandbyState(void)
{
/*__IO*/ volatile uint16_t SR1_Tmp = 0;
do
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
}while(0== I2C_WAIT_ACK());
I2C_STOP();
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
+56
View File
@@ -0,0 +1,56 @@
/**
******************************************************************************
* @file Project/ee_drivers/i2c_ee.h
* @author X9D Application Team
* @version V 0.2
* @date 12-JLY-2012
* @brief Header for i2c_ee.c module
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
*/
/* Define to prevent recursive inclusion ------------------------------------ */
#ifndef __I2C_EE_H
#define __I2C_EE_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx.h"
#include "stm32f2xx_conf.h"
#include "stdint.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#define EE_CMD_WRITE (0)
#define EE_CMD_READ (1)
#define I2C_delay() do{delayUsec(5);}while(0)
#define SCL_H do{GPIOB->BSRRL = I2C_EE_SCL;}while(0)
#define SCL_L do{GPIOB->BSRRH = I2C_EE_SCL;}while(0)
#define SDA_H do{GPIOB->BSRRL = I2C_EE_SDA;}while(0)
#define SDA_L do{GPIOB->BSRRH = I2C_EE_SDA;}while(0)
#define SCL_read (GPIOB->IDR & I2C_EE_SCL)
#define SDA_read (GPIOB->IDR & I2C_EE_SDA)
/* Exported functions ------------------------------------------------------- */
void I2C_EE_Init(void);
void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr);
void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite);
void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead);
void I2C_EE_WaitEepromStandbyState(void);
#endif /* __I2C_EE_H */
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
+197
View File
@@ -0,0 +1,197 @@
/**
******************************************************************************
* @file Project/lcd/lcd.c
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief This file provides LCD Init and botom drivers.
* *
******************************************************************************
*/
#include <stdint.h>
#include "lcd.h"
#include "spi.h"
#include "hal.h"
#include "Macro_define.h"
#define WriteData(x) AspiData(x)
#define WriteCommand(x) AspiCmd(x)
void Set_Address(u8 x, u8 y)
{
WriteCommand(x&0x0F); //Set Column Address LSB CA[3:0]
WriteCommand((x>>4)|0x10); //Set Column Address MSB CA[7:4]
WriteCommand((y&0x0F)|0x60); //Set Row Address LSB RA [3:0]
WriteCommand(((y>>4)&0x0F)|0x70); //Set Row Address MSB RA [7:4]
}
/**6 ponits in one line share the same address,3 bytes in the buffer.
3 bytes wrote in one time */
void refreshDisplay()
{
u8 _x1,_x0,temp_x0,temp_x00;
_x1 =( DISPLAY_W>>1) + 1;
temp_x0 = 0;
temp_x00 = temp_x0/3;
for(uint32_t y0=0; y0<=y1; y0++)
{
Set_Address(0, y0);//change the address every column
AspiCmd(0xAF);
for(uint_32_t x=0; x_x0<=_x1; _x0++)
{
WriteData(lcd_buffer[_x0][y0]);
//WriteData(lcd_buffer[_x0][y0]);
//WriteData(lcd_buffer[_x0][y0]);
}
}
}
/**Init the Backlight GPIO */
static void LCD_BL_Config()
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBL, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_BL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOBL, &GPIO_InitStructure);
}
/** Init the anolog spi gpio
*/
static void LCD_Hardware_Init()
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LCD, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
/*!< Configure lcd CLK\ MOSI\ A0pin in output pushpull mode *************/
GPIO_InitStructure.GPIO_Pin =PIN_LCD_MOSI | PIN_LCD_CLK | PIN_LCD_A0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO_LCD, &GPIO_InitStructure);
/*!< Configure lcd NCS pin in output pushpull mode ,PULLUP *************/
GPIO_InitStructure.GPIO_Pin = PIN_LCD_NCS;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIO_LCD, &GPIO_InitStructure);
}
#if 0
void Delay(uint32_t ms);
/* Initialize the LCD */
#endif
static void LCD_Init()
{
/*Hardware Reset need delay*/
/*LCD_RST_LOW();
Delay(50);
LCD_RST_HIGH();*/
AspiCmd(0x25); //Temperature compensation curve definition: 0x25 = -0.05%/oC
AspiCmd(0x2b); //Panel loading set ,Internal VLCD.
AspiCmd(0xEA); //set bias=1/10 :Command table NO.27
AspiCmd(0x81); //Set Vop
AspiCmd(50); //0--255
AspiCmd(0xA6); //inverse display off
AspiCmd(0xD1); //SET RGB:Command table NO.21 .SET RGB or BGR. D1=RGB
AspiCmd(0xD5); //set color mode 4K and 12bits :Command table NO.22
AspiCmd(0xA0); //line rates,25.2 Klps
AspiCmd(0xC8); //SET N-LINE INVERSION
AspiCmd(0x00); //Disable NIV
AspiCmd(0xF1); //Set CEN
AspiCmd(0x3F); // 1/64DUTY
AspiCmd(0x84); //Disable Partial Display
AspiCmd(0xC4); //MY=1,MX=0
AspiCmd(0x89); //WA=1,column (CA) increment (+1) first until CA reaches CA boundary, then RA will increment by (+1).
AspiCmd(0xF8); //Set Window Program Enable ,inside modle
AspiCmd(0xF4); //starting column address of RAM program window.
AspiCmd(0x00);
AspiCmd(0xF5); //starting row address of RAM program window.
AspiCmd(0x60);
AspiCmd(0xF6); //ending column address of RAM program window.
AspiCmd(0x47);
AspiCmd(0xF7); //ending row address of RAM program window.
AspiCmd(0x9F);
AspiCmd(0xAF); //dc2=1,IC into exit SLEEP MODE, dc3=1 gray=ON 开灰阶 ,dc4=1 Green Enhanc mode disabled 绿色增强模式关
}
void lcd_init()
{
LCD_BL_Config();
LCD_Hardware_Init();
LCD_Init();
}
#if 0
/***************************************************************
***********FOR Test
**********************************************************************/
void Delay(uint32_t ms)
{
u8 i;
while(ms != 0)
{
for(i=0;i<250;i++) {}
for(i=0;i<75;i++) {}
ms--;
}
}
void TEST_LCD()
{
//static u32 cnt;
//CC中断
GPIO_SetBits(GPIOB,GPIO_Pin_8);//BACKLIGHT
//Delay(3000);
//paintScreen();
clearScreen();
drawPoint(0,0,1);
paintRect(0,0,0,0);
reversePoint(0,0);
paintRect(0,0,0,0);
Delay(3000);
drawPoint(1,0,1);
paintRect(0,0,1,0);
Delay(3000);
reversePoint(1,0);
paintRect(0,0,1,0);
Delay(3000);
drawPoint(0,1,1);
paintRect(0,1,0,1);
Delay(3000);
reversePoint(0,1);
paintRect(0,1,0,1);
drawPoint(211,0,1);
paintRect(0,0,211,0);
Delay(3000);
reversePoint(211,0);
paintRect(0,0,211,0);
drawPoint(211,63,1);
paintRect(211,63,211,63);
Delay(3000);
reversePoint(211,63);
paintRect(211,63,211,63);
}
#endif
+62
View File
@@ -0,0 +1,62 @@
/**
******************************************************************************
* @file Project/main.c
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief This file provides the main fuction.
* *
******************************************************************************
*/
#include "stm32f2xx.h"
#include "intrinsics.h"
#include "stdint.h"
#include "stdio.h"
#include "SYS_NVIC.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "lcd.h"
#include "gui_tsk.h"
#include "item.h"
#include "Audio.h"
#include "sys_man.h"
#include "Macro_define.h"
#ifdef I2C_TEST
#include "i2c_ee.h"
#endif
#ifdef ADC_TEST
#include "adc.h"
#endif
int main()
{
Delay(10000); //delay 200+ ms
#ifdef DEBUG
debug();
#endif
__disable_interrupt();
/*HCLK=120M,SYSCLK=120M,PCLK1=30M,PCLK2=60M,SO APB1=60M(div=4),APB2=120M(div=2)*/
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);//add to watch to see the values
//clock init ok ,other peripherals init code;
__enable_interrupt();
while(1)
{
}
//return 0;
}
+50
View File
@@ -0,0 +1,50 @@
#include "hal.h"
#include "stm32f2xx.h"
#include "pwr_ctrl.h"
void pwr_ctrl_down()
{
GPIO_SetBits(GPIOPWR,PIN_MCU_PWR);
//ee_save_data();
GPIO_ResetBits(GPIOPWR,PIN_MCU_PWR);
}
void pwr_ctrl_on()
{
}
void check_pwr() //¶¨Ê±ÒÖ»òÖжϣ¬ÔÙ²âÊÔ
{
if( GPIO_ReadInputDataBit(GPIOPWR,PIN_PWR_STATUS) == Bit_RESET)
{
pwr_ctrl_down();
}
}
void pwr_io_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOC GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOPWR, ENABLE);
/* GPIO Configuration*/
GPIO_InitStructure.GPIO_Pin = PIN_MCU_PWR | PIN_PWR_ON;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOPWR, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_PWR_STATUS;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(GPIOPWR, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_PWR_LED;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOPWRLED, &GPIO_InitStructure);
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _PWR_CTRL_H_
#define _PWR_CTRL_H_
#endif
+282
View File
@@ -0,0 +1,282 @@
/*-------------------------------------------------------------------------- */
/* RTC controls for STM32 */
/* Copyright (c) 2009, Martin Thomas 4/2009, 3BSD-license */
/* partly based on code from STMircoelectronics, Peter Dannegger, "LaLaDumm" */
/*-------------------------------------------------------------------------- */
#include <stdint.h>
#include "stm32f10x.h"
#include "rtc.h"
#define FIRSTYEAR 2000 // start year
#define FIRSTDAY 6 // 0 = Sunday
static const uint8_t DaysInMonth[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
/*******************************************************************************
* Function Name : isDST
* Description : checks if given time is in Daylight Saving time-span.
* Input : time-struct, must be fully populated including weekday
* Output : none
* Return : false: no DST ("winter"), true: in DST ("summer")
* DST according to German standard
* Based on code from Peter Dannegger found in the microcontroller.net forum.
*******************************************************************************/
static bool isDST( const RTC_t *t )
{
uint8_t wday, month; // locals for faster access
month = t->month;
if( month < 3 || month > 10 ) { // month 1, 2, 11, 12
return false; // -> Winter
}
wday = t->wday;
if( t->mday - wday >= 25 && (wday || t->hour >= 2) ) { // after last Sunday 2:00
if( month == 10 ) { // October -> Winter
return false;
}
} else { // before last Sunday 2:00
if( month == 3 ) { // March -> Winter
return false;
}
}
return true;
}
/*******************************************************************************
* Function Name : adjustDST
* Description : adjusts time to DST if needed
* Input : non DST time-struct, must be fully populated including weekday
* Output : time-stuct gets modified
* Return : false: no DST ("winter"), true: in DST ("summer")
* DST according to German standard
* Based on code from Peter Dannegger found in the mikrocontroller.net forum.
*******************************************************************************/
static bool adjustDST( RTC_t *t )
{
uint8_t hour, day, wday, month; // locals for faster access
hour = t->hour;
day = t->mday;
wday = t->wday;
month = t->month;
if ( isDST(t) ) {
t->dst = 1;
hour++; // add one hour
if( hour == 24 ){ // next day
hour = 0;
wday++; // next weekday
if( wday == 7 ) {
wday = 0;
}
if( day == DaysInMonth[month-1] ) { // next month
day = 0;
month++;
}
day++;
}
t->month = month;
t->hour = hour;
t->mday = day;
t->wday = wday;
return true;
} else {
t->dst = 0;
return false;
}
}
/*******************************************************************************
* Function Name : counter_to_struct
* Description : populates time-struct based on counter-value
* Input : - counter-value (unit seconds, 0 -> 1.1.2000 00:00:00),
* - Pointer to time-struct
* Output : time-struct gets populated, DST not taken into account here
* Return : none
* Based on code from Peter Dannegger found in the mikrocontroller.net forum.
*******************************************************************************/
static void counter_to_struct( uint32_t sec, RTC_t *t )
{
uint16_t day;
uint8_t year;
uint16_t dayofyear;
uint8_t leap400;
uint8_t month;
t->sec = sec % 60;
sec /= 60;
t->min = sec % 60;
sec /= 60;
t->hour = sec % 24;
day = (uint16_t)(sec / 24);
t->wday = (day + FIRSTDAY) % 7; // weekday
year = FIRSTYEAR % 100; // 0..99
leap400 = 4 - ((FIRSTYEAR - 1) / 100 & 3); // 4, 3, 2, 1
for(;;) {
dayofyear = 365;
if( (year & 3) == 0 ) {
dayofyear = 366; // leap year
if( year == 0 || year == 100 || year == 200 ) { // 100 year exception
if( --leap400 ) { // 400 year exception
dayofyear = 365;
}
}
}
if( day < dayofyear ) {
break;
}
day -= dayofyear;
year++; // 00..136 / 99..235
}
t->year = year + FIRSTYEAR / 100 * 100; // + century
if( dayofyear & 1 && day > 58 ) { // no leap year and after 28.2.
day++; // skip 29.2.
}
for( month = 1; day >= DaysInMonth[month-1]; month++ ) {
day -= DaysInMonth[month-1];
}
t->month = month; // 1..12
t->mday = day + 1; // 1..31
}
/*******************************************************************************
* Function Name : struct_to_counter
* Description : calculates second-counter from populated time-struct
* Input : Pointer to time-struct
* Output : none
* Return : counter-value (unit seconds, 0 -> 1.1.2000 00:00:00),
* Based on code from "LalaDumm" found in the mikrocontroller.net forum.
*******************************************************************************/
static uint32_t struct_to_counter( const RTC_t *t )
{
uint16_t i;
uint32_t result = 0;
uint16_t idx, year;
year = t->year;
/* Calculate days of years before */
result = (uint32_t)year * 365;
if (t->year >= 1) {
result += (year + 3) / 4;
result -= (year - 1) / 100;
result += (year - 1) / 400;
}
/* Start with 2000 a.d. */
result -= 730485UL;
/* Make month an array index */
idx = t->month - 1;
/* Loop thru each month, adding the days */
for (i = 0; i < idx; i++) {
result += DaysInMonth[i];
}
/* Leap year? adjust February */
if (year%400 == 0 || (year%4 == 0 && year%100 !=0)) {
;
} else {
if (t->month > 1) {
result--;
}
}
/* Add remaining days */
result += t->mday;
/* Convert to seconds, add all the other stuff */
result = (result-1) * 86400L + (uint32_t)t->hour * 3600 +
(uint32_t)t->min * 60 + t->sec;
return result;
}
/*******************************************************************************
* Function Name : rtc_gettime
* Description : populates structure from HW-RTC, takes DST into account
* Input : None
* Output : time-struct gets modified
* Return : always true/not used
*******************************************************************************/
bool rtc_gettime (RTC_t *rtc)
{
uint32_t t;
while ( ( t = RTC_GetCounter() ) != RTC_GetCounter() ) { ; }
counter_to_struct( t, rtc ); // get non DST time
adjustDST( rtc );
return true;
}
/*******************************************************************************
* Function Name : my_RTC_SetCounter
* Description : sets the hardware-counter
* Input : new counter-value
* Output : None
* Return : None
*******************************************************************************/
static void my_RTC_SetCounter(uint32_t cnt)
{
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Change the current time */
RTC_SetCounter(cnt);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
/*******************************************************************************
* Function Name : rtc_settime
* Description : sets HW-RTC with values from time-struct, takes DST into
* account, HW-RTC always running in non-DST time
* Input : None
* Output : None
* Return : not used
*******************************************************************************/
bool rtc_settime (const RTC_t *rtc)
{
uint32_t cnt;
RTC_t ts;
cnt = struct_to_counter( rtc ); // non-DST counter-value
counter_to_struct( cnt, &ts ); // normalize struct (for weekday)
if ( isDST( &ts ) ) {
cnt -= 60*60; // Subtract one hour
}
PWR_BackupAccessCmd(ENABLE);
my_RTC_SetCounter( cnt );
PWR_BackupAccessCmd(DISABLE);
return true;
}
/*******************************************************************************
* Function Name : rtc_init
* Description : initializes HW RTC,
* sets default time-stamp if RTC has not been initialized before
* Input : None
* Output : None
* Return : not used
* see STM RTC example in the StdPeriph-Library package
*******************************************************************************/
int rtc_init(void) //not use back_vcc
{
}
+30
View File
@@ -0,0 +1,30 @@
#ifndef RTC_H_
#define RTC_H_
#include <stdint.h>
//#include "interger.h"
//#include <stdbool.h>
#include "stm32f2xx.h"
#ifndef false
#define false FALSE
#endif
#ifndef true
#define true TRUE
#endif
typedef struct {
uint16_t year; /* 1..4095 */
uint8_t month; /* 1..12 */
uint8_t mday; /* 1..31 */
uint8_t wday; /* 0..6, Sunday = 0*/
uint8_t hour; /* 0..23 */
uint8_t min; /* 0..59 */
uint8_t sec; /* 0..59 */
uint8_t dst; /* 0 Winter, !=0 Summer */
} RTC_t;
int rtc_init(void);
bool rtc_gettime (RTC_t*); /* Get time */
bool rtc_settime (const RTC_t*); /* Set time */
#endif
+128
View File
@@ -0,0 +1,128 @@
/**
******************************************************************************
* @file Project/spi/spi.c
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief This file provides spi Init(Analog spi),read and write.
driver for LCD.
* *
******************************************************************************
*/
#include "spi.h"
#include "hal.h"
/**
**********send command to lcd**************
*/
//hardware spi
/*u16 spiCmd(u8 addr)
{
u8 readValue;
SPI_RS_LOW();
SPI_NCS_LOW();
SPI_WRITE_BYTE(addr);
SPI_WAIT_DONE();
readValue=SPI_READ_BYTE();
SPI_NCS_HIGH();
return readValue;
}*/
//Anolog spi
void AspiCmd(u8 Command_Byte)
{
int i=8;
LCD_A0_LOW();
LCD_CLK_HIGH();
LCD_NCS_LOW();
while (i--)
{
LCD_CLK_LOW();
if(Command_Byte&0x80)
{
LCD_MOSI_HIGH();
}
else LCD_MOSI_LOW();
Command_Byte=Command_Byte<<1;
LCD_CLK_HIGH();
}
LCD_NCS_HIGH();
LCD_A0_HIGH();
}
/**
********send data to lcd**************
*/
//hardware spi
/*
u16 spiData(u8 addr)
{
u16 readValue;
OLED_RS_HIGH();
SPI_NCS_LOW();
SPI_WRITE_BYTE(addr);
SPI_WAIT_DONE();
readValue=SPI_READ_BYTE();
SPI_NCS_HIGH();
return readValue;
}
*/
//Anolog spi
void AspiData(u8 Para_data)
{
int i=8;
LCD_CLK_HIGH();
LCD_A0_HIGH();
LCD_NCS_LOW();
while (i--)
{
if(Para_data&0x80)
{
LCD_MOSI_HIGH();
}else LCD_MOSI_LOW();
Para_data<<=1;
LCD_CLK_LOW();
__no_operation();
LCD_CLK_HIGH();
__no_operation();
}
LCD_NCS_HIGH();
LCD_A0_HIGH();
}
/***
**********read one byte in a register*******
*/
/*
u16 spiRegAccess(u8 addrByte, u8 writeValue)
{
u8 readValue;
SPI_NCS_LOW();
SPI_WRITE_BYTE(addrByte);
SPI_WAIT_DONE();
SPI_WRITE_BYTE(writeValue);
SPI_WAIT_DONE();
readValue=SPI_READ_BYTE();
SPI_NCS_HIGH();
return readValue;
}
*/
+36
View File
@@ -0,0 +1,36 @@
/**
******************************************************************************
* @file Project/spi/spi.h
* @author X9D Application Team
* @Hardware version V0.2
* @date 11-July-2012
* @brief spi.c' Header file.
* *
******************************************************************************
*/
#ifndef _SPI_H_
#define _SPI_H_
#include "stm32f2xx.h"
#define LCD_NCS_HIGH() do{GPIO_SetBits(GPIO_LCD, PIN_LCD_NCS);}while(0)
#define LCD_NCS_LOW() do{GPIO_ResetBits(GPIO_LCD, PIN_LCD_NCS);}while(0)
#define LCD_A0_HIGH() do{GPIO_SetBits(GPIO_LCD, PIN_LCD_A0);}while(0)
#define LCD_A0_LOW() do{GPIO_ResetBits(GPIO_LCD, PIN_LCD_A0);}while(0)
#define LCD_RST_HIGH() do{GPIO_SetBits(GPIO_LCD, PIN_LCD_RST);}while(0)
#define LCD_RST_LOW() do{GPIO_ResetBits(GPIO_LCD, PIN_LCD_RST);}while(0)
#define LCD_CLK_HIGH() do{GPIO_SetBits(GPIO_LCD, PIN_LCD_CLK);}while(0)
#define LCD_CLK_LOW() do{GPIO_ResetBits(GPIO_LCD, PIN_LCD_CLK);}while(0)
#define LCD_MOSI_HIGH() do{GPIO_SetBits(GPIO_LCD, PIN_LCD_MOSI);}while(0)
#define LCD_MOSI_LOW() do{GPIO_ResetBits(GPIO_LCD, PIN_LCD_MOSI);}while(0)
void AspiCmd(u8 Command_Byte);
void AspiData(u8 Para_data);
//u16 spiRegAccess(u8 addrByte, u8 writeValue);
#endif
+6964
View File
File diff suppressed because it is too large Load Diff
+257
View File
@@ -0,0 +1,257 @@
/**
******************************************************************************
* @file Project/STM32F2xx_StdPeriph_Template/stm32f2xx_it.c
* @author MCD Application Team
* @version V1.1.0
* @date 13-April-2012
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and
* peripherals interrupt service routine.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx_it.h"
#include "Macro_define.h"
/** @addtogroup Template_Project
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************/
/* Cortex-M3 Processor Exceptions Handlers */
/******************************************************************************/
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
//void SVC_Handler(void)
//{
//}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
//void PendSV_Handler(void)
//{
//}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
//void SysTick_Handler(void)
//{
//}
/******************************************************************************/
/* STM32F2xx Peripherals Interrupt Handlers */
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
/* available peripheral interrupt handler's name please refer to the startup */
/* file (startup_stm32f2xx.s). */
/******************************************************************************/
/**
* @brief This function handles PPP interrupt request.
* @param None
* @retval None
*/
/*void PPP_IRQHandler(void)
{
}*/
#ifdef AUDIO_TEST
#include "Audio.h"
void SPI3_IRQHandler(void)
{
}
#endif
//all the available peripheral interrupt handler's name are followed
/*
; External Interrupts
DCD WWDG_IRQHandler ; Window WatchDog
DCD PVD_IRQHandler ; PVD through EXTI Line detection
DCD TAMP_STAMP_IRQHandler ; Tamper and TimeStamps through the EXTI line
DCD RTC_WKUP_IRQHandler ; RTC Wakeup through the EXTI line
DCD FLASH_IRQHandler ; FLASH
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line0
DCD EXTI1_IRQHandler ; EXTI Line1
DCD EXTI2_IRQHandler ; EXTI Line2
DCD EXTI3_IRQHandler ; EXTI Line3
DCD EXTI4_IRQHandler ; EXTI Line4
DCD DMA1_Stream0_IRQHandler ; DMA1 Stream 0
DCD DMA1_Stream1_IRQHandler ; DMA1 Stream 1
DCD DMA1_Stream2_IRQHandler ; DMA1 Stream 2
DCD DMA1_Stream3_IRQHandler ; DMA1 Stream 3
DCD DMA1_Stream4_IRQHandler ; DMA1 Stream 4
DCD DMA1_Stream5_IRQHandler ; DMA1 Stream 5
DCD DMA1_Stream6_IRQHandler ; DMA1 Stream 6
DCD ADC_IRQHandler ; ADC1, ADC2 and ADC3s
DCD CAN1_TX_IRQHandler ; CAN1 TX
DCD CAN1_RX0_IRQHandler ; CAN1 RX0
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
DCD EXTI9_5_IRQHandler ; External Line[9:5]s
DCD TIM1_BRK_TIM9_IRQHandler ; TIM1 Break and TIM9
DCD TIM1_UP_TIM10_IRQHandler ; TIM1 Update and TIM10
DCD TIM1_TRG_COM_TIM11_IRQHandler ; TIM1 Trigger and Commutation and TIM11
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI15_10_IRQHandler ; External Line[15:10]s
DCD RTC_Alarm_IRQHandler ; RTC Alarm (A and B) through EXTI Line
DCD OTG_FS_WKUP_IRQHandler ; USB OTG FS Wakeup through EXTI line
DCD TIM8_BRK_TIM12_IRQHandler ; TIM8 Break and TIM12
DCD TIM8_UP_TIM13_IRQHandler ; TIM8 Update and TIM13
DCD TIM8_TRG_COM_TIM14_IRQHandler ; TIM8 Trigger and Commutation and TIM14
DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare
DCD DMA1_Stream7_IRQHandler ; DMA1 Stream7
DCD FSMC_IRQHandler ; FSMC
DCD SDIO_IRQHandler ; SDIO
DCD TIM5_IRQHandler ; TIM5
DCD SPI3_IRQHandler ; SPI3
DCD UART4_IRQHandler ; UART4
DCD UART5_IRQHandler ; UART5
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC1&2 underrun errors
DCD TIM7_IRQHandler ; TIM7
DCD DMA2_Stream0_IRQHandler ; DMA2 Stream 0
DCD DMA2_Stream1_IRQHandler ; DMA2 Stream 1
DCD DMA2_Stream2_IRQHandler ; DMA2 Stream 2
DCD DMA2_Stream3_IRQHandler ; DMA2 Stream 3
DCD DMA2_Stream4_IRQHandler ; DMA2 Stream 4
DCD ETH_IRQHandler ; Ethernet
DCD ETH_WKUP_IRQHandler ; Ethernet Wakeup through EXTI line
DCD CAN2_TX_IRQHandler ; CAN2 TX
DCD CAN2_RX0_IRQHandler ; CAN2 RX0
DCD CAN2_RX1_IRQHandler ; CAN2 RX1
DCD CAN2_SCE_IRQHandler ; CAN2 SCE
DCD OTG_FS_IRQHandler ; USB OTG FS
DCD DMA2_Stream5_IRQHandler ; DMA2 Stream 5
DCD DMA2_Stream6_IRQHandler ; DMA2 Stream 6
DCD DMA2_Stream7_IRQHandler ; DMA2 Stream 7
DCD USART6_IRQHandler ; USART6
DCD I2C3_EV_IRQHandler ; I2C3 event
DCD I2C3_ER_IRQHandler ; I2C3 error
DCD OTG_HS_EP1_OUT_IRQHandler ; USB OTG HS End Point 1 Out
DCD OTG_HS_EP1_IN_IRQHandler ; USB OTG HS End Point 1 In
DCD OTG_HS_WKUP_IRQHandler ; USB OTG HS Wakeup through EXTI
DCD OTG_HS_IRQHandler ; USB OTG HS
DCD DCMI_IRQHandler ; DCMI
DCD CRYP_IRQHandler ; CRYP crypto
DCD HASH_RNG_IRQHandler ; Hash and Rng
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+60
View File
@@ -0,0 +1,60 @@
/**
******************************************************************************
* @file Project/STM32F2xx_StdPeriph_Template/stm32f2xx_it.h
* @author MCD Application Team
* @version V1.1.0
* @date 13-April-2012
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* 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 __STM32F2xx_IT_H
#define __STM32F2xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#ifdef __cplusplus
}
#endif
#endif /* __STM32F2xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+256
View File
@@ -0,0 +1,256 @@
#include "stm32f2xx.h"
#include "timer_init.h"
#include "hal.h"
#include "msg_que.h"
//Hardware Init Of Timer
//TIM10_CH1 LCD backlight
//PWM OUTPUT MODE 500HZ,400HZ闪动。修改TIM10-> CCR1(1-4000)改变占空比,正比。
void TIM10_CH1_BL_Init()
{
uint16_t PrescalerValue = 0;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* TIM10 clock enable ,GPIOBL clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBL, ENABLE);
/* GPIOC Configuration: TIM10_CH1 (PB.08)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_BL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOBL, &GPIO_InitStructure);
/* Connect TIM10 pins to AF3 */
GPIO_PinAFConfig(GPIOBL, GPIO_PinSource_BL, GPIO_AF_TIM10);
/*
APB2 = 120M,分频系数6,TIM10计数频率2M。TIM10频率为2M/4000=500HZ.
so the TIM10 Channel 1 generates a PWM signal with a frequency equal to
500Hz and a duty cycle = (TIM10_CCR1/ TIM10_ARR + 1)* 100 = 50%
*/
/* Compute the prescaler value */
PrescalerValue = (uint16_t) ((SystemCoreClock ) / 2000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 3999; //ARR=19999
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM10, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse =2000; //TIM10-> CCR1
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM10, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM10, TIM_OCPreload_Enable);
/* TIM10 enable counter */
TIM_Cmd(TIM10, ENABLE);
}
void TIM10_CH1_BL_Adjust(char mode)
{
switch(mode)
{
case BKL_DEC:
TIM10->CCR1 += 250;
if(TIM10->CCR1>4000)
TIM10->CCR1 = 4000;
break;
case BKL_INC:
if(TIM10->CCR1 < 250)
TIM10->CCR1 = 0;
else
TIM10->CCR1 -= 250;
break;
case BKL_OFF: TIM_Cmd(TIM10, DISABLE);break;
case BKL_ON: TIM_Cmd(TIM10, ENABLE);break;
default:break;
}
}
//TIM1_CH1:CPPM_OUTPUT
void TIM1_CH1_CPPM_Init()
{
}
static struct TimerStruct timer_struct[MAX_TIMER];
char led_lights;
/*******************************************
初始化应用层定时器
*******************************************/
static void initTimerStruct(void)
{
char i;
for(i=0;i<MAX_TIMER;i++)
{
timer_struct[i].valid=0;
}
}
/*****************************************
* timer hardware init
*****************************************/
void initTimer(void)
{
initTimerStruct();
}
/********************************************
定时器 tick 处理
********************************************/
void timer_tick(void)
{
{
short i;
struct TimerStruct *p=timer_struct;
for(i=0;i<MAX_TIMER;i++)
{
if(p->valid){
p->expires--;
if(p->expires==0)
{
p->valid=0;
//raiseEvent(p->event);
postMessage(p->pMsg->hWnd, p->pMsg->iMsg, p->pMsg->wParam, p->pMsg->lParam);
}
}
p++;
}
}
}
/****************************************
* 设置定时器
****************************************/
void setTimer(char timerID,char expires,PMSG pMsg)
{
struct TimerStruct *p=&timer_struct[timerID];
p->expires=expires;
p->pMsg =pMsg;
p->valid=1;
}
/****************************************
* 取消定时器
****************************************/
void cancelTimer(char timerID)
{
timer_struct[timerID].valid=0;
}
/**************************************************************************
*****************************************************************************
******************************************************************************/
static struct TimerStruct timer_struct[MAX_TIMER];
/*******************************************
初始化应用层定时器
*******************************************/
static void initTimerStruct(void)
{
char i;
for(i=0;i<MAX_TIMER;i++)
{
timer_struct[i].valid=0;
}
}
/*****************************************
* timer hardware init
*****************************************/
void initTimer(void)
{
initTimerStruct();
}
/********************************************
定时器 tick 处理
********************************************/
void timer_tick(void)
{
{
short i;
struct TimerStruct *p=timer_struct;
for(i=0;i<MAX_TIMER;i++)
{
if(p->valid){
p->expires--;
if(p->expires==0)
{
p->valid=0;
//raiseEvent(p->event);
postMessage(p->pMsg->hWnd, p->pMsg->iMsg, p->pMsg->wParam, p->pMsg->lParam);
}
}
p++;
}
}
}
/****************************************
* 设置定时器
****************************************/
void setTimer(char timerID,char expires,PMSG pMsg)
{
struct TimerStruct *p=&timer_struct[timerID];
p->expires=expires;
p->pMsg =pMsg;
p->valid=1;
}
/****************************************
* 取消定时器
****************************************/
void cancelTimer(char timerID)
{
timer_struct[timerID].valid=0;
}
/****************************************************************************
****************************************************************************/
+34
View File
@@ -0,0 +1,34 @@
#ifndef _TIMER_INIT_H_
#define _TIMER_INIT_H_
#include "frgui.h"
#define MAX_TIMER (5) //×î´óµÄtimerID
#define TIMER_1 (0)
#define TIMER_2 (1)
#define TIMER_3 (2)
#define TIMER_4 (3)
#define TIMER_5 (4)
struct TimerStruct
{
char valid;
char expires;
PMSG pMsg;
};
void initTimer(void);
void setTimer(char timerID,char expires,PMSG pMsg);
void cancelTimer(char timerID);
void timer_interrupt(void);
void timer_tick(void);
void TIM10_CH1_BL_Init();
#define BKL_DEC (0)
#define BKL_INC (1)
#define BKL_OFF (2)
#define BKL_ON (3)
#endif