123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- #include "includes.h"
- bool usb_log_status=false;
- static void gpiosInit(void);
- static void spiFlashInit(void);
- static void lcdsInit(void);
- void boardInit(void){
- logPortInit();//摰鮋�撌亦��嗆����枏�
- gpiosInit();
- lcdsInit();
- }
- //////////////////////撠��銝�銝𧘹T�亙藁/////////////////////////////////
- void msgAtSend(char *at){
- ohpoc_msg_send(at, strlen(at));
- }
- void msgAtSends(char *at ,int len){
- ohpoc_msg_send(at, len);
- }
- //////////////////////撠��AT�亙藁蝏𤘪�/////////////////////////////////
- //////////////////////�亙�銝脣藁�滨蔭撘�憪?////////////////////////////////
- void logDataCb(const char *data,uint32 length){
- usbCmdHandler(data,length);
- }
- bool logPortInit(void){
- bool ret;
- ret=nwy_usb_serial_reg_recv_cb(logDataCb);
- if(false==ret) OSI_LOGI(0,"nwy_usb_serial_reg_recv_cb failed");
- else{
- usb_log_status=true;
- MSG_INFO(1,"logPortInit ok");
- }
- return ret;
- }
- //////////////////////�亙��枏㫲蝏𤘪�///////////////////////////////
- ///////////////////////GPIOS�嘥��?/////////////////////////////
- unsigned short keyStatus=0;//靽嘥��桀�潛𠶖�?
- unsigned char hpStatus=0;
- const unsigned char keyTable[KS_KEY_MAX]={
- G_KEY_MIC_PTT
- };
- const unsigned char mKeyTable[MKS_KEY_INS]={
- G_KEY_IN1,
- G_KEY_IN2,
- G_KEY_IN3
- };
- static void startKeyTimer(void);
- static void gpioIsqActive(int param){
- unsigned short i;
- tryWakeupApp();//�㗇��桀𢆡雿頣��日�
- startKeyTimer();
- //璉�瘚𧢲芦�𡁏��?撠��潸挽蝵株�keyStatus�喳虾嚗�縧�硋𢆡蝑㗇�雿𨅯銁摰𡁏𧒄�其葉摰峕�
- for(i=0;i<KS_KEY_MAX;i++){
- if(keyTable[i]==param){
- if(0==nwy_gpio_get_value(param)) keyStatus |= 1<<i;
- else keyStatus &= ~(1<<i);
- return;
- }
- }
- }
-
- /*
- pid:gpio_pid
- up_down:0-down,1-up,2-null
- defVal:nwy_low nwy_high
- */
- void gpioOutPutInit(uint32 pid, char up_down,nwy_value_t defVal){
- nwy_gpio_set_direction(pid,nwy_output);//霈曄蔭銝箸䲮�?
- nwy_gpio_pullup_or_pulldown(pid,up_down);
- nwy_gpio_set_value(pid,defVal);
- }
- /*
- pid:gpio_pid
- up_down:0-down,1-up,2-null,3-no_config_up_down
- irq_type:0 銝𠰴�撱?1 銝钅�撱?2 銝𠰴�+銝钅�撱?3 擃?4 雿?
- */
- void gpioInputInit(uint32 pid,char up_down, char irq_type){
- nwy_close_gpio(pid);
- if(nwy_open_gpio_irq_config(pid,irq_type,gpioIsqActive)) nwy_gpio_open_irq_enable(pid);
- if(up_down!=3) nwy_gpio_pullup_or_pulldown(pid,up_down);
- }
- nwy_osiTimer_t *pKeytimer_t = NULL,*pBackLightTimer_t=NULL;
- #ifdef ENABLE_PWM_BEEP
- nwy_osiTimer_t *pPwmTimer=NULL;
- #endif
- bool pkeyTimerCtl=false;
- void startBackLightTimer(int time){
- if(NULL==pBackLightTimer_t) return;
- nwy_start_timer(pBackLightTimer_t,time);
- }
- static void startKeyTimer(void){
- if(NULL==pKeytimer_t) return;
- if(pkeyTimerCtl==true) return;
- pkeyTimerCtl=false;
- nwy_start_timer_periodic(pKeytimer_t,KEY_TIMER_TICK);
- }
- void stopKeyTimer(void){
- pkeyTimerCtl=false;
- nwy_stop_timer(pKeytimer_t);
- }
- static unsigned int msTick=0;//�其��𡁜��典����隡𤑳��嗅��嗅膥
- unsigned int getAppTick(void){return msTick;}
- static void Timeroutcallback(void *param){
- //瘥?00蝘鍦縧璉�瘚钅睸�潛𠶖�?�餅��?
- //璉�瘚𧢲��?
- keyCheck(keyStatus);
- //璉�瘚讠畆�菜��?
- mKeyCheck();
- msTick ++;
- }
- static void pwmTimerCb(void *param);
- static void setPin39OutIsr(void);
- static void gpioTask(void *param){
- unsigned short i;
- nwy_osiEvent_t event = {};
- unsigned int param1,param2,param3;
- MSG_WARN(1,"gpioThread start");
- //�𥕦遣銝�銝芸��嗅膥
- if(NULL == pKeytimer_t) pKeytimer_t = nwy_timer_init(nwy_get_current_thread(), Timeroutcallback, NULL);
- if(NULL == pKeytimer_t) MSG_WARN(1,"gpio timer init failed");
-
- if(NULL == pBackLightTimer_t) pBackLightTimer_t = nwy_timer_init(nwy_get_current_thread(), backLightCb, NULL);
- if(NULL == pBackLightTimer_t) MSG_WARN(1,"backlight timer init failed");
-
- #ifdef ENABLE_PWM_BEEP
- if(NULL == pPwmTimer) pPwmTimer = nwy_timer_init(nwy_get_current_thread(), pwmTimerCb, NULL);
- if(NULL == pPwmTimer) MSG_WARN(1,"pPwmTimer timer init failed");
- #endif
- startKeyTimer();//100ms銝�甈?
-
- //�嘥��𨰦PIO蝖砌辣IO銝箄��?
- gpioOutPutInit(G_SD_PWR, 1, nwy_low);
- gpioOutPutInit(G_KEY_OUT1, 1, nwy_low);
- gpioOutPutInit(G_KEY_OUT2, 1, nwy_low);
- gpioOutPutInit(G_KEY_OUT3, 1, nwy_low);
- gpioOutPutInit(G_LED1, 1, nwy_high);
- gpioOutPutInit(G_LED2, 1, nwy_low);
- gpioOutPutInit(G_POWER_HOLD, 1, nwy_high);//撘��箏��喲�雿讐㩞皞?銝漤�閬���橘�閬���箸𧒄嚗����誘頧臭辣�單㦤�喳虾
- gpioOutPutInit(G_LCD_BL, 1, nwy_low);
- gpioOutPutInit(G_SPK_EN, 1, nwy_low);
- gpioOutPutInit(G_LAN_EN, 1, nwy_low);
- //�嘥��𨰦PIO蝖砌辣IO銝箄��?
- gpioInputInit(G_KEY_MIC_PTT,1,2);//ISR 銝𠹺�撱塚� ���銝𦠜�
-
- gpioInputInit(G_KEY_IN1,1,1);//銝𦠜�颲枏�嚗䔶��滢葉�?
- gpioInputInit(G_KEY_IN2,1,1);
- gpioInputInit(G_KEY_IN3,1,1);
-
- //�嘥��𣇉畆�菜��桃𠶖�?
- keyStatusCtlAll(0);
-
- for(;;){
- nwy_wait_thead_event(nwy_get_current_thread(), &event,0);
- param1=event.param1;
- param2=event.param2;
- param3=event.param3;
- if(event.id==OHPOC_EVENT_KEY_NOR) keyHandler((unsigned short)param1,(unsigned char)param2);
- else if(event.id==OHPOC_EVENT_KEY_MAT) mKeyHandler((unsigned char)param1);
- }
- }
- static void gpiosInit(void){
- if(NULL==nwy_create_thread("gpio", gpioTask, NULL, NWY_OSI_PRIORITY_NORMAL, GPIO_TASK_THREAD_STACK, 5)) MSG_WARN(1,"gpioThread Error");
- else MSG_WARN(1,"gpioThread ok");
- }
- ///////////////////////GPIOS蝏𤘪�////////////////////////////////
- ////////////////////////SPIFLASH�亙藁////////////////////////////
- nwyspiflash_t *flashFp=NULL;
- static void spiFlashInit(void){
- nwyspiflash_t *fp;
- fp=nwy_flash_open(NAME_FLASH_1);
- if(NULL==fp){
- MSG_WARN(1,"nwy_flash_open failed");
- return;
- }
- flashFp=fp;
- //�唳旿霂餃��硋�憪见��滢�
- }
- ////////////////////////SPIFLASH蝏𤘪�////////////////////////////
- ////////////////////////AUTOPWR�亙藁/////////////////////////////
- void autoPwrSms(NWY_SVR_MSG_SERVICE_E msg, uint32_t param)
- {
- MSG_WARN(1,"SrvMsg:%d,%d",msg,param);
- switch(msg){
- case NWY_CAP_IND:MSG_WARN(1,"NWY_CAP_IND");break;
- case NWY_CHARGE_START_IND:MSG_WARN(1,"NWY_CHARGE_START_IND");break;
- case NWY_CHARGE_END_IND:MSG_WARN(1,"NWY_CHARGE_END_IND");break;
- case NWY_WARNING_IND:MSG_WARN(1,"NWY_WARNING_IND");break;
- case NWY_SHUTDOWN_IND:MSG_WARN(1,"NWY_SHUTDOWN_IND");break;
- case NWY_CHARGE_FINISH:MSG_WARN(1,"NWY_CHARGE_FINISH");break;
- case NWY_CHARGE_DISCONNECT:MSG_WARN(1,"NWY_CHARGE_DISCONNECT");break;
- case NWY_CHARGE_FAULT:MSG_WARN(1,"NWY_CHARGE_FAULT");break;
- default:break;
- }
- }
- static void autoPwrInit(void){
- nwy_set_auto_poweroff(3500,3400,20,autoPwrSms);
- }
- /////////////////////////AUTOPWR蝏𤘪�////////////////////////////
- /////////////////////////LCD�亙藁�嘥��?/////////////////////////
- #include "lcdDrv.h"
- static void lcdInitTask(void *param){
- MSG_WARN(1,"lcd init thread start");
- lcdDrv_Init(0);
- guiInit();
- guiTest();
- MSG_WARN(1,"lcd init thread end");
- sutApp.guiStatus=1;
- nwy_exit_thread();
- }
- static void lcdsInit(void){
- if(NULL==nwy_create_thread("lcdinit", lcdInitTask, NULL, NWY_OSI_PRIORITY_NORMAL, LCD_INIT_TASK_THREAD_STACK, 2)){
- MSG_WARN(1,"lcd init thread error");
- return;
- }
- }
- //////////////////////////LCD�亙藁蝏𤘪�///////////////////////////
- //////////////////////////PA�批��亙藁(憭𡝗𦆮雿輻鍂�齿�嚗諹�單㦤FM)///////////////////////////
- //8735
- //#define PA_MODE_AB
- //#define PA_MODE_D
- //#define PA_MODE_FM
- //#define PA_MODE_K
- //#define PA_MODE_MIANTI
- void delayUs(int64_t time){
- int64_t i;
- i=nwy_get_up_time_us()+time;
- while(nwy_get_up_time_us()<i);
- }
- void paControl(bool status){
- char i=0;
- #if 0
- #if defined (PA_MODE_AB)
- #define PACNT 0
- #elif defined (PA_MODE_D)
- #define PACNT 1
- #elif defined (PA_MODE_FM)
- #define PACNT 2
- #elif defined (PA_MODE_K)
- #define PACNT 3
- #elif defined (PA_MODE_MIANTI)
- #define PACNT 4
- #else
- #error "pls select pa control type"
- #endif
- #endif
- char PACNT=sutApp.pcant;
- if(status==true){
- MSG_INFO(1, "PACNT:%d",PACNT);
- for(i=0;i<PACNT;i++){
- CTL_SPK_EN(1);
- delayUs(2);
- CTL_SPK_EN(0);
- delayUs(2);
- }
- CTL_SPK_EN(1);
- }else CTL_SPK_EN(0);
- }
- ///////////////////////PA�批�蝏𤘪�/////////////////////////////////
- static void setPin39OutIsr(void){
- nwy_gpio_set_direction(G_PWR_DET,nwy_output);//餈嗘葵銝滚�隡𡁏瓷銝剜鱏嚗����
- nwy_gpio_pullup_or_pulldown(G_PWR_DET,1);
- //gpioInputInit(G_PWR_DET,1,2);//銝𦠜�嚗䔶���葉�踹��������漤�銝剜鱏鈭�)
- }
- #ifdef ENABLE_PWM_BEEP
- ///////////////////////PWM�批�撘�憪�////////////////////////////////
- static nwy_pwm_t* pwm_p=NULL;
- void pwmDeInitToSleep(void){
- nwy_pwm_deinit(pwm_p);//靚�鍂�穥CD隡𡁜枂�啁蒾撅讐緵鞊�
- }
- static void pwmTimerCb(void *param);
- void pwmBeepStart(int freq, int duty){
- sutPocStatus.beep=1;
- pwm_p=nwy_pwm_init(NAME_PWM_1, freq, duty);//freq,duty
- if(NULL==pwm_p){
- MSG_INFO(1, "PWM init failed");
- sutPocStatus.beep=0;
- return;
- }
- paControl(true);
- nwy_pwm_start(pwm_p);
- MSG_INFO(1, "PWM start");
- if(pPwmTimer!=NULL) nwy_start_timer(pPwmTimer, 100);
- }
- int getDutyBySpk(void){
- unsigned char vol;
- vol=newPara.spkVol;
- if(vol > 10) vol=10;
- //return vol/2;
- return vol;
- }
- void pttBeepStart(bool isMicReq){
- if(true==isMicReq) pwmBeepStart(500, 50);
- else pwmBeepStart(500, 50);
- }
- void beepStart(int freq){
- //const unsigned char duty[5]={100,99,98,97,96};
- int index=getDutyBySpk();
- if(index==0) return;//��撠誩ㄟ�嗥凒�乩���閬�偘�曆�
- pwmBeepStart(freq, index);//�删征瘥�80
- }
- void beepStop(void){
- nwy_pwm_stop(pwm_p);
- MSG_INFO(1, "beep stop");
- }
- static void pwmTimerCb(void *param){//beep 蝏𤘪��滢�
- beepStop();
- sutPocStatus.beep=0;
- }
- #else
- void beepStart(int freq){}
- #endif
- ///////////////////////PWM�批�蝏𤘪�////////////////////////////////
- //////////////////////靽格㺿EQ憓䂿��滨蔭��///////////////////////////////
- void modifyEqData(void){
- const char *handFreeEq="AT+CAVQE=0,1,12,\"01000700c800070002000000800c07000300f4ffa4060f000300fbff9001070000000000e803070000000000d007070000000000a60e070001000000\"\r\n";
-
- msgAtSend(handFreeEq);
- }
- //////////////////////靽格㺿颲枏枂憓䂿��滨蔭///////////////////////////////
- void modifyAudioOutGainConfig(void){
- char cmd[20]="AT+CACCP=0,1,2,\"";
- unsigned char alg1=211,alg2=0xff;
- unsigned char dac=125;//default=46
- int i;
- msgAtSend(cmd);
- for(i=0;i<16;i++){
- if(i==15){
- alg1=0;
- alg2=0;
- }
- snprintf(cmd, sizeof(cmd), "0000%02x00%02x%02x0000", dac,alg1,alg2);
- msgAtSend(cmd);
- alg1 += 3;
- }
- msgAtSend("\"\r\n");
- }
|