/*
 * Author: klaute -Kai Lauterbach - @kailauterbach - me@klaute.de
 * Date: 08/2016
 * License: GPLv3
 */

#ifndef __COMMAND_CONFIG_H__
#define __COMMAND_CONFIG_H__

/*****************************************************************************/

#include <stdio.h>
#include <string.h>

#include <avr/wdt.h>
#include <avr/eeprom.h>

#include "globals.h"

#include "uart/uart.h"

/*****************************************************************************/


void cc_setBaudrate(void);
void cc_getBaudrate(void);
void cc_setMuxLine(void);
void cc_getMuxLine(void);
void cc_startBootloader(void);

/*****************************************************************************/

#define CC_CMD_SET_BAUDRATE   0x0A
#define CC_CMD_GET_BAUDRATE   0x14
#define CC_CMD_SET_MUX_LINE   0x1E
#define CC_CMD_GET_MUX_LINE   0x28
#define CC_CMD_START_BTLDR    0x32

/*****************************************************************************/

#define CC_CMD_SET_BAUDRATE_FUNC   &cc_setBaudrate
#define CC_CMD_GET_BAUDRATE_FUNC   &cc_getBaudrate
#define CC_CMD_SET_MUX_LINE_FUNC   &cc_setMuxLine
#define CC_CMD_GET_MUX_LINE_FUNC   &cc_getMuxLine
#define CC_CMD_START_BTLDR_FUNC    &cc_startBootloader

/*****************************************************************************/

#define CC_CMD_SET_BAUDRATE_DATA_TO_READ  4 // set baudrate
#define CC_CMD_GET_BAUDRATE_DATA_TO_READ  0 // get baudrate
#define CC_CMD_SET_MUX_LINE_DATA_TO_READ  1 // set mux line
#define CC_CMD_GET_MUX_LINE_DATA_TO_READ  0 // get mux line
#define CC_CMD_START_BTLDR_DATA_TO_READ   0 // start bootloader

/*****************************************************************************/

#define CC_READ_DATA_MAX 64

/*****************************************************************************/

uint8_t cc_commands[] = { 
    CC_CMD_SET_BAUDRATE,
    CC_CMD_GET_BAUDRATE,
    CC_CMD_SET_MUX_LINE,
    CC_CMD_GET_MUX_LINE,
    CC_CMD_START_BTLDR,
  };

void (*cc_cmd_functions[])() = {
    CC_CMD_SET_BAUDRATE_FUNC,
    CC_CMD_GET_BAUDRATE_FUNC,
    CC_CMD_SET_MUX_LINE_FUNC,
    CC_CMD_GET_MUX_LINE_FUNC,
    CC_CMD_START_BTLDR_FUNC,
  };

uint8_t cc_cmd_data_to_read[] = {
     CC_CMD_SET_BAUDRATE_DATA_TO_READ,
     CC_CMD_GET_BAUDRATE_DATA_TO_READ,
     CC_CMD_SET_MUX_LINE_DATA_TO_READ,
     CC_CMD_GET_MUX_LINE_DATA_TO_READ,
     CC_CMD_START_BTLDR_DATA_TO_READ,
  };

uint8_t cc_read_data[CC_READ_DATA_MAX];

/*****************************************************************************/

#endif

