Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCD and control buttons #2

Open
wants to merge 10 commits into
base: ver-with-vario-and-sd
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include "semphr.h"
#include "queue.h"

#include "stm32f10x_gpio.h"

#include <string.h>

#include "iopins.h"

#include "ctrl.h"

#include "uart1.h" // UART1 (console)
Expand All @@ -15,14 +19,20 @@
#include "main.h"
#include "gps.h"

#ifdef WITH_LCD5110
#include "lcd5110.h"
#endif

#ifdef WITH_SDCARD
#include "diskio.h"
#include "ff.h"
#endif

//------------------------------------------------------------------------------

uint32_t get_fattime(void) { return GPS_FatTime; } // for FatFS to have the correct time

// ======================================================================================
//------------------------------------------------------------------------------

static char Line[64];

Expand Down Expand Up @@ -68,14 +78,14 @@ static void ProcessCtrlC(void) // print system

static NMEA_RxMsg NMEA;

static void ReadParameters(void) // read parameters requested by the user in the NMEA sent.
static void ReadParameters() // read parameters requested by the user in the NMEA sent.
{
}

static void ProcessNMEA(void) // process a valid NMEA that got to the console
static void ProcessNMEA() // process a valid NMEA that got to the console
{ }

static void ProcessInput(void)
static void ProcessInput()
{
for( ; ; )
{ uint8_t Byte; int Err=UART1_Read(Byte); if(Err<=0) break; // get byte from console, if none: exit the loop
Expand All @@ -87,6 +97,23 @@ static void ProcessInput(void)
}
}

static void ProcessControls() // process miscellaneous controls input
{
#if defined WITH_BUTTONS && defined WITH_LCD5110
inADC8::Read();

if (inButtonUp::BtnPress())
DisplProcCtrl(button_up);

if (inButtonDown::BtnPress())
DisplProcCtrl(button_down);

if (inButtonSet::BtnPress())
DisplProcCtrl(button_set);
#endif
}


#ifdef WITH_SDLOG
static uint16_t LogDate = 0; // [days] date = UnixTime/86400
static char LogName[14] = "TRK00000.LOG"; // log file name
Expand Down Expand Up @@ -186,14 +213,20 @@ void vTaskCTRL(void* pvParameters)

NMEA.Clear();

uint8_t counter = 0;
while(1)
{ vTaskDelay(1);

ProcessInput(); // process console input
ProcessInput(); // process console & button input

#ifdef WITH_SDLOG
ProcessLog(); // process lines to written to the log file
#endif

// 16ms period is enough for controls
if ((counter & 0xF) == 0)
ProcessControls();

counter++;
}
}

23 changes: 23 additions & 0 deletions ctrl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
//------------------------------------------------------------------------------

#ifndef __CTRL_H
#define __CTRL_H

//------------------------------------------------------------------------------

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

//------------------------------------------------------------------------------

// various control commands
enum ControlCmd
{
button_up,
button_down,
button_set,
};

//------------------------------------------------------------------------------

#ifdef WITH_SDLOG
extern xQueueHandle LogQueue;
inline void LogLine(char *Line, TickType_t Wait=2) { xQueueSend(LogQueue, &Line, Wait); }
Expand All @@ -13,3 +32,7 @@ inline void LogLine(char *Line, TickType_t Wait=2) { }
extern "C"
#endif
void vTaskCTRL(void* pvParameters);


//------------------------------------------------------------------------------
#endif // __CTRL_H
16 changes: 14 additions & 2 deletions gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
#include "nmea.h"
#include "ubx.h"

#include "ogn.h"

#include "uart1.h"
#include "uart2.h"

#include "parameters.h"

#include "gps.h"
#include "ctrl.h"

#include "knob.h"

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -60,6 +59,7 @@ static uint8_t PktIdx;
static TickType_t Burst_TickCount; // [msec] TickCount when the data burst from GPS started

TickType_t PPS_TickCount; // [msec] TickCount of the most recent PPS pulse
static uint32_t GPS_TimeSinceMSG; // [msec] time since the last GPS message received
uint32_t GPS_TimeSinceLock; // [sec] time since the GPS has a lock
volatile uint8_t GPS_Sec=0; // [sec] UTC time: second
uint32_t GPS_UnixTime=0; // [sec] UTC date/time in Unix format
Expand Down Expand Up @@ -111,6 +111,16 @@ static void GPS_LockEnd(void) // called when GPS looses a

// ----------------------------------------------------------------------------

const OgnPosition& GetGPSStatus()
{
// after 10 sec rx timeout, return empty data (reseting -1 also solves GPS_TimeSinceMSG overflow)
if (GPS_TimeSinceMSG > 10*1000)
Position[(PosIdx-1)&3].Clear();

return Position[(PosIdx-1)&3];
}


static void GPS_BurstStart(void) // when GPS starts sending the data on the serial port
{ Burst_TickCount=xTaskGetTickCount(); }

Expand Down Expand Up @@ -158,6 +168,7 @@ static void GPS_BurstEnd(void) // wh

static void GPS_NMEA(void) // when GPS gets a correct NMEA sentence
{ LED_PCB_Flash(2); // Flash the LED for 2 ms
GPS_TimeSinceMSG = 0;
Position[PosIdx].ReadNMEA(NMEA); // read position elements from NMEA
if( NMEA.isGPRMC() || NMEA.isGPGGA() )
{ static char CRNL[3] = "\r\n";
Expand Down Expand Up @@ -211,6 +222,7 @@ void vTaskGPS(void* pvParameters)
if(GPS_PPS_isOn()) { if(!PPS) { PPS=1; GPS_PPS_On(); } } // monitor GPS PPS signal
else { if( PPS) { PPS=0; GPS_PPS_Off(); } }

GPS_TimeSinceMSG++;
LineIdle++; // count idle time
for( ; ; )
{ uint8_t Byte; int Err=UART2_Read(Byte); if(Err<=0) break; // get Byte from serial port
Expand Down
4 changes: 4 additions & 0 deletions gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <semphr.h>
#include <queue.h>

#include "ogn.h"

#include "uart1.h"
#include "i2c.h"

Expand All @@ -19,6 +21,8 @@ uint16_t PPS_Phase(void); // [ms]

extern xQueueHandle xQueuePacket;

const OgnPosition& GetGPSStatus();

void GPS_Configuration (void);

#ifdef __cplusplus
Expand Down
47 changes: 47 additions & 0 deletions iopins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
/*
IO pin configuration.

Copyright (C) Richard Pecl 2015

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//------------------------------------------------------------------------------

#include "stm32f10x_gpio.h"

#include "iopins.h"


//------------------------------------------------------------------------------


// Initialize configurable IO pins.
void InitPins()
{
#ifdef WITH_BUTTONS
inADC8::Init();
#endif

#ifdef WITH_LCD5110
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
outDisplRST::Init(GPIO_Mode_Out_PP, GPIO_Speed_2MHz);
outDisplCE::Init(GPIO_Mode_Out_PP, GPIO_Speed_2MHz);
outDisplDC::Init(GPIO_Mode_Out_PP, GPIO_Speed_2MHz);
outDisplDIN::Init(GPIO_Mode_Out_PP, GPIO_Speed_2MHz);
outDisplCLK::Init(GPIO_Mode_Out_PP, GPIO_Speed_2MHz);
#endif
}

//------------------------------------------------------------------------------
Loading