Ejemplo n.º 1
0
Archivo: jump.c Proyecto: Bediko/r0ket
static void move_player(long frame_count) {
	// move x
	if(gpioGetValue(RB_BTN0) == 0) {
		game.player_x_vel--;
	}	    
	else if(gpioGetValue(RB_BTN1) == 0) {
		game.player_x_vel++;
	}
	else {
		game.player_x_vel = 0;
	}
	if(game.player_x_vel > MAX_VEL_X) {
		game.player_x_vel = MAX_VEL_X;
	}
	else if(game.player_x_vel < -1*MAX_VEL_X) {
		game.player_x_vel = -1*MAX_VEL_X;
	}
	game.player_x += game.player_x_vel + RESX;
	game.player_x %= RESX;

	// move y (jump)
	// half the speed
	if(frame_count%2 == 0) {

		int old_y = game.player_y;

		if(game.player_ground) {
			game.player_y_vel = JUMP_FORCE;
			game.player_ground = false;
		}

		game.player_y_vel += GRAVITY;
		game.player_y_vel = game.player_y_vel > MAX_VEL_Y ? MAX_VEL_Y : game.player_y_vel;
		int new_y = old_y + game.player_y_vel;

		// collision detection
		int player_x_center = game.player_x + PLAYER_SPRITE_WIDTH/2;
		for(int i = 0; i < NUM_PLATFORMS; i++) {
			if(game.player_y_vel > 0
					&& old_y < game.platforms_y[i] 
					&& new_y >= game.platforms_y[i]
					&& game.platforms_x1[i] <= player_x_center+2
					&& game.platforms_x2[i] >= player_x_center-2) {

				game.player_y = game.platforms_y[i]-1;
				game.player_y_vel = 0;
				game.player_ground = true;

				break;
			}
		}

		game.player_y = new_y;

		if(game.player_y > RESY + PLAYER_SPRITE_HEIGHT) {
			game.running = false;
		}
	}
}
Ejemplo n.º 2
0
int
main(void)
{
  // Configure cpu and mandatory peripherals
  systemInit();

  uint32_t currentSecond, lastSecond;
  currentSecond = lastSecond = 0;
  
  // uartInit(115200);
  prt();

  while (1)
  {
    // Toggle LED once per second
    currentSecond = systickGetSecondsActive();
    if (currentSecond != lastSecond)
    {
      lastSecond = currentSecond;
      gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, !(gpioGetValue(CFG_LED_PORT, CFG_LED_PIN)));
      uartSendByte('*');
    }

    // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h
    #ifdef CFG_INTERFACE 
      cmdPoll(); 
    #endif
  }

  return 0;
}
Ejemplo n.º 3
0
int main(void)
{
  // Configure cpu and mandatory peripherals
  systemInit();

  uint32_t currentSecond, lastSecond;
  currentSecond = lastSecond = 0;

  while (1)
  {
    // Toggle LED once per second ... rollover = 136 years :)
    currentSecond = systickGetSecondsActive();
    if (currentSecond != lastSecond)
    {
      lastSecond = currentSecond;
      if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
      {
        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); 
      }
      else
      {
        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); 
      }
    }

    // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h
    #ifdef CFG_INTERFACE 
      cmdPoll(); 
    #endif
  }

  return 0;
}
Ejemplo n.º 4
0
/** reaction.c
 *  First l0dable for my r0ket
 *  Improvement is welcome
 *
 * AUTHOR: hubba
*/
void ram(void)
{
    char x = gpioGetValue(RB_LED1);
    int rand_wait = 0;
    int react_time=0;
    int start_time = 0;
    int end_time = 0;

    gpioSetValue (RB_LED1,0);           //upperleft LED off
    lcdClear();
    lcdPrintln("Hello");
    lcdPrintln(GLOBAL(nickname));
    lcdPrintln("ReACTION");
    lcdRefresh();
    delayms(500);
    while(1)
    {
        react_time = 0;
        lcdPrintln("Press ENTER if ");
        lcdPrintln("LED is on!");
        lcdRefresh();
        rand_wait = getRandom();
        rand_wait = rand_wait%50;
        rand_wait = 40 + rand_wait*4;        // Minimum pause time is 400ms
        for(int i =0; i<=rand_wait; i++)     //directly calling delayms(rand_wait) didn't work
        {
            delayms(10);
        }
        gpioSetValue (RB_LED1, 1);          //upperleft LED ON
        getInputWaitRelease();
        start_time = getTimer()*(SYSTICKSPEED);
        while (getInputWait() != BTN_ENTER);    //wait for user input
        {

        }
        end_time =  getTimer()*(SYSTICKSPEED);
        react_time = end_time - start_time;     //measure  used time
        lcdClear();
        lcdPrint("Needed ");
        lcdPrintInt(react_time);
        lcdPrintln(" ms");
        lcdPrintln("DOWN: Exit");
        lcdPrintln("0ther: New game");
        lcdRefresh();
        gpioSetValue (RB_LED1,0);           //upperleft LED off

        getInputWaitRelease();
        if(getInputWait() ==  BTN_DOWN)     //Check for Exit/new game
        {
            gpioSetValue (RB_LED1, x);      //upperleft LED as before l0dable executed
            return;
        }
    }
    /* NEVER LAND HERE */
    lcdPrintln("Flow-Error");
    lcdRefresh();
    return;
};
Ejemplo n.º 5
0
void ram(void){
    char x = gpioGetValue(RB_LED1);

	for (int x=0;x<20;x++){
		gpioSetValue (RB_LED1, x%2); 
		delayms(50);
	};
    gpioSetValue (RB_LED1, x); 
}
Ejemplo n.º 6
0
static void
sts(void)
{
	int j, i;
	char s[64];

	j = 0;
	s[j++] = 's';
	s[j++] = '0' + gpioGetValue(1, 1);
	s[j++] = ' ';
	for (i = 7; i >- 0; i--)
		s[j++] = '0' + gpioGetValue(2, i);
	s[j++] = ' ';
	s[j++] = 'a';
	s[j++] = '0' + gpioGetValue(3, 0);
	s[j++] = ' ';
	s[j++] = 'i';
	s[j++] = '0' + gpioGetValue(3, 2);
	s[j++] = ' ';
	s[j++] = 's';
	s[j++] = '0' + gpioGetValue(3, 3);
	s[j++] = ' ';
	s[j++] = ' ';
	s[j++] = 's';
	s[j++] = '0' + gpioGetValue(0, 8);
	s[j++] = ' ';
	s[j++] = 'p';
	s[j++] = '0' + gpioGetValue(0, 9);
	s[j++] = ' ';
	s[j++] = 'b';
	s[j++] = '0' + gpioGetValue(0, 10);
	s[j++] = ' ';
	s[j++] = 'a';
	s[j++] = '0' + gpioGetValue(0, 11);
	s[j++] = ' ';
	s[j++] = 'e';
	s[j++] = '0' + gpioGetValue(3, 1);
	
	s[j++] = '\0';
	puts(s);
	puts("\r\n");
}
Ejemplo n.º 7
0
void cmd_sysinfo(uint8_t argc, char **argv)
{
  IAP_return_t iap_return;

  printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE);
  printf("%-25s : v%d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE);

  // 128-bit MCU Serial Number
  iap_return = iapReadSerialNumber();
  if(iap_return.ReturnCode == 0)
  {
    printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE);
  }

  // CLI and buffer Settings
  #ifdef CFG_INTERFACE
    printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE);
  #endif

  #ifdef CFG_PRINTF_UART
    uart_pcb_t *pcb = uartGetPCB();
    printf("%-25s : %d %s", "UART Baud Rate", pcb->baudrate, CFG_PRINTF_NEWLINE);
  #endif

  // TFT LCD Settings (if CFG_TFTLCD enabled)
  #ifdef CFG_TFTLCD
    printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE);
  #endif

  // Wireless Settings (if CFG_CHIBI enabled)
  #ifdef CFG_CHIBI
    chb_pcb_t *pcb = chb_get_pcb();
    printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE);
  #endif

  // System Uptime (based on systick timer)
  printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE);

  // System Temperature (if LM75B Present)
  #ifdef CFG_LM75B
    int32_t temp = 0;
    lm75bGetTemperature(&temp);
    temp *= 125;
    printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE);
  #endif

  #ifdef CFG_SDCARD
    printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE);
  #endif
}
Ejemplo n.º 8
0
static void conrtols(void){
  if (gpioGetValue(RB_BTN0)==0) {
    if (game.ship_x > 0){
      game.ship_x -= 1;
    }
	} else if (gpioGetValue(RB_BTN1)==0) {
	  if (game.ship_x < RESX-SHIP_WIDTH){ 
      game.ship_x += 1;
    }
	} else if (gpioGetValue(RB_BTN2)==0) {
	  if (game.ship_y < RESY-SHIP_HEIGHT){ 
      game.ship_y += 1;
    }
	} else if (gpioGetValue(RB_BTN3)==0) {
	  if (game.ship_y > 0){
      game.ship_y -= 1;
    }
	} else if (gpioGetValue(RB_BTN4)==0) {
    shoot();
	}
}
Ejemplo n.º 9
0
uint8_t lcdRead(uint8_t data)
{
    uint32_t op211cache=IOCON_PIO2_11;
    uint32_t op09cache=IOCON_PIO0_9;
    uint32_t dircache=GPIO_GPIO2DIR;
    IOCON_PIO2_11=IOCON_PIO2_11_FUNC_GPIO|IOCON_PIO2_11_MODE_PULLUP;
    IOCON_PIO0_9=IOCON_PIO0_9_FUNC_GPIO|IOCON_PIO0_9_MODE_PULLUP;
    gpioSetDir(SCK, 1);

    uint8_t i;

    gpioSetDir(SDA, 1);
    gpioSetValue(SCK, 0);
    gpioSetValue(CS, 0);
    delayms(1);

    gpioSetValue(SDA, 0);
    gpioSetValue(SCK, 1);
    delayms(1);
    
    for(i=0; i<8; i++){
        gpioSetValue(SCK, 0);
        delayms(1);
        if( data & 0x80 )
            gpioSetValue(SDA, 1);
        else
            gpioSetValue(SDA, 0);
        data <<= 1;
        gpioSetValue(SCK, 1);
        delayms(1);
    }
    uint8_t ret = 0;

    gpioSetDir(SDA, 0);
    for(i=0; i<8; i++){
        gpioSetValue(SCK, 0);
        delayms(1);
        ret <<= 1;
        ret |= gpioGetValue(SDA);
        gpioSetValue(SCK, 1);
        delayms(1);
    }
    gpioSetValue(SCK, 0);

    gpioSetValue(CS, 1);
    gpioSetDir(SDA, 1);
    IOCON_PIO2_11=op211cache;
    IOCON_PIO0_9=op09cache;
    GPIO_GPIO2DIR=dircache;
    delayms(1);
    return ret;
}
Ejemplo n.º 10
0
int main(void)
{
  #ifndef CFG_PWM
    #ERROR "CFG_PWM must be enabled in projectconfig.h for this example."
  #endif

  // Configure cpu and mandatory peripherals
  // PWM is initialised in systemInit and defaults to using P1.9
  systemInit();

  // Set duty cycle to 50% for square wave output
  pwmSetDutyCycle(50);

  // Frequency can be set anywhere from 2khz and 10khz (4khz is loudest)
  // Note: Since this is a 16-bit timer, make sure the delay is not
  //       greater than 0xFFFF (65535), though anything 2khz and higher
  //       is within an acceptable range
  // The piezo buzzer used for this example is the PS1240, available at
  // http://www.adafruit.com/index.php?main_page=product_info&cPath=35&products_id=160
  pwmSetFrequencyInTicks(CFG_CPU_CCLK / 2000);

  uint32_t currentSecond, lastSecond;
  currentSecond = lastSecond = 0;

  while (1)
  {
    // Beep the piezo buzzer very briefly once per second, toggling the LED at the same time
    currentSecond = systickGetSecondsActive();
    // Make sure that at least one second has passed
    if (currentSecond != lastSecond)
    {
      // Update the second tracker
      lastSecond = currentSecond;
      // Set the LED state and buzzer loudness depending on the current LED state
      if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
      {
        pwmSetFrequencyInTicks(CFG_CPU_CCLK / 4000);            // 4khz (louder)
        pwmStartFixed(200);                                     // 2x as long as @ 2khz since it's 2x faster
        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);   // Turn the LED on
      }
      else
      {
        pwmSetFrequencyInTicks(CFG_CPU_CCLK / 2000);            // 2khz (softer)
        pwmStartFixed(100);                                    
        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);  // Turn the LED off
      }
    }
  }

  return 0;
}
Ejemplo n.º 11
0
void VoltageCheck(void){

    chrg=gpioGetValue(RB_PWR_CHRG);

	results = adcRead(1);
	results *= 10560;
	results /= 1024;

	if( results < 3500 ){
        nrf_off();
	    gpioSetValue (RB_PWR_GOOD, 0); 
	    gpioSetValue (RB_LCD_BL, 0); 
	    SCB_SCR |= SCB_SCR_SLEEPDEEP;
	    PMU_PMUCTRL = PMU_PMUCTRL_DPDEN_DEEPPOWERDOWN;
	    __asm volatile ("WFI");
    };
Ejemplo n.º 12
0
int main(void)
{
  // Configure cpu and mandatory peripherals
  systemInit();

  while (1)
  {
    // Wait one second
    systickDelay(1000);
    // Toggle the LED
    if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
    {
      gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); 
    }
    else
    {
      gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); 
    }
  }

  return 0;
}
Ejemplo n.º 13
0
int main(void)
{
  // Configure cpu and mandatory peripherals
  systemInit();

  uint32_t currentSecond, lastSecond;
  currentSecond = lastSecond = 0;

  // Toggle LED once per second and constantly check CLI input
  while (1)
  {
    // Get the number of seconds the CPU has been active
    // If the value has changed we've advanced at least 1 second
    currentSecond = systickGetSecondsActive();
    if (currentSecond != lastSecond)
    {
      lastSecond = currentSecond;
      // Toggle the LED
      if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
      {
        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); 
      }
      else
      {
        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); 
      }
    }

    // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h
    #ifdef CFG_INTERFACE 
      cmdPoll(); 
    #endif
  }

  return 0;
}
Ejemplo n.º 14
0
U8 chb_set_state(U8 state)
{
    U8 curr_state, delay;

    // if we're sleeping then don't allow transition
    if (gpioGetValue(CHB_SLPTRPORT, CHB_SLPTRPIN))
    {
        return RADIO_WRONG_STATE;
    }

    // if we're in a transition state, wait for the state to become stable
    curr_state = chb_get_state();
    if ((curr_state == BUSY_TX_ARET) || (curr_state == BUSY_RX_AACK) || (curr_state == BUSY_RX) || (curr_state == BUSY_TX))
    {
        while (chb_get_state() == curr_state);
    }

    // At this point it is clear that the requested new_state is:
    // TRX_OFF, RX_ON, PLL_ON, RX_AACK_ON or TX_ARET_ON.
    // we need to handle some special cases before we transition to the new state
    switch (state)
    {
    case TRX_OFF:
        /* Go to TRX_OFF from any state. */
        CHB_SLPTR_DISABLE();
        chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1f);
        chb_delay_us(TIME_ALL_STATES_TRX_OFF);
        break;

    case TX_ARET_ON:
        if (curr_state == RX_AACK_ON)
        {
            /* First do intermediate state transition to PLL_ON, then to TX_ARET_ON. */
            chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f);
            chb_delay_us(TIME_RX_ON_PLL_ON);
        }
        break;

    case RX_AACK_ON:
        if (curr_state == TX_ARET_ON)
        {
            /* First do intermediate state transition to RX_ON, then to RX_AACK_ON. */
            chb_reg_read_mod_write(TRX_STATE, CMD_PLL_ON, 0x1f);
            chb_delay_us(TIME_RX_ON_PLL_ON);
        }
        break;
    }

    /* Now we're okay to transition to any new state. */
    chb_reg_read_mod_write(TRX_STATE, state, 0x1f);

    /* When the PLL is active most states can be reached in 1us. However, from */
    /* TRX_OFF the PLL needs time to activate. */
    delay = (curr_state == TRX_OFF) ? TIME_TRX_OFF_PLL_ON : TIME_RX_ON_PLL_ON;
    chb_delay_us(delay);

    if (chb_get_state() == state)
    {
        return RADIO_SUCCESS;
    }
    return RADIO_TIMED_OUT;
}
Ejemplo n.º 15
0
int main(void)
{
  #if !defined CFG_TFTLCD
    #error "CFG_TFTLCD must be enabled in projectconfig.h for this test"
  #endif
  #if defined CFG_INTERFACE
    #error "CFG_INTERFACE must be disabled in projectconfig.h for this test (to save space)"
  #endif

  // Configure cpu and mandatory peripherals
  systemInit();
  
  /* Set P2.0 to GPIO input (just in case) */
  gpioSetDir(2, 0, 0);

  /* Set P1.4/AD5 to analog input (only AD0..3 are configured by adcInit) */
  IOCON_PIO1_4 &= ~(IOCON_PIO1_4_ADMODE_MASK |
                    IOCON_PIO1_4_FUNC_MASK |
                    IOCON_PIO1_4_MODE_MASK);
  IOCON_PIO1_4 |=  (IOCON_PIO1_4_FUNC_AD5 &
                    IOCON_PIO1_4_ADMODE_ANALOG);

  // Rotate the screen and render the area around the data grid
  lcdSetOrientation(LCD_ORIENTATION_LANDSCAPE);
  renderLCDFrame();

  tsTouchData_t touch;

  // Start reading
  while (1)
  {
    // Wait up to 5ms for a touch event
    tsTouchError_t error = tsWaitForEvent(&touch, 5);
    if (!error)
    {
      if (touch.x > 25 && touch.x < 100 && touch.y > 210)
      {
        // Analog switch selected
        adcEnabled = adcEnabled ? false : true;
      }
      if (touch.x > 125 && touch.x < 200 && touch.y > 210)
      {
        // Digital switch selected
        digEnabled = digEnabled ? false : true;
      }
      // Refresh the frame
      renderLCDFrame();
    }

    // Read pins
    if (adcEnabled)
      addToBuffer(adcBuffer, adcRead(5) / 4); // 10-bit value converted to 8-bits
    if (digEnabled)
      addToBuffer(digBuffer, gpioGetValue(2, 0) ? 0xFF : 0x00);

    // Update the LCD is required
    renderLCDGrid();

    // Note, this will actually mean the timing is ~100mS + the amount of
    // time it took to get the readings and update the LCD
    // A timer interrupt could be used to get much more accurate results,
    // filling the buffer inside the IRQ and rendering the screen updates
    // every x milliseconds
    systickDelay(100);
  }

  return 0;
}
Ejemplo n.º 16
0
void cmd_sysinfo(uint8_t argc, char **argv)
{
  IAP_return_t iap_return;

  /* Note: Certain values are only reported if CFG_INTERFACE_LONGSYSINFO
     is set to 1 in projectconfig.h.  These extra values are more useful
     for debugging than real-world use, so there's no point wasiting
     flash space storing the code for them */

  printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE);
  printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE);

  // System Uptime (based on systick timer)
  printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE);

  // 128-bit MCU Serial Number
  iap_return = iapReadSerialNumber();
  if(iap_return.ReturnCode == 0)
  {
    printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE);
  }

  #if CFG_INTERFACE_LONGSYSINFO
    #ifdef CFG_USBCDC
      printf("%-25s : %d ms %s", "USB Init Timeout", CFG_USBCDC_INITTIMEOUT, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  // CLI and buffer Settings
  #if CFG_INTERFACE_LONGSYSINFO
    printf("%-25s : %d bytes %s", "CLI Max Command Size", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE);
    printf("%-25s : %s %s", "CLI IRQ Enabled", CFG_INTERFACE_ENABLEIRQ ? "True" : "False", CFG_PRINTF_NEWLINE);
    #if CFG_INTERFACE_ENABLEIRQ
      printf("%-25s : %d.%d %s", "CLI IRQ Location", CFG_INTERFACE_IRQPORT, CFG_INTERFACE_IRQPIN, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  #if CFG_INTERFACE_LONGSYSINFO
    #ifdef CFG_I2CEEPROM
      printf("%-25s : %d bytes %s", "EEPROM Size", CFG_I2CEEPROM_SIZE, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  #ifdef CFG_SDCARD
    printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE);
    #if CFG_INTERFACE_LONGSYSINFO
      printf("%-25s : %s %s", "FAT File System", CFG_SDCARD_READONLY ? "Read Only" : "Read/Write", CFG_PRINTF_NEWLINE);
    #endif
  #endif

  #ifdef CFG_PRINTF_UART
    uart_pcb_t *pcb = uartGetPCB();
    printf("%-25s : %u %s", "UART Baud Rate", (unsigned int)(pcb->baudrate), CFG_PRINTF_NEWLINE);
  #endif

  // TFT LCD Settings (if CFG_TFTLCD enabled)
  #ifdef CFG_TFTLCD
    printf("%-25s : %d %s", "LCD Width", (int)lcdGetWidth(), CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "LCD Height", (int)lcdGetHeight(), CFG_PRINTF_NEWLINE);
    #if CFG_INTERFACE_LONGSYSINFO
      printf("%-25s : %04X %s", "LCD Controller ID", (unsigned short)lcdGetControllerID(), CFG_PRINTF_NEWLINE);
      printf("%-25s : %s %s", "LCD Small Fonts", CFG_TFTLCD_INCLUDESMALLFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE);
      printf("%-25s : %s %s", "LCD AA Fonts", CFG_TFTLCD_USEAAFONTS == 1 ? "True" : "False", CFG_PRINTF_NEWLINE);
      lcdProperties_t lcdprops = lcdGetProperties();
      printf("%-25s : %s %s", "Touch Screen", lcdprops.touchscreen ? "True" : "False", CFG_PRINTF_NEWLINE);
      if (lcdprops.touchscreen)
      {
        printf("%-25s : %s %s", "Touch Screen Calibrated", eepromReadU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED) == 1 ? "True" : "False", CFG_PRINTF_NEWLINE);
        printf("%-25s : %d %s", "Touch Screen Threshold", CFG_TFTLCD_TS_DEFAULTTHRESHOLD, CFG_PRINTF_NEWLINE);
      }
    #endif
  #endif

  // Wireless Settings (if CFG_CHIBI enabled)
  #ifdef CFG_CHIBI
    chb_pcb_t *pcb = chb_get_pcb();
    printf("%-25s : %s %s", "Wireless", "AT86RF212", CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X %s", "802.15.4 Node Address", pcb->src_addr, CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE);
  #endif

  // System Temperature (if LM75B Present)
  #ifdef CFG_LM75B
    int32_t temp = 0;
    lm75bGetTemperature(&temp);
    temp *= 125;
    printf("%-25s : %d.%d C %s", "Temperature", temp / 1000, temp % 1000, CFG_PRINTF_NEWLINE);
  #endif

  // ADC Averaging
  #if CFG_INTERFACE_LONGSYSINFO
    printf("%-25s : %s %s", "ADC Averaging", ADC_AVERAGING_ENABLE ? "True" : "False", CFG_PRINTF_NEWLINE);
    #if ADC_AVERAGING_ENABLE
      printf("%-25s : %d %s", "ADC Averaging Samples", ADC_AVERAGING_SAMPLES, CFG_PRINTF_NEWLINE);
    #endif
  #endif

  // Debug LED
  #if CFG_INTERFACE_LONGSYSINFO
    printf("%-25s : %d.%d %s", "LED Location", CFG_LED_PORT, CFG_LED_PIN, CFG_PRINTF_NEWLINE);
  #endif
}
void cmd_sysinfo(uint8_t argc, char **argv)
{
  printf("%-25s : %d.%d MHz %s", "System Clock", CFG_CPU_CCLK / 1000000, CFG_CPU_CCLK % 1000000, CFG_PRINTF_NEWLINE);
  printf("%-25s : %d.%d.%d %s", "Firmware", CFG_FIRMWARE_VERSION_MAJOR, CFG_FIRMWARE_VERSION_MINOR, CFG_FIRMWARE_VERSION_REVISION, CFG_PRINTF_NEWLINE);

  // 128-bit MCU Serial Number
  IAP_return_t iap_return;
  iap_return = iapReadSerialNumber();
  if(iap_return.ReturnCode == 0)
  {
    printf("%-25s : %08X %08X %08X %08X %s", "Serial Number", iap_return.Result[0],iap_return.Result[1],iap_return.Result[2],iap_return.Result[3], CFG_PRINTF_NEWLINE);
  }

  // Check the battery voltage
  #ifdef CFG_BAT
    uint32_t c;
    gpioSetDir(CFG_BAT_ENPORT, CFG_BAT_ENPIN, gpioDirection_Output );   
    gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 1 );    // Enable the voltage divider
    systickDelay(5);
    c = adcRead(CFG_BAT_ADC);                           // Pre-read ADC to warm it up
    systickDelay(10);
    c = adcRead(CFG_BAT_ADC);
    c = (c * CFG_VREG_VCC_MAIN) / 1000;                 // Value in millivolts relative to supply voltage
    c = (c * CFG_BAT_MULTIPLIER) / 1000;                // Battery voltage in millivolts (depends on resistor values)
    gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 0 );    // Turn the voltage divider back off to save power
    printf("%-25s : %u.%u V %s", "Supply Voltage", (unsigned int)(c / 1000), (unsigned int)(c % 1000), CFG_PRINTF_NEWLINE);
  #endif

  // Wireless Settings (if CFG_CHIBI enabled)
  #ifdef CFG_CHIBI
    chb_pcb_t *pcb = chb_get_pcb();
    printf("%-25s : %s %s", "RF Transceiver", "AT86RF212", CFG_PRINTF_NEWLINE);
    #if CFG_CHIBI_PROMISCUOUS == 1
      printf("%-25s : %s %s", "RF Receive Mode", "Promiscuous", CFG_PRINTF_NEWLINE);
    #else
      printf("%-25s : %s %s", "RF Receive Mode", "Normal", CFG_PRINTF_NEWLINE);
    #endif
    printf("%-25s : 0x%04X (%d) %s", "802.15.4 PAN ID", CFG_CHIBI_PANID, CFG_CHIBI_PANID, CFG_PRINTF_NEWLINE);
    printf("%-25s : 0x%04X (%d) %s", "802.15.4 Node Address", pcb->src_addr, pcb->src_addr, CFG_PRINTF_NEWLINE);
    printf("%-25s : %d %s", "802.15.4 Channel", CFG_CHIBI_CHANNEL, CFG_PRINTF_NEWLINE);
  #endif

  // CLI and buffer Settings
  #ifdef CFG_INTERFACE
    printf("%-25s : %d bytes %s", "Max CLI Command", CFG_INTERFACE_MAXMSGSIZE, CFG_PRINTF_NEWLINE);
  #endif

  // System Uptime (based on systick timer)
  printf("%-25s : %u s %s", "System Uptime", (unsigned int)systickGetSecondsActive(), CFG_PRINTF_NEWLINE);

  // System Temperature (if LM75B Present)
  #ifdef CFG_LM75B
    int32_t temp = 0;
    lm75bGetTemperature(&temp);
    temp *= 125;
    printf("%-25s : %d.%d C %s", "Temperature", (int)(temp / 1000), (int)(temp % 1000), CFG_PRINTF_NEWLINE);
  #endif

  #ifdef CFG_SDCARD
    printf("%-25s : %s %s", "SD Card Present", gpioGetValue(CFG_SDCARD_CDPORT, CFG_SDCARD_CDPIN) ? "True" : "False", CFG_PRINTF_NEWLINE);
  #endif
}
Ejemplo n.º 18
0
void main_sec(void) {

    backlightInit();

    //disable the JTAG on PIO3_3
    IOCON_PIO3_3 = 0x10;

    int yctr=8;
    int dx=0;

    font_direction = FONT_DIR_LTR; // LeftToRight is the default

    yctr=18;

    uint8_t trigger;

    trigger=20;

    uint32_t ctr=0;
    char key;
    while (1) {
        ctr++;

        lcdDisplay(0);
        delayms(10);

        key= getInput();
        if(key==BTN_UP){
            trigger +=1;
        }else if (key ==BTN_DOWN){
            trigger -=1;
        };

        font=&Font_7x8;
        dx=DoString(0,0,"Trig:");
        dx=DoInt(dx,0,trigger);
        DoString(dx,0," ");

        // Easy flashing
        if(key==BTN_LEFT){
            DoString(0,8,"Enter ISP!");
            lcdDisplay(0);
            ISPandReset(5);
        };

        // Display nickname
        font = &Font_Ubuntu36pt;
        dx=DoString(0,0,"Sec");

        // Blink LED
        if(ctr++>trigger){
            ctr=0;
            if (gpioGetValue(RB_LED2) == CFG_LED_OFF){
                gpioSetValue (RB_LED2, CFG_LED_ON); 
            } else {
                gpioSetValue (RB_LED2, CFG_LED_OFF); 
            };
        };

        // Print Voltage
        font = &Font_7x8;
        dx=DoString(0,yctr+28,"Voltage:");
        DoInt(dx,yctr+28,GetVoltage());

    }
    return;
}
Ejemplo n.º 19
0
static uint8_t mainloop() {
	uint32_t volatile oldCount = BusIntCtr;
	uint32_t loopCount=BusIntCtr;
	perMin = 0; // counts in last 60 s
	uint32_t minuteTime = _timectr;
	startTime = minuteTime;
	uint8_t button;
	//usbHIDInit();
	while (1) {
		LED_OFF;
		if (loopCount != BusIntCtr) {
			loopCount=BusIntCtr;
			LED_ON;
			IOCON_PIO1_11 = IOCON_PIO1_11_FUNC_GPIO;
			gpioSetDir(RB_LED3,gpioDirection_Output ) ;
			gpioSetValue(RB_LED3, 1);
			if (!GLOBAL(positionleds) ) {
				gpioSetValue(RB_LED2,1);
				gpioSetValue(RB_LED0,1);
			}
		} else {
			if (gpioGetValue(RB_PWR_CHRG) || !GLOBALchargeled) {
				gpioSetDir(RB_LED3,gpioDirection_Input ); // only when not charging..
				}
				if (!GLOBAL(positionleds) ) {
					gpioSetValue(RB_LED0,0);
					gpioSetValue(RB_LED2,0);
				}
			}

		lcdClear();
		//lcdPrintln("   Geiger");
		//lcdPrintln("   Counter");


		memcpy(&lcdBuffer[RESX*RESY_B-sizeof(Header_Invers)],Header_Invers,sizeof(Header_Invers));
		lcdPrintln("");
		lcdPrintln("");
		// ####
		for (int i = 0; i < (14 * (_timectr - minuteTime)) / (60 * 100); i++) {
			lcdPrint("#");
		}
		lcdPrintln("");
		lcdPrint(" ");
		lcdPrintInt(BusIntCtr);
		lcdPrint(" in ");
		lcdPrintInt((_timectr - startTime) / 100);
		lcdPrintln("s");
		lcdPrint(" ");
		lcdPrintInt(perMin);
		lcdPrintln(" cpm");
		{
			uint32_t equivalent = nanoSievertPerH(perMin)+5; // letzte stelle runden
			lcdPrint(" ");
			lcdPrintInt(equivalent / 1000);
			lcdPrint(".");
			lcdPrintInt((equivalent % 1000) / 100);
			lcdPrintInt((equivalent % 100) / 10);
			//lcdPrintInt((equivalent % 10));
			lcdPrintln(" uSv/h");

		}
		//getGeigerMeshVal();
		lcdPrintln("");
		if (gpioGetValue(RB_PWR_CHRG)){
			uint32_t voltage=GetVoltage();
			if (voltage >= GOOD_VOLTAGE) {
				lcdPrintln("Bat: [++++] ");
			} else if (voltage >= HALF_VOLTAGE) {
				lcdPrintln("Bat: [ooo ] ");
			} else if (voltage >= MIN_SAFE_VOLTAGE) {
				lcdPrintln("Bat: [==  ]  ");
			} else if (voltage >= CRIT_VOLTAGE) {
				lcdPrintln("Bat: [-   ] L");
			} else {
				lcdPrintln("Battery: CRIT!");
			}
		} else {
			    lcdPrintln("Bat: Charging");
		}
		// remember: We have a 10ms Timer counter
		if ((minuteTime + 60 * 100) <= _timectr) {
			// dumb algo: Just use last 60 seconds count
			perMin = BusIntCtr - oldCount;
			minuteTime = _timectr;
			oldCount = BusIntCtr;
			//transmitGeigerMeshVal(perMin,minuteTime / (100));
		}
		lcdRefresh();
		delayms_queue_plus(42, 0);
		button = getInputRaw();
		if (button != BTN_NONE) {
			break;
		}

	}
	//usbHidDisconnect();
	return button;
}
Ejemplo n.º 20
0
Archivo: util.c Proyecto: Bediko/r0ket
void blink_led0(void){
    gpioSetValue (RB_LED0, 1-gpioGetValue(RB_LED0));
};
Ejemplo n.º 21
0
inline uint32_t readLineState() {
    return gpioGetValue(portNum, bitPos );
}
Ejemplo n.º 22
0
static void
prt(void)
{
	int i, j;

	printf("\r\nHello World\r\n");

	gpioSetDir(1, 1, gpioDirection_Input);
	for (i = 0; i < 8; i++)
		gpioSetDir(2, i, gpioDirection_Input);
	gpioSetDir(0, 8, gpioDirection_Output);
	gpioSetDir(0, 9, gpioDirection_Output);
	gpioSetDir(0, 10, gpioDirection_Output);

	IOCON_JTAG_TCK_PIO0_10 = 0
	    | IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO
	    | IOCON_JTAG_TDI_PIO0_11_ADMODE_DIGITAL;

	IOCON_JTAG_TDI_PIO0_11 = 0
	    | IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO
	    | IOCON_JTAG_TDI_PIO0_11_ADMODE_DIGITAL;

	gpioSetDir(0, 11, gpioDirection_Output);
	gpioSetDir(3, 0, gpioDirection_Input);
	gpioSetDir(3, 1, gpioDirection_Output);
	gpioSetDir(3, 2, gpioDirection_Input);
	gpioSetDir(3, 3, gpioDirection_Input);

	gpioSetInterrupt(1,                  // Port
	    1,                               // Pin
	    gpioInterruptSense_Edge,         // Edge/Level Sensitive
	    gpioInterruptEdge_Single,        // Single/Double Edge
	    gpioInterruptEvent_ActiveLow);   // Rising/Falling
	gpioIntEnable(1, 1);

	gpioSetValue(0,11,1);
	gpioSetValue(0,10,0);
	gpioSetValue(0,9,0);

	while (1) {
		j = CDC_getchar();
		switch (j) {
		case 's':	gpioSetValue(0,8,0); sts(); break;
		case 'S':	gpioSetValue(0,8,1); sts(); break;
		case 'p':	gpioSetValue(0,9,0); sts(); break;
		case 'P':	gpioSetValue(0,9,1); sts(); break;
		case 'b':	gpioSetValue(0,10,0); sts(); break;
		case 'B':	gpioSetValue(0,10,1); sts(); break;
		case 'a':	gpioSetValue(0,11,0); sts(); break;
		case 'A':	gpioSetValue(0,11,1); sts(); break;
		case 'e':	gpioSetValue(3,1,0); sts(); break;
		case 'E':	gpioSetValue(3,1,1); sts(); break;
		case 'x':
			while (1) 
				CDC_putchar('x');
			break;
		case '?':
			sts();
			break;
		}

		if (gpioGetValue(0, 10)) {
			CDC_putchar(got_prn);
			for (j = 0; j < 2; j++)
				gpioSetValue(0,11,0);
			gpioSetValue(0,11,1);
			gpioSetValue(0,10,0);
		}
	}


}