tutrc_harurobo_lib
読み取り中…
検索中…
一致する文字列を見つけられません
uart.hpp
[詳解]
1#pragma once
2
3#include "main.h"
4
5#include <cstddef>
6#include <cstdint>
7#include <unordered_map>
8
9#include "cmsis_os2.h"
10
11extern "C" int _write(int file, char *ptr, int len);
12
13namespace tutrc_harurobo_lib {
14
56class UART {
57public:
65 bool init(UART_HandleTypeDef *huart, size_t rx_queue_size = 64);
66
74 bool transmit(const uint8_t *data, size_t size);
75
84 bool receive(uint8_t *data, size_t size, uint32_t timeout);
85
89 size_t available();
90
94 void flush();
95
100
101private:
102 UART_HandleTypeDef *huart_;
103 osMutexId_t tx_mutex_;
104 osMutexId_t rx_mutex_;
105 osSemaphoreId_t tx_sem_;
106 osSemaphoreId_t rx_sem_;
107 osMutexId_t rx_queue_;
108 uint8_t rx_buf_;
109
110 static std::unordered_map<UART_HandleTypeDef *, UART *> instances_;
111 static UART *uart_printf_;
112 friend void ::HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
113 friend void ::HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
114 friend void ::HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
115 friend int ::_write(int file, char *ptr, int len);
116};
117
118} // namespace tutrc_harurobo_lib
Definition uart.hpp:56
bool transmit(const uint8_t *data, size_t size)
bool init(UART_HandleTypeDef *huart, size_t rx_queue_size=64)
bool receive(uint8_t *data, size_t size, uint32_t timeout)
Definition bno055.hpp:10
int _write(int file, char *ptr, int len)