From 70ff7350e7ff369ab81d1f55e6645a5828928385 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Mon, 2 May 2016 11:15:36 +0100
Subject: [PATCH] stmhal, cc3200: Change i2c.scan() method to scan addresses
 0x08-0x77.

A standard I2C address is 7 bits but addresses 0b0000xxx and 0b1111xxx
are reserved.  The scan() method is changed to reflect this, along with
the docs.
---
 cc3200/mods/pybi2c.c         | 2 +-
 docs/library/machine.I2C.rst | 2 +-
 stmhal/i2c.c                 | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c
index 70153801e..5022e614f 100644
--- a/cc3200/mods/pybi2c.c
+++ b/cc3200/mods/pybi2c.c
@@ -377,7 +377,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);
 STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
     pyb_i2c_check_init(&pyb_i2c_obj);
     mp_obj_t list = mp_obj_new_list(0, NULL);
-    for (uint addr = 1; addr <= 127; addr++) {
+    for (uint addr = 0x08; addr <= 0x77; addr++) {
         for (int i = 0; i < 3; i++) {
             if (pyb_i2c_scan_device(addr)) {
                 mp_obj_list_append(list, mp_obj_new_int(addr));
diff --git a/docs/library/machine.I2C.rst b/docs/library/machine.I2C.rst
index aa1caed20..d04ef5eef 100644
--- a/docs/library/machine.I2C.rst
+++ b/docs/library/machine.I2C.rst
@@ -106,7 +106,7 @@ Methods
 
 .. method:: i2c.scan()
 
-   Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
+   Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of those that respond.
    Only valid when in master mode.
 
 Constants
diff --git a/stmhal/i2c.c b/stmhal/i2c.c
index e52db0170..9f6506b01 100644
--- a/stmhal/i2c.c
+++ b/stmhal/i2c.c
@@ -475,7 +475,7 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
 STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready);
 
 /// \method scan()
-/// Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
+/// Scan all I2C addresses from 0x08 to 0x77 and return a list of those that respond.
 /// Only valid when in master mode.
 STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
     pyb_i2c_obj_t *self = self_in;
@@ -486,7 +486,7 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
 
     mp_obj_t list = mp_obj_new_list(0, NULL);
 
-    for (uint addr = 1; addr <= 127; addr++) {
+    for (uint addr = 0x08; addr <= 0x77; addr++) {
         for (int i = 0; i < 10; i++) {
             HAL_StatusTypeDef status = HAL_I2C_IsDeviceReady(self->i2c, addr << 1, 10, 200);
             if (status == HAL_OK) {
-- 
GitLab