示例#1
0
文件: main.c 项目: Tjalling7/asf
/**
 * \brief Shows on display an explanation of how to use the demonstration
 * SW1 pressed skips this explanation.
 */
static void main_introduction(void)
{
    LED_On(LED3_GPIO);  /* Keep power LED on */

    /* Display Atmel logo */
    if (!main_introduction_is_exist()) {
        gfx_mono_generic_put_bitmap(&bitmap_atmel, 10, 0);
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_EXIT,
                             0, 25, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_ATMEL_DELAY);
    /* Display message */
    if (!main_introduction_is_exist()) {
        gfx_mono_init();
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_A,
                             0, 10 * 0, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_B,
                             0, 10 * 1, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_C,
                             0, 10 * 2, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_HELP_DELAY);
    /* Display help */
    if (!main_introduction_is_exist()) {
        gfx_mono_init();
        gfx_mono_draw_string(DISPLAY_INTRO_HELP_A,
                             0, 10 * 0, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_HELP_B,
                             0, 10 * 1, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_HELP_C,
                             0, 10 * 2, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_HELP_DELAY);
    /* Display help */
    if (!main_introduction_is_exist()) {
        gfx_mono_init();
        gfx_mono_draw_string(DISPLAY_INTRO_INF_A,
                             0, 10 * 0, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_INF_B,
                             0, 10 * 1, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_INF_C,
                             0, 10 * 2, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_HELP_DELAY);

    /* Clean display */
    gfx_mono_init();
}
示例#2
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	board_init();
	sysclk_init();
	gfx_mono_init();

	/**
	 * After initialization the example will write the "Hello
	 * world!\\r\\nI'm board..." string to position 0, 0 on the display.
	 * Use the system font sysfont. Afterwards the system busy waits
	 * forever in a while true loop.
	 */
#if BOARD == XMEGA_A3BU_XPLAINED
	gfx_mono_draw_string("My name is\r\nXMEGA-A3BU Xplained!\r\nAnd I'm board...",
			0, 0, &sysfont);
#elif BOARD == XMEGA_C3_XPLAINED
	gfx_mono_draw_string("My name is\r\nXMEGA-C3 Xplained!\r\nAnd I'm board...",
			0, 0, &sysfont);
#else
#  error Unknow board.
#endif

	while (true) {
		/* Intentionally left empty. */
	}
}
示例#3
0
文件: bike.c 项目: skrutt/longboard
void init_platform() {
	button_init(&select_btn, PIN_PA14);
	button_init(&down_btn, PIN_PA15);
	device.speed = 255;
	device.inclination = 255;
	
	gfx_mono_init();
	ssd1306_init();
	configure_tc_cadence();
	cadence_sensor_init();
	
	
	// The page address to write to
	uint8_t page_address = 0;
	// The column address, or the X pixel.
	uint8_t column_address = 0;
	
	ssd1306_clear_buffer();
	gfx_mono_draw_string("Accelerometer",1, 18, &sysfont);
	gfx_mono_draw_string("Setup",37, 32, &sysfont);
	ssd1306_write_display();
	
	gfx_mono_active_menu = SPEED_VIEW;
	
}
示例#4
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	system_init();
	gfx_mono_init();

	uint8_t start_line_address = 0;
	uint8_t scroll = 0;
	uint32_t line = 0;

	/**
	 * After initialization the example will write the Star Wars opening scrolling text.
	 * Use the system font sysfont. Afterwards the text will be scrolled forever.
	 */

	while (true) {
		if (++start_line_address%8 == 0) {
			scroll = 1;
			gfx_mono_draw_string(string[line%LINES],0, ((line)%8)*8, &sysfont);
			line++;
		} else if (start_line_address % 7 != 0) {
			delay_ms(100);
		}

		if ( scroll != 0 ) {
			ssd1306_set_display_start_line_address(start_line_address-8);
		} else {
			gfx_mono_draw_string(string[line%LINES],0, ((line)%8)*8, &sysfont);
			line++;
		}
	}
}
int main (void)
{
	board_init();	//Board definition and selection
	sysclk_init();	//System clock init
	
	usart_init_rs232(USART_SERIAL_RFID, &usart_options_RFID);	//UART init
	usart_init_rs232(USART_SERIAL_Monitor, &usart_options_Monitor);
	
	gfx_mono_init();	//LCD init
	PORTE.OUTSET=PIN4_bm;	//LCD Back light on
	
	//RTC Init
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm);
	if (rtc_vbat_system_check(false) != VBAT_STATUS_OK)
		rtc_init();
	PORTE.DIRCLR=PIN5_bm;
	
	while(1)
	{
		if(Receive())
		{
			card_no=Check();
			if(card_no)
			{
				PORTR.OUTCLR=PIN0_bm;
				gfx_mono_draw_string("Card Detected",0,0,&sysfont);
				gfx_mono_draw_string("Welcome",0,10,&sysfont);
				gfx_mono_draw_string(names[card_no-1],55,10,&sysfont);
				rtc_timestamp=rtc_get_time();
				calendar_timestamp_to_date_tz(rtc_timestamp,5,30,&get_date);
				gfx_mono_draw_string(display_time(get_date,arr),0,20,&sysfont);
				delay_s(1);
				gfx_mono_init();
				PORTR.OUTSET=PIN0_bm;
			}
			else
			{
				PORTR.OUTCLR=PIN1_bm;
				gfx_mono_draw_string("Invalid Card",0,0,&sysfont);
				delay_s(1);
				gfx_mono_init();
				PORTR.OUTSET=PIN1_bm;
			}
		}
	}
}
示例#6
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/* Variable to store the last winner */
	uint8_t winner;

	system_init();
	delay_init();
	gfx_mono_init();

	init_buttons();
	init_display();

	/* Start game */
	while (true) {
		winner = 0;
		/* Wait for button interaction */
		while (get_button() == BUTTON_NONE) {
		}
		/* Draw empty board */
		setup_board();

		/* Start playing */
		for (int i = 0; i < 5; i++) {
			/* User's turn */
			user_turn();

			/* Check if the game is over */
			winner = we_have_a_winner();
			if (winner || i == 4) {
				break;
			}

			/* Add a delay for the opponent to "think" */
			delay_ms(500);
			/* Opponent's turn */
			opponent_turn();

			/* Check if the game is over */
			winner = we_have_a_winner();
			if (winner) {
				break;
			}
		}

		/* Game over, print winner and get ready for restart */
		if (winner == 1) {
			/* User won */
			gfx_mono_draw_string("You won!", STRING_X, 0, &sysfont);
			wins++;
		} else if (winner == 2) {
			gfx_mono_draw_string("You lost!", STRING_X, 0, &sysfont);
		} else {
			gfx_mono_draw_string("No winner!", STRING_X, 0, &sysfont);
		}

		gfx_mono_draw_string("Press a button", STRING_X, SQUARE3_Y, &sysfont);
		games++;
	}
}
示例#7
0
int main(void)
{
	struct adc_config         adc_conf;
	struct adc_channel_config adcch_conf;

	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();
	gfx_mono_init();

	// Enable back light of display
	ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

	// Initialize configuration structures.
	adc_read_configuration(&ADCA, &adc_conf);
	adcch_read_configuration(&ADCA, ADC_CH0, &adcch_conf);

	/* Configure the ADC module:
	 * - unsigned, 12-bit results
	 * - VCC voltage reference
	 * - 200 kHz maximum clock rate
	 * - manual conversion triggering
	 * - temperature sensor enabled
	 * - callback function
	 */
	adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_12,
			ADC_REF_VCC);
	adc_set_clock_rate(&adc_conf, 200000UL);
	adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);
	adc_enable_internal_input(&adc_conf, ADC_INT_TEMPSENSE);

	adc_write_configuration(&ADCA, &adc_conf);
	adc_set_callback(&ADCA, &adc_handler);

	/* Configure ADC channel 0:
	 * - single-ended measurement from temperature sensor
	 * - interrupt flag set on completed conversion
	 * - interrupts disabled
	 */
	adcch_set_input(&adcch_conf, ADCCH_POS_PIN1, ADCCH_NEG_NONE,
			1);
	adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);
	adcch_enable_interrupt(&adcch_conf);

	adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf);

	// Enable the ADC and start the first conversion.
	adc_enable(&ADCA);
	adc_start_conversion(&ADCA, ADC_CH0);

	do {
		// Sleep until ADC interrupt triggers.
		sleepmgr_enter_sleep();
	} while (1);
}
示例#8
0
int main(void)
{
	board_init();

	// Initialize graphics library
	gfx_mono_init();

	// Enable backlight
	ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

	gfx_mono_draw_string("Tests successful: \r\n1   2   3   4   5",
			0, 0, &sysfont);

	if (test_erase() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				0, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				0, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_write() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				4 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				4 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_atomic_write() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				8 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				8 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_split_write() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				12 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				12 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_erase_bytes() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				16 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				16 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	while (true) {}

}
示例#9
0
/**
 * \brief Main application routine
 *  - Initializes the board and LCD display
 *  - Initialize ADC ,to read ADC offset and configure for oversampling
 *  - If number of sample Reached to  total number of oversample required,
 *    call function to start process on oversampled ADC readings
 */
int main( void )
{
	/*
	 * Initialize basic features for the AVR XMEGA family.
	 *  - PMIC is needed to enable all interrupt levels.
	 *  - Board init for setting up GPIO and board specific features.
	 *  - Sysclk init for configuring clock speed and turning off unused
	 *    peripherals.
	 *  - Sleepmgr init for setting up the basics for the sleep manager,
	 */

	board_init();
	sysclk_init();
	pmic_init();
	sleepmgr_init();

	/* Initialize ST7565R controller and LCD display */
	gfx_mono_init();

	/* Display headings on LCD for oversampled result */
	gfx_mono_draw_string("Oversampled", 0, 0, &sysfont);

	/* Display headings on LCD for normal result */
	gfx_mono_draw_string("Normal", 80, 0, &sysfont);

	/* Initialize ADC ,to read ADC offset and configure ADC for oversampling
	**/
	init_adc();

	/* Enable global interrupt */
	cpu_irq_enable();

	/* Switch ON LCD back light */
	ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT);

	/* Set LCD contrast */
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	/* Continuous Execution Loop */
	while (1) {
		/*
		 * Check if number of sample reached to  total Number of
		 * oversample required by checking status of
		 * adc_oversampled_flag
		 */
		if (adc_oversampled_flag == true) {
			/* Reset the adc_oversampled_flag */
			adc_oversampled_flag = false;

			/* Process all received ADC samples and calculate analog
			 * input */
			adc_oversampled();
		}
	}
}
示例#10
0
int main (void)
{
	uint8_t menu_status;
	struct keyboard_event input;

	static usart_rs232_options_t SERIAL_OPTIONS = {
		.baudrate = 57600,
		.charlength = USART_CHSIZE_8BIT_gc,
		.paritytype = USART_PMODE_DISABLED_gc,
		.stopbits = false
	};

	sysclk_init();	
	board_init();
	solenoid_init();
	gfx_mono_init();
	usart_init_rs232(USART_SERIAL, &SERIAL_OPTIONS);

	gpio_toggle_pin(NHD_C12832A1Z_BACKLIGHT);

	while(true) 
	{
		gfx_mono_menu_init(&main_menu);

		do {
			do {
				keyboard_get_key_state(&input);
			} while (input.type != KEYBOARD_RELEASE);

			menu_status = gfx_mono_menu_process_key(&main_menu, input.keycode);
		} while (menu_status == GFX_MONO_MENU_EVENT_IDLE);

		//Determine what song to play based on 
		//the input from the user controlling the A3BU
		switch(menu_status) {
			case 0:
				song_menu(0);
				play_song_with_input(SAMPLE_SONG, SAMPLE_SONG_LENGTH);
				break;
			case 1:
				song_menu(1);
				play_song_with_input(STAIRWAY, 6);
				break;
			case 2:
				song_menu(2);
				play_song_with_input(MISERLOU, 1);
				break;
			case 3:
				song_menu(3);
				play_serial();
				break;
		}
	}
}
示例#11
0
/**
 * \brief Run spinner widget unit tests
 */
