Microchip® Advanced Software Framework

demo.c File Reference

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_tp_qm_measure_data
 Pointer to the measured data. 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
#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)

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)
#define PWMA_DUTY_CYCLE_INIT_VAL   0

Referenced by demo_init_pwma().

#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
#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
Enumerator
IDX_LED0 
IDX_LED1 
IDX_LED2 
IDX_LED3 
anonymous enum
Enumerator
DEMO_STATE_IDLE 
DEMO_STATE_WHEEL_PROCESS 
DEMO_STATE_BTNS_PROCESS 
anonymous enum
Enumerator
BTNS_STATE_MACHINE_IDLE 
BTNS_STATE_MACHINE_PLAY 
BTNS_STATE_MACHINE_UP_DOWN 
BTNS_STATE_MACHINE_RIGHT_LEFT 
anonymous enum
Enumerator
DIRECTION_STABLE 
DIRECTION_CLOCKWISE 
DIRECTION_ANTICLOCKWISE 
anonymous enum
Enumerator
INTENSITY_INCREASE 
INTENSITY_DECREASE 
anonymous enum
Enumerator
SPEED_INCREASE 
SPEED_DECREASE 
SPEED_NO_CHANGE 
anonymous enum
Enumerator
LIGHT_SWITCH_UP 
LIGHT_SWITCH_DOWN 
LIGHT_SWITCH_RELEASE 

static int compute_direction ( unsigned char  previous_position_angle,
unsigned char  position_angle 
)
static
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().

static void set_all_leds ( void  )
static

unsigned int btns_state_machine = BTNS_STATE_MACHINE_IDLE
static
unsigned int demo_state = DEMO_STATE_IDLE
static

Referenced by process_qtouchlib_data().

int leds_intensity_effect = INTENSITY_INCREASE
static
touch_measure_data_t* p_qm_measure_data

Pointer to the measured data.

Needs to be global since it is required for the QDebug module.

Pointer to the measured data.

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().