Microchip® Advanced Software Framework

sam/applications/starter_kit_demo/main.c File Reference

Starter Kit Demo.

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

#include <asf.h>
#include <string.h>

Macros

#define BUFFER_SIZE   128
 
#define IRQ_PRIOR_PIO   0
 

Functions

static void Button1_Handler (uint32_t id, uint32_t mask)
 Handler for Button 1 rising edge interrupt. More...
 
static void Button2_Handler (uint32_t id, uint32_t mask)
 Handler for Button 2 rising edge interrupt. More...
 
static void Button3_Handler (uint32_t id, uint32_t mask)
 Handler for Button 3 rising edge interrupt. More...
 
static void configure_adc (void)
 Configure the ADC for the light sensor. More...
 
static void configure_buttons (void)
 Configure the Pushbuttons. More...
 
static void display_sd_files (void)
 Show SD card content on the OLED screen. More...
 
static void display_sd_info (void)
 Show SD card status on the OLED screen. More...
 
static void get_num_files_on_sd (void)
 Get the number of files at the root of the SD card. More...
 
int main (void)
 
static void ProcessButtonEvt (uint8_t uc_button)
 Process Buttons Events. More...
 
static void SD_Detect_Handler (uint32_t id, uint32_t mask)
 Handler for SD card detect rising edge interrupt. More...
 
static void ssd1306_clear_char (void)
 Clear one character at the cursor current position on the OLED screen. More...
 
static void ssd1306_draw_graph (uint8_t col, uint8_t page, uint8_t width, uint8_t height, uint8_t *tab)
 Draw graph on the OLED screen using the provided point array. More...
 

Variables

volatile uint32_t app_mode = 2
 
volatile uint32_t app_mode_switch = 1
 
FATFS fs
 
volatile uint32_t sd_fs_found = 0
 
volatile uint32_t sd_listing_pos = 0
 
volatile uint32_t sd_num_files = 0
 
volatile uint32_t sd_update = 0
 

#define BUFFER_SIZE   128

Referenced by main().

#define IRQ_PRIOR_PIO   0

Referenced by configure_buttons().

static void Button1_Handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 1 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References ProcessButtonEvt().

Referenced by configure_buttons().

static void Button2_Handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 2 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References ProcessButtonEvt().

Referenced by configure_buttons().

static void Button3_Handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for Button 3 rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References ProcessButtonEvt().

Referenced by configure_buttons().

static void configure_adc ( void  )
static

Configure the ADC for the light sensor.

References adc_enable_channel(), ADC_TRIG_SW, gpio_configure_pin, pmc_enable_periph_clk(), and sysclk_get_cpu_hz().

Referenced by main().

static void configure_buttons ( void  )
static

Configure the Pushbuttons.

Configure the PIO as inputs and generate corresponding interrupt when pressed or released.

References Button1_Handler(), Button2_Handler(), Button3_Handler(), IRQ_PRIOR_PIO, pio_enable_interrupt(), pio_set_debounce_filter(), pmc_enable_periph_clk(), and SD_Detect_Handler().

Referenced by main().

static void display_sd_files ( void  )
static

Show SD card content on the OLED screen.

Note
Does not browse sub folders.

References _MAX_LFN, f_opendir(), f_readdir(), FILINFO::fname, FR_OK, sd_listing_pos, ssd1306_set_column_address(), ssd1306_set_page_address(), and ssd1306_write_text().

Referenced by main().

static void get_num_files_on_sd ( void  )
static

Get the number of files at the root of the SD card.

Result is stored in global sd_num_files.

References _MAX_LFN, f_opendir(), f_readdir(), FILINFO::fname, FR_OK, and sd_num_files.

Referenced by display_sd_info().

static void ProcessButtonEvt ( uint8_t  uc_button)
static

Process Buttons Events.

Parameters
uc_buttonThe button number.

References app_mode_switch, sd_fs_found, sd_listing_pos, sd_num_files, and sd_update.

Referenced by Button1_Handler(), Button2_Handler(), and Button3_Handler().

static void SD_Detect_Handler ( uint32_t  id,
uint32_t  mask 
)
static

Handler for SD card detect rising edge interrupt.

Parameters
idThe button ID.
maskThe button mask.

References sd_fs_found, sd_listing_pos, sd_num_files, and sd_update.

Referenced by configure_buttons().

static void ssd1306_clear_char ( void  )
static

Clear one character at the cursor current position on the OLED screen.

References ssd1306_write_data().

Referenced by main().

static void ssd1306_draw_graph ( uint8_t  col,
uint8_t  page,
uint8_t  width,
uint8_t  height,
uint8_t *  tab 
)
static

Draw graph on the OLED screen using the provided point array.

Parameters
colX coordinate.
pageY coordinate (please refer to OLED datasheet for page description).
widthGraph width.
heightGraph height.
tabData to draw. Must contain width elements.

References SSD1306_CMD_SET_PAGE_START_ADDRESS, ssd1306_set_column_address(), ssd1306_write_command(), and ssd1306_write_data().

Referenced by main().

volatile uint32_t app_mode = 2
volatile uint32_t app_mode_switch = 1

Referenced by main(), and ProcessButtonEvt().

volatile uint32_t sd_fs_found = 0
volatile uint32_t sd_listing_pos = 0
volatile uint32_t sd_num_files = 0
volatile uint32_t sd_update = 0