- Tested/debugged the display module. Now functional
- Tested the RTC - currently indicated with green LED toggle - functional Started with internal ADC driver git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@226 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file adc.c
|
||||
/// @brief Description
|
||||
// -----------------------------------------------------------------------------
|
||||
// Micro-Key bv
|
||||
// Industrieweg 28, 9804 TG Noordhorn
|
||||
// Postbus 92, 9800 AB Zuidhorn
|
||||
// The Netherlands
|
||||
// Tel: +31 594 503020
|
||||
// Fax: +31 594 505825
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @file adc.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "adc.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// NO WRITE - ADCs cannot write
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ErrorStatus ADC_construct(struct Adc* self, struct AdcParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
IODevice_construct(&self->device, read, NULL);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
@@ -27,12 +27,15 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "stm32f10x_bkp.h"
|
||||
#include "stm32f10x_gpio.h"
|
||||
#include "stm32f10x_pwr.h"
|
||||
#include "stm32f10x_it.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "spiDevice.h"
|
||||
#include "led.h"
|
||||
#include "rtc.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
#include "keypadMatrix.h"
|
||||
@@ -45,20 +48,16 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// UART1 Settings (Logger/Console)
|
||||
#define UART_LOG_TYPEDEF (USART1)
|
||||
#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)
|
||||
|
||||
// SPI3 settings (LCD / EEPROM)
|
||||
#define SPI_LCD_EEPROM_TYPEDEF (SPI3)
|
||||
#define SPI_LCD_EEPROM_Direction (SPI_Direction_2Lines_FullDuplex)
|
||||
#define SPI_LCD_EEPROM_RX_QUEUE (32)
|
||||
#define SPI_LCD_EEPROM_TX_QUEUE (32)
|
||||
@@ -81,6 +80,9 @@
|
||||
static struct Led _ledGreen;
|
||||
static struct Led _ledOrange;
|
||||
|
||||
// RTC
|
||||
static struct Rtc _rtc;
|
||||
|
||||
// USART
|
||||
static struct Uart _uart1;
|
||||
static struct UartParameters _uart1Parameters;
|
||||
@@ -106,6 +108,8 @@ static struct KeypadParameters _keypadParameters;
|
||||
struct Led* const ledGreen = &_ledGreen;
|
||||
struct Led* const ledOrange = &_ledOrange;
|
||||
|
||||
struct Rtc* const rtc = &_rtc;
|
||||
|
||||
struct Uart* const uart1 = &_uart1;
|
||||
struct UartParameters* uartLoggerParam = &_uart1Parameters;
|
||||
struct Uart* const uart3 = &_uart3;
|
||||
@@ -127,6 +131,7 @@ struct KeypadParameters* const keypadParam = &_keypadParameters;
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static ErrorStatus initClocks(void);
|
||||
static ErrorStatus initIO (void);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -139,16 +144,39 @@ ErrorStatus initPlatform(void)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
|
||||
// POWER THE PERIPHERY AND CLOCK BUSSES
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
returnValue = initClocks();
|
||||
}
|
||||
|
||||
// INITIALIZE ALL REQUIRED GPIO FOR IO OR PERIPHERAL USE
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
returnValue = initIO();
|
||||
}
|
||||
|
||||
// INITIALIZE AND CONFIGURE ALL REQUIRED IO AND PERIPHERY
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* LEDs */
|
||||
/* --------------------------------------------------------------------*/
|
||||
LED_construct(ledGreen);
|
||||
LED_construct(ledOrange);
|
||||
|
||||
// Initialize the Console UART
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* RTC */
|
||||
/* --------------------------------------------------------------------*/
|
||||
IRQ_setInterruptProperties(RTC_IRQn, 12, 12, ENABLE);
|
||||
RTC_construct(rtc);
|
||||
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* USART1 */
|
||||
/* --------------------------------------------------------------------*/
|
||||
IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE);
|
||||
uart1->USART_TypeDef = UART_LOG_TYPEDEF;
|
||||
uart1->USART_TypeDef = USART1;
|
||||
Uart_getDefaultParameters(uartLoggerParam);
|
||||
// Adjust to higher baudrate for intensive logging
|
||||
uartLoggerParam->baudrate = UART_LOG_BAUDRATE;
|
||||
@@ -156,9 +184,12 @@ ErrorStatus initPlatform(void)
|
||||
uartLoggerParam->txQueueSize = UART_LOG_TX_QUEUE;
|
||||
returnValue = Uart_construct(uart1, uartLoggerParam);
|
||||
|
||||
// // Initialize the Terminal UART
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* USART3 */
|
||||
/* --------------------------------------------------------------------*/
|
||||
// Initialize the Terminal UART
|
||||
IRQ_setInterruptProperties(USART3_IRQn, 15, 15, ENABLE);
|
||||
uart3->USART_TypeDef = UART_TER_TYPEDEF;
|
||||
uart3->USART_TypeDef = USART3;
|
||||
Uart_getDefaultParameters(uartTerminalParam);
|
||||
// Adjust to higher baudrate for intensive logging
|
||||
uartLoggerParam->baudrate = UART_TER_BAUDRATE;
|
||||
@@ -166,16 +197,22 @@ ErrorStatus initPlatform(void)
|
||||
uartLoggerParam->txQueueSize = UART_TER_TX_QUEUE;
|
||||
returnValue = Uart_construct(uart3, uartTerminalParam);
|
||||
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* SPI1 */
|
||||
/* --------------------------------------------------------------------*/
|
||||
IRQ_setInterruptProperties(SPI1_IRQn, 12, 12, ENABLE);
|
||||
spi1->initialized = false;
|
||||
spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
|
||||
spi1->SPI_TypeDef = SPI1;
|
||||
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);
|
||||
SpiDevice_construct(spiDAC, spi1, spiDACParam);
|
||||
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* SPI3 */
|
||||
/* --------------------------------------------------------------------*/
|
||||
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
|
||||
spi3->initialized = false;
|
||||
spi3->SPI_TypeDef = SPI_LCD_EEPROM_TYPEDEF;
|
||||
spi3->SPI_TypeDef = SPI3;
|
||||
// Get the SPI parameters from the NHD0420 driver. They are more critical than the parameters from the EEPROM
|
||||
NHD0420_getSpiParameters(spiDisplayParam);
|
||||
// In order to use multiple slaves on this bus (and to increase performance), some parameters are altered
|
||||
@@ -187,9 +224,12 @@ ErrorStatus initPlatform(void)
|
||||
///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);
|
||||
SpiDevice_construct(spiDisplay, spi3, spiDisplayParam);
|
||||
SpiDevice_construct(spiEEPROM, spi3, spiEEPROMParam);
|
||||
|
||||
/* --------------------------------------------------------------------*/
|
||||
/* KEYPAD COLUMNS */
|
||||
/* --------------------------------------------------------------------*/
|
||||
// Set-up the interrupts for the Keypad columns
|
||||
keypad->column[0].EXTI_InitStruct.EXTI_Line = EXTI_Line4;
|
||||
keypad->column[0].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
@@ -228,8 +268,7 @@ ErrorStatus initPlatform(void)
|
||||
}
|
||||
//#endif
|
||||
|
||||
|
||||
static ErrorStatus initIO (void)
|
||||
static ErrorStatus initClocks (void)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -239,6 +278,25 @@ static ErrorStatus initIO (void)
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_PWR, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_BKP, ENABLE);
|
||||
|
||||
// Allow access to BKP Domain
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
// Reset Backup Domain
|
||||
BKP_DeInit();
|
||||
// Enable LSE
|
||||
RCC_LSEConfig(RCC_LSE_ON);
|
||||
// Wait till LSE is ready
|
||||
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
|
||||
// Select LSE as RTC Clock Source
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
||||
// Enable RTC Clock
|
||||
RCC_RTCCLKCmd(ENABLE);
|
||||
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
|
||||
@@ -261,6 +319,13 @@ static ErrorStatus initIO (void)
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static ErrorStatus initIO (void)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
/*LED IO initialisation --------------------------------------------------*/
|
||||
// Init LED Green
|
||||
ledGreen->ledGpio.GPIO_Typedef = GPIOC;
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file rtc.c
|
||||
/// @brief Description
|
||||
// -----------------------------------------------------------------------------
|
||||
// Micro-Key bv
|
||||
// Industrieweg 28, 9804 TG Noordhorn
|
||||
// Postbus 92, 9800 AB Zuidhorn
|
||||
// The Netherlands
|
||||
// Tel: +31 594 503020
|
||||
// Fax: +31 594 505825
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @file rtc.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#include "rtc.h"
|
||||
#include "stm32f10x_rtc.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ErrorStatus RTC_construct(struct Rtc* self)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
//! Create semaphore to synchronize with RTC interrupt handler
|
||||
vSemaphoreCreateBinary(self->secondSync);
|
||||
// Take semaphore
|
||||
if (xSemaphoreTake(self->secondSync, 0) == pdFALSE)
|
||||
{
|
||||
//! An error has occurred
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
/* Wait for RTC registers synchronization */
|
||||
RTC_WaitForSynchro();
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
/* Enable the RTC Second */
|
||||
RTC_ITConfig(RTC_IT_SEC, ENABLE);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
/* Set RTC prescaler: set RTC period to 1sec */
|
||||
RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE)
|
||||
ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user