Merge branch 'master' of http://git.brisky.space:441/btl143/firmware_clover
This commit is contained in:
29
app/by_button.c
Normal file
29
app/by_button.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "by_button.h"
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
button_event_t button_event;
|
||||
|
||||
void by_button_init(void)
|
||||
{
|
||||
gpio_init(BUTTON_LEFT_PIN, GPI, 1, GPI_PULL_UP);
|
||||
gpio_init(BUTTON_DOWN_PIN, GPI, 1, GPI_PULL_UP);
|
||||
gpio_init(BUTTON_UP_PIN, GPI, 1, GPI_PULL_UP);
|
||||
gpio_init(BUTTON_CENTER_PIN, GPI, 1, GPI_PULL_UP);
|
||||
gpio_init(BUTTON_RIGHT_PIN, GPI, 1, GPI_PULL_UP);
|
||||
gpio_init(BUTTON_SIDE_PIN, GPI, 1, GPI_PULL_UP);
|
||||
|
||||
exti_init(BUTTON_LEFT_PIN, EXTI_TRIGGER_FALLING);
|
||||
exti_init(BUTTON_DOWN_PIN, EXTI_TRIGGER_FALLING);
|
||||
exti_init(BUTTON_UP_PIN, EXTI_TRIGGER_FALLING);
|
||||
exti_init(BUTTON_CENTER_PIN, EXTI_TRIGGER_BOTH);
|
||||
exti_init(BUTTON_RIGHT_PIN, EXTI_TRIGGER_FALLING);
|
||||
exti_init(BUTTON_SIDE_PIN, EXTI_TRIGGER_FALLING);
|
||||
}
|
||||
|
||||
uint8_t by_button_get_status(void)
|
||||
{
|
||||
uint8_t temp_s = (uint8_t)button_event;
|
||||
button_event = button_event_none;
|
||||
return temp_s;
|
||||
}
|
||||
33
app/by_button.h
Normal file
33
app/by_button.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _BY_BUTTON_H__
|
||||
#define _BY_BUTTON_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define LONG_PRESS_THRESHOLD_MS (300ULL)
|
||||
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
|
||||
|
||||
#define BUTTON_UP_PIN E12
|
||||
#define BUTTON_DOWN_PIN E11
|
||||
#define BUTTON_LEFT_PIN E10
|
||||
#define BUTTON_RIGHT_PIN E14
|
||||
#define BUTTON_CENTER_PIN E13
|
||||
#define BUTTON_SIDE_PIN E15
|
||||
|
||||
typedef enum button_event_t{
|
||||
button_event_none = 0,
|
||||
button_event_up,
|
||||
button_event_down,
|
||||
button_event_left,
|
||||
button_event_right,
|
||||
button_event_center_sp,
|
||||
button_event_center_lp,
|
||||
button_event_side,
|
||||
}button_event_t;
|
||||
|
||||
extern button_event_t button_event;
|
||||
|
||||
void by_button_init(void);
|
||||
uint8_t by_button_get_status(void);
|
||||
|
||||
#endif
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "by_buzzer.h"
|
||||
#include "by_rt_button.h"
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
#include <string.h>
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
#define BUZZER_QUEUE_LENGTH 40
|
||||
|
||||
uint16_t queue_long = 0;
|
||||
uint32_t a[40] = {0};
|
||||
|
||||
uint16_t queue_long = 0;
|
||||
const uint32_t max_long = 40;
|
||||
uint32_t a[40];
|
||||
void queue_init(void)
|
||||
{
|
||||
memset(a, 0, sizeof(a));
|
||||
@@ -14,7 +15,7 @@ void queue_init(void)
|
||||
|
||||
void queue_add_element(int element)
|
||||
{
|
||||
if (queue_long < max_long) {
|
||||
if (queue_long < BUZZER_QUEUE_LENGTH) {
|
||||
a[queue_long] = element;
|
||||
queue_long += 1;
|
||||
}
|
||||
@@ -38,5 +39,25 @@ void queue_pop_read(void)
|
||||
|
||||
void by_buzzer_init(void)
|
||||
{
|
||||
queue_init();
|
||||
pwm_init(BUZZER_PIN, 2000, 0);
|
||||
|
||||
by_buzzer_add(1250);
|
||||
by_buzzer_add(1500);
|
||||
by_buzzer_add(1750);
|
||||
}
|
||||
|
||||
void by_buzzer_add(uint16_t tone)
|
||||
{
|
||||
queue_add_element(tone);
|
||||
}
|
||||
|
||||
void by_buzzer_run(void)
|
||||
{
|
||||
if (queue_long != 0) {
|
||||
pwm_init(BUZZER_PIN, a[0], 5000);
|
||||
queue_pop_element();
|
||||
system_delay_ms(100);
|
||||
pwm_set_duty(BUZZER_PIN, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
#ifndef _BY_BUZZER_H__
|
||||
#define _BY_BUZZER_H__
|
||||
|
||||
#include "by_rt_button.h"
|
||||
|
||||
#include "stdio.h"
|
||||
#include "ch32v30x.h"
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
#define BY_PRESS_SHORT 2000
|
||||
#define BY_PRESS_LONG 2500
|
||||
#define BY_FORWARD 1500
|
||||
#define BY_BACKWARD 1800
|
||||
#define BUZZER_PIN TIM3_PWM_MAP0_CH2_A7
|
||||
extern void by_buzzer_init(void);
|
||||
extern void queue_init(void);
|
||||
extern void queue_add_element(int element);
|
||||
extern void queue_pop_element(void);
|
||||
extern void queue_pop_read(void);
|
||||
#define BUZZER_PIN TIM4_PWM_MAP1_CH3_D14
|
||||
|
||||
extern uint32_t a[40];
|
||||
extern uint16_t queue_long;
|
||||
extern const uint32_t max_long;
|
||||
extern uint8_t queue_flag;
|
||||
|
||||
extern void queue_init(void);
|
||||
extern void queue_add_element(int element);
|
||||
extern void queue_pop_element(void);
|
||||
extern void queue_pop_read(void);
|
||||
extern void by_buzzer_init(void);
|
||||
extern void by_buzzer_add(uint16_t tone);
|
||||
extern void by_buzzer_run(void);
|
||||
#endif
|
||||
29
app/by_led.c
Normal file
29
app/by_led.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "by_led.h"
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
#define LED_WARN_PIN E9
|
||||
#define LED_INFO_PIN E8
|
||||
|
||||
uint8_t led_warn_status = 1;
|
||||
uint8_t led_info_status = 1;
|
||||
|
||||
// TODO 将队列抽象出去,具有 blink 属性的设备均可使用
|
||||
|
||||
void by_led_init(void)
|
||||
{
|
||||
gpio_init(LED_WARN_PIN, GPO, 0, GPO_PUSH_PULL);
|
||||
gpio_init(LED_INFO_PIN, GPO, 0, GPO_PUSH_PULL);
|
||||
}
|
||||
|
||||
void by_led_warn_blink(void)
|
||||
{
|
||||
led_warn_status = !led_warn_status;
|
||||
gpio_set_level(LED_WARN_PIN, led_warn_status);
|
||||
}
|
||||
|
||||
void by_led_info_blink(void)
|
||||
{
|
||||
led_info_status = !led_info_status;
|
||||
gpio_set_level(LED_INFO_PIN, led_info_status);
|
||||
}
|
||||
8
app/by_led.h
Normal file
8
app/by_led.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _BY_LED_H__
|
||||
#define _BY_LED_H__
|
||||
|
||||
extern void by_led_init(void);
|
||||
extern void by_led_warn_blink(void);
|
||||
extern void by_led_info_blink(void);
|
||||
|
||||
#endif
|
||||
@@ -1,26 +0,0 @@
|
||||
#include "by_rt_button.h"
|
||||
#include "zf_common_headfile.h"
|
||||
uint8_t rotate_button;
|
||||
|
||||
void by_gpio_init(void)
|
||||
{
|
||||
gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP);
|
||||
}
|
||||
|
||||
void by_exit_init(void)
|
||||
{
|
||||
exti_init(E9, EXTI_TRIGGER_FALLING);
|
||||
exti_init(E11, EXTI_TRIGGER_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 查询旋钮状态 - 查询后状态归零
|
||||
*
|
||||
* @return uint8_t 当前旋钮状态
|
||||
*/
|
||||
uint8_t by_get_rb_status(void)
|
||||
{
|
||||
uint8_t temp_s = rotate_button;
|
||||
rotate_button = 0;
|
||||
return temp_s;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef _BY_RT_BUTTON_H__
|
||||
#define _BY_RT_BUTTON_H__
|
||||
|
||||
#include "stdio.h"
|
||||
#include "ch32v30x.h"
|
||||
|
||||
#define LONG_PRESS_THRESHOLD_MS (300ULL)
|
||||
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
|
||||
|
||||
typedef enum rotate_button_event {
|
||||
rotate_button_press_short = 1,
|
||||
rotate_button_press_long = 2,
|
||||
rotate_button_forward = 3,
|
||||
rotate_button_backward = 4,
|
||||
} rotate_button_event;
|
||||
|
||||
extern uint8_t rotate_button;
|
||||
|
||||
extern void by_exit_init(void);
|
||||
extern void by_gpio_init(void);
|
||||
extern uint8_t by_get_rb_status(void);
|
||||
extern void by_ips_show(void);
|
||||
|
||||
#endif
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "gl_state.h"
|
||||
#include "gl_img_process.h"
|
||||
#include "gl_common.h"
|
||||
#include "main.h"
|
||||
#include "gl_handle_img.h"
|
||||
#include "gl_transform_table.h"
|
||||
#include "gl_get_corners.h"
|
||||
|
||||
129
app/isr.c
129
app/isr.c
@@ -34,10 +34,11 @@
|
||||
********************************************************************************************************************/
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
#include "by_rt_button.h"
|
||||
#include "jj_blueteeth.h"
|
||||
#include "by_tiny_frame.h"
|
||||
#include "by_button.h"
|
||||
#include "by_buzzer.h"
|
||||
#include "jj_blueteeth.h"
|
||||
|
||||
#include "by_tiny_frame_parse.h"
|
||||
|
||||
void NMI_Handler(void) __attribute__((interrupt()));
|
||||
void HardFault_Handler(void) __attribute__((interrupt()));
|
||||
@@ -92,17 +93,18 @@ void USART1_IRQHandler(void)
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
|
||||
uart_query_byte(UART_2, &bt_buffer);
|
||||
bt_rx_flag = true;
|
||||
uint8_t data_s = 0;
|
||||
uart_query_byte(UART_2, &data_s);
|
||||
by_tiny_frame_parse_uart_handle(data_s);
|
||||
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
|
||||
}
|
||||
}
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) {
|
||||
#if DEBUG_UART_USE_INTERRUPT // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> debug <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
debug_interrupr_handler(); // <20><><EFBFBD><EFBFBD> debug <20><><EFBFBD>ڽ<EFBFBD><DABD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ݻᱻ debug <20><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
#endif // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD> DEBUG_UART_INDEX <20><><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD>Ӧ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ж<EFBFBD>ȥ
|
||||
#if DEBUG_UART_USE_INTERRUPT // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> debug <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
// debug_interrupr_handler(); // <20><><EFBFBD><EFBFBD> debug <20><><EFBFBD>ڽ<EFBFBD><DABD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ݻᱻ debug <20><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
|
||||
#endif // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD> DEBUG_UART_INDEX <20><><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD>Ӧ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ж<EFBFBD>ȥ
|
||||
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
|
||||
}
|
||||
}
|
||||
@@ -199,14 +201,6 @@ void EXTI9_5_IRQHandler(void)
|
||||
EXTI_ClearITPendingBit(EXTI_Line8);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line9)) {
|
||||
|
||||
if (SET == gpio_get_level(E10)) {
|
||||
rotate_button = rotate_button_backward;
|
||||
queue_add_element(BY_BACKWARD);
|
||||
} else {
|
||||
rotate_button = rotate_button_forward;
|
||||
queue_add_element(BY_FORWARD);
|
||||
}
|
||||
EXTI_ClearITPendingBit(EXTI_Line9);
|
||||
}
|
||||
}
|
||||
@@ -214,57 +208,75 @@ void EXTI9_5_IRQHandler(void)
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line10)) {
|
||||
|
||||
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A10/B10..E10) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
|
||||
|
||||
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A10/B10..E10) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
|
||||
|
||||
if (button_event == button_event_none) {
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(BUTTON_LEFT_PIN)) {
|
||||
button_event = button_event_left;
|
||||
}
|
||||
by_buzzer_add(1250);
|
||||
}
|
||||
EXTI_ClearITPendingBit(EXTI_Line10);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line11)) {
|
||||
static uint64_t time_via = 0;
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(E11)) {
|
||||
time_via = system_get_tick();
|
||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||
} else if (SET == gpio_get_level(E11)) {
|
||||
time_via = system_get_tick() - time_via;
|
||||
if (time_via > LONG_PRESS_THRESHOLD_TICK) {
|
||||
rotate_button = rotate_button_press_long;
|
||||
queue_add_element(BY_PRESS_LONG);
|
||||
|
||||
} else {
|
||||
rotate_button = rotate_button_press_short;
|
||||
queue_add_element(BY_PRESS_SHORT);
|
||||
if (button_event == button_event_none) {
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(BUTTON_DOWN_PIN)) {
|
||||
button_event = button_event_down;
|
||||
}
|
||||
time_via = 0;
|
||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||
by_buzzer_add(1250);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
|
||||
EXTI_ClearITPendingBit(EXTI_Line12);
|
||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
|
||||
if (button_event == button_event_none) {
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(BUTTON_UP_PIN)) {
|
||||
button_event = button_event_up;
|
||||
}
|
||||
by_buzzer_add(1250);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line13)) {
|
||||
// -----------------* ToF INT <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
|
||||
tof_module_exti_handler();
|
||||
// -----------------* ToF INT <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
|
||||
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A13/B13..E13) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
|
||||
|
||||
// <20>˴<EFBFBD><CBB4><EFBFBD>д<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> (A13/B13..E13) <20><><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD>
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line13);
|
||||
EXTI_ClearITPendingBit(EXTI_Line12);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line13)) {
|
||||
if (button_event == button_event_none) {
|
||||
static uint64_t time_via = 0;
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(BUTTON_CENTER_PIN)) {
|
||||
time_via = system_get_tick();
|
||||
} else if (SET == gpio_get_level(BUTTON_CENTER_PIN)) {
|
||||
time_via = system_get_tick() - time_via;
|
||||
if (time_via > LONG_PRESS_THRESHOLD_TICK) {
|
||||
button_event = button_event_center_lp;
|
||||
by_buzzer_add(2000);
|
||||
} else {
|
||||
button_event = button_event_center_sp;
|
||||
by_buzzer_add(1800);
|
||||
}
|
||||
time_via = 0;
|
||||
}
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line14)) {
|
||||
// -----------------* DM1XA <20><><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
|
||||
dm1xa_light_callback();
|
||||
// -----------------* DM1XA <20><><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
|
||||
EXTI_ClearITPendingBit(EXTI_Line14);
|
||||
EXTI_ClearITPendingBit(EXTI_Line13);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line14)) {
|
||||
if (button_event == button_event_none) {
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(BUTTON_RIGHT_PIN)) {
|
||||
button_event = button_event_right;
|
||||
by_buzzer_add(1250);
|
||||
}
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line15)) {
|
||||
// -----------------* DM1XA <20><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
|
||||
dm1xa_sound_callback();
|
||||
// -----------------* DM1XA <20><>/<2F><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> Ԥ<><D4A4><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *-----------------
|
||||
EXTI_ClearITPendingBit(EXTI_Line15);
|
||||
EXTI_ClearITPendingBit(EXTI_Line14);
|
||||
}
|
||||
if (SET == EXTI_GetITStatus(EXTI_Line15)) {
|
||||
if (button_event == button_event_none) {
|
||||
system_delay_ms(10);
|
||||
if (RESET == gpio_get_level(BUTTON_SIDE_PIN)) {
|
||||
button_event = button_event_side;
|
||||
by_buzzer_add(2000);
|
||||
by_buzzer_add(1500);
|
||||
}
|
||||
}
|
||||
EXTI_ClearITPendingBit(EXTI_Line15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +284,7 @@ void TIM1_UP_IRQHandler(void)
|
||||
{
|
||||
if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) {
|
||||
TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
|
||||
by_tiny_frame_parse_timer_handle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,74 +1,32 @@
|
||||
#include "jj_blueteeth.h"
|
||||
bool bt_rx_flag = false;
|
||||
bool bt_run_flag = false;
|
||||
bool bt_flow_flag = false;
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
#define BT_UART_BAUDRATE (115200)
|
||||
#define BT_UART_INDEX UART_8
|
||||
#define BT_UART_TX_PIN UART8_MAP0_TX_C4
|
||||
#define BT_UART_RX_PIN UART8_MAP0_RX_C5
|
||||
|
||||
bool bt_rx_flag = false;
|
||||
uint8_t bt_buffer; // 接收字符存入
|
||||
uint32_t bt_run = 0;
|
||||
uint32_t bt_flow = 0;
|
||||
float bt_angle = 0.0f;
|
||||
enum bt_order {
|
||||
Start_work = 0x01,
|
||||
Turn_Left = 0x02,
|
||||
Turn_Right = 0x03,
|
||||
Speed_up = 0x04,
|
||||
Speed_down = 0x05,
|
||||
Run_flag = 0x06,
|
||||
Flow_flag = 0x08,
|
||||
Flow_up = 0x09,
|
||||
Flow_down = 0x10,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 蓝牙初始化
|
||||
* @retval 无
|
||||
*/
|
||||
void jj_bt_init()
|
||||
{
|
||||
uart_init(UART_2, 115200, UART2_MAP1_TX_D5, UART2_MAP1_RX_D6);
|
||||
uart_rx_interrupt(UART_2, ENABLE);
|
||||
uart_init(BT_UART_INDEX, BT_UART_BAUDRATE, BT_UART_TX_PIN, UART8_MAP0_RX_C5);
|
||||
uart_rx_interrupt(BT_UART_INDEX, ENABLE);
|
||||
}
|
||||
/**
|
||||
* @brief 蓝牙中断回调
|
||||
*
|
||||
*@brief 蓝牙中断回调函数
|
||||
*/
|
||||
void jj_bt_run()
|
||||
{
|
||||
if (bt_rx_flag) {
|
||||
switch (bt_buffer) {
|
||||
case Start_work:
|
||||
|
||||
break;
|
||||
case Turn_Left:
|
||||
|
||||
break;
|
||||
case Turn_Right:
|
||||
|
||||
break;
|
||||
case Speed_down:
|
||||
bt_run -= 10;
|
||||
break;
|
||||
case Speed_up:
|
||||
bt_run += 10;
|
||||
break;
|
||||
case Run_flag:
|
||||
bt_run_flag = !bt_run_flag;
|
||||
break;
|
||||
case Flow_flag:
|
||||
bt_flow_flag = !bt_flow_flag;
|
||||
break;
|
||||
case Flow_up:
|
||||
bt_flow += 20;
|
||||
break;
|
||||
case Flow_down:
|
||||
bt_flow -= 20;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bt_rx_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
void bt_printf(const char *format, ...)
|
||||
void jj_bt_printf(const char *format, ...)
|
||||
{
|
||||
char sbuf[40];
|
||||
va_list args;
|
||||
@@ -77,8 +35,8 @@ void bt_printf(const char *format, ...)
|
||||
va_end(args);
|
||||
|
||||
for (uint16_t i = 0; i < strlen(sbuf); i++) {
|
||||
while (USART_GetFlagStatus((USART_TypeDef *)uart_index[UART_2], USART_FLAG_TC) == RESET)
|
||||
while (USART_GetFlagStatus((USART_TypeDef *)uart_index[BT_UART_INDEX], USART_FLAG_TC) == RESET)
|
||||
;
|
||||
USART_SendData((USART_TypeDef *)uart_index[UART_2], sbuf[i]);
|
||||
USART_SendData((USART_TypeDef *)uart_index[BT_UART_INDEX], sbuf[i]);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,9 @@
|
||||
#ifndef _JJ_BLUETEETH_H_
|
||||
#define _JJ_BLUETEETH_H_
|
||||
#include "stdio.h"
|
||||
#include "zf_driver_uart.h"
|
||||
|
||||
extern bool bt_rx_flag;
|
||||
extern bool bt_run_flag;
|
||||
extern bool bt_flow_flag;
|
||||
extern uint8_t bt_buffer;
|
||||
extern uint32_t bt_run;
|
||||
extern uint32_t bt_flow;
|
||||
extern float bt_angle;
|
||||
#include "stdio.h"
|
||||
|
||||
void jj_bt_init();
|
||||
void jj_bt_run();
|
||||
void bt_printf(const char *format, ...);
|
||||
|
||||
void jj_bt_printf(const char *format, ...);
|
||||
#endif
|
||||
@@ -5,28 +5,40 @@
|
||||
PARAM_INFO Param_Data[DATA_NUM];
|
||||
soft_iic_info_struct eeprom_param;
|
||||
TYPE_UNION iic_buffer[DATA_IN_FLASH_NUM];
|
||||
|
||||
|
||||
TYPE_UNION tiny_frame_param[20];
|
||||
uint32_t *addre[2];
|
||||
float data0 = 1.0f;
|
||||
float data1 = 1.05f;
|
||||
float data2 = 10.0f;
|
||||
float data3 = 100.0f;
|
||||
float data4 = 4.0f;
|
||||
float data5 = 66.0f;
|
||||
float data6 = 13.130f;
|
||||
float data7 = 10.0f;
|
||||
float data8 = 0.0f;
|
||||
/**
|
||||
* @brief 参数初始化注册
|
||||
*
|
||||
*/
|
||||
void jj_param_eeprom_init()
|
||||
void jj_param_eeprom_init(void)
|
||||
{
|
||||
soft_iic_init(&eeprom_param, K24C02_DEV_ADDR, K24C02_SOFT_IIC_DELAY, K24C02_SCL_PIN, K24C02_SDA_PIN); // eeprom初始化
|
||||
//PARAM_REG(CA_PT_MAXLEN, &PT_MAXLEN, EFLOAT, 1, "PT_MAXLEN:"); // 注冊
|
||||
// PARAM_REG(CA_FIX_BINTHRESHOLD, &FIX_BINTHRESHOLD, EFLOAT, 1, "FIX_BINTHRESHOLD:"); // 注冊
|
||||
// PARAM_REG(CA_PIXPERMETER, &PIXPERMETER, EFLOAT, 1, "PIXPERMETER:"); // 注冊
|
||||
// PARAM_REG(CA_RESAMPLEDIST, &RESAMPLEDIST, EFLOAT, 1, "RESAMPLEDIST:"); // 注冊
|
||||
// PARAM_REG(CA_COMMON_AIM, &COMMON_AIM, EFLOAT, 1, "COMMON_AIM:"); // 注冊
|
||||
// PARAM_REG(CA_CROSS_AIM, &CROSS_AIM, EFLOAT, 1, "CROSS_AIM:");
|
||||
|
||||
PARAM_REG(angle_Kp, &data0, EFLOAT, 1, "an_P:"); // 注冊
|
||||
PARAM_REG(angle_Ki, &data1, EFLOAT, 1, "an_I:"); // 注冊
|
||||
PARAM_REG(angle_Kd, &data2, EFLOAT, 1, "an_D:"); // 注冊
|
||||
PARAM_REG(imgax_Kp, &data3, EFLOAT, 1, "im_P:"); // 注冊
|
||||
PARAM_REG(imgax_Ki, &data4, EFLOAT, 1, "im_I:"); // 注冊
|
||||
PARAM_REG(imgax_Kd, &data5, EFLOAT, 1, "im_D:");
|
||||
PARAM_REG(other , &data6, EFLOAT, 1, "add:");
|
||||
PARAM_REG(delta_x , &data7, EFLOAT, 2, "delta_x:");
|
||||
PARAM_REG(delta_y , &data8, EFLOAT, 0, "delta_y:");
|
||||
jj_param_read(); // 注冊
|
||||
}
|
||||
/**
|
||||
* @brief 参数写入
|
||||
*
|
||||
*/
|
||||
void jj_param_write()
|
||||
void jj_param_write(void)
|
||||
{
|
||||
for (uint8 i = 0; i < DATA_IN_FLASH_NUM; i++) {
|
||||
switch (Param_Data[i].type) {
|
||||
@@ -34,15 +46,15 @@ void jj_param_write()
|
||||
iic_buffer[i].f32 = *((float *)(Param_Data[i].p_data));
|
||||
break;
|
||||
case EUINT32:
|
||||
iic_buffer[i].u32 = *((uint32_t *)(Param_Data[i].p_data));
|
||||
iic_buffer[i].u32 = *((uint32 *)(Param_Data[i].p_data));
|
||||
break;
|
||||
case EINT32:
|
||||
iic_buffer[i].s32 = *((int32_t *)(Param_Data[i].p_data));
|
||||
iic_buffer[i].s32 = *((int32 *)(Param_Data[i].p_data));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
soft_iic_write_8bit_registers(&eeprom_param, 4 * i, (uint8_t *)&iic_buffer[i], 4);
|
||||
eep_soft_iic_write_8bit_registers(&eeprom_param, (4 * i) >> 8, (4 * i), (uint8 *)&iic_buffer[i], 4);
|
||||
system_delay_ms(10);
|
||||
}
|
||||
}
|
||||
@@ -50,11 +62,11 @@ void jj_param_write()
|
||||
* @brief 参数读出
|
||||
*
|
||||
*/
|
||||
void jj_param_read()
|
||||
void jj_param_read(void)
|
||||
{
|
||||
for (uint8 i = 0; i < DATA_IN_FLASH_NUM; i++) {
|
||||
|
||||
soft_iic_read_8bit_registers(&eeprom_param, 4 * i, (uint8 *)&iic_buffer[i], 4);
|
||||
eep_soft_iic_read_8bit_registers(&eeprom_param, (4 * i) >> 8, (4 * i), (uint8 *)&iic_buffer[i], 4);
|
||||
switch (Param_Data[i].type) {
|
||||
case EFLOAT:
|
||||
*((float *)(Param_Data[i].p_data)) =
|
||||
|
||||
@@ -12,19 +12,28 @@
|
||||
Param_Data[_data_tag_].p_data = (void *)_p_data_; \
|
||||
Param_Data[_data_tag_].type = _type_; \
|
||||
Param_Data[_data_tag_].cmd = _cmd_; \
|
||||
Param_Data[_data_tag_].text = _text_; \
|
||||
//zf_assert(sizeof(_p_data_)<4);
|
||||
Param_Data[_data_tag_].text = _text_;
|
||||
|
||||
typedef enum {
|
||||
DATA_HEAD = -1,
|
||||
CA_PT_MAXLEN,
|
||||
CA_FIX_BINTHRESHOLD,
|
||||
CA_PIXPERMETER,
|
||||
CA_RESAMPLEDIST,
|
||||
CA_COMMON_AIM,
|
||||
CA_CROSS_AIM,
|
||||
|
||||
Page1_head=0,
|
||||
|
||||
angle_Kp=Page1_head,
|
||||
angle_Ki,
|
||||
angle_Kd,
|
||||
other,
|
||||
|
||||
Page2_head,
|
||||
// 第二页参数
|
||||
imgax_Kp=Page2_head,
|
||||
imgax_Ki,
|
||||
imgax_Kd,
|
||||
|
||||
Page3_head,
|
||||
DATA_IN_FLASH_NUM,
|
||||
|
||||
delta_x,
|
||||
delta_y,
|
||||
DATA_NUM,
|
||||
} data_tag_t;
|
||||
|
||||
@@ -38,22 +47,21 @@ typedef union {
|
||||
uint32_t u32;
|
||||
int32_t s32;
|
||||
float f32;
|
||||
uint8_t u8[4];
|
||||
uint8_t u8;
|
||||
} TYPE_UNION;
|
||||
|
||||
typedef struct {
|
||||
void *p_data;
|
||||
ENUM_TYPE type;
|
||||
uint8_t cmd;
|
||||
uint8_t cmd;//01:仅存储 00:仅显示 02:传输并显示
|
||||
char *text;
|
||||
} PARAM_INFO;
|
||||
|
||||
extern soft_iic_info_struct eeprom_param;
|
||||
extern PARAM_INFO Param_Data[DATA_NUM];
|
||||
extern TYPE_UNION iic_buffer[DATA_IN_FLASH_NUM];
|
||||
|
||||
void jj_param_eeprom_init();
|
||||
void jj_param_read();
|
||||
void jj_param_write();
|
||||
|
||||
extern TYPE_UNION tiny_frame_param[20];
|
||||
void jj_param_eeprom_init(void);
|
||||
void jj_param_write(void);
|
||||
void jj_param_read(void);
|
||||
extern float data7;
|
||||
#endif
|
||||
78
app/main.c
78
app/main.c
@@ -21,51 +21,77 @@
|
||||
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
||||
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
||||
********************************************************************************************************************/
|
||||
#include "zf_common_headfile.h"
|
||||
#include "gl_headfile.h"
|
||||
#include "by_rt_button.h"
|
||||
#include "./page/page.h"
|
||||
#include "jj_blueteeth.h"
|
||||
#include "jj_param.h"
|
||||
#include "./page/page_ui_widget.h"
|
||||
#include "page.h"
|
||||
#include "by_tiny_frame.h"
|
||||
#include "by_buzzer.h"
|
||||
#include "by_led.h"
|
||||
#include "jj_param.h"
|
||||
#include "jj_blueteeth.h"
|
||||
|
||||
/** 测试完成后移除 **/
|
||||
#include "by_tiny_frame_parse.h"
|
||||
#include "by_tiny_frame_pack.h"
|
||||
uint32_t data_test;
|
||||
/** 测试完成后移除 **/
|
||||
|
||||
void test(by_tf_parse_frame_t frame_s, uint8_t status)
|
||||
{
|
||||
printf("parse done\r\n");
|
||||
printf("--cmd: %0.2X\n--reg_addr: %0.4X\n--data: %0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
||||
if (status) {
|
||||
printf("noooooooo!\r\n");
|
||||
} else {
|
||||
printf("hhhhhhok\r\n");
|
||||
}
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
|
||||
clock_init(SYSTEM_CLOCK_120M);
|
||||
clock_init(SYSTEM_CLOCK_144M);
|
||||
system_delay_init();
|
||||
debug_init();
|
||||
mt9v03x_init();
|
||||
ips200_init(IPS200_TYPE_SPI);
|
||||
by_gpio_init();
|
||||
by_exit_init();
|
||||
|
||||
by_led_init();
|
||||
// by_buzzer_init();
|
||||
by_button_init();
|
||||
|
||||
jj_bt_init();
|
||||
by_buzzer_init();
|
||||
jj_param_eeprom_init();
|
||||
|
||||
Page_Init();
|
||||
|
||||
|
||||
pit_ms_init(TIM1_PIT, 1);
|
||||
|
||||
by_tiny_frame_init();
|
||||
printf("start running\r\n");
|
||||
tiny_frame_param[0].f32 = 100.5f;
|
||||
// by_tiny_frame_read(0x0D, 0x4059, &data_test);
|
||||
while (1) {
|
||||
Page_Run();
|
||||
jj_bt_run();
|
||||
queue_pop_read();
|
||||
// by_buzzer_run();
|
||||
by_tiny_frame_write(0x0D, 0x0000, tiny_frame_param[0].u32);
|
||||
by_tiny_frame_run();
|
||||
system_delay_ms(10);
|
||||
if (mt9v03x_finish_flag) {
|
||||
// 该操作消耗大概 1970 个 tick,折合约 110us
|
||||
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
||||
// adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17);
|
||||
// ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0);
|
||||
mt9v03x_finish_flag = 0;
|
||||
state_type = COMMON_STATE;
|
||||
img_processing();
|
||||
get_corners();
|
||||
aim_distance = COMMON_AIM;
|
||||
tracking();
|
||||
ElementJudge();
|
||||
ElementRun();
|
||||
MidLineTrack();
|
||||
ips200_show_float(0,180,pure_angle,2,2);
|
||||
ips200_show_int(0, 200, track_type, 2);
|
||||
ips200_show_int(0, 220, garage_type, 2);
|
||||
ips200_show_int(0, 240, cross_type, 2);
|
||||
ips200_show_int(0, 260, circle_type, 2);
|
||||
by_led_info_blink();
|
||||
// state_type = COMMON_STATE;
|
||||
// img_processing();
|
||||
// get_corners();
|
||||
// aim_distance = COMMON_AIM;
|
||||
// tracking();
|
||||
// ElementJudge();
|
||||
// ElementRun();
|
||||
// MidLineTrack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
#endif // MAIN_H
|
||||
@@ -1,12 +1,16 @@
|
||||
#include "page.h"
|
||||
|
||||
#include "by_rt_button.h"
|
||||
#include "by_button.h"
|
||||
|
||||
PAGE_LIST pagelist[page_max];
|
||||
static uint8_t page_busy = 0;
|
||||
static int8_t now_page = page_menu;
|
||||
static int8_t new_page = page_menu;
|
||||
static int8_t now_page = page_menu;
|
||||
|
||||
int8_t Get_new_page(void)
|
||||
{
|
||||
return new_page;
|
||||
}
|
||||
/**
|
||||
* @brief 注册一个基本页面,包含一个初始化函数,循环函数,退出函数,事件函数
|
||||
* @param pageID: 页面编号
|
||||
@@ -17,11 +21,11 @@ static int8_t new_page = page_menu;
|
||||
* @param eventCallback: 事件函数回调
|
||||
* @retval 无
|
||||
*/
|
||||
void Page_Register(uint8_t pageID, char *pageText,
|
||||
void Page_Register(uint8_t pageID,
|
||||
CallbackFunction_t setupCallback, CallbackFunction_t loopCallback,
|
||||
CallbackFunction_t exitCallback, EventFunction_t eventCallback)
|
||||
{
|
||||
pagelist[pageID].Text = pageText;
|
||||
|
||||
pagelist[pageID].SetupCallback = setupCallback;
|
||||
pagelist[pageID].LoopCallback = loopCallback;
|
||||
pagelist[pageID].ExitCallback = exitCallback;
|
||||
@@ -89,8 +93,8 @@ uint8_t Page_GetStatus(void)
|
||||
*/
|
||||
void Page_Run(void)
|
||||
{
|
||||
uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态
|
||||
if(temp_status){
|
||||
uint8_t temp_status = by_button_get_status(); // 轮询旋钮状态
|
||||
if (temp_status) {
|
||||
pagelist[now_page].EventCallback(temp_status);
|
||||
}
|
||||
|
||||
@@ -118,14 +122,16 @@ void Page_Run(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面初始化(注册,构建) ATTENTION 在此处添加新加入的页面
|
||||
* @brief 页面初始化(注册,构建)ATTENTION 在此处添加新加入的页面
|
||||
*
|
||||
*/
|
||||
void Page_Init(void)
|
||||
{
|
||||
PAGE_REG(page_menu);
|
||||
PAGE_REG(page_rtcam);
|
||||
PAGE_REG(page_param);
|
||||
PAGE_REG(page_menu, "main");
|
||||
PAGE_REG(page_rtcam, "rtcam");
|
||||
PAGE_REG(page_param1, "Param1");
|
||||
PAGE_REG(page_param2, "param2");
|
||||
PAGE_REG(page_dparam, "dparam");
|
||||
// PAGE_REG(page_argv);
|
||||
// PAGE_REG(page_sys);
|
||||
// PAGE_REG(page_run);
|
||||
|
||||
@@ -13,14 +13,16 @@
|
||||
|
||||
#include "zf_common_headfile.h"
|
||||
|
||||
#include "by_rt_button.h"
|
||||
#include "by_button.h"
|
||||
|
||||
enum PageID {
|
||||
PAGE_NULL = -1,
|
||||
//......
|
||||
page_menu,
|
||||
page_rtcam,
|
||||
page_param,
|
||||
page_param1,
|
||||
page_param2,
|
||||
page_dparam,
|
||||
// page_argv,
|
||||
// page_sys,
|
||||
// page_run,
|
||||
@@ -28,11 +30,11 @@ enum PageID {
|
||||
page_max,
|
||||
};
|
||||
|
||||
typedef enum page_event{
|
||||
page_event_forward = rotate_button_forward,
|
||||
page_event_backward = rotate_button_backward,
|
||||
page_event_press_short = rotate_button_press_short,
|
||||
page_event_press_long = rotate_button_press_long,
|
||||
typedef enum page_event {
|
||||
page_event_forward = button_event_up,
|
||||
page_event_backward = button_event_down,
|
||||
page_event_press_short = button_event_center_sp,
|
||||
page_event_press_long = button_event_center_lp,
|
||||
} page_event;
|
||||
|
||||
typedef void (*CallbackFunction_t)(void);
|
||||
@@ -45,16 +47,18 @@ typedef struct {
|
||||
EventFunction_t EventCallback;
|
||||
} PAGE_LIST;
|
||||
|
||||
//页面注册函数
|
||||
#define PAGE_REG(name)\
|
||||
do{\
|
||||
extern void PageRegister_##name(unsigned char pageID);\
|
||||
PageRegister_##name(name);\
|
||||
}while(0)
|
||||
// 页面注册函数
|
||||
#define PAGE_REG(_name_, _text_) \
|
||||
do { \
|
||||
extern void PageRegister_##_name_(unsigned char pageID); \
|
||||
PageRegister_##_name_(_name_); \
|
||||
} while (0); \
|
||||
pagelist[_name_].Text = _text_ ;
|
||||
|
||||
void Page_Register(uint8_t pageID, char *pageText,
|
||||
CallbackFunction_t setupCallback, CallbackFunction_t loopCallback,
|
||||
CallbackFunction_t exitCallback, EventFunction_t eventCallback);
|
||||
|
||||
void Page_Register(uint8_t pageID,
|
||||
CallbackFunction_t setupCallback, CallbackFunction_t loopCallback,
|
||||
CallbackFunction_t exitCallback, EventFunction_t eventCallback);
|
||||
|
||||
void Page_EventTransmit(unsigned char event);
|
||||
void Page_Shift(unsigned char pageID);
|
||||
@@ -63,7 +67,7 @@ void Page_OpenCurrentPage(void);
|
||||
uint8_t Page_GetStatus(void);
|
||||
void Page_Run(void);
|
||||
void Page_Init(void);
|
||||
int8_t Get_new_page(void);
|
||||
|
||||
extern PAGE_LIST pagelist[page_max];
|
||||
|
||||
#endif
|
||||
|
||||
72
app/page/page_dparam.c
Normal file
72
app/page/page_dparam.c
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "zf_common_headfile.h"
|
||||
#include "page_ui_widget.h"
|
||||
#include "page.h"
|
||||
#include "jj_param.h"
|
||||
// #define LINE_HEAD 1
|
||||
// #define LINE_END 7
|
||||
// static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||
// static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||
/***************************************************************************************
|
||||
*
|
||||
* 以下为页面模板函数
|
||||
*
|
||||
***************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief 页面初始化事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Setup()
|
||||
{
|
||||
ips200_clear();
|
||||
// 显示参数名称
|
||||
ips200_show_string(0, 0, "Dparam");
|
||||
|
||||
ips200_show_string(20, 18 + 2, (Param_Data[delta_x].text));
|
||||
ips200_show_string(20, 18 + 20, (Param_Data[delta_y].text));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面退出事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Exit()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面循环执行的内容
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Loop()
|
||||
{
|
||||
// 刷新参数数值
|
||||
ips200_show_float(90, 18 + 2, *((float *)(Param_Data[delta_x].p_data)), 4, 5);
|
||||
ips200_show_float(90, 18 + 20, *((float *)(Param_Data[delta_x].p_data)), 4, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面事件
|
||||
* @param btn:发出事件的按键
|
||||
* @param event:事件编号
|
||||
* @retval 无
|
||||
*/
|
||||
static void Event(page_event event)
|
||||
{
|
||||
if (page_event_press_long == event) {
|
||||
Page_Shift(page_menu);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面注册函数
|
||||
*
|
||||
* @param pageID
|
||||
*/
|
||||
void PageRegister_page_dparam(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Setup, Loop, Exit, Event);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ static void Setup()
|
||||
{
|
||||
ips200_clear();
|
||||
Print_Menu_p();
|
||||
Print_Curser(Curser, Curser_Last,RGB565_PURPLE);
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,9 +57,9 @@ static void Event(page_event event)
|
||||
Curser_Last = Curser;
|
||||
|
||||
if (page_event_forward == event) {
|
||||
Curser--; // 光标上移
|
||||
Curser++; // 光标上移
|
||||
} else if (page_event_backward == event) {
|
||||
Curser++; // 光标下移
|
||||
Curser--; // 光标下移
|
||||
} else if (page_event_press_short == event) {
|
||||
if (page_max > Curser && page_menu < Curser) {
|
||||
Page_Shift(Curser); // 切换到光标选中的页面
|
||||
@@ -72,7 +72,7 @@ static void Event(page_event event)
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
|
||||
Print_Curser(Curser, Curser_Last,RGB565_PURPLE);
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ static void Event(page_event event)
|
||||
*/
|
||||
void PageRegister_page_menu(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Text, Setup, Loop, Exit, Event);
|
||||
Page_Register(pageID, Setup, Loop, Exit, Event);
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
#include "jj_param.h"
|
||||
#include "page_ui_widget.h"
|
||||
#include "page.h"
|
||||
#include "math.h"
|
||||
#define LINE_HEAD 0
|
||||
#define LINE_END DATA_NUM - 2
|
||||
static char Text[] = "RealTime Param";
|
||||
int event_flag = 0;
|
||||
int32_t index_power = 0;
|
||||
static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||
void param_set();
|
||||
void param_printf();
|
||||
void param_change(uint8_t index, int param_event);
|
||||
/***************************************************************************************
|
||||
*
|
||||
* 以下为页面模板函数
|
||||
*
|
||||
***************************************************************************************/
|
||||
/**
|
||||
* @brief 页面初始化事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Setup()
|
||||
{
|
||||
ips200_clear();
|
||||
param_set();
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面退出事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Exit()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面循环执行的内容
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Loop()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief 页面事件
|
||||
* @param btn:发出事件的按键
|
||||
* @param event:事件编号
|
||||
* @retval 无
|
||||
*/
|
||||
static void Event(page_event event)
|
||||
{
|
||||
|
||||
if (0 == event_flag) {
|
||||
Curser_Last = Curser;
|
||||
if (page_event_forward == event) {
|
||||
Curser--; // 光标上移
|
||||
} else if (page_event_backward == event) {
|
||||
Curser++; // 光标下移
|
||||
} else if (page_event_press_short == event) {
|
||||
event_flag = 1; // 选中参数
|
||||
Print_Curser(Curser, Curser_Last, RGB565_RED);
|
||||
return;
|
||||
} else if (page_event_press_long == event) {
|
||||
jj_param_write();
|
||||
Page_Shift(page_menu);
|
||||
return;
|
||||
}
|
||||
if (Curser < LINE_HEAD) {
|
||||
Curser = LINE_END;
|
||||
} else if (Curser > LINE_END) {
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
} else if (1 == event_flag) {
|
||||
param_change(Curser, event);
|
||||
param_printf();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief 页面注册函数
|
||||
*
|
||||
* @param pageID
|
||||
*/
|
||||
void PageRegister_page_param(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Text, Setup, Loop, Exit, Event);
|
||||
}
|
||||
/**
|
||||
* @brief 参数显示更新
|
||||
*
|
||||
*/
|
||||
void param_printf()
|
||||
{
|
||||
if (EINT32 == Param_Data[Curser].type)
|
||||
ips200_show_int(50, Curser * 18 + 2, *((int32_t *)(Param_Data[Curser].p_data)), 5);
|
||||
else if (EUINT32 == Param_Data[Curser].type)
|
||||
ips200_show_uint(50, Curser * 18 + 2, *((uint32_t *)(Param_Data[Curser].p_data)), 5);
|
||||
else if (EFLOAT == Param_Data[Curser].type)
|
||||
ips200_show_float(50, Curser * 18 + 2, *((float *)(Param_Data[Curser].p_data)), 4, 5);
|
||||
}
|
||||
/**
|
||||
* @brief 参数初始化显示
|
||||
*
|
||||
*/
|
||||
void param_set()
|
||||
{
|
||||
for (int16_t i = 0; i < DATA_NUM - 1; i++) {
|
||||
ips200_show_string(10, i * 18 + 2, Param_Data[i].text);
|
||||
if (Param_Data[i].type == EINT32)
|
||||
ips200_show_int(50, i * 18 + 2, *((int32_t *)(Param_Data[i].p_data)), 5);
|
||||
else if (Param_Data[i].type == EFLOAT)
|
||||
ips200_show_float(50, i * 18 + 2, *((float *)(Param_Data[i].p_data)), 4, 5);
|
||||
}
|
||||
ips200_show_int(50, (DATA_NUM - 1) * 18 + 2, index_power, 5);
|
||||
}
|
||||
/**
|
||||
* @brief 参数改变
|
||||
*
|
||||
* @param index 当前指针所指参数索引
|
||||
* @param param_event 触发事件
|
||||
*/
|
||||
void param_change(uint8_t index, int param_event)
|
||||
{
|
||||
if (page_event_forward == param_event) {
|
||||
if (Param_Data[Curser].type == EFLOAT) {
|
||||
*((float *)(Param_Data[Curser].p_data)) += powf(10.0f, (float)index_power);
|
||||
} else if (Param_Data[Curser].type == EINT32) {
|
||||
*((int32_t *)(Param_Data[Curser].p_data)) += pow(10, index_power + 2);
|
||||
} else if (Param_Data[Curser].type == EUINT32) {
|
||||
*((uint32_t *)(Param_Data[Curser].p_data)) += pow(10, index_power + 2);
|
||||
}
|
||||
} else if (page_event_backward == param_event) {
|
||||
if (Param_Data[index].type == EFLOAT) {
|
||||
*((float *)(Param_Data[index].p_data)) -= powf(10.0f, (float)index_power);
|
||||
} else if (Param_Data[index].type == EINT32) {
|
||||
*((int32_t *)(Param_Data[index].p_data)) -= pow(10, index_power + 2);
|
||||
} else if (Param_Data[index].type == EUINT32) {
|
||||
*((uint32_t *)(Param_Data[index].p_data)) -= pow(10, index_power + 2);
|
||||
}
|
||||
} else if (page_event_press_short == param_event) {
|
||||
index_power++;
|
||||
if (index_power > 2) {
|
||||
index_power = -2;
|
||||
}
|
||||
ips200_show_int(50, (DATA_NUM - 1) * 18 + 2, index_power, 5);
|
||||
} else if (page_event_press_long == param_event) {
|
||||
event_flag = 0; // 回归选择参数事件
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,6 @@
|
||||
#define LINE_HEAD 11
|
||||
#define LINE_END 16
|
||||
|
||||
static char Text[] = "RealTime Image";
|
||||
|
||||
static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||
/***************************************************************************************
|
||||
@@ -81,7 +79,7 @@ static void Event(page_event event)
|
||||
*/
|
||||
void PageRegister_page_rtcam(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Text, Setup, Loop, Exit, Event);
|
||||
Page_Register(pageID, Setup, Loop, Exit, Event);
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
|
||||
160
app/page/page_sparam1.c
Normal file
160
app/page/page_sparam1.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "jj_param.h"
|
||||
#include "page_ui_widget.h"
|
||||
#include "page.h"
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_HEAD 1
|
||||
|
||||
static int16 pafrist;
|
||||
static int16 paend;
|
||||
static int16 palong;
|
||||
static int event_flag = 0;
|
||||
static int32_t index_power = 0;
|
||||
static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||
/***************************************************************************************
|
||||
*
|
||||
* 以下为页面模板函数
|
||||
*
|
||||
***************************************************************************************/
|
||||
/**
|
||||
* @brief 页面初始化事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Setup()
|
||||
{
|
||||
ips200_clear();
|
||||
|
||||
if (Get_new_page() == page_param1) {
|
||||
pafrist = 0;
|
||||
paend = Page2_head;
|
||||
ips200_show_string(0, 0, "Param1");
|
||||
} else if (Get_new_page() == page_param2) {
|
||||
pafrist = Page2_head;
|
||||
paend = Page3_head;
|
||||
ips200_show_string(0, 0, "Param2");
|
||||
}
|
||||
|
||||
palong = paend - pafrist;
|
||||
if (Curser < LINE_HEAD) {
|
||||
Curser = palong;
|
||||
} else if (Curser > palong) {
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
for (int16 i = 0; i < palong; i++) {
|
||||
ips200_show_string(20, i * 18 + 20, Param_Data[i + pafrist].text);
|
||||
if (Param_Data[i].type == EINT32)
|
||||
ips200_show_int(60, i * 18 + 20, *((int32 *)(Param_Data[i + pafrist].p_data)), 5);
|
||||
else if (Param_Data[i].type == EFLOAT)
|
||||
ips200_show_float(60, i * 18 + 20, *((float *)(Param_Data[i + pafrist].p_data)), 4, 5);
|
||||
}
|
||||
ips200_show_int(50, palong * 18 + 20, index_power, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面退出事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Exit()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面循环执行的内容
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Loop()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief 页面事件
|
||||
* @param btn:发出事件的按键
|
||||
* @param event:事件编号
|
||||
* @retval 无
|
||||
*/
|
||||
static void Event(page_event event)
|
||||
{
|
||||
|
||||
if (0 == event_flag) {
|
||||
|
||||
Curser_Last = Curser;
|
||||
if (page_event_forward == event) {
|
||||
Curser++; // 光标上移
|
||||
} else if (page_event_backward == event) {
|
||||
Curser--; // 光标下移
|
||||
} else if (page_event_press_short == event) {
|
||||
event_flag = 1; // 选中参数
|
||||
Print_Curser(Curser, Curser_Last, RGB565_RED);
|
||||
return;
|
||||
} else if (page_event_press_long == event) {
|
||||
jj_param_write();
|
||||
Page_Shift(page_menu);
|
||||
return;
|
||||
}
|
||||
if (Curser < LINE_HEAD) {
|
||||
Curser = palong;
|
||||
} else if (Curser > palong) {
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
} else if (1 == event_flag) {
|
||||
if (page_event_forward == event) {
|
||||
switch (Param_Data[Curser + pafrist - 1].type) {
|
||||
case EFLOAT:
|
||||
*((float *)(Param_Data[Curser + pafrist - 1].p_data)) += powf(10, index_power);
|
||||
break;
|
||||
case EINT32:
|
||||
*((int32 *)(Param_Data[Curser + pafrist - 1].p_data)) += 1;
|
||||
break;
|
||||
case EUINT32:
|
||||
*((uint32 *)(Param_Data[Curser + pafrist - 1].p_data)) += 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (page_event_backward == event) {
|
||||
switch (Param_Data[Curser + pafrist - 1].type) {
|
||||
case EFLOAT:
|
||||
*((float *)(Param_Data[Curser + pafrist - 1].p_data)) -= powf(10.0f, (float)index_power);
|
||||
break;
|
||||
case EINT32:
|
||||
*((int32 *)(Param_Data[Curser + pafrist - 1].p_data)) -= 1;
|
||||
break;
|
||||
case EUINT32:
|
||||
*((uint32 *)(Param_Data[Curser + pafrist - 1].p_data)) -= 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (page_event_press_short == event) {
|
||||
index_power++;
|
||||
if (index_power > 2) {
|
||||
index_power = -2;
|
||||
}
|
||||
ips200_show_int(50, palong * 18 + 20, index_power, 5);
|
||||
} else if (page_event_press_long == event) {
|
||||
event_flag = 0;
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
if (EINT32 == Param_Data[Curser + pafrist - 1].type)
|
||||
ips200_show_int(60, Curser * 18 + 2, *((int32 *)(Param_Data[Curser + pafrist - 1].p_data)), 5);
|
||||
else if (EUINT32 == Param_Data[Curser + pafrist - 1].type)
|
||||
ips200_show_uint(60, Curser * 18 + 2, *((int32 *)(Param_Data[Curser + pafrist - 1].p_data)), 5);
|
||||
else if (EFLOAT == Param_Data[Curser + pafrist - 1].type)
|
||||
ips200_show_float(60, Curser * 18 + 2, *((float *)(Param_Data[Curser + pafrist - 1].p_data)), 4, 5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面注册函数
|
||||
*
|
||||
* @param pageID
|
||||
*/
|
||||
void PageRegister_page_param1(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Setup, Loop, Exit, Event);
|
||||
}
|
||||
160
app/page/page_sparam2.c
Normal file
160
app/page/page_sparam2.c
Normal file
@@ -0,0 +1,160 @@
|
||||
#include "jj_param.h"
|
||||
#include "page_ui_widget.h"
|
||||
#include "page.h"
|
||||
#include <math.h>
|
||||
|
||||
#define LINE_HEAD 1
|
||||
|
||||
static int16 pafrist;
|
||||
static int16 paend;
|
||||
static int16 palong;
|
||||
static int event_flag = 0;
|
||||
static int32_t index_power = 0;
|
||||
static int8_t Curser = LINE_HEAD; // 定义光标位置
|
||||
static int8_t Curser_Last = LINE_HEAD; // 定义光标位置
|
||||
/***************************************************************************************
|
||||
*
|
||||
* 以下为页面模板函数
|
||||
*
|
||||
***************************************************************************************/
|
||||
/**
|
||||
* @brief 页面初始化事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Setup()
|
||||
{
|
||||
ips200_clear();
|
||||
|
||||
if (Get_new_page() == page_param1) {
|
||||
pafrist = 0;
|
||||
paend = Page2_head;
|
||||
ips200_show_string(0, 0, "Param1");
|
||||
} else if (Get_new_page() == page_param2) {
|
||||
pafrist = Page2_head;
|
||||
paend = Page3_head;
|
||||
ips200_show_string(0, 0, "Param2");
|
||||
}
|
||||
|
||||
palong = paend - pafrist;
|
||||
if (Curser < LINE_HEAD) {
|
||||
Curser = palong;
|
||||
} else if (Curser > palong) {
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
for (int16 i = 0; i < palong; i++) {
|
||||
ips200_show_string(20, i * 18 + 20, Param_Data[i + pafrist].text);
|
||||
if (Param_Data[i].type == EINT32)
|
||||
ips200_show_int(60, i * 18 + 20, *((int32 *)(Param_Data[i + pafrist].p_data)), 5);
|
||||
else if (Param_Data[i].type == EFLOAT)
|
||||
ips200_show_float(60, i * 18 + 20, *((float *)(Param_Data[i + pafrist].p_data)), 4, 5);
|
||||
}
|
||||
ips200_show_int(50, palong * 18 + 20, index_power, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面退出事件
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Exit()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面循环执行的内容
|
||||
* @param 无
|
||||
* @retval 无
|
||||
*/
|
||||
static void Loop()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @brief 页面事件
|
||||
* @param btn:发出事件的按键
|
||||
* @param event:事件编号
|
||||
* @retval 无
|
||||
*/
|
||||
static void Event(page_event event)
|
||||
{
|
||||
|
||||
if (0 == event_flag) {
|
||||
|
||||
Curser_Last = Curser;
|
||||
if (page_event_forward == event) {
|
||||
Curser++; // 光标上移
|
||||
} else if (page_event_backward == event) {
|
||||
Curser--; // 光标下移
|
||||
} else if (page_event_press_short == event) {
|
||||
event_flag = 1; // 选中参数
|
||||
Print_Curser(Curser, Curser_Last, RGB565_RED);
|
||||
return;
|
||||
} else if (page_event_press_long == event) {
|
||||
jj_param_write();
|
||||
Page_Shift(page_menu);
|
||||
return;
|
||||
}
|
||||
if (Curser < LINE_HEAD) {
|
||||
Curser = palong;
|
||||
} else if (Curser > palong) {
|
||||
Curser = LINE_HEAD;
|
||||
}
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
} else if (1 == event_flag) {
|
||||
if (page_event_forward == event) {
|
||||
switch (Param_Data[Curser + pafrist - 1].type) {
|
||||
case EFLOAT:
|
||||
*((float *)(Param_Data[Curser + pafrist - 1].p_data)) += powf(10, index_power);
|
||||
break;
|
||||
case EINT32:
|
||||
*((int32 *)(Param_Data[Curser + pafrist - 1].p_data)) += 1;
|
||||
break;
|
||||
case EUINT32:
|
||||
*((uint32 *)(Param_Data[Curser + pafrist - 1].p_data)) += 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (page_event_backward == event) {
|
||||
switch (Param_Data[Curser + pafrist - 1].type) {
|
||||
case EFLOAT:
|
||||
*((float *)(Param_Data[Curser + pafrist - 1].p_data)) -= powf(10.0f, (float)index_power);
|
||||
break;
|
||||
case EINT32:
|
||||
*((int32 *)(Param_Data[Curser + pafrist - 1].p_data)) -= 1;
|
||||
break;
|
||||
case EUINT32:
|
||||
*((uint32 *)(Param_Data[Curser + pafrist - 1].p_data)) -= 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (page_event_press_short == event) {
|
||||
index_power++;
|
||||
if (index_power > 2) {
|
||||
index_power = -2;
|
||||
}
|
||||
ips200_show_int(50, palong * 18 + 20, index_power, 5);
|
||||
} else if (page_event_press_long == event) {
|
||||
event_flag = 0;
|
||||
Print_Curser(Curser, Curser_Last, RGB565_PURPLE);
|
||||
}
|
||||
if (EINT32 == Param_Data[Curser + pafrist - 1].type)
|
||||
ips200_show_int(60, Curser * 18 + 2, *((int32 *)(Param_Data[Curser + pafrist - 1].p_data)), 5);
|
||||
else if (EUINT32 == Param_Data[Curser + pafrist - 1].type)
|
||||
ips200_show_uint(60, Curser * 18 + 2, *((int32 *)(Param_Data[Curser + pafrist - 1].p_data)), 5);
|
||||
else if (EFLOAT == Param_Data[Curser + pafrist - 1].type)
|
||||
ips200_show_float(60, Curser * 18 + 2, *((float *)(Param_Data[Curser + pafrist - 1].p_data)), 4, 5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 页面注册函数
|
||||
*
|
||||
* @param pageID
|
||||
*/
|
||||
void PageRegister_page_param2(unsigned char pageID)
|
||||
{
|
||||
Page_Register(pageID, Setup, Loop, Exit, Event);
|
||||
}
|
||||
38
app/tiny_frame/by_tiny_frame.c
Normal file
38
app/tiny_frame/by_tiny_frame.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "by_tiny_frame.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "crc16.h"
|
||||
#include "zf_common_headfile.h"
|
||||
#include "by_tiny_frame_config.h"
|
||||
#include "by_tiny_frame_parse.h"
|
||||
#include "by_tiny_frame_master_read.h"
|
||||
#include "by_tiny_frame_master_write.h"
|
||||
#include "by_tiny_frame_slave_read_write.h"
|
||||
|
||||
void by_tiny_frame_init(void)
|
||||
{
|
||||
/*** 初始化相关外设 ***/
|
||||
uart_init(BY_TF_UART_INDEX, BY_TF_UART_BAUDRATE, BY_TF_UART_TX_PIN, BY_TF_UART_RX_PIN);
|
||||
uart_rx_interrupt(BY_TF_UART_INDEX, ENABLE);
|
||||
|
||||
by_tiny_frame_parse_init();
|
||||
by_tiny_frame_pack_init();
|
||||
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
by_tiny_frame_parse_handle_register(by_tiny_frame_read_write_handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
void by_tiny_frame_run(void)
|
||||
{
|
||||
by_tiny_frame_parse_run();
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
by_tiny_frame_read_run();
|
||||
by_tiny_frame_write_run();
|
||||
#elif defined(BY_TF_DEVICE_SLAVE)
|
||||
by_tiny_frame_read_write_run();
|
||||
#endif
|
||||
}
|
||||
16
app/tiny_frame/by_tiny_frame.h
Normal file
16
app/tiny_frame/by_tiny_frame.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _BY_TINY_FRAME_H__
|
||||
#define _BY_TINY_FRAME_H__
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
#include "by_tiny_frame_master_read.h"
|
||||
#include "by_tiny_frame_master_write.h"
|
||||
#elif defined(BY_TF_DEVICE_SLAVE)
|
||||
#include "by_tiny_frame_slave_read_write.h"
|
||||
#endif
|
||||
|
||||
extern void by_tiny_frame_init(void);
|
||||
void by_tiny_frame_run(void);
|
||||
|
||||
#endif
|
||||
27
app/tiny_frame/by_tiny_frame_config.h
Normal file
27
app/tiny_frame/by_tiny_frame_config.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _BY_TINY_FRAME_CONFIG_H__
|
||||
#define _BY_TINY_FRAME_CONFIG_H__
|
||||
|
||||
#define BY_TF_DEBUG (1)
|
||||
|
||||
#define BY_TF_UART_TX_PIN (UART2_MAP0_TX_A2)
|
||||
#define BY_TF_UART_RX_PIN (UART2_MAP0_RX_A3)
|
||||
#define BY_TF_UART_INDEX (UART_2)
|
||||
#define BY_TF_UART_BAUDRATE (115200)
|
||||
|
||||
#define BY_TF_PARSE_BUFFER_SIZE (50)
|
||||
|
||||
// 注释此项则为主机,否则为从机
|
||||
// #define BY_TF_DEVICE_SLAVE
|
||||
|
||||
/********** 从机模式配置选项 **********/
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
// 从机地址 (多从机通信时注意修改地址,避免冲突)
|
||||
#define BY_TF_DEVICE_SLAVE_ADDRESS (0x0D)
|
||||
/********** 主机模式配置选项 **********/
|
||||
#else
|
||||
#define BY_TF_DEVICE_MASTER
|
||||
// 监听/解析 超时时间 单位毫秒
|
||||
#define BY_TF_PARSE_TIMEOUT (200)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
57
app/tiny_frame/by_tiny_frame_master_read.c
Normal file
57
app/tiny_frame/by_tiny_frame_master_read.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "by_tiny_frame_master_read.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
|
||||
uint32_t *data_p;
|
||||
|
||||
void by_tiny_frame_read_run(void)
|
||||
{
|
||||
}
|
||||
|
||||
void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data)
|
||||
{
|
||||
if (by_tiny_frame_pack_lock) {
|
||||
// 写入忙处理
|
||||
return;
|
||||
}
|
||||
|
||||
// 填充数据
|
||||
by_tf_pack_frame_t frame_s;
|
||||
frame_s.slave_id = slave_id;
|
||||
frame_s.cmd = BY_TINY_FRAME_READ_CMD_CODE;
|
||||
frame_s.reg_addr = reg_addr;
|
||||
frame_s.data = 0;
|
||||
|
||||
// 发送写请求
|
||||
by_tiny_frame_pack_send(&frame_s);
|
||||
// 设置响应监听 id
|
||||
by_tiny_frame_parse_set_listen_slave_id(slave_id);
|
||||
// 注册响应监听回调
|
||||
by_tiny_frame_parse_handle_register(by_tiny_frame_read_handle);
|
||||
// 开启响应监听
|
||||
by_tiny_frame_parse_start_listen();
|
||||
|
||||
by_tiny_frame_pack_lock = 0;
|
||||
}
|
||||
|
||||
void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
||||
{
|
||||
|
||||
by_tiny_frame_pack_lock = 0;
|
||||
if (!status) {
|
||||
*data_p = frame_s.data;
|
||||
}
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("****** READ REGISTER DONE ******\r\n");
|
||||
printf("SLAVE ID: 0x%0.2X\r\n", frame_s.frame[0]);
|
||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
||||
if (status) {
|
||||
printf("read operation failed!!!\r\n");
|
||||
} else {
|
||||
printf("read operation successful!!!\r\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
18
app/tiny_frame/by_tiny_frame_master_read.h
Normal file
18
app/tiny_frame/by_tiny_frame_master_read.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _BY_TINY_FRAME_MASTER_READ_H__
|
||||
#define _BY_TINY_FRAME_MASTER_READ_H__
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
|
||||
#include "by_tiny_frame_parse.h"
|
||||
#include "by_tiny_frame_pack.h"
|
||||
|
||||
#define BY_TINY_FRAME_READ_CMD_CODE (0x03)
|
||||
|
||||
extern void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data);
|
||||
extern void by_tiny_frame_read_run(void);
|
||||
extern void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
57
app/tiny_frame/by_tiny_frame_master_write.c
Normal file
57
app/tiny_frame/by_tiny_frame_master_write.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "by_tiny_frame_master_write.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
|
||||
#include "by_tiny_frame_pack.h"
|
||||
#include "by_tiny_frame_parse.h"
|
||||
|
||||
void by_tiny_frame_write_run(void)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data)
|
||||
{
|
||||
if(by_tiny_frame_pack_lock){
|
||||
//写入忙处理
|
||||
return;
|
||||
}
|
||||
|
||||
// 填充数据
|
||||
by_tf_pack_frame_t frame_s;
|
||||
frame_s.slave_id = slave_id;
|
||||
frame_s.cmd = BY_TINY_FRAME_WRITE_CMD_CODE;
|
||||
frame_s.reg_addr = reg_addr;
|
||||
frame_s.data = data;
|
||||
|
||||
// 发送写请求
|
||||
by_tiny_frame_pack_send(&frame_s);
|
||||
// 设置响应监听 id
|
||||
by_tiny_frame_parse_set_listen_slave_id(slave_id);
|
||||
// 注册响应监听回调
|
||||
by_tiny_frame_parse_handle_register(by_tiny_frame_write_handle);
|
||||
// 开启响应监听
|
||||
by_tiny_frame_parse_start_listen();
|
||||
|
||||
by_tiny_frame_pack_lock = 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
||||
{
|
||||
by_tiny_frame_pack_lock = 0;
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("****** WRITE REGISTER DONE ******\r\n");
|
||||
printf("SLAVE ID: 0x%0.2X\r\n", frame_s.frame[0]);
|
||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
||||
if (status) {
|
||||
printf("write operation failed!!!\r\n");
|
||||
|
||||
} else {
|
||||
printf("write operation successful!!!\r\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
18
app/tiny_frame/by_tiny_frame_master_write.h
Normal file
18
app/tiny_frame/by_tiny_frame_master_write.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _BY_TINY_FRAME_MASTER_WRITE_H__
|
||||
#define _BY_TINY_FRAME_MASTER_WRITE_H__
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
|
||||
#include "by_tiny_frame_parse.h"
|
||||
#include "by_tiny_frame_pack.h"
|
||||
|
||||
#define BY_TINY_FRAME_WRITE_CMD_CODE (0x06)
|
||||
|
||||
extern void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data);
|
||||
extern void by_tiny_frame_write_run(void);
|
||||
extern void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
42
app/tiny_frame/by_tiny_frame_pack.c
Normal file
42
app/tiny_frame/by_tiny_frame_pack.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "by_tiny_frame_pack.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "zf_common_headfile.h"
|
||||
#include "crc16.h"
|
||||
|
||||
uint8_t by_tiny_frame_pack_lock;
|
||||
|
||||
void by_tiny_frame_pack_init(void)
|
||||
{
|
||||
/** nothing to init **/
|
||||
by_tiny_frame_pack_lock = 0;
|
||||
}
|
||||
|
||||
void by_tiny_frame_pack_send(by_tf_pack_frame_t *frame_s)
|
||||
{
|
||||
uint16_t calc_crc_val = 0;
|
||||
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
frame_s->frame[0] = ((frame_s->slave_id << 1) + 1);
|
||||
#else
|
||||
frame_s->frame[0] = (frame_s->slave_id << 1);
|
||||
#endif
|
||||
|
||||
// 填充指令段
|
||||
frame_s->frame[1] = frame_s->cmd;
|
||||
// 填充寄存器地址段
|
||||
frame_s->frame[2] = (uint8_t)((frame_s->reg_addr >> 8) & 0xFF);
|
||||
frame_s->frame[3] = (uint8_t)(frame_s->reg_addr & 0xFF);
|
||||
// 填充数据段
|
||||
frame_s->frame[4] = (uint8_t)((frame_s->data >> 24) & 0xFF);
|
||||
frame_s->frame[5] = (uint8_t)((frame_s->data >> 16) & 0xFF);
|
||||
frame_s->frame[6] = (uint8_t)((frame_s->data >> 8) & 0xFF);
|
||||
frame_s->frame[7] = (uint8_t)(frame_s->data & 0xFF);
|
||||
// 填充 CRC 段
|
||||
calc_crc_val = crc16_check(frame_s->frame, (sizeof(frame_s->frame) - 2));
|
||||
frame_s->frame[8] = (uint8_t)((calc_crc_val >> 8) & 0xFF);
|
||||
frame_s->frame[9] = (uint8_t)(calc_crc_val & 0xFF);
|
||||
|
||||
/** 从串口发送 **/
|
||||
uart_write_buffer(BY_TF_UART_INDEX, frame_s->frame, sizeof(frame_s->frame));
|
||||
}
|
||||
26
app/tiny_frame/by_tiny_frame_pack.h
Normal file
26
app/tiny_frame/by_tiny_frame_pack.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _BY_TINY_FRAME_PACK_H__
|
||||
#define _BY_TINY_FRAME_PACK_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
|
||||
// 从机地址 (1b) - 功能码 (1b) - 寄存器地址 (2b) - 数据 (4b) - CRC(2b)
|
||||
// 从机地址 (1b) 0-127, 最低位表示发送方,主机请求低位为 0,从机应答低位为 1
|
||||
// 高字节在前
|
||||
|
||||
typedef struct by_tf_pack_frame_t {
|
||||
uint8_t frame[10];
|
||||
uint8_t slave_id;
|
||||
uint8_t cmd;
|
||||
uint16_t reg_addr;
|
||||
uint32_t data;
|
||||
} by_tf_pack_frame_t;
|
||||
|
||||
extern void by_tiny_frame_pack_init(void);
|
||||
extern void by_tiny_frame_pack_send(by_tf_pack_frame_t *frame_s);
|
||||
|
||||
extern uint8_t by_tiny_frame_pack_lock;
|
||||
|
||||
#endif
|
||||
198
app/tiny_frame/by_tiny_frame_parse.c
Normal file
198
app/tiny_frame/by_tiny_frame_parse.c
Normal file
@@ -0,0 +1,198 @@
|
||||
#include "by_tiny_frame_parse.h"
|
||||
|
||||
#include "crc16.h"
|
||||
#include "lwrb.h"
|
||||
|
||||
lwrb_t lwrb_struct;
|
||||
uint8_t buffer_rb[BY_TF_PARSE_BUFFER_SIZE];
|
||||
uint8_t buffer_out;
|
||||
uint8_t listen_slave_id;
|
||||
uint8_t listen_flag;
|
||||
uint16_t listen_timeout;
|
||||
uint16_t listen_timevia;
|
||||
by_tf_parse_frame_t frame_now;
|
||||
by_tf_parse_done_handle_func parse_done_handle;
|
||||
|
||||
void by_tiny_frame_parse_init(void)
|
||||
{
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
listen_timeout = BY_TF_PARSE_TIMEOUT;
|
||||
#endif
|
||||
|
||||
/** 初始化环形缓冲区 **/
|
||||
lwrb_init(&lwrb_struct, buffer_rb, 40);
|
||||
}
|
||||
|
||||
uint8_t by_tiny_frame_parse_listening(by_tf_parse_frame_t *frame_s, const uint8_t slave_id, const uint8_t buff)
|
||||
{
|
||||
|
||||
static uint8_t cnt_s = 0;
|
||||
static uint8_t cnt_rest_s = 0;
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("%0.2X\r\n", buff);
|
||||
#endif
|
||||
|
||||
do {
|
||||
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
if ((0 == cnt_s) && ((slave_id << 1) == buff)) {
|
||||
#else
|
||||
if ((0 == cnt_s) && (((slave_id << 1) + 1) == buff)) {
|
||||
#endif
|
||||
memset(frame_s, 0, sizeof(*frame_s));
|
||||
cnt_s = 1;
|
||||
cnt_rest_s = 9;
|
||||
frame_s->frame[0] = buff;
|
||||
break;
|
||||
}
|
||||
|
||||
if (1 <= cnt_s) {
|
||||
frame_s->frame[cnt_s] = buff;
|
||||
cnt_s++;
|
||||
}
|
||||
|
||||
if (0 == --cnt_rest_s) {
|
||||
cnt_s = 0;
|
||||
|
||||
frame_s->cmd = frame_s->frame[1];
|
||||
frame_s->reg_addr |= ((uint16_t)frame_s->frame[2] << 8);
|
||||
frame_s->reg_addr |= (uint16_t)frame_s->frame[3];
|
||||
frame_s->data |= ((uint32_t)frame_s->frame[4] << 24);
|
||||
frame_s->data |= ((uint32_t)frame_s->frame[5] << 16);
|
||||
frame_s->data |= ((uint32_t)frame_s->frame[6] << 8);
|
||||
frame_s->data |= (uint32_t)frame_s->frame[7];
|
||||
frame_s->crc_val |= ((uint16_t)frame_s->frame[8] << 8);
|
||||
frame_s->crc_val |= (uint16_t)frame_s->frame[9];
|
||||
return 0;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief by_tf_parse 串口回调函数,在对应串口中断函数中调用
|
||||
*
|
||||
* @param buff
|
||||
*/
|
||||
void by_tiny_frame_parse_uart_handle(uint8_t buff)
|
||||
{
|
||||
lwrb_write(&lwrb_struct, &buff, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief by_tf_parse 定时回调函数,要求触发周期为 1ms
|
||||
*
|
||||
*/
|
||||
void by_tiny_frame_parse_timer_handle(void)
|
||||
{
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
if (listen_flag) {
|
||||
listen_timevia++;
|
||||
} else {
|
||||
listen_timevia = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void by_tiny_frame_parse_run(void)
|
||||
{
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
if (0 == listen_flag) {
|
||||
return;
|
||||
} else {
|
||||
if (listen_timeout <= listen_timevia) {
|
||||
// 接收超时,停止监听
|
||||
parse_done_handle(frame_now, 1);
|
||||
by_tiny_frame_parse_end_listen();
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("by_tf_listen timeout\r\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < lwrb_get_full(&lwrb_struct); i++) {
|
||||
|
||||
if (!lwrb_read(&lwrb_struct, &buffer_out, 1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO 目前接收校验错误也会等待直至超时
|
||||
// TODO 待结合 read&wirte 部分修改监听的从机地址
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
if (!by_tiny_frame_parse_listening(&frame_now, BY_TF_DEVICE_SLAVE_ADDRESS, buffer_out))
|
||||
#else
|
||||
if (!by_tiny_frame_parse_listening(&frame_now, listen_slave_id, buffer_out))
|
||||
#endif
|
||||
{
|
||||
if (!by_tiny_frame_parse_crc(&frame_now)) {
|
||||
|
||||
// 接收成功后停止监听
|
||||
by_tiny_frame_parse_end_listen();
|
||||
// 解析成功回调
|
||||
parse_done_handle(frame_now, 0);
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("frame parsed!\r\n");
|
||||
#endif
|
||||
// 解析帧
|
||||
}
|
||||
}
|
||||
// if (!mp_cmd_parse_modbus_handle(data)) {
|
||||
// mp_cmd_mb_parse(&mp_cmd_mb_now, &mp_cmd_parsed_now);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s)
|
||||
{
|
||||
uint16_t calc_crc_val = 0;
|
||||
|
||||
calc_crc_val = crc16_check(frame_s->frame, (sizeof(frame_s->frame) - 2));
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("get: %0.2X", frame_s->crc_val);
|
||||
printf("\r\n");
|
||||
|
||||
printf("cal: %0.2X", calc_crc_val);
|
||||
printf("\r\n");
|
||||
#endif
|
||||
|
||||
if ((frame_s->crc_val == calc_crc_val) || (frame_s->crc_val == 0xFFFF)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 校验错误则直接结束监听
|
||||
by_tiny_frame_parse_end_listen();
|
||||
parse_done_handle(frame_now, 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_handle_register(by_tf_parse_done_handle_func func)
|
||||
{
|
||||
// FIXME 监听过程中应不允许更改
|
||||
// FIXME 未校验是否传入非空值,另外假设未执行注册,也会产生非法访问
|
||||
parse_done_handle = func;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_start_listen(void)
|
||||
{
|
||||
listen_flag = 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_end_listen(void)
|
||||
{
|
||||
listen_flag = 0;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_set_listen_slave_id(uint8_t slave_id)
|
||||
{
|
||||
listen_slave_id = slave_id;
|
||||
}
|
||||
33
app/tiny_frame/by_tiny_frame_parse.h
Normal file
33
app/tiny_frame/by_tiny_frame_parse.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _BY_TINY_FRAME_PARSE_H__
|
||||
#define _BY_TINY_FRAME_PARSE_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
|
||||
// 从机地址 (1b) - 功能码 (1b) - 寄存器地址 (2b) - 数据 (4b) - CRC(2b)
|
||||
// 从机地址 (1b) 0-127, 最低位表示发送方,主机请求低位为 0,从机应答低位为 1
|
||||
// 高字节在前
|
||||
|
||||
typedef struct by_tf_parse_frame_t {
|
||||
uint8_t frame[10];
|
||||
uint8_t cmd;
|
||||
uint16_t reg_addr;
|
||||
uint16_t crc_val;
|
||||
uint32_t data;
|
||||
} by_tf_parse_frame_t;
|
||||
|
||||
typedef void (*by_tf_parse_done_handle_func)(by_tf_parse_frame_t, uint8_t);
|
||||
|
||||
extern void by_tiny_frame_parse_init(void);
|
||||
extern void by_tiny_frame_parse_uart_handle(uint8_t buff);
|
||||
extern void by_tiny_frame_parse_timer_handle(void);
|
||||
extern void by_tiny_frame_parse_run(void);
|
||||
extern uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s);
|
||||
extern void by_tiny_frame_parse_handle_register(by_tf_parse_done_handle_func func);
|
||||
extern void by_tiny_frame_parse_start_listen(void);
|
||||
extern void by_tiny_frame_parse_end_listen(void);
|
||||
extern void by_tiny_frame_parse_set_listen_slave_id(uint8_t slave_id);
|
||||
|
||||
#endif
|
||||
50
app/tiny_frame/by_tiny_frame_slave_read_write.c
Normal file
50
app/tiny_frame/by_tiny_frame_slave_read_write.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "by_tiny_frame_slave_read_write.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
#include "by_tiny_frame_parse.h"
|
||||
#include "by_tiny_frame_pack.h"
|
||||
|
||||
#include "jj_param.h"
|
||||
|
||||
void by_tiny_frame_read_write_run(void)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
void by_tiny_frame_read_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
||||
{
|
||||
by_tf_pack_frame_t frame_pack_s;
|
||||
|
||||
frame_pack_s.slave_id = BY_TF_DEVICE_SLAVE_ADDRESS;
|
||||
frame_pack_s.cmd = frame_s.cmd;
|
||||
frame_pack_s.reg_addr = frame_s.reg_addr;
|
||||
|
||||
if (status) {
|
||||
// 接收出错,一般为 CRC 校验错误
|
||||
return;
|
||||
}
|
||||
|
||||
switch (frame_s.cmd) {
|
||||
case 0x03:
|
||||
// 添加查询接口,操作完成后应答,主机接收,即读取
|
||||
frame_pack_s.data =(uint32_t)(addre[frame_pack_s.reg_addr]);
|
||||
by_tiny_frame_pack_send(&frame_pack_s);
|
||||
break;
|
||||
case 0x06:
|
||||
// 添加写入接口,操作完成后应答,主机发送,即写入
|
||||
*addre[frame_pack_s.reg_addr] = frame_pack_s.data;
|
||||
by_tiny_frame_pack_send(&frame_pack_s);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("****** EXECUTE CMD SUCCESSFUL ******\r\n");
|
||||
printf("Device ID: 0x%0.2X\r\n", BY_TF_DEVICE_SLAVE_ADDRESS);
|
||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
17
app/tiny_frame/by_tiny_frame_slave_read_write.h
Normal file
17
app/tiny_frame/by_tiny_frame_slave_read_write.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _BY_TINY_FRAME_SLAVE_READ_WRITE_H__
|
||||
#define _BY_TINY_FRAME_SLAVE_READ_WRITE_H__
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
|
||||
#include "by_tiny_frame_parse.h"
|
||||
|
||||
#define BY_TINY_FRAME_READ_CMD_CODE (0x03)
|
||||
#define BY_TINY_FRAME_WRITE_CMD_CODE (0x06)
|
||||
|
||||
extern void by_tiny_frame_read_write_run(void);
|
||||
extern void by_tiny_frame_read_write_handle(by_tf_parse_frame_t frame_s, uint8_t status);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user