47 UartRx(
size_t buf_size) : queue_{buf_size} {
48 stm32cubemx_helper::set_context<Handle, UartRx>(
this);
49 HAL_UART_RegisterCallback(
50 Handle, HAL_UART_RX_COMPLETE_CB_ID, [](UART_HandleTypeDef *huart) {
51 auto uart = stm32cubemx_helper::get_context<Handle, UartRx>();
52 uart->queue_.push(uart->buf_, 0);
53 HAL_UART_Receive_IT(huart, &uart->buf_, 1);
55 HAL_UART_RegisterCallback(
56 Handle, HAL_UART_ERROR_CB_ID,
57 [](UART_HandleTypeDef *huart) { HAL_UART_Abort_IT(huart); });
58 HAL_UART_RegisterCallback(
59 Handle, HAL_UART_ABORT_COMPLETE_CB_ID, [](UART_HandleTypeDef *huart) {
60 auto uart = stm32cubemx_helper::get_context<Handle, UartRx>();
61 HAL_UART_Receive_IT(huart, &uart->buf_, 1);
63 HAL_UART_Receive_IT(Handle, &buf_, 1);
67 HAL_UART_Abort_IT(Handle);
68 HAL_UART_UnRegisterCallback(Handle, HAL_UART_RX_COMPLETE_CB_ID);
69 HAL_UART_UnRegisterCallback(Handle, HAL_UART_ERROR_CB_ID);
70 HAL_UART_UnRegisterCallback(Handle, HAL_UART_ABORT_COMPLETE_CB_ID);
71 stm32cubemx_helper::set_context<Handle, UartRx>(
nullptr);