Microchip® Advanced Software Framework

mega_1284p_xplained_example.c File Reference

MEGA-1284P Xplained Example.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include "avr_compiler.h"
#include "usart.h"
#include "init.h"
#include "touch_api.h"

Macros

#define ADC_NUM_OVERSAMPLING   16
 
#define ASCII_BACKSPACE   8
 
#define ASCII_CR   13
 
#define ASCII_SPACE   32
 
#define CMD_PROMPT   "\r\nMEGA-1284P Xplained>"
 
#define EXTENDED_STANDBY   0x0F
 Extended standby SMCR setting. More...
 
#define FLASHCOUNT   100
 
#define IDLE   0x01
 Idle SMCR setting. More...
 
#define MAX_CMD_BUFFER_LEN   32
 
#define NUM_COMMANDS   12
 
#define NUMBER_OF_PORTS   1
 Number of ports using touch. More...
 
#define POWER_DOWN   0x05
 Power-Down SMCR setting. More...
 
#define POWER_SAVE   0x07
 Power-Save SMCR setting. More...
 
#define QT_KEY_DETECT()   (qt_measure_data.qt_touch_status.sensor_states[0] & 0x01)
 Macro used for touch key detection. More...
 
#define STANDBY   0x0D
 Standby SMCR setting. More...
 

Enumerations

enum  adc_sources {
  FILTER_OUTPUT = 0x05,
  LIGHT_SENSOR = 0x06,
  NTC = 0x07
}
 ADC sources enum. More...
 

Functions

static void crystal_start_cmd (void)
 Function to handle 'start 32kHz crystal' command. More...
 
static void crystal_stop_cmd (void)
 Function to handle 'stop 32kHz crystal' command. More...
 
static void enter_sleep (uint8_t sleepmode)
 Function to enter sleep. More...
 
static void execute_demo_mode (void)
 brief Function to execute Demo mode. More...
 
static void execute_terminal_mode (void)
 brief Function to execute terminal mode. More...
 
static void ext_standby_cmd (void)
 Function to handle 'extended standby' command. More...
 
static void flash_leds (uint8_t flashcount)
 Function to flash leds flashcount amount of times. More...
 
static void flash_leds_cmd (void)
 Function to handle 'flash leds' command. More...
 
static void idle_mode_cmd (void)
 Function to handle 'idle' command. More...
 
 ISR (PCINT1_vect)
 PCINT8,9,10 ISR used for wake-up from sleep only. More...
 
 ISR (TIMER1_OVF_vect)
 TIMER1 overflow ISR used to dim LEDs in light sensor demo mode. More...
 
 ISR (TIMER1_COMPB_vect)
 TIMER1 compare B ISR used to dim LEDS in light sensor demo mode. More...
 
 ISR (TIMER1_COMPA_vect)
 TIMER1 compare A ISR used to time touch measurement. More...
 
 ISR (TIMER2_OVF_vect)
 TIMER2 overflow ISR used to indicate 32kHz crystal running. More...
 
static void light_sensor_demo (void)
 Function to handle 'light sensor demo' command. More...
 
int main (void)
 brief Example code that demonstrates the some of the basic features of the MEGA-1284P Xplained kit. More...
 
static void power_down_cmd (void)
 Function to handle 'power-down' command. More...
 
static void power_save_cmd (void)
 Function to handle 'power-save' command. More...
 
static void print_help ()
 Function to print supported commands. More...
 
static void process_command (const char *command)
 Function used to find and execute commands in terminal mode. More...
 
static uint16_t read_adc (enum adc_sources source)
 Function to start ADC conversion. More...
 
static void read_light_sensor (void)
 Function to read Light sensor ADC value. More...
 
static void read_ntc (void)
 Function to read NTC ADC value. More...
 
static void standby_cmd (void)
 Function to handle 'standby' command. More...
 
static void start32crystal (void)
 Function to start 32.768kHz crystal connected to TOSC1 and TOSC2. More...
 
static void stop32crystal (void)
 Function to stop 32.768kHz crystal connected to TOSC1 and TOSC2. More...
 

Variables

struct {
   char   cmd [20]
 
   void(*   func )(void)
 
   char   help [70]
 
commands [NUM_COMMANDS]
 Struct to hold all available commands, their help text and function to call. More...
 
static volatile uint16_t current_time_ms_touch = 0
 Current time, set by timer1 overflow ISR. More...
 
static volatile bool light_sensor_demo_mode = false
 Global variable used to identify if demo mode is enabled. More...
 
uint16_t qt_measurement_period_msec = 25
 Touch acquisition timer period in msec. More...
 
static volatile bool time_to_measure_touch = false
 Flag set by timer1 overflow ISR when it's time to measure touch. More...
 
FILE usart1_str = FDEV_SETUP_STREAM((int(*)(char, FILE *))usart1_putchar, NULL, _FDEV_SETUP_WRITE)
 Make sure printf knows where to print. More...
 

char cmd[20]

Referenced by print_help(), and process_command().

void(* func)(void)
char help[70]

Referenced by print_help().