int main (void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	gfx_mono_init();

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);


	// Define all the test cases
	DEFINE_TEST_CASE(single_spinner_spincollection_test, NULL,
			run_single_spinner_spincollection_test, NULL,
			"Single spinners in spincollection test");
	DEFINE_TEST_CASE(two_spinners_spincollection_test, NULL,
			run_two_spinners_spincollection_test, NULL,
			"Two spinners in spincollection test");
	DEFINE_TEST_CASE(three_spinners_spincollection_test, NULL,
			run_three_spinners_spincollection_test, NULL,
			"Three spinners in spincollection test");
	DEFINE_TEST_CASE(cancel_spinner_spincollection_test, NULL,
			run_cancel_spinner_spincollection_test, NULL,
			"Cancel spinner choice test");
	DEFINE_TEST_CASE(event_back_spincollection_test, NULL,
			run_event_back_spincollection_test, NULL,
			"Event back spincollection test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(spinctrl_tests) = {
		&single_spinner_spincollection_test,
		&two_spinners_spincollection_test,
		&three_spinners_spincollection_test,
		&event_back_spincollection_test,
		&cancel_spinner_spincollection_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(spinctrl_suite, spinctrl_tests,
			"Spinner widget with test suite");

	// Set up the test data pointer and run all tests in the suite
	test_suite_run(&spinctrl_suite);

	while (1) {
		/* Intentionally left empty. */
	}
}
示例#12
0
文件: example1.c 项目: kerichsen/asf
int main(void){

	struct gfx_mono_bitmap smiley;
	struct gfx_mono_bitmap smiley_flash;

	board_init();
	sysclk_init();

	/* Initialize GFX lib. Will configure the display controller and
	 * create a framebuffer in RAM if the controller lack two-way communication
	 */
	gfx_mono_init();

	// Setup bitmap struct for bitmap stored in RAM
	smiley.type = GFX_MONO_BITMAP_RAM;
	smiley.width = 8;
	smiley.height = 16;
	smiley.data.pixmap = smiley_data;

	// Setup bitmap for bitmap stored in FLASH
	smiley_flash.type = GFX_MONO_BITMAP_PROGMEM;
	smiley_flash.width = 8;
	smiley_flash.height = 16;
	smiley_flash.data.progmem = flash_bitmap;

	// Output bitmaps to display
	gfx_mono_put_bitmap(&smiley, 50, 0);
	gfx_mono_put_bitmap(&smiley_flash, 0, 0);

	//Draw  horizontal an vertical lines with length 128 and 32 pixels
	gfx_mono_draw_vertical_line(1, 0, 32, GFX_PIXEL_SET);
	gfx_mono_draw_horizontal_line(0, 2, 128, GFX_PIXEL_SET);

	// Draw a line from the top-left corner to the bottom right corner
	gfx_mono_draw_line(0, 0, 127, 31, GFX_PIXEL_SET);

	// Draw a rectangle with upper left corner at x=20,y=10 - width=height=10px
	gfx_mono_draw_rect(20, 10, 10, 10,GFX_PIXEL_SET);

	// Draw a 10x10 filled rectangle at x=10,y=10
	gfx_mono_draw_filled_rect(10, 10, 10, 10, GFX_PIXEL_SET);

	// Draw a whole circle at x=50,y=16 with radios=8 and all octants drawn
	gfx_mono_draw_circle(50, 16, 8, GFX_PIXEL_SET,GFX_WHOLE);

	// Draw a filled circle with all quadrant drawn
	gfx_mono_draw_filled_circle(80, 16, 10, GFX_PIXEL_SET, GFX_WHOLE);

	while(true) {
	// This while left intentionally blank to halt execution.
	}
}
示例#13
0
文件: main.c 项目: InSoonPark/asf
int main (void)
{
	system_init();
	gfx_mono_init();

	// Initialize the demo..
	demo_co_routines_init();

	// ..and let FreeRTOS run tasks!
	vTaskStartScheduler();

	do {
		// Intentionally left empty
	} while (true);
}
示例#14
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	struct gfx_mono_spinctrl spinner1;
	struct gfx_mono_spinctrl spinner2;
	struct gfx_mono_spinctrl spinner3;
	struct gfx_mono_spinctrl_spincollection spinners;

	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	system_init();
	gfx_mono_init();

	int16_t tmp[3];

	// Initialize spinners
	gfx_mono_spinctrl_init(&spinner1, SPINTYPE_STRING, spinnertitle,
			spinner_choicestrings, 0, 3, 0);
	gfx_mono_spinctrl_init(&spinner2, SPINTYPE_INTEGER,
			spinnertitle2, NULL, -60, -41, 0);
	gfx_mono_spinctrl_init(&spinner3, SPINTYPE_INTEGER,
			spinnertitle3, NULL, 19999, 20200, 0);

	// Initialize spincollection
	gfx_mono_spinctrl_spincollection_init(&spinners);

	// Add spinners to spincollection
	gfx_mono_spinctrl_spincollection_add_spinner(&spinner1, &spinners);
	gfx_mono_spinctrl_spincollection_add_spinner(&spinner2, &spinners);
	gfx_mono_spinctrl_spincollection_add_spinner(&spinner3, &spinners);

	// Show spincollection on screen
	gfx_mono_spinctrl_spincollection_show(&spinners);

	// Spincollection is now ready to process input from user

	while(1) {
		gfx_mono_spinctrl_spincollection_process_key(&spinners, GFX_MONO_SPINCTRL_KEYCODE_DOWN, tmp);
		delay_s(1);
		gfx_mono_spinctrl_spincollection_process_key(&spinners, GFX_MONO_SPINCTRL_KEYCODE_ENTER, tmp);
		delay_s(1);
	}
}
示例#15
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	struct gfx_mono_spinctrl spinner1;
	struct gfx_mono_spinctrl spinner2;
	struct gfx_mono_spinctrl spinner3;
	struct gfx_mono_spinctrl_spincollection spinners;
	int16_t results[GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION];

	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	board_init();
	sysclk_init();
	gfx_mono_init();

	// Initialize spinners
	gfx_mono_spinctrl_init(&spinner1, SPINTYPE_STRING, spinnertitle,
			spinner_choicestrings, 0, 3, 0);
	gfx_mono_spinctrl_init(&spinner2, SPINTYPE_INTEGER,
			spinnertitle2, NULL, -60, -41, 0);
	gfx_mono_spinctrl_init(&spinner3, SPINTYPE_INTEGER,
			spinnertitle3, NULL, 19999, 20200, 0);

	// Initialize spincollection
	gfx_mono_spinctrl_spincollection_init(&spinners);

	// Add spinners to spincollection
	gfx_mono_spinctrl_spincollection_add_spinner(&spinner1, &spinners);
	gfx_mono_spinctrl_spincollection_add_spinner(&spinner2, &spinners);
	gfx_mono_spinctrl_spincollection_add_spinner(&spinner3, &spinners);

	// Show spincollection on screen
	gfx_mono_spinctrl_spincollection_show(&spinners);

	// Spincollection is now ready to process input from user

	while(1) {
		// Intentionally left empty.
	}
}
示例#16
0
文件: main.c 项目: Tjalling7/asf
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
    irq_initialize_vectors();
    cpu_irq_enable();

    /* Initialize ASF services */
    sleepmgr_init();
    sysclk_init();
    board_init();
    gfx_mono_init();
    sd_mmc_init();
    rtc_init();
    stdio_usb_init(); /* Initialize STDIO and start USB */
    udc_stop(); /* Stop USB by default */

    main_introduction();

    /* Initialize tasks */
    app_touch_init();
    app_cpu_load_init();
    app_sampling_init();

    /* The main loop */
    while (true) {
        /* Enter in sleep mode */
        app_cpu_load_enter_sleep();
        sleepmgr_enter_sleep();

        /* Execute tasks */
        app_usb_task();
        app_microsd_task();
        app_sampling_task();
        app_touch_task();
        app_cpu_load_task();
    }
}
示例#17
0
/**
 * \brief Example 2 main application routine
 */
