Example #1
0
int main(void)
{
	__stack_chk_guard = random32();
	setup();
	memory_protect();
	oledInit();

	// at least one button is unpressed
	uint16_t state = gpio_port_read(BTN_PORT);
	if ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO) {

		check_firmware_sanity();

		oledClear();
		oledDrawBitmap(40, 0, &bmp_logo64_empty);
		oledRefresh();

		uint8_t hash[32];
		if (!signatures_ok(hash)) {
			show_unofficial_warning(hash);
		}

		load_app();

	}

	bootloader_loop();

	return 0;
}
Example #2
0
void tim3_isr(void) {
  TIM_SR(TIM3) &= ~TIM_SR_UIF;

  if ( 1||vblank ) {
    uint16_t a = gpio_port_read ( GPIOB );
    if ( a = 37 ) {
      gpio_toggle_blinkenlight();
      __asm__("nop");
    }

  }

}
Example #3
0
static uint8_t clock_in(void)
{
	uint8_t i,out;
	out = 0;
	for (i = 0; i < 8; i++)
	{
		gpio_set(R_CLK_PORT, R_CLK_PIN);
		out = out << 1;
		if (gpio_port_read(R_MI_PORT)&R_MI_PIN)
			out |= 0x1;
		gpio_clear(R_CLK_PORT, R_CLK_PIN);
	}
	return out;
}
Example #4
0
unsigned char lcdStatus() {
  unsigned char rv;
  int i;
  gpio_set(LCD_RW_PORT, LCD_RW_PIN);
  gpio_clear(LCD_DC_PORT, LCD_DC_PIN);
  
  gpio_clear(LCD_CS_PORT, LCD_CS_PIN);
  gpio_set(LCD_E_PORT, LCD_E_PIN);
  
  for(i=0;i<100;i++) {__asm__("nop\n\t");}
  
  rv = gpio_port_read(LCD_DATA_PORT) & LCD_DATA_MASK;
  gpio_clear(LCD_E_PORT, LCD_E_PIN);
  gpio_set(LCD_CS_PORT, LCD_CS_PIN);
  return rv;
}
Example #5
0
inline void lcd_write_byte(uint8_t b, bool rs_data)
{
    //place data
    gpio_port_write(GPIOD, (gpio_port_read(GPIOD) & ~0xFF) | (b & 0xFF));
    //R/W = write
    gpio_clear(GPIOE, GPIO1);
    // rs_data = true --> R/S = 1, else 0
    if (rs_data) {
        gpio_set(GPIOE, GPIO2);
    } else {
        gpio_clear(GPIOE, GPIO2);
    }
    //set E=true
    gpio_set(GPIOE, GPIO0);
    //wait 500ns or more before falling edge of E
    delay_us(1);
    gpio_clear(GPIOE, GPIO0);
}
Example #6
0
u32 ScanButtons()
{
    u8 idx = 0;
    u32 result = 0;
    const u16 *c, *r;
    gpio_set(COL_PORT, COL_PORT_MASK);
    for(c = columns; *c != 0xffff; c++) {
        gpio_clear(COL_PORT, *c);
        u16 but = gpio_port_read(ROW_PORT);
        gpio_set(COL_PORT, *c);
        for(r = rows; *r != 0xffff; r++) {
            if(! (but & *r)) {
                result |= 1 << (buttonmap[idx] - 1);
            }
            idx++;
        }
    }
    return result;
}
Example #7
0
void lcd_poll_busy(void)
{
    delay_us(40);
    // set DB7-0 as input temporarily
    gpio_mode_setup(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_NONE, 0xFF);
    // set R/W to "read"
    gpio_set(GPIOE, GPIO1);
    // set RS to "command"
    gpio_clear(GPIOE, GPIO2);
    uint8_t res = 0;
    do {
        gpio_set(GPIOE, GPIO0); // set enable
        res = gpio_port_read(GPIOD) & (1 << 7); // read command register
        delay_us(40); // wait between reads
        gpio_clear(GPIOE, GPIO0); // clear enable            
    } while (res != 0);

    // restore DB7-0 as output
    gpio_mode_setup(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_NONE, 0xFF);
    // set R/W to "write"
    gpio_clear(GPIOE, GPIO1);
}
Example #8
0
int main(void)
{
#ifndef APPVER
	setup();
#endif
	__stack_chk_guard = random32(); // this supports compiler provided unpredictable stack protection checks
#ifndef APPVER
	memory_protect();
	oledInit();
#endif

#ifndef APPVER
	// at least one button is unpressed
	uint16_t state = gpio_port_read(BTN_PORT);
	int unpressed = ((state & BTN_PIN_YES) == BTN_PIN_YES || (state & BTN_PIN_NO) == BTN_PIN_NO);

	if (firmware_present() && unpressed) {

		oledClear();
		oledDrawBitmap(40, 0, &bmp_logo64_empty);
		oledRefresh();

		uint8_t hash[32];
		int signed_firmware = signatures_ok(hash);
		if (SIG_OK != signed_firmware) {
			show_unofficial_warning(hash);
			timer_init();
		}

		load_app(signed_firmware);
	}
#endif

	bootloader_loop();

	return 0;
}
Example #9
0
u32 gpio_get(u32 gpioport, u32 gpios)
{
	return gpio_port_read(gpioport) & gpios;
}
Example #10
0
File: em-stop.c Project: GBert/misc
void sys_tick_handler(void) {
    static uint8_t data[5] = { 0, 0, 0, 0, 0 };

    /* We call this handler every 1ms so every 1ms = 0.001s
     * resulting in 1Hz message rate.
     */

    /* Transmit CAN frame. */
    counter++;

    if (gpio_port_read(GPIO_PORT_B_BASE) && (1 << 6)) {
	/* if status changed send command */
	if (status == 1) {
	    data[4] = 0;
	    can_transmit(CAN1, 0x0000fffe, true, false, 5, data);
	}
	status = 0;
    } else if (!(gpio_port_read(GPIO_PORT_B_BASE) && (1 << 7))) {
	/* if status changed send command */
	if (status == 0) {
	    data[4] = 1;
	    can_transmit(CAN1, 0x0000fffe, true, false, 5, data);
	}
	status = 1;
    }
#if 1
    switch (counter) {
    case 125:
	gpio_clear(GPIOB, GPIO3);
	break;
    case 250:
	gpio_set(GPIOB, GPIO3);
	break;
    case 375:
	gpio_clear(GPIOB, GPIO3);
	break;
    case 500:
	gpio_set(GPIOB, GPIO4);
	break;
    case 1000:
	counter = 0;
	break;
    default:
	break;
    }
#else
    if (counter == 1000) {
	counter = 0;
	if (status) {
	    data[4] = 1;
	} else {
	    data[4] = 0;
	}

	if (can_transmit(CAN1, 0x0000fffe,	/* (EX/ST)ID: CAN ID */
			 true,	/* IDE: CAN ID extended? */
			 false,	/* RTR: Request transmit? */
			 5,	/* DLC: Data length */
			 data) == -1) {
	    gpio_set(GPIOC, GPIO13);	/* LED green off */
	}
    }
#endif
}
Example #11
0
uint16_t gpio_get(uint32_t gpioport, uint16_t gpios)
{
	return gpio_port_read(gpioport) & gpios;
}