10000 Feature: shortcut I2C support for atmel-samd boards by matt-land · Pull Request #841 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Feature: shortcut I2C support for atmel-samd boards #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 17, 2018
Merged
Prev Previous commit
Next Next commit
support for 2
  • Loading branch information
Matt Land committed May 15, 2018
commit a10f04ad6ec516ff86a40159f9b09f22a21b653f
1 change: 1 addition & 0 deletions ports/atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 5 additions & 4 deletions ports/atmel-samd/board_busses.c
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be "No default I2C bus" so that it's clear what the error relates to.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. thanks

#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);
2 changes: 1 addition & 1 deletion ports/atmel-samd/board_busses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions ports/atmel-samd/boards/circuitplayground_express/pins.c
Original file line number Diff line number Diff line change
@@ -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) },
Expand Down
4 changes: 2 additions & 2 deletions ports/atmel-samd/boards/gemma_m0/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 0 additions & 9 deletions ports/atmel-samd/boards/gemma_m0/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
0