Files
QD4C-firmware/app/jj_param.c

91 lines
2.7 KiB
C
Raw Normal View History

#include "jj_param.h"
#include "./page/page_ui_widget.h"
#include "./page/page.h"
2024-01-16 20:03:21 +08:00
#include "zf_common_headfile.h"
#include "jj_motion.h"
2024-03-02 16:05:24 +08:00
PARAM_INFO Param_Data[DATA_NUM];
soft_iic_info_struct eeprom_param;
TYPE_UNION iic_buffer[DATA_IN_FLASH_NUM];
2024-03-03 19:23:21 +08:00
TYPE_UNION temp_frame_param[20];
2024-03-02 16:05:24 +08:00
/**
* @brief
*
*/
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初始化
2024-03-02 16:05:24 +08:00
PARAM_REG(angle_Kp, &an_Kp, EFLOAT, 1, "an_P:"); // 注冊
PARAM_REG(angle_Ki, &an_Ki, EFLOAT, 1, "an_I:"); // 注冊
PARAM_REG(angle_Kd, &an_Kd, EFLOAT, 1, "an_D:");
2024-03-10 08:34:33 +08:00
PARAM_REG(gyro_Kp, &gy_Kp, EFLOAT, 1, "gy_P:"); // 注冊
PARAM_REG(gyro_Ki, &gy_Ki, EFLOAT, 1, "gy_I:"); // 注冊
PARAM_REG(gyro_Kd, &gy_Kd, EFLOAT, 1, "gy_D:");
2024-03-02 16:05:24 +08:00
PARAM_REG(speed_Kp, &sp_Kp, EFLOAT, 1, "sp_P:"); // 注冊
PARAM_REG(speed_Ki, &sp_Ki, EFLOAT, 1, "sp_I:"); // 注冊
PARAM_REG(speed_Kd, &sp_Kd, EFLOAT, 1, "sp_D:");
PARAM_REG(pos_Kp, &po_Kp, EFLOAT, 1, "po_P:"); // 注冊
PARAM_REG(pos_Ki, &po_Ki, EFLOAT, 1, "po_I:"); // 注冊
PARAM_REG(pos_Kd, &po_Kd, EFLOAT, 1, "po_D:");
PARAM_REG(param_set_speed, &set_speed, EFLOAT, 1, "rate:");
jj_param_read(); // 注冊
}
/**
* @brief
*
*/
void jj_param_write(void)
{
for (uint8 i = 0; i < DATA_IN_FLASH_NUM-1; i++) {
switch (Param_Data[i].type) {
case EFLOAT:
2024-03-02 16:05:24 +08:00
iic_buffer[i].f32 = *((float *)(Param_Data[i].p_data));
break;
case EUINT32:
2024-03-02 16:05:24 +08:00
iic_buffer[i].u32 = *((uint32 *)(Param_Data[i].p_data));
break;
case EINT32:
2024-03-02 16:05:24 +08:00
iic_buffer[i].s32 = *((int32 *)(Param_Data[i].p_data));
break;
default:
break;
}
2024-03-02 16:05:24 +08:00
eep_soft_iic_write_8bit_registers(&eeprom_param, (4 * i) >> 8, (4 * i), (uint8 *)&iic_buffer[i], 4);
2024-01-16 20:03:21 +08:00
system_delay_ms(10);
}
}
/**
2024-03-02 16:05:24 +08:00
* @brief
*
*/
2024-03-02 16:05:24 +08:00
void jj_param_read(void)
{
2024-03-02 16:05:24 +08:00
for (uint8 i = 0; i < DATA_IN_FLASH_NUM-1; i++) {
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:
2024-03-02 16:05:24 +08:00
*((float *)(Param_Data[i].p_data)) =
iic_buffer[i].f32;
break;
case EUINT32:
2024-03-02 16:05:24 +08:00
*((uint32 *)(Param_Data[i].p_data)) =
iic_buffer[i].u32;
break;
case EINT32:
2024-03-02 16:05:24 +08:00
*((int32 *)(Param_Data[i].p_data)) =
iic_buffer[i].s32;
break;
default:
break;
}
2024-01-16 20:03:21 +08:00
system_delay_ms(10);
}
}