//------------------------------------------------------------------ void keypad_4x4_scan() { int value=0; BBBIO_GPIO_low(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_13); //line 1 value = BBBIO_GPIO_get(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_12 |BBBIO_GPIO_PIN_10 |BBBIO_GPIO_PIN_8 |BBBIO_GPIO_PIN_6 ); BBBIO_GPIO_high(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_13); key_status[0][0] = value >> 6 & 0x01; key_status[0][1] = value >> 8 & 0x01; key_status[0][2] = value >> 10 & 0x01; key_status[0][3] = value >> 12 & 0x01; BBBIO_GPIO_low(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_11); //line 2 value = BBBIO_GPIO_get(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_12 |BBBIO_GPIO_PIN_10 |BBBIO_GPIO_PIN_8 |BBBIO_GPIO_PIN_6 ); BBBIO_GPIO_high(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_11); key_status[1][0] = value >> 6 & 0x01; key_status[1][1] = value >> 8 & 0x01; key_status[1][2] = value >> 10 & 0x01; key_status[1][3] = value >> 12 & 0x01; BBBIO_GPIO_low(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_9); //line 3 value = BBBIO_GPIO_get(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_12 |BBBIO_GPIO_PIN_10 |BBBIO_GPIO_PIN_8 |BBBIO_GPIO_PIN_6 ); BBBIO_GPIO_high(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_9); key_status[2][0] = value >> 6 & 0x01; key_status[2][1] = value >> 8 & 0x01; key_status[2][2] = value >> 10 & 0x01; key_status[2][3] = value >> 12 & 0x01; BBBIO_GPIO_low(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_7); //line 4 value = BBBIO_GPIO_get(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_12 |BBBIO_GPIO_PIN_10 |BBBIO_GPIO_PIN_8 |BBBIO_GPIO_PIN_6 ); BBBIO_GPIO_high(BBBIO_GPIO2 ,BBBIO_GPIO_PIN_7); key_status[3][0] = value >> 6 & 0x01; key_status[3][1] = value >> 8 & 0x01; key_status[3][2] = value >> 10 & 0x01; key_status[3][3] = value >> 12 & 0x01; }
void bbio::open(){ // GPIO init init(); init_pins(); // ALL 5 pins are HIGH except for GND init_DAConvAD5328(); //BBBIO init iolib_init(); BBBIO_sys_Enable_GPIO(BBBIO_GPIO1); BBBIO_GPIO_set_dir(BBBIO_GPIO1 , port_dout_SPI[0] , port_din_SPI[0] | port_clk_SPI[0] | port_cs_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_din_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_cs_SPI[0]); }
//----------------------------------------------------------------- void ActionRun() { static int RunCounter=0; int LowValue =0; int HighValue =0; // assian pin value if(PulseQueue[SM_BUTTOM][RunCounter]==0) // p8_11 LowValue |= BBBIO_GPIO_PIN_13 ; else HighValue |= BBBIO_GPIO_PIN_13 ; if(PulseQueue[SM_ARM1][RunCounter]==0) // p8_12 p8_15 LowValue |= (BBBIO_GPIO_PIN_12 | BBBIO_GPIO_PIN_15) ; else HighValue |= (BBBIO_GPIO_PIN_12 | BBBIO_GPIO_PIN_15 ); if(PulseQueue[SM_ARM2][RunCounter]==0) // p8_16 LowValue |= BBBIO_GPIO_PIN_14 ; else HighValue |= BBBIO_GPIO_PIN_14 ; if(PulseQueue[SM_ARM3][RunCounter]==0) LowValue |= BBBIO_GPIO_PIN_5 ; else HighValue |= BBBIO_GPIO_PIN_5 ; if(PulseQueue[SM_HAND][RunCounter]==0) LowValue |= BBBIO_GPIO_PIN_4 ; else HighValue |= BBBIO_GPIO_PIN_4 ; // write logic to GPIO if(HighValue !=0) BBBIO_GPIO_high(BBBIO_GPIO1 , HighValue); if(LowValue !=0) BBBIO_GPIO_low(BBBIO_GPIO1 , LowValue); // add run counter RunCounter ++ ; if(RunCounter ==PulseIndex) { RunCounter =0; PulseFlag =0; } }
void SPI_read() { unsigned long pin_num=0x00; unsigned long sVal[NUM_ADC]; unsigned long commandout=0x00; /* SPI */ for(pin_num=0;pin_num<NUM_ADC_PORT;pin_num++){ for(int j=0;j<NUM_ADC;j++){ sVal[j]=0x00; } // set CS BBBIO_GPIO_high(BBBIO_GPIO1 ,port_cs_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0] | port_din_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_cs_SPI[0]); commandout=pin_num; commandout|=0x18; commandout<<=3; //wait_SPI(); for(int i=0;i<5;i++){ if(commandout&0x80){ BBBIO_GPIO_high(BBBIO_GPIO1 ,port_din_SPI[0]); } else{ BBBIO_GPIO_low(BBBIO_GPIO1 ,port_din_SPI[0]); } commandout<<=1; BBBIO_GPIO_high(BBBIO_GPIO1 ,port_clk_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0]); } //sleep(1); for(int i=0;i<2;i++){ BBBIO_GPIO_high(BBBIO_GPIO1 ,port_clk_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0]); } for(int i=0;i<12;i++){ BBBIO_GPIO_high(BBBIO_GPIO1 ,port_clk_SPI[0]); for(int j=0;j<NUM_ADC;j++){ sVal[j]<<=1; } for(int j=0;j<NUM_ADC;j++){ if(BBBIO_GPIO_get(BBBIO_GPIO1 ,port_dout_SPI[j])){ sVal[j]|=0x01; } } BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0]); } for(int j=0;j<NUM_ADC;j++){ SPI_sensor_value[j][pin_num]=sVal[j]; } } }
void bbio::close(){ BBBIO_GPIO_low(BBBIO_GPIO1 ,port_din_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_cs_SPI[0]); iolib_free(); }