feat: update CAN integration and T2G seat firmware

This commit is contained in:
vee
2026-08-01 15:55:21 +08:00
parent 8cda026ac2
commit 4aded5c21d
1443 changed files with 1007122 additions and 4978 deletions
File diff suppressed because it is too large Load Diff
@@ -8,14 +8,25 @@
#define MOTOR_API_FAILURE (1u)
#define MOTOR_PHYSICAL_VALUE_SCALE (100ul)
#define MOTOR_MODE0_DEFAULT_MAX_HALL_COUNT (480ul)
#define MOTOR_MODE0_MAX_POSITION_MM_X100 (10200ul)
#define MOTOR_MODE1_DEFAULT_MAX_HALL_COUNT (790ul)
#define MOTOR_MODE1_MAX_ANGLE_DEG_X100 (8500ul)
#define MOTOR_MODE2_DEFAULT_MAX_HALL_COUNT (1590ul)
#define MOTOR_MODE2_MAX_ANGLE_DEG_X100 (9000ul)
#define MOTOR_MODE3_DEFAULT_MAX_HALL_COUNT (960ul)
#define MOTOR_MODE3_MAX_POSITION_MM_X100 (24000ul)
/*
* 2026-07-30 endpoint-to-endpoint range calibration. Bench verification
* established identity mapping: logical M0..M3 use physical mode 0..3.
*/
#define MOTOR_MODE0_DEFAULT_MAX_HALL_COUNT (480ul) /* horizontal */
#define MOTOR_MODE0_MAX_POSITION_MM_X100 (21500ul)
#define MOTOR_MODE1_DEFAULT_MAX_HALL_COUNT (374ul) /* seat pan */
#define MOTOR_MODE1_MAX_VERTICAL_MM_X100 (5600ul)
#define MOTOR_MODE1_MAX_HORIZONTAL_MM_X100 (5100ul)
/* Compatibility name used by the generic scalar position API. */
#define MOTOR_MODE1_MAX_ANGLE_DEG_X100 \
MOTOR_MODE1_MAX_VERTICAL_MM_X100
#define MOTOR_MODE2_DEFAULT_MAX_HALL_COUNT (917ul) /* backrest */
#define MOTOR_MODE2_MAX_ANGLE_DEG_X100 (6800ul)
#define MOTOR_MODE3_DEFAULT_MAX_HALL_COUNT (647ul) /* legrest */
#define MOTOR_MODE3_MAX_ANGLE_DEG_X100 (7200ul)
/* Compatibility name used by the generic scalar position API. */
#define MOTOR_MODE3_MAX_POSITION_MM_X100 \
MOTOR_MODE3_MAX_ANGLE_DEG_X100
#define MOTOR_SPEED_VALUE_SCALE (100ul)
#define MOTOR_SPEED_MIN_DUTY_PERCENT (50u)
@@ -73,6 +84,8 @@ typedef struct
uint32_t valueX100;
uint32_t maxValueX100;
uint32_t positionMmX100;
uint32_t horizontalMmX100;
uint32_t verticalMmX100;
uint32_t angleDegX100;
uint32_t percentX100;
} motor_position_info_t;
@@ -103,6 +116,21 @@ typedef struct
uint8_t currentDutyPercent;
} motor_speed_info_t;
typedef struct
{
motor_mode_t mode;
bool sampleValid;
bool baselineValid;
bool highCurrent;
bool hallActivityLow;
bool calibrating;
uint16_t raw;
uint16_t baselineRaw;
uint16_t deltaRaw;
uint16_t stallThresholdRaw;
uint32_t sampleAgeMs;
} motor_current_info_t;
typedef struct
{
uint32_t positionHallCount;
@@ -122,9 +150,9 @@ uint32_t Motor_GetTimeMs(void);
void Motor_SetWatchdogServiceEnabled(bool enabled);
/*
* Physical values use fixed point x100: 102.00 mm is 10200 and
* 85.25 degrees is 8525. positionValid is false until an endpoint has
* been found after power-up.
* Physical values use fixed point x100: 215.00 mm is 21500 and
* 68.00 degrees is 6800. positionValid is restored from a verified clean
* record or becomes true after a known endpoint has been found.
*
* Ownership contract: call all control APIs and Motor_ServiceAll from one
* main-loop/owner context. They are not ISR-safe, thread-safe, or reentrant.
@@ -132,6 +160,7 @@ void Motor_SetWatchdogServiceEnabled(bool enabled);
* start calls from that owner.
*/
uint8_t Motor_GetPositionInfo(motor_mode_t mode, motor_position_info_t *info);
uint8_t Motor_GetCurrentInfo(motor_mode_t mode, motor_current_info_t *info);
/* Each mode has independent endpoint and stall reverse switches. */
uint8_t Motor_SetSafetyOptions(motor_mode_t mode,
@@ -146,6 +175,8 @@ bool Motor_IsMoving(motor_mode_t mode);
* Restore/store Hall-domain state. These calls are accepted only while the
* selected motor is stopped. max speed uses Hall rising edges/s x100.
*/
uint8_t Motor_ValidatePersistentState(motor_mode_t mode,
const motor_persistent_state_t *state);
uint8_t Motor_ApplyPersistentState(motor_mode_t mode,
const motor_persistent_state_t *state);
uint8_t Motor_GetPersistentState(motor_mode_t mode,
@@ -199,11 +230,17 @@ uint8_t Motor_GetSpeedInfo(motor_mode_t mode, motor_speed_info_t *info);
* range, preserves observed motion, and invalidates absolute position because
* physical travel cannot be rolled back. Each leg requires Hall coast
* tracking to settle before/after travel; quiet wait is bounded to five seconds.
* legTimeoutMs is the independent motion timeout applied to each endpoint leg.
*/
uint8_t Motor_Calibrate(motor_mode_t mode,
motor_calibration_action_t action,
uint32_t legTimeoutMs,
motor_calibration_result_t *result);
/* Application override used to keep CAN/status/safety services alive while
* the selected motor executes the blocking endpoint-calibration primitive. */
void Motor_CalibrationServiceHook(void);
/* Call continuously from the main loop; the ISR still kills PWM immediately. */
void Motor_ServiceAll(void);
@@ -218,16 +255,16 @@ void Motor_StopAll(void);
bool Motor_IsDriverFaultLatched(void);
uint8_t Motor0_GetPosition(motor_position_info_t *info);
uint8_t Motor1_GetAngle(motor_position_info_t *info);
uint8_t Motor1_GetPosition(motor_position_info_t *info);
uint8_t Motor2_GetAngle(motor_position_info_t *info);
uint8_t Motor3_GetPosition(motor_position_info_t *info);
uint8_t Motor3_GetAngle(motor_position_info_t *info);
uint8_t Motor0_MoveToPositionMmX100(uint32_t positionMmX100);
uint8_t Motor1_MoveToAngleDegX100(uint32_t angleDegX100);
uint8_t Motor1_MoveToVerticalMmX100(uint32_t verticalMmX100);
uint8_t Motor2_MoveToAngleDegX100(uint32_t angleDegX100);
uint8_t Motor3_MoveToPositionMmX100(uint32_t positionMmX100);
uint8_t Motor3_MoveToAngleDegX100(uint32_t angleDegX100);
uint8_t Motor0_SetSpeedPlan(uint32_t durationMs, uint32_t distanceMmX100);
uint8_t Motor1_SetSpeedPlan(uint32_t durationMs, uint32_t angleDegX100);
uint8_t Motor1_SetSpeedPlan(uint32_t durationMs, uint32_t verticalMmX100);
uint8_t Motor2_SetSpeedPlan(uint32_t durationMs, uint32_t angleDegX100);
uint8_t Motor3_SetSpeedPlan(uint32_t durationMs, uint32_t distanceMmX100);
uint8_t Motor3_SetSpeedPlan(uint32_t durationMs, uint32_t angleDegX100);
#endif /* MOTOR_CONTROL_H */