예제 #1
0
void check_for_qtr_shorts()
{
	// Test for shorts
	unsigned int sensor_pins[] = {IO_C0,IO_C1,IO_C2,IO_C3,IO_C4};
	unsigned char shorts = 1;
	clear();
	print("qtr");
	lcd_goto_xy(0,1);
	print("shorts");
	while (shorts)
	{
		unsigned char i;
		shorts = 0;
		for(i=0;i<5;i++)
		{
			unsigned char j;
			for (j=0;j<5;j++)
			{
				set_digital_input(sensor_pins[j],PULL_UP_ENABLED);
			}
			set_digital_output(sensor_pins[i],LOW);
			delay_ms(2);
			for (j=0;j<5;j++)
			{
				if (i == j && is_digital_input_high(sensor_pins[j]))
					shorts = 1;
				if (i != j && !is_digital_input_high(sensor_pins[j]))
					shorts = 1;
			}
		}
	}
}
예제 #2
0
int main()  
{  
    // Make PC1 be an input with its internal pull-up resistor enabled.  
    // It will read high when nothing is connected to it.  
    set_digital_input(IO_C1, PULL_UP_ENABLED);  
  
    while(1)  
    {  
        if(is_digital_input_high(IO_C1))     // Take digital reading of PC1.  
        {  
            set_digital_output(IO_D1, HIGH); // PC1 is high, so drive PD1 high.  
        }  
        else  
        {  
            set_digital_output(IO_D1, LOW);  // PC1 is low, so drive PD1 low.  
        }  
    }  
}
예제 #3
0
void sparrow_init() {

	//First: Turn off external power blocks
	set_digital_output(BOOST_5V_EN_PIN);
	write_pin(BOOST_5V_EN_PIN, false);

	set_digital_output(PORT_5V_EN_PIN);
	write_pin(PORT_5V_EN_PIN, false);

//TODO: Disable 5V USB generation (USB0_PPWR, P2_0)

//TODO: Set fault input interrupt handlers to shutdown peripheral and react accordingly
//E.g. USB_PWR_FAULT_HANDLER (P2_1)

	set_digital_output(AUDIO_POWER_EN_PIN);
	write_pin(AUDIO_POWER_EN_PIN, false);

	set_digital_output(WIFI_POWER_EN_PIN );
	write_pin(WIFI_POWER_EN_PIN, false );


//TODO: Why does this pin not work? For now, the input pullup keeps the eth domain powered up permamently.
//Setting OUT and writing this bit caused the device to hang. Might be correct now, check again.
//	set_digital_output(ETH_POWER_EN_PIN);
	write_pin(ETH_POWER_EN_PIN, false);

	//Set all ext devices to !reset
	set_digital_output(AUDIO_NRESET);
	write_pin(AUDIO_NRESET, false);

	//init base clock to xtal, main clock, via pll1
	clock_set_xtal_core_freq(MAIN_CLOCK_MHZ/XTAL_MHZ, 1);

	//enable derived base clocks for shared use. Dedicated clocks are enabled by the
	//respective peripheral interface
	clock_set_source(BASE_APB1_CLK, true, CLKSRC_PLL1);    //I2C0
	clock_set_source(BASE_APB3_CLK, true, CLKSRC_PLL1);    //I2C1

	//GPIO
	set_digital_output(LED1_PIN);
	set_digital_output(LED2_PIN);
	set_digital_output(LED3_PIN);
	set_digital_input(BUTTON_PIN, true, false, false);
	write_pin(LED1_PIN, false);
	write_pin(LED2_PIN, false);
	write_pin(LED3_PIN, false);



	//I2C
	i2c_configure_pin(I2C1_SDA_PIN_GROUP, I2C1_SDA_PIN_IDX, I2C1_SDA_PIN_MODE);
	i2c_configure_pin(I2C1_SCL_PIN_GROUP, I2C1_SCL_PIN_IDX, I2C1_SCL_PIN_MODE);
	i2c_init(0, I2C_MODE_FAST);
	i2c_init(1, I2C_MODE_FAST);
	//TODO: I2C1 might also be used as GPIOs

	//SPI
	scu_set_pin(SPI0_MISO_GROUP, SPI0_MISO_IDX, SPI0_MISO_MODE, false, false, true, true, true);
	scu_set_pin(SPI0_MOSI_GROUP, SPI0_MOSI_IDX, SPI0_MOSI_MODE, false, false, true, false, true);
	scu_set_pin(SPI0_SCK_GROUP, SPI0_SCK_IDX, SPI0_SCK_MODE, false, false, true, false, true);
	scu_set_pin(SPI0_SSEL_GROUP, SPI0_SSEL_IDX, SPI0_SSEL_MODE, false, false, true, false, true);
	
	scu_set_pin(SPI1_MISO_GROUP, SPI1_MISO_IDX, SPI1_MISO_MODE, false, false, true, true, true);
	scu_set_pin(SPI1_MOSI_GROUP, SPI1_MOSI_IDX, SPI1_MOSI_MODE, false, false, true, false, true);
	scu_set_pin(SPI1_SCK_GROUP, SPI1_SCK_IDX, SPI1_SCK_MODE, false, false, true, false, true);
	scu_set_pin(SPI1_SSEL_GROUP, SPI1_SSEL_IDX, SPI1_SSEL_MODE, false, false, true, false, true);



	//I2S
	i2s_configure_pin(I2S0_TX_MCLK_GROUP, I2S0_TX_MCLK_IDX, I2S0_TX_MCLK_MODE);
	i2s_configure_pin(I2S0_TX_WS_GROUP, I2S0_TX_WS_IDX, I2S0_TX_WS_MODE);
	i2s_configure_pin(I2S0_TX_SCK_GROUP, I2S0_TX_SCK_IDX, I2S0_TX_SCK_MODE);
	i2s_configure_pin(I2S0_TX_SD_GROUP, I2S0_TX_SD_IDX, I2S0_TX_SD_MODE);
	//i2s_configure_pin(I2S0_RX_MCLK_GROUP, I2S0_RX_MCLK_IDX, I2S0_RX_MCLK_MODE);
	//i2s_configure_pin(I2S0_RX_WS_GROUP, I2S0_RX_WS_IDX, I2S0_RX_WS_MODE);
	//i2s_configure_pin(I2S0_RX_SCK_GROUP, I2S0_RX_SCK_IDX, I2S0_RX_SCK_MODE);
	//i2s_configure_pin(I2S0_RX_SD_GROUP, I2S0_RX_SD_IDX, I2S0_RX_SD_MODE);


	//SD
	scu_set_pin_mode(SD_CD_GROUP, SD_CD_PIN, SD_CD_MODE);
	scu_enable_pin_in_buffer(SD_CD_GROUP, SD_CD_PIN, true);
	scu_set_pin_mode(SD_WP_GROUP, SD_WP_PIN, SD_WP_MODE);
	//TODO: configure WP pin
	scu_set_pin_mode(SD_CMD_GROUP, SD_CMD_PIN, SD_CMD_MODE);
	scu_set_pin_pullup(SD_CMD_GROUP, SD_CMD_PIN, true);
	scu_enable_pin_in_buffer(SD_CMD_GROUP, SD_CMD_PIN, true);
	scu_set_pin_mode(SD_D0_GROUP, SD_D0_PIN, SD_D0_MODE);
	scu_set_pin_pullup(SD_D0_GROUP, SD_D0_PIN, true);
	scu_enable_pin_in_buffer(SD_D0_GROUP, SD_D0_PIN, true);
	scu_set_pin_mode(SD_D1_GROUP, SD_D1_PIN, SD_D1_MODE);
	scu_set_pin_pullup(SD_D1_GROUP, SD_D1_PIN, true);
	scu_enable_pin_in_buffer(SD_D1_GROUP, SD_D1_PIN, true);
	scu_set_pin_mode(SD_D2_GROUP, SD_D2_PIN, SD_D2_MODE);
	scu_set_pin_pullup(SD_D2_GROUP, SD_D2_PIN, true);
	scu_enable_pin_in_buffer(SD_D2_GROUP, SD_D2_PIN, true);
	scu_set_pin_mode(SD_D3_GROUP, SD_D3_PIN, SD_D3_MODE);
	scu_set_pin_pullup(SD_D3_GROUP, SD_D3_PIN, true);
	scu_enable_pin_in_buffer(SD_D3_GROUP, SD_D3_PIN, true);
	scu_set_clock_pin_mode(SD_CLK_CLK, SD_CLK_MODE, false, false, true, false, false);


	//Ethernet RMII
	creg_init();
	creg_set_eth_interface(true);
	scu_set_clock_pin_mode(ETH_CLK_CLK, ETH_CLK_MODE, false, false, true, true, false);
	scu_set_pin(ETH_RXD0_GROUP,   ETH_RXD0_PIN,   ETH_RXD0_MODE,   false, false, true, true,  false);
	scu_set_pin(ETH_RXD1_GROUP,   ETH_RXD1_PIN,   ETH_RXD1_MODE,   false, false, true, true,  false);
	scu_set_pin(ETH_TXD0_GROUP,   ETH_TXD0_PIN,   ETH_TXD0_MODE,   false, false, true, false, false);
	scu_set_pin(ETH_TXD1_GROUP,   ETH_TXD1_PIN,   ETH_TXD1_MODE,   false, false, true, false, false);
	scu_set_pin(ETH_MDC_GROUP,    ETH_MDC_PIN,    ETH_MDC_MODE,    false, false, true, false, false);
	scu_set_pin(ETH_TXEN_GROUP,   ETH_TXEN_PIN,   ETH_TXEN_MODE,   false, false, true, false, false);
	scu_set_pin(ETH_CRS_DV_GROUP, ETH_CRS_DV_PIN, ETH_CRS_DV_MODE, false, false, true, true,  false);
	scu_set_pin(ETH_MDIO_GROUP,   ETH_MDIO_PIN,   ETH_MDIO_MODE,   false, false, true, true,  false);
	set_digital_input(ETH_NINT_PIN, true, false, true);
	set_digital_output(ETH_NRST_PIN);
	write_pin(ETH_NRST_PIN, false);	//put into reset

	//CC3000 WIFI
	set_digital_output(CC3000_SW_EN_PIN);
	write_pin(CC3000_SW_EN_PIN, false);
	set_digital_input(CC3000_IRQ_PIN, false, false, true);

}