From 60bad2431988dde1afc487e466404f57025ac92f Mon Sep 17 00:00:00 2001 From: Erki Date: Tue, 8 Jun 2021 23:18:56 +0300 Subject: [PATCH] The great renaming, part 1 --- Messaging/Inc/messaging_packet.hpp | 6 +- Messaging/Inc/messaging_parser.hpp | 78 ++++----- Peripherals/Inc/peripherals_adc.hpp | 6 +- Peripherals/Inc/peripherals_button.hpp | 30 ++-- Peripherals/Inc/peripherals_encoder.hpp | 38 ++--- Peripherals/Inc/peripherals_hal_st.hpp | 126 +++++++-------- Peripherals/Inc/peripherals_imu.hpp | 18 +-- Peripherals/Inc/peripherals_imu_icm.hpp | 150 +++++++++--------- Peripherals/Inc/peripherals_ir_sensors.hpp | 54 +++---- Peripherals/Inc/peripherals_motors.hpp | 68 ++++---- Peripherals/Inc/peripherals_pwm_channel.hpp | 43 ----- Peripherals/Inc/peripherals_rgb.hpp | 58 +++---- .../Inc/peripherals_ssd1306_display.hpp | 56 +++---- Peripherals/Inc/peripherals_utility.hpp | 12 +- Utility/Inc/utility_asynclogger.hpp | 43 ++--- Utility/Inc/utility_atomicscopeguard.hpp | 16 +- Utility/Inc/utility_fixedpoint.hpp | 6 +- Utility/Inc/utility_logging.hpp | 6 +- Utility/Inc/utility_pixelbuffer_effects.hpp | 6 +- Utility/Inc/utility_rand.hpp | 10 +- Utility/Inc/utility_ringbuffer.hpp | 64 ++++---- Utility/Inc/utility_seriallogger.hpp | 16 +- Utility/Src/utility_rand.cpp | 4 +- 23 files changed, 436 insertions(+), 478 deletions(-) delete mode 100644 Peripherals/Inc/peripherals_pwm_channel.hpp diff --git a/Messaging/Inc/messaging_packet.hpp b/Messaging/Inc/messaging_packet.hpp index 1dbbf43..df50a63 100644 --- a/Messaging/Inc/messaging_packet.hpp +++ b/Messaging/Inc/messaging_packet.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef MESSAGING_INC_MESSAGING_PACKET_HPP_ -#define MESSAGING_INC_MESSAGING_PACKET_HPP_ +#ifndef SKULLC_MESSAGING_PACKET_HPP_ +#define SKULLC_MESSAGING_PACKET_HPP_ #include #include @@ -106,4 +106,4 @@ constexpr std::uint8_t Packet::preamble[2]; }// namespace Messaging -#endif /* MESSAGING_INC_MESSAGING_PACKET_HPP_ */ +#endif /* SKULLC_MESSAGING_PACKET_HPP_ */ diff --git a/Messaging/Inc/messaging_parser.hpp b/Messaging/Inc/messaging_parser.hpp index 9362207..16fc188 100644 --- a/Messaging/Inc/messaging_parser.hpp +++ b/Messaging/Inc/messaging_parser.hpp @@ -2,8 +2,8 @@ // Created by erki on 27.03.21. // -#ifndef SKULLC_MESSAGING_PARSER_HPP -#define SKULLC_MESSAGING_PARSER_HPP +#ifndef SKULLC_MESSAGING_PARSER_HPP_ +#define SKULLC_MESSAGING_PARSER_HPP_ #include #include @@ -27,10 +27,10 @@ public: void reset() { - _state = _State::Preamble; - _expected = sizeof(P::preamble); - _current_pos = 0; - _current_offset = 0; + state_ = State_::Preamble; + expected_ = sizeof(P::preamble); + current_pos_ = 0; + current_offset_ = 0; } void pushByte(const std::uint8_t byte) @@ -38,41 +38,41 @@ public: if (packetReady()) return; - const std::uint32_t buffer_loc = _current_offset + _current_pos; + const std::uint32_t buffer_loc = current_offset_ + current_pos_; - switch (_state) + switch (state_) { - case _State::Preamble: - if (byte != P::preamble[_current_pos]) + case State_::Preamble: + if (byte != P::preamble[current_pos_]) { reset(); return; } [[fallthrough]]; - case _State::Length: - case _State::Body: - _buffer[buffer_loc] = byte; - _current_pos++; + case State_::Length: + case State_::Body: + buffer_[buffer_loc] = byte; + current_pos_++; break; default: break; } - if (_current_pos == _expected) + if (current_pos_ == expected_) { - _setupNextState(); + setupNextState_(); } } - bool packetReady() const { return _state == _State::Done; } + bool packetReady() const { return state_ == State_::Done; } bool getPacket(Packet& packet) const { - return packet.deserialize(_buffer.data(), _current_offset); + return packet.deserialize(buffer_.data(), current_offset_); } private: - enum class _State : std::uint32_t + enum class State_ : std::uint32_t { Preamble, Length, @@ -80,17 +80,17 @@ private: Done }; - std::array _buffer; - _State _state = _State::Preamble; + std::array buffer_; + State_ state_ = State_::Preamble; - std::uint32_t _current_pos = 0; - std::uint32_t _current_offset = 0; - std::uint32_t _expected = 0; + std::uint32_t current_pos_ = 0; + std::uint32_t current_offset_ = 0; + std::uint32_t expected_ = 0; template - T _deserializeLength(const std::uint32_t offset) + T deserializeLength_(const std::uint32_t offset) { - std::uint8_t* begin = _buffer.data() + offset; + std::uint8_t* begin = buffer_.data() + offset; T len(0); std::memcpy(&len, begin, sizeof(T)); @@ -98,30 +98,30 @@ private: return len; } - void _setupNextState() + void setupNextState_() { - switch (_state) + switch (state_) { - case _State::Preamble: - _state = _State::Length; - _expected = sizeof(typename P::length_type); + case State_::Preamble: + state_ = State_::Length; + expected_ = sizeof(typename P::length_type); break; - case _State::Length: - _state = _State::Body; - _expected = _deserializeLength(_current_offset); + case State_::Length: + state_ = State_::Body; + expected_ = deserializeLength_(current_offset_); break; - case _State::Body: - _state = _State::Done; + case State_::Body: + state_ = State_::Done; break; default: break; } - _current_offset += _current_pos; - _current_pos = 0; + current_offset_ += current_pos_; + current_pos_ = 0; } }; }// namespace Messaging -#endif// SKULLC_MESSAGING_PARSER_HPP +#endif// SKULLC_MESSAGING_PARSER_HPP_ diff --git a/Peripherals/Inc/peripherals_adc.hpp b/Peripherals/Inc/peripherals_adc.hpp index 294c5f1..af70d92 100644 --- a/Peripherals/Inc/peripherals_adc.hpp +++ b/Peripherals/Inc/peripherals_adc.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_INC_PERIPHERALS_ADC_HPP_ -#define PERIPHERALS_INC_PERIPHERALS_ADC_HPP_ +#ifndef SKULLC_PERIPHERALS_ADC_HPP_ +#define SKULLC_PERIPHERALS_ADC_HPP_ #include #include @@ -59,4 +59,4 @@ struct Adc }// namespace Peripherals -#endif /* PERIPHERALS_INC_PERIPHERALS_ADC_HPP_ */ +#endif /* SKULLC_PERIPHERALS_ADC_HPP_ */ diff --git a/Peripherals/Inc/peripherals_button.hpp b/Peripherals/Inc/peripherals_button.hpp index 4d19e88..954769a 100644 --- a/Peripherals/Inc/peripherals_button.hpp +++ b/Peripherals/Inc/peripherals_button.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_BUTTON_HPP_ -#define PERIPHERALS_BUTTON_HPP_ +#ifndef SKULLC_PERIPHERALS_BUTTON_HPP_ +#define SKULLC_PERIPHERALS_BUTTON_HPP_ #include @@ -39,38 +39,38 @@ public: void update() { - const bool is_pressed = sw.Read(); + const bool is_pressed = sw.read(); ButtonPress new_state = ButtonPress::NOT_PRESSED; - if (is_pressed && !_was_pressed) + if (is_pressed && !was_pressed_) { - _time_pressed_down = hal::GetMillis(); - } else if (!is_pressed && _was_pressed) + time_pressed_down_ = hal::getMillis(); + } else if (!is_pressed && was_pressed_) { - const std::uint32_t time_held = hal::GetMillis() - _time_pressed_down; + const std::uint32_t time_held = hal::getMillis() - time_pressed_down_; if (time_held > TIMEOUT_LONG_PRESS) new_state = ButtonPress::LONG_PRESS; else if (time_held > TIMEOUT_SHORT_PRESS) new_state = ButtonPress::SHORT_PRESS; - _time_pressed_down = 0; + time_pressed_down_ = 0; } - _was_pressed = is_pressed; - _current_state = new_state; + was_pressed_ = is_pressed; + current_state_ = new_state; } [[nodiscard]] ButtonPress getState() const { - return _current_state; + return current_state_; } private: - bool _was_pressed = false; - std::uint32_t _time_pressed_down = 0; - ButtonPress _current_state = ButtonPress::NOT_PRESSED; + bool was_pressed_ = false; + std::uint32_t time_pressed_down_ = 0; + ButtonPress current_state_ = ButtonPress::NOT_PRESSED; }; }// namespace Peripherals -#endif /* PERIPHERALS_BUTTON_HPP_ */ +#endif /* SKULLC_PERIPHERALS_BUTTON_HPP_ */ diff --git a/Peripherals/Inc/peripherals_encoder.hpp b/Peripherals/Inc/peripherals_encoder.hpp index e12f189..21c200c 100644 --- a/Peripherals/Inc/peripherals_encoder.hpp +++ b/Peripherals/Inc/peripherals_encoder.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_ENCODER_HPP_ -#define PERIPHERALS_ENCODER_HPP_ +#ifndef SKULLC_PERIPHERALS_ENCODER_HPP_ +#define SKULLC_PERIPHERALS_ENCODER_HPP_ #include @@ -26,7 +26,7 @@ public: Encoder() = delete; explicit Encoder(TIM_HandleTypeDef* htim, const std::uint32_t channels) - : _htim(htim), _channels(channels) + : htim_(htim), channels_(channels) {} Encoder(const Encoder&) = delete; @@ -36,40 +36,40 @@ public: void start() { - HAL_TIM_Base_Start_IT(_htim); - HAL_TIM_Encoder_Start_IT(_htim, _channels); + HAL_TIM_Base_Start_IT(htim_); + HAL_TIM_Encoder_Start_IT(htim_, channels_); } void stop() { - HAL_TIM_Encoder_Stop_IT(_htim, _channels); + HAL_TIM_Encoder_Stop_IT(htim_, channels_); } void reset() { - __HAL_TIM_SET_COUNTER(_htim, 0); - _full_revolutions = 0; + __HAL_TIM_SET_COUNTER(htim_, 0); + full_revolutions_ = 0; } void setRevolutionTickCount(const std::uint16_t& count) { - __HAL_TIM_SET_AUTORELOAD(_htim, count); + __HAL_TIM_SET_AUTORELOAD(htim_, count); } std::uint16_t getCurrentClicks() const { - const std::uint16_t val = __HAL_TIM_GET_COUNTER(_htim); + const std::uint16_t val = __HAL_TIM_GET_COUNTER(htim_); return val; } std::int32_t getFullRevolutions() const { - return _full_revolutions; + return full_revolutions_; } Dirs getDirection() const { - if (__HAL_TIM_IS_TIM_COUNTING_DOWN(_htim)) + if (__HAL_TIM_IS_TIM_COUNTING_DOWN(htim_)) return Dirs::BACKWARD; else return Dirs::FORWARD; @@ -77,20 +77,20 @@ public: void timerUpdateEvent() { - if (!__HAL_TIM_IS_TIM_COUNTING_DOWN(_htim)) - _full_revolutions++; + if (!__HAL_TIM_IS_TIM_COUNTING_DOWN(htim_)) + full_revolutions_++; else - _full_revolutions--; + full_revolutions_--; } private: - TIM_HandleTypeDef* _htim; - std::uint32_t _channels; + TIM_HandleTypeDef* htim_; + std::uint32_t channels_; - std::int32_t _full_revolutions = 0; + std::int32_t full_revolutions_ = 0; }; }// namespace Peripherals -#endif /* PERIPHERALS_ENCODER_HPP_ */ +#endif /* SKULLC_PERIPHERALS_ENCODER_HPP_ */ diff --git a/Peripherals/Inc/peripherals_hal_st.hpp b/Peripherals/Inc/peripherals_hal_st.hpp index c59d65b..0a369f4 100644 --- a/Peripherals/Inc/peripherals_hal_st.hpp +++ b/Peripherals/Inc/peripherals_hal_st.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_INC_PERIPHERALS_HAL_ST_HPP_ -#define PERIPHERALS_INC_PERIPHERALS_HAL_ST_HPP_ +#ifndef SKULLC_PERIPHERALS_HAL_ST_HPP_ +#define SKULLC_PERIPHERALS_HAL_ST_HPP_ #include @@ -36,7 +36,7 @@ IsrCallbackFn createCallback(Handler& h_in) struct StaticHal { - static void Initialize() + static void initialize() { #ifdef USE_DELAY_US CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; @@ -45,17 +45,17 @@ struct StaticHal #endif } - static std::uint32_t GetMillis() + static std::uint32_t getMillis() { return HAL_GetTick(); } - static void Delay(const std::uint32_t milliseconds) + static void delay(const std::uint32_t milliseconds) { HAL_Delay(milliseconds); } - static void DelayUs(const std::uint32_t micros) + static void delayUs(const std::uint32_t micros) { #ifdef USE_DELAY_US const std::uint32_t tick_start = DWT->CYCCNT; @@ -85,14 +85,14 @@ struct Gpio explicit Gpio(GPIO_TypeDef* port, const std::uint16_t pin, const bool inverted) : port(port), pin(pin), inverted(inverted) {} - void Set(const bool& state) + void set(const bool& state) { HAL_GPIO_WritePin(port, pin, GPIO_PinState(inverted ? !state : state)); } - void Toggle() { HAL_GPIO_TogglePin(port, pin); } + void toggle() { HAL_GPIO_TogglePin(port, pin); } - bool Read() const { return inverted ? !bool(HAL_GPIO_ReadPin(port, pin)) : bool(HAL_GPIO_ReadPin(port, pin)); } + bool read() const { return inverted ? !bool(HAL_GPIO_ReadPin(port, pin)) : bool(HAL_GPIO_ReadPin(port, pin)); } }; #define CREATE_GPIO(name) \ @@ -104,10 +104,10 @@ struct Gpio template< typename T, - HAL_StatusTypeDef (*transmit)( + HAL_StatusTypeDef (*transmit_)( T*, std::uint8_t* data, std::uint16_t data_len, std::uint32_t timeout), - HAL_StatusTypeDef (*receive)(T*, std::uint8_t* data, - std::uint16_t data_len, std::uint32_t timeout)> + HAL_StatusTypeDef (*receive_)(T*, std::uint8_t* data, + std::uint16_t data_len, std::uint32_t timeout)> struct SerialInterface { using underlying_handle_type = T; @@ -116,38 +116,38 @@ struct SerialInterface SerialInterface() = delete; explicit SerialInterface(underlying_handle_type* handle) : handle(handle) {} - bool Transmit(std::uint8_t* data, const std::uint32_t data_len) + bool transmit(std::uint8_t* data, const std::uint32_t data_len) { - return transmit(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK; + return transmit_(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK; } template - bool Transmit(std::array& array) + bool transmit(std::array& array) { static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); - return Transmit(reinterpret_cast(array.data()), std::uint32_t(N)); + return transmit(reinterpret_cast(array.data()), std::uint32_t(N)); } - bool Receive(std::uint8_t* data, const std::uint32_t data_len) + bool receive(std::uint8_t* data, const std::uint32_t data_len) { - return receive(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK; + return receive_(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK; } template - bool Receive(std::array& array) + bool receive(std::array& array) { static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); - return Receive(reinterpret_cast(array.data()), std::uint32_t(N)); + return receive(reinterpret_cast(array.data()), std::uint32_t(N)); } }; template + HAL_StatusTypeDef (*transmit_)(T*, std::uint8_t* data, + std::uint16_t data_len), + HAL_StatusTypeDef (*receive_)(T*, std::uint8_t* data, + std::uint16_t data_len)> struct SerialInterfaceAsync { using underlying_handle_type = T; @@ -157,30 +157,30 @@ struct SerialInterfaceAsync explicit SerialInterfaceAsync(underlying_handle_type* handle) : handle(handle) {} - bool Transmit(std::uint8_t* data, const std::uint32_t data_len) + bool transmit(std::uint8_t* data, const std::uint32_t data_len) { - return transmit(handle, data, data_len) == HAL_StatusTypeDef::HAL_OK; + return transmit_(handle, data, data_len) == HAL_StatusTypeDef::HAL_OK; } template - bool Transmit(std::array& array) + bool transmit(std::array& array) { static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); - return Transmit(reinterpret_cast(array.data()), std::uint32_t(N)); + return transmit_(reinterpret_cast(array.data()), std::uint32_t(N)); } - bool Receive(std::uint8_t* data, const std::uint32_t data_len) + bool receive(std::uint8_t* data, const std::uint32_t data_len) { - return receive(handle, data, data_len) == HAL_StatusTypeDef::HAL_OK; + return receive_(handle, data, data_len) == HAL_StatusTypeDef::HAL_OK; } template - bool Receive(std::array& array) + bool receive(std::array& array) { static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); - return Receive(reinterpret_cast(array.data()), std::uint32_t(N)); + return receive(reinterpret_cast(array.data()), std::uint32_t(N)); } }; @@ -198,63 +198,63 @@ struct SpiRegisters explicit SpiRegisters(const SpiInterface& handle, const Gpio& cs) : handle(handle), chip_select(cs) { - chip_select.Set(true); + chip_select.set(true); } - void WriteRegister(std::uint8_t reg, uint8_t data) + void writeRegister(std::uint8_t reg, uint8_t data) { - chip_select.Set(false); + chip_select.set(false); - handle.Transmit(®, 1); - handle.Transmit(&data, 1); + handle.transmit(®, 1); + handle.transmit(&data, 1); - chip_select.Set(true); + chip_select.set(true); } - void WriteRegisterMultibyte(std::uint8_t reg, std::uint8_t* data, + void writeRegisterMultibyte(std::uint8_t reg, std::uint8_t* data, const std::uint32_t len) { - chip_select.Set(false); + chip_select.set(false); - handle.Transmit(®, 1); - handle.Transmit(data, len); + handle.transmit(®, 1); + handle.transmit(data, len); - chip_select.Set(true); + chip_select.set(true); } - std::uint8_t ReadRegister(std::uint8_t reg, + std::uint8_t readRegister(std::uint8_t reg, const std::uint32_t read_delay = 0) { - chip_select.Set(false); + chip_select.set(false); - handle.Transmit(®, 1); + handle.transmit(®, 1); std::uint8_t output = 255; if (read_delay) - StaticHal::DelayUs(read_delay); + StaticHal::delayUs(read_delay); - handle.Receive(&output, 1); + handle.receive(&output, 1); - chip_select.Set(true); + chip_select.set(true); return output; } - void ReadRegisterMultibyte(std::uint8_t reg, std::uint8_t* data, + void readRegisterMultibyte(std::uint8_t reg, std::uint8_t* data, const std::uint32_t len, const std::uint32_t read_delay = 0) { - chip_select.Set(false); + chip_select.set(false); - handle.Transmit(®, 1); + handle.transmit(®, 1); if (read_delay) - StaticHal::DelayUs(read_delay); + StaticHal::delayUs(read_delay); - handle.Receive(data, len); + handle.receive(data, len); - chip_select.Set(true); + chip_select.set(true); } }; @@ -281,23 +281,23 @@ struct PwmChannel explicit PwmChannel(TIM_HandleTypeDef* handle, const std::uint32_t channel) : handle(handle), channel(channel) {} - void Enable() { HAL_TIM_PWM_Start(handle, channel); } + void enable() { HAL_TIM_PWM_Start(handle, channel); } - void Disable() { HAL_TIM_PWM_Stop(handle, channel); } + void disable() { HAL_TIM_PWM_Stop(handle, channel); } - void SetCompare(const std::uint32_t compare) + void setCompare(const std::uint32_t compare) { __HAL_TIM_SET_COMPARE(handle, channel, compare); } - std::uint32_t MaxValue() { return handle->Init.Period; } + std::uint32_t maxValue() { return handle->Init.Period; } }; #endif// HAL_TIM_MODULE_ENABLED struct ItmSerialInterface { - bool Transmit(std::uint8_t* data, const std::uint32_t data_len) + bool transmit(std::uint8_t* data, const std::uint32_t data_len) { for (std::uint32_t i = 0; i < data_len; i++) { @@ -307,11 +307,11 @@ struct ItmSerialInterface } template - bool Transmit(std::array& array) + bool transmit(std::array& array) { static_assert(sizeof(T) == sizeof(std::uint8_t), "Data is not a byte large."); - return Transmit(reinterpret_cast(array.data()), std::uint32_t(N)); + return transmit(reinterpret_cast(array.data()), std::uint32_t(N)); } }; @@ -319,4 +319,4 @@ struct ItmSerialInterface }// namespace Hal }// namespace Peripherals -#endif /* PERIPHERALS_INC_PERIPHERALS_HAL_ST_HPP_ */ +#endif /* SKULLC_PERIPHERALS_HAL_ST_HPP_ */ diff --git a/Peripherals/Inc/peripherals_imu.hpp b/Peripherals/Inc/peripherals_imu.hpp index 045b02b..db4065d 100644 --- a/Peripherals/Inc/peripherals_imu.hpp +++ b/Peripherals/Inc/peripherals_imu.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_IMU_HPP_ -#define PERIPHERALS_IMU_HPP_ +#ifndef SKULLC_PERIPHERALS_IMU_HPP_ +#define SKULLC_PERIPHERALS_IMU_HPP_ #include @@ -23,16 +23,16 @@ public: Z }; - virtual void Setup() = 0; - virtual void Calibrate(const std::uint32_t samples) = 0; + virtual void setup() = 0; + virtual void calibrate(const std::uint32_t samples) = 0; - virtual void ReadGyro(float* output) = 0; - virtual void ReadGyroRaw(std::int16_t* output) = 0; + virtual void readGyro(float* output) = 0; + virtual void readGyroRaw(std::int16_t* output) = 0; - virtual void ReadAccelerometer(float* output) = 0; - virtual void ReadAccelerometerRaw(std::int16_t* output) = 0; + virtual void readAccelerometer(float* output) = 0; + virtual void readAccelerometerRaw(std::int16_t* output) = 0; }; }// namespace Peripherals -#endif /* PERIPHERALS_IMU_HPP_ */ +#endif /* SKULLC_PERIPHERALS_IMU_HPP_ */ diff --git a/Peripherals/Inc/peripherals_imu_icm.hpp b/Peripherals/Inc/peripherals_imu_icm.hpp index ea57abe..4ecb0d9 100644 --- a/Peripherals/Inc/peripherals_imu_icm.hpp +++ b/Peripherals/Inc/peripherals_imu_icm.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_IMU_ICM_HPP_ -#define PERIPHERALS_IMU_ICM_HPP_ +#ifndef SKULLC_PERIPHERALS_IMU_ICM_HPP_ +#define SKULLC_PERIPHERALS_IMU_ICM_HPP_ #include #include @@ -45,42 +45,42 @@ public: ImuIcm() = delete; ImuIcm(const registers_handle& registers) : registers(registers) {} - void Setup() override + void setup() override { - registers.WriteRegister(_Registers::PWR_MGMT_1 & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::PWR_MGMT_1 & Registers_::WRITE_MASK, 0b10000000); - hal::Delay(10); + hal::delay(10); - registers.WriteRegister(_Registers::USER_CTRL & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::USER_CTRL & Registers_::WRITE_MASK, 0b00010000); - hal::Delay(10); + hal::delay(10); - registers.WriteRegister(_Registers::PWR_MGMT_1 & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::PWR_MGMT_1 & Registers_::WRITE_MASK, 0b00000000); - hal::Delay(10); + hal::delay(10); - registers.WriteRegister(_Registers::PWR_MGMT_1 & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::PWR_MGMT_1 & Registers_::WRITE_MASK, 0b00000001); - hal::Delay(10); + hal::delay(10); - registers.WriteRegister(_Registers::CONFIG & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::CONFIG & Registers_::WRITE_MASK, 0x03);// DLPF_CFG = 3, gyro filter = 41/59.0, gyro // rate = 1KHz, temp filter = 42 - hal::Delay(10); + hal::delay(10); - SetGyroscopeScale(_scale_gyro); + setGyroscopeScale(scale_gyro_); - SetAccelerometerScale(_scale_accel); + setAccelerometerScale(scale_accel_); // ACCEL_FCHOICE_B = 0, A_DLPF_CFG = 3 filter=44.8/61.5 rate=1KHz - registers.WriteRegister(_Registers::ACCEL_CONFIG2 & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::ACCEL_CONFIG2 & Registers_::WRITE_MASK, 0x03); - hal::Delay(10); + hal::delay(10); // SAMPLE_RATE = INTERNAL_SAMPLE_RATE / (1 + SMPLRT_DIV) Where // INTERNAL_SAMPLE_RATE = 1kHz - registers.WriteRegister(_Registers::SMPLRT_DIV & _Registers::WRITE_MASK, 0); - hal::Delay(10); + registers.writeRegister(Registers_::SMPLRT_DIV & Registers_::WRITE_MASK, 0); + hal::delay(10); // Enable interrupt @@ -88,15 +88,15 @@ public: // INT/DRDY pin is configured as push-pull. // INT/DRDY pin indicates interrupt pulse's width is 50us. // Interrupt status is cleared only by reading INT_STATUS register - registers.WriteRegister(_Registers::INT_PIN_CFG & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::INT_PIN_CFG & Registers_::WRITE_MASK, 0); - hal::Delay(10); + hal::delay(10); - registers.WriteRegister(_Registers::INT_ENABLE & _Registers::WRITE_MASK, 1); - hal::Delay(10); + registers.writeRegister(Registers_::INT_ENABLE & Registers_::WRITE_MASK, 1); + hal::delay(10); } - void Calibrate(const std::uint32_t samples) override + void calibrate(const std::uint32_t samples) override { std::array avg_gyro; std::array avg_accel; @@ -109,10 +109,10 @@ public: out[j] += raw[j]; }; - ReadGyroRaw(raw.data()); + readGyroRaw(raw.data()); add_to_avg(avg_gyro); - ReadAccelerometerRaw(raw.data()); + readAccelerometerRaw(raw.data()); add_to_avg(avg_accel); } @@ -121,128 +121,128 @@ public: const std::int32_t max = std::numeric_limits::max(); const std::int32_t min = std::numeric_limits::min(); - _bias_gyro[i] = Clamp(avg_gyro[i], max, min); - _bias_accel[i] = Clamp(avg_accel[i], max, min); + bias_gyro_[i] = clamp(avg_gyro[i], max, min); + bias_accel_[i] = clamp(avg_accel[i], max, min); } - _bias_accel[2] -= AccelerometerReadingToRaw(1); + bias_accel_[2] -= accelerometerReadingToRaw(1); } - void SetGyroscopeScale(const GyroScale scale) + void setGyroscopeScale(const GyroScale scale) { const std::uint8_t current_config = - registers.ReadRegister(_Registers::GYRO_CONFIG | _Registers::READ_MASK); + registers.readRegister(Registers_::GYRO_CONFIG | Registers_::READ_MASK); const std::uint8_t new_config = (current_config & 0xE7) | (std::uint8_t(scale) << 3); - registers.WriteRegister(_Registers::GYRO_CONFIG & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::GYRO_CONFIG & Registers_::WRITE_MASK, new_config); - _scale_gyro = scale; + scale_gyro_ = scale; } - void SetAccelerometerScale(const AccelerometerScale scale) + void setAccelerometerScale(const AccelerometerScale scale) { - const std::uint8_t current_config = registers.ReadRegister( - _Registers::ACCEL_CONFIG | _Registers::READ_MASK); + const std::uint8_t current_config = registers.readRegister( + Registers_::ACCEL_CONFIG | Registers_::READ_MASK); const std::uint8_t new_config = (current_config & 0xE7) | (std::uint8_t(scale) << 3); - registers.WriteRegister(_Registers::ACCEL_CONFIG & _Registers::WRITE_MASK, + registers.writeRegister(Registers_::ACCEL_CONFIG & Registers_::WRITE_MASK, new_config); - _scale_accel = scale; + scale_accel_ = scale; } - void ReadGyro(float* output) override + void readGyro(float* output) override { uint8_t data[6] = {0}; - registers.ReadRegisterMultibyte( - _Registers::GYRO_XOUT_H | _Registers::READ_MASK, data, 6); + registers.readRegisterMultibyte( + Registers_::GYRO_XOUT_H | Registers_::READ_MASK, data, 6); for (std::uint32_t i = 0; i < 3; i++) { - const std::int16_t bit = ByteToTypeBE(&data[i * 2]); - output[i] = GyroRawToReading(bit); + const std::int16_t bit = byteToTypeBE(&data[i * 2]); + output[i] = gyroRawToReading(bit); } } - void ReadGyroRaw(std::int16_t* output) override + void readGyroRaw(std::int16_t* output) override { uint8_t data[6] = {0}; - registers.ReadRegisterMultibyte( - _Registers::GYRO_XOUT_H | _Registers::READ_MASK, data, 6); + registers.readRegisterMultibyte( + Registers_::GYRO_XOUT_H | Registers_::READ_MASK, data, 6); for (std::uint32_t i = 0; i < 3; i++) { - output[i] = ByteToTypeBE(&data[i * 2]); + output[i] = byteToTypeBE(&data[i * 2]); } } - void ReadAccelerometer(float* output) override + void readAccelerometer(float* output) override { uint8_t data[6] = {0}; - registers.ReadRegisterMultibyte( - _Registers::ACCEL_XOUT_H | _Registers::READ_MASK, data, 6); + registers.readRegisterMultibyte( + Registers_::ACCEL_XOUT_H | Registers_::READ_MASK, data, 6); for (std::uint32_t i = 0; i < 3; i++) { - const std::int16_t bit = ByteToTypeBE(&data[i * 2]); - output[i] = AccelerometerRawToReading(bit); + const std::int16_t bit = byteToTypeBE(&data[i * 2]); + output[i] = accelerometerRawToReading(bit); } } - void ReadAccelerometerRaw(std::int16_t* output) override + void readAccelerometerRaw(std::int16_t* output) override { uint8_t data[6] = {0}; - registers.ReadRegisterMultibyte( - _Registers::ACCEL_XOUT_H | _Registers::READ_MASK, data, 6); + registers.readRegisterMultibyte( + Registers_::ACCEL_XOUT_H | Registers_::READ_MASK, data, 6); for (std::uint32_t i = 0; i < 3; i++) { - output[i] = ByteToTypeBE(&data[i * 2]); + output[i] = byteToTypeBE(&data[i * 2]); } } - std::int16_t AccelerometerReadingToRaw(const float& fs) const + std::int16_t accelerometerReadingToRaw(const float& fs) const { - return fs / _accel_fs_to_bit_constants[std::uint32_t(_scale_accel)]; + return fs / accel_fs_to_bit_constants_[std::uint32_t(scale_accel_)]; } - std::int16_t GyroReadingToRaw(const float& fs) const + std::int16_t gyroReadingToRaw(const float& fs) const { - return fs / _gyro_fs_to_bit_constants[std::uint32_t(_scale_gyro)]; + return fs / gyro_fs_to_bit_constants_[std::uint32_t(scale_gyro_)]; } - float AccelerometerRawToReading(const std::int16_t bit) const + float accelerometerRawToReading(const std::int16_t bit) const { - return float(bit) * _accel_fs_to_bit_constants[std::uint32_t(_scale_accel)]; + return float(bit) * accel_fs_to_bit_constants_[std::uint32_t(scale_accel_)]; } - float GyroRawToReading(const std::int16_t bit) const + float gyroRawToReading(const std::int16_t bit) const { - return float(bit) * _gyro_fs_to_bit_constants[std::uint32_t(_scale_gyro)]; + return float(bit) * gyro_fs_to_bit_constants_[std::uint32_t(scale_gyro_)]; } std::uint8_t readProductId() { - return registers.ReadRegister(_Registers::WHO_AM_I | _Registers::READ_MASK); + return registers.readRegister(Registers_::WHO_AM_I | Registers_::READ_MASK); } private: - GyroScale _scale_gyro = GyroScale::DPS_2000; - AccelerometerScale _scale_accel = AccelerometerScale::G16; + GyroScale scale_gyro_ = GyroScale::DPS_2000; + AccelerometerScale scale_accel_ = AccelerometerScale::G16; - std::array _bias_gyro; - std::array _bias_accel; + std::array bias_gyro_; + std::array bias_accel_; - static constexpr float _accel_fs_to_bit_constants[4] = { + static constexpr float accel_fs_to_bit_constants_[4] = { (2.0f / 32768.0f), (4.0f / 32768.0f), (8.0f / 32768.0f), (16.0f / 32768.0f)}; - static constexpr float _gyro_fs_to_bit_constants[4] = { + static constexpr float gyro_fs_to_bit_constants_[4] = { (250.0f / 32768.0f), (500.0f / 32768.0f), (1000.0f / 32768.0f), (2000.0f / 32768.0f)}; - struct _Registers + struct Registers_ { static constexpr std::uint32_t ICM20689_ID = 0x98; @@ -295,11 +295,11 @@ private: }; template -constexpr float ImuIcm::_accel_fs_to_bit_constants[4]; +constexpr float ImuIcm::accel_fs_to_bit_constants_[4]; template -constexpr float ImuIcm::_gyro_fs_to_bit_constants[4]; +constexpr float ImuIcm::gyro_fs_to_bit_constants_[4]; }// namespace Peripherals -#endif /* PERIPHERALS_IMU_ICM_HPP_ */ +#endif /* SKULLC_PERIPHERALS_IMU_ICM_HPP_ */ diff --git a/Peripherals/Inc/peripherals_ir_sensors.hpp b/Peripherals/Inc/peripherals_ir_sensors.hpp index 6b2f794..46399f6 100644 --- a/Peripherals/Inc/peripherals_ir_sensors.hpp +++ b/Peripherals/Inc/peripherals_ir_sensors.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_IR_SENSORS_HPP_ -#define PERIPHERALS_IR_SENSORS_HPP_ +#ifndef SKULLC_PERIPHERALS_IR_SENSORS_HPP_ +#define SKULLC_PERIPHERALS_IR_SENSORS_HPP_ #include #include @@ -31,23 +31,23 @@ public: explicit IrSensors(ADC_HandleTypeDef* hadc, const std::array& channels, Args&&... gpios) - : adc(hadc), _channels(channels), _gpios{std::forward(gpios)...} + : adc(hadc), channels_(channels), gpios_{std::forward(gpios)...} { static_assert(sizeof...(Args) == N, "Not enough GPIOs passed."); } void startReading() { - for (auto& gpio : _gpios) - gpio.Set(true); + for (auto& gpio : gpios_) + gpio.set(true); adc.startDma(); } void stopReading() { - for (auto& gpio : _gpios) - gpio.Set(false); + for (auto& gpio : gpios_) + gpio.set(false); adc.stopDma(); } @@ -56,8 +56,8 @@ public: { for (std::size_t i = 0; i < N; i++) { - _averages[i] -= _averages[i] / Average; - _averages[i] += adc.readings[i] / Average; + averages_[i] -= averages_[i] / Average; + averages_[i] += adc.readings[i] / Average; } } @@ -67,10 +67,10 @@ public: for (std::size_t i = 0; i < N; i++) { - const float interim = _averages[i] - _offsets[i]; + const float interim = averages_[i] - offsets_[i]; - data[i].first = _multipliers[i] * std::pow(interim, _exponents[i]); - data[i].second = data[i].first < _wall_thresholds[i]; + data[i].first = multipliers_[i] * std::pow(interim, exponents_[i]); + data[i].second = data[i].first < wall_thresholds_[i]; } return data; @@ -82,41 +82,41 @@ public: for (std::uint32_t i = 0; i < samples; i++) { - for (std::uint32_t ch = 0; ch < _channels.size(); ch++) - measurements[ch] += adc.read(_channels[ch], sample_time, 100); + for (std::uint32_t ch = 0; ch < channels_.size(); ch++) + measurements[ch] += adc.read(channels_[ch], sample_time, 100); } - for (std::uint32_t ch = 0; ch < _channels.size(); ch++) - _offsets[ch] = std::uint16_t(measurements[ch] / samples); + for (std::uint32_t ch = 0; ch < channels_.size(); ch++) + offsets_[ch] = std::uint16_t(measurements[ch] / samples); } void setExponents(const std::array& e) { - _exponents = e; + exponents_ = e; } void setMultipliers(const std::array& m) { - _multipliers = m; + multipliers_ = m; } void setWallThresholds(const std::array& t) { - _wall_thresholds = t; + wall_thresholds_ = t; } private: - std::array _channels; - std::array _gpios; - std::array _averages; + std::array channels_; + std::array gpios_; + std::array averages_; - std::array _offsets; - std::array _exponents; - std::array _multipliers; - std::array _wall_thresholds; + std::array offsets_; + std::array exponents_; + std::array multipliers_; + std::array wall_thresholds_; }; }// namespace Peripherals -#endif /* PERIPHERALS_IR_SENSORS_HPP_ */ +#endif /* SKULLC_PERIPHERALS_IR_SENSORS_HPP_ */ diff --git a/Peripherals/Inc/peripherals_motors.hpp b/Peripherals/Inc/peripherals_motors.hpp index 3c8777e..f733b4d 100644 --- a/Peripherals/Inc/peripherals_motors.hpp +++ b/Peripherals/Inc/peripherals_motors.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_MOTORS_HPP_ -#define PERIPHERALS_MOTORS_HPP_ +#ifndef SKULLC_PERIPHERALS_MOTORS_HPP_ +#define SKULLC_PERIPHERALS_MOTORS_HPP_ namespace Peripherals { @@ -22,9 +22,9 @@ struct TwoChannelMotorData class IMotors { public: - virtual void Set(const std::int16_t left, const std::int16_t right) = 0; - virtual void Coast() = 0; - virtual void Break() = 0; + virtual void set(const std::int16_t left, const std::int16_t right) = 0; + virtual void coast() = 0; + virtual void setBreak() = 0; }; template @@ -36,63 +36,63 @@ public: DualDrvMotors(const single_motor& left, const single_motor& right, const gpio& sleep_pin) - : _left(left), _right(right), _sleep_pin(sleep_pin) + : left_(left), right_(right), sleep_pin_(sleep_pin) { - _left.forward.Enable(); - _left.backward.Enable(); - _right.forward.Enable(); - _right.backward.Enable(); + left_.forward.enable(); + left_.backward.enable(); + right_.forward.enable(); + right_.backward.enable(); - Set(0, 0); + set(0, 0); } - virtual void Set(const std::int16_t left, const std::int16_t right) override + virtual void set(const std::int16_t left, const std::int16_t right) override { if (left > 0) { - _left.forward.SetCompare(left); - _left.backward.SetCompare(0); + left_.forward.setCompare(left); + left_.backward.setCompare(0); } else { - _left.forward.SetCompare(0); - _left.backward.SetCompare(-1 * left); + left_.forward.setCompare(0); + left_.backward.setCompare(-1 * left); } if (right > 0) { - _right.forward.SetCompare(right); - _right.backward.SetCompare(0); + right_.forward.setCompare(right); + right_.backward.setCompare(0); } else { - _right.forward.SetCompare(0); - _right.backward.SetCompare(-1 * right); + right_.forward.setCompare(0); + right_.backward.setCompare(-1 * right); } } - virtual void Coast() override + virtual void coast() override { - _left.forward.SetCompare(0); - _left.backward.SetCompare(0); + left_.forward.setCompare(0); + left_.backward.setCompare(0); - _right.forward.SetCompare(0); - _right.backward.SetCompare(0); + right_.forward.setCompare(0); + right_.backward.setCompare(0); } - virtual void Break() override + virtual void setBreak() override { - _left.forward.SetCompare(_left.forward.MaxValue()); - _left.backward.SetCompare(_left.backward.MaxValue()); + left_.forward.setCompare(left_.forward.maxValue()); + left_.backward.setCompare(left_.backward.maxValue()); - _right.forward.SetCompare(_right.forward.MaxValue()); - _right.backward.SetCompare(_right.backward.MaxValue()); + right_.forward.setCompare(right_.forward.maxValue()); + right_.backward.setCompare(right_.backward.maxValue()); } private: - single_motor _left; - single_motor _right; - gpio _sleep_pin; + single_motor left_; + single_motor right_; + gpio sleep_pin_; }; }// namespace Peripherals -#endif /* PERIPHERALS_MOTORS_HPP_ */ +#endif /* SKULLC_PERIPHERALS_MOTORS_HPP_ */ diff --git a/Peripherals/Inc/peripherals_pwm_channel.hpp b/Peripherals/Inc/peripherals_pwm_channel.hpp deleted file mode 100644 index f31183c..0000000 --- a/Peripherals/Inc/peripherals_pwm_channel.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * peripherals_pwm.hpp - * - * Created on: Feb 24, 2021 - * Author: erki - */ - -#ifndef PERIPHERALS_PWM_CHANNEL_HPP_ -#define PERIPHERALS_PWM_CHANNEL_HPP_ - -#include - -#include - -#include "peripherals_io.hpp" - -namespace Peripherals -{ - -struct PwmChannel -{ - TIM_HandleTypeDef* timer; - std::uint32_t channel; - std::uint32_t timer_code; - Io pin; - - PwmChannel() = delete; - - PwmChannel(TIM_HandleTypeDef* timer, const std::uint32_t channel, - const std::uint32_t timer_code, const Io& pin); - - void PinToPwm(); - void PinToGpio(); - - void Enable(); - void Disable(); - - void SetCompare(const std::uint32_t compare); -}; - -}// namespace Peripherals - -#endif /* PERIPHERALS_PWM_CHANNEL_HPP_ */ diff --git a/Peripherals/Inc/peripherals_rgb.hpp b/Peripherals/Inc/peripherals_rgb.hpp index 12fa144..221e754 100644 --- a/Peripherals/Inc/peripherals_rgb.hpp +++ b/Peripherals/Inc/peripherals_rgb.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ -#define PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ +#ifndef SKULLC_PERIPHERALS_RGB_HPP_ +#define SKULLC_PERIPHERALS_RGB_HPP_ namespace Peripherals { @@ -38,54 +38,54 @@ struct Rgb Rgb(const IOType& r, const IOType& g, const IOType& b) : red(r), green(g), blue(b) { - Set(RgbColor::OFF); + set(RgbColor::OFF); } - void Set(const RgbColor& new_color) + void set(const RgbColor& new_color) { color = new_color; switch (color) { case RgbColor::OFF: - red.Set(false); - green.Set(false); - blue.Set(false); + red.set(false); + green.set(false); + blue.set(false); break; case RgbColor::RED: - red.Set(true); - green.Set(false); - blue.Set(false); + red.set(true); + green.set(false); + blue.set(false); break; case RgbColor::GREEN: - red.Set(false); - green.Set(true); - blue.Set(false); + red.set(false); + green.set(true); + blue.set(false); break; case RgbColor::BLUE: - red.Set(false); - green.Set(false); - blue.Set(true); + red.set(false); + green.set(false); + blue.set(true); break; case RgbColor::CYAN: - red.Set(false); - green.Set(true); - blue.Set(true); + red.set(false); + green.set(true); + blue.set(true); break; case RgbColor::PINK: - red.Set(true); - green.Set(false); - blue.Set(true); + red.set(true); + green.set(false); + blue.set(true); break; case RgbColor::YELLOW: - red.Set(true); - green.Set(true); - blue.Set(false); + red.set(true); + green.set(true); + blue.set(false); break; case RgbColor::WHITE: - red.Set(true); - green.Set(true); - blue.Set(true); + red.set(true); + green.set(true); + blue.set(true); break; } } @@ -93,4 +93,4 @@ struct Rgb }// namespace Peripherals -#endif /* PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ */ +#endif /* SKULLC_PERIPHERALS_RGB_HPP_ */ diff --git a/Peripherals/Inc/peripherals_ssd1306_display.hpp b/Peripherals/Inc/peripherals_ssd1306_display.hpp index 1fdcc83..636d124 100644 --- a/Peripherals/Inc/peripherals_ssd1306_display.hpp +++ b/Peripherals/Inc/peripherals_ssd1306_display.hpp @@ -40,30 +40,30 @@ struct SSD1306WriteAdapter */ void writeCommand(std::uint8_t data) { - dc.Set(false); + dc.set(false); - cs.Set(false); - registers.Transmit(&data, 1); - cs.Set(true); + cs.set(false); + registers.transmit(&data, 1); + cs.set(true); } void writeCommand(std::uint8_t command, std::uint8_t data) { - dc.Set(false); + dc.set(false); - cs.Set(false); - registers.Transmit(&command, 1); - registers.Transmit(&data, 1); - cs.Set(true); + cs.set(false); + registers.transmit(&command, 1); + registers.transmit(&data, 1); + cs.set(true); } void writeData(std::uint8_t* data, const std::uint32_t len) { - dc.Set(true); + dc.set(true); - cs.Set(false); - registers.Transmit(data, len); - cs.Set(true); + cs.set(false); + registers.transmit(data, len); + cs.set(true); } }; @@ -100,29 +100,29 @@ public: void setup() { - hal::Delay(1); - reset_.Set(false); - hal::Delay(5); - reset_.Set(true); - hal::Delay(5); + hal::delay(1); + reset_.set(false); + hal::delay(5); + reset_.set(true); + hal::delay(5); // reference impl: https://gitlab.com/TTYRobotiklubi/micromouse/mousetrap2/-/blob/master/Src/Peripherals/lcd.c - //Set the display to sleep mode for the rest of the init. + //set the display to sleep mode for the rest of the init. registers_.writeCommand(Regs_::DISPLAY_OFF_YES_SLEEP); - //Set the clock speed, nominal ~105FPS + //set the clock speed, nominal ~105FPS //Low nibble is divide ratio //High level is oscillator frequency. Should be about 177 Hz. registers_.writeCommand(Regs_::CLOCK_DIVIDE_PREFIX, 0x80); - //Set the multiplex ratio to 1/32 + //set the multiplex ratio to 1/32 //Default is 0x3F (1/64 Duty), we need 0x1F (1/32 Duty) registers_.writeCommand(Regs_::MULTIPLEX_RATIO_PREFIX, 0x1F); - //Set the display offset to 0 (default) + //set the display offset to 0 (default) registers_.writeCommand(Regs_::DISPLAY_OFFSET_PREFIX, 0x00); - //Set the display RAM display start line to 0 (default) + //set the display RAM display start line to 0 (default) //Bits 0-5 can be set to 0-63 with a bitwise or registers_.writeCommand(Regs_::DISPLAY_START_LINE); @@ -132,24 +132,24 @@ public: //Map the columns correctly for our OLED glass layout. registers_.writeCommand(Regs_::SEG0_IS_COL_0); - //Set COM output scan correctly for our OLED glass layout. + //set COM output scan correctly for our OLED glass layout. registers_.writeCommand(Regs_::SCAN_DIR_UP); - //Set COM pins correctly for our OLED glass layout + //set COM pins correctly for our OLED glass layout registers_.writeCommand(Regs_::COM_CONFIG_PREFIX, Regs_::COM_CONFIG_SEQUENTIAL_LEFT); // Contrast. registers_.writeCommand(Regs_::CONTRAST_PREFIX, 0xBF); - // Set precharge (low nibble) / discharge (high nibble) timing. + // set precharge (low nibble) / discharge (high nibble) timing. // precharge = 1 clock // discharge = 15 clocks registers_.writeCommand(Regs_::PRECHARGE_PERIOD_PREFIX, 0xF1); - // Set VCOM deselect level. + // set VCOM deselect level. registers_.writeCommand(Regs_::VCOMH_DESELECT_PREFIX, Regs_::VCOMH_DESELECT_0p83xVCC); - // Set display to normal. + // set display to normal. registers_.writeCommand(Regs_::ENTIRE_DISPLAY_NORMAL); // Uninvert the display. diff --git a/Peripherals/Inc/peripherals_utility.hpp b/Peripherals/Inc/peripherals_utility.hpp index 077b683..34b2691 100644 --- a/Peripherals/Inc/peripherals_utility.hpp +++ b/Peripherals/Inc/peripherals_utility.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef PERIPHERALS_UTILITY_HPP_ -#define PERIPHERALS_UTILITY_HPP_ +#ifndef SKULLC_PERIPHERALS_UTILITY_HPP_ +#define SKULLC_PERIPHERALS_UTILITY_HPP_ #include #include @@ -20,7 +20,7 @@ namespace Peripherals #define SKULLC_TAG struct SKULLC_CONCAT(SkullCTag_, __COUNTER__) template -constexpr const T& Clamp(const T& v, const T& lo, const T& hi) +constexpr const T& clamp(const T& v, const T& lo, const T& hi) { if (v > hi) return hi; @@ -31,7 +31,7 @@ constexpr const T& Clamp(const T& v, const T& lo, const T& hi) } template -T ByteToTypeBE(const std::uint8_t a[N]) +T byteToTypeBE(const std::uint8_t a[N]) { T t(0); @@ -44,7 +44,7 @@ T ByteToTypeBE(const std::uint8_t a[N]) } template -T ByteToTypeLE(const std::uint8_t a[N]) +T byteToTypeLE(const std::uint8_t a[N]) { T t(0); @@ -69,4 +69,4 @@ constexpr T zeroInitialized() }// namespace Peripherals -#endif /* PERIPHERALS_UTILITY_HPP_ */ +#endif /* SKULLC_PERIPHERALS_UTILITY_HPP_ */ diff --git a/Utility/Inc/utility_asynclogger.hpp b/Utility/Inc/utility_asynclogger.hpp index 357a11e..a944b30 100644 --- a/Utility/Inc/utility_asynclogger.hpp +++ b/Utility/Inc/utility_asynclogger.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef UTILITY_INC_UTILITY_ASYNCLOGGER_HPP_ -#define UTILITY_INC_UTILITY_ASYNCLOGGER_HPP_ +#ifndef SKULLC_UTILITY_ASYNCLOGGER_HPP_ +#define SKULLC_UTILITY_ASYNCLOGGER_HPP_ #include "utility_atomicscopeguard.hpp" #include "utility_ilogger.hpp" @@ -28,7 +28,7 @@ public: using hal = H; AsyncLogger() = delete; - explicit AsyncLogger(const serial_interface& serial) : _serial(serial) {} + explicit AsyncLogger(const serial_interface& serial) : serial_(serial) {} AsyncLogger(const AsyncLogger&) = delete; AsyncLogger(AsyncLogger&&) = delete; @@ -40,23 +40,23 @@ public: { AtomicScopeGuard s; - if (_buffer_queue.size() == _buffer_queue.max_size()) + if (buffer_queue_.size() == buffer_queue_.max_size()) return; } std::va_list args; va_start(args, format); - _Data& tail = (*_buffer_queue.end()); + Data_& tail = (*buffer_queue_.end()); tail.length = vsnprintf(tail.buffer.data(), tail.buffer.size(), format, args); { AtomicScopeGuard s; - _buffer_queue.increment_tail(); + buffer_queue_.increment_tail(); - if (!_in_flight) - _sendNextLog(); + if (!in_flight_) + sendNextLog_(); } va_end(args); @@ -64,34 +64,35 @@ public: void txCompleteCallback() { - if (!_buffer_queue.empty()) - _sendNextLog(); + if (!buffer_queue_.empty()) + sendNextLog_(); else - _in_flight = false; + in_flight_ = false; } private: - struct _Data + struct Data_ { std::array buffer; std::int32_t length = 0; }; - Ringbuffer<_Data, BufferCount> _buffer_queue; - serial_interface _serial; - bool _in_flight = false; + Ringbuffer buffer_queue_; + serial_interface serial_; + /// @todo: thread safety + bool in_flight_ = false; - void _sendNextLog() + void sendNextLog_() { - _in_flight = true; + in_flight_ = true; - _Data& head = _buffer_queue.front(); - _serial.Transmit(reinterpret_cast(head.buffer.data()), + Data_& head = buffer_queue_.front(); + serial_.transmit(reinterpret_cast(head.buffer.data()), head.length); - _buffer_queue.pop_front(); + buffer_queue_.pop_front(); } }; }// namespace Utility -#endif /* UTILITY_INC_UTILITY_ASYNCLOGGER_HPP_ */ +#endif /* SKULLC_UTILITY_ASYNCLOGGER_HPP_ */ diff --git a/Utility/Inc/utility_atomicscopeguard.hpp b/Utility/Inc/utility_atomicscopeguard.hpp index 9c2630d..f4375e8 100644 --- a/Utility/Inc/utility_atomicscopeguard.hpp +++ b/Utility/Inc/utility_atomicscopeguard.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef UTILITY_INC_UTILITY_ATOMICSCOPEGUARD_HPP_ -#define UTILITY_INC_UTILITY_ATOMICSCOPEGUARD_HPP_ +#ifndef SKULLC_UTILITY_ATOMICSCOPEGUARD_HPP_ +#define SKULLC_UTILITY_ATOMICSCOPEGUARD_HPP_ #include @@ -20,7 +20,7 @@ struct AtomicScopeGuard AtomicScopeGuard() { hal::disableInterrupts(); - _reentrancy_counter++; + reentrancy_counter_++; } AtomicScopeGuard(const AtomicScopeGuard&) = delete; @@ -30,19 +30,19 @@ struct AtomicScopeGuard ~AtomicScopeGuard() { - _reentrancy_counter--; + reentrancy_counter_--; - if (!_reentrancy_counter) + if (!reentrancy_counter_) hal::enableInterrupts(); } private: - static std::int32_t _reentrancy_counter; + static std::int32_t reentrancy_counter_; }; template -std::int32_t AtomicScopeGuard::_reentrancy_counter = 0; +std::int32_t AtomicScopeGuard::reentrancy_counter_ = 0; }// namespace Utility -#endif /* UTILITY_INC_UTILITY_ATOMICSCOPEGUARD_HPP_ */ +#endif /* SKULLC_UTILITY_ATOMICSCOPEGUARD_HPP_ */ diff --git a/Utility/Inc/utility_fixedpoint.hpp b/Utility/Inc/utility_fixedpoint.hpp index 7c286c0..785bb02 100644 --- a/Utility/Inc/utility_fixedpoint.hpp +++ b/Utility/Inc/utility_fixedpoint.hpp @@ -2,8 +2,8 @@ // Created by erki on 30.04.21. // -#ifndef SKULLC_UTILITY_FIXEDPOINT_HPP -#define SKULLC_UTILITY_FIXEDPOINT_HPP +#ifndef SKULLC_UTILITY_FIXEDPOINT_HPP_ +#define SKULLC_UTILITY_FIXEDPOINT_HPP_ #include #include @@ -303,4 +303,4 @@ using Q31 = FixedPoint; }// namespace Peripherals -#endif//SKULLC_UTILITY_FIXEDPOINT_HPP +#endif//SKULLC_UTILITY_FIXEDPOINT_HPP_ diff --git a/Utility/Inc/utility_logging.hpp b/Utility/Inc/utility_logging.hpp index 07c5474..73a7680 100644 --- a/Utility/Inc/utility_logging.hpp +++ b/Utility/Inc/utility_logging.hpp @@ -2,8 +2,8 @@ // Created by erki on 14.03.21. // -#ifndef UTILITY_LOGGING_HPP_ -#define UTILITY_LOGGING_HPP_ +#ifndef SKULLC_UTILITY_LOGGING_HPP_ +#define SKULLC_UTILITY_LOGGING_HPP_ #include "utility_ilogger.hpp" @@ -34,4 +34,4 @@ void setLogger(ILogger& log); }// namespace Utility -#endif// UTILITY_LOGGING_HPP_ +#endif// SKULLC_UTILITY_LOGGING_HPP_ diff --git a/Utility/Inc/utility_pixelbuffer_effects.hpp b/Utility/Inc/utility_pixelbuffer_effects.hpp index 55f50cf..8f69617 100644 --- a/Utility/Inc/utility_pixelbuffer_effects.hpp +++ b/Utility/Inc/utility_pixelbuffer_effects.hpp @@ -2,8 +2,8 @@ // Created by erki on 16.05.21. // -#ifndef SKULLC_UTILITY_PIXELBUFFER_EFFECTS_HPP -#define SKULLC_UTILITY_PIXELBUFFER_EFFECTS_HPP +#ifndef SKULLC_UTILITY_PIXELBUFFER_EFFECTS_HPP_ +#define SKULLC_UTILITY_PIXELBUFFER_EFFECTS_HPP_ #include #include @@ -115,4 +115,4 @@ class ScreenScroll }// namespace Effects }// namespace Utility -#endif//SKULLC_UTILITY_PIXELBUFFER_EFFECTS_HPP +#endif//SKULLC_UTILITY_PIXELBUFFER_EFFECTS_HPP_ diff --git a/Utility/Inc/utility_rand.hpp b/Utility/Inc/utility_rand.hpp index ce3b7af..b49729b 100644 --- a/Utility/Inc/utility_rand.hpp +++ b/Utility/Inc/utility_rand.hpp @@ -2,12 +2,12 @@ // Created by erki on 29.04.21. // -#ifndef SKULLC_UTILITY_RAND_HPP -#define SKULLC_UTILITY_RAND_HPP +#ifndef SKULLC_UTILITY_RAND_HPP_ +#define SKULLC_UTILITY_RAND_HPP_ #include -namespace Peripherals +namespace Utility { inline std::uint32_t rand32(std::uint32_t& state) @@ -35,6 +35,6 @@ inline std::uint64_t rand64(std::uint64_t& state) void srand(const std::uint32_t& seed); std::uint32_t rand(); -}// namespace Peripherals +}// namespace Utility -#endif//SKULLC_UTILITY_RAND_HPP +#endif//SKULLC_UTILITY_RAND_HPP_ diff --git a/Utility/Inc/utility_ringbuffer.hpp b/Utility/Inc/utility_ringbuffer.hpp index 41e5cae..506ccf7 100644 --- a/Utility/Inc/utility_ringbuffer.hpp +++ b/Utility/Inc/utility_ringbuffer.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef UTILITY_RINGBUFFER_HPP_ -#define UTILITY_RINGBUFFER_HPP_ +#ifndef SKULLC_UTILITY_RINGBUFFER_HPP_ +#define SKULLC_UTILITY_RINGBUFFER_HPP_ #include #include @@ -116,27 +116,27 @@ public: pointer _arr_end; }; - Ringbuffer() : _head(&_data[0], &_data[0], &_data[N]), _tail(_head) {} + Ringbuffer() : head_(&data_[0], &data_[0], &data_[N]), tail_(head_) {} Ringbuffer(const Ringbuffer&) = delete; Ringbuffer(Ringbuffer&&) noexcept = default; - iterator begin() { return _head; } + iterator begin() { return head_; } - iterator end() { return _tail; } + iterator end() { return tail_; } - void clear() { _head = _tail; } + void clear() { head_ = tail_; } void push_back(const T& value) { if (size() == N) return; - *_tail = value; - ++_tail; + *tail_ = value; + ++tail_; - if (_tail == _head) - _is_full = true; + if (tail_ == head_) + is_full_ = true; } template @@ -145,16 +145,16 @@ public: if (size() == N) return; - new (&*_tail) T(std::forward(args)...); - ++_tail; + new (&*tail_) T(std::forward(args)...); + ++tail_; } void increment_tail() { - if (_is_full) - ++_head; + if (is_full_) + ++head_; - ++_tail; + ++tail_; } void pop_front() @@ -162,49 +162,49 @@ public: if (empty()) return; - ++_head; - _is_full = false; + ++head_; + is_full_ = false; } - reference front() { return *_head; } + reference front() { return *head_; } - const_reference front() const { return *_head; } + const_reference front() const { return *head_; } reference back() { if (empty()) - return *_tail; + return *tail_; else - return *(_tail - 1); + return *(tail_ - 1); } const_reference back() const { if (empty()) - return *_tail; + return *tail_; else - return *(_tail - 1); + return *(tail_ - 1); } size_type size() const { - if (_head == _tail) + if (head_ == tail_) { - if (_is_full) + if (is_full_) return N; else return 0; } const typename Ringbuffer::iterator::difference_type distance = - _tail - _head; + tail_ - head_; if (distance > 0) { return distance; } else { - return _head - _tail + 1; + return head_ - tail_ + 1; } } @@ -213,13 +213,13 @@ public: bool empty() const { return size() == 0; } private: - std::array _data; - bool _is_full = false; + std::array data_; + bool is_full_ = false; - iterator _head; - iterator _tail; + iterator head_; + iterator tail_; }; }// namespace Utility -#endif /* UTILITY_RINGBUFFER_HPP_ */ +#endif /* SKULLC_UTILITY_RINGBUFFER_HPP_ */ diff --git a/Utility/Inc/utility_seriallogger.hpp b/Utility/Inc/utility_seriallogger.hpp index aeb68e5..c657a75 100644 --- a/Utility/Inc/utility_seriallogger.hpp +++ b/Utility/Inc/utility_seriallogger.hpp @@ -5,8 +5,8 @@ * Author: erki */ -#ifndef UTILITY_INC_UTILITY_SERIALLOGGER_HPP_ -#define UTILITY_INC_UTILITY_SERIALLOGGER_HPP_ +#ifndef SKULLC_UTILITY_SERIALLOGGER_HPP_ +#define SKULLC_UTILITY_SERIALLOGGER_HPP_ #include #include @@ -24,7 +24,7 @@ public: using serial_interface = T; SerialLogger() = delete; - explicit SerialLogger(const serial_interface& serial) : _serial(serial) {} + explicit SerialLogger(const serial_interface& serial) : serial_(serial) {} void log(const char* format, ...) override { @@ -32,19 +32,19 @@ public: va_start(args, format); const std::int32_t len = - vsnprintf(_buffer.data(), _buffer.size(), format, args); + vsnprintf(buffer_.data(), buffer_.size(), format, args); if (len > 0) - _serial.Transmit(reinterpret_cast(_buffer.data()), len); + serial_.transmit(reinterpret_cast(buffer_.data()), len); va_end(args); } private: - serial_interface _serial; - std::array _buffer; + serial_interface serial_; + std::array buffer_; }; }// namespace Utility -#endif /* UTILITY_INC_UTILITY_SERIALLOGGER_HPP_ */ +#endif /* SKULLC_UTILITY_SERIALLOGGER_HPP_ */ diff --git a/Utility/Src/utility_rand.cpp b/Utility/Src/utility_rand.cpp index 8ea7c6a..29d2596 100644 --- a/Utility/Src/utility_rand.cpp +++ b/Utility/Src/utility_rand.cpp @@ -11,7 +11,7 @@ std::uint32_t rand_state = 0; } -namespace Peripherals +namespace Utility { void srand(const std::uint32_t& seed) @@ -24,4 +24,4 @@ std::uint32_t rand() return rand32(rand_state); } -}// namespace Peripherals +}// namespace Utility