Skip to content

Commit ed3e377

Browse files
committed
Merge remote-tracking branch 'upstream/master' into stm32-uart
2 parents 14b7080 + 93cdf51 commit ed3e377

File tree

17 files changed

+87
-31
lines changed

17 files changed

+87
-31
lines changed

ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ CIRCUITPY_I2CSLAVE = 0
2525
CIRCUITPY_NETWORK = 0
2626
CIRCUITPY_TOUCHIO = 0
2727
CIRCUITPY_PS2IO = 0
28+
29+
# Enable micropython.native
30+
CIRCUITPY_ENABLE_MPY_NATIVE = 1

ports/stm32f4/boards/feather_stm32f405_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
*/
2626

2727
#include "boards/board.h"
28+
#include "mpconfigboard.h"
2829

2930
void board_init(void) {
3031
}
3132

3233
bool board_requests_safe_mode(void) {
33-
return false;
34+
return false;
3435
}
3536

3637
void reset_board(void) {

ports/stm32f4/boards/feather_stm32f405_express/mpconfigboard.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2016 Glenn Ruben Bakke
7-
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
87
*
98
* Permission is hereby granted, free of charge, to any person obtaining a copy
109
* of this software and associated documentation files (the "Software"), to deal
@@ -41,3 +40,13 @@
4140
#define SPI_FLASH_MISO_PIN &pin_PB04
4241
#define SPI_FLASH_SCK_PIN &pin_PB03
4342
#define SPI_FLASH_CS_PIN &pin_PA15
43+
44+
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
45+
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
46+
47+
#define DEFAULT_SPI_BUS_SCK (&pin_PB13)
48+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB15)
49+
#define DEFAULT_SPI_BUS_MISO (&pin_PB14)
50+
51+
#define DEFAULT_UART_BUS_RX (&pin_PB11)
52+
#define DEFAULT_UART_BUS_TX (&pin_PB10)

ports/stm32f4/boards/feather_stm32f405_express/pins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
2525

2626
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB10) },
2727
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB11) },
28+
29+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
30+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
31+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
2832
};
2933
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/stm32f4/boards/pyboard_v11/mpconfigboard.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2016 Glenn Ruben Bakke
7-
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
87
*
98
* Permission is hereby granted, free of charge, to any person obtaining a copy
109
* of this software and associated documentation files (the "Software"), to deal
@@ -34,4 +33,7 @@
3433
#define FLASH_PAGE_SIZE (0x4000)
3534

3635
#define AUTORESET_DELAY_MS 500
37-
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
36+
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
37+
38+
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
39+
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)

ports/stm32f4/boards/pyboard_v11/pins.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
4646

4747
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) },
4848
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
4951
};
5052
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2016 Glenn Ruben Bakke
7-
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
87
*
98
* Permission is hereby granted, free of charge, to any person obtaining a copy
109
* of this software and associated documentation files (the "Software"), to deal

ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2016 Glenn Ruben Bakke
7-
* Copyright (c) 2018 Dan Halbert for Adafruit Industries
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
87
*
98
* Permission is hereby granted, free of charge, to any person obtaining a copy
109
* of this software and associated documentation files (the "Software"), to deal
@@ -36,3 +35,5 @@
3635
#define AUTORESET_DELAY_MS 500
3736
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000)
3837

38+
#define DEFAULT_I2C_BUS_SCL (&pin_PB10)
39+
#define DEFAULT_I2C_BUS_SDA (&pin_PB09)

ports/stm32f4/boards/stm32f412zg_discovery/pins.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
8888
{ MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_PE01) },
8989
{ MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_PE02) },
9090
{ MP_ROM_QSTR(MP_QSTR_LED4), MP_ROM_PTR(&pin_PE03) },
91+
92+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
9193
};
9294
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/stm32f4/common-hal/analogio/AnalogOut.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,23 @@
4040
#include "stm32f4xx_hal.h"
4141

4242
//DAC is shared between both channels.
43-
//TODO: store as struct with channel info, automatically turn it off if unused
44-
//on both channels for power save?
4543
#if HAS_DAC
4644
DAC_HandleTypeDef handle;
4745
#endif
4846

47+
STATIC bool dac_on[2];
48+
4949
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
5050
const mcu_pin_obj_t *pin) {
5151
#if !(HAS_DAC)
5252
mp_raise_ValueError(translate("No DAC on chip"));
5353
#else
5454
if (pin == &pin_PA04) {
5555
self->channel = DAC_CHANNEL_1;
56+
self->dac_index = 0;
5657
} else if (pin == &pin_PA05) {
5758
self->channel = DAC_CHANNEL_2;
59+
self->dac_index = 1;
5860
} else {
5961
mp_raise_ValueError(translate("Invalid DAC pin supplied"));
6062
}
@@ -82,22 +84,27 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
8284
mp_raise_ValueError(translate("DAC Channel Init Error"));
8385
}
8486

87+
dac_on[self->dac_index] = true;
8588
self->pin = pin;
86-
self->deinited = false;
8789
claim_pin(pin);
8890
#endif
8991
}
9092

9193
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
92-
return self->deinited;
94+
return !dac_on[self->dac_index];
9395
}
9496

