/*******************************************************************************
* Project:      Amped'RF Bluetooth
* File name:    GKI_io.c
* Description:  I/O abstraction layer
*
* Copyright (c) 2012 Amped'RF Inc., AR Technology  All rights reserved.
*******************************************************************************/
#include "Common.h"
#ifdef KEIL_ARM_CM3

tRamStart *pRamStart;
const uint32 RamSizeK = 64;

#if defined(ABSTRACT_IO)
#undef GPIO_Config
#undef GPIO_ReadInputDataBit
#undef GPIO_WriteBit
#undef GPIO_ReadBit

void  GPIO_Config(GPIO_TypeDef* GPIOx, uint16 bits, GPIOMode_TypeDef mode);
u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal);
void GPIO_BitWrite(GPIO_TypeDef* GPIOx, uint16 pin, uint8 val);

u16 IO_INVALID          = _IO_INVALID;
u16 IO_HCI_TX           = _IO_HCI_TX;
u16 IO_HCI_RX	        = _IO_HCI_RX;	
u16 IO_HCI_CTS          = _IO_HCI_CTS;
u16 IO_HCI_RTS          = _IO_HCI_RTS;
u16 IO_MAIN_TX	        = _IO_MAIN_TX;	
u16 IO_MAIN_RX	        = _IO_MAIN_RX;	
u16 IO_MAIN_CTS         = _IO_MAIN_CTS;
u16 IO_MAIN_RTS         = _IO_MAIN_RTS;
u16 IO_HCI_LPCLK        = _IO_HCI_LPCLK;
u16 IO_HCI_BT_RESET     = _IO_HCI_BT_RESET;
u16 IO_HCI_BT_WAKE      = _IO_HCI_BT_WAKE;
u16 IO_HCI_HOST_WAKE    = _IO_HCI_HOST_WAKE;
u16 IO_JTDI             = _IO_JTDI;
u16 IO_LPOCLK_EN        = _IO_LPOCLK_EN;
u16 IO_PA_BIAS          = _IO_PA_BIAS;
u16 IO_HCI_BT_CLK       = _IO_HCI_BT_CLK;
u16 IO_I2C_SCL          = _IO_I2C_SCL;
u16 IO_I2C_SDA          = _IO_I2C_SDA;

#if defined(BT24)
u16 IO_HCI_BT_PWR_ON    = _IO_HCI_BT_PWR_ON;
#endif
#endif






#if defined(IAR_ARM_CM3)
static void * _Port[3] = {
    ((void *) GPIOA_BASE),
    ((void *) GPIOB_BASE),
    ((void *) GPIOC_BASE)
};
#endif

#define _SOURCE(x)  (x>>4)
#define _BASE(x)    _Port[x>>4]
#define _PIN(x)     (x&0x0F)
#define _MASK(x)    (1<<_PIN(x))

#include <stdio.h>
void SerialPutString(char *);


//------------------------------------------------
// Configure GPIO -- replaces GPIO_Config()
//------------------------------------------------
void  GKI_io_Config(u16 io, u16 mode)
{
#if defined(IAR_ARM_CM3)
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.GPIO_Pin   = _MASK(io);
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStruct.GPIO_Mode  = mode;
    GPIO_Init(_BASE(io), &GPIO_InitStruct);

#elif defined(KEIL_ARM_CM3)
    // Put your code here
#endif
}


//------------------------------------------------
// Configure GPIO -- replaces GPIO_Config()
//------------------------------------------------
void  GKI_io_ConfigFast(u16 io, u16 mode)
{
#if defined(IAR_ARM_CM3)
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.GPIO_Pin   = _MASK(io);
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_InitStruct.GPIO_Mode  = mode;
    GPIO_Init(_BASE(io), &GPIO_InitStruct);

#elif defined(KEIL_ARM_CM3)
    // Put your code here
#endif
}


//------------------------------------------------
// Write GPIO bit -- replaces GPIO_BitWrite()
//------------------------------------------------
void  GKI_io_WriteBit(u16 io, u8 val)
{
#if defined(IAR_ARM_CM3)
    GPIO_WriteBit(_BASE(io), _MASK(io), val);

#elif defined(KEIL_ARM_CM3)
    // Put your code here
#endif
}


//------------------------------------------------
// Read GPIO bit -- replaces GPIO_BitRead()
//------------------------------------------------
bool  GKI_io_ReadBit(u16 io)
{
#if defined(IAR_ARM_CM3)
    return GPIO_ReadInputDataBit(_BASE(io), _MASK(io));

#elif defined(KEIL_ARM_CM3)
    // Put your code here
    return 0;
#endif
}


#endif // KEIL_ARM_CM3
//--------------------------------------------------------------
//