Commit 82a05cd2 authored by Sydney Speckle's avatar Sydney Speckle

mirgate existing codebase

parent 3cd589d5
This diff is collapsed.
#include <stdint.h>
typedef struct
{
uint16_t year;
uint8_t month;
uint8_t day;
int8_t weekday;
uint8_t hour;
uint8_t minute;
uint8_t second;
} datetime_t;
void UtcToLocalTime(datetime_t *dt, int8_t timezone, bool bTimezoneWithDaylightSaving);
void LocalTimeToUtc(datetime_t *dt, int8_t timezone, bool bTimezoneWithDaylightSaving);
\ No newline at end of file
#pragma once
#define FILE_IF_VERSION 0x20171122
typedef struct
{
uint32_t Version;
uint32_t Status;
uint32_t OwnerThreadId;
const char *Filename;
uint8_t *Buffer;
uint32_t Length;
volatile int32_t Result; // since Result might get polled, must use volatile
uint32_t CacheAddress;
uint32_t CacheSize;
uint32_t CacheFillLevel;
uint32_t OpenFlags;
uint32_t StorageStartSector;
uint32_t StorageAvailableSectors;
bool IsOpen;
const char *FilenameExtOps; // for delete, change attribute flags etc.
char *FilenameExtOps2; // for directory access
} FILEIF_Type;
typedef enum {
FILE_RESULT_OK = 0,
FILE_RESULT_DISK_ERR = -1,
FILE_RESULT_INT_ERR = -2,
FILE_RESULT_NOT_READY = -3,
FILE_RESULT_NO_FILE = -4,
FILE_RESULT_NO_PATH = -5,
FILE_RESULT_INVALID_NAME = -6,
FILE_RESULT_DENIED = -7,
FILE_RESULT_EXIST = -8,
FILE_RESULT_INVALID_OBJECT = -9,
FILE_RESULT_WRITE_PROTECTED = -10,
FILE_RESULT_INVALID_DRIVE = -11,
FILE_RESULT_NOT_ENABLED = -12,
FILE_RESULT_NO_FILESYSTEM = -13,
FILE_RESULT_MKFS_ABORTED = -14,
FILE_RESULT_TIMEOUT = -15,
FILE_RESULT_LOCKED = -16,
FILE_RESULT_NOT_ENOUGH_CORE = -17,
FILE_RESULT_TOO_MANY_OPEN_FILES = -18,
FILE_RESULT_INVALID_PARAMETER = -19
} file_result_t;
typedef const uint8_t * handle_t;
#define FILEFLAG_READ 0x1
#define FILEFLAG_WRITE 0x2
#define FILEFLAG_CREATENEW 0x4
#define FILEFLAG_CREATE 0x8
#define FILEFLAG_AUTOSYNC 0x100
typedef uint32_t file_flag_t;
namespace File
{
void Initialize(void);
void Reset(void);
int32_t Open(const char *filename, file_flag_t openflags);
int32_t Read(void *buffer, uint32_t length);
int32_t Write(const void *buffer, uint32_t length);
int32_t Close(void);
bool ListFirstFile(const char *dirname, char *namebuffer);
bool ListNextFile(char *namebuffer);
int32_t Delete(const char *filename);
int32_t Copy(const char *filenamesrc, const char *filenamedest);
handle_t LoadToCache(const char *filename);
void ClearCache(void);
int32_t GetCachedFileSize(handle_t handle);
void SaveCacheState(void);
void RestoreCacheState(void);
file_result_t GetLastResult(void);
}
/**
******************************************************************************
* @file fonts.h
* @author MCD Application Team
* @version V1.0.0
* @date 18-February-2014
* @brief Header for fonts.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FONTS_H
#define __FONTS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/** @addtogroup Utilities
* @{
*/
/** @addtogroup STM32_EVAL
* @{
*/
/** @addtogroup Common
* @{
*/
/** @addtogroup FONTS
* @{
*/
/** @defgroup FONTS_Exported_Types
* @{
*/
typedef struct _tFont
{
const uint8_t *table;
uint16_t Width;
uint16_t Height;
} sFONT;
extern const sFONT Font24;
extern const sFONT Font20;
extern const sFONT Font16;
extern const sFONT Font12;
extern const sFONT Font8;
/**
* @}
*/
/** @defgroup FONTS_Exported_Constants
* @{
*/
#define LINE(x) ((x) * (((sFONT *)BSP_LCD_GetFont())->Height))
/**
* @}
*/
/** @defgroup FONTS_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup FONTS_Exported_Functions
* @{
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __FONTS_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This diff is collapsed.
#include "graphics.h"
#include "fileiprocif.h"
#define COLOR_BUTTON_STD COLOR_LIGHTGRAY
#define COLOR_BUTTON_PRESSED COLOR_DARKGRAY
#define COLOR_BUTTON_ACTIVE COLOR_LIGHTGRAY
#define COLOR_BUTTON_LIGHT_SHADOW COLOR_BRIGHTGRAY
#define COLOR_BUTTON_DARK_SHADOW COLOR_DARKGRAY
#define COLOR_BUTTONTEXT COLOR_DARKEST
#define COLOR_BORDER COLOR_DARKGRAY
#define COLOR_TEXT COLOR_DARKEST
#define COLOR_BACKGROUND COLOR_LIGHTGRAY
#define COLOR_CONTROLS COLOR_LIGHTGRAY
#define COLOR_CTRLBACKGROUND COLOR_DARKEST
#define COLOR_FOCUS COLOR_ORANGE
#define COLOR_TRANSPARENT COLOR_BLACK
////////////////////////////////////////////////////////////////////////////////
typedef enum
{
GUI_ELEMENT_DUMMY,
GUI_ELEMENT_PUSHBTN,
GUI_ELEMENT_TOGGLEBTN,
GUI_ELEMENT_BITMAPBTN,
GUI_ELEMENT_ONOFFSWITCH,
GUI_ELEMENT_HSLIDER,
GUI_ELEMENT_VSLIDER,
GUI_ELEMENT_TEXTBOX,
GUI_ELEMENT_SELECTBOX,
GUI_ELEMENT_BTNGRID,
GUI_ELEMENT_LABEL,
GUI_ELEMENT_ANY
} gui_element_t;
typedef struct
{
uint16_t Invisible:1;
uint16_t Disabled:1;
uint16_t CenterText_h:1;
uint16_t CenterText_v:1;
uint16_t Effect3d:1;
uint16_t Border:1;
uint16_t ToggleMode:1;
uint16_t BlockFocus:1;
uint16_t HasFocus:1;
uint16_t MultiLine:1;
} gui_attributes_t;
typedef enum
{
TOUCHPANEL_ACTION_INVALID,
TOUCHPANEL_ACTION_PRESSED,
TOUCHPANEL_ACTION_RELEASED,
TOUCHPANEL_ACTION_MOVE
} touchpanel_action_t;
typedef struct
{
uint16_t x;
uint16_t y;
touchpanel_action_t action;
} touchpanel_msg_t;
class CClickableArea
{
public:
CClickableArea();
bool Draw(void);
gui_element_t m_Type;
gui_attributes_t m_Attributes;
rectangle_t m_rect;
operator uint16_t()
{
return m_Id;
}
bool operator==(const uint16_t value)
{
return m_Id == value;
}
bool operator!=(const uint16_t value)
{
return m_Id != value;
}
uint32_t GetValue(void)
{
return m_Value;
}
protected:
uint16_t m_Id;
int32_t m_Value;
};
////////////////////////////////////////////////////////////////////////////////
class CDummyArea : public CClickableArea
{
public:
CDummyArea();
};
////////////////////////////////////////////////////////////////////////////////
class CLabel : public CClickableArea
{
public:
CLabel();
void Initialize(uint16_t id, rectangle_t rect, uint8_t *text1);
void Draw(void);
void SetFont(fonthandle_t font);
protected:
uint8_t *m_pText1;
fonthandle_t m_font;
};
////////////////////////////////////////////////////////////////////////////////
class CPushButton : public CClickableArea
{
public:
CPushButton();
void Initialize(uint16_t id, rectangle_t rect, uint8_t *text1, uint8_t *text2);
void Draw(void);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
protected:
uint8_t *m_pText1;
bool m_Pressed;
};
////////////////////////////////////////////////////////////////////////////////
class CToggleButton : public CClickableArea
{
public:
CToggleButton();
void Initialize(uint16_t id, rectangle_t rect, uint8_t *text1, uint8_t *text2);
void Draw(void);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
protected:
uint8_t *m_pText1;
uint8_t *m_pText2;
bool m_Pressed;
};
////////////////////////////////////////////////////////////////////////////////
class CBitmapButton : public CClickableArea
{
public:
CBitmapButton();
void Initialize(uint16_t id, rectangle_t rect, uint8_t *filename);
void Draw(void);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
protected:
bitmaphandle_t m_Bitmap;
};
////////////////////////////////////////////////////////////////////////////////
class CButtonGrid : public CClickableArea
{
public:
CButtonGrid();
void Initialize(uint16_t id, rectangle_t rect, uint8_t *filename, uint8_t columns, uint8_t rows);
void Draw(void) ;
void Pressed(uint16_t x, uint16_t y);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
protected:
bitmaphandle_t m_Bitmap;
uint8_t m_Rows, m_Columns; // number
uint16_t m_ElementWidth,m_ElementHeight;
};
////////////////////////////////////////////////////////////////////////////////
class COnOffSwitch : public CClickableArea
{
public:
COnOffSwitch ();
void Draw(void);
void Initialize(uint16_t id, rectangle_t rect);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
protected:
};
////////////////////////////////////////////////////////////////////////////////
class CHSlider : public CClickableArea
{
public:
CHSlider();
void Draw(void);
void Initialize(uint16_t id, rectangle_t rect);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
void Move(uint16_t touchx);
};
////////////////////////////////////////////////////////////////////////////////
class CVSlider : public CClickableArea
{
public:
CVSlider();
void Draw(void);
void Initialize(uint16_t id, rectangle_t rect);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
void Move(uint16_t touchx);
};
////////////////////////////////////////////////////////////////////////////////
class CTextBox : public CClickableArea
{
public:
CTextBox();
void Draw(bool drawstd = true);
void Initialize(uint16_t id, rectangle_t rect, uint8_t *txt);
void Pressed(void);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
void Move(uint16_t touchy);
void Scroll(int16_t deltay);
uint16_t RemoveFirstLine(void);
void InsertLine(const uint8_t *text, uint32_t bufferlength);
void ScrollToEnd(void);
void SetFont(fonthandle_t font);
void SetLineSpacing(uint16_t linespacing);
void Configure(uint16_t numlines, uint16_t offsetY, uint16_t linespacing = 0);
void SetFirstLine(int16_t firstline);
uint16_t m_InitialTouchY;
protected:
uint16_t m_Totallines;
uint16_t m_LineSpacing;
uint16_t m_Textlen;
uint8_t *m_pText;
int16_t m_RemainingScrollY;
fonthandle_t m_font;
uint16_t m_NumLinesY;
uint16_t m_TextOffsetY;
int16_t m_Firstline;
};
#define GUI_SELBOXMODE_STD 0
#define GUI_SELBOXMODE_SHOWLIST 1
#define GUI_SELBOXMODE_SCROLL 2
class CSelectBox : public CTextBox
{
public:
CSelectBox();
void Initialize(uint16_t id, rectangle_t rect, uint8_t *txt);
void Released(uint16_t x, uint16_t y, bool bChangeValue = true);
void Scroll(int16_t deltay);
void Draw(void);
void ResetState(void);
bool IsListVisible(void);
uint8_t m_Mode;
private:
};
typedef struct
{
CClickableArea &CArea;
uint32_t areaid;
rectangle_t rect;
const void *ptresource1;
const void *ptresource2;
} guipage_t;
typedef enum
{
OPTIONDIALOG_BUTTONS_OK = 2, // start with value 2 so number of buttons can be
OPTIONDIALOG_BUTTONS_CANCEL = 3, // calculate by the formale: n = value / 3
OPTIONDIALOG_BUTTONS_OKCANCEL = 4,
OPTIONDIALOG_BUTTONS_YESNO = 5,
OPTIONDIALOG_BUTTONS_YESNOCANCEL = 6
}
optiondialog_buttons_t;
typedef enum
{
OPTIONDIALOG_RESULT_UNKNOWN = 0,
OPTIONDIALOG_RESULT_OK = 1,
OPTIONDIALOG_RESULT_CANCEL = 2,
OPTIONDIALOG_RESULT_YES = 3,
OPTIONDIALOG_RESULT_NO = 4
}
optiondialog_result_t;
namespace Gui
{
uint16_t DefaultHandler(os_msg_t msg, const guipage_t page[], bool bFirstPage = true);
void Redraw(const guipage_t page[], uint16_t id = 0xffff);
void Initialize(const guipage_t page[]);
touchpanel_msg_t DecodeTouchpanelMsg(os_msg_t &msg);
void RemoveFocusFromPage(const guipage_t page[]);
void SetFontForPage(const guipage_t page[], fonthandle_t font, gui_element_t guielement = GUI_ELEMENT_ANY);
void SetDefaultFont(fonthandle_t font);
optiondialog_result_t ShowOptionDialog(uint16_t id, rectangle_t &rect, const char *text, optiondialog_buttons_t optdlgbuttons, bool blockingmode = true);
}
extern CDummyArea GUI_PAGEEND;
#include <stdint.h>
#include <mtmessaging.h>
// This file includes a svc call wrapper for OS functions
// A developer of an user program should not call any of this functions directly
#if defined ( __ICCARM__ )
#pragma default_function_attributes = @ ".VMM_Section_ROM"
#endif
// GCC is used when user program is compiled; must provide the used SVC calls here:
namespace Internal
{
#if defined (__GNUC__)
__attribute__ ( ( always_inline ) ) inline os_msgqueue_t * GetMessageQueuePointer(uint32_t threadnum)
{
os_msgqueue_t * result;
asm volatile ("mov r0, %1\n"
"svc 0x00\n"
"mov %0,r0" : "=r" (result) : "r" (threadnum) : "r0");
return result;
}
__attribute__ ( ( always_inline ) ) inline void SetActiveThreadMonitor(uint32_t *pThreadSelect)
{
asm volatile ("mov r0, %0\n"
"svc 0x04\n" : : "r" (pThreadSelect) : "r0");
}
__attribute__ ( ( always_inline ) ) inline void ControlCmd(uint32_t cmd, uint32_t param)
{
asm volatile ("mov r0, %0\n"
"mov r1, %1\n"
"svc 0x05\n" : : "r" (cmd), "r" (param) : "r0","r1");
}
__attribute__ ( ( always_inline ) ) inline void Sleep(uint32_t ms)
{
asm volatile ("mov r0, %0\n"
"svc 0xe1\n" : : "r" (ms): "r0");
}
__attribute__ ( ( always_inline ) ) inline void SleepEx(uint32_t ms, uint32_t threadtorun)
{
asm volatile ("mov r0, %0\n"
"mov r1, %1\n"
"svc 0xf0\n" : : "r" (ms), "r" (threadtorun) : "r0","r1");
}
__attribute__ ( ( always_inline ) ) inline void WaitForMessage(uint32_t timeout)
{
asm volatile ("mov r0, %0\n"
"svc 0xeb\n" : : "r" (timeout): "r0");
}
__attribute__ ( ( always_inline ) ) inline uint32_t PostMessage(uint32_t threadnum, uint32_t msg, uint32_t timestamp, uint32_t tag)
{
uint32_t result;
asm volatile ("mov r0, %1\n"
"mov r1, %2\n"
"mov r2, %3\n"
"mov r3, %4\n"
"svc 0xec\n"
"mov %0,r0" : "=r" (result) : "r" (threadnum), "r" (msg), "r" (timestamp), "r" (tag) : "r0","r1","r2","r3");
return result;
}
__attribute__ ( ( always_inline ) ) inline void ConfigureScheduler(uint32_t multiplier)
{
asm volatile ("mov r0, %0\n"
"svc 0x06\n" : : "r" (multiplier): "r0");
}
__attribute__ ( ( always_inline ) ) inline void WakeupThread(uint32_t threadnum)
{
asm volatile ("mov r0, %0\n"
"svc 0xe5\n" : : "r" (threadnum): "r0");
}
__attribute__ ( ( always_inline ) ) inline void ContinueThread(uint32_t threadnum)
{
asm volatile ("mov r0, %0\n"
"svc 0xe3\n" : : "r" (threadnum): "r0");
}
__attribute__ ( ( always_inline ) ) inline uint32_t GetCurrentThreadID(void)
{
uint32_t result;
asm volatile ("svc 0x01\n"
"mov %0,r0" : "=r" (result) : : "r0");
return result;
}
__attribute__ ( ( always_inline ) ) inline void * GetIprocInterface(const char name[4], uint32_t version)
{
void * result;
asm volatile ("mov r0, %1\n"
"mov r1, %2\n"
"svc 0x02\n"
"mov %0,r0" : "=r" (result) : "r" (name) , "r" (version) : "r0","r1");
return result;
}
#endif
// IAR is used for the internal user program in user.cpp
#if defined ( __ICCARM__ )
#pragma swi_number=0x00
__swi os_msgqueue_t * GetMessageQueuePointer(uint32_t threadnum);
#pragma swi_number=0x01
__swi uint32_t GetCurrentThreadID(void);
#pragma swi_number=0x02
__swi void * GetIprocInterface(const char name[4], uint32_t version);
#pragma swi_number=0x03
__swi uint32_t RegisterIprocInterface(const char name[4], void *ptIF);
#pragma swi_number=0x04
__swi uint32_t SetActiveThreadMonitor(uint32_t *pThreadSelect);
#pragma swi_number=0x05
__swi uint32_t ControlCmd(uint32_t cmd, uint32_t param);
#pragma swi_number=0xe3
__swi void ContinueThread(uint32_t threadnum);
#pragma swi_number=0xe5
__swi void WakeupThread(uint32_t threadnum);
#pragma swi_number=0xeb
__swi void WaitForMessage(uint32_t timeout);
#pragma swi_number=0xec
__swi uint32_t PostMessage(uint32_t threadnum, uint32_t msg, uint32_t timestamp, uint32_t tag);
#pragma swi_number=0xf0
__swi uint32_t SleepEx(uint32_t ms, uint32_t threadselect);
#endif
inline uint32_t PostMsgToRealtimeTask(uint32_t msgid, uint32_t tag, msg_priority_t msgpriority = MSG_PRIORITY_HIGH)
{
return PostMessage(3, msgid | (0x80000000 * msgpriority), GETREFTIMER, tag);
}
}
#pragma once
#define IO_IF_VERSION 0x20170411
uint32_t IOGetAnalogValue(uint32_t);
typedef struct
{
uint32_t Version;
uint32_t Status;
uint32_t OwnerThreadId;
uint32_t AdcBufferAddress;
uint32_t PinChangeIrqThread;
uint32_t PinChangeNotificationMsg;
uint32_t input_portaddresses[8];
uint32_t output_portaddresses[8];
} IOIF_Type;
typedef enum
{
PINCHANGE_NOTIFY_OFF = 0,
PINCHANGE_NOTIFY_RISINGEDGE = 1,
PINCHANGE_NOTIFY_FALLINGEDGE = 2,
PINCHANGE_NOTIFY_BOTHEDGES = 3
} pinchange_notify_t;
typedef enum
{
INPUT_DIGITAL_1 = 0,
INPUT_DIGITAL_2 = 1,
INPUT_DIGITAL_3 = 2,
INPUT_DIGITAL_4 = 3,
INPUT_DIGITAL_5 = 4,
INPUT_DIGITAL_6 = 5,
INPUT_ANALOG_1 = 100,
INPUT_ANALOG_2 = 101