void LoopLicht(void)
{
    if(ledOn == 0x08)						//4de bit actief (led: D4)
    {
        ledOn = 0x01;						//1ste bit actief (led: D1)
    }
    else
    {
        ledOn = ledOn << 1; 					//Actieve bit links shiften
    }

    LEDSet(ledOn);
}
Beispiel #2
0
void Robot::DisabledPeriodic() {
	CheesyVisionServer *cheeseView = CheesyVisionServer::GetInstance();

	if(oi->getDriverJoystickRight()->GetRawButton(7))
		SMDB();
	driveTrain->CheckForTurns();
	
	//SmartDashboard::PutNumber("AutoChooser", (int)autoProgram);
	
	pickup->beaterBarOut->Set(false);
	pickup->wings->Set(false);
	
	Scheduler::GetInstance()->Run();
	
	LEDSet(4);
	//KinectInfo
//	SmartDashboard::PutBoolean("TooManyPlayers!!!!!", kinect->GetNumberOfPlayers() <= 1);
//	SmartDashboard::PutBoolean("NoPlayers!!!!!!!", kinect->GetNumberOfPlayers() > 0);
	SmartDashboard::PutBoolean("LeftHand", cheeseView->GetLeftStatus());
	SmartDashboard::PutBoolean("RightHand", cheeseView->GetRightStatus());
	SmartDashboard::PutBoolean("RightSelect", turnDirection == 1);
	SmartDashboard::PutBoolean("LeftSelect", turnDirection == -1);
	//Autonomous Selection Feedback
	switch (static_cast<AutoProgram>((int)(autoChooser->GetSelected())))
	{
	case fire1Side:
		SmartDashboard::PutNumber("AutonomousSelection", 1);
		break;
	case fire1Center:
		SmartDashboard::PutNumber("AutonomousSelection", 2);
		break;
	case fire2DriveForward:
		SmartDashboard::PutNumber("AutonomousSelection", 3);
		break;
	case fire2DriveForwardWide:
		SmartDashboard::PutNumber("AutonomousSelection", 4);
		break;
	case fire2Side:
		SmartDashboard::PutNumber("AutonomousSelection", 5);
		break;
	case fire3FromCenter:
		SmartDashboard::PutNumber("AutonomousSelection", 6);
		break;
	}	
}
Beispiel #3
0
/*
 * Main entry point
 */
