編輯:關於Android編程
內核空間:利用內核中現有的GPIO驅動輸出高低電平,使用內核軟中斷防止模擬時序時被中斷導致延時誤差大;GPIO設備讀取數據後引發軟中斷產生模擬IR。
代碼:
1. .h文件中的數據結構以及宏定義
struct IR_CODE { U16 uHead; U8 uScancode; U8 bOutreverse; }; typedef struct GPIO_Reg GPIO_Reg_t; typedef struct IR_CODE IR_CODE_t; //add by yanxi for ir out start 140117 #define IR_HEAD0 0 #define IR_HEAD1 1 #define IR_TIME_BASE 2 #define IR_CODE_0 3 #define IR_CODE_1 4 #define IR_CODE_END 5 //38k = 26.315us #define TIMER_9000US 342 #define TIMER_4500US 171 #define TIMER_560US 21 #define TIMER_1680US 63 //add by yanxi for ir out end 140117
2.當用戶空間寫數據到設備節點時, _MDrv_GPIO_Write被執行,通過copy_from_user 獲取IR數據,並使用_MDrv_GPIO_SendIR發送IR
static ssize_t _MDrv_GPIO_Write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { IR_CODE_t mIR_CODE_t; GPIO_PRINT("%s is invoked\n", __FUNCTION__); copy_from_user(&mIR_CODE_t, (IR_CODE_t __user *) buf, sizeof(IR_CODE_t)); printk("\n yanxidebug uHead:%x uScancode:%x bOutreverse:%d",mIR_CODE_t.uHead,mIR_CODE_t.uScancode,mIR_CODE_t.bOutreverse); _MDrv_GPIO_SendIR((unsigned int)mIR_CODE_t.uHead,(unsigned int)mIR_CODE_t.uScancode,(BOOL)mIR_CODE_t.bOutreverse); return 0; }
static void _MDrv_GPIO_SendIR(unsigned int Head, int scancode, BOOL bOutreverse) { GPIO_PRINT("\n %s Head:%d scancode:%d bOutreverse:%d\n", __FUNCTION__,Head,scancode,bOutreverse); mHead = Head; mscancode = scancode; mbOutreverse = bOutreverse; raise_softirq(SENDIR_SOFTIRQ); }
int irq_handle_function(int irq, void *device_id) { GPIO_PRINT("\n %s \n", __FUNCTION__); S8 TranselateBitPos; U8 Ir_trans_sta; int mcount = 0; unsigned int head = 0x007f; U8 head0 = head >> 8; U8 head1 = head &0x00ff; U16 mkeycode = mscancode; BOOL outreverse = true; //init state Ir_trans_sta=IR_HEAD0; TranselateBitPos=32; //send ir code while(TranselateBitPos>=0) { mcount = 0; switch(Ir_trans_sta) { case IR_HEAD0: Ir_trans_sta= IR_HEAD1; if(outreverse) { mcount = TIMER_9000US; } else { MHal_GPIO_Set_Low(0); mdelay(9); } break; case IR_HEAD1: Ir_trans_sta= IR_TIME_BASE; if(!outreverse)//outreverse true { mcount = TIMER_4500US;//output high ;38k } else { MHal_GPIO_Set_High(0);//outreverse false,low vol mdelay(4); udelay(500); } break; case IR_TIME_BASE: if(TranselateBitPos>24) { if( ((head0>>(32-TranselateBitPos)) & 0x1) == 0x1 ) Ir_trans_sta= IR_CODE_1; else Ir_trans_sta= IR_CODE_0; } else if(TranselateBitPos>16) { if( ((head1>>(24-TranselateBitPos)) & 0x1) == 0x1 ) Ir_trans_sta= IR_CODE_1; else Ir_trans_sta= IR_CODE_0; } else if(TranselateBitPos>8) { if( ((mkeycode>>(16-TranselateBitPos))&0x1) == 0x1 ){ Ir_trans_sta= IR_CODE_1; } else { Ir_trans_sta= IR_CODE_0; } } else if(TranselateBitPos>0) { if( ((mkeycode>>(8-TranselateBitPos))&0x1) == 0x1 ) Ir_trans_sta= IR_CODE_0; else Ir_trans_sta= IR_CODE_1; } else { Ir_trans_sta= IR_CODE_END; } if(!outreverse) { MHal_GPIO_Set_Low(0); udelay(560); } else { mcount = TIMER_560US; } break; case IR_CODE_0: Ir_trans_sta= IR_TIME_BASE; if(outreverse) { MHal_GPIO_Set_Low(0); udelay(500); } else { mcount = TIMER_560US; } TranselateBitPos--; break; case IR_CODE_1: Ir_trans_sta= IR_TIME_BASE; if(outreverse) { MHal_GPIO_Set_Low(0); udelay(1680); } else { mcount = TIMER_1680US; } TranselateBitPos--; break; case IR_CODE_END: Ir_trans_sta= IR_HEAD0; MHal_GPIO_Set_High(0); TranselateBitPos=-1;//force to exit. break; default:break; } //38k generate while(mcount-- > 0){ MHal_GPIO_Set_High(0); MHal_GPIO_Set_High(0); MHal_GPIO_Set_High(0); MHal_GPIO_Set_High(0); udelay(11); MHal_GPIO_Set_Low(0); MHal_GPIO_Set_Low(0); MHal_GPIO_Set_Low(0); MHal_GPIO_Set_Low(0); udelay(11); } } return IRQ_NONE; } 完...
一、前言作為一個android開發者,使用xml寫UI,實在是太方便了。最近學習Weex,需要使用css來布局。學成之後,發現使用CSS的Flex布局樣式也非常方便。在c
在今年GDC上發現一個非常有趣的演講,叫做Animating With Math,遂實現之,是講述頂點shader動畫的,舉了幾個經典的例子,但是講者並沒有給代碼,而是像
本文實例為大家分享了Android自定義加載控件,第一次小人跑動的加載效果眼前一亮,相比傳統的PrograssBar高大上不止一點,於是走起,自定義了控件LoadingV
項目開發中需要實現這種效果 多余兩行,兩行最後是省略號,省略號後面是下拉更多 之前用過的是Html.fromHtml去處理圖文混排的,僅僅是文字後圖片或者文字顏色字