Example #1
0
File: app.c Project: InSoonPark/asf
/**
 *  \brief Initialize the app in low power: now PB0 push button has been pressed
 *  once, the application switches in low power mode: Stop LCD controller, stop
 *  LCD backlight, stop QTouch acquisition, switch SAM4L in power scaling PS1
 *  mode. SAM4L is in RUN mode.
 */
void app_init_lowpower(void)
{

	// Stop LCD Controller
	lcdca_disable();

	// Stop QTouch Initialization
	touch_sensors_deinit();

	// Initialize board features
	board_init();

	// Clear LCD backlight
	ioport_set_pin_level(LCD_BL_GPIO, IOPORT_PIN_LEVEL_LOW);

	// Disable the peripheral that we do not use anymore
	sysclk_disable_peripheral_clock(CATB);
	sysclk_disable_peripheral_clock(PDCA);
	sysclk_disable_peripheral_clock(LCDCA);

	// Set MCU Status
	ui_set_mcu_status(POWER_SCALING_PS1, SLEEP_MODE_RUN,
		12000000, CPU_SRC_RC4M);

	// Switch in selected Power Scaling mode
	app_switch_power_scaling(ui_get_power_scaling_mcu_status());

	// Send new MCU status to the board monitor
	ui_bm_send_mcu_status();

}
Example #2
0
/**
 * \brief User Interface - Board Monitor Initialization :
 *  and send SAM4L status.
 */
void ui_bm_init(void)
{
	/*
	 * Initialize Board Monitor and send first status
	 */
	sysclk_enable_peripheral_clock(BM_USART_USART);
	bm_init();
	sysclk_disable_peripheral_clock(BM_USART_USART);
	ui_bm_send_mcu_status();
}
Example #3
0
/**
 *  \brief Lower power and QTouch Demo for SAM4L entry point.
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t event_qtouch_slider_position = 0;
	power_scaling_t power_scaling = POWER_SCALING_PS1;
	sleep_mode_t sleep_mode = SLEEP_MODE_RUN;
	/*
	 * QTouch library:
	 * Use touch_config_sam4l.h file to configure Sensor Pins, number of Sensors
	 * and Sensor Global configuration information.

	 * Use touch.c touch_sensors_config() function to set Sensor specific
	 * configuration data such as the Sensor Threshold setting.
	 */

	/*
	 * At startup the application run in full demo mode (all features on,
	 * includes QTouch and segment LCD). Initialize the board IO configuration,
	 * clocks, QTouch library, External interrupts, NVIC and UI SAM4L is running
	 * at 12 MHz from internal RCFAST (configured at 12MHz).
	 */
	app_init();

	// Stay in full demo mode until push button PB0 button is pressed
	while (!event_is_push_button_pressed()){
		// Runs prime number algorithm
		app_prime_number_run();
		/*
		 * Capture QTouch inputs (sliders and CS0 QTouch button): displays the
		 * slider value (0..255) to the segment LCD, CS0 will change the SAM4L
		 * Power Scaling mode (from PS0 to PS2).
		 */
		touch_sensors_measure();
		if (event_qtouch_get_button_state()) {
			/*
			 * Change Power Scaling Mode: circle from PS0 to PS2.
			 * - Read current Power Scaling status,
			 * - Change Power Scaling Value,
			 * - Switch into this Power Scaling Value.
			 */
			power_scaling = ui_get_power_scaling_mcu_status();
			if (power_scaling == POWER_SCALING_PS0) {
				power_scaling = POWER_SCALING_PS1;
			} else if ((power_scaling == POWER_SCALING_PS1) &&
					   (is_ps2_mode_supported_by_the_part())) {
				power_scaling = POWER_SCALING_PS2;
			} else {
				power_scaling = POWER_SCALING_PS0;
			}
			ui_set_power_scaling_mcu_status(power_scaling);
			app_switch_power_scaling(power_scaling);
			// Send new MCU status to the board monitor
			ui_bm_send_mcu_status();
			// Refresh LCD Text area with this new power scaling value
			ui_lcd_refresh_txt();
			// Initialize touch sensing after Power Scaling mode change
			touch_sensors_deinit();
			touch_sensors_init();
		}
		/*
		 * Display slider value (0...255) if slider is pressed, clear display
		 * if not.
		 */
		if (event_qtouch_get_slider_state(&event_qtouch_slider_position)) {
			ui_lcd_refresh_alphanum(true,
				event_qtouch_slider_position);
		} else {
			ui_lcd_refresh_alphanum(false,
				event_qtouch_slider_position);
		}
	}
	/*
	 * Now PB0 push button has been pressed once, the application switches in
	 * low power mode: Stop LCD controller, stop LCD back light, stop QTouch
	 * acquisition, switch SAM4L in power scaling PS1 mode.
	 * SAM4L is in RUN mode.
	 */
	app_init_lowpower();

	while(1u){
		// Runs prime number algorithm
		app_prime_number_run();
		/*
		 * Run in low power mode: if PB0 is pressed, the SAM4L will enter one of
		 * the sleep modes (from RUN to WAIT to RET to BACKUP, then restart to
		 * RUN). For each sleep mode transition, the SAM4L is sending the
		 * information for the board monitor (over the USART). The current SAM4L
		 * sleep mode is displayed by the board monitor on the OLED display.
		*/
		if (event_is_push_button_pressed()) {
			/*
			 * Change Sleep Mode: RUN->WAIT->RET->BACKUP.
			 * - Read current Sleep Mode status,
			 * - Change Sleep Mode Value,
			 * - Enter into this Sleep Mode Value.
			 */
			sleep_mode = ui_get_sleep_mode_mcu_status();
			switch(sleep_mode){
				case SLEEP_MODE_WAIT:
					sleep_mode = SLEEP_MODE_RETENTION;
				break;
				case SLEEP_MODE_RETENTION:
					sleep_mode = SLEEP_MODE_BACKUP;
				break;
				case SLEEP_MODE_BACKUP:
					sleep_mode = SLEEP_MODE_RUN;
				break;
				case SLEEP_MODE_RUN:
				default:
					sleep_mode = SLEEP_MODE_WAIT;
				break;
			}
			ui_set_sleep_mode_mcu_status(sleep_mode);
			// Send new MCU status to the board monitor
			ui_bm_send_mcu_status();
			// Now we're ready to enter the selected sleep mode
			app_enter_sleep_mode(sleep_mode);
		}
	}

}// end main function