int main(void) {

    //=====init green led
    LEDInit();
    LEDSet(1);

    //=====setup eth interface
    uint16_t plen = 0,  dat_p = 0;
    //initialize enc28j60
    enc28j60Init(mymac);



    _delay_ms(100);

    // Magjack leds configuration, see enc28j60 datasheet, page 11 
    // LEDB=yellow LEDA=green
    // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
    // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
    enc28j60PhyWrite(PHLCON,0x476);


    _delay_ms(100);

    //init the ethernet/ip layer:
    init_udp_or_www_server(mymac,myip);
    www_server_port(MYWWWPORT);
    register_ping_rec_callback(PingCallback);


    while(1){

        // handle ping and wait for a tcp packet:
        dat_p = packetloop_arp_icmp_tcp(buf, enc28j60PacketReceive(BUFFER_SIZE, buf));

        // dat_p will be unequal to zero if there is a valid http get
        if(dat_p==0){
            // do nothing
            continue;
        }
        // tcp port 80 begin
        if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
            dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
            dat_p = fill_tcp_data_p(buf, dat_p, PSTR("<h1>200 OK</h1>"));
            goto SENDTCP;
        }
        if (strncmp("/ ",(char *) & (buf[ dat_p + 4] ), 2) == 0 ){
            nAccessCount++;
            dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
            // webcontent
            char szWebText[130] = {0};
            sprintf(szWebText,
                    "<b>ATmega8 Webserver / ENC28J60</b><br><br>Server stats:<br>Acc:%d Png:%d<br><br>(C) Radu Motisan 2012, www.pocketmagic.net<br/>Tomasz Jokiel",
                    nAccessCount, nPingCount);
            dat_p = fill_tcp_data(buf, dat_p, szWebText);
            //
            goto SENDTCP;
        }
        // all other URLs:
        dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
        SENDTCP:
        www_server_reply(buf, dat_p); // send web page data


    }

    return (0);
} 
Beispiel #4
0
void LEDToggle() {
    if (led_state) LEDSet(0); else LEDSet(1);
}
Beispiel #5
0
void Robot::TeleopPeriodic() {
	LEDSet(5);
	
	driveTrain->CheckForTurns();
	
	if(oi->getDriverJoystickRight()->GetRawButton(7))
		SMDB();
		
/******************DRIVETRAIN**************************************/	
	
	//Resets gyro to zero when crab starts
	if (!prevTrigger && oi->getDriverJoystickRight()->GetRawButton(1))
		driveTrain->gyro->Reset();
	
	prevTrigger = oi->getDriverJoystickRight()->GetRawButton(1);
	
	if(oi->getDriverJoystickLeft()->GetRawButton(1) && oi->getDriverJoystickRight()->GetMagnitude() < .1)
	{
		driveTrain->Lock();
		undoTurnsPressed = true;
	}
	else if(oi->getDriverJoystickRight()->GetRawButton(1))
	{
		driveTrain->Crab(oi->getJoystickTwist(),-oi->getJoystickY(),oi->getJoystickX(),true);	
	}
	else 
	{
		driveTrain->Steer(oi->getLeftJoystickXRadians(),oi->getJoystickY(),0.5);
	}
	
/*	if (undoTurnsPressed && !oi->getDriverJoystickLeft()->GetRawButton(1))
	{
		driveTrain->frontLeft->Enable();
		driveTrain->frontRight->Enable();
		driveTrain->rearLeft->Enable();
		driveTrain->rearRight->Enable();
		undoTurnsPressed = false;
	}
*/	
	
/******************SHOOTER**************************************/
	
	if(oi->getGamePad()->GetRawButton(10)){
		if(oi->getGamePad()->GetRawAxis(6) < 0) {
			shooter->Reset();
		}
		else if(oi->getGamePad()->GetRawAxis(6) > 0) {
			shooter->RelieveStress();
		}
		else {
			shooter->RunCams(-oi->getGamePad()->GetRawAxis(2), true);
		}
	}
	else if(oi->getDriverJoystickRight()->GetRawButton(9) || oi->getGamePad()->GetRawButton(9)){
		shooter->RelieveStress();
	}
	else if(oi->getDriverJoystickRight()->GetRawButton(11)){
		shooter->Reset();
	}
	else {
		shooter->CamChecker(); //Runs every cycle to control cam postion
		if((oi->getDriverJoystickRight()->GetRawButton(3)) && !shooter->GetFiring()) {
			if(!pickup->beaterBarOut->Get())
				beaterBarTimer->Reset();
			pickup->beaterBarOut->Set(true);
			shooter->Fire(0.6 - beaterBarTimer->Get(), true);
		}
		else if (oi->getDriverJoystickRight()->GetRawButton(2)) {
			shooter->Fire(0,false);
		}
	}
	
	
	shooter->fingers->Set(oi->getGamePad()->GetRawButton(2));
	
/******************WINGS**************************************/
	
	if(oi->getGamePad()->GetRawButton(7))
		pickup->wings->Set(true);
	if(oi->getGamePad()->GetRawButton(5))
		pickup->wings->Set(false);
	
	
/******************BEATERBAR**************************************/	
	
	if(fabs(oi->getGamePad()->GetRawAxis(4)) > fabs(oi->getGamePad()->GetRawAxis(2))) {
		pickup->beaterBar->Set((oi->getGamePad()->GetRawAxis(4)));
	}
	else
		pickup->beaterBar->Set(oi->getGamePad()->GetRawAxis(2));
	
	if(oi->getDriverJoystickLeft()->GetRawButton(4))
		pickup->beaterBar->Set(1);
	
	if(oi->getDriverJoystickLeft()->GetRawButton(5))
		pickup->beaterBar->Set(-1);
	
	if ((oi->getGamePad()->GetRawButton(8) || oi->getDriverJoystickLeft()->GetRawButton(2)) && !pickup->beaterBarOut->Get()) {
		pickup->beaterBarOut->Set(true);
		beaterBarTimer->Reset();
	}
	if (oi->getGamePad()->GetRawButton(6) || oi->getDriverJoystickLeft()->GetRawButton(3)) {
		pickup->beaterBarOut->Set(false);
	}
	
	Scheduler::GetInstance()->Run();
}
Beispiel #6
0
void Robot::AutonomousPeriodic() {
	//KinectInfo
	SmartDashboard::PutBoolean("TooManyPlayers!!!!!", kinect->GetNumberOfPlayers() <= 1);
	SmartDashboard::PutBoolean("NoPlayers!!!!!!!", kinect->GetNumberOfPlayers() > 0);
	SmartDashboard::PutBoolean("LeftHand", KinectLeftSelect());
	SmartDashboard::PutBoolean("RightHand", KinectRightSelect());
	SmartDashboard::PutBoolean("RightSelect", turnDirection == 1);
	SmartDashboard::PutBoolean("LeftSelect", turnDirection == -1);
	
	driveTrain->CheckForTurns();
	
	if(oi->getDriverJoystickRight()->GetRawButton(7))
		SMDB();
//	if (autonomousTimer->HasPeriodPassed(1))
//		LEDSet(4);
	LEDSet(7);
	if(autoStep != FirstResetShooter && autoStep != FirstTurn && autoStep !=DriveForwardFirstTurn && autoStep != DriveForwardReset) {
		shooter->CamChecker();
	}
	
	
	switch(autoStep) {
	
	case ResetShooterAndCollect:
		x = 0;
		y = 0;
		if(autoStepTimer->HasPeriodPassed(.2)){
			if(pickup->beaterBar->GetOutputCurrent() >= peakBeaterBarCurrent) {
				peakBeaterBarCurrent = pickup->beaterBar->GetOutputCurrent();
				ballCollectedInc = 0;
			}
			else
				ballCollectedInc++;
		}
		pickup->beaterBar->Set(1);
		SmartDashboard::PutString("AutoStep", "ResetShooter");
		if(shooter->GetResetCamComplete() && (ballCollectedInc > 50 || autoStepTimer->HasPeriodPassed(1.5))) {
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
			ballCollectedInc = 0;
		}
		break;
		
	case FirstResetShooter:
		x = 0;
		y = 0;
		
		if(!shooter->GetResetCamComplete()) {
			shooter->Reset();
			pickup->beaterBar->Set(-.25);
		}
		else {
			shooter->CamChecker();
		}
		if(turnDirection == 0) {
			if(KinectLeftSelect() || autoStepTimer->HasPeriodPassed(2.0)) {
				turnDirection = -1;
			}
			else if (KinectRightSelect()) {
				turnDirection = 1;
			}
		}
		
		SmartDashboard::PutString("AutoStep", "FirstResetShooter");
		if(turnDirection != 0 && autoStepTimer->HasPeriodPassed(0.25)) {
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
		}
		break;
		
	case WaitToFire50:
		x = 0;
		y = 0;
		SmartDashboard::PutString("AutoStep", "FindTarget");
		if(autonomousTimer->HasPeriodPassed(5.0))
			autoStepComplete = true;
		break;
		
	case WaitToFire75:
		x = 0;
		y = 0;
		SmartDashboard::PutString("AutoStep", "FindTarget");
		if(autonomousTimer->HasPeriodPassed(7.5))
			autoStepComplete = true;
		break;
		
	case WaitForHot:
		if(KinectLeftSelect() || KinectRightSelect())
			autoStepComplete = true;
		SmartDashboard::PutString("AutoStep", "WaitForHot");
		break;
		
	case FirstTurn:
		twist = turnDegree*turnDirection;
		x = 0;
		y = 0;
		if(!shooter->GetResetCamComplete()) {
			shooter->Reset();
			if(autoProgram == fire3FromCenter){
				pickup->beaterBar->Set(-.25);
			}
			else if(!autoStepTimer->HasPeriodPassed(0.25)){
				pickup->beaterBar->Set(.25);
			}
			else
				pickup->beaterBar->Set(0);
			
		}
		else {
			shooter->CamChecker();
		}
		driveTrain->DriveControlTwist->SetPID(.035, 0, .15);
		SmartDashboard::PutString("AutoStep", "FirstTurn");
		if(!driveTrain->DriveControlTwist->OnTarget()) {
			onTargetTimer->Reset();
		}
		if(onTargetTimer->HasPeriodPassed(.2) && shooter->GetResetCamComplete()){
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
		}
		break;
		
	case DriveForwardReset:
		driveTrain->DriveControlTwist->SetPID(.010, 0, .05);		
		x = 0;
		y = -.5;
		twist = 0;
		
		if(!shooter->GetResetCamComplete()) {
			shooter->Reset();
			pickup->beaterBar->Set(-.25);
			}
		else {
			shooter->CamChecker();
		}
		SmartDashboard::PutString("AutoStep", "DriveForwardReset");
		if(autoStepTimer->HasPeriodPassed(1.3) && shooter->GetResetCamComplete()) {
			autoStepComplete = true;
			x = 0;
			y = 0;
			twist = 0;
		}
		break;
		
	case DriveForwardFirstTurn:
		
		if(pickup->ballInPickup->Get() == 1) {
			pickup->beaterBar->Set(.75);
		}
		else {
			pickup->beaterBar->Set(0);
		}
		
		if(turnDirection == 0) {
			if(KinectLeftSelect() || autoStepTimer->HasPeriodPassed(2.5)) {
				turnDirection = -1;
			}
			else if (KinectRightSelect()) {
				turnDirection = 1;
			}
		}
		if(!autoStepTimer->HasPeriodPassed(1.45)) {
			x = 0;
			y = -.5;
			twist = 0;
			driveTrain->DriveControlTwist->SetPID(.010, 0, .05);
		}
		else {
			x = 0;
			y = 0;
			twist = turnDegree*turnDirection;
			driveTrain->DriveControlTwist->SetPID(.040, 0, .15);
		}
		
		if(!shooter->GetResetCamComplete()) {
			shooter->Reset();
			}
		else {
			shooter->CamChecker();
		}
		
		SmartDashboard::PutString("AutoStep", "DriveForwardFirstTurn");
		
		if(turnDirection != 0 && (KinectRightSelect() || KinectLeftSelect())) {
			turnDegree = 20;
		}
		else
			turnDegree = 10;
		
		SmartDashboard::PutBoolean("Wide", turnDegree > 15);
		
		if(!driveTrain->DriveControlTwist->OnTarget() || turnDirection == 0 || twist == 0) {
			onTargetTimer->Reset();
		}
		if(turnDirection != 0 && onTargetTimer->HasPeriodPassed(1.0) && shooter->GetResetCamComplete()){
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
			x = 0;
			y = 0;
		}
		break;
	
	case SecondTurn:
		twist = turnDegree*-turnDirection;
		x = 0;
		y = 0;
		driveTrain->DriveControlTwist->SetPID(.035, 0, .15);
		pickup->beaterBar->Set(-.25);
		SmartDashboard::PutString("AutoStep", "SecondTurn");
		
		if((KinectRightSelect() || KinectLeftSelect())) {
			turnDegree = 20;
		}
		else
			turnDegree = 10;
		
		SmartDashboard::PutBoolean("Wide", turnDegree > 15);
		
		if(!driveTrain->DriveControlTwist->OnTarget()) {
			onTargetTimer->Reset();
		}
		if(onTargetTimer->HasPeriodPassed(.2) && shooter->GetResetCamComplete()){
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
		}
		break;
		
	case Fire:
		x = 0;
		y = 0;
		shooter->Fire(0, false);
		SmartDashboard::PutString("AutoStep", "Fire");
		if(shooter ->GetCorrectedCamPos() < 4.5 && shooter->GetCorrectedCamPos() > 4.0)
			autoStepComplete = true;
		break;
			
	case Chill:
		x = 0;
		y = 0;
		SmartDashboard::PutString("AutoStep", "Chill");
		if(autoStepTimer->HasPeriodPassed(.5))
			autoStepComplete = true;
		break;
	
	case CollectBall:
		pickup->beaterBar->Set(1);
		x = 0;
		y = 0;
		if(autoStepTimer->HasPeriodPassed(.2) && pickup->beaterBar->GetOutputCurrent() >= peakBeaterBarCurrent) {
			peakBeaterBarCurrent = pickup->beaterBar->GetOutputCurrent();
			ballCollectedInc = 0;
		}
		else
			ballCollectedInc++;
		SmartDashboard::PutString("AutoStep", "CollectBall");
		if(autoStepTimer->HasPeriodPassed(1.5) || ballCollectedInc >= 50) {
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
			peakBeaterBarCurrent = 0;
			ballCollectedInc = 0;
		}
		break;
		
		
	case LoadBall:
		pickup->beaterBarOut->Set(false);
		pickup->beaterBar->Set(-.5);
		x = 0;
		y = 0;
		SmartDashboard::PutString("AutoStep", "LoadBall");
		if(autoStepTimer->HasPeriodPassed(.2)){
			autoStepComplete = true;
		}
		break;
		
	case DropPickup:
		pickup->beaterBarOut->Set(true);
		if(autoStepTimer->HasPeriodPassed(.2)) {
			pickup->beaterBar->Set(.5);
		}
		x = 0;
		y = 0;
		SmartDashboard::PutString("AutoStep", "DropPickup");
		if(autoStepTimer->HasPeriodPassed(0.6)) {
			autoStepComplete = true;
			pickup->beaterBar->Set(0.0);
		}
		break;
	
	case DriveForward:
		x = 0;
		y = -1.0;
		pickup->beaterBar->Set(-.5);
		SmartDashboard::PutString("AutoStep", "DriveForward");
		if(autoStepTimer->HasPeriodPassed(.75)) {
			autoStepComplete = true;
			pickup->beaterBar->Set(0);
		}
		break;
		
	case End:
		x = 0;
		y = 0;
		SmartDashboard::PutString("AutoStep", "End");
		break;
	}
	
	driveTrain->DriveControlTwist->SetSetpoint(twist);
	driveTrain->Crab(driveTrain->CrabSpeedTwist->Get(), y, x, true);
	
/***********************Increment Through Program****************************/	
	if (autoStepComplete) {
		autoStepTimer->Reset();
		autoStepComplete = false;
		autoStepIncrementer ++;
		onTargetTimer->Reset();
		try {
			autoStep = genericAutoProgram.at(autoStepIncrementer);
		}
		catch (const out_of_range& oor) {
			printf ("AutoProgram Vector Out of Range \n");
		}
	}
}
Beispiel #7
0
void Robot::AutonomousInit() {
	LEDSet(7);
    autoProgram = static_cast<AutoProgram>((int)(autoChooser->GetSelected()));
	autoStepTimer->Reset();
	autoStepIncrementer = 0;
	turnDirection = 0;
	peakBeaterBarCurrent = 0;
	ballCollectedInc = 0;
	genericAutoProgram.clear();
	autonomousTimer->Reset();
	driveTrain->gyro->Reset();
	x = 0;
	y = 0;
	twist = 0;
	switch(autoProgram) {
	
	case fire1Side:
		genericAutoProgram.push_back(DriveForwardReset);
		genericAutoProgram.push_back(WaitForHot);
		genericAutoProgram.push_back(Fire);	
		genericAutoProgram.push_back(End);				
		break;
		
	case fire1Center:
		genericAutoProgram.push_back(DriveForwardFirstTurn);
		genericAutoProgram.push_back(Fire);
		genericAutoProgram.push_back(End);				
		break;
		
	case fire2Side:
		genericAutoProgram.push_back(DropPickup);
		genericAutoProgram.push_back(DriveForwardReset);
		genericAutoProgram.push_back(WaitForHot);
		genericAutoProgram.push_back(Fire);	
		genericAutoProgram.push_back(ResetShooterAndCollect);
		genericAutoProgram.push_back(LoadBall);
		genericAutoProgram.push_back(Fire);
		genericAutoProgram.push_back(End);		
		break;
		
	case fire2DriveForward: case fire2DriveForwardWide:
		genericAutoProgram.push_back(DropPickup);
		genericAutoProgram.push_back(DriveForwardFirstTurn);
		genericAutoProgram.push_back(Fire);
		genericAutoProgram.push_back(ResetShooterAndCollect);
		genericAutoProgram.push_back(LoadBall);
		genericAutoProgram.push_back(WaitToFire50);
		genericAutoProgram.push_back(SecondTurn);
		//genericAutoProgram.push_back(DropPickup);
		genericAutoProgram.push_back(Fire);
		genericAutoProgram.push_back(End);		
		break;
		
	case fire3FromCenter:
		genericAutoProgram.push_back(FirstResetShooter);
		genericAutoProgram.push_back(FirstTurn);
		genericAutoProgram.push_back(DropPickup);
		genericAutoProgram.push_back(Fire);
		genericAutoProgram.push_back(ResetShooterAndCollect);
		genericAutoProgram.push_back(LoadBall);
		genericAutoProgram.push_back(SecondTurn);
		genericAutoProgram.push_back(DropPickup);
		genericAutoProgram.push_back(WaitToFire50);
		genericAutoProgram.push_back(Fire);		
		genericAutoProgram.push_back(ResetShooterAndCollect);
		genericAutoProgram.push_back(LoadBall);
		genericAutoProgram.push_back(DriveForward);
		genericAutoProgram.push_back(Chill);
		genericAutoProgram.push_back(DropPickup);
		genericAutoProgram.push_back(Fire);
		genericAutoProgram.push_back(End);
		break;
		
	}
	autoStep = genericAutoProgram[autoStepIncrementer];
	
	driveTrain->DriveControlTwist->Enable();
	driveForwardAngle = 0;
//	LEDSet(7);
	//odroid->sendProcessImage->Set(true);

	turnDegree = 13;
	
	if (autoProgram == fire3FromCenter || autoProgram == fire2DriveForwardWide) {
		turnDegree = 20;
	}


}
Beispiel #8
0
static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 
			unsigned long arg)
{
	struct lcd_display button_display;
	unsigned long address, a;
	int index;

	switch (cmd) {
	case LCD_On:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x0F);
		break;		

	case LCD_Off:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x08);
		break;

	case LCD_Reset:
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x01);
		udelay(150);
		LCDWriteInst(0x06);
		break;

	case LCD_Clear:
		udelay(150);
		BusyCheck();
       		LCDWriteInst(0x01);     
		break;

	case LCD_Cursor_Left:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x10);
		break;

	case LCD_Cursor_Right:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x14);
		break;	

	case LCD_Cursor_Off:
		udelay(150);
                BusyCheck();
                LCDWriteInst(0x0C);
	        break;

        case LCD_Cursor_On:
                udelay(150);
                BusyCheck();
                LCDWriteInst(0x0F);
                break;

        case LCD_Blink_Off:
                udelay(150);
                BusyCheck();
                LCDWriteInst(0x0E);
                break;

	case LCD_Get_Cursor_Pos:{
                struct lcd_display display;

		udelay(150);
                BusyCheck();
		display.cursor_address = ( LCDReadInst ); 
		display.cursor_address = ( display.cursor_address & 0x07F );
		if(copy_to_user((struct lcd_display*)arg, &display, sizeof(struct lcd_display)))
		  return -EFAULT;

		break;
		}


	case LCD_Set_Cursor_Pos: {
                struct lcd_display display;

                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
		  return -EFAULT;

		a = (display.cursor_address | kLCD_Addr ); 

                udelay(150);
                BusyCheck();    
                LCDWriteInst( a );

                break;
		}
	
	case LCD_Get_Cursor: {
                struct lcd_display display;

                udelay(150);
                BusyCheck();    
		display.character = LCDReadData;	

		if(copy_to_user((struct lcd_display*)arg, &display, sizeof(struct lcd_display)))
		  return -EFAULT;
                udelay(150);
                BusyCheck();
                LCDWriteInst(0x10);

		break;
		}

	case LCD_Set_Cursor:{
                struct lcd_display display;
   
                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
		  return -EFAULT;

                udelay(150);
		BusyCheck();    
                LCDWriteData( display.character );
                udelay(150);
                BusyCheck();
                LCDWriteInst(0x10);

                break;
                }


	case LCD_Disp_Left:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x18);
		break;

	case LCD_Disp_Right:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x1C);
		break;

	case LCD_Home:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x02);
		break;

	case LCD_Write: {
		struct lcd_display display;
   

                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
		  return -EFAULT;
 
		udelay(150);
                BusyCheck();    
                LCDWriteInst(0x80);
		udelay(150);
		BusyCheck();
	
		for (index = 0; index < (display.size1); index++) {
			udelay(150);
			BusyCheck();	
			LCDWriteData( display.line1[index]);
			BusyCheck();	
		}		
		
		udelay(150);
		BusyCheck();	
		LCDWriteInst(0xC0);	
		udelay(150);
		BusyCheck();	
                for (index = 0; index < (display.size2); index++) {
                        udelay(150);
                        BusyCheck();    
                        LCDWriteData( display.line2[index]);
		}
 
		break;	
	}
	
	case LCD_Read: {	
        	struct lcd_display display;

		BusyCheck();
		for (address = kDD_R00; address <= kDD_R01; address++) {
			a = (address | kLCD_Addr );	

			udelay(150);
			BusyCheck();
			LCDWriteInst( a );
			udelay(150);
			BusyCheck();
			display.line1[address] = LCDReadData;
		}

		display.line1[ 0x27 ] = '\0';
	
		for (address = kDD_R10; address <= kDD_R11; address++) {
			a = (address | kLCD_Addr );     
        
			udelay(150);
	 		BusyCheck();
        		LCDWriteInst( a );
       
        		udelay(150);
	 		BusyCheck();
        		display.line2[address - 0x40 ] = LCDReadData;
		 }

		display.line2[ 0x27 ] = '\0';

		if(copy_to_user((struct lcd_display*)arg, &display,
				sizeof(struct lcd_display)))
		  return -EFAULT;
		break;
	}

