diff options
| author | Hierophect <hierophect@gmail.com> | 2019-11-12 09:49:17 -0500 |
|---|---|---|
| committer | Hierophect <hierophect@gmail.com> | 2019-11-12 09:49:17 -0500 |
| commit | ed3e377390862da98dcf39d164ebb1d64b950e1f (patch) | |
| tree | f99e2932b884abd1377d15921274a74f3323a86f | |
| parent | 14b70806a5aacd3a5346940e6a07d32464d73506 (diff) | |
| parent | 93cdf51b7f385f4ce9fe4c41a1a0cf3b7b642255 (diff) | |
Merge remote-tracking branch 'upstream/master' into stm32-uart
| -rw-r--r-- | ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk | 3 | ||||
| -rw-r--r-- | ports/stm32f4/boards/feather_stm32f405_express/board.c | 3 | ||||
| -rw-r--r-- | ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h | 13 | ||||
| -rw-r--r-- | ports/stm32f4/boards/feather_stm32f405_express/pins.c | 4 | ||||
| -rw-r--r-- | ports/stm32f4/boards/pyboard_v11/mpconfigboard.h | 8 | ||||
| -rw-r--r-- | ports/stm32f4/boards/pyboard_v11/pins.c | 2 | ||||
| -rw-r--r-- | ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h | 3 | ||||
| -rw-r--r-- | ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h | 5 | ||||
| -rw-r--r-- | ports/stm32f4/boards/stm32f412zg_discovery/pins.c | 2 | ||||
| -rw-r--r-- | ports/stm32f4/common-hal/analogio/AnalogOut.c | 19 | ||||
| -rw-r--r-- | ports/stm32f4/common-hal/analogio/AnalogOut.h | 2 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.h | 4 | ||||
| -rw-r--r-- | py/circuitpy_mpconfig.mk | 7 | ||||
| -rw-r--r-- | py/compile.c | 2 | ||||
| -rw-r--r-- | py/emitnative.c | 18 | ||||
| -rw-r--r-- | py/objfun.c | 2 | ||||
| -rw-r--r-- | shared-module/displayio/I2CDisplay.c | 21 |
17 files changed, 87 insertions, 31 deletions
diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk index 19917898b..aa94af6a4 100644 --- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk @@ -25,3 +25,6 @@ CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_NETWORK = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_PS2IO = 0 + +# Enable micropython.native +CIRCUITPY_ENABLE_MPY_NATIVE = 1 diff --git a/ports/stm32f4/boards/feather_stm32f405_express/board.c b/ports/stm32f4/boards/feather_stm32f405_express/board.c index 4421970ee..82b0c506e 100644 --- a/ports/stm32f4/boards/feather_stm32f405_express/board.c +++ b/ports/stm32f4/boards/feather_stm32f405_express/board.c @@ -25,12 +25,13 @@ */ #include "boards/board.h" +#include "mpconfigboard.h" void board_init(void) { } bool board_requests_safe_mode(void) { - return false; + return false; } void reset_board(void) { diff --git a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h index d795342dd..67ddc885a 100644 --- a/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h +++ b/ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke - * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2019 Lucian Copeland 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 @@ -41,3 +40,13 @@ #define SPI_FLASH_MISO_PIN &pin_PB04 #define SPI_FLASH_SCK_PIN &pin_PB03 #define SPI_FLASH_CS_PIN &pin_PA15 + +#define DEFAULT_I2C_BUS_SCL (&pin_PB06) +#define DEFAULT_I2C_BUS_SDA (&pin_PB07) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB13) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB15) +#define DEFAULT_SPI_BUS_MISO (&pin_PB14) + +#define DEFAULT_UART_BUS_RX (&pin_PB11) +#define DEFAULT_UART_BUS_TX (&pin_PB10) diff --git a/ports/stm32f4/boards/feather_stm32f405_express/pins.c b/ports/stm32f4/boards/feather_stm32f405_express/pins.c index 518ab6d2a..4aa1f362a 100644 --- a/ports/stm32f4/boards/feather_stm32f405_express/pins.c +++ b/ports/stm32f4/boards/feather_stm32f405_express/pins.c @@ -25,5 +25,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB10) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB11) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/stm32f4/boards/pyboard_v11/mpconfigboard.h b/ports/stm32f4/boards/pyboard_v11/mpconfigboard.h index e8441d665..9d8f72f77 100644 --- a/ports/stm32f4/boards/pyboard_v11/mpconfigboard.h +++ b/ports/stm32f4/boards/pyboard_v11/mpconfigboard.h @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke - * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2019 Lucian Copeland 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 @@ -34,4 +33,7 @@ #define FLASH_PAGE_SIZE (0x4000) #define AUTORESET_DELAY_MS 500 -#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
\ No newline at end of file +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000) + +#define DEFAULT_I2C_BUS_SCL (&pin_PB06) +#define DEFAULT_I2C_BUS_SDA (&pin_PB07) diff --git a/ports/stm32f4/boards/pyboard_v11/pins.c b/ports/stm32f4/boards/pyboard_v11/pins.c index ccbb58ab9..8783dfcf1 100644 --- a/ports/stm32f4/boards/pyboard_v11/pins.c +++ b/ports/stm32f4/boards/pyboard_v11/pins.c @@ -46,5 +46,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) }, { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index d5491fe36..d7898ba0b 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke - * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2019 Lucian Copeland 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 diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h index ebee98f89..45505dee2 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke - * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2019 Lucian Copeland 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 @@ -36,3 +35,5 @@ #define AUTORESET_DELAY_MS 500 #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000) +#define DEFAULT_I2C_BUS_SCL (&pin_PB10) +#define DEFAULT_I2C_BUS_SDA (&pin_PB09) diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/pins.c b/ports/stm32f4/boards/stm32f412zg_discovery/pins.c index 461dee799..ab90b0455 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/pins.c +++ b/ports/stm32f4/boards/stm32f412zg_discovery/pins.c @@ -88,5 +88,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_PE01) }, { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_LED4), MP_ROM_PTR(&pin_PE03) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/stm32f4/common-hal/analogio/AnalogOut.c b/ports/stm32f4/common-hal/analogio/AnalogOut.c index 5eb8c2dc0..79ced0492 100644 --- a/ports/stm32f4/common-hal/analogio/AnalogOut.c +++ b/ports/stm32f4/common-hal/analogio/AnalogOut.c @@ -40,12 +40,12 @@ #include "stm32f4xx_hal.h" //DAC is shared between both channels. -//TODO: store as struct with channel info, automatically turn it off if unused -//on both channels for power save? #if HAS_DAC DAC_HandleTypeDef handle; #endif +STATIC bool dac_on[2]; + void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self, const mcu_pin_obj_t *pin) { #if !(HAS_DAC) @@ -53,8 +53,10 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self, #else if (pin == &pin_PA04) { self->channel = DAC_CHANNEL_1; + self->dac_index = 0; } else if (pin == &pin_PA05) { self->channel = DAC_CHANNEL_2; + self->dac_index = 1; } else { mp_raise_ValueError(translate("Invalid DAC pin supplied")); } @@ -82,22 +84,27 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self, mp_raise_ValueError(translate("DAC Channel Init Error")); } + dac_on[self->dac_index] = true; self->pin = pin; - self->deinited = false; claim_pin(pin); #endif } bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { - return self->deinited; + return !dac_on[self->dac_index]; } void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { #if HAS_DAC reset_pin_number(self->pin->port,self->pin->number); self->pin = mp_const_none; - self->deinited = true; - //TODO: if both are de-inited, should we turn off the DAC? + dac_on[self->dac_index] = false; + + //turn off the DAC if both channels are off + if(dac_on[0] == false && dac_on[1] == false) { + __HAL_RCC_DAC_CLK_DISABLE(); + HAL_DAC_DeInit(&handle); + } #endif } diff --git a/ports/stm32f4/common-hal/analogio/AnalogOut.h b/ports/stm32f4/common-hal/analogio/AnalogOut.h index 1381d4d3a..61591d0e6 100644 --- a/ports/stm32f4/common-hal/analogio/AnalogOut.h +++ b/ports/stm32f4/common-hal/analogio/AnalogOut.h @@ -41,7 +41,7 @@ typedef struct { #endif const mcu_pin_obj_t * pin; uint8_t channel; - bool deinited; + uint8_t dac_index:1; } analogio_analogout_obj_t; void analogout_reset(void); diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 2cb617819..b1e7bc05a 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -56,8 +56,8 @@ #define MICROPY_COMP_MODULE_CONST (1) #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0) #define MICROPY_DEBUG_PRINTERS (0) -#define MICROPY_EMIT_INLINE_THUMB (0) -#define MICROPY_EMIT_THUMB (0) +#define MICROPY_EMIT_INLINE_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE) +#define MICROPY_EMIT_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE) #define MICROPY_EMIT_X64 (0) #define MICROPY_ENABLE_DOC_STRING (0) #define MICROPY_ENABLE_FINALISER (1) diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index ac79d32d0..c1199571b 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -294,3 +294,10 @@ ifndef CIRCUITPY_BITBANG_APA102 CIRCUITPY_BITBANG_APA102 = 0 endif CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102) + + +# Enabled micropython.native decorator (experimental) +ifndef CIRCUITPY_ENABLE_MPY_NATIVE +CIRCUITPY_ENABLE_MPY_NATIVE = 0 +endif +CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE) diff --git a/py/compile.c b/py/compile.c index 1218aa07e..8b17935bd 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3207,7 +3207,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind } if (pass > MP_PASS_SCOPE) { mp_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]); - for (uint j = 1; j < n_args; j++) { + for (int j = 1; j < n_args; j++) { if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[j])) { compile_syntax_error(comp, nodes[i], translate("'data' requires integer arguments")); return; diff --git a/py/emitnative.c b/py/emitnative.c index 67b0025c6..6d23bf097 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -58,6 +58,22 @@ #define DEBUG_printf(...) (void)0 #endif +#ifndef N_X64 + #define N_X64 (0) +#endif +#ifndef N_X86 + #define N_X86 (0) +#endif +#ifndef N_THUMB + #define N_THUMB (0) +#endif +#ifndef N_ARM + #define N_ARM (0) +#endif +#ifndef N_XTENSA + #define N_XTENSA (0) +#endif + // wrapper around everything in this file #if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA @@ -443,10 +459,12 @@ STATIC void emit_native_end_pass(emit_t *emit) { type_sig |= (emit->local_vtype[i] & 0xf) << (i * 4 + 4); } + #pragma GCC diagnostic ignored "-Wcast-align" mp_emit_glue_assign_native(emit->scope->raw_code, emit->do_viper_types ? MP_CODE_NATIVE_VIPER : MP_CODE_NATIVE_PY, f, f_len, (mp_uint_t*)((byte*)f + emit->const_table_offset), emit->scope->num_pos_args, emit->scope->scope_flags, type_sig); + #pragma GCC diagnostic pop } } diff --git a/py/objfun.c b/py/objfun.c index b8364815b..7e5899456 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -546,7 +546,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_fun_asm_t *self = self_in; - mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false); + mp_arg_check_num_kw_array(n_args, n_kw, self->n_args, self->n_args, false); void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data); diff --git a/shared-module/displayio/I2CDisplay.c b/shared-module/displayio/I2CDisplay.c index d9452dc50..0307410d1 100644 --- a/shared-module/displayio/I2CDisplay.c +++ b/shared-module/displayio/I2CDisplay.c @@ -42,12 +42,22 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) { + // Reset the display before probing + self->reset.base.type = &mp_type_NoneType; + if (reset != NULL) { + self->reset.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&self->reset, reset); + common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); + never_reset_pin_number(reset->number); + common_hal_displayio_i2cdisplay_reset(self); + } + // Probe the bus to see if a device acknowledges the given address. if (!common_hal_busio_i2c_probe(i2c, device_address)) { mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address); } - // Write to the device and return 0 on success or an appropriate error code from mperrno.h + // Write to the device and return 0 on success or an appropriate error code from mperrno.h self->bus = i2c; common_hal_busio_i2c_never_reset(self->bus); // Our object is statically allocated off the heap so make sure the bus object lives to the end @@ -55,15 +65,6 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, gc_never_free(self->bus); self->address = device_address; - - self->reset.base.type = &mp_type_NoneType; - if (reset != NULL) { - self->reset.base.type = &digitalio_digitalinout_type; - common_hal_digitalio_digitalinout_construct(&self->reset, reset); - common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); - never_reset_pin_number(reset->number); - common_hal_displayio_i2cdisplay_reset(self); - } } void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) { |
