Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eyr1n committed Oct 29, 2024
1 parent 8b25825 commit 3908195
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions include/tutrc_harurobo_lib/bno055.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace tutrc_harurobo_lib {

class BNO055 {
public:
// TODO: timeout引数
bool init(UART *uart) {
uart_ = uart;
uint32_t start = osKernelGetTickCount();
Expand Down
2 changes: 1 addition & 1 deletion include/tutrc_harurobo_lib/can.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace tutrc_harurobo_lib {

class CAN : public CANBase {
public:
CAN(CAN_HandleTypeDef *hcan, size_t rx_queue_size = 64);
bool init(CAN_HandleTypeDef *hcan, size_t rx_queue_size = 64);
bool transmit(const CANMessage *msg) override;
bool receive(CANMessage *msg, uint32_t timeout) override;
size_t available() override;
Expand Down
2 changes: 1 addition & 1 deletion include/tutrc_harurobo_lib/pwm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace tutrc_harurobo_lib {

class PWM {
public:
PWM(TIM_HandleTypeDef *htim, uint32_t channel);
bool init(TIM_HandleTypeDef *htim, uint32_t channel);
uint32_t get_compare();
void set_compare(uint32_t compare);

Expand Down
13 changes: 6 additions & 7 deletions src/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ namespace tutrc_harurobo_lib {

std::unordered_map<CAN_HandleTypeDef *, CAN *> CAN::instances_;

CAN::CAN(CAN_HandleTypeDef *hcan, size_t rx_queue_size) : hcan_(hcan) {
bool CAN::init(CAN_HandleTypeDef *hcan, size_t rx_queue_size) {
hcan_ = hcan;
instances_[hcan_] = this;
rx_queue_ = osMessageQueueNew(rx_queue_size, sizeof(CANMessage), nullptr);

if (hcan_->State != HAL_CAN_STATE_READY) {
Error_Handler();
return false;
}

CAN_FilterTypeDef filter = {};
Expand All @@ -37,17 +38,15 @@ CAN::CAN(CAN_HandleTypeDef *hcan, size_t rx_queue_size) : hcan_(hcan) {
filter.SlaveStartFilterBank = 14;

if (HAL_CAN_ConfigFilter(hcan_, &filter) != HAL_OK) {
Error_Handler();
return false;
}

if (HAL_CAN_ActivateNotification(hcan_, CAN_IT_RX_FIFO0_MSG_PENDING) !=
HAL_OK) {
Error_Handler();
return false;
}

if (HAL_CAN_Start(hcan_) != HAL_OK) {
Error_Handler();
}
return HAL_CAN_Start(hcan_) == HAL_OK;
}

bool CAN::transmit(const CANMessage *msg) {
Expand Down
1 change: 1 addition & 0 deletions src/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bool Encoder::init(TIM_HandleTypeDef *htim, uint16_t ppr, float period) {
htim_ = htim;
ppr_ = ppr;
period_ = period;

return HAL_TIM_Encoder_Start(htim_, TIM_CHANNEL_ALL) == HAL_OK;
}

Expand Down
10 changes: 5 additions & 5 deletions src/pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace tutrc_harurobo_lib {

PWM::PWM(TIM_HandleTypeDef *htim, uint32_t channel)
: htim_(htim), channel_(channel) {
if (HAL_TIM_PWM_Start(htim_, channel_) != HAL_OK) {
Error_Handler();
}
bool PWM::init(TIM_HandleTypeDef *htim, uint32_t channel) {
htim_ = htim;
channel_ = channel;

return HAL_TIM_PWM_Start(htim_, channel_) == HAL_OK;
}

uint32_t PWM::get_compare() { return __HAL_TIM_GET_COMPARE(htim_, channel_); }
Expand Down

0 comments on commit 3908195

Please sign in to comment.