/******************************************************************************
 * The MIT License
 *
 * Copyright (c) 2011 LeafLabs, LLC.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *****************************************************************************/

/**
 * @file   blacksasi_f411m.h
 * @author Per Mårtensson
 * @brief  Private include file
 */

#ifndef _BOARD_BLACKSASI_F411M_H_
#define _BOARD_BLACKSASI_F411M_H_

#define Port2Pin(port, bit) ((port-'A')*16+bit)

#define CLOCK_SPEED_MHZ  100

/*****************************************************************************/
// Board pin definitions
#define BOARD_USB_DM_PIN		PA11
#define BOARD_USB_DP_PIN		PA12

#define BOARD_LED_PIN           PA4
#define BOARD_LED1_PIN          PA4
#define BOARD_LED2_PIN          PA5
#define BOARD_LED3_PIN          PA6
#define BOARD_EXT_LED           PA0

#define BOARD_SWITCH1_PIN       PC4
#define BOARD_SWITCH2_PIN       PC5
#define BOARD_SWITCH3_PIN       PC10
#define BOARD_SWITCH4_PIN       PC11
#define BOARD_REV_PIN0          PA7
#define BOARD_REV_PIN1          PA8
#define BOARD_REV_PIN2          PA9
#define BOARD_SDCARD_INSERT     PB0

#define BOARD_NR_USARTS         6
#define BOARD_USART1_TX_PIN     PA9
#define BOARD_USART1_RX_PIN     PA10
#define BOARD_USART2_TX_PIN     PA2
#define BOARD_USART2_RX_PIN     PA3
#define BOARD_USART3_TX_PIN     PB10
#define BOARD_USART3_RX_PIN     PB11
#define BOARD_UART4_TX_PIN      PA0
#define BOARD_UART4_RX_PIN      PA1
#define BOARD_UART5_TX_PIN      PC12
#define BOARD_UART5_RX_PIN      PD2
#define BOARD_USART6_TX_PIN     PC6
#define BOARD_USART6_RX_PIN     PC7

#define BOARD_NR_I2C            0

#define BOARD_NR_SPI            3
#define BOARD_SPI1_NSS_PIN      PB1
#define BOARD_SPI1_SCK_PIN      PB3
#define BOARD_SPI1_MISO_PIN     PB4
#define BOARD_SPI1_MOSI_PIN     PB5
#define BOARD_SPI1A_NSS_PIN     PB1
#define BOARD_SPI1A_SCK_PIN     PB3
#define BOARD_SPI1A_MISO_PIN    PB4
#define BOARD_SPI1A_MOSI_PIN    PB5


#define BOARD_SPI2_NSS_PIN      PB12
#define BOARD_SPI2_SCK_PIN      PB13
#define BOARD_SPI2_MISO_PIN     PB14
#define BOARD_SPI2_MOSI_PIN     PB15
#define BOARD_SPI2A_NSS_PIN     PB9
#define BOARD_SPI2A_SCK_PIN     PB10
#define BOARD_SPI2A_MISO_PIN    PC2
#define BOARD_SPI2A_MOSI_PIN    PC3
#define BOARD_SPI3_NSS_PIN      PA15
#define BOARD_SPI3_SCK_PIN      PD12
#define BOARD_SPI3_MISO_PIN     PD12
#define BOARD_SPI3_MOSI_PIN     PD12

#define BOARD_SDIO_D0           PB4
#define BOARD_SDIO_D1           PB10
#define BOARD_SDIO_D2           PB13
#define BOARD_SDIO_D3           PB1
#define BOARD_SDIO_CLK          PB3
#define BOARD_SDIO_CMD          PB5

#define BOARD_SCSI_DBX          PE0
#define BOARD_SCSI_MSG          PE2
#define BOARD_SCSI_RST          PA15
#define BOARD_SCSI_SEL          PE3
#define BOARD_SCSI_CD           PE4
#define BOARD_SCSI_REQ          PE5
#define BOARD_SCSI_IO           PE6
#define BOARD_SCSI_DAT0         PD0
#define BOARD_SCSI_DAT1         PD1
#define BOARD_SCSI_DAT2         PD2
#define BOARD_SCSI_DAT3         PD3
#define BOARD_SCSI_DAT4         PD4
#define BOARD_SCSI_DAT5         PD5
#define BOARD_SCSI_DAT6         PD6
#define BOARD_SCSI_DAT7         PD7
#define BOARD_SCSI_DBP          PD8
#define BOARD_SCSI_BSY          PB6
#define BOARD_SCSI_ACK          PB7
#define BOARD_TRANS_OE          PB12
#define BOARD_SCSI_ATN          PB14
#define BOARD_SCSI_DTD          PC0                 // Needs to be on the same port as BOARD_SCSI_IND
#define BOARD_SCSI_IND          PC1                 // Needs to be on the same port as BOARD_SCSI_DTD
#define BOARD_SCSI_TAD          PC2
#define BOARD_SCSI_TERM_HIGH    PB8                 // Needs to be on the same port as BOARD_SCSI_TERM_LOW
#define BOARD_SCSI_TERM_LOW     PB9                 // Needs to be on the same port as BOARD_SCSI_TERM_HIGH
#define BOARD_SCSI_TERM_POWER   PC8

#define BOARD_NR_PWM_PINS       22
#define BOARD_NR_ADC_PINS       16
#define BOARD_NR_USED_PINS      22
#define BOARD_JTMS_SWDIO_PIN    PA13 
#define BOARD_JTCK_SWCLK_PIN    PA14 


/*****************************************************************************/
// Pins reserved for the on-board hardware
#define USB_DM_PIN		BOARD_USB_DM_PIN // PA11
#define USB_DP_PIN		BOARD_USB_DP_PIN // PA12
/*



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

enum {
PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7,PA8,PA9,PA10,PA11,PA12,PA13,PA14,PA15,
PB0,PB1,PB2,PB3,PB4,PB5,PB6,PB7,PB8,PB9,PB10,PB11,PB12,PB13,PB14,PB15,
PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PC8,PC9,PC10,PC11,PC12,PC13,PC14,PC15,
PD0,PD1,PD2,PD3,PD4,PD5,PD6,PD7,PD8,PD9,PD10,PD11,PD12,PD13,PD14,PD15,
PE0,PE1,PE2,PE3,PE4,PE5,PE6,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15,

BOARD_NR_GPIO_PINS
};

#endif
