예제 #1
0
LedShift::LedShift(uint8_t nRegs, uint8_t dataPin, uint8_t latchPin, uint8_t enablePin, uint8_t clockPin){
  
  pinMode(dataPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  
  // Precompute the clock and data register/bitmasks to speed up the ISR
  dataReg =  portOutputRegister(digitalPinToPort(dataPin));
  dataBit = digitalPinToBitMask(dataPin);
  latchReg =  portOutputRegister(digitalPinToPort(latchPin));
  latchBit = digitalPinToBitMask(latchPin);
  enableReg = portOutputRegister(digitalPinToPort(enablePin));
  enableBit = digitalPinToBitMask(enablePin);
  clockReg = portOutputRegister(digitalPinToPort(clockPin));
  clockBit = digitalPinToBitMask(clockPin);

  // Set up the data buffer
  numRegisters = nRegs;
  //curDataPacket = new dataPacket [numRegisters];
  curDataPacket = (dataPacket*)malloc(numRegisters*sizeof(dataPacket));
  // *** NOTE: no error checking!

  // Initialize pin states
  Latch();
  Enable();
}
예제 #2
0
void SDR1000::SRLoad(uint8 addr, uint8 new_data) // parallel only
{
	uint8 tmp_data;
	uint8 pio_data;
	pio_data = pio_ic01->GetData();
	pio_data &= 0xC0; // clear unused bits
	// Shift 8 bits into the 4 RFE Registers
	for(int i=0x80; i>0; i >>= 1)
	{
		if((i & new_data) == 0) // current bit is low
		{
			tmp_data = pio_data | SCLR_NOT; tmp_data |= DCDR_NE;
			Latch(PIO_IC01, tmp_data);		// Output 0 bit
			tmp_data |= SCK;
			Latch(PIO_IC01, tmp_data);		// Clock 0 into shift register
		}
		else // current bit is high
		{
			tmp_data = pio_data | SCLR_NOT; tmp_data |= DCDR_NE; tmp_data |= SER;
			Latch(PIO_IC01, tmp_data);							// Output 1 bit
			tmp_data |= SCK;
			Latch(PIO_IC01, tmp_data);							// Clock 1 into shift register
		}

		tmp_data = (pio_data | SCLR_NOT); tmp_data |= DCDR_NE;
		Latch(PIO_IC01, tmp_data);				// Return SCK low
	}

	// Strobe the RFE 1:4 decoder output to transfer contents
	// of shift register to output latches
	tmp_data = pio_data | SCLR_NOT; tmp_data |= addr; tmp_data |= DCDR_NE; 
	Latch(PIO_IC01, tmp_data);		// Latch 2:4 decoder outputs
	tmp_data = pio_data | SCLR_NOT; tmp_data |= addr;
	Latch(PIO_IC01, tmp_data);		// Take 2:4 decoder enable low
	tmp_data = pio_data | SCLR_NOT; tmp_data |= addr; tmp_data |= DCDR_NE; 
	Latch(PIO_IC01, tmp_data);		// Take 2:4 decoder enable high
}
예제 #3
0
/*
================
sdTeleporter::OnTouch
================
*/
void sdTeleporter::OnTouch( idEntity *other, const trace_t& trace ) {
	if ( gameLocal.isClient ) {
		return;
	}

	idPlayer* player = other->Cast< idPlayer >();
	if ( player != NULL && !player->IsSpectator() && player->GetHealth() <= 0 ) {
		return;
	}

	// abort if it didn't touch the trigger model
	if ( trace.c.id != 1 ) {
		return;
	}

	// abort if there is no target
	if ( targets.Num() == 0 ) {
		return;
	}

	bool teamValid = true;

	// abort if the other is on a disabled team
	sdTeamInfo* otherTeam = other->GetGameTeam();
	if ( otherTeam != NULL ) {
		if ( !teamInfo[ otherTeam->GetIndex() ].enabled ) {
			teamValid = false;

			idPlayer* otherPlayer = other->Cast< idPlayer >();
			if ( otherPlayer != NULL ) {
				if ( otherPlayer->IsDisguised() ) {
					sdTeamInfo* disguiseTeam = otherPlayer->GetDisguiseTeam();
					if ( disguiseTeam != NULL ) {
						if ( teamInfo[ disguiseTeam->GetIndex() ].enabled ) {
							teamValid = true;
						}
					}
				}
			}
		}
	}

	if ( !teamValid ) {
		return;
	}

	if ( !other->AllowTeleport() ) {
		return;
	}

	// check if this entity has already been touched
	if ( latches.FindIndex( other ) != -1 ) {
		return;
	}

	const idVec3& myPosition = GetPhysics()->GetOrigin();
	const idMat3& myAxes = GetAxis();

	// only allow the entity to teleport if its moving INTO the teleporter
	float moveDir = other->GetPhysics()->GetLinearVelocity() * myAxes[ 0 ];
	if ( moveDir > 0.0f ) {
		return;
	}


	Latch( other );

	idEntity *targetEntity = targets[ 0 ].GetEntity();

	// get the positions of the target and the latch
	idVec3 targetPosition = targetEntity->GetPhysics()->GetOrigin();
	idMat3 targetAxes = targetEntity->GetAxis();

	// find the target teleporter
	// TODO: Make it an entity key on the target entity
	sdTeleporter* targetTeleporter = NULL;
	idClass* typeInstance = Type.instances.Next();
	for ( ; typeInstance; typeInstance = typeInstance->GetInstanceNode()->Next() ) {
		sdTeleporter* testTeleporter = reinterpret_cast< sdTeleporter* >( typeInstance );
		idBounds bounds = testTeleporter->GetPhysics()->GetAbsBounds();
		if ( bounds.ContainsPoint( targetPosition ) ) {
			targetTeleporter = testTeleporter;
		}
	}

	if ( targetTeleporter != NULL ) {
		targetTeleporter->Latch( other );
	}


	// modify the position & angles if its a vehicle that should land on the ramp
	sdTransport* transportOther = other->Cast< sdTransport >();
	idPlayer* playerOther = other->Cast< idPlayer >();
	sdJetPack* jetPackOther = other->Cast< sdJetPack >();

	bool shouldTraceDown = false;
	bool shouldOrientToRamp = false;
	bool shouldOrientBackTrace = false;
	float traceDownOffset = 0.0f;
	if ( transportOther != NULL && transportOther->GetVehicleControl() != NULL ) {
		shouldTraceDown = transportOther->GetVehicleControl()->TeleportOntoRamp();
		shouldOrientToRamp = transportOther->GetVehicleControl()->TeleportOntoRampOriented();
		shouldOrientBackTrace = transportOther->GetVehicleControl()->TeleportBackTraceOriented();
		traceDownOffset = transportOther->GetVehicleControl()->TeleportOntoRampHeightOffset();
	}
	if ( playerOther != NULL || jetPackOther != NULL ) {
		shouldTraceDown = true;
	}

	if ( shouldOrientToRamp ) {
		// find the normal of the surface
		trace_t downTrace;
		gameLocal.clip.TracePoint( CLIP_DEBUG_PARMS downTrace, targetPosition + idVec3( 0.0f, 0.0f, 128.0f ), targetPosition - idVec3( 0.0f, 0.0f, 512.0f ), CONTENTS_MOVEABLECLIP, NULL );

		// find the new target axes using that
		idMat3 newTargetAxes;
		newTargetAxes[ 2 ] = downTrace.c.normal;
		newTargetAxes[ 1 ] = newTargetAxes[ 2 ].Cross( targetAxes[ 0 ] );
		newTargetAxes[ 1 ].Normalize();
		newTargetAxes[ 0 ] = newTargetAxes[ 1 ].Cross( newTargetAxes[ 2 ] );
		newTargetAxes[ 0 ].Normalize();
		targetAxes = newTargetAxes;
	}

	if ( shouldTraceDown ) {
		// trace down to find where to land
		trace_t downTrace;
		const idBounds& bounds = other->GetPhysics()->GetBounds();
		idMat3 traceAxis = targetAxes;
		if ( !shouldOrientToRamp ) {
			traceAxis = mat3_identity;
		}

		gameLocal.clip.TraceBounds( CLIP_DEBUG_PARMS downTrace, targetPosition + idVec3( 0.0f, 0.0f, 128.0f ), targetPosition - idVec3( 0.0f, 0.0f, 512.0f ),
									bounds, traceAxis, CONTENTS_MOVEABLECLIP, NULL );

		targetPosition = downTrace.endpos + idVec3( 0.0f, 0.0f, traceDownOffset );
	}

	// trace from front to back against the trigger to make sure the new position is outside the teleporting trigger
	if ( targetTeleporter != NULL ) {
		trace_t backTrace;
		const idBounds& bounds = other->GetPhysics()->GetBounds();
		idMat3 traceAxis = targetAxes;
		if ( !shouldOrientBackTrace ) {
			traceAxis = mat3_identity;
		}

		idClipModel* triggerCM = targetTeleporter->GetPhysics()->GetClipModel( 1 );
		const idClipModel* boundsClip = gameLocal.clip.GetTemporaryClipModel( bounds );

		idVec3 endTraceBack = targetPosition;
		idVec3 startTraceBack = endTraceBack + 1024.0f*targetAxes[ 0 ];

		// check all the collision models of the other against our trigger model
		gameLocal.clip.TranslationModel( CLIP_DEBUG_PARMS backTrace, startTraceBack, endTraceBack,
											boundsClip, traceAxis, -1, triggerCM, triggerCM->GetOrigin(), triggerCM->GetAxis() );

		if ( backTrace.fraction < 1.0f ) {
			// push forwards a bit
			targetPosition = backTrace.endpos + 32.0f * targetAxes[ 0 ];
		}
	}


	teleportParms_t parms;
	parms.location			= targetPosition;
	parms.orientation		= targetAxes;
	parms.linearVelocity	= exitVelocity * targetAxes;
	parms.angularVelocity	= vec3_zero;
	parms.spawnId			= gameLocal.GetSpawnId( other );

	// finally, we want to check if the entity went in backwards, in which case
	// they should come out backwards too
	const idMat3& otherAxes = other->GetAxis();
	if ( otherAxes[ 0 ] * myAxes[ 0 ] > 0.7f ) {
		parms.orientation[ 0 ] *= -1.0f;
		parms.orientation[ 1 ] *= -1.0f;
	}

	if ( delay > 0 ) {
		StartTeleport( parms );
		return;
	}

	FinishTeleport( parms );
}
예제 #4
0
void SDR1000::ResetDDS() // parallel only
{
	Latch(PIO_IC08, DDSRESET | DDSWRB); // reset the chip
	Sleep(1);
	Latch(PIO_IC08, DDSWRB); // leave DDSWRB high
}
예제 #5
0
파일: nagra2.c 프로젝트: bas-t/descrambler
void cN2Timer::Ctrl(unsigned char val)
{
  if(Running()) {
    ctrl=(ctrl&~tmRUNNING) | (val&tmRUNNING);
    if(!Running()) {
      Stop();
      --cycles;
      Update();
      PRINTF(L_SYS_EMU,"n2timer %d: stopped cycles=%d (%02x) ctrl=%02x latch=%02x\n",nr,cycles,val,ctrl,latch&0xff);
      }
    }
  else {
    ctrl=(ctrl&~tmMASK) | (val&tmMASK);
    divisor=GetDivisor();
    if(divisor) invDivisor=1.0/divisor;
    if(Running()) {
      if(!(ctrl&tmLATCHED) && divisor>0) {
        if(this->val==0) {
          timerBugged=true;
          cycles=(unsigned int)divisor;
          }
        else {
          cycles=(unsigned int)(((timerBugged?0x100:latch)-this->val+1) * divisor);
          }
        }
      if((ctrl&tmINTERRUPT)) {
        intrCycles=cycles+(unsigned int)((timerBugged?0x101:this->val?this->val:latch)*divisor);
        if(nr==2) PRINTF(L_SYS_EMU,"n2timer %d: set for %u cycles (%02x %02x)",nr,intrCycles-cycles,Latch(),ctrl&0xff);
        }
      ctrl&=~tmLATCHED;
      }
    }
}
예제 #6
0
파일: main.c 프로젝트: u60/cube-o-mania
int main()
{
	volatile signed int i, aColumn, aLevel, mask, mux, patterncntr;

	patterncntr = 0;
	Hold = 0;

	InitPorts();
	CARDinit();
	USARTinit();

	while (1) 
	{
	
		while (patterncntr < numanimas)
		{
			X = 0;
			eX = 0;
			XChanged = 0;
			dX = pgm_read_byte(&AnimationA[patterncntr].hold);
			fademode = pgm_read_byte(&AnimationA[patterncntr].fade);

			for (i = 0; i < MaxLedPins; i++)
			{	
				eY[i] = 0;
				/*
				aDivRes = div(i, LedPinsPerLevel);
				aLevel = aDivRes.quot;
				aLedPin = i;
				aLedPin %= LedPinsPerLevel;
				*/
			  	YStart = pgm_read_byte(&AnimationA[patterncntr].pwm[i]);
				PWM[i] = YStart;
				if (patterncntr < numanimas-1) idx = patterncntr+1; else idx = 0;
				YEnd = pgm_read_byte(&AnimationA[idx].pwm[i]);
				dY[i] = YEnd-YStart;		 
			}
			Hold = 0;

			while (Hold <= pgm_read_byte(&AnimationA[patterncntr].hold))
			{
				
				if (fademode > 0) fade();

				for (i=0; i<=PWMres; i++)
				{	
					
					CARDloop();
					USARTloop();
					
					mux = MaxMux;
					while (mux > 0)
					{
						mux--;
						for (aColumn = LedPinsPerColumn-1; aColumn >= 0; aColumn--)
						{	
							mask = 0;
							aLevel = MaxLevels;
							while (aLevel > 0)
							{	
								aLevel--;
								idx = aColumn+mux * LedPinsPerColumn + aLevel * LedPinsPerLevel;
								if (i < PWM[idx]) mask |= (1 << aLevel);
							}
							SetLevelPins(mask);
			
						}
						switch (mux)
						{
							case 0 :
							   SetLevelPins(15);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   break;
							case 1 :
							   SetLevelPins(0);
							   SetLevelPins(15);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   break;
							case 2 :
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(15);
							   SetLevelPins(0);
							   break;
							case 3 :
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(15);
							   break;
						}
						i = i;	
						Latch();
					}		
				}
			if (fademode == 0)	Hold++;	
			} 
			Hold = 0;
			patterncntr++;	
		}
		patterncntr = 0;
	}
}
예제 #7
0
int Sdr1kUsb::Open(BOOL rfe, BOOL adc, int select)
{
	if (usbStatus >= 0) Close();
	GetNumDevs();
	int idx = select;
	if (select < 0) idx = 0;
	while (idx < devcount) {
		if (usbOpen(device[idx])) {
			if (usbSetConfiguration(1) == 0
				&& usbClaimInterface(0) == 0
				&& usbSetAltinterface(1) == 0)
			{
				usbStatus = 0;
				break;
			}
			usbClose();
		}
		if (select < 0) idx++;
		else return usbStatus;
	}
	if (usbStatus < 0) return usbStatus;

#ifdef SDR1KUSB_INFO
	printf("device %d: %s\n", idx, device[idx]->filename);
	printf("hardware: %s\n", hw[idx]->name);
#endif

	inEP = hw[idx]->inEP;
	outEP = hw[idx]->outEP;
	usbClearHalt(inEP);
	usbClearHalt(outEP);

	int* fwSize = hw[idx]->fwSize;
	int* fwAddr = hw[idx]->fwAddr;
	BYTE** fwBytes = hw[idx]->fwBytes;
	for (int i = 0; fwSize[i] > 0; i++) {
		ezusbFirmwareDownload(fwAddr[i], fwBytes[i], fwSize[i]);
	}

	int eepromSize = hw[idx]->eepromSize;
	if (eepromSize == 16) {
		BYTE eeprom[16];
		usbBulkRead(inEP, eeprom, 16);
#ifdef SDR1KUSB_INFO
		printf("EEPROM:");
		for (int i = 0; i < 16; i++) {
			printf(" %02X", eeprom[i]);
		}
		printf("\n");
#endif
	}

	inputEvent = 0;
	usbUpdatePeriod = USB_UPDATE_DEFAULT;

	outcount = 0;
	startUsbThread();

	Latch(0x0F, 0);
	DDSReset();

	rfeEnabled = rfe;
	if (rfeEnabled) {
		LatchBpf(0);	// bpfBits |= 0x24
		adcEnabled = adc;
		SRLoadIC11(0);
		SRLoadIC7(0);
		SRLoadIC10(0);
		SRLoadIC9(0);
	}
	else adcEnabled = 0;

	if (Commit() < 0) {
		Close();
		return usbStatus;
	}
	return idx;
}