1、MTK Driver Introduction,首先需要注意两个宏定义1. _CUST_NEW_ 程序中有多处用该宏将代码隔开 Make文件中若如下定义: DRV_CUSTOM_TOOL_SUPPORT = TRUE Option.mak文件中 ifdef DRV_CUSTOM_TOOL_SUPPORTifeq ($(strip $(DRV_CUSTOM_TOOL_SUPPORT),TRUE)COM_DEFS += _CUST_NEW_endif endif,2. WIN32 #ifndef WIN32 #endif用该宏将真机与模拟器的代码分隔开,一. GPIO口的初使化与使用, GPIO口
2、的初始化方法:两种:1.工具 customdrvDrv_ToolDrvGen.exe修改: customdrvmisc_drvIWIT23_NEP_07A_PMJ_BBcodegencodegen.dws2.程序中修改:Gpio_drv.c void GPIO_init(void) 操作1. 写状态a. 模式修改GPIO_ModeSetup(kal_uint16 pin, kal_uint16 conf_dada)b. 方向修改void GPIO_InitIO(char direction, char port)c. 置高与置低GPIO_WriteIO(char data, char port
3、),d. 上拉与下拉的使能 void GPIO_PullenSetup(kal_uint16 pin, kal_bool enable)2. 读取状态a. 返回模式 char GPIO_ReturnMode(char port);b. 返回方向 char GPIO_ReturnDir(char port);c. 返回电平值 char GPIO_ReturnDout(char port); 3. GPIO使用中需注意的问题,二.中断的配置与使用,. 中断个数8个 EINT0, EINT1为专用中断, EINT2-7 与GPIO等功能复用. 设置中断模式通过DRV_TOOL或Gpio_init(v
4、oid)来初始化,也可在程序中通过 GPIO_ModeSetup(kal_uint16 pin, kal_uint16 conf_dada)随时修改. 中断注册函数在某个TASK中注册中断,建议注册在AUX_TASK中,便于管理EINT_Registration(FLICK_EINT_NO, KAL_TRUE, flick_state, FLICK_EINT_HISR, KAL_TRUE);. 中断处理函数 以FLICK及BATTERY两个中断为例:,void FLICK_EINT_HISR(void) /added by Jeff Ji 071024 ilm_struct *flick_il
5、m;aux_id_struct *aux_id_data;if (flick_state = LEVEL_HIGH)aux_id_data = (aux_id_struct*)construct_local_para(sizeof(aux_id_struct), TD_CTRL);aux_id_data-aux_id = AUX_ID_FLICK_OFF; DRV_BuildPrimitive(flick_ilm,MOD_EINT_HISR,MOD_UEM,MSG_ID_AUX_ID,aux_id_data);,elseaux_id_data = (aux_id_struct*)constru
6、ct_local_para(sizeof(aux_id_struct), TD_CTRL);aux_id_data-aux_id = AUX_ID_FLICK_ON;DRV_BuildPrimitive(flick_ilm,MOD_EINT_HISR,MOD_UEM,MSG_ID_AUX_ID, aux_id_data);msg_send_ext_queue(flick_ilm);flick_state = !flick_state;EINT_Set_Polarity(FLICK_EINT_NO,flick_state); ,void BATTERY_EINT_HISR(void) iwit_
7、battery_state = !iwit_battery_state;EINT_Set_Polarity(BAT_EINT_NO,iwit_battery_state);iwit_fakeChargerAct = KAL_TRUE;if(iwit_battery_state = LEVEL_HIGH)/plug outbmt_set_chr_status(bmt_chr_out);bmt_charger_action(KAL_FALSE);else /plug inif(iwit_charger_present)bmt_set_chr_status(bmt_chr_in);bmt_charg
8、er_action(KAL_TRUE); ,三. 键盘配置,5X6键盘 Powerkey单独,第6列 DEVICE_KEY_END Keypad_def.c 配置行列矩阵 Kbd_table.h 定义 DRIVER KEY CODE KeyBrd.c 定义KeyPadMap GlobalConstants.h 定义MMI KEY CODE,四. LCD驱动Lcd_sw.h1. 定义写命令及写数据的函数#define LCD_CtrlWrite_HX8306A(_data) *(volatile kal_uint32 *) LCD_HX8306A_CTRL_ADDR= (_data 2. 定义是
9、否使用DMA方式 #define LCD_CMD_DMA_MODE3. 若是并口屏,要定义LCD接口的位数 #define LCD_18BIT_MODE, Lcd.cvoid LCD_FunConfig(void) MainLCD = void LCD_Init_ST7549T(kal_uint32 bkground, void *buf_addr) void LCD_BlockWrite_ST7549T(kal_uint16 startx,kal_uint16 starty,kal_uint16 endx,kal_uint16 endy) void LCD_EnterSleep_ST7549
10、T(void) void LCD_ExitSleep_ST7549T(void) void LCD_SetContrast_ST7549T(kal_uint8 level), 串口屏 void init_lcd_interface(void) SPI_Initialize();/modified by jeff ji 071024 /* init_lcd_interface() *void lcdSendSerialData(kal_uint8 SerialData, kal_bool rs) #define lcdSendCmd(cmd) lcdSendSerialData(cmd, 0)
11、#define lcdSendData(data) lcdSendSerialData(data,1), 并口屏:void init_lcd_interface(void) kal_uint32 i;REG_LCD_ROI_CTRL=0;CLEAR_LCD_CTRL_RESET_PIN; #if (defined(MT6219)|defined(MT6226)|defined(MT6226M)|defined(MT6227)|defined(MT6223)| defined(MT6223P)SET_LCD_PARALLEL_CE2WR_SETUP_TIME(kal_uint32)2);SET_
12、LCD_PARALLEL_CE2WR_HOLD_TIME(2);SET_LCD_PARALLEL_CE2RD_SETUP_TIME(2);SET_LCD_PARALLEL_WRITE_WAIT_STATE(3);SET_LCD_PARALLEL_READ_LATENCY_TIME(31);SET_LCD_ROI_CTRL_CMD_LATENCY(3,#if (defined(MT6226)|defined(MT6226M)|defined(MT6227)|defined(MT6223)| defined(MT6223P)#if (defined(LCD_16BIT_MODE) SET_LCD_
13、PARALLEL_16BIT_DATA_BUS;/ywm+ 20060518 #elif (defined(LCD_18BIT_MODE)GPIO_ModeSetup(55, 1);*(volatile unsigned short *) 0x801201B0) |= 0x4000;*(volatile unsigned short *) 0x801201D0) |= 0x0001; SET_LCD_PARALLEL_18BIT_DATA_BUS; #elif (defined(LCD_8BIT_MODE)SET_LCD_PARALLEL_8BIT_DATA_BUS;#endif #endif
14、 #if (defined(MT6219)DISABLE_LCD_PARALLEL_SYNC;#endif#endif SET_LCD_CTRL_RESET_PIN;Delayms(100); /* init_lcd_interface() */,五. 音效优化,Speaker Receiver Micphone 模式:normal ; handfree ; headset Nvram_default_audio.c 值的范围 0 - 255 Audcoeff.cFIR 需使用音频测试仪器测出的参数,一般都是normal模式下的参数; handfree模式下的参数要依靠经验和尝试来确定。 co
15、nst unsigned short DG_DL_Speech = 0x1000; const unsigned short DG_Microphone = 0x1400; 以上两个变量为Receiver及Microphone的数字增益,值可以在0x1000至0x2000之间调整,但一般情况下不需调整。使用默认值,而只调整Nvram_default_audio.c当中的模拟增益值的大小即可,audcoeff_default.h#define DEFAULT_SPEECH_LOUDSPK_MODE_PARA 128, 224, 5128, 0, 374, 0, 400, 0 第一个参数范围值0至
16、1024 , 值越大,回声抑制越弱 ; 值越小,回声抑制越强。该值可以用于改善音频的回声及断续。 其它值不建议修改.,_Apply_Mic_Setting对MIC的设置,注意MIC的单端及差分设置 void _apply_mic_setting_c63216(kal_int16 a_lowest) if( afe.mic_src=L1SP_LNA_1 ) /* Headset Mode */*AFE_VAC_CON0 |= 0x0480; /* Switch input source to headset microphone */*AFE_VAC_CON1 |= 0x0040; /* Swi
17、tch on resister string */else /* Normal Mode */*AFE_VAC_CON0 /* Switch off resister string */ ,六. ADC使用,1. 工具配置 2. 系数设置Chr_parameter.c const kal_uint16 adc_volt_factorADC_MAX_CHANNEL 100,100,50,250,50,50,/*NC*/50 /*NC*/, 50为一倍,3. ADC测量 Auxmain.c,七. Touch panel1.MAKE文件中如下配置 TOUCH_PANEL_SUPPORT = MT63
18、01 2. Touch_panel_spi.h#define SPI_DIN_PIN gpio_tp_spi_din_pin /*GPO*/#define SPI_CLK_PIN gpio_tp_spi_clk_pin /*GPO*/ #define SPI_DOUT_PIN gpio_tp_spi_dout_pin /*GPI*/ #define SPI_CS_PIN gpio_tp_spi_cs_pin /*GPO*/ #define SPI_BUSY_PIN gpio_tp_spi_busy_pin /*GPI*/ 3. Touch_panel_custom.h #define TOUC
19、H_PANEL_COORD_X_START 0 #define TOUCH_PANEL_COORD_X_END 239 #define TOUCH_PANEL_COORD_Y_START 0 #define TOUCH_PANEL_COORD_Y_END 319,八. USB 1. MAKE文件中 _CHARGER_USB_DETECT_WIHT_ONE_EINT_USB_ENABLE_USB_IN_NORMAL_MODE_SUPPORT = TRUE 2. ADC配置,工具配置ADC_CHR_USB 3. Chr_parameter.c const kal_uint16 adc_volt_f
20、actorADC_MAX_CHANNEL 100,100,50,250,50,50,/*NC*/50 /*NC*/,九. UART串口初始化Uart.c中,void UART_HWInit(UART_PORT port)UARTDCBStruct UART_DefaultConfig =UART_BAUD_115200, /* baud; */len_8, /* dataBits; */sb_1, /*stopBits; */pa_none, /* parity; */fc_none, /*no flow control*/0x11, /* xonChar; */0x13, /* xoffCh
21、ar; */KAL_FALSE;, 关于AT模式串口及Trace模式串口的设置(NVRAM)Nvram_common_config.c static kal_uint8 const NVRAM_EF_PORT_SETTING_DEFAULT = #if defined(_ONLY_ONE_UART_)0x63, 0x00, /* TST uses uart_port2(value is 1) */0x00, 0x00, /* APP uses uart_port1 */ #else0x01, 0x00, /* TST uses uart_port2(value is 1) */0x00, 0x
22、00, /* APP uses uart_port1 */ #endif,#if defined(EMPTY_MMI)0x00, 0x10, 0x0E, 0x00, /* tst default baud rate base = 921600 = 0x000E1000 */ #else0x00, 0xC2, 0x01, 0x00, /* tst default baud rate base = 115200 = 0x0001C200 */ #endif#if defined (_GPRS_MODE_) 0x00, 0xC2, 0x01, 0x00, /* ps default baud rat
23、e base = 115200 = 0x0001C200 */ #else0x00, 0xC2, 0x01,0x00, /* ps default baud rate base = 57600 = 0x0000E100 */ #endif 0x00, /* High SpeedSIM */0x00, /* SWDBG */ 0x03, 0x63, /* uart power setting, plus 1-byte padding */0x00, 0x00,0x00, 0x00 /* CTI baud rate */ ;,十. 充电控制,1. 充电器检测EINT 配置 2. 充电开始与停止bm
24、t_charge_start();bmt_charge_end();3.充电电流控制 Pmu.c pmu_chr_cur_level pmu_ret_chr_current(void) 4. 电池电量等级kal_uint32 const NVRAM_EF_CUST_HW_LEVEL_TBL_DEFAULT = 5. chr_parameter.c,十一. 工厂测试模式,1. FactoryModeSrc.c const testlet TestsMAX_AUTO_TEST_ITEMS 2. Nvram_common_config.c static kal_uint8 const NVRAM_E
25、F_AUTOTEST_DEFAULTNVRAM_EF_AUTOTEST_SIZE ,十二. 其它, WDT的使用 调试时使用, 在出现死循环情况时. void WDT_Enable(kal_bool en) 将该函数默认为Disable. 但当RAM CRUSH掉后,无效. void DRV_RESET(void)LCD, 键盘背光及马达控制 Uem_gpio.c kal_bool custom_cfg_gpio_set_level(kal_uint8 gpio_dev_type, kal_uint8 gpio_dev_level ),3.工程模式 *#3646633# 4. META工具的使用 5. 总的初始化函数 Init.c 中 void Application_Initialize (void *first_available_memory),