123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #include "includes.h"
- //////////////////////封装一下AT接口/////////////////////////////////
- void msgAtSend(char *at){
- #ifndef USE_BND_POC
- ohpoc_msg_send(at, strlen(at));
- #else
- //broad_send_at(at);
- ModemSendAt(at);
- #endif
-
- }
- void msgAtSends(char *at ,int len){
- #ifndef USE_BND_POC
- ohpoc_msg_send(at, len);
- #else
- ModemSendAt(at);//发送至模块
- #endif
- }
- //////日志打印口配置/////////////////
- void my_usb_evt_cb(lsUSBEvent_t event, unsigned long p){
- LSAPI_OSI_Event_t usb_event;
- usb_event.id = OHPOC_EVENT_USB;
- usb_event.param1=event;
- //wlog_info("my_usb_evt_cb:%d",event);
- osiEventTrySend((LSAPI_OSI_Thread_t *)p, &usb_event, 0);
- }
- LSAPI_Device_USBConfig_t usb_cfg = {
- .name = LSAPI_DEV_USB_COM7,
- .event_cb = my_usb_evt_cb,
- };
- bool usbThreadExit=false;
- LSAPI_Device_t *usbdev=NULL;
- LSAPI_OSI_Thread_t *gUsbWRTd;
- static void usbPortHandler(void *param){
- int ret;
- unsigned char buffer[100];
- LSAPI_OSI_Event_t waitevent;
- LSAPI_Log_Debug("usb create ok");
- while(usbThreadExit==false){
- LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent);
- if(waitevent.param1==LS_USB_EVENT_RX_ARRIVED){
- while(LSAPI_Device_ReadAvail(usbdev)>0){
- ret = LSAPI_Device_Read(usbdev, buffer, sizeof(buffer));
- if(ret< sizeof(buffer)) buffer[ret]=0;
- usbCmdHandler(buffer,ret);
- }
- //WakeupNow("usbCallBack");
- }
- }
- LSAPI_Log_Debug("usbPortHandler exit");
- LSAPI_Device_Close(usbdev);
- gUsbWRTd=NULL;
- LSAPI_OSI_ThreadExit();
- }
- static bool logPortInit(void){
- gUsbWRTd=LSAPI_OSI_ThreadCreate("usb", usbPortHandler, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024*32, 4);
- if(gUsbWRTd==NULL) return false;
- usb_cfg.event_cb_ctx = gUsbWRTd;
- usbdev = LSAPI_Device_USBCreateEx(&usb_cfg);
- if(usbdev==NULL){
- usbThreadExit=true;
- LSAPI_Log_Debug("usbex create err");
- return false;
- }
- if(false==LSAPI_Device_Open(usbdev)){
- LSAPI_Log_Debug("usb LSAPI_Device_Open failed");
- return false;
- }
- LSAPI_Device_SetAutoSleep(usbdev, 500);
- LSAPI_Log_Debug("usbComInit done");
- return true;
- }
- void usbOutPut(unsigned char *info, int len){
- if(NULL==usbdev) return;
- if(LSAPI_Device_WriteAvail(usbdev) != -1) LSAPI_Device_Write(usbdev, info,len);
- }
- void usbOutPutStr(unsigned char *info){
- if(NULL==usbdev) return;
- if(LSAPI_Device_WriteAvail(usbdev) != -1) LSAPI_Device_Write(usbdev, info,strlen(info));
- }
- static void lcdInitTask(void *param){
- //MSG_WARN(1,"lcd init thread start");
- if(0==lcdDrv_Init(0)) MSG_INFO(1, "lcd init ok");
- else MSG_INFO(1, "lcd init failed");
- guiInit();
- MSG_WARN(1,"lcd init thread end");
- sutApp.guiStatus=1;
- LSAPI_OSI_ThreadExit();
- }
- static void lcdsInit(void){
- if(NULL==LSAPI_OSI_ThreadCreate("lcdinit", lcdInitTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, LCD_INIT_TASK_THREAD_STACK, 2)){
- MSG_WARN(1,"lcd init thread error");
- return;
- }
- }
- //////////////////gpio及定时器/////////////////////////////
- LSAPI_OSI_Timer_t *pKeytimer_t=NULL;
- LSAPI_OSI_Timer_t *pBackLightTimer_t=NULL;
- bool pkeyTimerCtl=false;
- unsigned short keyStatus=0;
- unsigned short getKeyValue(){return keyStatus;}
- static void startKeyTimer(void){
- if(NULL==pKeytimer_t) return;
- if(pkeyTimerCtl==true) return;
- pkeyTimerCtl=true;
- LSAPI_OSI_TimerStart(pKeytimer_t,KEY_TIMER_TICK);
- }
- void stopKeyTimer(void){
- pkeyTimerCtl=false;
- LSAPI_OSI_TimerStop(pKeytimer_t);
- }
- static unsigned int msTick=0;//用于做应用层的非休眠时定时器
- unsigned int getAppTick(void){return msTick;}
- static void Timeroutcallback(void *param){
- //毿00秒去检测键值状怿去抖势
- //检测按锿
- keyCheck(keyStatus);
- msTick ++;
- //EarDlyCheck();
- if(pkeyTimerCtl==true) LSAPI_OSI_TimerStart(pKeytimer_t,KEY_TIMER_TICK);
- }
- LSAPI_Device_t *LcdBlCtl;
- LSAPI_Device_t *RedGpio;
- LSAPI_Device_t *GreenGpio;
- LSAPI_Device_t *SpkGpio;
- #define RED_GPIO_ID 22
- #define GREEN_GPIO_ID 18
- #define SPK_GPIO_ID 21
- void gpioConfigOutput(void){
- bool write_value = false;
- LSAPI_GpioConfig_t gpioConfig = {0};
- // config property
- gpioConfig.mode = LS_GPIO_OUTPUT;
- gpioConfig.out_level=true;
- // create instance
- gpioConfig.id = GREEN_GPIO_ID;
- RedGpio = LSAPI_Device_GPIOCreate(&gpioConfig);
- gpioConfig.id = RED_GPIO_ID;
- GreenGpio = LSAPI_Device_GPIOCreate(&gpioConfig);
- gpioConfig.id = SPK_GPIO_ID;
- SpkGpio = LSAPI_Device_GPIOCreate(&gpioConfig);
-
- LSAPI_Device_Open(RedGpio);
- LSAPI_Device_Write(RedGpio, (void *)&write_value, 1);
- LSAPI_Device_Open(GreenGpio);
- LSAPI_Device_Write(GreenGpio, (void *)&write_value, 1);
- LSAPI_Device_Open(SpkGpio);
- LSAPI_Device_Write(SpkGpio, (void *)&write_value, 1);
-
- LcdBlCtl=LSAPI_Device_LedCreate(LS_LED_1);
- LSAPI_Device_Open(LcdBlCtl);
- lcdBackList(0);
- }
- void redLedCtl(bool onoff){
- bool write_value = onoff;
- LSAPI_Device_Write(RedGpio, (void *)&write_value, 1);
- }
- void greenLedCtl(bool onoff){
- bool write_value = onoff;
- LSAPI_Device_Write(GreenGpio, (void *)&write_value, 1);
- }
- void spkCtl(bool onoff){
- bool write_value = onoff;
- //bool write_value = 1;
-
- LSAPI_Device_Write(SpkGpio, (void *)&write_value, 1);
- }
- void lcdBackList(char onoff){
- unsigned int led_value;
- if(onoff==0) led_value=0;
- else led_value=1;
- LSAPI_Device_Write(LcdBlCtl, &led_value, 1);
- }
- void startBackLightTimer(int time){
- if(NULL==pBackLightTimer_t) return;
- LSAPI_OSI_TimerStart(pBackLightTimer_t,time);
- }
- static void gpioTask(void *param){
- unsigned int param1,param2,param3;
- LSAPI_OSI_Event_t event = {};
- //创建一个定时器
- if(NULL == pKeytimer_t) pKeytimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), Timeroutcallback, NULL);
- if(NULL == pKeytimer_t) MSG_WARN(1,"gpio timer init failed");
-
- if(NULL == pBackLightTimer_t) pBackLightTimer_t = LSAPI_OSI_TimerCreate(LSAPI_OSI_ThreadCurrent(), backLightCb, NULL);
- if(NULL == pBackLightTimer_t) MSG_WARN(1,"backlight timer init failed");
-
- startKeyTimer();
- gpioConfigOutput();
- uioStatusInit();
- for(;;){
- LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &event);
- param1=event.param1;
- param2=event.param2;
- param3=event.param3;
- if(event.id==OHPOC_EVENT_KEY_NOR) keyHandler((unsigned short)param1,(unsigned char)param2);
- }
- }
- LSAPI_OSI_Thread_t *gGpioTd=NULL;
- static void gpiosInit(void){
- gGpioTd=LSAPI_OSI_ThreadCreate("gpio", gpioTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024*32, 5);
- if(NULL==gGpioTd) MSG_WARN(1,"gpioThread Error");
- else MSG_WARN(1,"gpioThread ok");
- }
- void keySendEvent(unsigned short key, unsigned char keyType){
- threadSendEvent(gGpioTd,OHPOC_EVENT_KEY_NOR, key,keyType,NULL);
- tryWakeupApp();
- }
- //////////////////按键实始化//////////////////////////
- #define POWER_KEY_PRESSED_TIMEOUT (3000)
- typedef struct ls_key{
- bool ready_shutdown;
- LSAPI_OSI_Timer_t *key_timer;
- }lsKey_t;
- static void _lsKeyTimer(void *p){
- lsKey_t *key = (lsKey_t *)p;
- key->ready_shutdown = true;
- }
- static void _lsKeyCB(lskeyMap_t id, lskeyState_t evt, void *p){
- lsKey_t *key = (lsKey_t *)p;
- uint8_t status;
- if (evt & LS_KEY_STATE_PRESS) keyStatus |= (1<<id);
- if (evt & LS_KEY_STATE_RELEASE) keyStatus &= ~(1<<id);
-
- startKeyTimer();
- }
- void keyPadInit(void){
- lsKey_t *key = (lsKey_t *)LSAPI_OSI_Malloc(sizeof(lsKey_t));
- if (key == NULL){
- MSG_WARN(1,"ls_keypad:calloc faild");
- return;
- }
- key->key_timer = LSAPI_OSI_TimerCreate(NULL, _lsKeyTimer, key);
- if (key->key_timer == NULL){
- LSAPI_OSI_Free(key);
- return;
- }
- LSAPI_Device_KeypadCreate(_lsKeyCB, key);
- }
- //////////////////////////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=LSAPI_OSI_UpTimeUs()+time;
- while(LSAPI_OSI_UpTimeUs()<i);
- }
- void paControl(bool status){
- char i=0;
- char PACNT=sutApp.pcant;//
- if(status==true){
- MSG_INFO(1, "PACNT:%d",PACNT);
- for(i=0;i<PACNT;i++){
- spkCtl(true);
- delayUs(2);
- spkCtl(false);
- delayUs(2);
- }
- spkCtl(true);
- }else spkCtl(false);
- }
- ///////////////////////PA控制结束/////////////////////////////////
- /////////////////////PWM//////////////////////////
- void pttBeepStart(bool isMicReq){
- // if(sutApp.volLev<=0) return;//如果音量调到最小,对讲不产生tone音,当然后对讲播放也没有声音了
- // if(true==isMicReq) pwmBeepStart(500, 50);
- // else pwmBeepStart(500, 50);
- }
- void beepStart(int freq){
- // //const unsigned char duty[5]={100,99,98,97,96};
- // //const unsigned char duty[10]={10,9,8,7,6,5,4,3,2,1};
- // int index=getDutyBySpk();
- // if(index==0) return;//最小声时直接不需要播放了
- // pwmBeepStart(freq, index);
- }
- void beepStop(void){
- // nwy_pwm_stop(pwm_p);
- // MSG_INFO(1, "beep stop");
- }
- //////////////////
- void boardInit(void){
- if(logPortInit()==true) MSG_INFO(1, "Log ok");
- gpiosInit();
- CreateSerialAtThead();//
- lcdsInit();
- keyPadInit();
- }
|