= ,
,
,
touch_state_t;
BOARD_LED_PORT HAL_GPIOA
BOARD_LED_PIN HAL_GPIO_PIN_5
BOARD_UART_BAUD_RATE BOARD_UART_TIMEOUT_MS BOARD_LED_INTERVAL_MS BOARD_ACCEL_INTERVAL_MS BOARD_ACCEL_RETRY_MS BOARD_I2C_TIMEOUT_MS BOARD_I2C_TIMING_100KHZ BOARD_MOTOR_HALF_STEP_MS BOARD_TOUCH_CONFIRM_MS BOARD_TOUCH_DIAG_INTERVAL_MS BOARD_TOUCH_DIAGNOSTIC BOARD_ACCEL_STREAM BOARD_AI_CONFIRM_WINDOWS BOARD_TOUCH_PORT HAL_GPIOA
BOARD_TOUCH_PIN HAL_GPIO_PIN_10
BOARD_MOTOR_IN1_PORT HAL_GPIOC
BOARD_MOTOR_IN1_PIN HAL_GPIO_PIN_1
BOARD_MOTOR_IN2_PORT HAL_GPIOB
BOARD_MOTOR_IN2_PIN HAL_GPIO_PIN_4
BOARD_MOTOR_IN3_PORT HAL_GPIOB
BOARD_MOTOR_IN3_PIN HAL_GPIO_PIN_10
BOARD_MOTOR_IN4_PORT HAL_GPIOA
BOARD_MOTOR_IN4_PIN HAL_GPIO_PIN_8
LIS3DH_WHO_AM_I_REG LIS3DH_WHO_AM_I_VALUE LIS3DH_CTRL_REG1 LIS3DH_CTRL_REG4 LIS3DH_OUT_X_L LIS3DH_CTRL_REG1_100HZ_XYZ LIS3DH_CTRL_REG4_BDU_HR_2G NEAI_INPUT_SIGNAL_LENGTH != || NEAI_INPUT_AXIS_NUMBER != || NEAI_NUMBER_OF_CLASSES != hal_uart_handle_t uart2;
BOARD_TOUCH_DIAGNOSTIC == hal_i2c_handle_t i2c1;
hal_exti_handle_t touch_exti;
BOARD_TOUCH_DIAGNOSTIC == uint32_t lis3dh_address;
ai_signalNEAI_INPUT_SIGNAL_LENGTH * NEAI_INPUT_AXIS_NUMBER;
uint16_t ai_sample_count;
uint8_t ai_ready;
int8_t ai_confirmed_class = -;
int8_t ai_candidate_class = -;
uint8_t ai_candidate_count;
uint8_t motor_phase_index;
uint32_t next_motor_step_ms;
uint8_t is_motor_running;
uint8_t motor_status_pending;
uint8_t touch_ready;
touch_state_t touch_state;
uint32_t touch_confirm_due_ms;
uint32_t touch_edge_count;
uint32_t touch_accept_count;
uint32_t touch_reject_count;
hal_status_t ;
hal_status_t ;
hal_status_t *message, uint32_t size_bytes;
BOARD_TOUCH_DIAGNOSTIC == hal_status_t ;
hal_status_t ;
hal_status_t int16_t acceleration_mg;
int16_t acceleration_mg;
hal_status_t ;
hal_status_t ;
hal_exti_handle_t *hexti, hal_exti_trigger_t trigger;
uint8_t coil_mask;
uint32_t now_ms;
hal_status_t hal_gpio_config_t config = .= ,
.= ,
.= ,
.= ,
.= ,
.= ;
;
BOARD_LED_PORT, BOARD_LED_PIN, &config;
hal_status_t hal_gpio_config_t pins = .= ,
.= ,
.= ,
.= ,
.= HAL_GPIO_AF7_USART2,
.= ;
hal_uart_config_t config = .= BOARD_UART_BAUD_RATE,
.= ,
.= ,
.= ,
.= ,
.= ,
.= ,
.= ,
.= ;
;
, HAL_GPIO_PIN_2 | HAL_GPIO_PIN_3, &pins!= ;
!= ;
;
&uart2, != ;
&uart2, &config;
hal_status_t *message, uint32_t size_bytes&uart2, message, size_bytes, BOARD_UART_TIMEOUT_MS;
BOARD_TOUCH_DIAGNOSTIC == hal_status_t hal_gpio_config_t pins = .= ,
.= ,
.= ,
.= ,
.= HAL_GPIO_AF4_I2C1,
.= ;
hal_i2c_config_t config = .= BOARD_I2C_TIMING_100KHZ,
.= ,
.= ;
;
, HAL_GPIO_PIN_6 | HAL_GPIO_PIN_7, &pins!= ;
!= ;
!= ;
;
&i2c1, != ;
&i2c1, &config;
hal_status_t uint32_t addresses= << , << ;
uint8_t id;
uint8_t value;
uint32_t index = ; index < ; ++index&i2c1, addressesindex, LIS3DH_WHO_AM_I_REG,
, &id, , BOARD_I2C_TIMEOUT_MS== &&
id == LIS3DH_WHO_AM_I_VALUElis3dh_address = addressesindex;
value = LIS3DH_CTRL_REG4_BDU_HR_2G;
&i2c1, lis3dh_address, LIS3DH_CTRL_REG4,
, &value, , BOARD_I2C_TIMEOUT_MS!= ;
value = LIS3DH_CTRL_REG1_100HZ_XYZ;
&i2c1, lis3dh_address, LIS3DH_CTRL_REG1,
, &value, , BOARD_I2C_TIMEOUT_MS;
;
hal_status_t int16_t acceleration_mguint8_t raw;
hal_status_t status = &i2c1, lis3dh_address,
LIS3DH_OUT_X_L | ,
, raw,
raw, BOARD_I2C_TIMEOUT_MS;
status != status;
uint32_t axis = ; axis < ; ++axisint16_t value = int16_tuint16_traw* axis|
uint16_traw* axis + << ;
acceleration_mgaxis= value / ;
;
int16_t acceleration_mgai_ready == ;
uint32_t offset = uint32_tai_sample_count * NEAI_INPUT_AXIS_NUMBER;
uint32_t axis = ; axis < NEAI_INPUT_AXIS_NUMBER; ++axisai_signaloffset + axis= acceleration_mgaxis;
++ai_sample_count;
ai_sample_count < NEAI_INPUT_SIGNAL_LENGTH;
ai_sample_count = ;
probabilitiesNEAI_NUMBER_OF_CLASSES;
class_id = -;
neai_state status = ai_signal, probabilities, &class_id;
status != ai_candidate_count = ;
, - ;
;
class_id != && class_id != ai_candidate_count = ;
, - ;
;
class_id != ai_confirmed_classclass_id != ai_candidate_classai_candidate_class = int8_tclass_id;
ai_candidate_count = ;
++ai_candidate_count >= BOARD_AI_CONFIRM_WINDOWSai_confirmed_class = int8_tclass_id;
ai_candidate_count = ;
ai_candidate_count = ;
ai_candidate_count == *label = ai_confirmed_class == ? : ;
label, ai_confirmed_class == ? - :
- ;
hal_status_t hal_gpio_config_t config = .= ,
.= ,
.= ,
.= ,
.= ,
.= ;
;
;
;
BOARD_MOTOR_IN1_PORT, BOARD_MOTOR_IN1_PIN, &config!= ||
BOARD_MOTOR_IN2_PORT, BOARD_MOTOR_IN2_PIN, &config!= ||
BOARD_MOTOR_IN3_PORT, BOARD_MOTOR_IN3_PIN, &config!= ||
BOARD_MOTOR_IN4_PORT, BOARD_MOTOR_IN4_PIN, &config!= ;
;
hal_status_t hal_gpio_config_t config = .= ,
.= ,
.= ,
.= ,
.= ,
.= ;
;
BOARD_TOUCH_PORT, BOARD_TOUCH_PIN, &config!= ;
hal_exti_config_t exti_config = .= ,
.= ;
&touch_exti, != ||
&touch_exti, &exti_config!= ||
&touch_exti, != ;
&touch_exti, ;
touch_state = BOARD_TOUCH_PORT, BOARD_TOUCH_PIN== ?
: ;
NVIC_SetPriority, USE_HAL_TICK_INT_PRIORITY;
NVIC_EnableIRQ;
&touch_exti, ;
hal_exti_handle_t *hexti, hal_exti_trigger_t triggerhexti;
touch_edge_count++;
trigger == trigger = BOARD_TOUCH_PORT, BOARD_TOUCH_PIN== ?
: ;
trigger == touch_state == touch_confirm_due_ms = + BOARD_TOUCH_CONFIRM_MS;
touch_state = ;
touch_state == touch_state = ;
trigger == && touch_state == touch_confirm_due_ms = + BOARD_TOUCH_CONFIRM_MS;
touch_state = ;
&touch_exti;
uint8_t coil_maskBOARD_MOTOR_IN1_PORT, BOARD_MOTOR_IN1_PIN,
coil_mask & ? : ;
BOARD_MOTOR_IN2_PORT, BOARD_MOTOR_IN2_PIN,
coil_mask & ? : ;
BOARD_MOTOR_IN3_PORT, BOARD_MOTOR_IN3_PIN,
coil_mask & ? : ;
BOARD_MOTOR_IN4_PORT, BOARD_MOTOR_IN4_PIN,
coil_mask & ? : ;
uint32_t now_msuint8_t = , , , , , , , ;
is_motor_running == || int32_tnow_ms - next_motor_step_ms< ;
motor_phase_index;
motor_phase_index = motor_phase_index + & ;
next_motor_step_ms = now_ms + BOARD_MOTOR_HALF_STEP_MS;
uint32_t now_ms = ;
touch_ready == ;
touch_state == ||
touch_state == &&
int32_tnow_ms - touch_confirm_due_ms>= uint8_t touch_is_high =
BOARD_TOUCH_PORT, BOARD_TOUCH_PIN== ? : ;
touch_state == touch_state = touch_is_high == ? : ;
touch_is_high != touch_state = ;
touch_accept_count++;
is_motor_running = !is_motor_running;
is_motor_running != motor_phase_index = ;
next_motor_step_ms = now_ms;
;
motor_status_pending = ;
touch_state = ;
touch_reject_count++;
now_ms;
uint32_t next_led_ms;
BOARD_TOUCH_DIAGNOSTIC == uint32_t next_accel_ms;
uint32_t next_probe_ms;
BOARD_TOUCH_DIAGNOSTIC == uint8_t is_led_on = ;
BOARD_TOUCH_DIAGNOSTIC == uint8_t has_sensor = ;
int16_t acceleration_mg;
BOARD_TOUCH_DIAGNOSTIC == || BOARD_ACCEL_STREAM == != -;
!= || != ||
!= ||
!= -;
BOARD_TOUCH_DIAGNOSTIC == != -;
ai_ready = == ? : ;
, - ;
BOARD_TOUCH_DIAGNOSTIC == ai_ready == , - ;
BOARD_TOUCH_DIAGNOSTIC == next_led_ms = ;
BOARD_TOUCH_DIAGNOSTIC == next_accel_ms = ;
next_probe_ms = ;
BOARD_TOUCH_DIAGNOSTIC == , - ;
touch_ready = ;
uint32_t now_ms = ;
uint8_t has_motor_status;
uint8_t motor_state_snapshot;
;
has_motor_status = motor_status_pending;
motor_status_pending = ;
motor_state_snapshot = is_motor_running;
;
has_motor_status != motor_state_snapshot != ? : ,
motor_state_snapshot != ? - :
- ;
BOARD_TOUCH_DIAGNOSTIC == int32_tnow_ms - next_led_ms>= is_led_on = !is_led_on;
BOARD_LED_PORT, BOARD_LED_PIN,
is_led_on ? : ;
next_led_ms += BOARD_LED_INTERVAL_MS;
BOARD_TOUCH_DIAGNOSTIC == has_sensor == && int32_tnow_ms - next_probe_ms>= == has_sensor = ;
next_accel_ms = + BOARD_ACCEL_INTERVAL_MS;
, - ;
, - ;
next_probe_ms = + BOARD_ACCEL_RETRY_MS;
has_sensor != && int32_tnow_ms - next_accel_ms>= acceleration_mg== BOARD_ACCEL_STREAM == acceleration_mg;
has_sensor = ;
ai_sample_count = ;
ai_confirmed_class = -;
ai_candidate_class = -;
ai_candidate_count = ;
, - ;
next_accel_ms += BOARD_ACCEL_INTERVAL_MS;
int32_t- next_accel_ms>= next_accel_ms = + BOARD_ACCEL_INTERVAL_MS;