From 0ea2f9650e6b915c285635025e7e1b810482c4c2 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 5 Jan 2017 17:06:44 -0800 Subject: [PATCH] C++14: const all the methods! --- firmware/application/si5351.hpp | 26 +++++++++++++------------- firmware/common/i2c_pp.hpp | 6 +++--- firmware/common/memory_map.hpp | 6 +++--- firmware/common/spi_image.hpp | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/firmware/application/si5351.hpp b/firmware/application/si5351.hpp index e76a4bbb..58104f82 100644 --- a/firmware/application/si5351.hpp +++ b/firmware/application/si5351.hpp @@ -168,7 +168,7 @@ struct Inputs { const uint32_t f_clkin; const uint32_t clkin_div; - constexpr uint32_t f_clkin_out() { + constexpr uint32_t f_clkin_out() const { return f_clkin / clkin_div; } }; @@ -181,23 +181,23 @@ struct PLL { const uint32_t b; const uint32_t c; - constexpr uint32_t f_vco() { + constexpr uint32_t f_vco() const { return f_in * (a + (float)b / (float)c); } - constexpr uint32_t p1() { + constexpr uint32_t p1() const { return 128 * a + (uint32_t)(128 * (float)b / (float)c) - 512; } - constexpr uint32_t p2() { + constexpr uint32_t p2() const { return 128 * b - c * (uint32_t)(128 * (float)b / (float)c); } - constexpr uint32_t p3() { + constexpr uint32_t p3() const { return c; } - constexpr PLLReg reg(const uint8_t pll_n) { + constexpr PLLReg reg(const uint8_t pll_n) const { return { uint8_t(26 + (pll_n * 8)), uint8_t((p3() >> 8) & 0xff), @@ -224,23 +224,23 @@ struct MultisynthFractional { const uint32_t c; const uint32_t r_div; - constexpr uint32_t p1() { + constexpr uint32_t p1() const { return 128 * a + (uint32_t)(128 * (float)b / (float)c) - 512; } - constexpr uint32_t p2() { + constexpr uint32_t p2() const { return 128 * b - c * (uint32_t)(128 * (float)b / (float)c); } - constexpr uint32_t p3() { + constexpr uint32_t p3() const { return c; } - constexpr uint32_t f_out() { + constexpr uint32_t f_out() const { return f_src / (a + (float)b / (float)c) / (1 << r_div); } - constexpr MultisynthFractionalReg reg(const uint8_t multisynth_n) { + constexpr MultisynthFractionalReg reg(const uint8_t multisynth_n) const { return { uint8_t(42 + (multisynth_n * 8)), uint8_t((p3() >> 8) & 0xFF), @@ -260,11 +260,11 @@ struct MultisynthInteger { const uint32_t a; const uint32_t r_div; - constexpr uint8_t p1() { + constexpr uint8_t p1() const { return a; } - constexpr uint32_t f_out() { + constexpr uint32_t f_out() const { return f_src / a / (1 << r_div); } }; diff --git a/firmware/common/i2c_pp.hpp b/firmware/common/i2c_pp.hpp index 7eabab0b..62f729e7 100644 --- a/firmware/common/i2c_pp.hpp +++ b/firmware/common/i2c_pp.hpp @@ -46,15 +46,15 @@ struct I2CClockConfig { return 1e9 / f; } - constexpr uint32_t i2c_period_count() { + constexpr uint32_t i2c_period_count() const { return period_ns(bus_f) / period_ns(clock_source_f) + 0.5f; } - constexpr uint32_t i2c_high_count() { + constexpr uint32_t i2c_high_count() const { return high_period_ns / period_ns(clock_source_f) + 0.5f; } - constexpr uint32_t i2c_low_count() { + constexpr uint32_t i2c_low_count() const { return i2c_period_count() - i2c_high_count(); } }; diff --git a/firmware/common/memory_map.hpp b/firmware/common/memory_map.hpp index 8b32a0cd..d8624d74 100644 --- a/firmware/common/memory_map.hpp +++ b/firmware/common/memory_map.hpp @@ -43,15 +43,15 @@ public: } - constexpr uint32_t base() { + constexpr uint32_t base() const { return base_; } - constexpr uint32_t end() { + constexpr uint32_t end() const { return base_ + size_; } - constexpr size_t size() { + constexpr size_t size() const { return size_; } diff --git a/firmware/common/spi_image.hpp b/firmware/common/spi_image.hpp index e1143712..7b53fd75 100644 --- a/firmware/common/spi_image.hpp +++ b/firmware/common/spi_image.hpp @@ -86,7 +86,7 @@ struct region_t { const size_t offset; const size_t size; - constexpr const void* base() { + constexpr const void* base() const { return reinterpret_cast(portapack::memory::map::spifi_cached.base() + offset); } };