[riot-notifications] [RIOT-OS/RIOT] cpu/sam0: re-work i2c driver (#7588)

lebrush notifications at github.com
Fri Sep 22 14:20:43 CEST 2017


lebrush commented on this pull request.



>  
     /* Enable Smart Mode (ACK is sent when DATA.DATA is read) */
-    I2CSercom->CTRLB.reg = SERCOM_I2CM_CTRLB_SMEN;
+    dev(bus)->CTRLB.reg = SERCOM_I2CM_CTRLB_SMEN;
 
     /* Find and set baudrate. Read speed configuration. Set transfer
      * speed: SERCOM_I2CM_CTRLA_SPEED(0): Standard-mode (Sm) up to 100
      * kHz and Fast-mode (Fm) up to 400 kHz */
     switch (speed) {

I meant the following: you can redefine the `i2c_speed_t` in `periph_cpu_common.h` as 

```C
typedef enum {
I2C_SPEED_NORMAL = 100000,
I2C_SPEED_FAST = 400000,
...
} i2c_speed_t;
```

Then you can skip the `switch`:

```C
tmp_baud = (int32_t)(((CLOCK_CORECLOCK + (2 * (speed)) - 1) / (2 * (speed))) - 5);
if (tmp_baud < 255 && tmp_baud > 0) {
	dev(bus)->CTRLA.reg |= SERCOM_I2CM_CTRLA_SPEED(0);
	dev(bus)->BAUD.reg = SERCOM_I2CM_BAUD_BAUD(tmp_baud);
}
```

But now I relised that the `high` speed has different values (2 instead of 0 and HSBAD instead of BAUD), so I'm not sure it makes sense.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/7588#discussion_r140479452
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20170922/654f4762/attachment-0001.html>


More information about the notifications mailing list