uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Functions | Variables
program.c File Reference

Program storage module implementation. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <avr/eeprom.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include "gpio.h"
#include "program.h"
Include dependency graph for program.c:

Functions

void copy_current_bank_to (uint8_t target_bank)
 Copies all programs in the current bank to another bank. More...
 
void copy_current_program_to (uint8_t target_program)
 Copies the current program to the specified position in memory. More...
 
char * export_bank (const uint8_t bank)
 Exports a program bank. More...
 
void enter_program (uint8_t number)
 Loads and executes the specified program. More...
 
bool import_bank (const uint8_t bank, const char *data)
 Imports and stores a program bank given as a hex-string. More...
 
void init_program_module (uint32_t program_initializer_value, void(*const execute_program_callback)(uint32_t program_data))
 Initializes the program storage module. More...
 
uint32_t read_program_data (uint8_t number)
 Reads a program data word from the specified position in memory. More...
 
void update_current_program (uint32_t program_data)
 Updates and stores the current program. More...
 
void wipe_current_bank (void)
 Reinitializes all programs in the current bank. More...
 
void wipe_current_program (void)
 Reinitializes the currently loaded program. More...
 
void write_program (uint8_t number, uint32_t data)
 Stores a given program data word in the specified position in memory. More...
 

Variables

static uint32_t program_data_storage [120] EEMEM
 EEPROM program storage. More...
 
static uint32_t program_initializer
 Initialization value for empty programs. More...
 
static struct program current_program
 Current program. More...
 
static void(* execute_program )(uint32_t)
 Callback for program execution. More...
 

Detailed Description

Program storage module implementation.

Function Documentation

◆ copy_current_bank_to()

void copy_current_bank_to ( uint8_t  target_bank)

Copies all programs in the current bank to another bank.

Irreversibly overwrites all programs in the target bank.

Parameters
target_bankTarget bank number [0..11].

◆ copy_current_program_to()

void copy_current_program_to ( uint8_t  target_program)

Copies the current program to the specified position in memory.

Irreversibly overwrites the target program.

Parameters
target_programTarget program number [0..119].

◆ enter_program()

void enter_program ( uint8_t  number)

Loads and executes the specified program.

Reads the new program data from EEPROM, updates the internal state and calls the registered callback function, which executes the program. If the specified program number is the same as the stored current program number, this function does nothing.

Parameters
numberProgram number [0..119].
See also
init_program_module

◆ export_bank()

char* export_bank ( const uint8_t  number)

Exports a program bank.

Reads the data from EEPROM and converts it to a string of hexadecimal digits.

Parameters
numberthe number of the program bank to export
Returns
the programs stored in EEPROM as a hex-string

◆ import_bank()

bool import_bank ( const uint8_t  number,
const char *  data 
)

Imports and stores a program bank given as a hex-string.

Overwrites stored program data!

Parameters
numberthe number of the program bank to import [0..11]
datathe program bank to store as a string of hexadecimal digits
Returns
true if sanity checks passed

◆ init_program_module()

void init_program_module ( uint32_t  program_initializer,
void(*)(uint32_t program_data execute_program_callback 
)

Initializes the program storage module.

Stores the specified program data initialization word, used in the wipe functions and registers the provided callback function, which is executed whenever the current program data word is updated either by wiping the program or loading a new one.

Parameters
program_initializerOn wiping, programs are initialized with this value.
execute_program_callbackCallback for program execution. This procedure is called with the program configuration data that was read from memory as the parameter program_data.
See also
wipe_current_program
enter_program

◆ read_program_data()

uint32_t read_program_data ( uint8_t  number)

Reads a program data word from the specified position in memory.

Parameters
numberProgram number [0..119].

◆ update_current_program()

void update_current_program ( uint32_t  program_data)

Updates and stores the current program.

Parameters
program_datathe new configuration

◆ wipe_current_bank()

void wipe_current_bank ( void  )

Reinitializes all programs in the current bank.

See also
wipe_current_program

◆ wipe_current_program()

void wipe_current_program ( void  )

Reinitializes the currently loaded program.

Updates the internal program data word with the initializer, stores it and executes the initialized program.

◆ write_program()

void write_program ( uint8_t  number,
uint32_t  data 
)

Stores a given program data word in the specified position in memory.

Parameters
numberProgram number [0..119].
dataProgram data as 32-bit dword.

Variable Documentation

◆ current_program

struct program current_program
static

Current program.

◆ EEMEM

uint32_t program_data_storage [ 120 ] EEMEM
static

EEPROM program storage.

◆ execute_program

void(* execute_program) (uint32_t)
static

Callback for program execution.

◆ program_initializer

uint32_t program_initializer
static

Initialization value for empty programs.