9597
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
9698
#if HAS_DAC
9799
reset_pin_number(self->pin->port,self->pin->number);
98100
self->pin = mp_const_none;
99-
self->deinited = true;
100-
//TODO: if both are de-inited, should we turn off the DAC?
101+
dac_on[self->dac_index] = false;
102+
103+
//turn off the DAC if both channels are off
104+
if(dac_on[0] == false && dac_on[1] == false) {
105+
__HAL_RCC_DAC_CLK_DISABLE();
106+
HAL_DAC_DeInit(&handle);
107+
}
101108
#endif
102109
}
103110

ports/stm32f4/common-hal/analogio/AnalogOut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct {
4141
#endif
4242
const mcu_pin_obj_t * pin;
4343
uint8_t channel;
44-
bool deinited;
44+
uint8_t dac_index:1;
4545
} analogio_analogout_obj_t;
4646

4747
void analogout_reset(void);

py/circuitpy_mpconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
#define MICROPY_COMP_MODULE_CONST (1)
5757
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
5858
#define MICROPY_DEBUG_PRINTERS (0)
59-
#define MICROPY_EMIT_INLINE_THUMB (0)
60-
#define MICROPY_EMIT_THUMB (0)
59+
#define MICROPY_EMIT_INLINE_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE)
60+
#define MICROPY_EMIT_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE)
6161
#define MICROPY_EMIT_X64 (0)
6262
#define MICROPY_ENABLE_DOC_STRING (0)
6363
#define MICROPY_ENABLE_FINALISER (1)

py/circuitpy_mpconfig.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,10 @@ ifndef CIRCUITPY_BITBANG_APA102
294294
CIRCUITPY_BITBANG_APA102 = 0
295295
endif
296296
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
297+
298+
299+
# Enabled micropython.native decorator (experimental)
300+
ifndef CIRCUITPY_ENABLE_MPY_NATIVE
301+
CIRCUITPY_ENABLE_MPY_NATIVE = 0
302+
endif
303+
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3207,7 +3207,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
32073207
}
32083208
if (pass > MP_PASS_SCOPE) {
32093209
mp_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]);
3210-
for (uint j = 1; j < n_args; j++) {
3210+
for (int j = 1; j < n_args; j++) {
32113211
if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[j])) {
32123212
compile_syntax_error(comp, nodes[i], translate("'data' requires integer arguments"));
32133213
return;

py/emitnative.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@
5858
#define DEBUG_printf(...) (void)0
5959
#endif
6060

61+
#ifndef N_X64
62+
#define N_X64 (0)
63+
#endif
64+
#ifndef N_X86
65+
#define N_X86 (0)
66+
#endif
67+
#ifndef N_THUMB
68+
#define N_THUMB (0)
69+
#endif
70+
#ifndef N_ARM
71+
#define N_ARM (0)
72+
#endif
73+
#ifndef N_XTENSA
74+
#define N_XTENSA (0)
75+
#endif
76+
6177
// wrapper around everything in this file
6278
#if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA
6379

@@ -443,10 +459,12 @@ STATIC void emit_native_end_pass(emit_t *emit) {
443459
type_sig |= (emit->local_vtype[i] & 0xf) << (i * 4 + 4);
444460
}
445461

462+
#pragma GCC diagnostic ignored "-Wcast-align"
446463
mp_emit_glue_assign_native(emit->scope->raw_code,
447464
emit->do_viper_types ? MP_CODE_NATIVE_VIPER : MP_CODE_NATIVE_PY,
448465
f, f_len, (mp_uint_t*)((byte*)f + emit->const_table_offset),
449466
emit->scope->num_pos_args, emit->scope->scope_flags, type_sig);
467+
#pragma GCC diagnostic pop
450468
}
451469
}
452470

py/objfun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
546546
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) {
547547
mp_obj_fun_asm_t *self = self_in;
548548

549-
mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false);
549+
mp_arg_check_num_kw_array(n_args, n_kw, self->n_args, self->n_args, false);
550550

551551
void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data);
552552

shared-module/displayio/I2CDisplay.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,29 @@
4242
void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
4343
busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) {
4444

45+
// Reset the display before probing
46+
self->reset.base.type = &mp_type_NoneType;
47+
if (reset != NULL) {
48+
self->reset.base.type = &digitalio_digitalinout_type;
49+
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
50+
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
51+
never_reset_pin_number(reset->number);
52+
common_hal_displayio_i2cdisplay_reset(self);
53+
}
54+
4555
// Probe the bus to see if a device acknowledges the given address.
4656
if (!common_hal_busio_i2c_probe(i2c, device_address)) {
4757
mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address);
4858
}
4959

50-
// Write to the device and return 0 on success or an appropriate error code from mperrno.h
60+
// Write to the device and return 0 on success or an appropriate error code from mperrno.h
5161
self->bus = i2c;
5262
common_hal_busio_i2c_never_reset(self->bus);
5363
// Our object is statically allocated off the heap so make sure the bus object lives to the end
5464
// of the heap as well.
5565
gc_never_free(self->bus);
5666

5767
self->address = device_address;
58-
59-
self->reset.base.type = &mp_type_NoneType;
60-
if (reset != NULL) {
61-
self->reset.base.type = &digitalio_digitalinout_type;
62-
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
63-
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
64-
never_reset_pin_number(reset->number);
65-
common_hal_displayio_i2cdisplay_reset(self);
66-
}
6768
}
6869

6970
void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) {

0 commit comments

Comments
 (0)