Библа для отрисовки всякого на диод
есть 2 экзампла для i2c oled 128x32 - плеер с иконками - вывод графиками синус и ЭКГ (не встроена пока в gfx библиотеку)
This commit is contained in:
269
Core/Example/general_gpio.c
Normal file
269
Core/Example/general_gpio.c
Normal file
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file general_gpio.c
|
||||
* @brief Модуль для инициализации портов.
|
||||
**************************************************************************
|
||||
@verbatim
|
||||
//-------------------Функции-------------------//
|
||||
Functions: users
|
||||
- GPIO_Clock_Enable Инициализация тактирования порта
|
||||
@endverbatim
|
||||
***************************************************************************/
|
||||
#include "general_gpio.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//------------------------GPIO INIT FUNCTIONS------------------------
|
||||
|
||||
HAL_StatusTypeDef GPIO_Clock_Enable(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
// choose port for enable clock
|
||||
if (GPIOx==GPIOA)
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
else if (GPIOx==GPIOB)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
else if (GPIOx==GPIOC)
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
else if (GPIOx==GPIOD)
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
else if (GPIOx==GPIOE)
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
else
|
||||
status = HAL_ERROR;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//------------------------GPIO INIT FUNCTIONS------------------------
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//------------------------GPIO LED FUNCTIONS-------------------------
|
||||
|
||||
/**
|
||||
* @brief Инициализировать светодиод (структуру светодиода)
|
||||
* @param led - указатель на структуру светодиода
|
||||
* @param GPIOx - указатель на структуру порта для светодиода
|
||||
* @param GPIO_PIN_X - пин для светодиода
|
||||
* @param LED_On_State - состояния пина, при котором светодиод будет включен
|
||||
*/
|
||||
HAL_StatusTypeDef GPIO_LED_Init(GPIO_LEDTypeDef *led, GPIO_TypeDef *GPIOx, uint32_t GPIO_PIN_X, uint8_t LED_ActiveLevel)
|
||||
{
|
||||
if(check_null_ptr_2(led, GPIOx))
|
||||
return HAL_ERROR;
|
||||
|
||||
led->LED_Port = GPIOx;
|
||||
led->LED_Pin = GPIO_PIN_X;
|
||||
led->LED_ActiveLvl = LED_ActiveLevel;
|
||||
|
||||
GPIO_LED_Off(led);
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Включить светодиод
|
||||
* @param led - указатель на структуру светодиода
|
||||
*/
|
||||
HAL_StatusTypeDef GPIO_LED_On(GPIO_LEDTypeDef *led)
|
||||
{
|
||||
if(check_null_ptr_1(led))
|
||||
return HAL_ERROR;
|
||||
|
||||
led->state = LED_IS_ON;
|
||||
if(led->LED_Port != NULL)
|
||||
HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, led->LED_ActiveLvl);
|
||||
else
|
||||
return HAL_ERROR;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
/**
|
||||
* @brief Выключить светодиод
|
||||
* @param led - указатель на структуру светодиода
|
||||
*/
|
||||
HAL_StatusTypeDef GPIO_LED_Off(GPIO_LEDTypeDef *led)
|
||||
{
|
||||
if(check_null_ptr_1(led))
|
||||
return HAL_ERROR;
|
||||
|
||||
led->state = LED_IS_OFF;
|
||||
if(led->LED_Port != NULL)
|
||||
HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, !led->LED_ActiveLvl);
|
||||
else
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Активировать моргание светодиодом
|
||||
* @param led - указатель на структуру светодиода
|
||||
* @details Функция ставит режим моргания, который после управляется в @ref GPIO_LED_Dynamic_Handle
|
||||
*/
|
||||
HAL_StatusTypeDef GPIO_LED_Blink_Start(GPIO_LEDTypeDef *led, uint32_t period)
|
||||
{
|
||||
if(check_null_ptr_2(led, led->LED_Port))
|
||||
return HAL_ERROR;
|
||||
|
||||
led->state = LED_IS_BLINKING;
|
||||
led->LED_Period = period;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Активировать моргание светодиодом
|
||||
* @param led - указатель на структуру светодиода
|
||||
* @details Функция ставит режим моргания, который после управляется в @ref GPIO_LED_Dynamic_Handle
|
||||
*/
|
||||
HAL_StatusTypeDef GPIO_LED_Fading_Start(GPIO_LEDTypeDef *led, uint32_t period)
|
||||
{
|
||||
if(check_null_ptr_2(led, led->LED_Port))
|
||||
return HAL_ERROR;
|
||||
|
||||
led->state = LED_IS_FADING;
|
||||
led->LED_Period = period;
|
||||
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
//uint8_t LED_PWM_FADING_DUTYS[LED_PWM_TICKS] = {0 1 2 3 4 5 6 7 8 9 10 11 12 }
|
||||
/**
|
||||
* @brief Управление динамическими режимами свечения светодиода
|
||||
* @param led - указатель на структуру светодиода
|
||||
* @details Функция моргает/плавно моргает светодиодом в неблокирующем режиме
|
||||
* Т.е. функцию надо вызывать постоянно, чтобы она мониторила тики
|
||||
* и в нужный момент переключала светодиод
|
||||
*/
|
||||
void GPIO_LED_Dynamic_Handle(GPIO_LEDTypeDef *led)
|
||||
{
|
||||
if(check_null_ptr_2(led, led->LED_Port))
|
||||
return;
|
||||
|
||||
/* Режим моргания светодиода */
|
||||
if(led->state == LED_IS_BLINKING)
|
||||
{
|
||||
uint32_t tickcurrent = HAL_GetTick();
|
||||
/* Ожидание истечения периода моргания */
|
||||
if((tickcurrent - led->tickprev) > led->LED_Period)
|
||||
{
|
||||
/* Моргание */
|
||||
HAL_GPIO_TogglePin(led->LED_Port, led->LED_Pin);
|
||||
|
||||
led->tickprev = tickcurrent;
|
||||
}
|
||||
}
|
||||
/* Режим плавного моргания светодиода */
|
||||
else if(led->state == LED_IS_FADING)
|
||||
{
|
||||
static unsigned direction = 0;
|
||||
static int duty = 0;
|
||||
uint32_t tickcurrent = HAL_GetTick();
|
||||
/* Ожидание момента изменения яркости */
|
||||
/* Период ШИМ 20 мс, поэтому менять яроксть надо 40 раз за период (туда обратно) */
|
||||
if((tickcurrent - led->tickprev) > led->LED_Period/(LED_PWM_TICKS*2))
|
||||
{
|
||||
/* Формирование разтухания */
|
||||
if(direction == 0)
|
||||
{
|
||||
if(++duty >= LED_PWM_TICKS)
|
||||
{
|
||||
direction = 1;
|
||||
duty = LED_PWM_TICKS;
|
||||
}
|
||||
}
|
||||
/* Формирование затухания */
|
||||
else
|
||||
{
|
||||
if(--duty <= 0)
|
||||
{
|
||||
direction = 0;
|
||||
duty = 0;
|
||||
}
|
||||
}
|
||||
led->tickprev = tickcurrent;
|
||||
}
|
||||
/* Формирование ШИМ для изменения яркости */
|
||||
int duty_crt = (duty*duty/LED_PWM_TICKS);
|
||||
if(tickcurrent%LED_PWM_TICKS < duty_crt)
|
||||
{
|
||||
HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, led->LED_ActiveLvl);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(led->LED_Port, led->LED_Pin, !led->LED_ActiveLvl);
|
||||
}
|
||||
}
|
||||
}
|
||||
//------------------------GPIO LED FUNCTIONS-------------------------
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//------------------------GPIO SW FUNCTIONS-------------------------
|
||||
|
||||
/**
|
||||
* @brief Инициализировать кнопку (структуру кнопки)
|
||||
* @param sw - указатель на структуру кнопки
|
||||
* @param GPIOx - указатель на структуру порта для кнопки
|
||||
* @param GPIO_PIN_X - пин для кнопки
|
||||
* @param SW_ActiveLevel - состояния пина, когда кнопка нажата
|
||||
*/
|
||||
HAL_StatusTypeDef GPIO_Switch_Init(GPIO_SwitchTypeDef *sw, GPIO_TypeDef *GPIOx, uint32_t GPIO_PIN_X, uint8_t SW_ActiveLevel)
|
||||
{
|
||||
if(check_null_ptr_2(sw, GPIOx))
|
||||
return HAL_ERROR;
|
||||
|
||||
sw->Sw_Port = GPIOx;
|
||||
sw->Sw_Pin = GPIO_PIN_X;
|
||||
sw->Sw_ActiveLvl = SW_ActiveLevel;
|
||||
|
||||
if(sw->Sw_FilterDelay == 0)
|
||||
sw->Sw_FilterDelay = 50;
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Считать состоянии кнопки
|
||||
* @param sw - указатель на структуру кнопки
|
||||
* @return 1 - если кнопка нажата, 0 - если отжата
|
||||
* @details Функция включает в себя неблокирующую проверку на дребезг
|
||||
* Т.е. функцию надо вызывать постоянно, чтобы она мониторила состояние кнопки
|
||||
*/
|
||||
uint8_t GPIO_Read_Swich(GPIO_SwitchTypeDef *sw)
|
||||
{
|
||||
if(check_null_ptr_1(sw))
|
||||
return 0;
|
||||
|
||||
sw->Sw_GrandPrevState = sw->Sw_PrevState;
|
||||
if(HAL_GPIO_ReadPin(sw->Sw_Port, sw->Sw_Pin) == sw->Sw_ActiveLvl)
|
||||
{
|
||||
sw->Sw_PrevState = 1;
|
||||
|
||||
if(sw->tickprev == 0)
|
||||
sw->tickprev = HAL_GetTick();
|
||||
|
||||
if((HAL_GetTick() - sw->tickprev) >= sw->Sw_FilterDelay)
|
||||
{
|
||||
if(HAL_GPIO_ReadPin(sw->Sw_Port, sw->Sw_Pin) == sw->Sw_ActiveLvl)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sw->tickprev = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sw->Sw_PrevState = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//------------------------GPIO SW FUNCTIONS-------------------------
|
||||
//-------------------------------------------------------------------
|
||||
66
Core/Example/general_gpio.h
Normal file
66
Core/Example/general_gpio.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file general_gpio.h
|
||||
* @brief Заголовочный файл для модуля инициализации портов.
|
||||
*************************************************************************/
|
||||
#ifndef __GPIO_GENERAL_H_
|
||||
#define __GPIO_GENERAL_H_
|
||||
|
||||
#include "mylibs_defs.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LED_IS_OFF = 0,
|
||||
LED_IS_ON = 1,
|
||||
LED_IS_BLINKING = 2,
|
||||
LED_IS_FADING = 3,
|
||||
}GPIO_LEDStateTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GPIO_LEDStateTypeDef state;
|
||||
|
||||
GPIO_TypeDef *LED_Port;
|
||||
uint32_t LED_Pin;
|
||||
|
||||
uint8_t LED_ActiveLvl;
|
||||
uint32_t LED_Period;
|
||||
uint32_t tickprev;
|
||||
}GPIO_LEDTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GPIO_TypeDef *Sw_Port;
|
||||
uint32_t Sw_Pin;
|
||||
|
||||
uint8_t Sw_ActiveLvl;
|
||||
uint32_t Sw_PrevState;
|
||||
uint32_t Sw_FilterDelay;
|
||||
uint32_t Sw_GrandPrevState;
|
||||
uint32_t tickprev;
|
||||
}GPIO_SwitchTypeDef;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////---FUNCTIONS---///////////////////////////
|
||||
HAL_StatusTypeDef GPIO_Clock_Enable(GPIO_TypeDef *GPIOx);
|
||||
/* Инициализировать кнопку (структуру кнопки) */
|
||||
HAL_StatusTypeDef GPIO_Switch_Init(GPIO_SwitchTypeDef *sw, GPIO_TypeDef *GPIOx, uint32_t GPIO_PIN_X, uint8_t SW_On_State);
|
||||
/* Считать состоянии кнопки запуска */
|
||||
uint8_t GPIO_Read_Swich(GPIO_SwitchTypeDef *swstart);
|
||||
|
||||
/* Инициализировать светодиод (структуру светодиода) */
|
||||
HAL_StatusTypeDef GPIO_LED_Init(GPIO_LEDTypeDef *led, GPIO_TypeDef *GPIOx, uint32_t GPIO_PIN_X, uint8_t LED_On_State);
|
||||
/* Включить светодиод */
|
||||
HAL_StatusTypeDef GPIO_LED_On(GPIO_LEDTypeDef *led);
|
||||
/* Выключить светодиод */
|
||||
HAL_StatusTypeDef GPIO_LED_Off(GPIO_LEDTypeDef *led);
|
||||
/* Активировать моргание светодиодом */
|
||||
HAL_StatusTypeDef GPIO_LED_Blink_Start(GPIO_LEDTypeDef *led, uint32_t period);
|
||||
/* Активировать моргание светодиодом */
|
||||
HAL_StatusTypeDef GPIO_LED_Fading_Start(GPIO_LEDTypeDef *led, uint32_t period);
|
||||
/* Управление динамическими режимами свечения светодиода */
|
||||
void GPIO_LED_Dynamic_Handle(GPIO_LEDTypeDef *led);
|
||||
///////////////////////////---FUNCTIONS---///////////////////////////
|
||||
|
||||
|
||||
#endif // __GPIO_GENERAL_H_
|
||||
314
Core/Example/gfx_oled_example.c
Normal file
314
Core/Example/gfx_oled_example.c
Normal file
@@ -0,0 +1,314 @@
|
||||
#include "gfx_oled_example.h"
|
||||
#include "math.h"
|
||||
int menu_white_theme = 0;
|
||||
|
||||
//#define SINE_EXAMPLE
|
||||
//#define ECG_EXAMPLE
|
||||
#define PLAYER_EXAMPLE
|
||||
|
||||
|
||||
#define ECG_SIZE 550
|
||||
|
||||
|
||||
// Примерный массив, симулирующий ЭКГ-сигнал (нормализованный от 0 до 1)
|
||||
const float ecg_data[ECG_SIZE] = {1.05893, 0.999357, 0.933132, 0.744792, 0.664672, 0.328846, 0.136133, -0.00837916, -0.131494,
|
||||
-0.1437, -0.182276, -0.215992, -0.128979, -0.131278, -0.0675223, 0.0027252, 0.0467067, -0.078859, -0.0658536, 0.0626352,
|
||||
-0.0462435, 0.0476623, 0.0535328, 0.122938, 0.0501136, 0.034033, 0.0919253, 0.108374, 0.0667457, 0.0351678, -0.00115748,
|
||||
0.0896459, 0.0288452, -0.0102636, 0.136738, 0.0397245, 0.0856079, 0.141222, 0.0826385, 0.165799, 0.105852, 0.172638,
|
||||
0.186488, 0.144543, 0.0710717, 0.145054, 0.176092, 0.158212, 0.157025, 0.29588, 0.231833, 0.338024, 0.253539, 0.344064,
|
||||
0.284527, 0.381661,0.385494, 0.324123, 0.305506, 0.433373, 0.477326, 0.364201,0.44309, 0.405536, 0.4922, 0.485606,
|
||||
0.370194, 0.512566, 0.540046, 0.445303, 0.518052, 0.456006, 0.364917, 0.367834, 0.40163, 0.460996, 0.466174, 0.447784,
|
||||
0.341301,0.371422, 0.268949, 0.259113, 0.249429, 0.343, 0.291218, 0.214958, 0.260874, 0.176372, 0.143037, 0.287679,
|
||||
0.21553, 0.275687, 0.215986, 0.180708, 0.215402, 0.217034, 0.228714, 0.0215511,0.18583, 0.1273, 0.195534, 0.0965174,
|
||||
0.0809704, 0.140033, 0.0206099, 0.0704855, 0.147377, 0.0789603, 0.130335, 0.106715, 0.074257, 0.00483191,0.0875146,
|
||||
-0.0300366, 0.0777518, 0.084268, 0.0977437, 0.129822, 0.148143, 0.105601,0.0682866, 0.137946, 0.068663, -0.0435304,
|
||||
-0.0222684, 0.12664, 0.0515385, 0.12427, -0.00217019, 0.0670832, 0.0832982, -0.0355677, 0.081701,0.031973, -0.0298655,
|
||||
0.0588815, 0.000209182, -0.0129383, 0.0042788, -0.00678231,0.00246806, -0.0260747, 0.0931759, 0.0232501,0.075334, 0.107382,
|
||||
0.0689022, 0.0769642, 0.0595603, -0.00397555, 0.0700185, 0.143251, 0.148137, 0.028107, 0.0164351, 0.0884327, 0.104194, 0.060235,
|
||||
0.0187268, 0.167828, -0.00462437, 0.000835874, 0.00885075, 0.0145025, 0.106193, 0.0975606, -0.00591114, 0.17083, 0.131315, 0.134244,
|
||||
0.000579408, 0.161378, 0.177776, 0.189649, 0.16676, 0.154687, 0.103331, 0.0398174, 0.0883113, 0.0404233, 0.0256448, 0.214035,
|
||||
0.0942273, 0.101924, 0.119377, 0.157289, 0.205664, 0.0941939, 0.271559, 0.229571, 0.303699, 0.217788, 0.252682, 0.189268,
|
||||
0.228094, 0.338367, 0.283619, 0.407, 0.258733, 0.438339, 0.351821, 0.385913, 0.442646, 0.296084, 0.314822, 0.315994, 0.364966,
|
||||
0.36342, 0.206273, 0.207504, 0.228995, 0.153435, 0.231611, 0.179904, 0.133949, 0.127457, 0.254484, 0.197385, 0.146029, 0.225966,
|
||||
0.0566748, 0.178446, 0.171133, 0.131769, 0.0525685, 0.132109, 0.069929, 0.0340608, 0.0468317, 0.180335, 0.0104617, 0.0354713,
|
||||
-0.0163161, 0.0425572, -0.0653781, 0.0877674, -0.0742378, -0.110943, -0.0746231, -0.0359488, -0.073415, 0.168732, 0.13128,
|
||||
0.249452, 0.351835, 0.563543, 0.679657, 0.92211, 1.08445, 1.1125, 0.993184, 0.916222, 0.925942, 0.786796, 0.53263, 0.270246,
|
||||
0.25373, 0.0244354, -0.0842442, -0.0607408, -0.243356, -0.243292, -0.105114, -0.0890295, -0.0677865, 0.0111256, 0.0417756,
|
||||
0.0859112, 0.00967447, 0.10676, 0.0906405, 0.0659345, 0.00378074, 0.150838, 0.0649321, 0.121398, 0.15057, 0.0259133, 0.0332993,
|
||||
0.120676, 0.111174, 0.195936, 0.181734, 0.173334, 0.0417151, 0.0514996, 0.0606249, 0.209138, 0.245178, 0.201025, 0.0990306,
|
||||
0.226141, 0.113311, 0.125047, 0.240658, 0.189883, 0.267101, 0.298959, 0.279095, 0.324262, 0.237427, 0.351991, 0.413902, 0.408103,
|
||||
0.266948, 0.337957, 0.353324, 0.430994, 0.427623, 0.479357, 0.407738, 0.387289, 0.374333, 0.521238, 0.416679, 0.460645, 0.499469,
|
||||
0.439634, 0.525509, 0.495788, 0.429484, 0.55411, 0.414761, 0.448777, 0.431282, 0.482458, 0.385804, 0.438642, 0.367588, 0.357191,
|
||||
0.478922, 0.366946, 0.415339, 0.473029, 0.351773, 0.389086, 0.386449, 0.305993, 0.335247, 0.210934, 0.360828, 0.197025, 0.198693,
|
||||
0.291518, 0.216643, 0.260826, 0.174855, 0.139573, 0.082479, 0.200454, 0.14318, 0.13979, 0.164275, 0.0477158, 0.0931762, 0.179358,
|
||||
0.159488, 0.0412108, 0.0386311, 0.0279973, 0.00843795, 0.0892224, 0.133798, 0.145674, 0.106026, 0.0205011, 0.124274, 0.0226069,
|
||||
0.0237319, 0.0163099, 0.024851, 0.030066, 0.0357348, 0.0601346, 0.0601495, 0.0406621, 0.0476954, 0.176459, 0.138954, 0.109933,
|
||||
0.0361806, 0.0422346, 0.0158523, 0.183712, 0.142873, 0.113671, 0.065383, 0.0365197, 0.128355, 0.202013, 0.0390733, 0.0570969,
|
||||
0.0854399, 0.0214106, 0.143953, 0.0881267, 0.204725, 0.0891005, 0.133303, 0.04055, 0.0864498, 0.0429089, 0.162802, 0.185894,
|
||||
0.0823151, 0.14975, 0.0719509, 0.119721, 0.180551, 0.134033, 0.0820637, 0.0753133, 0.106455, 0.100938, 0.0888068, 0.129034,
|
||||
0.166379, 0.103271, 0.104842, 0.0445476, 0.0251081, 0.0789694, 0.0852342, 0.153383, 0.215103, 0.212132, 0.118084, 0.0764331,
|
||||
0.183322, 0.185061, 0.184503, 0.188901, 0.0658428, 0.186253, 0.148702, 0.105533, 0.0908859, 0.245061, 0.125606, 0.134644, 0.247456,
|
||||
0.306363, 0.244781, 0.29657, 0.201664, 0.376652, 0.308954, 0.351074, 0.236012, 0.40292, 0.401634, 0.284931, 0.372803, 0.337598,
|
||||
0.383977, 0.35428, 0.3549, 0.303027, 0.310696, 0.25438, 0.423706, 0.356807, 0.398502, 0.229798, 0.365983, 0.325231, 0.266461,
|
||||
0.224066, 0.173261, 0.258585, 0.141305, 0.0968079, 0.226929, 0.198325, 0.198878, 0.177088, 0.126345, 0.115497, 0.196221,
|
||||
0.092804, 0.18902, 0.18094, 0.190455, 0.11711, 0.137381, 0.192176, 0.0792287, -0.0132089, 0.128102, 0.0579884, -0.0206506,
|
||||
0.0874069, -0.0799489, 0.0058573, 0.015077, 0.0137692, 0.0355411, 0.113175, 0.321936, 0.427422, 0.70414, 0.801907, 1.04001,
|
||||
1.11783, 1.1273, 1.02789, 1.10223, 0.829465, 0.792606, 0.470991, 0.324366, 0.108762, 0.0881276, -0.102915, -0.195709, -0.0950335,
|
||||
-0.178844, -0.103735, -0.131323, -0.0461341, -0.129231, 0.0830591, 0.0903014, 0.102478, 0.132797, 0.0580604, 0.111787, 0.108011,
|
||||
0.102112, 0.0534435, 0.0500927, 0.0925822, 0.0498444, 0.167477, 0.206324, 0.0179187, 0.12221, 0.0360253, 0.18297, 0.224765, 0.0451847,
|
||||
0.225041, 0.0467012, 0.186295, 0.213311, 0.171037, 0.249559, 0.261215, 0.216183, 0.128802};
|
||||
|
||||
|
||||
|
||||
void GFX_Draw_LoopIcon(uint8_t *Buffer_Frame, uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t pxColor);
|
||||
|
||||
GFXIconsTypeDef icons;
|
||||
|
||||
void Example_GFX_IconInit(void)
|
||||
{
|
||||
// play
|
||||
icons.StopPlay.stop.xPos1 = play_icon_x_left-1;
|
||||
icons.StopPlay.stop.yPos1 = play_icon_y_up;
|
||||
icons.StopPlay.stop.xPos2 = play_icon_x_left-1;
|
||||
icons.StopPlay.stop.yPos2 = play_icon_y_down;
|
||||
icons.StopPlay.stop.xPos3 = play_icon_x_rigth+1;
|
||||
icons.StopPlay.stop.yPos3 = play_icon_y_mid;
|
||||
icons.StopPlay.stop.pxColor = 1;
|
||||
|
||||
// stop
|
||||
icons.StopPlay.play_lines[0].xPos_Start = play_icon_x_left+1;
|
||||
icons.StopPlay.play_lines[0].yPos_Start = play_icon_y_up;
|
||||
icons.StopPlay.play_lines[0].xPos_End = play_icon_x_left+1;
|
||||
icons.StopPlay.play_lines[0].yPos_End = play_icon_y_down;
|
||||
icons.StopPlay.play_lines[0].pxColor = 1;
|
||||
icons.StopPlay.play_lines[1].xPos_Start = play_icon_x_rigth;
|
||||
icons.StopPlay.play_lines[1].yPos_Start = play_icon_y_up;
|
||||
icons.StopPlay.play_lines[1].xPos_End = play_icon_x_rigth;
|
||||
icons.StopPlay.play_lines[1].yPos_End = play_icon_y_down;
|
||||
icons.StopPlay.play_lines[1].pxColor = 1;
|
||||
|
||||
// stop/play pressed
|
||||
icons.StopPlay.PressedArea.selected_Width = selected_width;
|
||||
icons.StopPlay.PressedArea.xPos_Start = play_icon_x_left-1-selected_width;
|
||||
icons.StopPlay.PressedArea.yPos_Start = play_icon_y_up-selected_width;
|
||||
icons.StopPlay.PressedArea.area_Width = play_icon_x_rigth+2-(play_icon_x_left-1)+2*selected_width+1;
|
||||
icons.StopPlay.PressedArea.area_Height = play_icon_y_down-play_icon_y_up+2*selected_width+1;
|
||||
|
||||
// forward
|
||||
icons.Forward.line.xPos_Start = forward_icon_x_rigth;
|
||||
icons.Forward.line.yPos_Start = forward_icon_y_up;
|
||||
icons.Forward.line.xPos_End = forward_icon_x_rigth;
|
||||
icons.Forward.line.yPos_End = forward_icon_y_down;
|
||||
icons.Forward.line.pxColor = 1;
|
||||
icons.Forward.trig.xPos1 = forward_icon_x_left;
|
||||
icons.Forward.trig.yPos1 = forward_icon_y_up;
|
||||
icons.Forward.trig.xPos2 = forward_icon_x_left;
|
||||
icons.Forward.trig.yPos2 = forward_icon_y_down;
|
||||
icons.Forward.trig.xPos3 = forward_icon_x_rigth-1;
|
||||
icons.Forward.trig.yPos3 = forward_icon_y_mid;
|
||||
icons.Forward.trig.pxColor = 1;
|
||||
|
||||
// forward pressed
|
||||
icons.Forward.PressedArea.selected_Width = selected_width;
|
||||
icons.Forward.PressedArea.xPos_Start = forward_icon_x_left-selected_width;
|
||||
icons.Forward.PressedArea.yPos_Start = forward_icon_y_up-selected_width;
|
||||
icons.Forward.PressedArea.area_Width = forward_icon_x_rigth-(forward_icon_x_left)+2*selected_width+1;
|
||||
icons.Forward.PressedArea.area_Height = forward_icon_y_down-forward_icon_y_up+2*selected_width+1;
|
||||
|
||||
// backward
|
||||
icons.Backward.line.xPos_Start = backward_icon_x_left;
|
||||
icons.Backward.line.yPos_Start = backward_icon_y_up;
|
||||
icons.Backward.line.xPos_End = backward_icon_x_left;
|
||||
icons.Backward.line.yPos_End = backward_icon_y_down;
|
||||
icons.Backward.line.pxColor = 1;
|
||||
icons.Backward.trig.xPos1 = backward_icon_x_rigth;
|
||||
icons.Backward.trig.yPos1 = backward_icon_y_up;
|
||||
icons.Backward.trig.xPos2 = backward_icon_x_rigth;
|
||||
icons.Backward.trig.yPos2 = backward_icon_y_down;
|
||||
icons.Backward.trig.xPos3 = backward_icon_x_left+1;
|
||||
icons.Backward.trig.yPos3 = backward_icon_y_mid;
|
||||
icons.Backward.trig.pxColor = 1;
|
||||
|
||||
// backward pressed
|
||||
icons.Backward.PressedArea.xPos_Start = backward_icon_x_left-selected_width;
|
||||
icons.Backward.PressedArea.yPos_Start = backward_icon_y_up-selected_width;
|
||||
icons.Backward.PressedArea.area_Width = backward_icon_x_rigth-(backward_icon_x_left)+2*selected_width+1;
|
||||
icons.Backward.PressedArea.area_Height = backward_icon_y_down-backward_icon_y_up+2*selected_width+1;
|
||||
|
||||
// loop
|
||||
icons.Loop.xPos_Start = loop_icon_x_start;
|
||||
icons.Loop.yPos_Start = loop_icon_y_start;
|
||||
icons.Loop.icon_Width = loop_icon_width;
|
||||
icons.Loop.icon_Height = loop_icon_height;
|
||||
|
||||
// loop pressed
|
||||
icons.Loop.PressedArea.xPos_Start = loop_icon_x_start+3;
|
||||
icons.Loop.PressedArea.yPos_Start = loop_icon_y_start+3;
|
||||
icons.Loop.PressedArea.area_Width = loop_icon_width-5;
|
||||
icons.Loop.PressedArea.area_Height = loop_icon_height-5;
|
||||
// иконка зацикливания
|
||||
GFX_Draw_LoopIcon(oled_buf, loop_icon_x_start, loop_icon_y_start, loop_icon_width, loop_icon_height, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Example_OLED_GFX_Update(PlayerTypeDef *player)
|
||||
{
|
||||
static uint32_t oled_prevtick = 0;
|
||||
uint32_t oled_period = 50;
|
||||
if(uwTick - oled_prevtick > oled_period)
|
||||
{
|
||||
oled_prevtick = uwTick;
|
||||
Example_GFX_CreateFrame(player);
|
||||
oled_refresh();
|
||||
}
|
||||
}
|
||||
float sine_cnt_step = 0.01;
|
||||
int shift = 1;
|
||||
float ecg_cnt = 0;
|
||||
float ecg_cnt_step = 1;
|
||||
float ecg_scale = 16;
|
||||
void Example_GFX_CreateFrame(PlayerTypeDef *player)
|
||||
{
|
||||
#if defined(SINE_EXAMPLE) || defined(ECG_EXAMPLE)
|
||||
static float sine_cnt;
|
||||
static int display_cnt;
|
||||
static int pix_y_prev = 0;
|
||||
|
||||
#if defined(SINE_EXAMPLE)
|
||||
int pix_y = (int)((float)(sinf(sine_cnt)+shift)*((float)32/(1+shift)));
|
||||
#elif defined(ECG_EXAMPLE)
|
||||
int pix_y = (ecg_data[(int)ecg_cnt]*ecg_scale)+16;
|
||||
ecg_cnt += ecg_cnt_step;
|
||||
if(ecg_cnt > ECG_SIZE)
|
||||
ecg_cnt = 0;
|
||||
#endif
|
||||
|
||||
if(pix_y - pix_y_prev > 0)
|
||||
{
|
||||
for(int y = pix_y_prev+1; y <= pix_y; y++)
|
||||
{
|
||||
if(y<=32)
|
||||
GFX_Draw_Pixel(oled_buf, display_cnt, 32 - y, 1);
|
||||
}
|
||||
}
|
||||
else if (pix_y - pix_y_prev < 0)
|
||||
{
|
||||
for(int y = pix_y_prev-1; y >= pix_y; y--)
|
||||
{
|
||||
if(y<=32)
|
||||
GFX_Draw_Pixel(oled_buf, display_cnt, 32 - y, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
GFX_Draw_Pixel(oled_buf, display_cnt, 32 - pix_y, 1);
|
||||
|
||||
display_cnt++;
|
||||
|
||||
|
||||
|
||||
sine_cnt += sine_cnt_step;
|
||||
pix_y_prev = pix_y;
|
||||
|
||||
if(display_cnt>GFX_BufferWidth)
|
||||
{
|
||||
display_cnt = 0;
|
||||
GFX_Clean_Buffer_Frame(oled_buf, sizeof(oled_buf));
|
||||
|
||||
}
|
||||
#elif defined(PLAYER_EXAMPLE)
|
||||
GFX_Clean_Buffer_Frame(oled_buf, sizeof(oled_buf));
|
||||
|
||||
// название песни
|
||||
GFX_Output_String(oled_buf, 0, 0, "Harry Potter Theme", 0, 0);
|
||||
|
||||
// кнопка стоп/плей
|
||||
// GFX_Draw_Circle(oled_buf, circle_stopplay_x, circle_stopplay_y, circle_stopplay_r, 1);
|
||||
|
||||
// иконка "плей"
|
||||
if(player->play)
|
||||
{
|
||||
GFX_Draw_Line(oled_buf, &icons.StopPlay.play_lines[0]);
|
||||
GFX_Draw_Line(oled_buf, &icons.StopPlay.play_lines[1]);
|
||||
}
|
||||
// иконка "стоп"
|
||||
else
|
||||
{
|
||||
GFX_Draw_Triangle(oled_buf, &icons.StopPlay.stop);
|
||||
}
|
||||
if(player->pressed_start)
|
||||
GFX_Invertion_Area(oled_buf, icons.StopPlay.PressedArea.xPos_Start, icons.StopPlay.PressedArea.yPos_Start, icons.StopPlay.PressedArea.area_Width, icons.StopPlay.PressedArea.area_Height);
|
||||
|
||||
|
||||
// дорожка песни
|
||||
__GFX_Draw_Line(oled_buf, 0, GFX_BufferHeight-2, player->currenttime*GFX_BufferWidth, GFX_BufferHeight-2, 1);
|
||||
|
||||
|
||||
// перемотка вперед
|
||||
GFX_Draw_Triangle(oled_buf, &icons.Forward.trig);
|
||||
GFX_Draw_Line(oled_buf, &icons.Forward.line);
|
||||
if(player->pressed_forward)
|
||||
GFX_Invertion_Area(oled_buf, icons.Forward.PressedArea.xPos_Start, icons.Forward.PressedArea.yPos_Start, icons.Forward.PressedArea.area_Width, icons.Forward.PressedArea.area_Height);
|
||||
|
||||
|
||||
// перемотка назад
|
||||
GFX_Draw_Triangle(oled_buf, &icons.Backward.trig);
|
||||
GFX_Draw_Line(oled_buf, &icons.Backward.line);
|
||||
if(player->pressed_backward)
|
||||
GFX_Invertion_Area(oled_buf, icons.Backward.PressedArea.xPos_Start, icons.Backward.PressedArea.yPos_Start, icons.Backward.PressedArea.area_Width, icons.Backward.PressedArea.area_Height);
|
||||
|
||||
// индикация скорости
|
||||
char buff_speed[5];
|
||||
sprintf(buff_speed, "x%.1f", player->speed);
|
||||
if((player->speed < 1.05) && player->speed > 0.95)
|
||||
GFX_Output_String(oled_buf, speed_x_cursore, speed_y_cursore, buff_speed, 0, 0);
|
||||
else
|
||||
{
|
||||
GFX_Output_String(oled_buf, speed_x_cursore, speed_y_cursore, buff_speed, 0, 1);
|
||||
}
|
||||
// GFX_Draw_Line(oled_buf, speed_underline_x_left, speed_underline_y, speed_underline_x_rigth, speed_underline_y, 1);
|
||||
|
||||
// иконка зацикливания
|
||||
GFX_Draw_LoopIcon(oled_buf, icons.Loop.xPos_Start, icons.Loop.yPos_Start, icons.Loop.icon_Width, icons.Loop.icon_Height, 1);
|
||||
if(player->loop)
|
||||
GFX_Invertion_Area(oled_buf, icons.Loop.PressedArea.xPos_Start, icons.Loop.PressedArea.yPos_Start, icons.Loop.PressedArea.area_Width, icons.Loop.PressedArea.area_Height);
|
||||
|
||||
#endif // PLAYER_EXAMPLE
|
||||
|
||||
if(menu_white_theme)
|
||||
{
|
||||
GFX_Invertion_Display(oled_buf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Функция рисования значка "зациклить песню" */
|
||||
/* Сгенерировано чат гпт */
|
||||
void GFX_Draw_LoopIcon(uint8_t *Buffer_Frame, uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t pxColor)
|
||||
{
|
||||
#define arr_size 2
|
||||
#define spot_width 2
|
||||
uint8_t r = (width < height ? width : height) / 4; // Радиус закруглений ограничен минимальным размером
|
||||
|
||||
// Четыре дуги по углам
|
||||
__GFX_Draw_Arc(Buffer_Frame, x + width - r, y + r, r, 270, 360, pxColor); // Верхний правый угол
|
||||
__GFX_Draw_Arc(Buffer_Frame, x + r, y + r, r, 180, 270, pxColor); // Верхний левый угол
|
||||
__GFX_Draw_Arc(Buffer_Frame, x + r, y + height - r, r, 90, 180, pxColor); // Нижний левый угол
|
||||
__GFX_Draw_Arc(Buffer_Frame, x + width - r, y + height - r, r, 0, 90, pxColor); // Нижний правый угол
|
||||
|
||||
// Прямые линии между дугами
|
||||
__GFX_Draw_Line(Buffer_Frame, x + r, y, x + width - r-spot_width, y, pxColor); // Верхняя горизонталь
|
||||
__GFX_Draw_Line(Buffer_Frame, x, y + r, x, y + height - r, pxColor); // Левая вертикаль
|
||||
__GFX_Draw_Line(Buffer_Frame, x + r+spot_width, y + height, x + width - r, y + height, pxColor); // Нижняя горизонталь
|
||||
__GFX_Draw_Line(Buffer_Frame, x + width, y + r, x + width, y + height - r, pxColor); // Правая вертикаль
|
||||
|
||||
// Стрелки
|
||||
__GFX_Draw_Line(Buffer_Frame, x + width - r-spot_width, y, x + width - r - arr_size-spot_width, y - arr_size, pxColor); // Верхняя стрелка
|
||||
__GFX_Draw_Line(Buffer_Frame, x + width - r-spot_width, y, x + width - r - arr_size-spot_width, y + arr_size, pxColor);
|
||||
|
||||
__GFX_Draw_Line(Buffer_Frame, x + r+spot_width, y + height, x + r + arr_size+spot_width, y + height - arr_size, pxColor); // Нижняя стрелка
|
||||
__GFX_Draw_Line(Buffer_Frame, x + r+spot_width, y + height, x + r + arr_size+spot_width, y + height + arr_size, pxColor);
|
||||
}
|
||||
111
Core/Example/gfx_oled_example.h
Normal file
111
Core/Example/gfx_oled_example.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#ifndef GFX_OLED_EXAMPLE_H
|
||||
#define GFX_OLED_EXAMPLE_H
|
||||
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "menu_interface.h"
|
||||
#include "gfx_buffer.h"
|
||||
#include "oled.h"
|
||||
|
||||
#define font_size 10 //refer to font_tahoma_8_prop
|
||||
|
||||
#define displaycenter_x (62)
|
||||
#define displaycenter_y (18)
|
||||
|
||||
|
||||
#define control_panel_y_shift (2)
|
||||
#define control_panel_y_height (8)
|
||||
#define control_panel_y_mid (displaycenter_y + control_panel_y_shift)
|
||||
#define control_panel_y_up (control_panel_y_mid - (control_panel_y_height/2))
|
||||
#define control_panel_y_down (control_panel_y_mid + (control_panel_y_height/2))
|
||||
|
||||
#define play_icon_x_widht (3)
|
||||
#define play_icon_y_size control_panel_y_height//(8)
|
||||
|
||||
#define play_icon_x_left (displaycenter_x - play_icon_x_widht)
|
||||
#define play_icon_x_rigth (displaycenter_x + play_icon_x_widht)
|
||||
#define play_icon_y_up (control_panel_y_up)
|
||||
#define play_icon_y_down (control_panel_y_down)
|
||||
#define play_icon_y_mid (control_panel_y_mid)
|
||||
|
||||
|
||||
#define forward_backward_icon_x_shift (18)
|
||||
|
||||
|
||||
#define forward_icon_x_left (play_icon_x_left + forward_backward_icon_x_shift)
|
||||
#define forward_icon_x_rigth (play_icon_x_rigth + forward_backward_icon_x_shift+3)
|
||||
#define forward_icon_y_up (control_panel_y_up)
|
||||
#define forward_icon_y_down (control_panel_y_down)
|
||||
#define forward_icon_y_mid (control_panel_y_mid)
|
||||
|
||||
#define backward_icon_x_left (play_icon_x_left - forward_backward_icon_x_shift-3)
|
||||
#define backward_icon_x_rigth (play_icon_x_rigth - forward_backward_icon_x_shift)
|
||||
#define backward_icon_y_up (control_panel_y_up)
|
||||
#define backward_icon_y_down (control_panel_y_down)
|
||||
#define backward_icon_y_mid (control_panel_y_mid)
|
||||
|
||||
|
||||
#define speed_x_shift (39)
|
||||
#define speed_y_shift (-3)
|
||||
|
||||
#define speed_x_cursore (displaycenter_x+speed_x_shift)
|
||||
#define speed_y_cursore (displaycenter_y+speed_y_shift)
|
||||
|
||||
#define loop_icon_x_shift (speed_x_shift+3)
|
||||
#define loop_icon_y_shift (-2)
|
||||
|
||||
#define loop_icon_x_start (displaycenter_x-loop_icon_x_shift-loop_icon_width)
|
||||
#define loop_icon_y_start (displaycenter_y+loop_icon_y_shift)
|
||||
#define loop_icon_width (11)
|
||||
#define loop_icon_height 8
|
||||
|
||||
#define selected_width (1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t xPos_Start;
|
||||
uint8_t yPos_Start;
|
||||
uint8_t area_Width;
|
||||
uint8_t area_Height;
|
||||
uint8_t selected_Width;
|
||||
}PresesIconTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GFX_LineHandleTypeDef play_lines[2];
|
||||
GFX_TriangleHandleTypeDef stop;
|
||||
PresesIconTypeDef PressedArea;
|
||||
}StopPlayIconTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GFX_LineHandleTypeDef line;
|
||||
GFX_TriangleHandleTypeDef trig;
|
||||
PresesIconTypeDef PressedArea;
|
||||
}ForwardBackwardIconTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// GFX_ArcHandleTypeDef arc[4];
|
||||
// GFX_LineHandleTypeDef line[4];
|
||||
// GFX_LineHandleTypeDef line_arrow1[2];
|
||||
// GFX_LineHandleTypeDef line_arrow2[2];
|
||||
uint8_t xPos_Start;
|
||||
uint8_t yPos_Start;
|
||||
uint8_t icon_Width;
|
||||
uint8_t icon_Height;
|
||||
PresesIconTypeDef PressedArea;
|
||||
}LoopIconTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
StopPlayIconTypeDef StopPlay;
|
||||
ForwardBackwardIconTypeDef Forward;
|
||||
ForwardBackwardIconTypeDef Backward;
|
||||
LoopIconTypeDef Loop;
|
||||
}GFXIconsTypeDef;
|
||||
|
||||
|
||||
void Example_GFX_IconInit(void);
|
||||
void Example_GFX_CreateFrame(PlayerTypeDef *player);
|
||||
void Example_OLED_GFX_Update(PlayerTypeDef *player);
|
||||
#endif //GFX_OLED_EXAMPLE_H
|
||||
145
Core/Example/menu_interface.c
Normal file
145
Core/Example/menu_interface.c
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "menu_interface.h"
|
||||
|
||||
void Menu_Control_Init(PlayerTypeDef *player)
|
||||
{
|
||||
GPIO_Switch_Init(&player->SwTheme, GPIO_SwTheme, GPIO_Pin_SwTheme, SW_ON);
|
||||
GPIO_Switch_Init(&player->SwPlay, GPIO_SwPlay, GPIO_Pin_SwPlay, SW_ON);
|
||||
GPIO_Switch_Init(&player->SwForward, GPIO_SwForward, GPIO_Pin_SwForward, SW_ON);
|
||||
GPIO_Switch_Init(&player->SwBackward, GPIO_SwBackward, GPIO_Pin_SwBackward, SW_ON);
|
||||
GPIO_Switch_Init(&player->SwSpeed, GPIO_SwSpeed, GPIO_Pin_SwSpeed, SW_ON);
|
||||
GPIO_Switch_Init(&player->SwLoop, GPIO_SwLoop, GPIO_Pin_SwLoop, SW_ON);
|
||||
|
||||
player->SwTheme.Sw_FilterDelay = 70;
|
||||
player->SwPlay.Sw_FilterDelay = 70;
|
||||
player->SwForward.Sw_FilterDelay = 70;
|
||||
player->SwBackward.Sw_FilterDelay = 70;
|
||||
player->SwSpeed.Sw_FilterDelay = 70;
|
||||
player->SwLoop.Sw_FilterDelay = 70;
|
||||
|
||||
player->speed = 1;
|
||||
|
||||
}
|
||||
|
||||
extern int menu_white_theme;
|
||||
void Menu_Control_ReadGPIO(PlayerTypeDef *player)
|
||||
{
|
||||
#ifdef GPIO_CONTROL
|
||||
/* Обработка кнопки темы меню */
|
||||
if(GPIO_Read_Swich(&player->SwTheme))
|
||||
{
|
||||
if(player->SwTheme.Sw_GrandPrevState == 0)
|
||||
menu_white_theme ^= 1;
|
||||
}
|
||||
|
||||
/* Обработка кнопки плей */
|
||||
if(GPIO_Read_Swich(&player->SwPlay))
|
||||
{
|
||||
if(player->SwPlay.Sw_GrandPrevState == 0)
|
||||
player->play ^= 1;
|
||||
|
||||
player->pressed_start = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->pressed_start = 0;
|
||||
}
|
||||
|
||||
/* Обработка кнопки прокрутки вперед */
|
||||
if(GPIO_Read_Swich(&player->SwForward))
|
||||
{
|
||||
player->pressed_forward = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->pressed_forward = 0;
|
||||
}
|
||||
|
||||
/* Обработка кнопки прокрутки назад */
|
||||
if(GPIO_Read_Swich(&player->SwBackward))
|
||||
{
|
||||
player->pressed_backward = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->pressed_backward = 0;
|
||||
}
|
||||
|
||||
/* Обработка кнопки зацикливания */
|
||||
if(GPIO_Read_Swich(&player->SwLoop))
|
||||
{
|
||||
if(player->SwLoop.Sw_GrandPrevState == 0)
|
||||
player->loop ^= 1;
|
||||
}
|
||||
|
||||
/* Обработка кнопки скорости */
|
||||
if(GPIO_Read_Swich(&player->SwSpeed))
|
||||
{
|
||||
if(player->SwSpeed.Sw_GrandPrevState == 0)
|
||||
player->speed += 0.5;
|
||||
|
||||
|
||||
if(player->speed > 0.05)
|
||||
player->speed = 0.5;
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
float sim_music_long_sec = 10;
|
||||
float sim_music_step = 0;
|
||||
void Menu_Control_Music(PlayerTypeDef *player)
|
||||
{
|
||||
if(player->currenttime > 1)
|
||||
{
|
||||
player->currenttime = 0;
|
||||
if(player->loop == 0)
|
||||
player->play = 0;
|
||||
}
|
||||
else if(player->currenttime < 0)
|
||||
{
|
||||
if(player->loop)
|
||||
player->currenttime = 1;
|
||||
else
|
||||
player->currenttime = 0;
|
||||
}
|
||||
|
||||
|
||||
sim_music_step = 1/(sim_music_long_sec*100);
|
||||
// если шкатулка запущена
|
||||
if(player->play)
|
||||
{
|
||||
// если кнопки перемотки не нажаты, то подтягивает заданную скорость воспроизведения
|
||||
if((player->pressed_backward == 0) && (player->pressed_forward == 0) )
|
||||
{
|
||||
sim_music_step *= player->speed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sim_music_step = 0;
|
||||
}
|
||||
|
||||
// перемотка назад
|
||||
if((player->pressed_backward == 1) && (player->pressed_forward == 0) )
|
||||
{
|
||||
if(player->currenttime > 0)
|
||||
{
|
||||
sim_music_step = -1/(sim_music_long_sec*100);
|
||||
}
|
||||
}
|
||||
|
||||
// перемотка вперед
|
||||
if((player->pressed_forward == 1) && (player->pressed_backward == 0) )
|
||||
{
|
||||
sim_music_step = 1/(sim_music_long_sec*100)*2;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t prevtick = 0;
|
||||
if(uwTick - prevtick > 10)
|
||||
{
|
||||
prevtick = uwTick;
|
||||
player->currenttime += sim_music_step;
|
||||
}
|
||||
}
|
||||
53
Core/Example/menu_interface.h
Normal file
53
Core/Example/menu_interface.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef MENU_INTERFACE_H
|
||||
#define MENU_INTERFACE_H
|
||||
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "general_gpio.h"
|
||||
#include "main.h"
|
||||
|
||||
#define GPIO_CONTROL //comment for control from watch window
|
||||
|
||||
#define GPIO_SwTheme SW_THEME_GPIO_Port
|
||||
#define GPIO_Pin_SwTheme SW_THEME_Pin
|
||||
|
||||
#define GPIO_SwSpeed SW_SPEED_GPIO_Port
|
||||
#define GPIO_Pin_SwSpeed SW_SPEED_Pin
|
||||
|
||||
#define GPIO_SwForward SW_FORWARD_GPIO_Port
|
||||
#define GPIO_Pin_SwForward SW_FORWARD_Pin
|
||||
|
||||
#define GPIO_SwPlay SW_PLAY_GPIO_Port
|
||||
#define GPIO_Pin_SwPlay SW_PLAY_Pin
|
||||
|
||||
#define GPIO_SwBackward SW_BACKWARD_GPIO_Port
|
||||
#define GPIO_Pin_SwBackward SW_BACKWARD_Pin
|
||||
|
||||
#define GPIO_SwLoop SW_LOOP_GPIO_Port
|
||||
#define GPIO_Pin_SwLoop SW_LOOP_Pin
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned play:1;
|
||||
unsigned loop:1;
|
||||
unsigned pressed_start:1;
|
||||
unsigned pressed_forward:1;
|
||||
unsigned pressed_backward:1;
|
||||
float currenttime;
|
||||
float speed;
|
||||
|
||||
|
||||
GPIO_SwitchTypeDef SwTheme;
|
||||
GPIO_SwitchTypeDef SwPlay;
|
||||
GPIO_SwitchTypeDef SwForward;
|
||||
GPIO_SwitchTypeDef SwBackward;
|
||||
GPIO_SwitchTypeDef SwSpeed;
|
||||
GPIO_SwitchTypeDef SwLoop;
|
||||
}PlayerTypeDef;
|
||||
extern PlayerTypeDef Player;
|
||||
|
||||
|
||||
void Menu_Control_Init(PlayerTypeDef *player);
|
||||
void Menu_Control_ReadGPIO(PlayerTypeDef *player);
|
||||
void Menu_Control_Music(PlayerTypeDef *player);
|
||||
|
||||
#endif //MENU_INTERFACE_H
|
||||
29
Core/Example/mylibs_config.h
Normal file
29
Core/Example/mylibs_config.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mylibs_config.h
|
||||
* @brief Конфигурации для библиотек MyLibs
|
||||
**************************************************************************
|
||||
* @defgroup MYLIBS_CONFIG Configs My Libs
|
||||
* @ingroup MYLIBS_ALL
|
||||
* @brief Конфигурации для библиотек MyLibs
|
||||
@{
|
||||
*************************************************************************/
|
||||
#ifndef __MYLIBS_CONFIG_H_
|
||||
#define __MYLIBS_CONFIG_H_
|
||||
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
// user includes
|
||||
//#define INCLUDE_BIT_ACCESS_LIB
|
||||
//#define INCLUDE_TRACKERS_LIB
|
||||
//#define INCLUDE_TRACE_LIB
|
||||
#define INCLUDE_GENERAL_PERIPH_LIBS
|
||||
//#define FREERTOS_DELAY
|
||||
|
||||
#define SW_ON 0
|
||||
#define SW_OFF 1
|
||||
|
||||
/** MYLIBS_CONFIG
|
||||
* @}
|
||||
*/
|
||||
#endif //__MYLIBS_CONFIG_H_
|
||||
155
Core/Example/mylibs_defs.h
Normal file
155
Core/Example/mylibs_defs.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
**************************************************************************
|
||||
* @file mylibs_defs.h
|
||||
* @brief Заголочный файл для дефайнов библиотеки MyLibsGeneral.
|
||||
**************************************************************************
|
||||
* @defgroup MYLIBS_DEFINES My Libs defines
|
||||
* @brief Базовые дефайны для всего проекта
|
||||
*
|
||||
*************************************************************************/
|
||||
#ifndef __MYLIBS_DEFINES_H_
|
||||
#define __MYLIBS_DEFINES_H_
|
||||
|
||||
#include "mylibs_config.h"
|
||||
|
||||
/***************************************************************************
|
||||
******************************ERROR_HANDLER********************************/
|
||||
/**
|
||||
* @addtogroup ERROR_HANDLER_DEFINES Error Handler defines
|
||||
* @ingroup MYLIBS_DEFINES
|
||||
* @brief Дефайны для определения функции обработки ошибок
|
||||
@{
|
||||
*/
|
||||
|
||||
/* extern Error_Handler from main.h */
|
||||
extern void Error_Handler(void);
|
||||
|
||||
/* Define error handler for MyLibs */
|
||||
#define MyLibs_Error_Handler(_params_) Error_Handler(_params_)
|
||||
/* If error handler not defined - set void */
|
||||
#ifndef MyLibs_Error_Handler
|
||||
#define ((void)0U)
|
||||
#endif // MyLibs_Error_Handler
|
||||
|
||||
/** @brief Check one pointer */
|
||||
#define check_null_ptr_1(_p1_) (_p1_ == NULL)
|
||||
/** @brief Check two pointers */
|
||||
#define check_null_ptr_2(_p1_, _p2_) ((_p1_ == NULL) || (_p2_ == NULL))
|
||||
/** @brief Check three pointers */
|
||||
#define check_null_ptr_3(_p1_, _p2_, _p3_) ((_p1_ == NULL) || (_p2_ == NULL) || (_p3_ == NULL))
|
||||
/** @brief Check four pointers */
|
||||
#define check_null_ptr_4(_p1_, _p2_, _p3_, _p4_) ((_p1_ == NULL) || (_p2_ == NULL) || (_p3_ == NULL) || (_p4_ == NULL))
|
||||
/** @brief Check five pointers */
|
||||
#define check_null_ptr_5(_p1_, _p2_, _p3_, _p4_, _p5_) ((_p1_ == NULL) || (_p2_ == NULL) || (_p3_ == NULL) || (_p4_ == NULL) || (_p5_ == NULL))
|
||||
|
||||
/** ERROR_HANDLER_DEFINES
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
********************************ACCESS_DEFINES*****************************/
|
||||
|
||||
#define ClearStruct(_struct_) memset(&(_struct_), 0, sizeof(_struct_))
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
******************************DELAYS_DEFINES*******************************/
|
||||
/**
|
||||
* @addtogroup DELAYS_DEFINES Delays defines
|
||||
* @ingroup MYLIBS_DEFINES
|
||||
* @brief Дефайны для реализации задержек
|
||||
@{
|
||||
*/
|
||||
|
||||
#ifdef FREERTOS_DELAY
|
||||
#define msDelay(_ms_) osDelay(_ms_)
|
||||
#else
|
||||
#define msDelay(_ms_) HAL_Delay(_ms_)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Save tick at starting delay (tickstart in HAL)
|
||||
* @param _pvar_ - указатель для переменной для сохранения тиков.
|
||||
* @details Сохраняет начало отсчета задержки (текущее количество тиков)
|
||||
*/
|
||||
#define msDelayStart(_pvar_) *(_pvar_) = HAL_GetTick()
|
||||
|
||||
/**
|
||||
* @brief Wait for delay after tickstart in _pvar_
|
||||
* @param _pvar_ - указатель для переменной для сохранения тиков.
|
||||
* @details Выставляет 1, когда задержка активна
|
||||
*/
|
||||
#define msDelayWhileActive(_ms_, _pvar_) (HAL_GetTick() - *(_pvar_) < _ms_)
|
||||
|
||||
/**
|
||||
* @brief Wait until delay is done tickstart in _pvar_
|
||||
* @param _pvar_ - указатель для переменной для сохранения тиков.
|
||||
* @details Выставляет 1, когда задержка истекла
|
||||
*/
|
||||
#define msDelayWaitDone(_ms_, _pvar_) (HAL_GetTick() - *(_pvar_) >= _ms_)
|
||||
|
||||
/** DELAYS_DEFINES
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*******************************MATH_DEFINES********************************/
|
||||
/**
|
||||
* @addtogroup MATH_DEFINES Math defines
|
||||
* @ingroup MYLIBS_DEFINES
|
||||
* @brief Дефайны для различных математических функций
|
||||
@{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Calc dividing including remainder
|
||||
* @param _val_ - делимое.
|
||||
* @param _div_ - делитель.
|
||||
* @details Если результат деления без остатка: он возвращается как есть
|
||||
Если с остатком - округляется вверх
|
||||
*/
|
||||
//#define Divide_Up(_val_, _div_) (((_val_)%(_div_))? (_val_)/(_div_)+1 : (_val_)/_div_) /* через тернарный оператор */
|
||||
#define Divide_Up(_val_, _div_) ((_val_ - 1) / _div_) + 1 /* через мат выражение */
|
||||
|
||||
/**
|
||||
* @brief Swap between Little Endian and Big Endian
|
||||
* @param v - Переменная для свапа.
|
||||
* @return v (new) - Свапнутая переменная.
|
||||
* @details Переключения между двумя типами хранения слова: HI-LO байты и LO-HI байты.
|
||||
*/
|
||||
#define ByteSwap16(v) (((v&0xFF00) >> (8)) | ((v&0x00FF) << (8)))
|
||||
|
||||
/**
|
||||
* @brief Absolute
|
||||
* @param x - Переменная для модудя.
|
||||
* @return x (new) - Число по модулю.
|
||||
* @details Берет число по модулю. Хз как работает библиотечный abs в stdlib.h, мб это быстрее, но вряд ли конечно.
|
||||
*/
|
||||
#define ABS(x) ( ((x) > 0)? (x) : -(x))
|
||||
|
||||
/** MATH_DEFINES
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef LED_PWM_TICKS
|
||||
#define LED_PWM_TICKS 15
|
||||
#endif
|
||||
|
||||
#ifndef LED_ON
|
||||
#define LED_ON 1
|
||||
#endif
|
||||
#ifndef LED_OFF
|
||||
#define LED_OFF 0
|
||||
#endif
|
||||
|
||||
#ifndef SW_ON
|
||||
#define SW_ON 1
|
||||
#endif
|
||||
#ifndef SW_OFF
|
||||
#define SW_OFF 0
|
||||
#endif
|
||||
|
||||
#endif //__MYLIBS_DEFINES_H_
|
||||
Reference in New Issue
Block a user