Ejemplo n.º 1
0
void iboot_loader_run(void) {
	uint64_t startTime = timer_get_system_microtime();
	// boot iboot when either the up button is pressed or after 10 seconds
	static Boolean buttonPressed = FALSE;
	static Boolean messageShown = FALSE;
	while(1) {
		if (!gpio_pin_state(BUTTONS_VOLUP)
			|| (has_elapsed(startTime, 10 * 1000 * 1000) && !buttonPressed)) {
			load_iboot();
			task_stop();
		}
		if (gpio_pin_state(BUTTONS_HOLD)) {
			buttonPressed = TRUE;
		}
		if (has_elapsed(startTime, 2 * 1000 * 1000) && !messageShown) {
			// show a welcome message after 2 seconds to skip all of the usb spam
			bufferPrintf("===================\r\n");
			bufferPrintf("Welcome to the 2g touch experimental openiBoot!\r\n");
			bufferPrintf("iBoot will be automatically loaded after 10 seconds\r\n");
			bufferPrintf("Press the power button to cancel automatic booting\r\n");
			bufferPrintf("Press the volume up button to load ios\r\n");
			bufferPrintf("===================\r\n");
			bufferPrintf("\r\n\r\n\r\n");
			messageShown = TRUE;
		}
		task_yield();
	}
}
Ejemplo n.º 2
0
int gpio_detect_configuration() {
	static int hasDetected = FALSE;
	static int detectedConfig = 0;

	if(hasDetected) {
		return detectedConfig;
	}

	detectedConfig = (gpio_pin_state(GPIO_DETECT3) ? 1 : 0) | ((gpio_pin_state(GPIO_DETECT2) ? 1 : 0) << 1) | ((gpio_pin_state(GPIO_DETECT1) ? 1 : 0) << 2);
	hasDetected = TRUE;
	return detectedConfig;
}
Ejemplo n.º 3
0
void cmd_gpio_pinstate(int argc, char** argv) {
	if(argc < 2) {
		bufferPrintf("Usage: %s <port>\r\n", argv[0]);
		return;
	}

	uint32_t port = parseNumber(argv[1]);
	bufferPrintf("Pin 0x%x state: 0x%x\r\n", port, gpio_pin_state(port));
}
Ejemplo n.º 4
0
int radio_setup_2g()
{
	gpio_pin_output(RADIO_GPIO_BB_MUX_SEL, OFF);

	gpio_pulldown_configure(RADIO_BB_PULLDOWN, GPIOPDDown);

	gpio_pin_output(RADIO_GPIO_BB_ON, OFF);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_RADIO_ON, ON);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_BB_RESET, ON);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_BB_RESET, OFF);
	udelay(100000);

	gpio_pin_use_as_input(RADIO_GPIO_BB_DETECT);
	if(gpio_pin_state(RADIO_GPIO_BB_DETECT) != 0)
	{
		bufferPrintf("radio: comm board not present, powered on, or at+xdrv=10,2 had been issued.\r\n");
		return -1;
	}

	bufferPrintf("radio: comm board detected.\r\n");

    
	if(!radio_wait_for_ok(10))
	{
		bufferPrintf("radio: no response from baseband!\r\n");
		return -1;
	}
  

	bufferPrintf("radio: setting speed to 750000 baud.\r\n");

	radio_write("at+ipr=750000\r\n");

	// wait a millisecond for the command to totally clear uart
	// I wasn't able to detect this condition with uart registers (looking at FIFO count, transmitter empty)
	udelay(1000);

	uart_set_baud_rate(RADIO_UART, 750000);

	if(!radio_wait_for_ok(10))
	{
		bufferPrintf("radio: no response from baseband!\r\n");
		return -1;
	}

	RadioAvailable = TRUE;

	bufferPrintf("radio: ready.\r\n");

	speaker_setup();

	return 0;
}
Ejemplo n.º 5
0
int gpio_setup() {
	// Initialise it
	uint8_t v[8];
	if (!(GET_REG(POWER + POWER_ID) & 1)) {
		gpio_custom_io(0x502, 0);
		gpio_custom_io(0x503, 0);
		gpio_custom_io(0x504, 0);
		gpio_pulldown_configure(0x502, GPIOPDDown);
		gpio_pulldown_configure(0x503, GPIOPDDown);
		gpio_pulldown_configure(0x504, GPIOPDDown);
		gpio_custom_io(0x202, 0);
		gpio_custom_io(0x301, 0);
		gpio_custom_io(0x304, 0);
		gpio_custom_io(0x305, 0);
		gpio_pulldown_configure(0x202, GPIOPDDown);
		gpio_pulldown_configure(0x301, GPIOPDDown);
		gpio_pulldown_configure(0x304, GPIOPDDown);
		gpio_pulldown_configure(0x305, GPIOPDDown);
		udelay(100);
		v[0] = chipid_get_gpio_epoch();
		v[1] = gpio_pin_state(0x504);
		v[2] = gpio_pin_state(0x503);
		v[3] = gpio_pin_state(0x502);
		v[4] = gpio_pin_state(0x305);
		v[5] = gpio_pin_state(0x304);
		v[6] = gpio_pin_state(0x301);
		v[7] = gpio_pin_state(0x202);
		gpio_custom_io(0x502, 4);
		gpio_custom_io(0x503, 4);
		gpio_custom_io(0x504, 4);
		gpio_custom_io(0x202, 4);
		gpio_custom_io(0x301, 4);
		gpio_custom_io(0x304, 4);
		gpio_custom_io(0x305, 4);
		uint32_t new_status = ((v[0] << 3 | v[1] << 2 | v[2] << 1 | v[3]) << 16) | ((v[4] << 3 | v[5] << 2 | v[6] << 1 | v[7]) << 8) | 1;
		SET_REG(POWER + POWER_ID, (GET_REG(POWER + POWER_ID) & 0xFF000000) | (new_status & 0xFFFFFF));
	}

	interrupt_install(GPIO_INTERRUPT, gpio_handle_interrupt, 0);
	interrupt_enable(GPIO_INTERRUPT);

	return 0;
}
Ejemplo n.º 6
0
int gpio_setup() {
	uint8_t v[9];
	if (!(GET_REG(POWERID) & 1)) {
		gpio_pin_use_as_input(0x107);
		gpio_pin_use_as_input(0x106);
		gpio_pin_use_as_input(0x105);
		gpio_pin_use_as_input(0x104);
		gpio_pin_use_as_input(0x103);
		gpio_pin_use_as_input(0x102);
		gpio_pin_use_as_input(0x101);
		gpio_pin_use_as_input(0x100);
		udelay(50);

		v[0] = CHIPID_GET_GPIO(chipid_get_gpio());
		v[1] = gpio_pin_state(0x104);
		v[2] = gpio_pin_state(0x105);
		v[3] = gpio_pin_state(0x106);
		v[4] = gpio_pin_state(0x107);
		v[5] = gpio_pin_state(0x100);
		v[6] = gpio_pin_state(0x101);
		v[7] = gpio_pin_state(0x102);
		v[8] = gpio_pin_state(0x103);

		gpio_pin_reset(0x107);
		gpio_pin_reset(0x106);
		gpio_pin_reset(0x105);
		gpio_pin_reset(0x104);
		gpio_pin_reset(0x103);
		gpio_pin_reset(0x102);
		gpio_pin_reset(0x101);
		gpio_pin_reset(0x100);

		uint32_t new_status = ((v[0] << 3 | v[1] << 2 | v[2] << 1 | v[3]) << 16) | ((v[4] << 3 | v[5] << 2 | v[6] << 1 | v[7]) << 8) | 1;
		SET_REG(POWERID, (GET_REG(POWERID) & 0xFF000000) | (new_status & 0xFFFFFF));
	}

	return 0;
}
Ejemplo n.º 7
0
int radio_setup_3g()
{
	gpio_pulldown_configure(RADIO_BB_PULLDOWN, GPIOPDDown);

	pmu_gpio(RADIO_GPIO_BB_ON, TRUE, OFF);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_RADIO_ON, ON);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_BB_RESET, ON);
	udelay(100000);
	gpio_pin_output(RADIO_GPIO_BB_RESET, OFF);
	udelay(100000);

	gpio_pin_use_as_input(RADIO_GPIO_RESET_DETECT);
	if(gpio_pin_state(RADIO_GPIO_RESET_DETECT) != 1)
	{
		bufferPrintf("radio: comm board not present, powered on, or at+xdrv=10,2 had been issued.\r\n");
		return -1;
	}

	bufferPrintf("radio: comm board detected.\r\n");

	if(!radio_wait_for_ok(10))
	{
		bufferPrintf("radio: no response from baseband!\r\n");
		return -1;
	}

	RadioAvailable = TRUE;

	bufferPrintf("radio: ready.\r\n");

	speaker_setup();

	return 0;
}
Ejemplo n.º 8
0
int buttons_is_home_pushed() {
	if(gpio_pin_state(BUTTONS_HOME) && pmu_get_reg(BUTTONS_IIC_STATE))
		return TRUE;
	else
		return FALSE;
}
Ejemplo n.º 9
0
int gpio_setup() {
#if !defined(CONFIG_IPHONE_4) && !defined(CONFIG_IPAD)
	int i;

	GPIORegs = (GPIORegisters*) GPIO;

	for(i = 0; i < GPIO_NUMINTGROUPS; i++) {
		// writes to all the interrupt status register to acknowledge and discard any pending
		SET_REG(GPIOIC + GPIO_INTSTAT + (i * 0x4), GPIO_INTSTAT_RESET);

		// disable all interrupts
		SET_REG(GPIOIC + GPIO_INTEN + (i * 0x4), GPIO_INTEN_RESET);
	}

	memset(InterruptGroups, 0, sizeof(InterruptGroups));

	interrupt_install(0x21, gpio_handle_interrupt, 0);
	interrupt_install(0x20, gpio_handle_interrupt, 1);
	interrupt_install(0x1f, gpio_handle_interrupt, 2);
	interrupt_install(0x03, gpio_handle_interrupt, 3);
	interrupt_install(0x02, gpio_handle_interrupt, 4);
	interrupt_install(0x01, gpio_handle_interrupt, 5);
	interrupt_install(0x00, gpio_handle_interrupt, 6);

	interrupt_enable(0x21);
	interrupt_enable(0x20);
	interrupt_enable(0x1f);
	interrupt_enable(0x03);
	interrupt_enable(0x02);
	interrupt_enable(0x01);
	interrupt_enable(0x00);

	clock_gate_switch(GPIO_CLOCKGATE, ON);

	return 0;
#else
	uint8_t v[8];
	if (!(GET_REG(GPIO) & 1)) {
		gpio_set(0x502, 0);
		gpio_set(0x503, 0);
		gpio_set(0x504, 0);
		gpio_switch(0x502, 0xFFFFFFFF);
		gpio_switch(0x503, 0xFFFFFFFF);
		gpio_switch(0x504, 0xFFFFFFFF);
		gpio_set(0x202, 0);
		gpio_set(0x301, 0);
		gpio_set(0x304, 0);
		gpio_set(0x305, 0);
		gpio_switch(0x202, 0xFFFFFFFF);
		gpio_switch(0x301, 0xFFFFFFFF);
		gpio_switch(0x304, 0xFFFFFFFF);
		gpio_switch(0x305, 0xFFFFFFFF);
		udelay(100);
		v[0] = chipid_get_gpio();
		v[1] = gpio_pin_state(0x504);
		v[2] = gpio_pin_state(0x503);
		v[3] = gpio_pin_state(0x502);
		v[4] = gpio_pin_state(0x305);
		v[5] = gpio_pin_state(0x304);
		v[6] = gpio_pin_state(0x301);
		v[7] = gpio_pin_state(0x202);
		gpio_set(0x502, 4);
		gpio_set(0x503, 4);
		gpio_set(0x504, 4);
		gpio_set(0x202, 4);
		gpio_set(0x301, 4);
		gpio_set(0x304, 4);
		gpio_set(0x305, 4);
		uint32_t new_status = ((v[0] << 3 | v[1] << 2 | v[2] << 1 | v[3]) << 16) | ((v[4] << 3 | v[5] << 2 | v[6] << 1 | v[7]) << 8) | 1;
		SET_REG(POWER + POWER_ID, (GET_BITS(GET_REG(POWER + POWER_ID), 24, 8)) | (new_status & 0xFFFFFF));
	}

	return 0;
#endif
}
Ejemplo n.º 10
0
int buttons_is_pushed(int which) {
	if(gpio_pin_state(which) && pmu_get_reg(BUTTONS_IIC_STATE))
		return TRUE;
	else
		return FALSE;
}