int main(void)
{
	uint8_t flashbuf[8];
	uint32_t checksum1;
	uint32_t checksum2;

	board_init();
	sysclk_init();
	gfx_mono_init();

	// Calculate checksum for an address range in flash.
	checksum1 = crc_flash_checksum(CRC_FLASH_RANGE, FLASHADDR, 4);

	// Read out the buffer from flash
	nvm_flash_read_buffer(FLASHADDR, flashbuf, 4);

	// Calculate checksum for the buffer from flash
	checksum2 = crc_io_checksum(flashbuf, 4, CRC_32BIT);

	// Make sure the calculated checksums are equal and write to screen
	if (checksum1 == checksum2) {
		gfx_mono_draw_string("Address range CRC OK",
				0, 0, &sysfont);
	}

	// Append the flash checksum and recalculate
	crc32_append_value(checksum1, flashbuf+4);
	checksum1 = crc_io_checksum(flashbuf, 8, CRC_32BIT);

	// Make sure the checksum is zero and write to screen
	if (checksum1 == 0) {
		gfx_mono_draw_string("IO CRC zero       OK", 0,
				SYSFONT_HEIGHT + 1, &sysfont);
	}

	// Calculate checksum for the boot section
	checksum1 = crc_flash_checksum(CRC_BOOT, 0, 0);

	// Recalculate checksum for the boot section using flash range CRC
	checksum2 = crc_flash_checksum(CRC_FLASH_RANGE, BOOT_SECTION_START,
			BOOT_SECTION_END-BOOT_SECTION_START+1);

	// Make sure the checksums are equal and write to screen
	if (checksum1 == checksum2) {
		gfx_mono_draw_string("Boot section CRC  OK",
				0, (SYSFONT_HEIGHT + 1)*2, &sysfont);
	}

	// Calculate checksum for the application section
	checksum1 = crc_flash_checksum(CRC_APP, 0, 0);

	// Recalculate checksum for the application section using flash range CRC
	checksum2 = crc_flash_checksum(CRC_FLASH_RANGE, APP_SECTION_START,
			APP_SECTION_END-APP_SECTION_START+1);
	// Make sure the checksums are equal and write to screen
	if (checksum1 == checksum2) {
		gfx_mono_draw_string("App section CRC   OK",
				0, (SYSFONT_HEIGHT + 1)*3, &sysfont);
	}

	// End of application, loop forever
	while (true) {
		// Intentionally left empty
	}

}
示例#18
0
int main (void)
{
	sysclk_init();
	board_init();
	pmic_init();
	gfx_mono_init();
	adc_sensors_init();
	// Enable display backlight
	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	cpu_irq_enable();
	
	while(true){
		
		if(state==1){
			start_game();
			}else if(state==2){
			tc_enable(&TCC0);
			tc_set_overflow_interrupt_callback(&TCC0, sun_count);
			tc_set_wgm(&TCC0, TC_WG_NORMAL);
			tc_write_period(&TCC0, 13500);
			tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO);
			tc_write_clock_source(&TCC0, TC_CLKSEL_DIV256_gc);
			
			tc_enable(&TCC1);
			tc_set_overflow_interrupt_callback(&TCC1, button_press);
			tc_set_wgm(&TCC1, TC_WG_NORMAL);
			tc_write_period(&TCC1, 62500);
			tc_set_overflow_interrupt_level(&TCC1, TC_INT_LVL_LO);
			tc_write_clock_source(&TCC1, TC_CLKSEL_DIV8_gc);
			
			gfx_mono_draw_string("SUN:   0", 0, 0, &sysfont);
			gfx_mono_draw_string(">", 0, cursor_position, &sysfont);
			gfx_mono_draw_string("Score:  0", 63, 0, &sysfont);
			
			randomPeta();
			
			char* score_string = NULL;
			uint16_t old_score = 0;
			
			for(j = 0; j <= 70; j++){
				
				if(sun_value > 10){
					
					lightsensor_measure();
					while (!lightsensor_data_is_ready()) {
						// Wait until the conversion is complete
					}
					if(lightsensor_get_raw_value() > 250){
						sun_value -= 10;
						sunBurst();
						gfx_mono_draw_filled_rect(12,8,114,24,GFX_PIXEL_CLR);
					}
				}
				

				if(score > old_score){
					sprintf(score_string, "%3d", score);
					gfx_mono_draw_string(score_string, 100, 0, &sysfont);
					old_score = score;
				}
				
				if(lose){
					state=3;
					break;
					}else if(zombie==0){
					state=4;
					break;
				}
				
				
				tampilkanPeta();
				tampilkanTembak();
				delay_ms(1000);
			}
			}else if(state==3){
			cpu_irq_disable();
			gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR);
			while(true){
				gfx_mono_draw_string("GAME OVER",36,8,&sysfont)	;
				gfx_mono_draw_string("You Lose",39,20,&sysfont)	;
			}
			}else if(state==4){
			cpu_irq_disable();
			gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR);
			while(true){
				gfx_mono_draw_string("GAME OVER",36,2,&sysfont)	;
				gfx_mono_draw_string("You Win",42,12,&sysfont)	;
				gfx_mono_draw_string("Score = ",30,22,&sysfont)	;
				char* score_string = NULL;
				sprintf(score_string, "%3d", score);
				gfx_mono_draw_string(score_string, 79, 22, &sysfont);
			}
		}
	}
	
}
示例#19
0
文件: main.c 项目: Realtime-7/asf
/**
 * \brief Main function.
 *
 * Initializes the board, displays splash screens, then launches application.
 *
 * If the application exits (fails), the error is written to display and an
 * infinite loop with watchdog resets is entered.
 */
