示例#1
0
文件: card_spi.c 项目: hl1itj/Team3
/*-------------------------------------------------------------------------------*/
void cardSpiWriteBuffer(char *out, uint16 count) {
/*-------------------------------------------------------------------------------*/
	uint16 i;

	if (count == 0) {
		return;
	} else if (count == 1) {
		cardSpiTransfer(*out);
		return;
	}

	/* enable card SPI with CS hold */
	cardSpiStart(true);

	for ( i = 0; i < count-1; i++ ) {
		CARD_EEPDATA = out[i];		/* send character */
		while(cardSpiBusy());		/* busy wait */
		swiDelay(2000);
	}

	/* last character has to be transferred with chip select hold disabled */
	cardSpiStart(false);

	CARD_EEPDATA = out[count-1];	/* send last character */
	while(cardSpiBusy());			/* busy wait */

	/* disable card SPI */
	cardSpiStop();

#ifdef ARM9
	swiDelay(2000);
#else
	swiDelay(12);
#endif
}
示例#2
0
文件: ndsmotion.c 项目: bowies/Team3
// checks whether a DS Motion Pak is plugged in
int motion_pak_is_inserted(void){
    int motion_pak = 0;
	unsigned char return_byte = V_SRAM[10]; // read first byte of DS Motion Pak check
	swiDelay(WAIT_CYCLES);
	return_byte = V_SRAM[0];
	swiDelay(WAIT_CYCLES);
	if (return_byte==0xF0) { // DS Motion Pak returns 0xF0
		return_byte = V_SRAM[0]; // read second byte of DS Motion Pak check
		swiDelay(WAIT_CYCLES);
		if(return_byte==0x0F) { // DS Motion Pak returns 0x0F
			motion_pak = 1;
		}
	}
    return motion_pak;
}
示例#3
0
//---------------------------------------------------------------------------------
void avrDataHandler(int bytes, void *user_data) {
//---------------------------------------------------------------------------------
	AvrFifoMessage msg;
	int value;

	fifoGetDatamsg(FIFO_AVR, bytes, (u8*)&msg);
	
	if(msg.type == PROFILE_MESSAGE) {
    	long int i;
    	
		for(i=0;i < (50000);i++) {
		    swiDelay(10000);
		}
    	
    	fifoSendValue32(FIFO_AVR, (u32)1337 );
	} else if(msg.type == CONFIG_MESSAGE) {
	   	shortwait = WAIT_1MS * msg.SPIConfig.m1;
	   	speed = msg.SPIConfig.m2;
	   	spi_debug = msg.SPIConfig.debug;
	} else if(msg.type == LED_FLASH_MESSAGE) {
	    send_chars(2, FLASH_LED_COMMAND, msg.LEDFlash.count);
	} else if (msg.type == ANALOG_READ_MESSAGE) {
		send_chars(2, ANALOG_READ_COMMAND, msg.AnalogRead.pin);
		swiDelay(10000);
		send_chars(3, NULL_COMMAND, 0, 0);

		fifoSendDatamsg(FIFO_AVR, sizeof(incoming), incoming);
		//value = incoming[1];
		//value |= (incoming[2] << 8);
		/*value = read_increment(1);
		swiDelay(COMMAND_WAIT);
		value |= (read_increment(1) << 8);*/
		
		//fifoSendValue32(FIFO_AVR, (u32)value);
	} else if (msg.type == IO_PORT_GET_MESSAGE) {
		value = ioport_get(msg.IOPortGetSet.address);
		fifoSendValue32(FIFO_AVR, (u32)value);
	} else if (msg.type == IO_PORT_SET_MESSAGE) {
		ioport_set(msg.IOPortGetSet.address, msg.IOPortGetSet.value);
	} else if (msg.type == PWM_MESSAGE) {
		if(msg.PWM.command == PWM_ON) {
			if(msg.PWM.output == PWM5) {
				reg_orequal(TCCR2B, _BV(CS22));
				//TCCR2B |= CS22
			}
		}
	}
}
示例#4
0
uint8_t ioport_get(uint8_t address) {
    uint8_t value;
	send_chars(2, IO_REG_GET_COMMAND, address);
	swiDelay(10000); // 2.1 ms
	value = read_increment(1);
	return value;
}
示例#5
0
文件: card_spi.c 项目: hl1itj/Team3
/*-------------------------------------------------------------------------------*/
char cardSpiTransfer(char c) {
/*-------------------------------------------------------------------------------*/
	cardSpiStart(false);			/* enable card SPI */

	CARD_EEPDATA = c;				/* send charactr */
	while(cardSpiBusy());			/* busy wait */
	cardSpiStop();					/* disable card SPI */

#ifdef ARM9
	swiDelay(2000);
#else
	swiDelay(12);
#endif

	return CARD_EEPDATA;
}
示例#6
0
uint8_t reg_orequal(uint8_t address, uint8_t val) {
	uint8_t d;
	d = ioport_get(address);
	d |= val;
	swiDelay(COMMAND_WAIT);
	ioport_set(address, d);
	return d;
}
示例#7
0
void swiAction(unsigned char SwiID)
{
	unsigned char exID;

	if(SwiID >= sizeof(lut))
		return;

	exID = lut[SwiID];
	if(exID == 255)
		return;

	P1 = tbl[(exID&7)];
	P0 = tbl[(exID>>3)];
	swiDelay(0x1f,0xff);

	P1 = 0xff;
	P0 = 0xff;
	swiDelay(0x03,0xff);
}
示例#8
0
int CommandStopRecording(void)
{
    NTXMFifoMessage command;
    command.commandType = STOP_RECORDING;

    fifoSendDatamsg(FIFO_NTXM, sizeof(command), (u8*)&command);

    while(!fifoCheckValue32(FIFO_NTXM))
        swiDelay(1);

    return (int)fifoGetValue32(FIFO_NTXM);
}
示例#9
0
文件: card_spi.c 项目: hl1itj/Team3
/*-------------------------------------------------------------------------------*/
void putDebugChar(unsigned char data)
/*-------------------------------------------------------------------------------*/
{
	cardSpiStart(false);

	CARD_EEPDATA = USB_DATA;
	while(cardSpiBusy());
	cardSpiStop();

	swiDelay(10000);

	cardSpiStart(false);

	CARD_EEPDATA = data;
	while(cardSpiBusy());
	cardSpiStop();

#ifdef ARM9
	swiDelay(10000);
#else
	swiDelay(12);
#endif
}
示例#10
0
文件: card_spi.c 项目: elzk/nds-ide
/*-------------------------------------------------------------------------------*/
void cardSpiTransferBuffer(char *out, char *in, uint16 count) {
/*-------------------------------------------------------------------------------*/

	uint16 i;

	if (count == 0) {
		return;
	} else if (count == 1) {
		*in = cardSpiTransfer(*out);
		return;
	}

	/* enable card SPI with CS hold */
	cardSpiStart(true);

	for ( i = 0; i < count-1; i++ ) {
		REG_AUXSPIDATA = out[i];		/* send character */
		while(cardSpiBusy());		/* busy wait */
		in[i] = REG_AUXSPIDATA;		/* receive character */
	}

	/* last character has to be transferred with chip select hold disabled */
	cardSpiStart(false);

	REG_AUXSPIDATA = out[count-1];	/* send last character */
	while(cardSpiBusy());			/* busy wait */
	in[count-1] = REG_AUXSPIDATA;		/* receive character */

	/* disable card SPI */
	cardSpiStop();

#ifdef ARM9
	swiDelay(24);
#else
	swiDelay(12);
#endif
}
示例#11
0
//---------------------------------------------------------------------------------
void micSetAmp_TWL(u8 control, u8 gain) {
//---------------------------------------------------------------------------------

	static const u8 gaintbl[] = { 0x1F, 0x2B, 0x37, 0x43 };

	if (control == PM_AMP_ON) {
		cdcWriteReg(CDC_SOUND, 0x2E, 0x03); // set adc bias
		bool adcOn = cdcReadReg(CDC_CONTROL, 0x51) & 0x80;
		bool dacOn = cdcReadReg(CDC_CONTROL, 0x3F) & 0xC0;
		cdcWriteReg(CDC_CONTROL, 0x51, 0x80); // turn on adc
		if (!adcOn || !dacOn) {
			swiDelay(0x28E91F); // 20ms
		}
		cdcWriteReg(CDC_CONTROL, 0x52, 0x00); // unmute adc
		cdcWriteReg(CDC_SOUND, 0x2F, gaintbl[gain&3]); // set gain
	} else if (control == PM_AMP_OFF) {
		cdcWriteReg(CDC_CONTROL, 0x52, 0x80); // mute adc
		cdcWriteReg(CDC_CONTROL, 0x51, 0x00); // turn off adc
		cdcWriteReg(CDC_SOUND, 0x2E, 0x00); // set adc bias
	}
}
示例#12
0
文件: menu.c 项目: LemonBoy/grape
void print_msg (const char *msg)
{
    iprintf("\n-- %s\n", msg);
    swiDelay(50000000);
}
示例#13
0
int main(void)
{
	aplist *head = NULL;
	aplist *cur;
	
	bool attached = true;
	// change this to false if you are only testing servos
	bool wifi_scan = true;
	// change this for emulator 
	bool emulate = false;

	float pain = 0.9f;
	time_t update = 0;
	uint8 num;
	uint8 servo_pos = 0;
	uint8 current_servo = 1;
	unsigned char SERVO_PINS[3] = { SERVO_PIN1 ,SERVO_PIN2 ,SERVO_PIN3 } ;

	uint16 val[3] = { 0 };
	uint8 i;

	touchPosition touch;
	
	videoSetMode(MODE_4_2D);
	vramSetBankA(VRAM_A_MAIN_BG);

	// set up our bitmap background
	bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0);
	decompress(cclogoBitmap, BG_GFX,  LZ77Vram);

	// initialise lower screen for textoutput
	consoleDemoInit();

	if (emulate == false) {	

	  iprintf("Initializing WiFi.. ");
	  Wifi_InitDefault(false);
	  while (Wifi_CheckInit() != 1) {
	  }
	  Wifi_ScanMode();
	  iprintf("done\n");
	  
	  iprintf("Initializing DS brut.. ");
	  uart_init();
	  uart_set_spi_rate(1000);
	  iprintf("done\n\n\n");

	  iprintf("Using servo pins: %u %u %u\n\n", SERVO_PIN1, SERVO_PIN2, SERVO_PIN3);
	  iprintf("Default pain multiplier: %.2f\n\n", pain);
	  swiDelay(60000000);
	  while (1) {
		  
		  scanKeys();
		  touchRead(&touch);	
		  if (keysDown() & KEY_X) {
			  if (attached) {
				  servo_detach(SERVO_PIN1);
				  servo_detach(SERVO_PIN2);
				  servo_detach(SERVO_PIN3);
				  attached = false;
			  } else {
				  attached = true;
			  }
		  }
		  if (keysDown() & KEY_A) {
			  if (attached) {
				uint8 i = 0;
				for (i=0;i<3;i++) {
					servo_set(SERVO_PINS[i],0);
				}
			  }
			  //servo_set(SERVO_PIN1, 180-((rand() % 100)+(rand() % 50)+(rand() % 25)));
			  //servo_set(SERVO_PIN2, 180-((rand() % 100)+(rand() % 50)+(rand() % 25)));
			  //servo_set(SERVO_PIN3, 180-((rand() % 100)+(rand() % 50)+(rand() % 25)));
		  }
		  if (keysDown() & KEY_B) {
			  if (wifi_scan == true)	{
				  wifi_scan = false;
			  }
			  else {
				  wifi_scan = true;
			  }
		  }
		  if (keysDown() & KEY_DOWN) {
			  pain -= 0.1f;
			  if (pain < 0.0f) {
				  pain = 0.0f;
			  }
			  update = time(NULL);
		  }
		  if (keysDown() & KEY_UP) {
			  pain += 0.1f;
			  if (2.0f < pain) {
				  pain = 2.0f;
			  }
			  update = time(NULL);
		  }
		  if (keysDown() & KEY_L) {
			  current_servo += 1;
			  if (current_servo > 3) {
				  current_servo = 1;
			  }
		  }
		  consoleClear();
		  if (wifi_scan == true) {
			num = 0;
			cur = head;
			iprintf("\n");
			while (cur && num < 15) {
				// display
				if (!(cur->flags & 0x2)) {
					cur = cur->next;
					continue;
				}
				iprintf("%2u ", num);
				if (cur->ssid[0] == '\0') {
					iprintf("%02x%02x%02x%02x%02x%02x", cur->mac[0], cur->mac[1], cur->mac[2], cur->mac[3], cur->mac[4], cur->mac[5]);
				} else {
					iprintf("%s", cur->ssid);
				}
				iprintf(" @ %u", cur->rssi);
				if ((cur->flags & 0x06) == 0x06) {
					iprintf(" WPA");
				} else if (cur->flags & 0x02) {
					iprintf(" WEP");
				}
				
				// calculate servo commands
				if (attached && num < 3) {
						val[num] = (uint16)(cur->rssi*pain);
						if (180 < val[num]) {
							val[num] = 180;
						}
						iprintf(" %u", val[num]);
				}
				
				iprintf("\n");
				if (num == 2) {
					iprintf ("\n");
				}
				
				num++;
				cur = cur->next;
			}
			iprintf("\n");
			if (time(NULL) < update+3) {
				printf("\npain multiplier: %.2f\n", pain);
			}
			
			// set the servo to zero if we don't have enough wifi nodes
			for (i=num; i<3; i++) {
				val[i] = 0;
			}
			
			if (attached) {
				servo_set(SERVO_PIN1, (uint8)val[0]);
				servo_set(SERVO_PIN2, 180-(uint8)val[1]);
				servo_set(SERVO_PIN3, (uint8)val[2]);
			}
			updateApList(&head, 0x00, NULL, NULL);
			sortApList(&head, false);

		  }

		  if (KEY_TOUCH && attached && !wifi_scan) {
			  servo_pos = (touch.rawx / 3850.) * 180;	
			  iprintf ("servo pos x: %d;", servo_pos);
			  iprintf ("\n");
			  servo_set(SERVO_PINS[current_servo-1],servo_pos);
			  iprintf ("current servo: %d", current_servo);
			  iprintf ("\n\n");
		  }
		  
		  
		  swiWaitForVBlank();
	  }
 	}	
