BM8563
The Bm8563 component provides a driver for the Bm8563 RTC chip.
API Reference
Header File
Functions
Warning
doxygenfunction: Unable to resolve function “operator==” with arguments None in doxygen xml output for project “esp-docs” from directory: /home/runner/work/espp/espp/doc/_build/en/esp32/xml_in/. Potential matches:
- bool operator==(const AdcConfig &lhs, const AdcConfig &rhs)
- bool operator==(const Config &rhs) const = default
- bool operator==(const DetentConfig &lhs, const DetentConfig &rhs)
- bool operator==(const Hsv &rhs) const = default
- bool operator==(const PinConfig &rhs) const = default
- bool operator==(const PointerData &rhs) const = default
- bool operator==(const Rgb &rhs) const = default
- bool operator==(const TouchpadData &rhs) const = default
- bool operator==(const TouchpadData &rhs) const = default
- bool operator==(const Vector2d &other) const
- bool operator==(const espp::Bm8563::Date &lhs, const espp::Bm8563::Date &rhs)
- bool operator==(const espp::Bm8563::DateTime &lhs, const espp::Bm8563::DateTime &rhs)
- bool operator==(const espp::Bm8563::Time &lhs, const espp::Bm8563::Time &rhs)
- bool operator==(const espp::QwiicNes::ButtonState &lhs, const espp::QwiicNes::ButtonState &rhs)
- bool operator==(const espp::St25dv::IT_STS &lhs, const espp::St25dv::IT_STS &rhs)
Warning
doxygenfunction: Unable to resolve function “operator==” with arguments None in doxygen xml output for project “esp-docs” from directory: /home/runner/work/espp/espp/doc/_build/en/esp32/xml_in/. Potential matches:
- bool operator==(const AdcConfig &lhs, const AdcConfig &rhs)
- bool operator==(const Config &rhs) const = default
- bool operator==(const DetentConfig &lhs, const DetentConfig &rhs)
- bool operator==(const Hsv &rhs) const = default
- bool operator==(const PinConfig &rhs) const = default
- bool operator==(const PointerData &rhs) const = default
- bool operator==(const Rgb &rhs) const = default
- bool operator==(const TouchpadData &rhs) const = default
- bool operator==(const TouchpadData &rhs) const = default
- bool operator==(const Vector2d &other) const
- bool operator==(const espp::Bm8563::Date &lhs, const espp::Bm8563::Date &rhs)
- bool operator==(const espp::Bm8563::DateTime &lhs, const espp::Bm8563::DateTime &rhs)
- bool operator==(const espp::Bm8563::Time &lhs, const espp::Bm8563::Time &rhs)
- bool operator==(const espp::QwiicNes::ButtonState &lhs, const espp::QwiicNes::ButtonState &rhs)
- bool operator==(const espp::St25dv::IT_STS &lhs, const espp::St25dv::IT_STS &rhs)
Warning
doxygenfunction: Unable to resolve function “operator==” with arguments None in doxygen xml output for project “esp-docs” from directory: /home/runner/work/espp/espp/doc/_build/en/esp32/xml_in/. Potential matches:
- bool operator==(const AdcConfig &lhs, const AdcConfig &rhs)
- bool operator==(const Config &rhs) const = default
- bool operator==(const DetentConfig &lhs, const DetentConfig &rhs)
- bool operator==(const Hsv &rhs) const = default
- bool operator==(const PinConfig &rhs) const = default
- bool operator==(const PointerData &rhs) const = default
- bool operator==(const Rgb &rhs) const = default
- bool operator==(const TouchpadData &rhs) const = default
- bool operator==(const TouchpadData &rhs) const = default
- bool operator==(const Vector2d &other) const
- bool operator==(const espp::Bm8563::Date &lhs, const espp::Bm8563::Date &rhs)
- bool operator==(const espp::Bm8563::DateTime &lhs, const espp::Bm8563::DateTime &rhs)
- bool operator==(const espp::Bm8563::Time &lhs, const espp::Bm8563::Time &rhs)
- bool operator==(const espp::QwiicNes::ButtonState &lhs, const espp::QwiicNes::ButtonState &rhs)
- bool operator==(const espp::St25dv::IT_STS &lhs, const espp::St25dv::IT_STS &rhs)
Classes
-
class Bm8563 : public espp::BasePeripheral<>
The BM8563 RTC driver.
This driver is for the BM8563 RTC chip.
Example
// make the I2C that we'll use to communicate espp::I2c i2c({ .port = I2C_NUM_0, .sda_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SDA_GPIO, .scl_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SCL_GPIO, .sda_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE, }); // now make the bm8563 auto bm8563 = espp::Bm8563({ .write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), .write_then_read = std::bind(&espp::I2c::write_read, &i2c, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5), }); std::error_code ec; // set the time espp::Bm8563::DateTime date_time = {.date = { .year = 2023, .month = 11, .weekday = 4, .day = 23, }, .time = {.hour = 8, .minute = 15, .second = 30}}; bm8563.set_date_time(date_time, ec); if (ec) { fmt::print("Error setting date time: {}\n", ec.message()); } else { fmt::print("Date time set to {}\n", date_time); } // and finally, make the task to periodically poll the bm8563 and print // the state auto task_fn = [&bm8563](std::mutex &m, std::condition_variable &cv) { std::error_code ec; // Get the date time and print it auto date_time = bm8563.get_date_time(ec); if (ec) { fmt::print("Error getting date time: {}\n", ec.message()); } else { fmt::print("Date time is {}\n", date_time); } // NOTE: sleeping in this way allows the sleep to exit early when the // task is being stopped / destroyed { std::unique_lock<std::mutex> lk(m); cv.wait_for(lk, 1s); } return false; // don't stop the task }; auto task = espp::Task({.callback = task_fn, .task_config = {.name = "BM8563 Task"}, .log_level = espp::Logger::Verbosity::WARN}); task.start();
Public Types
-
typedef std::function<bool(uint8_t)> probe_fn
Function to probe the peripheral
- Param address
The address to probe
- Return
True if the peripheral is found at the given address
Public Functions
-
inline DateTime get_date_time(std::error_code &ec)
Get the date and time.
- Parameters
ec – The error code.
- Returns
The date and time.
-
inline void set_date_time(const DateTime &dt, std::error_code &ec)
Set the date and time.
- Parameters
dt – The date and time.
ec – The error code.
-
inline Date get_date(std::error_code &ec)
Get the date.
- Parameters
ec – The error code.
- Returns
The date.
-
inline void set_date(const Date &d, std::error_code &ec)
Set the date.
- Parameters
d – The date.
ec – The error code.
-
inline Time get_time(std::error_code &ec)
Get the time.
- Parameters
ec – The error code.
- Returns
The time.
-
inline void set_time(const Time &t, std::error_code &ec)
Set the time.
- Parameters
t – The time.
ec – The error code.
- inline bool probe (std::error_code &ec) requires(UseAddress)
Probe the peripheral
Note
This function is thread safe
Note
If the probe function is not set, this function will return false and set the error code to operation_not_supported
Note
This function is only available if UseAddress is true
- Parameters
ec – The error code to set if there is an error
- Returns
True if the peripheral is found
- inline void set_address (uint8_t address) requires(UseAddress)
Set the address of the peripheral
Note
This function is thread safe
Note
This function is only available if UseAddress is true
- Parameters
address – The address of the peripheral
- inline void set_probe (const probe_fn &probe) requires(UseAddress)
Set the probe function
Note
This function is thread safe
Note
This should rarely be used, as the probe function is usually set in the constructor. If you need to change the probe function, consider using the set_config function instead.
Note
This function is only available if UseAddress is true
- Parameters
probe – The probe function
-
inline void set_write(const write_fn &write)
Set the write function
Note
This function is thread safe
Note
This should rarely be used, as the write function is usually set in the constructor. If you need to change the write function, consider using the set_config function instead.
- Parameters
write – The write function
-
inline void set_read(const read_fn &read)
Set the read function
Note
This function is thread safe
Note
This should rarely be used, as the read function is usually set in the constructor. If you need to change the read function, consider using the set_config function instead.
- Parameters
read – The read function
-
inline void set_read_register(const read_register_fn &read_register)
Set the read register function
Note
This function is thread safe
Note
This should rarely be used, as the read register function is usually set in the constructor. If you need to change the read register function, consider using the set_config function instead.
- Parameters
read_register – The read register function
-
inline void set_write_then_read(const write_then_read_fn &write_then_read)
Set the write then read function
Note
This function is thread safe
Note
This should rarely be used, as the write then read function is usually set in the constructor. If you need to change the write then
- Parameters
write_then_read – The write then read function
-
inline void set_separate_write_then_read_delay(const std::chrono::milliseconds &delay)
Set the delay between the write and read operations in write_then_read
Note
This function is thread safe
Note
This should rarely be used, as the delay is usually set in the constructor. If you need to change the delay, consider using the set_config function instead.
Note
This delay is only used if the write_then_read function is not set to a custom function and the write and read functions are separate functions.
- Parameters
delay – The delay between the write and read operations in write_then_read
-
inline void set_config(const Config &config)
Set the configuration for the peripheral
Note
This function is thread safe
Note
The configuration should normally be set in the constructor, but this function can be used to change the configuration after the peripheral has been created - for instance if the peripheral could be found on different communications buses.
- Parameters
config – The configuration for the peripheral
-
inline void set_config(Config &&config)
Set the configuration for the peripheral
Note
This function is thread safe
Note
The configuration should normally be set in the constructor, but this function can be used to change the configuration after the peripheral has been created - for instance if the peripheral could be found on different communications buses.
- Parameters
config – The configuration for the peripheral
-
inline const std::string &get_name() const
Get the name of the component
Note
This is the tag of the logger
- Returns
A const reference to the name of the component
-
inline void set_log_tag(const std::string_view &tag)
Set the tag for the logger
- Parameters
tag – The tag to use for the logger
-
inline espp::Logger::Verbosity get_log_level() const
Get the log level for the logger
See also
See also
- Returns
The verbosity level of the logger
-
inline void set_log_level(espp::Logger::Verbosity level)
Set the log level for the logger
See also
See also
- Parameters
level – The verbosity level to use for the logger
-
inline void set_log_verbosity(espp::Logger::Verbosity level)
Set the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls set_log_level
- Parameters
level – The verbosity level to use for the logger
-
inline espp::Logger::Verbosity get_log_verbosity() const
Get the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls get_log_level
- Returns
The verbosity level of the logger
-
inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)
Set the rate limit for the logger
See also
Note
Only calls to the logger that have _rate_limit suffix will be rate limited
- Parameters
rate_limit – The rate limit to use for the logger
Public Static Functions
-
static inline uint8_t bcd2byte(uint8_t value)
Convert a BCD value to a byte.
- Parameters
value – The BCD value.
- Returns
The byte value.
-
static inline uint8_t byte2bcd(uint8_t value)
Convert a byte value to BCD.
- Parameters
value – The byte value.
- Returns
The BCD value.
Public Static Attributes
-
static constexpr uint8_t DEFAULT_ADDRESS = (0x51)
The default I2C address for the BM8563.
-
struct Config
The configuration structure.
Public Members
-
BasePeripheral::write_fn write
The I2C write function.
-
BasePeripheral::write_then_read_fn write_then_read
The I2C write then read function.
-
BasePeripheral::write_fn write
-
struct Date
The date structure.
-
struct DateTime
The date and time structure.
-
struct Time
The time structure.
-
typedef std::function<bool(uint8_t)> probe_fn