summaryrefslogtreecommitdiff
path: root/ucoo/hal/i2c/i2c_hard.stm32.hh
diff options
context:
space:
mode:
authorNicolas Schodet2016-07-25 15:18:40 +0200
committerNicolas Schodet2019-10-09 23:05:44 +0200
commit4695b47da68a5b2f75270bea21e15b8f1b9fd6ff (patch)
tree6e5ef4d34ee69bcd6c6627f25a0ca3aa902d47e3 /ucoo/hal/i2c/i2c_hard.stm32.hh
parentd7df91926bdb529e68eff9a215aef72072803b6e (diff)
Switch to CMSIS
Diffstat (limited to 'ucoo/hal/i2c/i2c_hard.stm32.hh')
-rw-r--r--ucoo/hal/i2c/i2c_hard.stm32.hh26
1 files changed, 19 insertions, 7 deletions
diff --git a/ucoo/hal/i2c/i2c_hard.stm32.hh b/ucoo/hal/i2c/i2c_hard.stm32.hh
index 98e4930..81c5deb 100644
--- a/ucoo/hal/i2c/i2c_hard.stm32.hh
+++ b/ucoo/hal/i2c/i2c_hard.stm32.hh
@@ -27,14 +27,26 @@
#include "config/ucoo/hal/i2c.hh"
+#include "ucoo/arch/reg.hh"
+
namespace ucoo {
/// I2C interface, using dedicated hardware.
class I2cHard : public I2c
{
public:
+ /// Available instances.
+ enum class Instance
+ {
+ I2C1,
+ I2C2,
+#ifdef I2C3_BASE
+ I2C3,
+#endif
+ };
+ public:
/// Constructor for the Nth I2C.
- I2cHard (int n);
+ I2cHard (Instance inst);
/// Shutdown.
~I2cHard ();
/// Enable and setup
@@ -62,11 +74,11 @@ class I2cHard : public I2c
/// I2C number.
int n_;
/// Is it enabled?
- bool enabled_;
+ bool enabled_ = false;
/// Slave address.
- uint8_t slave_addr_;
+ uint8_t slave_addr_ = 0;
/// Handler called to source or sink data for slave exchanges.
- DataHandler *slave_data_handler_;
+ DataHandler *slave_data_handler_ = nullptr;
/// Slave buffer.
char slave_buf_[CONFIG_UCOO_HAL_I2C_SLAVE_BUFFER_SIZE];
/// Current buffer count (bytes to send), or buffer size (available room).
@@ -75,11 +87,11 @@ class I2cHard : public I2c
/// byte).
int buf_index_;
/// Master access granted.
- bool master_;
+ bool master_ = false;
/// Current master transfer status.
- int master_status_;
+ int master_status_ = STATUS_ERROR;
/// Current master transfer buffer.
- char *master_buf_;
+ char *master_buf_ = nullptr;
/// Current master transfer size, copied to buf_count_ when active.
int master_count_;
/// Current master transfer slave address, LSB is set for receiver mode.