加入按键
This commit is contained in:
parent
7ac6baf560
commit
ce04a54b9d
|
@ -23,7 +23,8 @@
|
|||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
@ -49,6 +50,7 @@ extern "C" {
|
|||
/* USER CODE BEGIN Includes */
|
||||
#include "sys.h"
|
||||
#include "delay.h"
|
||||
#include "btn.h"
|
||||
#include "lib.h"
|
||||
#include "bsp.h"
|
||||
|
||||
|
@ -97,16 +99,18 @@ void Error_Handler(void);
|
|||
#define OLED_SDA_GPIO_Port GPIOB
|
||||
#define OLDE_SCK_Pin LL_GPIO_PIN_13
|
||||
#define OLDE_SCK_GPIO_Port GPIOB
|
||||
#define KEY_1_Pin LL_GPIO_PIN_14
|
||||
#define KEY_1_GPIO_Port GPIOB
|
||||
#ifndef NVIC_PRIORITYGROUP_0
|
||||
#define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bit for pre-emption priority,
|
||||
#define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bit for pre-emption priority, \
|
||||
4 bits for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bit for pre-emption priority,
|
||||
#define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bit for pre-emption priority, \
|
||||
3 bits for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority,
|
||||
#define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority, \
|
||||
2 bits for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority,
|
||||
#define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority, \
|
||||
1 bit for subpriority */
|
||||
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority,
|
||||
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority, \
|
||||
0 bit for subpriority */
|
||||
#endif
|
||||
|
||||
|
|
|
@ -94,9 +94,9 @@ void MX_GPIO_Init(void)
|
|||
LL_GPIO_Init(TMC2240_DIR_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_14
|
||||
|LL_GPIO_PIN_15|LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5
|
||||
|LL_GPIO_PIN_6|LL_GPIO_PIN_7|LL_GPIO_PIN_8|LL_GPIO_PIN_9;
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_15
|
||||
|LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6
|
||||
|LL_GPIO_PIN_7|LL_GPIO_PIN_8|LL_GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
|
@ -108,6 +108,12 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/**/
|
||||
GPIO_InitStruct.Pin = KEY_1_Pin;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(KEY_1_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "sys.h"
|
||||
#include "flow.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "btn.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -243,6 +243,7 @@ void TIM1_UP_IRQHandler(void)
|
|||
{
|
||||
TIM_IRQ_HANDLER(TASK_TIM);
|
||||
LL_IncTick();
|
||||
button_ticks();
|
||||
FLOW_TICK_UPDATE();
|
||||
}
|
||||
/* USER CODE END TIM1_UP_IRQn 1 */
|
||||
|
|
|
@ -364,6 +364,18 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\application\key.c</PathWithFileName>
|
||||
<FilenameWithoutPath>key.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -374,7 +386,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -386,7 +398,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -398,7 +410,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -410,7 +422,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -422,7 +434,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -434,7 +446,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -446,7 +458,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -458,7 +470,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -470,7 +482,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -490,7 +502,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -502,7 +514,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -514,7 +526,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -526,7 +538,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -538,7 +550,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -550,7 +562,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -562,7 +574,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -574,7 +586,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -586,7 +598,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>6</GroupNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -606,7 +618,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>7</GroupNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -618,7 +630,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>7</GroupNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -630,7 +642,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>7</GroupNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -650,7 +662,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -662,7 +674,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -674,7 +686,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -686,7 +698,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -698,7 +710,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -710,7 +722,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -722,7 +734,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -734,7 +746,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -746,7 +758,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileNumber>41</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -758,7 +770,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>41</FileNumber>
|
||||
<FileNumber>42</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -770,7 +782,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>42</FileNumber>
|
||||
<FileNumber>43</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -782,7 +794,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>43</FileNumber>
|
||||
<FileNumber>44</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -794,7 +806,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>44</FileNumber>
|
||||
<FileNumber>45</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -806,7 +818,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>45</FileNumber>
|
||||
<FileNumber>46</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -818,7 +830,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>8</GroupNumber>
|
||||
<FileNumber>46</FileNumber>
|
||||
<FileNumber>47</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -652,6 +652,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\User\application\app.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>key.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\User\application\key.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,12 +2,17 @@
|
|||
#include "app.h"
|
||||
#include "board.h"
|
||||
#include "flow.h"
|
||||
|
||||
#include "key.h"
|
||||
static struct flow business_fw; // 业务流程
|
||||
static struct flow idle_fw; // 空闲任务
|
||||
|
||||
app_t app;
|
||||
|
||||
void key_1_callback(PressEvent e)
|
||||
{
|
||||
app.angel = 360;
|
||||
}
|
||||
|
||||
static uint8_t business_inspection(struct flow *fl)
|
||||
{
|
||||
FL_HEAD(fl);
|
||||
|
@ -40,7 +45,6 @@ static uint8_t idle_inspection(struct flow *fl)
|
|||
{
|
||||
GPIO_TOGGLE(LED_BLUE_GPIO_Port, LED_BLUE_Pin);
|
||||
tmc2240_config_read(TMC2240_1);
|
||||
tmc2240_process(TMC2240_1);
|
||||
ssd1306_f6x8_string(0, 2, " tick:");
|
||||
ssd1306_f6x8_number(40, 2, tick++, 0);
|
||||
ssd1306_f6x8_string(0, 4, " cfg:");
|
||||
|
@ -79,11 +83,11 @@ void app_init(void)
|
|||
{
|
||||
ssd1306_draw_progress_bar(i);
|
||||
}
|
||||
|
||||
ssd1306_clear();
|
||||
key_init();
|
||||
FL_INIT(&business_fw); // 业务流程
|
||||
FL_INIT(&idle_fw); // 空闲任务
|
||||
|
||||
ENABLE_TIM(TASK_TIM);
|
||||
ENABLE_TIM(TMC2240_TIM);
|
||||
ssd1306_clear();
|
||||
}
|
||||
|
|
|
@ -18,4 +18,5 @@ extern app_t app;
|
|||
|
||||
void app_init(void);
|
||||
void app_run(void);
|
||||
|
||||
#endif // APP_H
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include "key.h"
|
||||
#include "btn.h"
|
||||
|
||||
#define INVALID_BUTTON_TICKS 200 // 无效按键时间 毫秒
|
||||
static uint32_t key_start_ticks = 0;
|
||||
/* 按钮 */
|
||||
struct Button key_1;
|
||||
struct Button key_2;
|
||||
struct Button key_3;
|
||||
struct Button key_4;
|
||||
struct Button key_5;
|
||||
struct Button key_6;
|
||||
|
||||
static BOOL allow_condition(void)
|
||||
{
|
||||
/**
|
||||
* key的初始化在LCD板子上电之前,因为是低电平有效,所以会误判为按键按下
|
||||
*/
|
||||
if (sys_millis() - key_start_ticks < INVALID_BUTTON_TICKS) // 仿真的时候按键会有毛刺,在xx秒之后按下有效
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static uint8_t read_button_gpio(button_id_e button_id)
|
||||
{
|
||||
if (allow_condition() == FALSE)
|
||||
{
|
||||
return ACTIVE_LEVEL_HIGH;
|
||||
}
|
||||
switch (button_id)
|
||||
{
|
||||
case KEY_1:
|
||||
return GPIO_READ(KEY_1_GPIO_Port, KEY_1_Pin);
|
||||
|
||||
default:
|
||||
return ACTIVE_LEVEL_LOW;
|
||||
}
|
||||
}
|
||||
|
||||
static void key_1_press_down_handler(void *btn)
|
||||
{
|
||||
key_1_callback(PRESS_DOWN);
|
||||
}
|
||||
|
||||
void key_init(void)
|
||||
{
|
||||
key_start_ticks = sys_millis();
|
||||
GPIO_SET_INPUT(KEY_1_GPIO_Port, KEY_1_Pin);
|
||||
|
||||
button_init(&key_1, read_button_gpio, ACTIVE_LEVEL_LOW, KEY_1, KEY_1);
|
||||
|
||||
button_attach(&key_1, PRESS_DOWN, key_1_press_down_handler);
|
||||
|
||||
button_start(&key_1);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _KEY_H_
|
||||
#define _KEY_H_
|
||||
#include "main.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
KEY_1 = 1,
|
||||
} button_id_e;
|
||||
|
||||
void key_1_callback(PressEvent e);
|
||||
|
||||
void key_init(void);
|
||||
#endif // _KEY_H_
|
|
@ -256,7 +256,7 @@ void tmc2240_config_read(tmc2240_index_e index)
|
|||
tmc->data.tmc2240_temperature = (float32)(tmc->data.tmc2240_adc_temp - 2038) / 7.7;
|
||||
}
|
||||
|
||||
void tmc2240_process(tmc2240_index_e index)
|
||||
void tmc2240_test(tmc2240_index_e index)
|
||||
{
|
||||
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
|
||||
tmc2240_t *tmc = &_tmc2240[index];
|
||||
|
@ -310,7 +310,27 @@ void tmc2240_motor_set_angle(tmc2240_index_e index, int32_t angle)
|
|||
|
||||
tmc->motor.pulse_count = ABS(angle) / tmc->motor.step_angle;
|
||||
tmc->motor.step_angle_count = 0;
|
||||
|
||||
tmc->params.enable = TRUE;
|
||||
|
||||
_tmc2240_direction(index, tmc->params.direction);
|
||||
if (PWM_GET_ARR(tmc->timer) != tmc->params.arr)
|
||||
{
|
||||
if (tmc->params.arr == 0)
|
||||
{
|
||||
tmc->params.arr = tmc->default_tm.arr;
|
||||
}
|
||||
PWM_SET_ARR(tmc->timer, tmc->params.arr);
|
||||
tmc->params.freq = PWM_GET_FREQ(tmc->timer);
|
||||
}
|
||||
|
||||
tmc2240_percent(index, tmc->params.percent);
|
||||
|
||||
if (tmc->config.chopconf.bits.mres != tmc->read_config.chopconf.bits.mres)
|
||||
{
|
||||
tmc2240_reg_write(index, TMC2240_CHOPCONF, tmc->config.chopconf.data);
|
||||
_tmc2240_motor_update(index);
|
||||
}
|
||||
_tmc2240_enable(index, tmc->params.enable);
|
||||
}
|
||||
|
||||
|
|
|
@ -367,6 +367,6 @@ tmc2240_t *tmc2240_get(tmc2240_index_e index);
|
|||
void tmc2240_motor_set_angle(tmc2240_index_e index, int32_t angle);
|
||||
void tmc2240_motor_update(tmc2240_index_e index);
|
||||
|
||||
void tmc2240_process(tmc2240_index_e index);
|
||||
void tmc2240_test(tmc2240_index_e index);
|
||||
void tmc2240_config_read(tmc2240_index_e index);
|
||||
#endif // __TMC2240_H
|
||||
|
|
19
motor.ioc
19
motor.ioc
|
@ -43,12 +43,13 @@ Mcu.Pin0=PC13-TAMPER-RTC
|
|||
Mcu.Pin1=PD0-OSC_IN
|
||||
Mcu.Pin10=PB12
|
||||
Mcu.Pin11=PB13
|
||||
Mcu.Pin12=PA9
|
||||
Mcu.Pin13=PA10
|
||||
Mcu.Pin14=PA13
|
||||
Mcu.Pin15=PA14
|
||||
Mcu.Pin16=VP_SYS_VS_Systick
|
||||
Mcu.Pin17=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin12=PB14
|
||||
Mcu.Pin13=PA9
|
||||
Mcu.Pin14=PA10
|
||||
Mcu.Pin15=PA13
|
||||
Mcu.Pin16=PA14
|
||||
Mcu.Pin17=VP_SYS_VS_Systick
|
||||
Mcu.Pin18=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin2=PD1-OSC_OUT
|
||||
Mcu.Pin3=PA3
|
||||
Mcu.Pin4=PA4
|
||||
|
@ -57,7 +58,7 @@ Mcu.Pin6=PA6
|
|||
Mcu.Pin7=PA7
|
||||
Mcu.Pin8=PB0
|
||||
Mcu.Pin9=PB1
|
||||
Mcu.PinsNb=18
|
||||
Mcu.PinsNb=19
|
||||
Mcu.ThirdParty0=RealThread.RT-Thread.3.1.5
|
||||
Mcu.ThirdPartyNb=1
|
||||
Mcu.UserConstants=
|
||||
|
@ -130,6 +131,10 @@ PB13.GPIO_PuPd=GPIO_PULLUP
|
|||
PB13.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PB13.PinState=GPIO_PIN_RESET
|
||||
PB13.Signal=GPIO_Output
|
||||
PB14.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PB14.GPIO_Label=KEY_1
|
||||
PB14.GPIO_PuPd=GPIO_PULLUP
|
||||
PB14.Signal=GPIO_Input
|
||||
PC13-TAMPER-RTC.GPIOParameters=GPIO_Label
|
||||
PC13-TAMPER-RTC.GPIO_Label=LED_BLUE
|
||||
PC13-TAMPER-RTC.Signal=GPIO_Output
|
||||
|
|
Loading…
Reference in New Issue