while (1) {
		  swiWaitForVBlank();
}
	return 0;
}
示例#14
0
// works with ds brut firmware version 0x14
// tested with DS brut (master) rev. a & rev. b
int usleep(unsigned long usec)
{
    swiDelay(4190 * usec / 1000);
}
示例#15
0
//end interface routine
void main()
{
	unsigned char temp;
	unsigned char sid;//id of serial to send 
	long i=1000;
	IE = 0;//close int

	sjSerialInit();
	

	//set serial port parameter (clock 11.0592M)
	//9600 baut rate 8 data non parity and 1 stop.
	SCON = 0x70;
	PCON = 0x00;
	//timer count
	TH1 = 0xfd;
	//use timer 1 to be serial
	//use timer 0 to be analog I/O
	TMOD = 0x22;
	TR1 = 1;

	init_uart();
	turn_rx_on();//enable I/O serial
	flush_input_buffer();
	IE = 0x92;//enable serial int and timer0 interrupt//IE=90
	sid = 0;
	
	asp_tx = 1;//set the asp_tx to be output pin
	if(asp_rx);//set the asp_rx to be input pin

//	sjSerialSendByte('?');
	swiReset();
	/*
	*	Protocal routine: 
	*	1.	HMARK sid(!=HMARK) :set sid
	*   2.	normal HMARK is repeated
	*/
	swiDelay(0x0f,0xff);
	
	while(1)
	{

		if(sjSerialIsDataWaiting())
		{
			temp = sjSerialWaitForOneByte();
			if(temp == HMARK)
			{
				temp = sjSerialWaitForOneByte();		
				if(temp != HMARK)
				{
					sid = temp;
					continue;
				}
			}
			if(sid == 's')//send to switch
			{
				if(temp == HMARK)
				{
					while(1)
					{
						temp = sjSerialWaitForOneByte();
						if(temp == EMARK)
							break;
						if(temp == RMARK)
						{
							swiReset();
							continue;
						}
						if(temp == QMARK)
							continue;
						swiAction(temp);
					}
					sjSerialSendByte(HMARK);
					temp = P2;
					sjSerialSendByte(temp);
					temp = P3;
/*
					temp = 0;
					if(P3^4)
						temp |= (0x10);
					if(P3^5)
						temp |= (0x20);
*/
					sjSerialSendByte(temp);
					sjSerialSendByte(EMARK);
				}
			}
			if(sid == 'n')//send to navmeter
			{
				ioputchar(temp);
			}
			if(sid == 't')
			{
				P0=sjSerialWaitForOneByte();
				P1=sjSerialWaitForOneByte();
				sjSerialSendByte(EMARK);
			}
		}
		if(kbhit())
		{
			temp = iogetchar();
			sjSerialSendByte(temp);
		}
	}
}