예제 #1
0
void systemInit()
{
  cpuInit();
  systickInit((CFG_CPU_CCLK / 1000) * CFG_SYSTICK_DELAY_IN_MS);
  gpioInit();
  pmuInit();
  adcInit();    // Init adc pins to avoid wasting 60uA in deep sleep

  #ifdef CFG_PRINTF_UART
    // Initialise UART with the default baud rate (set in projectconfig.h)
    uartInit(CFG_UART_BAUDRATE);
  #endif

  // Switch to 3.3V if TPS780 (etc.) is being used
  #if defined CFG_VREG_ALT_PRESENT && CFG_VREG_ALT_PRESENT == 1
    gpioSetDir(CFG_VREG_ALT_PORT, CFG_VREG_ALT_PIN, gpioDirection_Output);
    gpioSetValue(CFG_VREG_ALT_PORT, CFG_VREG_ALT_PIN, 0);
    gpioSetPullup(&CFG_VREG_ALT_REG32, gpioPullupMode_Inactive);
  #endif

  // Set LED pin as output and turn LED off
  gpioSetDir(CFG_LED_PORT, CFG_LED_PIN, 1);
  gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);

  // Initialise the ST7565 128x64 pixel display
  #ifdef CFG_ST7565
    st7565Init();
    st7565ClearScreen();    // Clear the screen  
    st7565Backlight(1);     // Enable the backlight
  #endif

  // Initialise the SSD1306 OLED display
  #ifdef CFG_SSD1306
    ssd1306Init(SSD1306_SWITCHCAPVCC);
    ssd1306ClearScreen();   // Clear the screen  
  #endif

  // Initialise EEPROM
  #ifdef CFG_I2CEEPROM
    mcp24aaInit();
  #endif

  // Initialise Chibi
  #ifdef CFG_CHIBI
    // Write addresses to EEPROM for the first time if necessary
    // uint16_t addr_short = 0x1166;
    // uint64_t addr_ieee =  addr_short;
    // mcp24aaWriteBuffer(CFG_CHIBI_EEPROM_SHORTADDR, (uint8_t *)&addr_short, 2);
    // mcp24aaWriteBuffer(CFG_CHIBI_EEPROM_IEEEADDR, (uint8_t *)&addr_ieee, 8);
    chb_init();
  #endif

  // Setup SD Card
  #ifdef CFG_SDCARD
    // Turn off SD card by default (saves power)
    gpioSetDir(CFG_SDCARD_ENPORT, CFG_SDCARD_ENPIN, gpioDirection_Output); /* Set enable pin to output */
    gpioSetValue(CFG_SDCARD_ENPORT, CFG_SDCARD_ENPIN, 0);                  /* Disable card by setting ENPIN low */
    gpioSetPullup(&CFG_SDCARD_ENREG32, gpioPullupMode_Inactive);
  #endif

  #ifdef CFG_LM75B
    // Initialise LM75B
    lm75bInit();
    // Read temp once to make sure we are in sleep mode
    int32_t temp;
    lm75bGetTemperature(&temp);
  #endif

  #ifdef CFG_BAT
    // Turn off battery voltage divider by default
    gpioSetDir(CFG_BAT_ENPORT, CFG_BAT_ENPIN, gpioDirection_Output );   // Set voltage divider enable pin to output
    gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 0 );                    // Disable the voltage divider by default
    gpioSetPullup(&CFG_BAT_ENREG32, gpioPullupMode_Inactive);
  #endif

  // Start the command line interface (if requested)
  #ifdef CFG_INTERFACE
    printf("%sType '?' for a list of available commands%s", CFG_PRINTF_NEWLINE, CFG_PRINTF_NEWLINE);
    cmdInit();
  #endif
}
예제 #2
0
파일: kk2.cpp 프로젝트: kenpx4/KK2
int main()
{
	int i, last_led_update = 0;

	initWiring();

	st7565Init(Font5x7);
	st7565ClearScreen();
	st7565SetBrightness(12);

	st7565DrawString(1, 5, "Test");

	for(i = 0; i < 100; i++)
	{
		st7565DrawPixel(1+i,14);
	}

	st7565Refresh();

#if KKVER == 21
	Fastwire::setup(100, true);
	MPU6050 mpu;
	mpu.initialize();
#endif

	DDRB &= _BV(LED_PIN); // Set pin 3 of port B to output (LED pin)

	for(;;)
	{
		char buff[512];
		if(millis() - last_led_update > 1000)
		{
			PORTB ^= _BV(LED_PIN);
			last_led_update = millis();
		}

		st7565ClearScreen();

#if KKVER == 21
		if(mpu.testConnection())
		{
			st7565DrawString(1,20, "Connected");
		}
		else
		{
			st7565DrawString(1,20, "Not connected");
		}

		sprintf(buff, "acc_x = %d\n", mpu.getAccelerationX());

		st7565DrawString(1,30, buff);
#else
		st7565DrawString(1,20, "No ACC available");
#endif
		st7565Refresh();

		delay(50);
	}

	return 0;
}