This file contains the demo main functions.
Copyright (c) 2010-2018 Microchip Technology Inc. and its subsidiaries.
#include "board.h"
#include "gpio.h"
#include "scif_uc3l.h"
#include "pwma.h"
#include "delay.h"
#include "touch_api_at32uc3l.h"
Macros | |
#define | AUTO_RUNNING_LIGHTS_DEFAULT_TIMER 25 |
#define | AUTO_RUNNING_LIGHTS_MAX_TIMER (1000) |
#define | AUTO_RUNNING_LIGHTS_MIN_TIMER (1) |
#define | AUTO_RUNNING_LIGHTS_SPEED_STEPS (1) |
#define | BTN_SENSOR_DOWN_MASK (0x2u) |
#define | BTN_SENSOR_LEFT_MASK (0x8u) |
#define | BTN_SENSOR_PLAYPAUSE_MASK (0x10u) |
#define | BTN_SENSOR_RIGHT_MASK (0x20u) |
#define | BTN_SENSOR_UP_MASK (0x4u) |
#define | DIM_LIGHT_SUDDEN_OFF_LIMIT (32UL) |
#define | DIM_LIGHT_SUDDEN_ON_LIMIT (32UL) |
#define | WHEEL_SENSORS_MASK (0x1u) |
PWMA settings. | |
#define | PWMA_OUTPUT_FREQUENCY 470588 |
#define | PWMA_GCLK_FREQUENCY 120000000 |
#define | PWMA_CHANNELS_MASK ((LED0_PWM<<0)|(LED1_PWM<<8)|(LED2_PWM<<16)|(LED3_PWM<<24)) |
Define the channel mask for using Interlinked multi mode method as the channel is limited to 4. More... | |
#define | PWMA_MIN_DUTY_CYCLES 0 |
Minimum number of duty cycles for a PWM channel. More... | |
#define | PWMA_MAX_DUTY_CYCLES 0xFF |
Maximum number of duty cycles for a PWM channel. More... | |
#define | PWMA_DUTY_CYCLES_STEP 0xF |
#define | PWMA_DUTY_CYCLE_INIT_VAL 0 |
#define | PWMA_DUTY_CYCLE_INCREASE (+1) |
#define | PWMA_DUTY_CYCLE_DECREASE (-1) |
Enumerations | |
enum | { IDX_LED0, IDX_LED1, IDX_LED2, IDX_LED3 } |
enum | { DEMO_STATE_IDLE, DEMO_STATE_WHEEL_PROCESS, DEMO_STATE_BTNS_PROCESS } |
enum | { BTNS_STATE_MACHINE_IDLE, BTNS_STATE_MACHINE_PLAY, BTNS_STATE_MACHINE_UP_DOWN, BTNS_STATE_MACHINE_RIGHT_LEFT } |
enum | { DIRECTION_STABLE = 0, DIRECTION_CLOCKWISE = PWMA_DUTY_CYCLE_DECREASE, DIRECTION_ANTICLOCKWISE = PWMA_DUTY_CYCLE_INCREASE } |
enum | { INTENSITY_INCREASE, INTENSITY_DECREASE } |
enum | { SPEED_INCREASE, SPEED_DECREASE, SPEED_NO_CHANGE } |
enum | { LIGHT_SWITCH_UP, LIGHT_SWITCH_DOWN, LIGHT_SWITCH_RELEASE } |
Functions | |
static int | compute_direction (unsigned char previous_position_angle, unsigned char position_angle) |
void | demo_automatic_ledshow_play (int repeat) |
Prologue of the demo. More... | |
void | demo_init_pwma (void) |
Initialize the PWMA module for the demo. More... | |
static void | emulate_light_switch (int switch_event) |
static void | play_auto_running_lights (int speed_changes) |
static void | play_level_bar (int intensity_direction) |
static void | process_buttons (touch_acq_status_t touch_acq_status) |
void | process_qtouchlib_data (void) |
Process the latest qtouchlib data. More... | |
static void | process_wheel (void) |
static void | reset_leds (void) |
static void | set_all_leds (void) |
Variables | |
static unsigned int | btns_state_machine = BTNS_STATE_MACHINE_IDLE |
static int | current_led = IDX_LED0 |
static unsigned int | demo_state = DEMO_STATE_IDLE |
uint16_t | duty_cycles_per_led [LED_COUNT] |
static int | leds_intensity_effect = INTENSITY_INCREASE |
touch_measure_data_t * | p_qm_measure_data |
QMatrix measured data pointer. More... | |
volatile uint8_t | qm_measurement_done_touch |
Flag set by touch_qm_measure_complete_callback() function when a fresh Touch status is available. More... | |
#define AUTO_RUNNING_LIGHTS_DEFAULT_TIMER 25 |
Referenced by play_auto_running_lights().
#define AUTO_RUNNING_LIGHTS_MAX_TIMER (1000) |
Referenced by play_auto_running_lights().
#define AUTO_RUNNING_LIGHTS_MIN_TIMER (1) |
Referenced by play_auto_running_lights().
#define AUTO_RUNNING_LIGHTS_SPEED_STEPS (1) |
Referenced by play_auto_running_lights().
#define BTN_SENSOR_DOWN_MASK (0x2u) |
Referenced by process_buttons(), and process_qtouchlib_data().
#define BTN_SENSOR_LEFT_MASK (0x8u) |
Referenced by process_buttons(), and process_qtouchlib_data().
#define BTN_SENSOR_PLAYPAUSE_MASK (0x10u) |
Referenced by process_buttons(), and process_qtouchlib_data().
#define BTN_SENSOR_RIGHT_MASK (0x20u) |
Referenced by process_buttons(), and process_qtouchlib_data().
#define BTN_SENSOR_UP_MASK (0x4u) |
Referenced by process_buttons(), and process_qtouchlib_data().
#define DIM_LIGHT_SUDDEN_OFF_LIMIT (32UL) |
Referenced by emulate_light_switch().
#define DIM_LIGHT_SUDDEN_ON_LIMIT (32UL) |
Referenced by emulate_light_switch().
#define PWMA_CHANNELS_MASK ((LED0_PWM<<0)|(LED1_PWM<<8)|(LED2_PWM<<16)|(LED3_PWM<<24)) |
Define the channel mask for using Interlinked multi mode method as the channel is limited to 4.
Referenced by play_auto_running_lights(), play_level_bar(), and process_wheel().
#define PWMA_DUTY_CYCLE_DECREASE (-1) |
#define PWMA_DUTY_CYCLE_INCREASE (+1) |
Referenced by demo_automatic_ledshow_play().
#define PWMA_DUTY_CYCLE_INIT_VAL 0 |
Referenced by demo_init_pwma().
#define PWMA_DUTY_CYCLES_STEP 0xF |
Referenced by demo_automatic_ledshow_play(), emulate_light_switch(), play_auto_running_lights(), play_level_bar(), and process_wheel().
#define PWMA_GCLK_FREQUENCY 120000000 |
Referenced by demo_init_pwma().
#define PWMA_MAX_DUTY_CYCLES 0xFF |
Maximum number of duty cycles for a PWM channel.
Referenced by demo_automatic_ledshow_play(), emulate_light_switch(), play_auto_running_lights(), play_level_bar(), process_wheel(), and reset_leds().
#define PWMA_MIN_DUTY_CYCLES 0 |
Minimum number of duty cycles for a PWM channel.
Referenced by demo_automatic_ledshow_play(), emulate_light_switch(), play_auto_running_lights(), play_level_bar(), process_wheel(), and set_all_leds().
#define PWMA_OUTPUT_FREQUENCY 470588 |
The PWMA frequency is 470588 so that the TOP value is maximum(i.e 0xff)
Referenced by demo_init_pwma().
#define WHEEL_SENSORS_MASK (0x1u) |
Referenced by process_qtouchlib_data().
anonymous enum |
|
static |
References abs, DIRECTION_ANTICLOCKWISE, DIRECTION_CLOCKWISE, and DIRECTION_STABLE.
Referenced by process_wheel().
void demo_automatic_ledshow_play | ( | int | repeat | ) |
Prologue of the demo.
All 4 LEDs blink n(=repeat) times simultaneously with PWM fading effect.
References current_led, delay_ms, duty_cycles_per_led, i, max, min, PWMA_DUTY_CYCLE_INCREASE, PWMA_DUTY_CYCLES_STEP, PWMA_MAX_DUTY_CYCLES, PWMA_MIN_DUTY_CYCLES, and pwma_set_channels_value().
Referenced by main().
void demo_init_pwma | ( | void | ) |
Initialize the PWMA module for the demo.
References gpio_enable_module_pin(), pwma_config_enable(), PWMA_DUTY_CYCLE_INIT_VAL, PWMA_GCLK_FREQUENCY, PWMA_OUTPUT_FREQUENCY, pwma_set_channels_value(), scif_gc_enable(), scif_gc_setup(), SCIF_GCCTRL_RC120M, and scif_start_rc120M().
Referenced by main().
|
static |
|
static |
References AUTO_RUNNING_LIGHTS_DEFAULT_TIMER, AUTO_RUNNING_LIGHTS_MAX_TIMER, AUTO_RUNNING_LIGHTS_MIN_TIMER, AUTO_RUNNING_LIGHTS_SPEED_STEPS, current_led, duty_cycles_per_led, IDX_LED0, INTENSITY_DECREASE, INTENSITY_INCREASE, leds_intensity_effect, max, min, PWMA_CHANNELS_MASK, PWMA_DUTY_CYCLES_STEP, PWMA_MAX_DUTY_CYCLES, PWMA_MIN_DUTY_CYCLES, pwma_set_multiple_values(), SPEED_DECREASE, and SPEED_INCREASE.
Referenced by process_buttons().
|
static |
References current_led, duty_cycles_per_led, i, INTENSITY_INCREASE, PWMA_CHANNELS_MASK, PWMA_DUTY_CYCLES_STEP, PWMA_MAX_DUTY_CYCLES, PWMA_MIN_DUTY_CYCLES, and pwma_set_multiple_values().
Referenced by process_buttons().
|
static |
References BTN_SENSOR_DOWN_MASK, BTN_SENSOR_LEFT_MASK, BTN_SENSOR_PLAYPAUSE_MASK, BTN_SENSOR_RIGHT_MASK, BTN_SENSOR_UP_MASK, btns_state_machine, BTNS_STATE_MACHINE_PLAY, BTNS_STATE_MACHINE_RIGHT_LEFT, BTNS_STATE_MACHINE_UP_DOWN, emulate_light_switch(), INTENSITY_DECREASE, INTENSITY_INCREASE, leds_intensity_effect, LIGHT_SWITCH_DOWN, LIGHT_SWITCH_RELEASE, LIGHT_SWITCH_UP, tag_touch_measure_data_t::p_sensor_states, play_auto_running_lights(), play_level_bar(), qm_measurement_done_touch, reset_leds(), SPEED_DECREASE, SPEED_INCREASE, and SPEED_NO_CHANGE.
Referenced by process_qtouchlib_data().
void process_qtouchlib_data | ( | void | ) |
Process the latest qtouchlib data.
References tag_touch_measure_data_t::acq_status, BTN_SENSOR_DOWN_MASK, BTN_SENSOR_LEFT_MASK, BTN_SENSOR_PLAYPAUSE_MASK, BTN_SENSOR_RIGHT_MASK, BTN_SENSOR_UP_MASK, btns_state_machine, BTNS_STATE_MACHINE_IDLE, demo_state, DEMO_STATE_BTNS_PROCESS, DEMO_STATE_IDLE, DEMO_STATE_WHEEL_PROCESS, NULL, tag_touch_measure_data_t::p_sensor_states, process_buttons(), process_wheel(), reset_leds(), TOUCH_ROTOR_SLIDER_POS_CHANGE, TOUCH_STATUS_CHANGE, and WHEEL_SENSORS_MASK.
Referenced by main().
|
static |
References compute_direction(), current_led, DIRECTION_ANTICLOCKWISE, DIRECTION_CLOCKWISE, DIRECTION_STABLE, duty_cycles_per_led, IDX_LED0, tag_touch_measure_data_t::p_rotor_slider_values, PWMA_CHANNELS_MASK, PWMA_DUTY_CYCLES_STEP, PWMA_MAX_DUTY_CYCLES, PWMA_MIN_DUTY_CYCLES, and pwma_set_multiple_values().
Referenced by process_qtouchlib_data().
|
static |
References current_led, duty_cycles_per_led, i, IDX_LED0, PWMA_MAX_DUTY_CYCLES, and pwma_set_channels_value().
Referenced by emulate_light_switch(), process_buttons(), and process_qtouchlib_data().
|
static |
References duty_cycles_per_led, i, PWMA_MIN_DUTY_CYCLES, and pwma_set_channels_value().
Referenced by emulate_light_switch().
|
static |
Referenced by process_buttons(), and process_qtouchlib_data().
|
static |
|
static |
Referenced by process_qtouchlib_data().
uint16_t duty_cycles_per_led[LED_COUNT] |
Referenced by demo_automatic_ledshow_play(), emulate_light_switch(), play_auto_running_lights(), play_level_bar(), process_wheel(), reset_leds(), and set_all_leds().
|
static |
Referenced by play_auto_running_lights(), and process_buttons().
touch_measure_data_t* p_qm_measure_data |
QMatrix measured data pointer.
QMatrix measured data pointer.
Needs to be global since it is required for the QDebug module.
volatile uint8_t qm_measurement_done_touch |
Flag set by touch_qm_measure_complete_callback() function when a fresh Touch status is available.
Referenced by main(), process_buttons(), and touch_qm_measure_complete_callback().