From b0bacd9b0b0cbe8a633ab00f8174c509a2b1d243 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 13:15:24 -0400 Subject: [PATCH 01/11] review code --- ports/atmel-samd/board_busses.c | 48 +++++++++++++++++++ ports/atmel-samd/board_busses.h | 33 +++++++++++++ .../boards/circuitplayground_express/pins.c | 1 + .../boards/gemma_m0/mpconfigboard.h | 3 ++ ports/atmel-samd/boards/gemma_m0/pins.c | 11 +++++ 5 files changed, 96 insertions(+) create mode 100644 ports/atmel-samd/board_busses.c create mode 100644 ports/atmel-samd/board_busses.h diff --git a/ports/atmel-samd/board_busses.c b/ports/atmel-samd/board_busses.c new file mode 100644 index 0000000000..5aa33b924f --- /dev/null +++ b/ports/atmel-samd/board_busses.c @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/busio/I2C.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "mpconfigboard.h" + +STATIC mp_obj_t i2c_singleton = NULL; + +STATIC mp_obj_t board_i2c(void) { + #if !defined(DEFAULT_I2C_BUS_SCA) || !defined(DEFAULT_I2C_BUS_SCL) + mp_raise_NotImplementedError('no default bus'); + #endif + if (i2c_singleton == NULL) { + busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t); + self->base.type = &busio_i2c_type; + + assert_pin_free(DEFAULT_I2C_BUS_SCA); + assert_pin_free(DEFAULT_I2C_BUS_SCL); + common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCA, DEFAULT_I2C_BUS_SCL, 400000); + i2c_singleton = (mp_obj_t)self; + } + return i2c_singleton; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); diff --git a/ports/atmel-samd/board_busses.h b/ports/atmel-samd/board_busses.h new file mode 100644 index 0000000000..fdddd452bf --- /dev/null +++ b/ports/atmel-samd/board_busses.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H +#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H + +void board_i2c(void); +mp_obj_t board_i2c_obj; + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H diff --git a/ports/atmel-samd/boards/circuitplayground_express/pins.c b/ports/atmel-samd/boards/circuitplayground_express/pins.c index aecd7f416a..9541262665 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/pins.c +++ b/ports/atmel-samd/boards/circuitplayground_express/pins.c @@ -56,5 +56,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA05) }, { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA07) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h index 6457d481f3..14f6e0814c 100644 --- a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h @@ -12,6 +12,9 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 +#define DEFAULT_I2C_BUS_SCL (&pin_PA04) +#define DEFAULT_I2C_BUS_SCA (&pin_PA05) + #include "internal_flash.h" #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/ports/atmel-samd/boards/gemma_m0/pins.c b/ports/atmel-samd/boards/gemma_m0/pins.c index 5d3bedca0e..f17c8c7b23 100644 --- a/ports/atmel-samd/boards/gemma_m0/pins.c +++ b/ports/atmel-samd/boards/gemma_m0/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, // pad 1 @@ -19,5 +20,15 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); +// https://learn.adafruit.com/building-circuitpython/build-circuitpython +// make BOARD=gemma_m0 +// screen /dev/tty.usbmodem1411 +// enger +// control AK to kill screen +// import board +// board.I2C() +// two long clicks +// /ports/amtel-sand/build-gemma_m0/firmware.uf2 \ No newline at end of file From a10f04ad6ec516ff86a40159f9b09f22a21b653f Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 13:53:53 -0400 Subject: [PATCH 02/11] support for 2 --- ports/atmel-samd/Makefile | 1 + ports/atmel-samd/board_busses.c | 9 +++++---- ports/atmel-samd/board_busses.h | 2 +- .../boards/circuitplayground_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/circuitplayground_express/pins.c | 1 + ports/atmel-samd/boards/gemma_m0/mpconfigboard.h | 4 ++-- ports/atmel-samd/boards/gemma_m0/pins.c | 9 --------- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index e85a11b570..eb25c1aa30 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -227,6 +227,7 @@ SRC_ASF := $(addprefix asf4/$(CHIP_FAMILY)/, $(SRC_ASF)) SRC_C = \ audio_dma.c \ + board_busses.c \ background.c \ clocks.c \ $(CHIP_FAMILY)_clocks.c \ diff --git a/ports/atmel-samd/board_busses.c b/ports/atmel-samd/board_busses.c index 5aa33b924f..4f5b03d036 100644 --- a/ports/atmel-samd/board_busses.c +++ b/ports/atmel-samd/board_busses.c @@ -27,22 +27,23 @@ #include "shared-bindings/busio/I2C.h" #include "shared-bindings/microcontroller/Pin.h" #include "mpconfigboard.h" +#include "pins.h" STATIC mp_obj_t i2c_singleton = NULL; STATIC mp_obj_t board_i2c(void) { - #if !defined(DEFAULT_I2C_BUS_SCA) || !defined(DEFAULT_I2C_BUS_SCL) + #if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL) mp_raise_NotImplementedError('no default bus'); #endif if (i2c_singleton == NULL) { busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t); self->base.type = &busio_i2c_type; - assert_pin_free(DEFAULT_I2C_BUS_SCA); + assert_pin_free(DEFAULT_I2C_BUS_SDA); assert_pin_free(DEFAULT_I2C_BUS_SCL); - common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCA, DEFAULT_I2C_BUS_SCL, 400000); + common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000); i2c_singleton = (mp_obj_t)self; } return i2c_singleton; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); +MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); diff --git a/ports/atmel-samd/board_busses.h b/ports/atmel-samd/board_busses.h index fdddd452bf..e872e4902b 100644 --- a/ports/atmel-samd/board_busses.h +++ b/ports/atmel-samd/board_busses.h @@ -28,6 +28,6 @@ #define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H void board_i2c(void); -mp_obj_t board_i2c_obj; +extern mp_obj_fun_builtin_fixed_t board_i2c_obj; #endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h index 73d45f2cf8..c307d50689 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h @@ -58,3 +58,6 @@ // Explanation of how a user got into safe mode. #define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up" + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) \ No newline at end of file diff --git a/ports/atmel-samd/boards/circuitplayground_express/pins.c b/ports/atmel-samd/boards/circuitplayground_express/pins.c index 9541262665..c0545fd7c0 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/pins.c +++ b/ports/atmel-samd/boards/circuitplayground_express/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, diff --git a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h index 14f6e0814c..f98119e11d 100644 --- a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.h @@ -12,8 +12,8 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 -#define DEFAULT_I2C_BUS_SCL (&pin_PA04) -#define DEFAULT_I2C_BUS_SCA (&pin_PA05) +#define DEFAULT_I2C_BUS_SCL (&pin_PA05) +#define DEFAULT_I2C_BUS_SDA (&pin_PA04) #include "internal_flash.h" diff --git a/ports/atmel-samd/boards/gemma_m0/pins.c b/ports/atmel-samd/boards/gemma_m0/pins.c index f17c8c7b23..6d9d2ad759 100644 --- a/ports/atmel-samd/boards/gemma_m0/pins.c +++ b/ports/atmel-samd/boards/gemma_m0/pins.c @@ -23,12 +23,3 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); -// https://learn.adafruit.com/building-circuitpython/build-circuitpython -// make BOARD=gemma_m0 -// screen /dev/tty.usbmodem1411 -// enger -// control AK to kill screen -// import board -// board.I2C() -// two long clicks -// /ports/amtel-sand/build-gemma_m0/firmware.uf2 \ No newline at end of file From bd7f603748cac9946e384c676921b40baa36a10d Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 14:06:01 -0400 Subject: [PATCH 03/11] zero + feather logger --- ports/atmel-samd/boards/arduino_zero/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/arduino_zero/pins.c | 4 ++++ .../boards/circuitplayground_express/mpconfigboard.h | 2 +- ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/feather_m0_adalogger/pins.c | 4 ++++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h index 6eeddb36c7..12f7dbe40b 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h @@ -14,3 +14,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file diff --git a/ports/atmel-samd/boards/arduino_zero/pins.c b/ports/atmel-samd/boards/arduino_zero/pins.c index 8b28c0fc22..dc873d9e67 100644 --- a/ports/atmel-samd/boards/arduino_zero/pins.c +++ b/ports/atmel-samd/boards/arduino_zero/pins.c @@ -1,6 +1,8 @@ #include "shared-bindings/board/__init__.h" #include "samd21_pins.h" +#include "board_busses.h" + STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -30,5 +32,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h index c307d50689..6ea0d93602 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h @@ -60,4 +60,4 @@ #define BOARD_USER_SAFE_MODE_ACTION "pressing both buttons at start up" #define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h index 8802d39d99..6e23ebc61b 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h @@ -12,3 +12,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) \ No newline at end of file diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/pins.c b/ports/atmel-samd/boards/feather_m0_adalogger/pins.c index a229b6bab1..fdcb691fcf 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/pins.c +++ b/ports/atmel-samd/boards/feather_m0_adalogger/pins.c @@ -1,4 +1,6 @@ #include "samd21_pins.h" +#include "board_busses.h" + STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -30,5 +32,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From cd1f6627e411d71eec8d94f32c7530d415a0cab7 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 14:09:00 -0400 Subject: [PATCH 04/11] formatting --- ports/atmel-samd/boards/arduino_zero/mpconfigboard.h | 2 +- ports/atmel-samd/boards/arduino_zero/pins.c | 1 - ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h index 12f7dbe40b..11e01b6c60 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h @@ -16,4 +16,4 @@ #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) #define DEFAULT_I2C_BUS_SCL (&pin_PA23) -#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/arduino_zero/pins.c b/ports/atmel-samd/boards/arduino_zero/pins.c index dc873d9e67..74cff5ae86 100644 --- a/ports/atmel-samd/boards/arduino_zero/pins.c +++ b/ports/atmel-samd/boards/arduino_zero/pins.c @@ -33,6 +33,5 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h index 6e23ebc61b..38df41b94c 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h @@ -14,4 +14,4 @@ #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) #define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) From cdeb7ddff8b3f82e3cf303c04682d041fe51db31 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 14:27:05 -0400 Subject: [PATCH 05/11] fix non- builds --- ports/atmel-samd/board_busses.c | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/ports/atmel-samd/board_busses.c b/ports/atmel-samd/board_busses.c index 4f5b03d036..5c539e3f5c 100644 --- a/ports/atmel-samd/board_busses.c +++ b/ports/atmel-samd/board_busses.c @@ -28,22 +28,35 @@ #include "shared-bindings/microcontroller/Pin.h" #include "mpconfigboard.h" #include "pins.h" +#include "py/runtime.h" -STATIC mp_obj_t i2c_singleton = NULL; -STATIC mp_obj_t board_i2c(void) { - #if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL) - mp_raise_NotImplementedError('no default bus'); - #endif - if (i2c_singleton == NULL) { - busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t); - self->base.type = &busio_i2c_type; - assert_pin_free(DEFAULT_I2C_BUS_SDA); - assert_pin_free(DEFAULT_I2C_BUS_SCL); - common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000); - i2c_singleton = (mp_obj_t)self; +#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL) + + STATIC mp_obj_t board_i2c(void) { + //board_i2c_obj = NULL; + mp_raise_NotImplementedError("no default bus"); + return NULL; } - return i2c_singleton; -} + +#else + STATIC mp_obj_t i2c_singleton = NULL; + + STATIC mp_obj_t board_i2c(void) { + + if (i2c_singleton == NULL) { + busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t); + self->base.type = &busio_i2c_type; + + assert_pin_free(DEFAULT_I2C_BUS_SDA); + assert_pin_free(DEFAULT_I2C_BUS_SCL); + common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000); + i2c_singleton = (mp_obj_t)self; + } + return i2c_singleton; + + } +#endif + MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); From 4e65752d6e88f5d81ef9180dfab90760ff32bd63 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 15:28:23 -0400 Subject: [PATCH 06/11] feather m0 boards --- ports/atmel-samd/boards/feather_m0_adalogger/pins.c | 2 -- ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/feather_m0_basic/pins.c | 2 ++ ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/feather_m0_express/pins.c | 2 ++ ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h | 5 +++++ ports/atmel-samd/boards/feather_m0_rfm69/pins.c | 2 ++ ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h | 6 ++++++ ports/atmel-samd/boards/feather_m0_rfm9x/pins.c | 2 ++ .../atmel-samd/boards/feather_m0_supersized/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/feather_m0_supersized/pins.c | 2 ++ 11 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/pins.c b/ports/atmel-samd/boards/feather_m0_adalogger/pins.c index fdcb691fcf..cf4160d723 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/pins.c +++ b/ports/atmel-samd/boards/feather_m0_adalogger/pins.c @@ -1,7 +1,6 @@ #include "samd21_pins.h" #include "board_busses.h" - STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) }, @@ -33,6 +32,5 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h index 04cbc4ff8a..d949244972 100644 --- a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h @@ -13,3 +13,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/feather_m0_basic/pins.c b/ports/atmel-samd/boards/feather_m0_basic/pins.c index c9119e77bc..2916df7a1c 100644 --- a/ports/atmel-samd/boards/feather_m0_basic/pins.c +++ b/ports/atmel-samd/boards/feather_m0_basic/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -23,5 +24,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h index c85f553ba9..c34869a572 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h @@ -48,3 +48,6 @@ #include "external_flash/external_flash.h" #define BOARD_HAS_CRYSTAL 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/feather_m0_express/pins.c b/ports/atmel-samd/boards/feather_m0_express/pins.c index c5c70ee5dc..740be2cbd6 100644 --- a/ports/atmel-samd/boards/feather_m0_express/pins.c +++ b/ports/atmel-samd/boards/feather_m0_express/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -24,5 +25,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h index 33445940e6..ff5512d814 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h @@ -13,3 +13,8 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + +// https://learn.adafruit.com/assets/46254 +// https://learn.adafruit.com/assets/46255 +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/pins.c b/ports/atmel-samd/boards/feather_m0_rfm69/pins.c index eb5f531e36..6a35c33d49 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/pins.c +++ b/ports/atmel-samd/boards/feather_m0_rfm69/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -26,5 +27,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_RFM69_D0), MP_ROM_PTR(&pin_PA09) }, { MP_ROM_QSTR(MP_QSTR_RFM69_RST), MP_ROM_PTR(&pin_PA08) }, { MP_ROM_QSTR(MP_QSTR_RFM69_CS), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h index a2563cc9f1..cac39ee846 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.h @@ -13,3 +13,9 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + +// https://learn.adafruit.com/assets/46254 +// https://learn.adafruit.com/assets/46255 +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + diff --git a/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c b/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c index 2e5d0a8e68..bf4b3b347d 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c +++ b/ports/atmel-samd/boards/feather_m0_rfm9x/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -26,5 +27,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_RFM9X_D0), MP_ROM_PTR(&pin_PA09) }, { MP_ROM_QSTR(MP_QSTR_RFM9X_RST), MP_ROM_PTR(&pin_PA08) }, { MP_ROM_QSTR(MP_QSTR_RFM9X_CS), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h index 5bc74d5a74..7525c01624 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h @@ -47,3 +47,6 @@ #define EXTERNAL_FLASH_DEVICES S25FL064L #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/feather_m0_supersized/pins.c b/ports/atmel-samd/boards/feather_m0_supersized/pins.c index c5c70ee5dc..740be2cbd6 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/pins.c +++ b/ports/atmel-samd/boards/feather_m0_supersized/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -24,5 +25,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From ff6e6b51557ff1d6d69e279f39ffba6dd113e300 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 15:33:27 -0400 Subject: [PATCH 07/11] best effort --- ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/metro_m0_express/pins.c | 2 ++ ports/atmel-samd/boards/trinket_m0/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/trinket_m0/pins.c | 2 ++ ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/trinket_m0_haxpress/pins.c | 2 ++ ports/atmel-samd/boards/ugame10/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/ugame10/pins.c | 2 ++ 8 files changed, 20 insertions(+) diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h index e635acd593..9b8b0ab88c 100644 --- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h @@ -49,3 +49,6 @@ #include "external_flash/external_flash.h" #define BOARD_HAS_CRYSTAL 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/metro_m0_express/pins.c b/ports/atmel-samd/boards/metro_m0_express/pins.c index 58510faabb..32f3f875c4 100644 --- a/ports/atmel-samd/boards/metro_m0_express/pins.c +++ b/ports/atmel-samd/boards/metro_m0_express/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -29,5 +30,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h index 05033ad38b..a0c4db3d6c 100644 --- a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h @@ -14,3 +14,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA09) +#define DEFAULT_I2C_BUS_SDA (&pin_PA08) diff --git a/ports/atmel-samd/boards/trinket_m0/pins.c b/ports/atmel-samd/boards/trinket_m0/pins.c index ac58986009..74d03def29 100644 --- a/ports/atmel-samd/boards/trinket_m0/pins.c +++ b/ports/atmel-samd/boards/trinket_m0/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA08) }, @@ -27,5 +28,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h index ea45c1f8b8..3b1eab4b20 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h @@ -54,3 +54,6 @@ #define EXTERNAL_FLASH_DEVICES W25Q32BV #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c b/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c index ac58986009..74d03def29 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA08) }, @@ -27,5 +28,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.h b/ports/atmel-samd/boards/ugame10/mpconfigboard.h index 1652314ed8..57caefb882 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.h +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.h @@ -47,3 +47,6 @@ #define EXTERNAL_FLASH_DEVICES S25FL216K #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file diff --git a/ports/atmel-samd/boards/ugame10/pins.c b/ports/atmel-samd/boards/ugame10/pins.c index af516a401d..2af55f6da7 100644 --- a/ports/atmel-samd/boards/ugame10/pins.c +++ b/ports/atmel-samd/boards/ugame10/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) }, @@ -23,5 +24,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) }, { MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From fbb57f902d83a8be83b25155adb9d4190eff050e Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 15 May 2018 15:37:48 -0400 Subject: [PATCH 08/11] better error message --- ports/atmel-samd/board_busses.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/board_busses.c b/ports/atmel-samd/board_busses.c index 5c539e3f5c..fa38972064 100644 --- a/ports/atmel-samd/board_busses.c +++ b/ports/atmel-samd/board_busses.c @@ -36,7 +36,7 @@ STATIC mp_obj_t board_i2c(void) { //board_i2c_obj = NULL; - mp_raise_NotImplementedError("no default bus"); + mp_raise_NotImplementedError("No default I2C bus"); return NULL; } From 2c067edf540fcc1f1f4aa68f0992ce8480a954bb Mon Sep 17 00:00:00 2001 From: Matt Land Date: Wed, 16 May 2018 15:54:01 -0400 Subject: [PATCH 09/11] used pins.c instead of README.rst --- ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h | 4 ++-- ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h | 4 ++-- ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h | 4 ++-- ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h | 4 ++-- ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/feather_m4_express/pins.c | 2 ++ ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/itsybitsy_m0_express/pins.c | 2 ++ ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/itsybitsy_m4_express/pins.c | 2 ++ ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/metro_m4_express/pins.c | 2 ++ ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h | 3 +++ ports/atmel-samd/boards/metro_m4_express_revb/pins.c | 2 ++ ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h | 4 ++-- ports/atmel-samd/boards/ugame10/mpconfigboard.h | 3 --- ports/atmel-samd/boards/ugame10/pins.c | 2 -- 17 files changed, 35 insertions(+), 15 deletions(-) diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h index 38df41b94c..dc9aabf17c 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h @@ -13,5 +13,5 @@ #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) -#define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) +#define DEFAULT_I2C_BUS_SCL (&pin_PA22) +#define DEFAULT_I2C_BUS_SDA (&pin_PA23) diff --git a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h index d949244972..dff82912ec 100644 --- a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h @@ -14,5 +14,5 @@ #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) -#define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h index c34869a572..4435412dfa 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h @@ -49,5 +49,5 @@ #define BOARD_HAS_CRYSTAL 1 -#define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h index 7525c01624..037d9b9922 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h @@ -48,5 +48,5 @@ #include "external_flash/external_flash.h" -#define DEFAULT_I2C_BUS_SCL (&pin_PB03) -#define DEFAULT_I2C_BUS_SDA (&pin_PB02) +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h index 6e10222562..930dc9ee28 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h @@ -31,3 +31,6 @@ #define EXTERNAL_FLASH_QSPI_DUAL #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PA13) +#define DEFAULT_I2C_BUS_SDA (&pin_PA12) \ No newline at end of file diff --git a/ports/atmel-samd/boards/feather_m4_express/pins.c b/ports/atmel-samd/boards/feather_m4_express/pins.c index c161e736ed..2fa5fa1b56 100644 --- a/ports/atmel-samd/boards/feather_m4_express/pins.c +++ b/ports/atmel-samd/boards/feather_m4_express/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, @@ -26,5 +27,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA22) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA23) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PB23) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h index a7ecd27ea8..4058a9bcd2 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h @@ -46,3 +46,6 @@ GD25Q16C #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c b/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c index b70bb6a76c..8eec4ca224 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, @@ -38,5 +39,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA01) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA00) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h index 95c542a43e..0ff0ee2c34 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h @@ -31,3 +31,6 @@ #define EXTERNAL_FLASH_DEVICES GD25Q16C #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PA13) +#define DEFAULT_I2C_BUS_SDA (&pin_PA12) \ No newline at end of file diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c b/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c index 11aeda9c67..490922a46a 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/pins.c @@ -1,4 +1,5 @@ #include "samd51_pins.h" +#include "board_busses.h" // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from @@ -35,5 +36,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PB03) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h index 7012037717..0d93ed700e 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h @@ -32,3 +32,6 @@ #define EXTERNAL_FLASH_DEVICES S25FL116K, S25FL216K, GD25Q16C #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/metro_m4_express/pins.c b/ports/atmel-samd/boards/metro_m4_express/pins.c index 32ecdf4923..1d24a0f2f2 100644 --- a/ports/atmel-samd/boards/metro_m4_express/pins.c +++ b/ports/atmel-samd/boards/metro_m4_express/pins.c @@ -1,4 +1,5 @@ #include "samd51_pins.h" +#include "board_busses.h" // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from @@ -41,5 +42,6 @@ STATIC const mp_map_elem_t board_global_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), (mp_obj_t)&pin_PB06 }, { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), (mp_obj_t)&pin_PA27 }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h index 206d85465e..8f3c0cd0e0 100644 --- a/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express_revb/mpconfigboard.h @@ -60,3 +60,6 @@ GD25Q16C #include "external_flash/external_flash.h" + +#define DEFAULT_I2C_BUS_SCL (&pin_PB03) +#define DEFAULT_I2C_BUS_SDA (&pin_PB02) diff --git a/ports/atmel-samd/boards/metro_m4_express_revb/pins.c b/ports/atmel-samd/boards/metro_m4_express_revb/pins.c index a18906f73d..5e6e719ace 100644 --- a/ports/atmel-samd/boards/metro_m4_express_revb/pins.c +++ b/ports/atmel-samd/boards/metro_m4_express_revb/pins.c @@ -1,4 +1,5 @@ #include "samd51_pins.h" +#include "board_busses.h" // This mapping only includes functional names because pins broken // out on connectors are labeled with their MCU name available from @@ -40,5 +41,6 @@ STATIC const mp_map_elem_t board_global_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_LED_RX), (mp_obj_t)&pin_PB06 }, { MP_OBJ_NEW_QSTR(MP_QSTR_LED_TX), (mp_obj_t)&pin_PA27 }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h index 3b1eab4b20..9142a7d7a7 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h @@ -55,5 +55,5 @@ #include "external_flash/external_flash.h" -#define DEFAULT_I2C_BUS_SCL (&pin_PA23) -#define DEFAULT_I2C_BUS_SDA (&pin_PA22) +#define DEFAULT_I2C_BUS_SCL (&pin_PA09) +#define DEFAULT_I2C_BUS_SDA (&pin_PA08) diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.h b/ports/atmel-samd/boards/ugame10/mpconfigboard.h index 57caefb882..1652314ed8 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.h +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.h @@ -47,6 +47,3 @@ #define EXTERNAL_FLASH_DEVICES S25FL216K #include "external_flash/external_flash.h" - -#define DEFAULT_I2C_BUS_SCL (&pin_PA23) -#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file diff --git a/ports/atmel-samd/boards/ugame10/pins.c b/ports/atmel-samd/boards/ugame10/pins.c index 2af55f6da7..af516a401d 100644 --- a/ports/atmel-samd/boards/ugame10/pins.c +++ b/ports/atmel-samd/boards/ugame10/pins.c @@ -1,5 +1,4 @@ #include "samd21_pins.h" -#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) }, @@ -24,6 +23,5 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) }, { MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 8a351595ef6df62c2c223e2bfe7b35f29db3bf84 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Wed, 16 May 2018 15:57:25 -0400 Subject: [PATCH 10/11] formatting, trailing newlines --- ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h | 2 +- ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h | 2 +- ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h | 2 +- ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h index ff5512d814..1a3fa72f21 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.h @@ -17,4 +17,4 @@ // https://learn.adafruit.com/assets/46254 // https://learn.adafruit.com/assets/46255 #define DEFAULT_I2C_BUS_SCL (&pin_PA23) -#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h index 930dc9ee28..48c63454e5 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h @@ -33,4 +33,4 @@ #include "external_flash/external_flash.h" #define DEFAULT_I2C_BUS_SCL (&pin_PA13) -#define DEFAULT_I2C_BUS_SDA (&pin_PA12) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PA12) diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h index 4058a9bcd2..7b0280acb3 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.h @@ -48,4 +48,4 @@ #include "external_flash/external_flash.h" #define DEFAULT_I2C_BUS_SCL (&pin_PA23) -#define DEFAULT_I2C_BUS_SDA (&pin_PA22) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) diff --git a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h index 0ff0ee2c34..e8335ef3f8 100644 --- a/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/itsybitsy_m4_express/mpconfigboard.h @@ -33,4 +33,4 @@ #include "external_flash/external_flash.h" #define DEFAULT_I2C_BUS_SCL (&pin_PA13) -#define DEFAULT_I2C_BUS_SDA (&pin_PA12) \ No newline at end of file +#define DEFAULT_I2C_BUS_SDA (&pin_PA12) From e8e75c056a884ce87d1a1e2eeea1ee266ba0fcd5 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Wed, 16 May 2018 17:02:41 -0400 Subject: [PATCH 11/11] For the two boards without SCL and SDA can you still add the board global entry for I2C? That way they'll raise the NotImplementedError with the better message instead of a NameError. --- ports/atmel-samd/board_busses.c | 2 +- ports/atmel-samd/boards/pirkey_m0/pins.c | 2 ++ ports/atmel-samd/boards/ugame10/pins.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/board_busses.c b/ports/atmel-samd/board_busses.c index fa38972064..0dc95a32c7 100644 --- a/ports/atmel-samd/board_busses.c +++ b/ports/atmel-samd/board_busses.c @@ -51,7 +51,7 @@ assert_pin_free(DEFAULT_I2C_BUS_SDA); assert_pin_free(DEFAULT_I2C_BUS_SCL); - common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000); + common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0); i2c_singleton = (mp_obj_t)self; } return i2c_singleton; diff --git a/ports/atmel-samd/boards/pirkey_m0/pins.c b/ports/atmel-samd/boards/pirkey_m0/pins.c index a1b7db85c8..dac6687955 100644 --- a/ports/atmel-samd/boards/pirkey_m0/pins.c +++ b/ports/atmel-samd/boards/pirkey_m0/pins.c @@ -1,9 +1,11 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_REMOTEIN), MP_ROM_PTR(&pin_PA28) }, { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/ugame10/pins.c b/ports/atmel-samd/boards/ugame10/pins.c index af516a401d..2af55f6da7 100644 --- a/ports/atmel-samd/boards/ugame10/pins.c +++ b/ports/atmel-samd/boards/ugame10/pins.c @@ -1,4 +1,5 @@ #include "samd21_pins.h" +#include "board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA00) }, @@ -23,5 +24,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_B), MP_ROM_PTR(&pin_PA14) }, { MP_ROM_QSTR(MP_QSTR_C), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_D), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);