//  set all GPIO leds to led_display.leds 

	case LED_Set: {	
		struct lcd_display led_display;
	

	        if(copy_from_user(&led_display, (struct lcd_display*)arg,
				  sizeof(struct lcd_display)))
		  return -EFAULT;

		led_state = led_display.leds;
		LEDSet(led_state);

        	break;
	}


//  set only bit led_display.leds

        case LED_Bit_Set: {
                int i;
		int bit=1;
                struct lcd_display led_display;


                if(copy_from_user(&led_display, (struct lcd_display*)arg,
				  sizeof(struct lcd_display)))
		  return -EFAULT;

		for (i=0;i<(int)led_display.leds;i++)
			{
				bit = 2*bit;	
			}

		led_state = led_state | bit;
                LEDSet(led_state);
                break;
        }

//  clear only bit led_display.leds

        case LED_Bit_Clear: {
                int i;
		int bit=1;
                struct lcd_display led_display;


                if(copy_from_user(&led_display, (struct lcd_display*)arg,
				  sizeof(struct lcd_display)))
		  return -EFAULT;

                for (i=0;i<(int)led_display.leds;i++)
                        {
                                bit = 2*bit;
                        }

		led_state = led_state &  ~bit;
                LEDSet(led_state);
                break;
        }


	case BUTTON_Read: {
		button_display.buttons = GPIRead;
                if(copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
		  return -EFAULT;
		break;
	}

        case LINK_Check: {
                button_display.buttons = *((volatile unsigned long *) (0xB0100060) );
                if(copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
		  return -EFAULT;
                break;
        }

	case LINK_Check_2: {
		int iface_num;

		/* panel-utils should pass in the desired interface status is wanted for
		 * in "buttons" of the structure.  We will set this to non-zero if the
		 * link is in fact up for the requested interface.  --DaveM
		 */
		if(copy_from_user(&button_display, (struct lcd_display *)arg, sizeof(button_display)))
		  return -EFAULT;
		iface_num = button_display.buttons;
#if defined(CONFIG_TULIP) && 0
		if (iface_num >= 0 &&
		    iface_num < MAX_INTERFACES &&
		    linkcheck_callbacks[iface_num] != NULL) {
			button_display.buttons =
				linkcheck_callbacks[iface_num](linkcheck_cookies[iface_num]);
		} else
#endif
			button_display.buttons = 0;

                if(__copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
		  return -EFAULT;
                break;
	}

//  Erase the flash

	case FLASH_Erase: {

		int ctr=0;

		    // Chip Erase Sequence
		WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
		WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
		WRITE_FLASH( kFlash_Addr1, kFlash_Erase3 );
		WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
		WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
		WRITE_FLASH( kFlash_Addr1, kFlash_Erase6 );

		printk( "Erasing Flash.\n");

		while ( (!dqpoll(0x00000000,0xFF)) && (!timeout(0x00000000)) ) {
		    ctr++;
		}

		printk("\n");
		printk("\n");
		printk("\n");

		if (READ_FLASH(0x07FFF0)==0xFF) { printk("Erase Successful\r\n"); }
		else if (timeout) { printk("Erase Timed Out\r\n"); }

	break;
	}

// burn the flash 

	case FLASH_Burn: {

		volatile unsigned long burn_addr;
		unsigned long flags;
		int i;
		unsigned char *rom;
		

                struct lcd_display display;

                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
		  return -EFAULT;
		rom = (unsigned char *) kmalloc((128),GFP_ATOMIC);
                if ( rom == NULL ) {
                       printk ("broken\n");
                       return 1;
                   }

		printk("Churning and Burning -");
		save_flags(flags);
		for (i=0; i<FLASH_SIZE; i=i+128) {

		        if(copy_from_user(rom, display.RomImage + i, 128))
			   return -EFAULT;
			burn_addr = kFlashBase + i;
			cli();
			for ( index = 0; index < ( 128 ) ; index++ ) 
		  	  {

				WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
		 	    	WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
		 	    	WRITE_FLASH( kFlash_Addr1, kFlash_Prog );
		 	    	*((volatile unsigned char *)burn_addr) = (volatile unsigned char) rom[index];

		   	 	 while ( (!dqpoll(burn_addr,(volatile unsigned char) rom[index])) && (!timeout(burn_addr)) ) {
		  	   		}
		  	   	burn_addr++;
		  	  }
			restore_flags(flags);
                	if ( *((volatile unsigned char *)(burn_addr-1)) == (volatile unsigned char) rom[index-1]  ) {
               		 } else if (timeout) {
                	    printk("Program timed out\r\n");
               		 }


		}
		kfree(rom);

	break;
	}

//  read the flash all at once 
	
	case FLASH_Read: {

		unsigned char *user_bytes;
                volatile unsigned long read_addr;
                int i;

		user_bytes = &(((struct lcd_display *)arg)->RomImage[0]);

		if(!access_ok(VERIFY_WRITE, user_bytes, FLASH_SIZE))
                         return -EFAULT;

		printk("Reading Flash");
		for (i=0; i<FLASH_SIZE; i++) {
			unsigned char tmp_byte;
			read_addr = kFlashBase + i;
			tmp_byte = *((volatile unsigned char *)read_addr);
			if(__put_user (tmp_byte, &user_bytes[i]))
			  return -EFAULT;
		}


	break;
	}





	default:
		return 0;
	break;

	}

	return 0;

}
Beispiel #9
0
static int lcd_ioctl(struct inode *inode, struct file *file,
		     unsigned int cmd, unsigned long arg)
{
	struct lcd_display button_display;
	unsigned long address, a;

	switch (cmd) {
	case LCD_On:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x0F);
		break;

	case LCD_Off:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x08);
		break;

	case LCD_Reset:
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x3F);
		udelay(150);
		LCDWriteInst(0x01);
		udelay(150);
		LCDWriteInst(0x06);
		break;

	case LCD_Clear:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x01);
		break;

	case LCD_Cursor_Left:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x10);
		break;

	case LCD_Cursor_Right:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x14);
		break;

	case LCD_Cursor_Off:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x0C);
		break;

	case LCD_Cursor_On:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x0F);
		break;

	case LCD_Blink_Off:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x0E);
		break;

	case LCD_Get_Cursor_Pos:{
			struct lcd_display display;

			udelay(150);
			BusyCheck();
			display.cursor_address = (LCDReadInst);
			display.cursor_address =
			    (display.cursor_address & 0x07F);
			if (copy_to_user
			    ((struct lcd_display *) arg, &display,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			break;
		}


	case LCD_Set_Cursor_Pos:{
			struct lcd_display display;

			if (copy_from_user
			    (&display, (struct lcd_display *) arg,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			a = (display.cursor_address | kLCD_Addr);

			udelay(150);
			BusyCheck();
			LCDWriteInst(a);

			break;
		}

	case LCD_Get_Cursor:{
			struct lcd_display display;

			udelay(150);
			BusyCheck();
			display.character = LCDReadData;

			if (copy_to_user
			    ((struct lcd_display *) arg, &display,
			     sizeof(struct lcd_display)))
				return -EFAULT;
			udelay(150);
			BusyCheck();
			LCDWriteInst(0x10);

			break;
		}

	case LCD_Set_Cursor:{
			struct lcd_display display;

			if (copy_from_user
			    (&display, (struct lcd_display *) arg,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			udelay(150);
			BusyCheck();
			LCDWriteData(display.character);
			udelay(150);
			BusyCheck();
			LCDWriteInst(0x10);

			break;
		}


	case LCD_Disp_Left:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x18);
		break;

	case LCD_Disp_Right:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x1C);
		break;

	case LCD_Home:
		udelay(150);
		BusyCheck();
		LCDWriteInst(0x02);
		break;

	case LCD_Write:{
			struct lcd_display display;
			unsigned int index;


			if (copy_from_user
			    (&display, (struct lcd_display *) arg,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			udelay(150);
			BusyCheck();
			LCDWriteInst(0x80);
			udelay(150);
			BusyCheck();

			for (index = 0; index < (display.size1); index++) {
				udelay(150);
				BusyCheck();
				LCDWriteData(display.line1[index]);
				BusyCheck();
			}

			udelay(150);
			BusyCheck();
			LCDWriteInst(0xC0);
			udelay(150);
			BusyCheck();
			for (index = 0; index < (display.size2); index++) {
				udelay(150);
				BusyCheck();
				LCDWriteData(display.line2[index]);
			}

			break;
		}

	case LCD_Read:{
			struct lcd_display display;

			BusyCheck();
			for (address = kDD_R00; address <= kDD_R01;
			     address++) {
				a = (address | kLCD_Addr);

				udelay(150);
				BusyCheck();
				LCDWriteInst(a);
				udelay(150);
				BusyCheck();
				display.line1[address] = LCDReadData;
			}

			display.line1[0x27] = '\0';

			for (address = kDD_R10; address <= kDD_R11;
			     address++) {
				a = (address | kLCD_Addr);

				udelay(150);
				BusyCheck();
				LCDWriteInst(a);

				udelay(150);
				BusyCheck();
				display.line2[address - 0x40] =
				    LCDReadData;
			}

			display.line2[0x27] = '\0';

			if (copy_to_user
			    ((struct lcd_display *) arg, &display,
			     sizeof(struct lcd_display)))
				return -EFAULT;
			break;
		}

//  set all GPIO leds to led_display.leds

	case LED_Set:{
			struct lcd_display led_display;


			if (copy_from_user
			    (&led_display, (struct lcd_display *) arg,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			led_state = led_display.leds;
			LEDSet(led_state);

			break;
		}


//  set only bit led_display.leds

	case LED_Bit_Set:{
			unsigned int i;
			int bit = 1;
			struct lcd_display led_display;


			if (copy_from_user
			    (&led_display, (struct lcd_display *) arg,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			for (i = 0; i < (int) led_display.leds; i++) {
				bit = 2 * bit;
			}

			led_state = led_state | bit;
			LEDSet(led_state);
			break;
		}

//  clear only bit led_display.leds

	case LED_Bit_Clear:{
			unsigned int i;
			int bit = 1;
			struct lcd_display led_display;


			if (copy_from_user
			    (&led_display, (struct lcd_display *) arg,
			     sizeof(struct lcd_display)))
				return -EFAULT;

			for (i = 0; i < (int) led_display.leds; i++) {
				bit = 2 * bit;
			}

			led_state = led_state & ~bit;
			LEDSet(led_state);
			break;
		}


	case BUTTON_Read:{
			button_display.buttons = GPIRead;
			if (copy_to_user
			    ((struct lcd_display *) arg, &button_display,
			     sizeof(struct lcd_display)))
				return -EFAULT;
			break;
		}

	case LINK_Check:{
			button_display.buttons =
			    *((volatile unsigned long *) (0xB0100060));
			if (copy_to_user
			    ((struct lcd_display *) arg, &button_display,
			     sizeof(struct lcd_display)))
				return -EFAULT;
			break;
		}

	case LINK_Check_2:{
			int iface_num;

			/* panel-utils should pass in the desired interface status is wanted for
			 * in "buttons" of the structure.  We will set this to non-zero if the
			 * link is in fact up for the requested interface.  --DaveM
			 */
			if (copy_from_user
			    (&button_display, (struct lcd_display *) arg,
			     sizeof(button_display)))
				return -EFAULT;
			iface_num = button_display.buttons;
#if defined(CONFIG_TULIP) && 0
			if (iface_num >= 0 &&
			    iface_num < MAX_INTERFACES &&
			    linkcheck_callbacks[iface_num] != NULL) {
				button_display.buttons =
				    linkcheck_callbacks[iface_num]
				    (linkcheck_cookies[iface_num]);
			} else
#endif
				button_display.buttons = 0;

			if (__copy_to_user
			    ((struct lcd_display *) arg, &button_display,
			     sizeof(struct lcd_display)))
				return -EFAULT;
			break;
		}

	default:
		return -EINVAL;

	}

	return 0;

}