int main(void)
{
    /* Holds state of the QTouch button */
    enum pot_t potstate      = POT_OFF;
    /* Last state of the QTouch button for change detection */
    enum pot_t last_potstate = POT_OFF;
    /* Holds user-selected power-setting */
    uint8_t wattage      = 0;
    /* Last power-setting for change detection */
    uint8_t last_wattage = 0;
    /* Whether the plate element is/should be actuated */
    bool power      = false;
    /* Last power setting for change detection */
    bool last_power = false;
    /* Last time a simulation step was executed */
    uint32_t last_sim_step;
    /* Last time a control step was executed */
    uint32_t last_ctl_step;

    /* The WDT was just reset by the WDT functional test*/
    classb_last_wdt_reset = rtc_get_time();

    last_sim_step = classb_last_wdt_reset;
    last_ctl_step = classb_last_wdt_reset;

    sysclk_init();
    board_init();
    pmic_init();
    gfx_mono_init();
    touch_init();
    main_init_rtc32();

    cpu_irq_enable();

    /* Enable display backlight */
    ioport_set_pin_level(LCD_BACKLIGHT_ENABLE_PIN,
                         LCD_BACKLIGHT_ENABLE_LEVEL);

    /* If an error was detected, skip directly to displaying it */
    if (classb_error) {
        goto display_error;
    }


    /* Check if required jumpers are mounted, show explanation if not */
    if (!main_check_jumpers()) {
        show_explain_splash();
    }

    /* Display a splash screen showing button functions */
    show_button_splash();

    /* Initialize the ADC, DAC and Timer/Counter modules that are used to
     * emulate real world objects.
     */
    main_init_adc_dac();
    main_init_tc();

    /* Initialize subsystems used for Class B testing */
    oven_classb_init_tests();

    /* Reset the simulation states */
    oven_plant_init();

    /* Clear screen */
    gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);

    /* Draw the initial axis system */
    oven_ui_draw_axis();

    /* Draw the user interface */
    oven_ui_update_graphics(potstate, wattage, power);

    /* Run simulation as long as no error is detected in class B tests */
    while (!classb_error) {
        uint32_t current_time;

        oven_wdt_periodic_reset();
        current_time = rtc_get_time();

        /* Add power on SW1 press, wrap at 20 */
        if (oven_ui_power_button_is_pressed()) {
            wattage = (wattage + 5) % 20;
        }

        /* Check QTouch sensor and map this to `potstate`. This is
         * needed both for simulation and for the control routine.
         */
        potstate = (!touch_key_is_pressed()) ? POT_ON : POT_OFF;

        /* Execute control routine periodically */
        if (current_time > (last_ctl_step + OVEN_CTL_STEP_TIME)) {
            ovenctl_execute_control_step(current_time, &wattage,
                                         &power, potstate);
            last_ctl_step = current_time;
        }

        /* Execute simulation step periodically */
        if (current_time > (last_sim_step + OVEN_SIM_STEP_TIME)) {
            main_execute_simulation_step(current_time, potstate);
            last_sim_step = current_time;
        }

        /* Update graphics on wattage, power or pot on/off change */
        if ((potstate != last_potstate) || (power != last_power)
                || (wattage != last_wattage)) {
            oven_ui_update_graphics(potstate, wattage, power);
        }

        /* Update variable states for change detection on next loop
         * iteration.
         */
        last_power    = power;
        last_wattage  = wattage;
        last_potstate = potstate;

        /* If back/menu button is pressed, pause simulation and test
         * timers, and show menu.
         */
        if (oven_ui_back_button_is_pressed()) {
            /* Disable interrupt monitoring, if enabled */
            classb_intmon_set_state(TEMP_SANITY_TEST, M_DISABLE);
            classb_intmon_set_state(PER_CLASSB_TESTS, M_DISABLE);

            OVEN_PERIODIC_TEMPTEST_TC.CTRLA &= ~TC1_CLKSEL_gm;
            OVEN_PERIODIC_CLASSB_TC.CTRLA &= ~TC0_CLKSEL_gm;

            /* Show the error insertion menu */
            oven_classb_error_insertion();

            /* Re-enable timers upon return */
            OVEN_PERIODIC_CLASSB_TC.CTRLA |= TC_CLKSEL_DIV1024_gc;
            /* If user did not induce an error in the temperature
             * test timing, re-enable it correctly.
             */
            if ((OVEN_PERIODIC_TEMPTEST_TC.CTRLA & TC1_CLKSEL_gm)
                    == TC_CLKSEL_OFF_gc) {
                OVEN_PERIODIC_TEMPTEST_TC.CTRLA
                |= TC_CLKSEL_DIV1024_gc;
            }

            /* Re-enable interrupt monitoring if the oven is
             * supposed to be on, i.e., they were enabled before.
             */
            if (wattage > 0) {
                classb_intmon_set_state(TEMP_SANITY_TEST,
                                        M_ENABLE);
                classb_intmon_set_state(PER_CLASSB_TESTS,
                                        M_ENABLE);
            }

            /* Reset UI */
            gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);
            oven_ui_draw_axis();
            oven_ui_update_graphics(potstate, wattage, power);
        }
    }

