|
|
|
|
@@ -37,6 +37,7 @@
|
|
|
|
|
#include "uart.h"
|
|
|
|
|
#include "keypadMatrix.h"
|
|
|
|
|
#include "nhd0420.h"
|
|
|
|
|
#include "MAX5715.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
@@ -48,19 +49,13 @@
|
|
|
|
|
#define UART_LOG_BAUDRATE (57600)
|
|
|
|
|
#define UART_LOG_TX_QUEUE (256)
|
|
|
|
|
|
|
|
|
|
// UART3 Settings (Developer terminal)
|
|
|
|
|
#define UART_TER_TYPEDEF (USART3)
|
|
|
|
|
#define UART_TER_BAUDRATE (115200)
|
|
|
|
|
#define UART_TER_TX_QUEUE (512)
|
|
|
|
|
|
|
|
|
|
// SPI1 settings
|
|
|
|
|
#define SPI_DAC_TYPEDEF (SPI1)
|
|
|
|
|
#define SPI_DAC_Direction (SPI_Direction_2Lines_FullDuplex)
|
|
|
|
|
#define SPI_DAC_Mode (SPI_Mode_Master)
|
|
|
|
|
#define SPI_DAC_DataSize (SPI_DataSize_8b)
|
|
|
|
|
#define SPI_DAC_CPOL (SPI_CPOL_High)
|
|
|
|
|
#define SPI_DAC_CPHA (SPI_CPHA_2Edge)
|
|
|
|
|
#define SPI_DAC_NSS (SPI_NSS_Hard)
|
|
|
|
|
#define SPI_DAC_BaudRatePrescaler (SPI_BaudRatePrescaler_128)
|
|
|
|
|
#define SPI_DAC_FirstBit (SPI_FirstBit_MSB)
|
|
|
|
|
#define SPI_DAC_CRCPolynomial (7)
|
|
|
|
|
#define SPI_DAC_RX_QUEUE (32)
|
|
|
|
|
#define SPI_DAC_TX_QUEUE (32)
|
|
|
|
|
|
|
|
|
|
// SPI3 settings (LCD / EEPROM)
|
|
|
|
|
#define SPI_LCD_EEPROM_TYPEDEF (SPI3)
|
|
|
|
|
@@ -89,10 +84,13 @@ static struct Led _ledOrange;
|
|
|
|
|
// USART
|
|
|
|
|
static struct Uart _uart1;
|
|
|
|
|
static struct UartParameters _uart1Parameters;
|
|
|
|
|
static struct Uart _uart3;
|
|
|
|
|
static struct UartParameters _uart3Parameters;
|
|
|
|
|
|
|
|
|
|
// SPI
|
|
|
|
|
static struct Spi _spi1;
|
|
|
|
|
static struct SpiDevice _spiDAC;
|
|
|
|
|
static struct SpiParameters _spi1DACParameters;
|
|
|
|
|
static struct Spi _spi3;
|
|
|
|
|
static struct SpiParameters _spi3DisplayParameters;
|
|
|
|
|
static struct SpiParameters _spi3EEPROMParameters;
|
|
|
|
|
@@ -110,10 +108,13 @@ struct Led* const ledOrange = &_ledOrange;
|
|
|
|
|
|
|
|
|
|
struct Uart* const uart1 = &_uart1;
|
|
|
|
|
struct UartParameters* uartLoggerParam = &_uart1Parameters;
|
|
|
|
|
struct Uart* const uart3 = &_uart3;
|
|
|
|
|
struct UartParameters* uartTerminalParam = &_uart3Parameters;
|
|
|
|
|
|
|
|
|
|
struct Spi* const spi1 = &_spi1;
|
|
|
|
|
struct Spi* const spi3 = &_spi3;
|
|
|
|
|
struct SpiDevice* const spiDAC = &_spiDAC;
|
|
|
|
|
struct SpiParameters* const spiDACParam = &_spi1DACParameters;
|
|
|
|
|
struct SpiDevice* const spiDisplay = &_spiDisplay;
|
|
|
|
|
struct SpiParameters* const spiDisplayParam = &_spi3DisplayParameters;
|
|
|
|
|
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
|
|
|
|
|
@@ -155,11 +156,22 @@ ErrorStatus initPlatform(void)
|
|
|
|
|
uartLoggerParam->txQueueSize = UART_LOG_TX_QUEUE;
|
|
|
|
|
returnValue = Uart_construct(uart1, uartLoggerParam);
|
|
|
|
|
|
|
|
|
|
// IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
|
|
|
|
|
// spi1->initialized = false;
|
|
|
|
|
// spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
|
|
|
|
|
// SPI_getDefaultParameters(&_spi1Parameters);
|
|
|
|
|
// SPI_construct(spi1, &_spi1Parameters);
|
|
|
|
|
// // Initialize the Terminal UART
|
|
|
|
|
IRQ_setInterruptProperties(USART3_IRQn, 15, 15, ENABLE);
|
|
|
|
|
uart3->USART_TypeDef = UART_TER_TYPEDEF;
|
|
|
|
|
Uart_getDefaultParameters(uartTerminalParam);
|
|
|
|
|
// Adjust to higher baudrate for intensive logging
|
|
|
|
|
uartLoggerParam->baudrate = UART_TER_BAUDRATE;
|
|
|
|
|
// Adjust the TX queue size for intensive logging
|
|
|
|
|
uartLoggerParam->txQueueSize = UART_TER_TX_QUEUE;
|
|
|
|
|
returnValue = Uart_construct(uart3, uartTerminalParam);
|
|
|
|
|
|
|
|
|
|
IRQ_setInterruptProperties(SPI1_IRQn, 12, 12, ENABLE);
|
|
|
|
|
spi1->initialized = false;
|
|
|
|
|
spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
|
|
|
|
|
MAX5715_getSpiParameters(spiDACParam);
|
|
|
|
|
GPIO_SetBits(spiDAC->SPI_CE.GPIO_Typedef, spiDAC->SPI_CE.GPIO_InitStruct.GPIO_Pin);
|
|
|
|
|
SpiDevice_construct(spiDAC, spi1, spiDACParam, spiDAC->SPI_CE);
|
|
|
|
|
|
|
|
|
|
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
|
|
|
|
|
spi3->initialized = false;
|
|
|
|
|
@@ -174,6 +186,7 @@ ErrorStatus initPlatform(void)
|
|
|
|
|
spiDisplayParam->txQueueSize = SPI_LCD_EEPROM_TX_QUEUE;
|
|
|
|
|
///TODO SPI_CE should be initialized individually
|
|
|
|
|
GPIO_SetBits(spiDisplay->SPI_CE.GPIO_Typedef, spiDisplay->SPI_CE.GPIO_InitStruct.GPIO_Pin);
|
|
|
|
|
GPIO_SetBits(spiEEPROM->SPI_CE.GPIO_Typedef, spiEEPROM->SPI_CE.GPIO_InitStruct.GPIO_Pin);
|
|
|
|
|
SpiDevice_construct(spiDisplay, spi3, spiDisplayParam, spiDisplay->SPI_CE);
|
|
|
|
|
SpiDevice_construct(spiEEPROM, spi3, spiEEPROMParam, spiEEPROM->SPI_CE);
|
|
|
|
|
|
|
|
|
|
@@ -223,6 +236,9 @@ static ErrorStatus initIO (void)
|
|
|
|
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
|
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
|
|
|
|
|
|
|
|
|
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
|
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
|
|
|
|
|
|
|
|
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
|
|
|
|
|
|
|
|
|
@@ -233,9 +249,9 @@ static ErrorStatus initIO (void)
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! Enable USART clock
|
|
|
|
|
|
|
|
|
|
/* Peripheral bus power --------------------------------------------------*/
|
|
|
|
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
|
|
|
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
|
|
|
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);
|
|
|
|
|
@@ -277,6 +293,22 @@ static ErrorStatus initIO (void)
|
|
|
|
|
// Apply pin-remapping for UART1 I/Os (alternative I/Os usage)
|
|
|
|
|
GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
|
|
|
|
|
|
|
|
|
|
/* USART3 initialisation -------------------------------------------------*/
|
|
|
|
|
// Init TX line
|
|
|
|
|
uart3->USART_TX.GPIO_Typedef = GPIOB;
|
|
|
|
|
uart3->USART_TX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
|
|
|
uart3->USART_TX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
|
|
|
|
|
uart3->USART_TX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(uart3->USART_TX.GPIO_Typedef, &uart3->USART_TX.GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
// Init RX line
|
|
|
|
|
uart3->USART_RX.GPIO_Typedef = GPIOB;
|
|
|
|
|
uart3->USART_RX.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
|
|
|
uart3->USART_RX.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
|
|
|
|
|
uart3->USART_RX.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(uart3->USART_RX.GPIO_Typedef, &uart3->USART_RX.GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* SPI initialisation ----------------------------------------------------*/
|
|
|
|
|
// SPI1 CLK
|
|
|
|
|
_spi1.SPI_CLK.GPIO_Typedef = GPIOA;
|
|
|
|
|
@@ -298,11 +330,12 @@ static ErrorStatus initIO (void)
|
|
|
|
|
GPIO_Init(_spi1.SPI_MOSI.GPIO_Typedef, &_spi1.SPI_MOSI.GPIO_InitStruct);
|
|
|
|
|
// SPI1 CE
|
|
|
|
|
_spiDAC.SPI_CE.GPIO_Typedef = GPIOA;
|
|
|
|
|
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
|
|
|
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
|
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
|
|
|
|
|
_spiDAC.SPI_CE.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_Init(_spiDAC.SPI_CE.GPIO_Typedef, &_spiDAC.SPI_CE.GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spiDAC->spi = &_spi1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|