display_error:
    /* Show red status LED and write the error on display */
    oven_ui_set_status_leds(S_RED);
    oven_classb_display_error();

    /* Enter infinite loop of watchdog resets so user can read display */
    while (true) {
        oven_wdt_periodic_reset();
    }
}
int main(void)
{
	static uint8_t ret = 0;
	uint8_t i = 0;
	uint8_t ibuf[16] = {0};
	static uint8_t test_pattern[PATTERN_TEST_LENGTH];
	sensor_data_t sensor_data;
	twi_master_options_t opt;

	irq_initialize_vectors();

	sysclk_init();

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	gfx_mono_init();
	ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	gfx_mono_draw_string("Reading....\r\n", 0, 0, &sysfont);
	gfx_mono_generic_draw_filled_rect(0, 8, 128, 8, GFX_PIXEL_CLR);

	/* configure the pins connected to LEDs as output and set their default
	 * initial state to low (LEDs off).
	 */
	ioport_configure_pin(LED_LOW, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(LED_HIGH, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(LED_CRIT, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(LED_NORM, IOPORT_DIR_OUTPUT);

	ioport_set_pin_low(LED_LOW);
	ioport_set_pin_low(LED_HIGH);
	ioport_set_pin_low(LED_CRIT);
	ioport_set_pin_low(LED_NORM);

	/* Configure the ALERT/EVENT pin which is
	 * routed to pin 2 of J2 on A3BU Xplained
	 * This pin can be used for polling or interrupt
	 */
	ioport_configure_pin(EVENT_PIN, IOPORT_DIR_INPUT);

	attach_device(EXAMPLE_TS_DEVICE_ADDR, EXAMPLE_TS_DEVICE);
	opt.chip = EXAMPLE_TS_DEVICE_ADDR;
	opt.speed = TWI_SPEED;

	/* Initialize TWI driver with options */
	twi_master_setup(TWI_MODULE, &opt);

	sensor_data.config_reg.value = 0;
	/* Set configuration register to 12-bis resolution */
	sensor_data.config_reg.option.RES  = AT30TS7_RES12;

	if (write_config(sensor_data.config_reg.value) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Set the polarity of ALERT/EVENT pin to low */

	if (set_config_option(&sensor_data, AT30TS_POL, AT30TS7_POL_ACTIVE_LOW) !=
	TWI_SUCCESS) {
	test_fail_indication();
	}

	/* Read the configuration register */
	if (read_config(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

#if defined _AT30TS00_ || defined _AT30TSE002B_
	/* Set t_high limit register to +75.0000C */
	if (write_tcrit(pos, 75, 0000) != TWI_SUCCESS) {
		test_fail_indication();
	}
#endif

	/* Set t_high limit register to +50.7500C */
	if (write_temperature_high(pos, 50, 7500) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Set t_low limit register to -25.2500C */

	/*
	 * if (write_temperature_low(neg, 25, 2500)!= TWI_SUCCESS) {
	 * test_fail_indication();
	 * }
	 */

	/* Set t_low limit register to +35.5000C */
	if (write_temperature_low(pos, 35, 5000) != TWI_SUCCESS) {
		test_fail_indication();
	}

#if defined _AT30TS00_ || defined _AT30TSE002B_
	/* Read t_crit register register */
	if (read_tcrit(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}
#endif

	/* Read t_high limit register */
	if (read_temperature_high(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read t_low register register */
	if (read_temperature_low(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Non volatile register functionality */
#if defined _AT30TS750_  || defined _AT30TSE752_ || \
	defined _AT30TSE754_ || defined _AT30TSE758_

	/* Copy volatile registers to nonvolatile registers
	 * vol configuration register  -> nonvol configuration register
	 * vol t_high register -> nonvol t_high register
	 * vol t_low  register -> nonvol t_low register
	 */
        ret = ts75_copy_vol_nonvol_register();
	if (ret != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the nonvol configuration register */
	if (read_nvconfig(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the nonvol t_high register */
	if (read_nvthigh(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the nonvol t_low register */
	if (read_nvtlow(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Clear vol configuration register */
	if (write_config(0x0000) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the vol configuration register */
	if (read_config(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Copy nonvolatile registers to volatile registers */
	if (ts75_copy_nonvol_vol_register() != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the configuration register */
	if (read_config(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}
#endif
        /* To avoid 'variable unused' warning */
        test_pattern[0] = ibuf[0];
        ibuf[0] = test_pattern[0];

	/* EEPROM Test */
#if defined _AT30TSE002B_  || defined _AT30TSE752_ || \
	defined _AT30TSE754_   || defined _AT30TSE758_

	/* Generate Test Pattern */
	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		test_pattern[i] = 0x41 + i; // 'ABCD...'
	}

	/* Perform a write access & check write result */
	if ((ret = ts_write_memory(EE_TEST_ADDR, PATTERN_TEST_LENGTH,
	(void *)test_pattern)) != TWI_SUCCESS) {
		gfx_mono_draw_string("EE Write Failed ", 0, 24, &sysfont);
		test_fail_indication();
	}

	/* Allow time for EEPROM to settle */
	delay_ms(5);
	/* Clear test_pattern */
	memset(ibuf, 0, sizeof(ibuf));

	/* Perform a read access & check read result */
	if (ts_read_eeprom(EE_TEST_ADDR, PATTERN_TEST_LENGTH,
			ibuf) != TWI_SUCCESS) {
		gfx_mono_draw_string("EE Read Failed ", 0, 24, &sysfont);
		test_fail_indication();
	}

	/* Check received data against sent data */
	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		if (ibuf[i] != test_pattern[i]) {
			gfx_mono_draw_string("EE Read mismatch ", 0, 24,
				&sysfont);
			test_fail_indication();
		}
	}

	gfx_mono_draw_string("EE Write/Read OK", 0, 24, &sysfont);
	gfx_mono_draw_string((char const*)ibuf, 0, 16, &sysfont);
#endif
	/*
	 * Temperature reading contained in struct,i.e.
	 * temperature register value = 0x3240 (+50.25C), AT30TSE758 device
	 * sensor_data.temperature.itemp = 50 //!< integer part
	 * sensor_data.temperature.ftemp = 2500 //!< fractional part
	 * sensor_data.temperature.sign = 0 //!< sign (pos(+) = 0, neg(-) = 1)
	 * sensor_data.temperature.raw_value = 0x324 //!< raw data
	 */

	char senseData[50] = {0};
	while (1) {
		/* Read temperature */
		read_temperature(&sensor_data);
		sprintf(senseData, "%d.%04d DegC",
					sensor_data.temperature.itemp,
						sensor_data.temperature.ftemp);
		gfx_mono_draw_string(senseData, 0, 8, &sysfont);
		ioport_set_pin_low(LED_NORM);
		delay_ms(200);
		ioport_set_pin_high(LED_NORM);
		delay_ms(200);
	}
}
示例#21
0
/**
 * \brief Run gfx_mono unit tests
 */
int main (void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	gfx_mono_init();

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);


	// Define all the test cases
	DEFINE_TEST_CASE(clear_display_test, NULL, run_clear_display_test, NULL,
			"Clear display test");
	DEFINE_TEST_CASE(set_display_test, NULL, run_set_display_test, NULL,
			"Set display test");
	DEFINE_TEST_CASE(draw_rectangles_test, NULL, run_draw_rectangles_test,
			NULL, "Draw filled rectangles test");
	DEFINE_TEST_CASE(draw_filled_rectangle_test, NULL,
			run_draw_filled_rectangle_test, NULL,
			"Draw filled rectangle in one page test");
	DEFINE_TEST_CASE(draw_rectangle_two_pages_test, NULL,
			run_draw_rectangle_two_pages_test, NULL,
			"Draw filled rectangle in two pages test");
	DEFINE_TEST_CASE(draw_rectangle_outline_test, NULL,
			run_draw_rectangle_outline_test, NULL, 
			"Draw rectangle outline test");
	DEFINE_TEST_CASE(draw_filled_circle_test, NULL,
			run_draw_filled_circle_test, NULL, "Draw filled circle test");
	DEFINE_TEST_CASE(draw_circle_outline_test, NULL,
			run_draw_circle_outline_test, NULL, "Draw circle outline test");
	DEFINE_TEST_CASE(draw_vertical_line_test, NULL, 
			run_draw_vertical_line_test, NULL, "Draw vertical line test");
	DEFINE_TEST_CASE(draw_horizontal_line_test, NULL,
			run_draw_horizontal_line_test, NULL, "Draw horizontal line test");
	DEFINE_TEST_CASE(draw_diagonal_line_test, NULL,
			run_draw_diagonal_line_test, NULL,
			"Draw a line between two points test");
	DEFINE_TEST_CASE(draw_flash_bitmap_test, NULL, run_draw_flash_bitmap_test,
			NULL, "Draw bitmap stored in FLASH test");
	DEFINE_TEST_CASE(draw_ram_bitmap_test, NULL, run_draw_ram_bitmap_test,
			NULL, "Draw bitmap stored in RAM test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(gfx_mono_tests) = {
			&clear_display_test,
			&set_display_test,
			&draw_rectangles_test,
			&draw_filled_rectangle_test,
			&draw_rectangle_two_pages_test,
			&draw_rectangle_outline_test,
			&draw_filled_circle_test,
			&draw_circle_outline_test,
			&draw_horizontal_line_test,
			&draw_vertical_line_test,
			&draw_diagonal_line_test,
			&draw_flash_bitmap_test,
			&draw_ram_bitmap_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(gfx_mono_suite, gfx_mono_tests, "gfx_mono test suite");

	// Set up the test data pointer and run all tests in the suite
	test_suite_run(&gfx_mono_suite);

	while (1) {
		/* Intentionally left empty. */
	}
}
示例#22
0
/**
 * \brief Main function.
 *
 * Initializes the board and reads out the production date stored in EEPROM and
 * set timezone from EEPROM if it is set. If it is not set it will open the
 * timezone selector to select the local timezone. It then runs the menu system
 * in an infinite while loop.
 */
int main(void)
{
	uint8_t menu_status;
	struct keyboard_event input;
	uint32_t rtc_timestamp;

	sysclk_init();
	board_init();
	pmic_init();
	gfx_mono_init();
	touch_init();
	adc_sensors_init();

	// Enable display backlight
	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);

	// Workaround for known issue: Enable RTC32 sysclk
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm) {
		// Wait for RTC32 sysclk to become stable
	}

	// If we have battery power and RTC is running, don't initialize RTC32
	if (rtc_vbat_system_check(false) != VBAT_STATUS_OK) {
		rtc_init();

		// Set current time to after production date
		rtc_timestamp = production_date_get_timestamp() + 1;
		rtc_set_time(rtc_timestamp);
	}

	// Get current time
	rtc_timestamp = rtc_get_time();
	// Make sure RTC has not been set to a too early date .
	if (rtc_timestamp < FIRST_POSSIBLE_TIMESTAMP) {
		// Set time to 01.01.2011 00:00:00
		rtc_set_time(FIRST_POSSIBLE_TIMESTAMP);
	}

	// Initialize USB CDC class
	cdc_start();

	cpu_irq_enable();

	// Display a splash screen showing button functions
	button_splash();

	// Set timezone from EEPROM or to a default value
	timezone_init();

	/* Main loop. Read keyboard status and pass input to menu system.
	 * When an element has been selected in the menu, it will return the
	 * index of the element that should be run. This can be an application
	 * or another menu.
	 */
	while (true) {

		// (re)initialize menu system
		gfx_mono_menu_init(&main_menu);

		do {
			do {
				keyboard_get_key_state(&input);
			// Wait for key release
			} while (input.type != KEYBOARD_RELEASE);

			// Send key to menu system
			menu_status = gfx_mono_menu_process_key(&main_menu, input.keycode);
		// Wait for something useful to happen in the menu system
		} while (menu_status == GFX_MONO_MENU_EVENT_IDLE);

		switch (menu_status) {
		case 0:
			ntc_sensor_application();
			break;
		case 1:
			lightsensor_application();
			break;
		case 2:
			production_date_application();
			break;
		case 3:
			date_time_application();
			break;
		case 4:
			// Toggle LCD Backlight
			gpio_toggle_pin(NHD_C12832A1Z_BACKLIGHT);
			break;
		case GFX_MONO_MENU_EVENT_EXIT:
			// Fall trough to default and show button splash
		default:
			button_splash();
			break;
		};
	}
}
int main(void)
{
	struct adc_config         adc_conf;
	struct adc_channel_config adcch_conf;

	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();
	gfx_mono_init();

	// Enable the back light of the LCD
	ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

	// Initialize configuration structures.
	adc_read_configuration(&ADCB, &adc_conf);
	adcch_read_configuration(&ADCB, ADC_CH0, &adcch_conf);

	/* Configure the ADC module:
	 * - unsigned, 12-bit results
	 * - bandgap (1 V) voltage reference
	 * - 200 kHz maximum clock rate
	 * - manual conversion triggering
	 */
	adc_set_conversion_parameters(&adc_conf, ADC_SIGN_OFF, ADC_RES_12,
			ADC_REF_BANDGAP);
	adc_set_clock_rate(&adc_conf, 200000UL);
	adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);

	adc_write_configuration(&ADCB, &adc_conf);

	/* Configure ADC channel 0:
	 * - single-ended measurement from configured input pin
	 * - interrupt flag set on completed conversion
	 */
	adcch_set_input(&adcch_conf, INPUT_PIN, ADCCH_NEG_NONE,
			1);
	adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);
	adcch_disable_interrupt(&adcch_conf);

	adcch_write_configuration(&ADCB, ADC_CH0, &adcch_conf);

	// Enable the ADC and do one dummy conversion.
	adc_enable(&ADCB);
	adc_start_conversion(&ADCB, ADC_CH0);
	adc_wait_for_interrupt_flag(&ADCB, ADC_CH0);

	// Light up LED 1, wait for button press.
	ioport_set_pin_low(LED1_PIN);
	wait_for_button();

	// Perform oversampling of offset.
	cal_data.offset = get_mean_sample_value();

	// Light up LED 2, wait for button press.
	ioport_set_pin_low(LED2_PIN);
	wait_for_button();

	// Perform oversampling of 0.9 V for gain calibration.
	cal_data.gain = get_mean_sample_value() - cal_data.offset;

	// Turn off LEDs.
	ioport_set_pin_high(LED1_PIN);
	ioport_set_pin_high(LED2_PIN);

	// Enable interrupts on ADC channel, then trigger first conversion.
	adcch_enable_interrupt(&adcch_conf);
	adcch_write_configuration(&ADCB, ADC_CH0, &adcch_conf);
	adc_start_conversion(&ADCB, ADC_CH0);

	do {
		// Sleep until ADC interrupt triggers.
		sleepmgr_enter_sleep();
	} while (1);
}
示例#24
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/* The sensor_platform_init() function will initialize the system
	 * clock and sensor bus support in addition to configuring the
	 * XMEGA-A3BU and Sensor Xplained boards.
	 *
	 * Use gfx_mono_init() to initialize the monochrome graphical system
	 * API then write a splash screen after enabling the LCD display
	 * backlight and setting the contrast.
	 */
	sensor_platform_init();
	gfx_mono_init();

	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	gfx_mono_draw_string(
			"Atmel\r\nSensors Xplained\r\nInertial Sensor Demo",
			0, 0, &sysfont);

	delay_ms(2000);

	clear_screen();

	gfx_mono_draw_string("Press button SW1", 1, 5, &sysfont);
	gfx_mono_draw_string("to change sensor", 1, 13, &sysfont);

	delay_ms(1000);

	screen_border();

	/* Attach descriptors to sensors on an Xplained add-on board. */
	sensor_t accelerometer;
	sensor_attach(&accelerometer, SENSOR_TYPE_ACCELEROMETER, 0, 0);

	sensor_t gyroscope;
	sensor_attach(&gyroscope, SENSOR_TYPE_GYROSCOPE, 0, 0);

	sensor_t compass;
	sensor_attach(&compass, SENSOR_TYPE_COMPASS, 0, 0);

	/* Configure operational parameters for select sensors. */
	sensor_set_range(&accelerometer, 2000 /* milli-g */);
	sensor_set_bandwidth(&accelerometer, 25 /* Hertz */);

	while (true) {
		/* Initialize a sensor data descriptor for scaled data. */
		static sensor_data_t sensor_data = {.scaled = true};

		do {
			/* Measure & show acceleration until button SW1 is
			 * pushed. */
			sensor_read(&accelerometer, SENSOR_READ_ACCELERATION, &sensor_data);
			draw_formatted_data(acceleration_format, &sensor_data);
		} while (!switch_pressed(SW1));

		do {
			/* Measure & show rotation until button SW1 is pushed. */
			sensor_read(&gyroscope, SENSOR_READ_ROTATION, &sensor_data);
			draw_formatted_data(rotation_format, &sensor_data);
		} while (!switch_pressed(SW1));

		static gfx_coord_t const ring_center_x = 112;
		static gfx_coord_t const ring_center_y = 16;
		static gfx_coord_t const ring_radius   = 15;

		/* Compass needle point x- and y-coordinate. */
		gfx_coord_t needle_x = ring_center_x;
		gfx_coord_t needle_y = ring_center_y;

		/* Draw the compass ring. */
		gfx_mono_draw_circle(ring_center_x, ring_center_y, ring_radius,
				GFX_PIXEL_SET, GFX_WHOLE);

		do {
			/* Measure & show magnetic heading until button SW1 is
			 * pushed.
			 */
			sensor_read(&compass, SENSOR_READ_HEADING, &sensor_data);

			/* Calculate compass needle coordinates on the display
			 * by using sin() & cos() to find the x- and y-coordinate of the
			 * needle point. Note that the 'direction' value is in degrees
			 * and must be converted to radians for the C-library math
			 * functions.
			 */
			int const needle_length = ring_radius - 3;
			double const direction  = radians(sensor_data.heading.direction);

			/* Erase the old compass needle. */
			gfx_mono_draw_line(ring_center_x, ring_center_y,
					needle_x, needle_y, GFX_PIXEL_CLR);

			needle_x = ring_center_x +
					(needle_length * sin(direction + M_PI));
			needle_y = ring_center_y +
					(needle_length * cos(direction + M_PI));

			/* Draw the new compass needle. */
			gfx_mono_draw_line(ring_center_x, ring_center_y,
					needle_x, needle_y, GFX_PIXEL_SET);

			draw_formatted_data(heading_format, &sensor_data);
		} while (!switch_pressed(SW1));

		/* Clear last compass needle and compass ring. */
		gfx_mono_draw_line(ring_center_x, ring_center_y,
				needle_x, needle_y, GFX_PIXEL_CLR);

		gfx_mono_draw_circle(ring_center_x, ring_center_y, ring_radius,
				GFX_PIXEL_CLR, GFX_WHOLE);

		screen_border();

		do {
			/* Measure & show temperature until button SW1 is pushed. */
			sensor_read(&gyroscope, SENSOR_READ_TEMPERATURE, &sensor_data);

			/* Arrange temperature data values in array with
			 * Fahrenheit and Celsius formats.
			 */
			int32_t const temp_deg_c = sensor_data.temperature.value;
			int32_t const temp_deg_f = CELSIUS_TO_FAHRENHEIT(temp_deg_c);

			sensor_data.value[0] = temp_deg_f;
			sensor_data.value[1] = temp_deg_c;

			draw_formatted_data(temperature_format, &sensor_data);
		} while (!switch_pressed(SW1));
	}
}
示例#25
0
/**
 * \brief Example application entry routine
 */
int main(void)
{
	/* The sensor_platform_init() function will initialize the system
	 * clock and sensor bus support in addition to configuring the
	 * XMEGA-A3BU and Sensor Xplained boards.
	 *
	 * Use gfx_mono_init() to initialize the monochrome graphical system
	 * API then write a splash screen after enabling the LCD display
	 * backlight and setting the contrast.
	 *
	 * The MCU is going to be put in a sleep mode, so initialize the
	 * sleep manager API with a call to the sleepmgr_init() routine.
	 */
	sensor_platform_init();
	gfx_mono_init();
	sleepmgr_init();

	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	/* Attach an accelerometer on a Sensors Xplained board. */
	sensor_t accelerometer;
	sensor_attach(&accelerometer, SENSOR_TYPE_ACCELEROMETER, 0, 0);

	/* Enable the accelerometer low-g (free fall) event. */
	sensor_enable_event(&accelerometer, SENSOR_EVENT_LOW_G);

	/* Set the free fall threshold (low-g event), bandwidth and range. */
	sensor_set_threshold(&accelerometer, SENSOR_THRESHOLD_LOW_G,
			LOW_G_THRESHOLD);
	sensor_set_bandwidth(&accelerometer, BANDWIDTH);
	sensor_set_range(&accelerometer, RANGE);

	while (true) {
		/* Put the accelerometer into a low-power mode (if available). */
		sensor_set_state(&accelerometer, SENSOR_STATE_LOW_POWER);

		LED_Off(ACCEL_LED);

		clear_screen();

		/* Display the "armed" message and put the MCU in sleep mode. */
		gfx_mono_draw_string("ATMEL Drop Demo\r\nXMEGA Powered Down\r\n"
				"g Sensor Armed", 1, 5, &sysfont);

		sleepmgr_lock_mode(SLEEP_MODE);
		sleepmgr_enter_sleep();

		/* The following runs after the MCU has been woken by an
		 * external low-g interrupt from the accelerometer.
		 *
		 * Turn on the red LED while falling and put the accelerometer
		 * into a high-power mode (if available) to sample date points.
		 */
		LED_On(ACCEL_LED);

		sensor_set_state(&accelerometer, SENSOR_STATE_HIGHEST_POWER);

		static scalar_t acceleration_waveform[DATA_SAMPLE_COUNT];
		scalar_t acceleration_max = 0;

		for (int data_count = 0; data_count < DATA_SAMPLE_COUNT;
				++data_count) {
			acceleration_waveform[data_count] = 0;

			for (int i = 0; i < SAMPLE_AVG_COUNT; ++i) {
				/* Calculate the gravity vector magnitude. */
				vector3_t gvec;
				sensor_get_vector(&accelerometer, &gvec);

				scalar_t const acceleration_magnitude
					= vector3_magnitude(&gvec);

				/* Store the maximum g magnitude for this
				 * sub-group. */
				if (acceleration_magnitude >
						acceleration_waveform[data_count]) {
					acceleration_waveform[data_count]
						= acceleration_magnitude;
				}

				/* Store the maximum g magnitude for the whole
				 * data set. */
				if (acceleration_magnitude > acceleration_max) {
					acceleration_max = acceleration_magnitude;
				}
			}
		}

		clear_screen();

		/* Turn the max acceleration into a string and convert to g. */
		static char max_g_string[20];

		if (acceleration_max > LOW_G_SATURATION) {
			sprintf(max_g_string, "g Sensor Saturated");
		} else {
			sprintf(max_g_string, "Peak = %02.2f g",
					acceleration_max / 1000);
		}

		/* Print the max g on the monochrome display. */
		gfx_mono_draw_string("Drop Detected", 1, 5, &sysfont);
		gfx_mono_draw_string(max_g_string, 1, 13, &sysfont);
		gfx_mono_draw_string("Press SW1 for chart", 1, 21, &sysfont);

		do {
			LED_Toggle(ACCEL_LED);
			delay_ms(100);
		} while (!switch_pressed(SW1));

		/* Plot the collected data points to create the waveform chart. */
		clear_screen();
		screen_border();

		for (int data_count = 0; data_count < DATA_SAMPLE_COUNT; ++data_count) {
			gfx_mono_draw_filled_circle(data_count,
					32 -
					(acceleration_waveform[data_count] / 500), 1,
					GFX_PIXEL_SET, GFX_WHOLE);
		}

		do {
			LED_Toggle(PROMPT_LED);
			delay_ms(100);
		} while (!switch_pressed(SW1));

		LED_Off(PROMPT_LED);
	}
}