From 8e15f36baada85345f8356ffcc8f8d48612a0c5e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Feb 2021 16:58:29 -0600 Subject: [PATCH 01/48] pulseio (pulsein) for RP2040 --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 231 ++++++++++++++++++ .../raspberrypi/common-hal/pulseio/PulseIn.h | 53 ++++ .../raspberrypi/common-hal/pulseio/PulseOut.c | 97 ++++++++ .../raspberrypi/common-hal/pulseio/PulseOut.h | 44 ++++ .../raspberrypi/common-hal/pulseio/__init__.c | 1 + .../common-hal/rp2pio/StateMachine.c | 2 + .../common-hal/rp2pio/StateMachine.h | 2 + ports/raspberrypi/mpconfigport.mk | 2 +- 8 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 ports/raspberrypi/common-hal/pulseio/PulseIn.c create mode 100644 ports/raspberrypi/common-hal/pulseio/PulseIn.h create mode 100644 ports/raspberrypi/common-hal/pulseio/PulseOut.c create mode 100644 ports/raspberrypi/common-hal/pulseio/PulseOut.h create mode 100644 ports/raspberrypi/common-hal/pulseio/__init__.c diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c new file mode 100644 index 0000000000..c642561c89 --- /dev/null +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -0,0 +1,231 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017-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 "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" + +#include + +#include "background.h" +#include "mpconfigport.h" +#include "py/gc.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/pulseio/PulseIn.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "supervisor/shared/translate.h" +#include "bindings/rp2pio/StateMachine.h" +#include "common-hal/pulseio/PulseIn.h" + +pulseio_pulsein_obj_t* save_self; + +#define NO_PIN 0xff + +const uint16_t pulsein_program[] = { +// set pindirs, 0 ; For input + 0xe080, +// wait 0 pin, 0 ; Wait for first low to start + 0x2020, +// irq wait 0 ; set IRQ 0 and wait + 0xc020, +// .bitloop +// in pins, 1 [1] ; sample every 3 cycles (2 instructions, 1 delay) + 0x4101, +// jmp bitloop + 0x0003, +}; + +void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, + const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) { + + self->buffer = (uint16_t *) m_malloc(maxlen * sizeof(uint16_t), false); + if (self->buffer == NULL) { + mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t)); + } + self->pin = pin->number; + self->maxlen = maxlen; + self->idle_state = idle_state; + self->start = 0; + self->len = 0; + save_self = self; + + // Set everything up. + rp2pio_statemachine_obj_t state_machine; + + bool ok = rp2pio_statemachine_construct(&state_machine, + pulsein_program, sizeof(pulsein_program) / sizeof(pulsein_program[0]), + 125000 * 4, + NULL, 0, + NULL, 0, + pin, 1, + NULL, 0, + NULL, 0, + 1 << self->pin, false, true, + false, 8, false, // TX, unused + true, 32, true, // RX iauto-push every 32 bits + false); // claim pins + self->pio = state_machine.pio; + self->sm = state_machine.state_machine; + self->sm_cfg = state_machine.sm_config; + self->offset = state_machine.offset; + if ( self->pio == pio0 ) { + self->pio_interrupt = PIO0_IRQ_0; + } else { + self->pio_interrupt = PIO1_IRQ_0; + } + + pio_sm_set_in_pins(self->pio,self->sm,pin->number); + pio_sm_set_enabled(self->pio, self->sm, false); + irq_set_exclusive_handler(self->pio_interrupt, common_hal_pulseio_pulsein_interrupt); + irq_set_enabled(self->pio_interrupt, true); + hw_clear_bits(&self->pio->inte0, 1u << self->sm); + hw_set_bits(&self->pio->inte0, 1u << (self->sm+8)); + pio_sm_set_enabled(self->pio, self->sm, true); + +} + +bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { + return self->pin == NO_PIN; +} + +void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { + if (common_hal_pulseio_pulsein_deinited(self)) { + return; + } + irq_set_enabled(self->pio_interrupt, false); + pio_sm_set_enabled(self->pio, self->sm, false); + pio_sm_unclaim (self->pio, self->sm); + m_free(self->buffer); + self->pin = NO_PIN; +} + +void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) { + pio_sm_set_enabled(self->pio, self->sm, false); +} + +void common_hal_pulseio_pulsein_interrupt() { + + pulseio_pulsein_obj_t* self = save_self; +// clear interrupt + hw_clear_bits(&self->pio->inte0, 1u << self->sm); + self->pio->irq = 1u << self->sm; + irq_clear(self->pio_interrupt); + pio_sm_clear_fifos(self->pio,self->sm); + bool last_level = true; + uint level_count = 0; + uint16_t result = 0; + uint16_t buf_index = 0; + while ( buf_index < self->maxlen ) { + uint32_t rxfifo = 0; + rxfifo = pio_sm_get_blocking(self->pio, self->sm); + // translate from fifo to buffer + for (uint i = 0; i < 32; i++) { + bool level = (rxfifo & (1 << i)) >> i; + if (level == last_level ) { + level_count ++; + } else { + result = level_count * 6; + last_level = level; + level_count = 1; + // ignore pulses that are too long and too short + if (result < 10000 && result > 10) { + self->buffer[buf_index] = result; + buf_index++; + self->len++; + } + } + } + // check for a pulse thats too long (20ms) + if ( level_count > 3000 ) { + break; + } + } + pio_sm_set_enabled(self->pio, self->sm, false); + pio_sm_init(self->pio, self->sm, self->offset, &self->sm_cfg); + pio_sm_restart(self->pio,self->sm); + pio_sm_set_enabled(self->pio, self->sm, true); + irq_set_enabled(self->pio_interrupt, true); +} +void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, + uint16_t trigger_duration) { + // Send the trigger pulse. + if (trigger_duration > 0) { + gpio_set_function(self->pin ,GPIO_FUNC_SIO); + gpio_set_dir(self->pin,true); + gpio_put(self->pin, false); + common_hal_mcu_delay_us((uint32_t)trigger_duration); + gpio_set_function(self->pin ,GPIO_FUNC_PIO0); + } + + // Reconfigure the pin for PIO + common_hal_mcu_delay_us(100); + gpio_set_function(self->pin, GPIO_FUNC_PIO0); + pio_sm_set_enabled(self->pio, self->sm, true); + pio_sm_exec(self->pio,self->sm,0x20a0); +} + +void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) { + self->start = 0; + self->len = 0; +} + +uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) { + if (self->len == 0) { + mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_PulseIn); + } + uint16_t value = self->buffer[self->start]; + self->start = (self->start + 1) % self->maxlen; + self->len--; + if (self->len == 0 ) { + // reset buffer pointer + self->start = 0; + } + return value; +} + +uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) { + return self->maxlen; +} + +uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) { + return self->len; +} + +bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) { + return true; +} + +uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self, + int16_t index) { + if (index < 0) { + index += self->len; + } + if (index < 0 || index >= self->len) { + mp_raise_IndexError_varg(translate("%q index out of range"), MP_QSTR_PulseIn); + } + uint16_t value = self->buffer[(self->start + index) % self->maxlen]; + return value; +} diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h new file mode 100644 index 0000000000..35f7309eef --- /dev/null +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -0,0 +1,53 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 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_COMMON_HAL_PULSEIO_PULSEIN_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H + +#include "common-hal/microcontroller/Pin.h" +#include "src/rp2_common/hardware_pio/include/hardware/pio.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint8_t pin; + uint16_t* buffer; + uint16_t maxlen; + bool idle_state; + volatile uint16_t start; + volatile uint16_t len; + pio_sm_config sm_cfg; + PIO pio; + uint8_t sm; + uint8_t offset; + uint16_t pio_interrupt; +} pulseio_pulsein_obj_t; + +void pulsein_reset(void); +void common_hal_pulseio_pulsein_interrupt(); + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.c b/ports/raspberrypi/common-hal/pulseio/PulseOut.c new file mode 100644 index 0000000000..57c516afd0 --- /dev/null +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.c @@ -0,0 +1,97 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George + * + * 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 "common-hal/pulseio/PulseOut.h" + +#include + +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" + +#include "mpconfigport.h" +#include "py/gc.h" +#include "py/runtime.h" +#include "shared-bindings/pulseio/PulseOut.h" +#include "supervisor/shared/translate.h" + +static uint8_t refcount = 0; + + +static uint16_t *pulse_buffer = NULL; +static volatile uint16_t pulse_index = 0; +static uint16_t pulse_length; +static volatile uint32_t current_compare = 0; + +void pulse_finish(void) { + pulse_index++; + + // Always turn it off. + if (pulse_index >= pulse_length) { + return; + } + current_compare = (current_compare + pulse_buffer[pulse_index] * 3 / 4) & 0xffff; +} + +void pulseout_reset() { + refcount = 0; +} + +void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, + const pwmio_pwmout_obj_t* carrier, + const mcu_pin_obj_t* pin, + uint32_t frequency, + uint16_t duty_cycle) { + if (!carrier || pin || frequency) { + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); + } + + refcount++; + + self->pin = carrier->pin->number; + +} + +bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self) { + return self->pin == NO_PIN; +} + +void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) { + if (common_hal_pulseio_pulseout_deinited(self)) { + return; + } + + + refcount--; + self->pin = NO_PIN; +} + +void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) { + pulse_buffer = pulses; + pulse_index = 0; + pulse_length = length; + + current_compare = pulses[0] * 3 / 4; + +} diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.h b/ports/raspberrypi/common-hal/pulseio/PulseOut.h new file mode 100644 index 0000000000..e3f17e2d66 --- /dev/null +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.h @@ -0,0 +1,44 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 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_COMMON_HAL_PULSEIO_PULSEOUT_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +#define NO_PIN 0xff + +typedef struct { + mp_obj_base_t base; + uint8_t pin; +} pulseio_pulseout_obj_t; + +void pulseout_reset(void); +void pulseout_interrupt_handler(uint8_t index); + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H diff --git a/ports/raspberrypi/common-hal/pulseio/__init__.c b/ports/raspberrypi/common-hal/pulseio/__init__.c new file mode 100644 index 0000000000..2bee925bc7 --- /dev/null +++ b/ports/raspberrypi/common-hal/pulseio/__init__.c @@ -0,0 +1 @@ +// No pulseio module functions. diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 90c48130e1..da85748a9d 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -193,6 +193,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, if (program_offset == 32) { program_offset = pio_add_program(self->pio, &program_struct); } + self->offset = program_offset; _current_program_id[pio_index][state_machine] = program_id; _current_program_len[pio_index][state_machine] = program_len; _current_program_offset[pio_index][state_machine] = program_offset; @@ -262,6 +263,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, self->in_shift_right = in_shift_right; sm_config_set_fifo_join(&c, join); + self->sm_config = c; pio_sm_init(self->pio, self->state_machine, program_offset, &c); pio_sm_set_enabled(self->pio, self->state_machine, true); diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h index 6b70b6b5b5..289e91b7d7 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h @@ -43,6 +43,8 @@ typedef struct { bool out_shift_right; bool in_shift_right; uint32_t actual_frequency; + pio_sm_config sm_config; + uint8_t offset; } rp2pio_statemachine_obj_t; void reset_rp2pio_statemachine(void); diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index ab85c59f9a..6f411387f5 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -26,13 +26,13 @@ endif CIRCUITPY_FULL_BUILD = 1 CIRCUITPY_BITOPS = 1 CIRCUITPY_PWMIO = 1 +CIRCUITPY_PULSEIO = 1 # Things that need to be implemented. CIRCUITPY_COUNTIO = 0 # Use PWM interally CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_NVM = 0 -CIRCUITPY_PULSEIO = 0 # Use PIO interally CIRCUITPY_ROTARYIO = 0 # Use PIO interally CIRCUITPY_WATCHDOG = 1 From 17ff5dcc9934e6ed442bfa4d6cac2a435093e4aa Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Feb 2021 17:04:05 -0600 Subject: [PATCH 02/48] Return NotImplementedError for PulseOut --- ports/raspberrypi/common-hal/pulseio/PulseOut.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.c b/ports/raspberrypi/common-hal/pulseio/PulseOut.c index 57c516afd0..f3f7121434 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.c @@ -63,9 +63,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, const mcu_pin_obj_t* pin, uint32_t frequency, uint16_t duty_cycle) { - if (!carrier || pin || frequency) { - mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); - } + mp_raise_NotImplementedError(translate("Unsupported operation")); refcount++; From 86e60f5f351659bfff4ff2cce37df36dc74e8352 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 Feb 2021 17:26:35 -0600 Subject: [PATCH 03/48] Clean up formatting --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index c642561c89..bee4398a2d 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -143,25 +143,25 @@ void common_hal_pulseio_pulsein_interrupt() { rxfifo = pio_sm_get_blocking(self->pio, self->sm); // translate from fifo to buffer for (uint i = 0; i < 32; i++) { - bool level = (rxfifo & (1 << i)) >> i; - if (level == last_level ) { - level_count ++; - } else { - result = level_count * 6; - last_level = level; - level_count = 1; + bool level = (rxfifo & (1 << i)) >> i; + if (level == last_level ) { + level_count ++; + } else { + result = level_count * 6; + last_level = level; + level_count = 1; // ignore pulses that are too long and too short - if (result < 10000 && result > 10) { - self->buffer[buf_index] = result; - buf_index++; - self->len++; - } + if (result < 10000 && result > 10) { + self->buffer[buf_index] = result; + buf_index++; + self->len++; + } } - } - // check for a pulse thats too long (20ms) - if ( level_count > 3000 ) { - break; - } + } + // check for a pulse thats too long (20ms) + if ( level_count > 3000 ) { + break; + } } pio_sm_set_enabled(self->pio, self->sm, false); pio_sm_init(self->pio, self->sm, self->offset, &self->sm_cfg); @@ -181,7 +181,7 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, } // Reconfigure the pin for PIO - common_hal_mcu_delay_us(100); + common_hal_mcu_delay_us(100); gpio_set_function(self->pin, GPIO_FUNC_PIO0); pio_sm_set_enabled(self->pio, self->sm, true); pio_sm_exec(self->pio,self->sm,0x20a0); From 79429321767492c79db4c6cce45d681261d78c66 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Feb 2021 14:14:55 -0600 Subject: [PATCH 04/48] Requested changes --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 59 ++++++++++--------- .../raspberrypi/common-hal/pulseio/PulseIn.h | 8 +-- .../raspberrypi/common-hal/pulseio/PulseOut.h | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index bee4398a2d..8841cb9266 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017-2018 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2017-2021 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 @@ -45,8 +45,6 @@ pulseio_pulsein_obj_t* save_self; #define NO_PIN 0xff const uint16_t pulsein_program[] = { -// set pindirs, 0 ; For input - 0xe080, // wait 0 pin, 0 ; Wait for first low to start 0x2020, // irq wait 0 ; set IRQ 0 and wait @@ -55,7 +53,7 @@ const uint16_t pulsein_program[] = { // in pins, 1 [1] ; sample every 3 cycles (2 instructions, 1 delay) 0x4101, // jmp bitloop - 0x0003, + 0x0002, }; void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, @@ -85,25 +83,27 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, NULL, 0, 1 << self->pin, false, true, false, 8, false, // TX, unused - true, 32, true, // RX iauto-push every 32 bits + true, 32, true, // RX auto-push every 32 bits false); // claim pins - self->pio = state_machine.pio; - self->sm = state_machine.state_machine; - self->sm_cfg = state_machine.sm_config; - self->offset = state_machine.offset; - if ( self->pio == pio0 ) { + self->state_machine.pio = state_machine.pio; + self->state_machine.state_machine = state_machine.state_machine; + self->state_machine.sm_config = state_machine.sm_config; + self->state_machine.offset = state_machine.offset; + if ( self->state_machine.pio == pio0 ) { self->pio_interrupt = PIO0_IRQ_0; } else { self->pio_interrupt = PIO1_IRQ_0; } - pio_sm_set_in_pins(self->pio,self->sm,pin->number); - pio_sm_set_enabled(self->pio, self->sm, false); + pio_sm_set_in_pins(self->state_machine.pio,self->state_machine.state_machine,pin->number); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); irq_set_exclusive_handler(self->pio_interrupt, common_hal_pulseio_pulsein_interrupt); irq_set_enabled(self->pio_interrupt, true); - hw_clear_bits(&self->pio->inte0, 1u << self->sm); - hw_set_bits(&self->pio->inte0, 1u << (self->sm+8)); - pio_sm_set_enabled(self->pio, self->sm, true); + hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); + hw_set_bits(&self->state_machine.pio->inte0, 1u << (self->state_machine.state_machine+8)); + // exec a set pindirs to 0 for input + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0xe080); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); } @@ -116,31 +116,31 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { return; } irq_set_enabled(self->pio_interrupt, false); - pio_sm_set_enabled(self->pio, self->sm, false); - pio_sm_unclaim (self->pio, self->sm); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); + pio_sm_unclaim (self->state_machine.pio, self->state_machine.state_machine); m_free(self->buffer); self->pin = NO_PIN; } void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) { - pio_sm_set_enabled(self->pio, self->sm, false); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); } void common_hal_pulseio_pulsein_interrupt() { pulseio_pulsein_obj_t* self = save_self; // clear interrupt - hw_clear_bits(&self->pio->inte0, 1u << self->sm); - self->pio->irq = 1u << self->sm; + hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); + self->state_machine.pio->irq = 1u << self->state_machine.state_machine; irq_clear(self->pio_interrupt); - pio_sm_clear_fifos(self->pio,self->sm); + pio_sm_clear_fifos(self->state_machine.pio,self->state_machine.state_machine); bool last_level = true; uint level_count = 0; uint16_t result = 0; uint16_t buf_index = 0; while ( buf_index < self->maxlen ) { uint32_t rxfifo = 0; - rxfifo = pio_sm_get_blocking(self->pio, self->sm); + rxfifo = pio_sm_get_blocking(self->state_machine.pio, self->state_machine.state_machine); // translate from fifo to buffer for (uint i = 0; i < 32; i++) { bool level = (rxfifo & (1 << i)) >> i; @@ -163,10 +163,10 @@ void common_hal_pulseio_pulsein_interrupt() { break; } } - pio_sm_set_enabled(self->pio, self->sm, false); - pio_sm_init(self->pio, self->sm, self->offset, &self->sm_cfg); - pio_sm_restart(self->pio,self->sm); - pio_sm_set_enabled(self->pio, self->sm, true); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); + pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); + pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); irq_set_enabled(self->pio_interrupt, true); } void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, @@ -175,7 +175,7 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, if (trigger_duration > 0) { gpio_set_function(self->pin ,GPIO_FUNC_SIO); gpio_set_dir(self->pin,true); - gpio_put(self->pin, false); + gpio_put(self->pin, !self->idle_state); common_hal_mcu_delay_us((uint32_t)trigger_duration); gpio_set_function(self->pin ,GPIO_FUNC_PIO0); } @@ -183,8 +183,9 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, // Reconfigure the pin for PIO common_hal_mcu_delay_us(100); gpio_set_function(self->pin, GPIO_FUNC_PIO0); - pio_sm_set_enabled(self->pio, self->sm, true); - pio_sm_exec(self->pio,self->sm,0x20a0); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); + // exec a wait for the selected pin to go high + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); } void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) { diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h index 35f7309eef..6be13ebb1c 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2017-2021 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 @@ -29,6 +29,7 @@ #include "common-hal/microcontroller/Pin.h" #include "src/rp2_common/hardware_pio/include/hardware/pio.h" +#include "common-hal/rp2pio/StateMachine.h" #include "py/obj.h" @@ -40,10 +41,7 @@ typedef struct { bool idle_state; volatile uint16_t start; volatile uint16_t len; - pio_sm_config sm_cfg; - PIO pio; - uint8_t sm; - uint8_t offset; + rp2pio_statemachine_obj_t state_machine; uint16_t pio_interrupt; } pulseio_pulsein_obj_t; diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.h b/ports/raspberrypi/common-hal/pulseio/PulseOut.h index e3f17e2d66..10c1a1756e 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2017-2021 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 From 6046d37f31c85ab90e3073c3a9ba5ec185082667 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 2 Mar 2021 21:23:45 -0600 Subject: [PATCH 05/48] Update PulseIn.c --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 8841cb9266..cd466dd93d 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -81,6 +81,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, pin, 1, NULL, 0, NULL, 0, + 1, self->pin, 1 << self->pin, false, true, false, 8, false, // TX, unused true, 32, true, // RX auto-push every 32 bits From 58fb7b9b327fa2532a123df9660669a0385f0b30 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 2 Mar 2021 21:27:46 -0600 Subject: [PATCH 06/48] Update mpconfigport.mk to get builds working --- ports/raspberrypi/mpconfigport.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 6f411387f5..63a58b5a17 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -26,6 +26,8 @@ endif CIRCUITPY_FULL_BUILD = 1 CIRCUITPY_BITOPS = 1 CIRCUITPY_PWMIO = 1 + + CIRCUITPY_PULSEIO = 1 # Things that need to be implemented. From 30d491e136b0606ca6e38dd84869aab1e7f2f44f Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 2 Mar 2021 21:30:49 -0600 Subject: [PATCH 07/48] Update mpconfigport.mk --- ports/raspberrypi/mpconfigport.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 63a58b5a17..f0ed852c00 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -34,7 +34,7 @@ CIRCUITPY_PULSEIO = 1 CIRCUITPY_COUNTIO = 0 # Use PWM interally CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_NVM = 0 +CIRCUITPY_NVM = 1 CIRCUITPY_ROTARYIO = 0 # Use PIO interally CIRCUITPY_WATCHDOG = 1 From 9b96bae66883f10895506e8917639936495ed9b8 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 2 Mar 2021 21:36:00 -0600 Subject: [PATCH 08/48] Update mpconfigport.mk --- ports/raspberrypi/mpconfigport.mk | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index f0ed852c00..78aab307f1 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -27,14 +27,12 @@ CIRCUITPY_FULL_BUILD = 1 CIRCUITPY_BITOPS = 1 CIRCUITPY_PWMIO = 1 - -CIRCUITPY_PULSEIO = 1 - # Things that need to be implemented. CIRCUITPY_COUNTIO = 0 # Use PWM interally CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_NVM = 1 +CIRCUITPY_PULSEIO = 1 # Use PIO interally CIRCUITPY_ROTARYIO = 0 # Use PIO interally CIRCUITPY_WATCHDOG = 1 From ced707ed329e83749d3474ea6f391f03f5bd1bdf Mon Sep 17 00:00:00 2001 From: DavePutz Date: Wed, 3 Mar 2021 10:55:08 -0600 Subject: [PATCH 09/48] Update call to rp2pio_statemachine_construct --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index cd466dd93d..ea0d24f869 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -84,6 +84,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, 1, self->pin, 1 << self->pin, false, true, false, 8, false, // TX, unused + false, true, 32, true, // RX auto-push every 32 bits false); // claim pins self->state_machine.pio = state_machine.pio; From 88353f2f5bbe86879bd38f89dc73f3317ce288af Mon Sep 17 00:00:00 2001 From: DavePutz Date: Wed, 3 Mar 2021 11:00:58 -0600 Subject: [PATCH 10/48] Update mpconfigport.mk --- ports/raspberrypi/mpconfigport.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 78aab307f1..8bf31208f9 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -32,7 +32,7 @@ CIRCUITPY_COUNTIO = 0 # Use PWM interally CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_NVM = 1 -CIRCUITPY_PULSEIO = 1 # Use PIO interally +CIRCUITPY_PULSEIO = 1 CIRCUITPY_ROTARYIO = 0 # Use PIO interally CIRCUITPY_WATCHDOG = 1 From 2d941b070f348ef2f104825c7c6db9b22da49e83 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Thu, 4 Mar 2021 13:51:46 -0600 Subject: [PATCH 11/48] Changed interrupt to per-word basis; cleaned up other small items --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 124 ++++++++++-------- .../raspberrypi/common-hal/pulseio/PulseIn.h | 2 +- 2 files changed, 67 insertions(+), 59 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index ea0d24f869..7053b55248 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017-2021 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2021 Dave Putz 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 @@ -29,9 +29,6 @@ #include -#include "background.h" -#include "mpconfigport.h" -#include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/pulseio/PulseIn.h" @@ -43,17 +40,19 @@ pulseio_pulsein_obj_t* save_self; #define NO_PIN 0xff +volatile bool last_level; +volatile uint16_t level_count = 0; +volatile uint16_t result = 0; +volatile uint16_t buf_index = 0; -const uint16_t pulsein_program[] = { -// wait 0 pin, 0 ; Wait for first low to start - 0x2020, -// irq wait 0 ; set IRQ 0 and wait - 0xc020, -// .bitloop -// in pins, 1 [1] ; sample every 3 cycles (2 instructions, 1 delay) - 0x4101, -// jmp bitloop - 0x0002, +uint16_t pulsein_program[] = { + 0x2020, // 0: wait 0 pin, 0 + 0xe03f, // 1: set x, 31 + 0x4001, // 2: in pins, 1 + 0x0042, // 3: jmp x--, 2 + 0x8060, // 4: push iffull block + 0xc020, // 5: irq wait 0 + 0x0001, // 6: jmp 1 }; void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, @@ -69,19 +68,23 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, self->start = 0; self->len = 0; save_self = self; + // change initial state machine wait if idle_state is false + if (idle_state == false) { + pulsein_program[0] = 0x20a0; + } // Set everything up. rp2pio_statemachine_obj_t state_machine; bool ok = rp2pio_statemachine_construct(&state_machine, pulsein_program, sizeof(pulsein_program) / sizeof(pulsein_program[0]), - 125000 * 4, + 1000000 * 3, NULL, 0, NULL, 0, pin, 1, NULL, 0, NULL, 0, - 1, self->pin, + 1, 0, 1 << self->pin, false, true, false, 8, false, // TX, unused false, @@ -96,17 +99,22 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, } else { self->pio_interrupt = PIO1_IRQ_0; } + pio_sm_clear_fifos(self->state_machine.pio,self->state_machine.state_machine); + last_level = self->idle_state; + level_count = 0; + result = 0; + buf_index = 0; - pio_sm_set_in_pins(self->state_machine.pio,self->state_machine.state_machine,pin->number); - pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); + pio_sm_set_in_pins(state_machine.pio,state_machine.state_machine,pin->number); + pio_sm_set_enabled(state_machine.pio,state_machine.state_machine, false); irq_set_exclusive_handler(self->pio_interrupt, common_hal_pulseio_pulsein_interrupt); - irq_set_enabled(self->pio_interrupt, true); - hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); - hw_set_bits(&self->state_machine.pio->inte0, 1u << (self->state_machine.state_machine+8)); - // exec a set pindirs to 0 for input - pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0xe080); - pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); + hw_clear_bits(&state_machine.pio->inte0, 1u << state_machine.state_machine); + hw_set_bits(&state_machine.pio->inte0, 1u << (state_machine.state_machine+8)); + // exec a set pindirs to 0 for input + pio_sm_exec(state_machine.pio,state_machine.state_machine,0xe080); + irq_set_enabled(self->pio_interrupt, true); + pio_sm_set_enabled(state_machine.pio, state_machine.state_machine, true); } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { @@ -131,48 +139,48 @@ void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) { void common_hal_pulseio_pulsein_interrupt() { pulseio_pulsein_obj_t* self = save_self; -// clear interrupt - hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); - self->state_machine.pio->irq = 1u << self->state_machine.state_machine; - irq_clear(self->pio_interrupt); - pio_sm_clear_fifos(self->state_machine.pio,self->state_machine.state_machine); - bool last_level = true; - uint level_count = 0; - uint16_t result = 0; - uint16_t buf_index = 0; - while ( buf_index < self->maxlen ) { - uint32_t rxfifo = 0; - rxfifo = pio_sm_get_blocking(self->state_machine.pio, self->state_machine.state_machine); - // translate from fifo to buffer - for (uint i = 0; i < 32; i++) { - bool level = (rxfifo & (1 << i)) >> i; - if (level == last_level ) { - level_count ++; - } else { - result = level_count * 6; - last_level = level; - level_count = 1; + uint32_t rxfifo = 0; + + rxfifo = pio_sm_get_blocking(self->state_machine.pio, self->state_machine.state_machine); + // translate from fifo to buffer + for (uint i = 0; i < 32; i++) { + bool level = (rxfifo & (1 << i)) >> i; + if (level == last_level ) { + level_count ++; + } else { + result = level_count; + last_level = level; + level_count = 1; // ignore pulses that are too long and too short - if (result < 10000 && result > 10) { + if (result < 2000 && result > 10) { self->buffer[buf_index] = result; buf_index++; self->len++; } } } - // check for a pulse thats too long (20ms) - if ( level_count > 3000 ) { - break; - } + gpio_put(pin_GPIO15.number, true); +// clear interrupt + irq_clear(self->pio_interrupt); + hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); + self->state_machine.pio->irq = 1u << self->state_machine.state_machine; +// check for a pulse thats too long (2000 us) and reset + if ( level_count > 2000 ) { + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); + pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); + pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); + pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); + irq_set_enabled(self->pio_interrupt, true); } - pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); - pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); - pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); - pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); - irq_set_enabled(self->pio_interrupt, true); } void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, uint16_t trigger_duration) { + // exec a wait for the selected pin to change state + if (self->idle_state == true ) { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); + } else { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020); + } // Send the trigger pulse. if (trigger_duration > 0) { gpio_set_function(self->pin ,GPIO_FUNC_SIO); @@ -186,8 +194,6 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, common_hal_mcu_delay_us(100); gpio_set_function(self->pin, GPIO_FUNC_PIO0); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); - // exec a wait for the selected pin to go high - pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); } void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) { @@ -202,9 +208,11 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) { uint16_t value = self->buffer[self->start]; self->start = (self->start + 1) % self->maxlen; self->len--; + // if we are empty reset buffer pointer and counters if (self->len == 0 ) { - // reset buffer pointer self->start = 0; + buf_index = 0; + level_count = 0; } return value; } diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h index 6be13ebb1c..e99e1ff822 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017-2021 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2021 Dave Putz 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 From b7f03f9487608c413d30aaa43446afad0df3ad51 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Thu, 4 Mar 2021 13:52:40 -0600 Subject: [PATCH 12/48] Update PulseOut.h --- ports/raspberrypi/common-hal/pulseio/PulseOut.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.h b/ports/raspberrypi/common-hal/pulseio/PulseOut.h index 10c1a1756e..4f1bb9fa7a 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017-2021 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2021 Dave Putz 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 From c5c297d2c06dbeb1754ea6aeb595c13ef41ad3eb Mon Sep 17 00:00:00 2001 From: DavePutz Date: Thu, 4 Mar 2021 13:53:19 -0600 Subject: [PATCH 13/48] Update PulseOut.c --- ports/raspberrypi/common-hal/pulseio/PulseOut.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.c b/ports/raspberrypi/common-hal/pulseio/PulseOut.c index f3f7121434..e284cd46a2 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * SPDX-FileCopyrightText: Copyright (c) 2016 Damien P. George + * Copyright (c) 2021 Dave Putz 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 From 3b76299f396d548dfe1eeacefc9a284edbc24e42 Mon Sep 17 00:00:00 2001 From: nitz Date: Sun, 7 Mar 2021 01:06:50 -0500 Subject: [PATCH 14/48] Add new nRF port for SF MicroMod nRF52840. --- .../sparkfun_nrf52840_micromod/README.md | 70 +++++++++++ .../boards/sparkfun_nrf52840_micromod/board.c | 38 ++++++ .../mpconfigboard.h | 60 ++++++++++ .../mpconfigboard.mk | 11 ++ .../boards/sparkfun_nrf52840_micromod/pins.c | 112 ++++++++++++++++++ 5 files changed, 291 insertions(+) create mode 100644 ports/nrf/boards/sparkfun_nrf52840_micromod/README.md create mode 100644 ports/nrf/boards/sparkfun_nrf52840_micromod/board.c create mode 100644 ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h create mode 100644 ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk create mode 100644 ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/README.md b/ports/nrf/boards/sparkfun_nrf52840_micromod/README.md new file mode 100644 index 0000000000..094102c277 --- /dev/null +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/README.md @@ -0,0 +1,70 @@ +# SparkFun MicroMod nRF52840 Processor + +Featuring the nRF52840 SoC from Nordic Semiconductor, the [SparkFun MicroMod nRF52840 Processor](https://www.sparkfun.com/products/16984) offers a powerful combination of ARM Cortex-M4 CPU and 2.4 GHz Bluetooth transceiver in the MicroMod form-factor with the M.2 MicroMod connector to allow you to plug in a compatible MicroMod Carrier Board with any number of peripherals. + +The MicroMod nRF52840 Processor features the same Raytac MDBT50Q-P1M found on our [Pro nRF52840 Mini](https://www.sparkfun.com/products/15025). This module includes an integrated trace antenna, fits the IC to an FCC-approved footprint along with including decoupling and timing mechanisms that would need to be designed into a circuit using the bare nRF52840 IC. The Bluetooth transceiver included on the nRF52840 boasts a BT 5.1 stack and supports Bluetooth 5, Bluetooth mesh, IEEE 802.15.4 (Zigbee & Thread) and 2.4Ghz RF wireless protocols (including Nordic's proprietary RF protocol) allowing you to pick which option works best for your application. + +We've also routed two I2C buses, 2 SPI buses, eleven GPIO, dedicated digital, analog, PWM & PDM pins along with multiple serial UARTS to cover nearly all of your peripheral needs. + +## CircuitPython Pin Defs + +CircuitPython pin definitions, while simialr to other boards represent a slight departure from just the typical `A` and `D` pin definitions. The majority of general pins are labled as `G` (or alternatively, `BUS`,) as the MicroMod system they build on uses those names to specify pins that may not be specficially analog or digital. + +This can be somewhat confusing, especially around the analog pins. Here's a quick pin-map. This pin map will use the label either on the [SparkFun MicroMod ATP Carrier Board](https://www.sparkfun.com/products/16885), or the pin name on the [graphical datasheet](https://cdn.sparkfun.com/assets/learn_tutorials/1/4/0/1/MicroMod_nRF52840_v1.0_Graphical_Datasheet.pdf). Some of the aditional aliases are just names to make naming consistent (e.g.: RTS/CTS), but they also can refer to additional functionality a pin may have (e.g.: NFC pins) + +MicroMod Pin # | ATP Pin Label | Pin Definition | Additional Definitons | Pin/Port Reference | Notes +:--------------|:--------------|:--------------|:-----------------------|:-------------------|:------ +8 | G11 | | | (Not Connected) | +10 | D0 | D0 | | P0_27 | +11 | BOOT | BOOT | BUTTON1 | P0_07 | +12 | SDA | SDA | | P0_08 | +13 | RTS1 | RTS | RTS1 | P1_02 | +14 | SCL | SCL | | P0_11 | +15 | CTS1 | CTS | CTS1 | P1_09 | +16 | /I2C INT | I2C_INT | P0_15 | +17 | TX | TX | TX1 | P1_03 | +18 | D1 | D1 | CAM_TRIG | P1_08 | +19 | RX | RX | RX1 | P1_10 | +20 | RX2 | RX2 | | P1_05 | +22 | TX2 | TX2 | | P1_07 | +32 | PWM0 | PWM0 | P0_06 | +34 | A0 | A0 | ADC0 | P0_04 | Attached to AIN2 +38 | A1 | A1 | ADC1 | P0_05 | Attached to AIN3 +40 | G0 | G0 | BUS0 | P0_29 | Attached to AIN5 +42 | G1 | G1 | BUS1 | P0_03 | Attached to AIN1 +44 | G2 | G2 | BUS2 | P1_13 | +46 | G3 | G3 | BUS3 | P1_12 | +47 | PWM1 | PWM1 | P0_16 | +48 | G4 | G4 | BUS4 | P1_11 | +49 | BATT_VIN | BATT_VIN3 | | P0_30 | Attached to AIN6, will be battery voltage / 3. | +50 | PDM_CLK | PDM_CLK | | P0_25 | +51 | SDA1 | SDA1 | | P1_01 | +52 | PDM_DATA | PDM_DATA | | P0_26 | +53 | SCL1 | SCL1 | | P0_24 | +55 | /CS | CS | | P0_20 | +57 | SCK | SCK | | P0_28 | Attached to AIN4 +59 | COPI | COPI | MOSI | P0_31 | Attached to AIN7 +61 | CIPO | CIPO | MISO | P0_02 | +63 | G10 | G10 | NFC2, ADC_DP, CAM_VSYNC | P0_10 | Attached to NFC2 +65 | G9 | G9 | NFC1, ADC_DM, CAM_HSYNC | P0_09 | Attached to NFC1 +67 | G8 | G8 | | P1_14 | +69 | G7 | G7 | BUS7 | P1_04 | +71 | G6 | G6 | BUS6 | P1_06 | +73 | G5 | G5 | BUS5 | P0_15 | + +## Peripheral Naming + +CircuitPython attempts to stay in line with the naming of the serial peripheral naming in the MicroMod system. The bare UART pins are also named 1. The UART 2 pins are named 2. However, the I2C names on MicroMod are and 1. Perhaps this will change in the future, but as of [Interface v1](https://cdn.sparkfun.com/assets/learn_tutorials/1/2/0/6/SparkFun_MicroMod_Interface_v1.0_-_Pin_Descriptions.pdf), it may lead to some confusion. + + +## Bootloader Notes + +The MicroMod nRF52840 Processor needs to have the [Adafruit nRF52 UF2 bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader/pull/194) flashed on it. [[TODO: LINK TO BUILD]] + +## Hardware Reference + +The MicroMod nRF52840 Processor hardware layout is open source: + +* [Schematic](https://cdn.sparkfun.com/assets/f/0/9/9/e/MicroMod_Processor_Board-nRF52840.pdf) +* [Eagle Files](https://cdn.sparkfun.com/assets/3/0/5/d/a/MicroMod_Processor_Board-nRF52840.zip) +* [Hookup Guide](https://learn.sparkfun.com/tutorials/micromod-nrf52840-processor-hookup-guide) diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/board.c b/ports/nrf/boards/sparkfun_nrf52840_micromod/board.c new file mode 100644 index 0000000000..7817933281 --- /dev/null +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 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 "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h new file mode 100644 index 0000000000..91997710a2 --- /dev/null +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h @@ -0,0 +1,60 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2021 Chris Marc Dailey + * + * 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 "nrfx/hal/nrf_gpio.h" + +#define MICROPY_HW_BOARD_NAME "SparkFun MicroMod nRF52840" +#define MICROPY_HW_MCU_NAME "nRF52840" + +#define DEFAULT_I2C_BUS_SCL (&pin_P0_11) +#define DEFAULT_I2C_BUS_SDA (&pin_P0_08) + +#define DEFAULT_SPI_BUS_SCK (&pin_P0_28) +#define DEFAULT_SPI_BUS_MOSI (&pin_P0_31) +#define DEFAULT_SPI_BUS_MISO (&pin_P0_02) + +#define DEFAULT_UART_BUS_RX (&pin_P1_10) +#define DEFAULT_UART_BUS_TX (&pin_P1_03) + +#define BOARD_HAS_32KHZ_XTAL (1) +#define BOARD_HAS_CRYSTAL (1) + +#if QSPI_FLASH_FILESYSTEM +#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 14) // Labeled 'SPI_COPI1/SDIO_CMD' in schematic. +#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) // Labeled 'SPI_CIPO1/SDIO_DATA0' in schematic. +#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 23) // Labeled 'SPI_DATA2' in schematic. +#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(1, 0) // Labeled 'SPI_CS1/SDIO_DATA3' in schematic. +#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19) // Labeled 'SPI_SCK1/SDIO_CLK' in schematic. +#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 12) // Labeled 'FLASH_CS' in schematic. +#endif // QSPI_FLASH_FILESYSTEM + +#if SPI_FLASH_FILESYSTEM +#define SPI_FLASH_MOSI_PIN (&pin_P0_14) +#define SPI_FLASH_MISO_PIN (&pin_P0_21) +#define SPI_FLASH_SCK_PIN (&pin_P0_19) +#define SPI_FLASH_CS_PIN (&pin_P0_12) +#endif // SPI_FLASH_FILESYSTEM diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk new file mode 100644 index 0000000000..e6070a0563 --- /dev/null +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk @@ -0,0 +1,11 @@ +USB_VID = 0x1B4F +USB_PID = 0xabcd +$(warning SparkFun nRF52840 MicroMod needss USB PID!) +USB_PRODUCT = "SFE_nRF52840_MicroMod" +USB_MANUFACTURER = "SparkFun Electronics" + +MCU_CHIP = nrf52840 + +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICE_COUNT = 1 +EXTERNAL_FLASH_DEVICES = "W25Q128JV_PM" diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c new file mode 100644 index 0000000000..a8adeacf7a --- /dev/null +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c @@ -0,0 +1,112 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + // D pins (D0-D1) + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P0_27) }, // 0.27 - D0 + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P1_08) }, // 1.08 - D1 | CAM_TRIG + { MP_ROM_QSTR(MP_QSTR_CAM_TRIG), MP_ROM_PTR(&pin_P1_08) }, // CAM_TRIG alias + + // A pins (A0-A1) + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) }, // 0.04 - A0 | ADC0 (AIN2) + { MP_ROM_QSTR(MP_QSTR_ADC0), MP_ROM_PTR(&pin_P0_04) }, // ADC0 alias + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05) }, // 0.05 - A1 | ADC1 (AIN3) + { MP_ROM_QSTR(MP_QSTR_ADC1), MP_ROM_PTR(&pin_P0_05) }, // ADC1 alias + + // G pins (G0-G11, G11 NC) + { MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_P0_29) }, // 0.29 - G0 | GPIO0 | BUS0 (AIN5) + { MP_ROM_QSTR(MP_QSTR_BUS0), MP_ROM_PTR(&pin_P0_29) }, // BUS0 alias + { MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_P0_03) }, // 0.03 - G1 | GPIO1 | BUS1 (AIN1) + { MP_ROM_QSTR(MP_QSTR_BUS1), MP_ROM_PTR(&pin_P0_03) }, // BUS1 alias + { MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_P1_13) }, // 1.13 - G2 | GPIO2 | BUS2 + { MP_ROM_QSTR(MP_QSTR_BUS2), MP_ROM_PTR(&pin_P1_13) }, // BUS2 alias + { MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_P1_12) }, // 1.12 - G3 | GPIO3 | BUS3 + { MP_ROM_QSTR(MP_QSTR_BUS3), MP_ROM_PTR(&pin_P1_12) }, // BUS3 alias + { MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_P1_11) }, // 1.11 - G4 | GPIO4 | BUS4 + { MP_ROM_QSTR(MP_QSTR_BUS4), MP_ROM_PTR(&pin_P1_11) }, // BUS4 alias + { MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_P0_17) }, // 0.17 - G5 | GPIO5 | BUS5 + { MP_ROM_QSTR(MP_QSTR_BUS5), MP_ROM_PTR(&pin_P0_17) }, // BUS5 alias + { MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_P1_06) }, // 1.06 - G6 | GPIO6 | BUS6 + { MP_ROM_QSTR(MP_QSTR_BUS6), MP_ROM_PTR(&pin_P1_06) }, // BUS6 alias + { MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_P1_04) }, // 1.04 - G7 | GPIO7 | BUS7 + { MP_ROM_QSTR(MP_QSTR_BUS7), MP_ROM_PTR(&pin_P1_04) }, // BUS7 alias + { MP_ROM_QSTR(MP_QSTR_G8), MP_ROM_PTR(&pin_P1_14) }, // 1.14 - G8 | GPIO8 + { MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_P0_09) }, // 0.09 - G9 | GPIO9/NFC1 | ADC_D- | CAM_HSYNC (NFC1) + { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, // NFC1 alias + { MP_ROM_QSTR(MP_QSTR_ADC_DM), MP_ROM_PTR(&pin_P0_09) }, // ADC_DM alias + { MP_ROM_QSTR(MP_QSTR_CAM_HSYNC), MP_ROM_PTR(&pin_P0_09) }, // CAM_HSYNC alias + { MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_P0_10) }, // 0.10 - G10 | GPIO10/NFC2 | ADC_D+ | CAM_VSYNC (NFC2) + { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, // NFC2 alias + { MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_P0_10) }, // ADC_DP alias + { MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_P0_10) }, // CAM_VSYNC alias + // NC - G11 + + // PWM pins (PWM0-PWM1) + { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_P0_06) }, // 0.06 - PWM0 + { MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_P0_16) }, // 0.16 - PWM1 + + // PDM + { MP_ROM_QSTR(MP_QSTR_PDM_CLK), MP_ROM_PTR(&pin_P0_25) }, // 0.25 - PDM_CLK | AUD_BCLK + { MP_ROM_QSTR(MP_QSTR_PDM_DATA), MP_ROM_PTR(&pin_P0_26) }, // 0.26 - PDM_DATA | AUD_LRCLK + + // Battery Voltage Monitor + { MP_ROM_QSTR(MP_QSTR_BATT_VIN3), MP_ROM_PTR(&pin_P0_30) }, // 0.30 - BATT_VIN/3 (AIN6) + + // I2C + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_08) }, // 0.08 - SDA + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11) }, // 0.11 - SCL (TRACEDATA2) + + { MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_P0_15) }, // 0.15 - I2C_INT + + { MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_P1_01) }, // 1.01 - SDA1 + { MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_P0_24) }, // 0.24 - SCL1 + + // SPI + { MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_P0_02) }, // 0.02 - CIPO | SPI_CIPO + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_02) }, // MISO alias + { MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_P0_31) }, // 0.31 - COPI | SPI_COPI (AIN7) + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_31) }, // MOSI alias + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_28) }, // 0.28 - SCK | SPI_SCK (AIN4) + { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_P0_20) }, // 0.20 - /CS | SPI_/CS + + // Flash SPI + { MP_ROM_QSTR(MP_QSTR_IOSCK), MP_ROM_PTR(&pin_P0_19) }, // 0.00 - IOSCK | Flash Serial Clock + { MP_ROM_QSTR(MP_QSTR_IOCSN), MP_ROM_PTR(&pin_P0_12) }, // 0.00 - IOCSN | Flash /Chip Select + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_P0_14) }, // 0.00 - IO0 | Flash Data 0 + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_P0_21) }, // 0.00 - IO1 | Flash Data 1 + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_P0_23) }, // 0.00 - IO2 | Flash Data 2 + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_P1_00) }, // 0.00 - IO3 | Flash Data 3 + + // Reset Pin + { MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&pin_P1_14) }, // 0.18 - /RESET (NRESET) + + // LED + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_13) }, // 0.13 - LED_BUILTIN | STAT | Blue LED + + // Button + { MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_07) }, // 0.07 - /BOOT [Active Low] (TRACECLK) - Is button on carriers. + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_P0_07) }, // BOOT alias + + // UART + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P1_10) }, // 1.10 - UART RX | RX1 + { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_P1_10) }, // RX1 alias + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P1_03) }, // 1.03 - UART TX | TX1 + { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_P1_03) }, // TX1 alias + { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_PTR(&pin_P1_09) }, // 1.09 - UART CTS | CTS1 (TRACEDATA3) + { MP_ROM_QSTR(MP_QSTR_CTS1), MP_ROM_PTR(&pin_P1_09) }, // CTS1 alias + { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_PTR(&pin_P1_02) }, // 1.02 - UART RTS | RTS1 + { MP_ROM_QSTR(MP_QSTR_RTS1), MP_ROM_PTR(&pin_P1_02) }, // RTS1 alias + + { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_P1_05) }, // 1.05 - UART RX | RX2 + { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_P1_07) }, // 1.07 - UART TX | TX2 + + // Crystal + { MP_ROM_QSTR(MP_QSTR_XL1), MP_ROM_PTR(&pin_P0_00) }, // 0.00 - XL1 | 32.768kHz Crystal Pin 1 + { MP_ROM_QSTR(MP_QSTR_XL2), MP_ROM_PTR(&pin_P0_01) }, // 0.01 - XL2 | 32.768kHz Crystal Pin 2 + + // Board Objects + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; + +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 8e8368d59452b1d54f9d0a87feb49896ada24b99 Mon Sep 17 00:00:00 2001 From: nitz Date: Sun, 7 Mar 2021 01:25:31 -0500 Subject: [PATCH 15/48] Add sparkfun_nrf52840_micromod to `build.yml` --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 32e3bc900c..34f4c43cb4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -314,6 +314,7 @@ jobs: - "simmel" - "snekboard" - "sparkfun_lumidrive" + - "sparkfun_nrf52840_micromod" - "sparkfun_nrf52840_mini" - "sparkfun_qwiic_micro_no_flash" - "sparkfun_qwiic_micro_with_flash" From 26eb429cc69ec8697d733d27e7125190d068d20f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 7 Mar 2021 18:23:14 -0500 Subject: [PATCH 16/48] restore install/delete for i2c driver --- ports/esp32s2/common-hal/busio/I2C.c | 39 +++++++++++------------- ports/esp32s2/common-hal/wifi/__init__.c | 1 + 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index 8372eb8c30..c1a0f75ac4 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -53,7 +53,6 @@ void i2c_reset(void) { } } } -static bool i2c_inited[I2C_NUM_MAX]; void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { @@ -90,10 +89,9 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, #endif - if (xSemaphoreCreateBinaryStatic(&self->semaphore) != &self->semaphore) { + if (xSemaphoreCreateMutexStatic(&self->semaphore) != &self->semaphore) { mp_raise_RuntimeError(translate("Unable to create lock")); } - xSemaphoreGive(&self->semaphore); self->sda_pin = sda; self->scl_pin = scl; self->i2c_num = I2C_NUM_MAX; @@ -106,34 +104,29 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, mp_raise_ValueError(translate("All I2C peripherals are in use")); } i2c_status[self->i2c_num] = STATUS_IN_USE; + + // Delete any previous driver. + i2c_driver_delete(self->i2c_num); + i2c_config_t i2c_conf = { .mode = I2C_MODE_MASTER, .sda_io_num = self->sda_pin->number, .scl_io_num = self->scl_pin->number, - .sda_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C sda signal*/ - .scl_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C scl signal*/ .master = { .clk_speed = frequency, } }; - esp_err_t result = i2c_param_config(self->i2c_num, &i2c_conf); - if (result != ESP_OK) { - mp_raise_ValueError(translate("Invalid pins")); + if (i2c_param_config(self->i2c_num, &i2c_conf) != ESP_OK) { + mp_raise_ValueError(translate("Invalid frequency")); } - - if (!i2c_inited[self->i2c_num]) { - result = i2c_driver_install(self->i2c_num, - I2C_MODE_MASTER, - 0, - 0, - 0); - if (result != ESP_OK) { - mp_raise_OSError(MP_EIO); - } - i2c_inited[self->i2c_num] = true; - + if (i2c_driver_install(self->i2c_num, + I2C_MODE_MASTER, + 0, + 0, + 0) != ESP_OK) { + mp_raise_OSError(MP_EIO); } claim_pin(sda); @@ -149,12 +142,14 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { return; } - i2c_status[self->i2c_num] = STATUS_FREE; + i2c_driver_delete(self->i2c_num); - common_hal_reset_pin(self->sda_pin); common_hal_reset_pin(self->scl_pin); + common_hal_reset_pin(self->sda_pin); self->sda_pin = NULL; self->scl_pin = NULL; + + i2c_status[self->i2c_num] = STATUS_FREE; } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index b8e8f731bd..a3927b7c3e 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -109,6 +109,7 @@ void common_hal_wifi_init(void) { wifi_radio_obj_t* self = &common_hal_wifi_radio_obj; self->netif = esp_netif_create_default_wifi_sta(); + self->started = false; // Even though we just called esp_netif_create_default_wifi_sta, // station mode isn't actually ready for use until esp_wifi_set_mode() From 88650bc4d04e8fd7da7760aca1530a4f5eec10d7 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Mon, 8 Mar 2021 22:48:57 -0600 Subject: [PATCH 17/48] Removed leftover debug code --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 7053b55248..79d8e7ee5b 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -1,4 +1,4 @@ -/* +b/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) From 3db0fec267902cddb4d88aaca55e7ae7f59dc9a8 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 8 Mar 2021 23:20:57 -0600 Subject: [PATCH 18/48] Added check for maxlen --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 7053b55248..b9052f3c60 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -152,20 +152,19 @@ void common_hal_pulseio_pulsein_interrupt() { last_level = level; level_count = 1; // ignore pulses that are too long and too short - if (result < 2000 && result > 10) { + if (result < 4000 && result > 10) { self->buffer[buf_index] = result; buf_index++; self->len++; } } } - gpio_put(pin_GPIO15.number, true); // clear interrupt irq_clear(self->pio_interrupt); hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); self->state_machine.pio->irq = 1u << self->state_machine.state_machine; -// check for a pulse thats too long (2000 us) and reset - if ( level_count > 2000 ) { +// check for a pulse thats too long (2000 us) or maxlen reached, and reset + if (( level_count > 4000 ) || (buf_index >= self->maxlen)) { pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); From 576da73a17bd6847e93efcf4260a787813ccdf45 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 8 Mar 2021 23:23:51 -0600 Subject: [PATCH 19/48] Added check for maxlen --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index fb05876b95..6377fa7a9c 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -1,4 +1,4 @@ -b/* +/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) @@ -163,7 +163,7 @@ void common_hal_pulseio_pulsein_interrupt() { irq_clear(self->pio_interrupt); hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); self->state_machine.pio->irq = 1u << self->state_machine.state_machine; -// check for a pulse thats too long (2000 us) or maxlen reached, and reset +// check for a pulse thats too long (4000 us) or maxlen reached, and reset if (( level_count > 4000 ) || (buf_index >= self->maxlen)) { pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); From f0e3274a33f8fa7dd109925d185c1c1dc758f63e Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 9 Mar 2021 11:13:09 -0600 Subject: [PATCH 20/48] Update to agree with modified StateMachine.h --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 6377fa7a9c..1b433d79c3 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -82,6 +82,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, NULL, 0, NULL, 0, pin, 1, + 0,0, NULL, 0, NULL, 0, 1, 0, From a61db7f12e4278e39ae7096dd975a4285127416c Mon Sep 17 00:00:00 2001 From: Chris Dailey Date: Tue, 9 Mar 2021 12:54:52 -0500 Subject: [PATCH 21/48] Updated SparkFun MicroMod USB PID As per the PID provide by TheHoff, [here](https://forum.sparkfun.com/viewtopic.php?p=223812#p223812) --- .../mpconfigboard.mk | 73 ++++++++++++++++--- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk index e6070a0563..1a0d23c266 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk @@ -1,11 +1,66 @@ -USB_VID = 0x1B4F -USB_PID = 0xabcd -$(warning SparkFun nRF52840 MicroMod needss USB PID!) -USB_PRODUCT = "SFE_nRF52840_MicroMod" -USB_MANUFACTURER = "SparkFun Electronics" +/* + * The MIT License (MIT) + * + * Copyright (c) 2018 Ha Thach for Adafruit Industries + * Copyright (c) 2021 Chris Marc Dailey + * + * 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. + */ -MCU_CHIP = nrf52840 +#ifndef _SPARKFUN_NRF52840_MICROMOD_H_ +#define _SPARKFUN_NRF52840_MICROMOD_H_ -QSPI_FLASH_FILESYSTEM = 1 -EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = "W25Q128JV_PM" +#define _PINNUM(port, pin) ((port)*32 + (pin)) + +/*------------------------------------------------------------------*/ +/* LED + *------------------------------------------------------------------*/ +#define LEDS_NUMBER 1 +#define LED_PRIMARY_PIN _PINNUM(0, 13) +#define LED_STATE_ON 1 + +/*------------------------------------------------------------------*/ +/* BUTTON + *------------------------------------------------------------------*/ +#define BUTTONS_NUMBER 2 +#define BUTTON_1 _PINNUM(0, 7) +#define BUTTON_2 _PINNUM(0, 10) +#define BUTTON_PULL NRF_GPIO_PIN_PULLUP + +//--------------------------------------------------------------------+ +// BLE OTA +//--------------------------------------------------------------------+ +#define BLEDIS_MANUFACTURER "SparkFun" +#define BLEDIS_MODEL "MicroMod nRF52840" + +//--------------------------------------------------------------------+ +// USB +//--------------------------------------------------------------------+ +#define USB_DESC_VID 0x1B4F +#define USB_DESC_UF2_PID 0x0022 +#define USB_DESC_CDC_ONLY_PID 0x0023 + +//------------- UF2 -------------// +#define UF2_PRODUCT_NAME "SparkFun MicroMod nRF52840" +#define UF2_VOLUME_LABEL "SFMM852BOOT" +#define UF2_BOARD_ID "micromod-nRF52840" + +#define UF2_INDEX_URL "https://www.sparkfun.com/products/16984" + +#endif /* _SPARKFUN_NRF52840_MICROMOD_H_ */ From 1ae858126acb02c461de8f30e99b2961995b305a Mon Sep 17 00:00:00 2001 From: nitz Date: Tue, 9 Mar 2021 17:29:10 -0500 Subject: [PATCH 22/48] Fix the mpconfigboard.mk that was screwy? --- .../mpconfigboard.mk | 72 +++---------------- 1 file changed, 8 insertions(+), 64 deletions(-) diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk index 1a0d23c266..4c4bcd0896 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.mk @@ -1,66 +1,10 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 Ha Thach for Adafruit Industries - * Copyright (c) 2021 Chris Marc Dailey - * - * 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. - */ +USB_VID = 0x1B4F +USB_PID = 0x0021 +USB_PRODUCT = "SFE_nRF52840_MicroMod" +USB_MANUFACTURER = "SparkFun Electronics" -#ifndef _SPARKFUN_NRF52840_MICROMOD_H_ -#define _SPARKFUN_NRF52840_MICROMOD_H_ +MCU_CHIP = nrf52840 -#define _PINNUM(port, pin) ((port)*32 + (pin)) - -/*------------------------------------------------------------------*/ -/* LED - *------------------------------------------------------------------*/ -#define LEDS_NUMBER 1 -#define LED_PRIMARY_PIN _PINNUM(0, 13) -#define LED_STATE_ON 1 - -/*------------------------------------------------------------------*/ -/* BUTTON - *------------------------------------------------------------------*/ -#define BUTTONS_NUMBER 2 -#define BUTTON_1 _PINNUM(0, 7) -#define BUTTON_2 _PINNUM(0, 10) -#define BUTTON_PULL NRF_GPIO_PIN_PULLUP - -//--------------------------------------------------------------------+ -// BLE OTA -//--------------------------------------------------------------------+ -#define BLEDIS_MANUFACTURER "SparkFun" -#define BLEDIS_MODEL "MicroMod nRF52840" - -//--------------------------------------------------------------------+ -// USB -//--------------------------------------------------------------------+ -#define USB_DESC_VID 0x1B4F -#define USB_DESC_UF2_PID 0x0022 -#define USB_DESC_CDC_ONLY_PID 0x0023 - -//------------- UF2 -------------// -#define UF2_PRODUCT_NAME "SparkFun MicroMod nRF52840" -#define UF2_VOLUME_LABEL "SFMM852BOOT" -#define UF2_BOARD_ID "micromod-nRF52840" - -#define UF2_INDEX_URL "https://www.sparkfun.com/products/16984" - -#endif /* _SPARKFUN_NRF52840_MICROMOD_H_ */ +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICE_COUNT = 1 +EXTERNAL_FLASH_DEVICES = "W25Q128JV_PM" From 0c58cc47726bb8ca0b43af81263382a2a6fffef4 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 9 Mar 2021 16:37:29 -0600 Subject: [PATCH 23/48] Moved pin wait to an initial exec --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 1b433d79c3..0013aece49 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -46,13 +46,12 @@ volatile uint16_t result = 0; volatile uint16_t buf_index = 0; uint16_t pulsein_program[] = { - 0x2020, // 0: wait 0 pin, 0 - 0xe03f, // 1: set x, 31 - 0x4001, // 2: in pins, 1 - 0x0042, // 3: jmp x--, 2 - 0x8060, // 4: push iffull block - 0xc020, // 5: irq wait 0 - 0x0001, // 6: jmp 1 + 0xe03f, // 0: set x, 31 + 0x4001, // 1: in pins, 1 + 0x0041, // 2: jmp x--, 2 + 0x8060, // 3: push iffull block + 0xc020, // 4: irq wait 0 + 0x0000, // 5: jmp 1 }; void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, @@ -68,10 +67,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, self->start = 0; self->len = 0; save_self = self; - // change initial state machine wait if idle_state is false - if (idle_state == false) { - pulsein_program[0] = 0x20a0; - } // Set everything up. rp2pio_statemachine_obj_t state_machine; @@ -91,6 +86,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, false, true, 32, true, // RX auto-push every 32 bits false); // claim pins + pio_sm_set_enabled(state_machine.pio,state_machine.state_machine, false); self->state_machine.pio = state_machine.pio; self->state_machine.state_machine = state_machine.state_machine; self->state_machine.sm_config = state_machine.sm_config; @@ -107,15 +103,20 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, buf_index = 0; pio_sm_set_in_pins(state_machine.pio,state_machine.state_machine,pin->number); - pio_sm_set_enabled(state_machine.pio,state_machine.state_machine, false); irq_set_exclusive_handler(self->pio_interrupt, common_hal_pulseio_pulsein_interrupt); hw_clear_bits(&state_machine.pio->inte0, 1u << state_machine.state_machine); hw_set_bits(&state_machine.pio->inte0, 1u << (state_machine.state_machine+8)); // exec a set pindirs to 0 for input pio_sm_exec(state_machine.pio,state_machine.state_machine,0xe080); - irq_set_enabled(self->pio_interrupt, true); + //exec the appropriate wait for pin + if (self->idle_state == true ) { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020); + } else { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); + } pio_sm_set_enabled(state_machine.pio, state_machine.state_machine, true); + irq_set_enabled(self->pio_interrupt, true); } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { @@ -177,9 +178,9 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, uint16_t trigger_duration) { // exec a wait for the selected pin to change state if (self->idle_state == true ) { - pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); - } else { pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020); + } else { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); } // Send the trigger pulse. if (trigger_duration > 0) { @@ -191,7 +192,7 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, } // Reconfigure the pin for PIO - common_hal_mcu_delay_us(100); + common_hal_mcu_delay_us(200); gpio_set_function(self->pin, GPIO_FUNC_PIO0); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); } From fe0655e121a1433d7e773672883b25fa78f6cb95 Mon Sep 17 00:00:00 2001 From: nitz Date: Tue, 9 Mar 2021 17:39:29 -0500 Subject: [PATCH 24/48] Update pins, remove unused defs from board config. --- .../mpconfigboard.h | 7 - .../boards/sparkfun_nrf52840_micromod/pins.c | 149 +++++++++--------- 2 files changed, 72 insertions(+), 84 deletions(-) diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h index 91997710a2..c53fc45d22 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/mpconfigboard.h @@ -51,10 +51,3 @@ #define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19) // Labeled 'SPI_SCK1/SDIO_CLK' in schematic. #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 12) // Labeled 'FLASH_CS' in schematic. #endif // QSPI_FLASH_FILESYSTEM - -#if SPI_FLASH_FILESYSTEM -#define SPI_FLASH_MOSI_PIN (&pin_P0_14) -#define SPI_FLASH_MISO_PIN (&pin_P0_21) -#define SPI_FLASH_SCK_PIN (&pin_P0_19) -#define SPI_FLASH_CS_PIN (&pin_P0_12) -#endif // SPI_FLASH_FILESYSTEM diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c index a8adeacf7a..bd457f14a9 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c @@ -2,111 +2,106 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { // D pins (D0-D1) - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P0_27) }, // 0.27 - D0 - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P1_08) }, // 1.08 - D1 | CAM_TRIG - { MP_ROM_QSTR(MP_QSTR_CAM_TRIG), MP_ROM_PTR(&pin_P1_08) }, // CAM_TRIG alias + {MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P0_27)}, // 0.27 - D0 + {MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P1_08)}, // 1.08 - D1 | CAM_TRIG + {MP_ROM_QSTR(MP_QSTR_CAM_TRIG), MP_ROM_PTR(&pin_P1_08)}, // CAM_TRIG alias // A pins (A0-A1) - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) }, // 0.04 - A0 | ADC0 (AIN2) - { MP_ROM_QSTR(MP_QSTR_ADC0), MP_ROM_PTR(&pin_P0_04) }, // ADC0 alias - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05) }, // 0.05 - A1 | ADC1 (AIN3) - { MP_ROM_QSTR(MP_QSTR_ADC1), MP_ROM_PTR(&pin_P0_05) }, // ADC1 alias + {MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04)}, // 0.04 - A0 | ADC0 (AIN2) + {MP_ROM_QSTR(MP_QSTR_ADC0), MP_ROM_PTR(&pin_P0_04)}, // ADC0 alias + {MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05)}, // 0.05 - A1 | ADC1 (AIN3) + {MP_ROM_QSTR(MP_QSTR_ADC1), MP_ROM_PTR(&pin_P0_05)}, // ADC1 alias // G pins (G0-G11, G11 NC) - { MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_P0_29) }, // 0.29 - G0 | GPIO0 | BUS0 (AIN5) - { MP_ROM_QSTR(MP_QSTR_BUS0), MP_ROM_PTR(&pin_P0_29) }, // BUS0 alias - { MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_P0_03) }, // 0.03 - G1 | GPIO1 | BUS1 (AIN1) - { MP_ROM_QSTR(MP_QSTR_BUS1), MP_ROM_PTR(&pin_P0_03) }, // BUS1 alias - { MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_P1_13) }, // 1.13 - G2 | GPIO2 | BUS2 - { MP_ROM_QSTR(MP_QSTR_BUS2), MP_ROM_PTR(&pin_P1_13) }, // BUS2 alias - { MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_P1_12) }, // 1.12 - G3 | GPIO3 | BUS3 - { MP_ROM_QSTR(MP_QSTR_BUS3), MP_ROM_PTR(&pin_P1_12) }, // BUS3 alias - { MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_P1_11) }, // 1.11 - G4 | GPIO4 | BUS4 - { MP_ROM_QSTR(MP_QSTR_BUS4), MP_ROM_PTR(&pin_P1_11) }, // BUS4 alias - { MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_P0_17) }, // 0.17 - G5 | GPIO5 | BUS5 - { MP_ROM_QSTR(MP_QSTR_BUS5), MP_ROM_PTR(&pin_P0_17) }, // BUS5 alias - { MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_P1_06) }, // 1.06 - G6 | GPIO6 | BUS6 - { MP_ROM_QSTR(MP_QSTR_BUS6), MP_ROM_PTR(&pin_P1_06) }, // BUS6 alias - { MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_P1_04) }, // 1.04 - G7 | GPIO7 | BUS7 - { MP_ROM_QSTR(MP_QSTR_BUS7), MP_ROM_PTR(&pin_P1_04) }, // BUS7 alias - { MP_ROM_QSTR(MP_QSTR_G8), MP_ROM_PTR(&pin_P1_14) }, // 1.14 - G8 | GPIO8 - { MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_P0_09) }, // 0.09 - G9 | GPIO9/NFC1 | ADC_D- | CAM_HSYNC (NFC1) - { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, // NFC1 alias - { MP_ROM_QSTR(MP_QSTR_ADC_DM), MP_ROM_PTR(&pin_P0_09) }, // ADC_DM alias - { MP_ROM_QSTR(MP_QSTR_CAM_HSYNC), MP_ROM_PTR(&pin_P0_09) }, // CAM_HSYNC alias - { MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_P0_10) }, // 0.10 - G10 | GPIO10/NFC2 | ADC_D+ | CAM_VSYNC (NFC2) - { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, // NFC2 alias - { MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_P0_10) }, // ADC_DP alias - { MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_P0_10) }, // CAM_VSYNC alias - // NC - G11 + {MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_P0_29)}, // 0.29 - G0 | GPIO0 | BUS0 (AIN5) + {MP_ROM_QSTR(MP_QSTR_BUS0), MP_ROM_PTR(&pin_P0_29)}, // BUS0 alias + {MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_P0_03)}, // 0.03 - G1 | GPIO1 | BUS1 (AIN1) + {MP_ROM_QSTR(MP_QSTR_BUS1), MP_ROM_PTR(&pin_P0_03)}, // BUS1 alias + {MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_P1_13)}, // 1.13 - G2 | GPIO2 | BUS2 + {MP_ROM_QSTR(MP_QSTR_BUS2), MP_ROM_PTR(&pin_P1_13)}, // BUS2 alias + {MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_P1_12)}, // 1.12 - G3 | GPIO3 | BUS3 + {MP_ROM_QSTR(MP_QSTR_BUS3), MP_ROM_PTR(&pin_P1_12)}, // BUS3 alias + {MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_P1_11)}, // 1.11 - G4 | GPIO4 | BUS4 + {MP_ROM_QSTR(MP_QSTR_BUS4), MP_ROM_PTR(&pin_P1_11)}, // BUS4 alias + {MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_P0_17)}, // 0.17 - G5 | GPIO5 | BUS5 + {MP_ROM_QSTR(MP_QSTR_BUS5), MP_ROM_PTR(&pin_P0_17)}, // BUS5 alias + {MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_P1_06)}, // 1.06 - G6 | GPIO6 | BUS6 + {MP_ROM_QSTR(MP_QSTR_BUS6), MP_ROM_PTR(&pin_P1_06)}, // BUS6 alias + {MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_P1_04)}, // 1.04 - G7 | GPIO7 | BUS7 + {MP_ROM_QSTR(MP_QSTR_BUS7), MP_ROM_PTR(&pin_P1_04)}, // BUS7 alias + {MP_ROM_QSTR(MP_QSTR_G8), MP_ROM_PTR(&pin_P1_14)}, // 1.14 - G8 | GPIO8 + {MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_P0_09)}, // 0.09 - G9 | GPIO9/NFC1 | ADC_D- | CAM_HSYNC (NFC1) + {MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09)}, // NFC1 alias + {MP_ROM_QSTR(MP_QSTR_ADC_DM), MP_ROM_PTR(&pin_P0_09)}, // ADC_DM alias + {MP_ROM_QSTR(MP_QSTR_CAM_HSYNC), MP_ROM_PTR(&pin_P0_09)}, // CAM_HSYNC alias + {MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_P0_10)}, // 0.10 - G10 | GPIO10/NFC2 | ADC_D+ | CAM_VSYNC (NFC2) + {MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10)}, // NFC2 alias + {MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_P0_10)}, // ADC_DP alias + {MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_P0_10)}, // CAM_VSYNC alias + // NC - G11 // PWM pins (PWM0-PWM1) - { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_P0_06) }, // 0.06 - PWM0 - { MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_P0_16) }, // 0.16 - PWM1 + {MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_P0_06)}, // 0.06 - PWM0 + {MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_P0_16)}, // 0.16 - PWM1 // PDM - { MP_ROM_QSTR(MP_QSTR_PDM_CLK), MP_ROM_PTR(&pin_P0_25) }, // 0.25 - PDM_CLK | AUD_BCLK - { MP_ROM_QSTR(MP_QSTR_PDM_DATA), MP_ROM_PTR(&pin_P0_26) }, // 0.26 - PDM_DATA | AUD_LRCLK + {MP_ROM_QSTR(MP_QSTR_PDM_CLK), MP_ROM_PTR(&pin_P0_25)}, // 0.25 - PDM_CLK | AUD_BCLK + {MP_ROM_QSTR(MP_QSTR_PDM_DATA), MP_ROM_PTR(&pin_P0_26)}, // 0.26 - PDM_DATA | AUD_LRCLK // Battery Voltage Monitor - { MP_ROM_QSTR(MP_QSTR_BATT_VIN3), MP_ROM_PTR(&pin_P0_30) }, // 0.30 - BATT_VIN/3 (AIN6) + {MP_ROM_QSTR(MP_QSTR_BATT_VIN3), MP_ROM_PTR(&pin_P0_30)}, // 0.30 - BATT_VIN/3 (AIN6) // I2C - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_08) }, // 0.08 - SDA - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11) }, // 0.11 - SCL (TRACEDATA2) + {MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_08)}, // 0.08 - SDA + {MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11)}, // 0.11 - SCL (TRACEDATA2) - { MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_P0_15) }, // 0.15 - I2C_INT + {MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_P0_15)}, // 0.15 - I2C_INT - { MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_P1_01) }, // 1.01 - SDA1 - { MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_P0_24) }, // 0.24 - SCL1 + {MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_P1_01)}, // 1.01 - SDA1 + {MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_P0_24)}, // 0.24 - SCL1 // SPI - { MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_P0_02) }, // 0.02 - CIPO | SPI_CIPO - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_02) }, // MISO alias - { MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_P0_31) }, // 0.31 - COPI | SPI_COPI (AIN7) - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_31) }, // MOSI alias - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_28) }, // 0.28 - SCK | SPI_SCK (AIN4) - { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_P0_20) }, // 0.20 - /CS | SPI_/CS + {MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_P0_02)}, // 0.02 - CIPO | SPI_CIPO + {MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_02)}, // MISO alias + {MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_P0_31)}, // 0.31 - COPI | SPI_COPI (AIN7) + {MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_31)}, // MOSI alias + {MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_28)}, // 0.28 - SCK | SPI_SCK (AIN4) + {MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_P0_20)}, // 0.20 - /CS | SPI_/CS - // Flash SPI - { MP_ROM_QSTR(MP_QSTR_IOSCK), MP_ROM_PTR(&pin_P0_19) }, // 0.00 - IOSCK | Flash Serial Clock - { MP_ROM_QSTR(MP_QSTR_IOCSN), MP_ROM_PTR(&pin_P0_12) }, // 0.00 - IOCSN | Flash /Chip Select - { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_P0_14) }, // 0.00 - IO0 | Flash Data 0 - { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_P0_21) }, // 0.00 - IO1 | Flash Data 1 - { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_P0_23) }, // 0.00 - IO2 | Flash Data 2 - { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_P1_00) }, // 0.00 - IO3 | Flash Data 3 + // QSPI, used by flash on this board, but is broken out on MicroMod connector. + {MP_ROM_QSTR(MP_QSTR_SPI_SCK1), MP_ROM_PTR(&pin_P0_19)}, // 0.00 - IOSCK | Flash Serial Clock + {MP_ROM_QSTR(MP_QSTR_SPI_COPI1), MP_ROM_PTR(&pin_P0_14)}, // 0.00 - IO0 | Flash Data 0 + {MP_ROM_QSTR(MP_QSTR_SPI_CIPO1), MP_ROM_PTR(&pin_P0_21)}, // 0.00 - IO1 | Flash Data 1 + {MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_P0_23)}, // 0.00 - IO2 | Flash Data 2 + {MP_ROM_QSTR(MP_QSTR_SPI_CS1), MP_ROM_PTR(&pin_P1_00)}, // 0.00 - IO3 | Flash Data 3 // Reset Pin - { MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&pin_P1_14) }, // 0.18 - /RESET (NRESET) + {MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&pin_P1_14)}, // 0.18 - /RESET (NRESET) // LED - { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_13) }, // 0.13 - LED_BUILTIN | STAT | Blue LED + {MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_13)}, // 0.13 - LED_BUILTIN | STAT | Blue LED // Button - { MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_07) }, // 0.07 - /BOOT [Active Low] (TRACECLK) - Is button on carriers. - { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_P0_07) }, // BOOT alias + {MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_07)}, // 0.07 - /BOOT [Active Low] (TRACECLK) - Is button on carriers. + {MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_P0_07)}, // BOOT alias // UART - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P1_10) }, // 1.10 - UART RX | RX1 - { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_P1_10) }, // RX1 alias - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P1_03) }, // 1.03 - UART TX | TX1 - { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_P1_03) }, // TX1 alias - { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_PTR(&pin_P1_09) }, // 1.09 - UART CTS | CTS1 (TRACEDATA3) - { MP_ROM_QSTR(MP_QSTR_CTS1), MP_ROM_PTR(&pin_P1_09) }, // CTS1 alias - { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_PTR(&pin_P1_02) }, // 1.02 - UART RTS | RTS1 - { MP_ROM_QSTR(MP_QSTR_RTS1), MP_ROM_PTR(&pin_P1_02) }, // RTS1 alias + {MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P1_10)}, // 1.10 - UART RX | RX1 + {MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_P1_10)}, // RX1 alias + {MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P1_03)}, // 1.03 - UART TX | TX1 + {MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_P1_03)}, // TX1 alias + {MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_PTR(&pin_P1_09)}, // 1.09 - UART CTS | CTS1 (TRACEDATA3) + {MP_ROM_QSTR(MP_QSTR_CTS1), MP_ROM_PTR(&pin_P1_09)}, // CTS1 alias + {MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_PTR(&pin_P1_02)}, // 1.02 - UART RTS | RTS1 + {MP_ROM_QSTR(MP_QSTR_RTS1), MP_ROM_PTR(&pin_P1_02)}, // RTS1 alias - { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_P1_05) }, // 1.05 - UART RX | RX2 - { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_P1_07) }, // 1.07 - UART TX | TX2 - - // Crystal - { MP_ROM_QSTR(MP_QSTR_XL1), MP_ROM_PTR(&pin_P0_00) }, // 0.00 - XL1 | 32.768kHz Crystal Pin 1 - { MP_ROM_QSTR(MP_QSTR_XL2), MP_ROM_PTR(&pin_P0_01) }, // 0.01 - XL2 | 32.768kHz Crystal Pin 2 + {MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_P1_05)}, // 1.05 - UART RX | RX2 + {MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_P1_07)}, // 1.07 - UART TX | TX2 // Board Objects - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + {MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj)}, + {MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj)}, + {MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj)}, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 5beb529f61d9da1d8cf446a12d47725d0e14459e Mon Sep 17 00:00:00 2001 From: nitz Date: Tue, 9 Mar 2021 17:39:29 -0500 Subject: [PATCH 25/48] Update pins, remove unused defs from board config. --- .../boards/sparkfun_nrf52840_micromod/pins.c | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c index bd457f14a9..389d5f6b97 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c @@ -2,106 +2,106 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { // D pins (D0-D1) - {MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P0_27)}, // 0.27 - D0 - {MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P1_08)}, // 1.08 - D1 | CAM_TRIG - {MP_ROM_QSTR(MP_QSTR_CAM_TRIG), MP_ROM_PTR(&pin_P1_08)}, // CAM_TRIG alias + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P0_27) }, // 0.27 - D0 + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P1_08) }, // 1.08 - D1 | CAM_TRIG + { MP_ROM_QSTR(MP_QSTR_CAM_TRIG), MP_ROM_PTR(&pin_P1_08) }, // CAM_TRIG alias // A pins (A0-A1) - {MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04)}, // 0.04 - A0 | ADC0 (AIN2) - {MP_ROM_QSTR(MP_QSTR_ADC0), MP_ROM_PTR(&pin_P0_04)}, // ADC0 alias - {MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05)}, // 0.05 - A1 | ADC1 (AIN3) - {MP_ROM_QSTR(MP_QSTR_ADC1), MP_ROM_PTR(&pin_P0_05)}, // ADC1 alias + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) }, // 0.04 - A0 | ADC0 (AIN2) + { MP_ROM_QSTR(MP_QSTR_ADC0), MP_ROM_PTR(&pin_P0_04) }, // ADC0 alias + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05) }, // 0.05 - A1 | ADC1 (AIN3) + { MP_ROM_QSTR(MP_QSTR_ADC1), MP_ROM_PTR(&pin_P0_05) }, // ADC1 alias // G pins (G0-G11, G11 NC) - {MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_P0_29)}, // 0.29 - G0 | GPIO0 | BUS0 (AIN5) - {MP_ROM_QSTR(MP_QSTR_BUS0), MP_ROM_PTR(&pin_P0_29)}, // BUS0 alias - {MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_P0_03)}, // 0.03 - G1 | GPIO1 | BUS1 (AIN1) - {MP_ROM_QSTR(MP_QSTR_BUS1), MP_ROM_PTR(&pin_P0_03)}, // BUS1 alias - {MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_P1_13)}, // 1.13 - G2 | GPIO2 | BUS2 - {MP_ROM_QSTR(MP_QSTR_BUS2), MP_ROM_PTR(&pin_P1_13)}, // BUS2 alias - {MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_P1_12)}, // 1.12 - G3 | GPIO3 | BUS3 - {MP_ROM_QSTR(MP_QSTR_BUS3), MP_ROM_PTR(&pin_P1_12)}, // BUS3 alias - {MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_P1_11)}, // 1.11 - G4 | GPIO4 | BUS4 - {MP_ROM_QSTR(MP_QSTR_BUS4), MP_ROM_PTR(&pin_P1_11)}, // BUS4 alias - {MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_P0_17)}, // 0.17 - G5 | GPIO5 | BUS5 - {MP_ROM_QSTR(MP_QSTR_BUS5), MP_ROM_PTR(&pin_P0_17)}, // BUS5 alias - {MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_P1_06)}, // 1.06 - G6 | GPIO6 | BUS6 - {MP_ROM_QSTR(MP_QSTR_BUS6), MP_ROM_PTR(&pin_P1_06)}, // BUS6 alias - {MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_P1_04)}, // 1.04 - G7 | GPIO7 | BUS7 - {MP_ROM_QSTR(MP_QSTR_BUS7), MP_ROM_PTR(&pin_P1_04)}, // BUS7 alias - {MP_ROM_QSTR(MP_QSTR_G8), MP_ROM_PTR(&pin_P1_14)}, // 1.14 - G8 | GPIO8 - {MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_P0_09)}, // 0.09 - G9 | GPIO9/NFC1 | ADC_D- | CAM_HSYNC (NFC1) - {MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09)}, // NFC1 alias - {MP_ROM_QSTR(MP_QSTR_ADC_DM), MP_ROM_PTR(&pin_P0_09)}, // ADC_DM alias - {MP_ROM_QSTR(MP_QSTR_CAM_HSYNC), MP_ROM_PTR(&pin_P0_09)}, // CAM_HSYNC alias - {MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_P0_10)}, // 0.10 - G10 | GPIO10/NFC2 | ADC_D+ | CAM_VSYNC (NFC2) - {MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10)}, // NFC2 alias - {MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_P0_10)}, // ADC_DP alias - {MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_P0_10)}, // CAM_VSYNC alias - // NC - G11 + { MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_P0_29) }, // 0.29 - G0 | GPIO0 | BUS0 (AIN5) + { MP_ROM_QSTR(MP_QSTR_BUS0), MP_ROM_PTR(&pin_P0_29) }, // BUS0 alias + { MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_P0_03) }, // 0.03 - G1 | GPIO1 | BUS1 (AIN1) + { MP_ROM_QSTR(MP_QSTR_BUS1), MP_ROM_PTR(&pin_P0_03) }, // BUS1 alias + { MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_P1_13) }, // 1.13 - G2 | GPIO2 | BUS2 + { MP_ROM_QSTR(MP_QSTR_BUS2), MP_ROM_PTR(&pin_P1_13) }, // BUS2 alias + { MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_P1_12) }, // 1.12 - G3 | GPIO3 | BUS3 + { MP_ROM_QSTR(MP_QSTR_BUS3), MP_ROM_PTR(&pin_P1_12) }, // BUS3 alias + { MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_P1_11) }, // 1.11 - G4 | GPIO4 | BUS4 + { MP_ROM_QSTR(MP_QSTR_BUS4), MP_ROM_PTR(&pin_P1_11) }, // BUS4 alias + { MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_P0_17) }, // 0.17 - G5 | GPIO5 | BUS5 + { MP_ROM_QSTR(MP_QSTR_BUS5), MP_ROM_PTR(&pin_P0_17) }, // BUS5 alias + { MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_P1_06) }, // 1.06 - G6 | GPIO6 | BUS6 + { MP_ROM_QSTR(MP_QSTR_BUS6), MP_ROM_PTR(&pin_P1_06) }, // BUS6 alias + { MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_P1_04) }, // 1.04 - G7 | GPIO7 | BUS7 + { MP_ROM_QSTR(MP_QSTR_BUS7), MP_ROM_PTR(&pin_P1_04) }, // BUS7 alias + { MP_ROM_QSTR(MP_QSTR_G8), MP_ROM_PTR(&pin_P1_14) }, // 1.14 - G8 | GPIO8 + { MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_P0_09) }, // 0.09 - G9 | GPIO9/NFC1 | ADC_D- | CAM_HSYNC (NFC1) + { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, // NFC1 alias + { MP_ROM_QSTR(MP_QSTR_ADC_DM), MP_ROM_PTR(&pin_P0_09) }, // ADC_DM alias + { MP_ROM_QSTR(MP_QSTR_CAM_HSYNC), MP_ROM_PTR(&pin_P0_09) }, // CAM_HSYNC alias + { MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_P0_10) }, // 0.10 - G10 | GPIO10/NFC2 | ADC_D+ | CAM_VSYNC (NFC2) + { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, // NFC2 alias + { MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_P0_10) }, // ADC_DP alias + { MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_P0_10) }, // CAM_VSYNC alias + // NC - G11 // PWM pins (PWM0-PWM1) - {MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_P0_06)}, // 0.06 - PWM0 - {MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_P0_16)}, // 0.16 - PWM1 + { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_P0_06) }, // 0.06 - PWM0 + { MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_P0_16) }, // 0.16 - PWM1 // PDM - {MP_ROM_QSTR(MP_QSTR_PDM_CLK), MP_ROM_PTR(&pin_P0_25)}, // 0.25 - PDM_CLK | AUD_BCLK - {MP_ROM_QSTR(MP_QSTR_PDM_DATA), MP_ROM_PTR(&pin_P0_26)}, // 0.26 - PDM_DATA | AUD_LRCLK + { MP_ROM_QSTR(MP_QSTR_PDM_CLK), MP_ROM_PTR(&pin_P0_25) }, // 0.25 - PDM_CLK | AUD_BCLK + { MP_ROM_QSTR(MP_QSTR_PDM_DATA), MP_ROM_PTR(&pin_P0_26) }, // 0.26 - PDM_DATA | AUD_LRCLK // Battery Voltage Monitor - {MP_ROM_QSTR(MP_QSTR_BATT_VIN3), MP_ROM_PTR(&pin_P0_30)}, // 0.30 - BATT_VIN/3 (AIN6) + { MP_ROM_QSTR(MP_QSTR_BATT_VIN3), MP_ROM_PTR(&pin_P0_30) }, // 0.30 - BATT_VIN/3 (AIN6) // I2C - {MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_08)}, // 0.08 - SDA - {MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11)}, // 0.11 - SCL (TRACEDATA2) + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_08) }, // 0.08 - SDA + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11) }, // 0.11 - SCL (TRACEDATA2) - {MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_P0_15)}, // 0.15 - I2C_INT + { MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_P0_15) }, // 0.15 - I2C_INT - {MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_P1_01)}, // 1.01 - SDA1 - {MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_P0_24)}, // 0.24 - SCL1 + { MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_P1_01) }, // 1.01 - SDA1 + { MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_P0_24) }, // 0.24 - SCL1 // SPI - {MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_P0_02)}, // 0.02 - CIPO | SPI_CIPO - {MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_02)}, // MISO alias - {MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_P0_31)}, // 0.31 - COPI | SPI_COPI (AIN7) - {MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_31)}, // MOSI alias - {MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_28)}, // 0.28 - SCK | SPI_SCK (AIN4) - {MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_P0_20)}, // 0.20 - /CS | SPI_/CS + { MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_P0_02) }, // 0.02 - CIPO | SPI_CIPO + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_02) }, // MISO alias + { MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_P0_31) }, // 0.31 - COPI | SPI_COPI (AIN7) + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_31) }, // MOSI alias + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_28) }, // 0.28 - SCK | SPI_SCK (AIN4) + { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_P0_20) }, // 0.20 - /CS | SPI_/CS // QSPI, used by flash on this board, but is broken out on MicroMod connector. - {MP_ROM_QSTR(MP_QSTR_SPI_SCK1), MP_ROM_PTR(&pin_P0_19)}, // 0.00 - IOSCK | Flash Serial Clock - {MP_ROM_QSTR(MP_QSTR_SPI_COPI1), MP_ROM_PTR(&pin_P0_14)}, // 0.00 - IO0 | Flash Data 0 - {MP_ROM_QSTR(MP_QSTR_SPI_CIPO1), MP_ROM_PTR(&pin_P0_21)}, // 0.00 - IO1 | Flash Data 1 - {MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_P0_23)}, // 0.00 - IO2 | Flash Data 2 - {MP_ROM_QSTR(MP_QSTR_SPI_CS1), MP_ROM_PTR(&pin_P1_00)}, // 0.00 - IO3 | Flash Data 3 + { MP_ROM_QSTR(MP_QSTR_SPI_SCK1), MP_ROM_PTR(&pin_P0_19) }, // 0.00 - IOSCK | Flash Serial Clock + { MP_ROM_QSTR(MP_QSTR_SPI_COPI1), MP_ROM_PTR(&pin_P0_14) }, // 0.00 - IO0 | Flash Data 0 + { MP_ROM_QSTR(MP_QSTR_SPI_CIPO1), MP_ROM_PTR(&pin_P0_21) }, // 0.00 - IO1 | Flash Data 1 + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_P0_23) },// 0.00 - IO2 | Flash Data 2 + { MP_ROM_QSTR(MP_QSTR_SPI_CS1), MP_ROM_PTR(&pin_P1_00) }, // 0.00 - IO3 | Flash Data 3 // Reset Pin - {MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&pin_P1_14)}, // 0.18 - /RESET (NRESET) + { MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&pin_P1_14) }, // 0.18 - /RESET (NRESET) // LED - {MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_13)}, // 0.13 - LED_BUILTIN | STAT | Blue LED + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_13) }, // 0.13 - LED_BUILTIN | STAT | Blue LED // Button - {MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_07)}, // 0.07 - /BOOT [Active Low] (TRACECLK) - Is button on carriers. - {MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_P0_07)}, // BOOT alias + { MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_07) }, // 0.07 - /BOOT [Active Low] (TRACECLK) - Is button on carriers. + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_P0_07) }, // BOOT alias // UART - {MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P1_10)}, // 1.10 - UART RX | RX1 - {MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_P1_10)}, // RX1 alias - {MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P1_03)}, // 1.03 - UART TX | TX1 - {MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_P1_03)}, // TX1 alias - {MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_PTR(&pin_P1_09)}, // 1.09 - UART CTS | CTS1 (TRACEDATA3) - {MP_ROM_QSTR(MP_QSTR_CTS1), MP_ROM_PTR(&pin_P1_09)}, // CTS1 alias - {MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_PTR(&pin_P1_02)}, // 1.02 - UART RTS | RTS1 - {MP_ROM_QSTR(MP_QSTR_RTS1), MP_ROM_PTR(&pin_P1_02)}, // RTS1 alias + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P1_10) }, // 1.10 - UART RX | RX1 + { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_P1_10) }, // RX1 alias + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P1_03) }, // 1.03 - UART TX | TX1 + { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_P1_03) }, // TX1 alias + { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_PTR(&pin_P1_09) }, // 1.09 - UART CTS | CTS1 (TRACEDATA3) + { MP_ROM_QSTR(MP_QSTR_CTS1), MP_ROM_PTR(&pin_P1_09) }, // CTS1 alias + { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_PTR(&pin_P1_02) }, // 1.02 - UART RTS | RTS1 + { MP_ROM_QSTR(MP_QSTR_RTS1), MP_ROM_PTR(&pin_P1_02) }, // RTS1 alias - {MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_P1_05)}, // 1.05 - UART RX | RX2 - {MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_P1_07)}, // 1.07 - UART TX | TX2 + { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_P1_05) }, // 1.05 - UART RX | RX2 + { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_P1_07) }, // 1.07 - UART TX | TX2 // Board Objects - {MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj)}, - {MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj)}, - {MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj)}, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From d5365cb066137b6f2240a1eb24ee1ac812c3e080 Mon Sep 17 00:00:00 2001 From: nitz Date: Tue, 9 Mar 2021 18:36:29 -0500 Subject: [PATCH 26/48] =?UTF-8?q?SDIO/QSPI=20pin=20names.=20=C2=AF\=5F(?= =?UTF-8?q?=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boards/sparkfun_nrf52840_micromod/pins.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c index 389d5f6b97..65700f24e4 100644 --- a/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c +++ b/ports/nrf/boards/sparkfun_nrf52840_micromod/pins.c @@ -68,12 +68,18 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_28) }, // 0.28 - SCK | SPI_SCK (AIN4) { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_P0_20) }, // 0.20 - /CS | SPI_/CS - // QSPI, used by flash on this board, but is broken out on MicroMod connector. - { MP_ROM_QSTR(MP_QSTR_SPI_SCK1), MP_ROM_PTR(&pin_P0_19) }, // 0.00 - IOSCK | Flash Serial Clock - { MP_ROM_QSTR(MP_QSTR_SPI_COPI1), MP_ROM_PTR(&pin_P0_14) }, // 0.00 - IO0 | Flash Data 0 - { MP_ROM_QSTR(MP_QSTR_SPI_CIPO1), MP_ROM_PTR(&pin_P0_21) }, // 0.00 - IO1 | Flash Data 1 - { MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_P0_23) },// 0.00 - IO2 | Flash Data 2 - { MP_ROM_QSTR(MP_QSTR_SPI_CS1), MP_ROM_PTR(&pin_P1_00) }, // 0.00 - IO3 | Flash Data 3 + // QSPI, used by flash on this board, but is broken out + // on the MicroMod connector, to to the SDIO pins. + { MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_P0_19) }, // 0.00 - SDIO SCK | Used as: QSPI flash SCK + { MP_ROM_QSTR(MP_QSTR_SPI_SCK1), MP_ROM_PTR(&pin_P0_19) }, // SPI_SCK1 alias + { MP_ROM_QSTR(MP_QSTR_SDIO_CMD), MP_ROM_PTR(&pin_P0_14) }, // 0.00 - SDIO CMD | Used as: QSPI flash D0 (or SDI) + { MP_ROM_QSTR(MP_QSTR_SPI_COPI1), MP_ROM_PTR(&pin_P0_14) }, // SPI_COPI1 alias + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA0), MP_ROM_PTR(&pin_P0_21) },// 0.00 - SDIO DATA0 | Used as: QSPI flash D1 (or SDO) + { MP_ROM_QSTR(MP_QSTR_SPI_CIPO1), MP_ROM_PTR(&pin_P0_21) }, // SPI_CIPO1 alias + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA1), MP_ROM_PTR(&pin_P0_22) },// 0.00 - SDIO DATA1 | Unused for flash. + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_P0_23) },// 0.00 - SDIO DATA2 | Used as: QSPI flash D2 + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA3), MP_ROM_PTR(&pin_P1_00) },// 0.00 - SDIO DATA3 | Use das: QSPI flash D3 (or /HOLD) + { MP_ROM_QSTR(MP_QSTR_SPI_CS1), MP_ROM_PTR(&pin_P1_00) }, // SPI_CS1 alias // Reset Pin { MP_ROM_QSTR(MP_QSTR_RESET), MP_ROM_PTR(&pin_P1_14) }, // 0.18 - /RESET (NRESET) From a3c3e8a0fa5e06910747f1a95a12b899562a618d Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 9 Mar 2021 22:41:08 -0600 Subject: [PATCH 27/48] fix trailing whitespace --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 0013aece49..8ddeab9308 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -109,7 +109,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, // exec a set pindirs to 0 for input pio_sm_exec(state_machine.pio,state_machine.state_machine,0xe080); - //exec the appropriate wait for pin + //exec the appropriate wait for pin if (self->idle_state == true ) { pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020); } else { From 85f0f07d51343bd67c1b2308bdfed192cc470549 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Wed, 10 Mar 2021 11:37:27 -0600 Subject: [PATCH 28/48] add fill_region and draw_line to bitmaptools --- locale/circuitpython.pot | 6 +- shared-bindings/bitmaptools/__init__.c | 150 ++++++++++++++++++++++++- shared-bindings/bitmaptools/__init__.h | 10 ++ shared-module/bitmaptools/__init__.c | 146 ++++++++++++++++++++++++ shared-module/displayio/Bitmap.h | 2 + 5 files changed, 308 insertions(+), 6 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 2e31d5dfc1..6e57945edf 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1042,10 +1042,6 @@ msgstr "" msgid "Group already used" msgstr "" -#: shared-module/displayio/Group.c -msgid "Group full" -msgstr "" - #: ports/mimxrt10xx/common-hal/busio/SPI.c ports/stm/common-hal/busio/I2C.c #: ports/stm/common-hal/busio/SPI.c ports/stm/common-hal/canio/CAN.c #: ports/stm/common-hal/sdioio/SDCard.c @@ -3643,7 +3639,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index cf48d12dc1..6804889081 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -243,13 +243,161 @@ STATIC mp_obj_t bitmaptools_obj_rotozoom(size_t n_args, const mp_obj_t *pos_args MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_rotozoom_obj, 0, bitmaptools_obj_rotozoom); // requires at least 2 arguments (destination bitmap and source bitmap) +//| +//| def fill_region( +//| dest_bitmap: displayio.Bitmap, +//| x1: int, y1: int, +//| x2: int, y2: int, +//| value: int) -> None: +//| """Draws the color value into the destination bitmap within the +//| rectangular region bounded by (x1,y1) and (x2,y2), exclusive. +//| +//| :param bitmap dest_bitmap: Destination bitmap that will be written into +//| :param int x1: x-pixel position of the first corner of the rectangular fill region +//| :param int y1: y-pixel position of the first corner of the rectangular fill region +//| :param int x2: x-pixel position of the second corner of the rectangular fill region +//| :param int y2: y-pixel position of the second corner of the rectangular fill region +//| :param int value: Bitmap palette index that will be written into the rectangular +//| fill region in the destination bitmap""" +//| ... +//| +STATIC mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ + enum {ARG_dest_bitmap, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_value}; + + static const mp_arg_t allowed_args[] = { + {MP_QSTR_dest_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ}, + {MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_x2, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_y2, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_value, MP_ARG_REQUIRED | MP_ARG_INT}, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + displayio_bitmap_t *destination = MP_OBJ_TO_PTR(args[ARG_dest_bitmap].u_obj); // the destination bitmap + + uint32_t value, color_depth; + value = args[ARG_value].u_int; + color_depth = (1 << destination->bits_per_value); + if (color_depth <= value) { + mp_raise_ValueError(translate("out of range of target")); + } + + int16_t x1 = args[ARG_x1].u_int; + int16_t y1 = args[ARG_y1].u_int; + int16_t x2 = args[ARG_x2].u_int; + int16_t y2 = args[ARG_y2].u_int; + + // Ensure x1 < x2 and y1 < y2 + if (x1 > x2) { + int16_t temp=x2; + x2=x1; + x1=temp; + } + if (y1 > y2) { + int16_t temp=y2; + y2=y1; + y1=temp; + } + + // constrain to bitmap dimensions + if (x1 < 0) { + x1 = 0; + } else if (x1 > destination->width) { + x1 = destination->width; + } + if (x2 < 0) { + x2 = 0; + } else if (x2 > destination->width) { + x2 = destination->width; + } + if (y1 < 0) { + y1 = 0; + } else if (y1 > destination->height) { + y1 = destination->height; + } + if (y2 < 0) { + y2 = 0; + } else if (y2 > destination->height) { + y2 = destination->height; + } + + common_hal_bitmaptools_fill_region(destination, x1, y1, x2, y2, value); + + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_region); +// requires all 6 arguments + +//| +//| def draw_line( +//| dest_bitmap: displayio.Bitmap, +//| x1: int, y1: int, +//| x2: int, y2: int, +//| value: int) -> None: +//| """Draws a line into a bitmap specified two endpoints (x1,y1) and (x2,y2). +//| +//| :param bitmap dest_bitmap: Destination bitmap that will be written into +//| :param int x1: x-pixel position of the line's first endpoint +//| :param int y1: y-pixel position of the line's first endpoint +//| :param int x2: x-pixel position of the line's second endpoint +//| :param int y2: y-pixel position of the line's second endpoint +//| :param int value: Bitmap palette index that will be written into the +//| line in the destination bitmap""" +//| ... +//| +STATIC mp_obj_t bitmaptools_obj_draw_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ + enum {ARG_dest_bitmap, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_value}; + + static const mp_arg_t allowed_args[] = { + {MP_QSTR_dest_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ}, + {MP_QSTR_x1, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_y1, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_x2, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_y2, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_value, MP_ARG_REQUIRED | MP_ARG_INT}, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + displayio_bitmap_t *destination = MP_OBJ_TO_PTR(args[ARG_dest_bitmap].u_obj); // the destination bitmap + + uint32_t value, color_depth; + value = args[ARG_value].u_int; + color_depth = (1 << destination->bits_per_value); + if (color_depth <= value) { + mp_raise_ValueError(translate("out of range of target")); + } + + int16_t x1 = args[ARG_x1].u_int; + int16_t y1 = args[ARG_y1].u_int; + int16_t x2 = args[ARG_x2].u_int; + int16_t y2 = args[ARG_y2].u_int; + + // verify points are within the bitmap boundary (inclusive) + if ( (x1 < 0) || (x2 < 0) || (y1 < 0) || (y2 < 0) || + (x1 >= destination->width) || (x2 >= destination->width) || + (y1 >= destination->height) || (y2 >= destination->height) ) { + mp_raise_ValueError(translate("out of range of target")); + } + + common_hal_bitmaptools_draw_line(destination, x1, y1, x2, y2, value); + + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_draw_line_obj, 0, bitmaptools_obj_draw_line); +// requires all 6 arguments STATIC const mp_rom_map_elem_t bitmaptools_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_rotozoom), MP_ROM_PTR(&bitmaptools_rotozoom_obj) }, + { MP_ROM_QSTR(MP_QSTR_fill_region), MP_ROM_PTR(&bitmaptools_fill_region_obj) }, + { MP_ROM_QSTR(MP_QSTR_draw_line), MP_ROM_PTR(&bitmaptools_draw_line_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bitmaptools_module_globals, bitmaptools_module_globals_table); - const mp_obj_module_t bitmaptools_module = { .base = {&mp_type_module }, .globals = (mp_obj_dict_t*)&bitmaptools_module_globals, diff --git a/shared-bindings/bitmaptools/__init__.h b/shared-bindings/bitmaptools/__init__.h index e2bb6938bc..1ab6e41293 100644 --- a/shared-bindings/bitmaptools/__init__.h +++ b/shared-bindings/bitmaptools/__init__.h @@ -39,4 +39,14 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16 float scale, uint32_t skip_index, bool skip_index_none); +void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination, + int16_t x1, int16_t y1, + int16_t x2, int16_t y2, + uint32_t value); + +void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination, + int16_t x0, int16_t y0, + int16_t x1, int16_t y1, + uint32_t value); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BITMAPTOOLS__INIT__H diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 7dc4024ef4..72db55c242 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -26,10 +26,12 @@ #include "shared-bindings/displayio/Bitmap.h" +#include "shared-module/displayio/Bitmap.h" #include "py/runtime.h" #include "math.h" +#include "stdlib.h" void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16_t oy, int16_t dest_clip0_x, int16_t dest_clip0_y, @@ -172,3 +174,147 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16 rowv += dvCol; } } + +void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination, + int16_t x1, int16_t y1, + int16_t x2, int16_t y2, + uint32_t value) { + // writes the value (a bitmap color index) into a bitmap in the specified rectangular region + // + // input checks should ensure that x1 < x2 and y1 < y2 and are within the bitmap region + + if (destination->read_only) { + mp_raise_RuntimeError(translate("Read-only object")); + } + + // update the dirty rectangle + displayio_bitmap_set_dirty_area(destination, x1, y1, x2, y2); + + int16_t x, y; + for (x = x1; x < x2; x++) { + for (y = y1; y < y2; y++ ) { + displayio_bitmap_write_pixel(destination, x, y, value); + } + } +} + +int16_t constrain(int16_t input, int16_t min, int16_t max) { + // constrain the input between the min and max values + if (input < min) { + return min; + } + if (input > max) { + return max; + } + return input; +} + +void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination, + int16_t x0, int16_t y0, + int16_t x1, int16_t y1, + uint32_t value) { + + if (destination->read_only) { + mp_raise_RuntimeError(translate("Read-only object")); + } + + // + // adapted from Adafruit_CircuitPython_Display_Shapes.Polygon._line + // + + // update the dirty rectangle + int16_t xbb0, xbb1, ybb0, ybb1; + if (x0 < x1) { + xbb0 = x0; + xbb1 = x1 + 1; + } else { + xbb0 = x1; + xbb1 = x0 + 1; + } + if (y0 < y1) { + ybb0 = y0; + ybb1 = y1 + 1; + } else { + ybb0 = y1; + ybb1 = y0 + 1; + } + + xbb0 = constrain(xbb0, 0, destination->width); + xbb1 = constrain(xbb1, 0, destination->width); + ybb0 = constrain(ybb0, 0, destination->height); + ybb1 = constrain(ybb1, 0, destination->height); + + displayio_bitmap_set_dirty_area(destination, xbb0, ybb0, xbb1, ybb1); + + int16_t temp, x, y; + + if (x0 == x1) { // vertical line + if (y0 > y1) { // ensure y1 > y0 + temp = y0; + y0 = y1; + y1 = temp; + } + for (y = y0; y < (y1 + 1); y++) { // write a horizontal line + displayio_bitmap_write_pixel(destination, x0, y, value); + } + } + else if (y0 == y1) { // horizontal line + if (x0 > x1) { // ensure y1 > y0 + temp = x0; + x0 = x1; + x1 = temp; + } + for (x = x0; x < (x1 + 1); x++) { // write a horizontal line + displayio_bitmap_write_pixel(destination, x, y0, value); + } + } + else { + bool steep; + steep = ( abs(y1 - y0) > abs(x1 - x0) ); + + if ( steep ) { // flip x0<->y0 and x1<->y1 + temp = x0; + x0 = y0; + y0 = temp; + temp = x1; + x1 = y1; + y1 = temp; + } + + if (x0 > x1) { // flip x0<->x1 and y0<->y1 + temp = x0; + x0 = x1; + x1 = temp; + temp = y0; + y0 = y1; + y1 = temp; + } + + int16_t dx, dy, ystep; + dx = x1 - x0; + dy = abs(y1 - y0); + + float err = dx / 2; + + if (y0 < y1) { + ystep = 1; + } + else { + ystep = -1; + } + + for (x = x0; x < (x1 + 1); x++) { + if (steep) { + displayio_bitmap_write_pixel(destination, y0, x, value); + } + else { + displayio_bitmap_write_pixel(destination, x, y0, value); + } + err -= dy; + if (err < 0) { + y0 += ystep; + err += dx; + } + } + } +} diff --git a/shared-module/displayio/Bitmap.h b/shared-module/displayio/Bitmap.h index f4bd7ce4d3..d6aaaa8bac 100644 --- a/shared-module/displayio/Bitmap.h +++ b/shared-module/displayio/Bitmap.h @@ -49,5 +49,7 @@ typedef struct { void displayio_bitmap_finish_refresh(displayio_bitmap_t *self); displayio_area_t* displayio_bitmap_get_refresh_areas(displayio_bitmap_t *self, displayio_area_t* tail); +void displayio_bitmap_set_dirty_area(displayio_bitmap_t *self, int16_t x1, int16_t y1, int16_t x2, int16_t y2); +void displayio_bitmap_write_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_BITMAP_H From c95def0b3209f8ec66f0fb322cc4235328065ed2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 10 Mar 2021 17:37:04 -0600 Subject: [PATCH 29/48] raspberrypi: Enable mp3 playback The rp2040 is _very_ marginal for mp3 playback, and currently sometimes triggers a bug that gives garbled audio output. However, it does work for some limited situations. --- lib/mp3 | 2 +- ports/raspberrypi/mpconfigport.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mp3 b/lib/mp3 index bc58a65496..7a5de1ad77 160000 --- a/lib/mp3 +++ b/lib/mp3 @@ -1 +1 @@ -Subproject commit bc58a654964c799e972719a63ff12694998f3549 +Subproject commit 7a5de1ad777e95b0f4fab7bbd35678c7d319b1b5 diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 03de6ce5ee..3388280278 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -25,6 +25,7 @@ endif CIRCUITPY_FRAMEBUFFERIO = 1 CIRCUITPY_FULL_BUILD = 1 +CIRCUITPY_AUDIOMP3 ?= 1 CIRCUITPY_BITOPS = 1 CIRCUITPY_PWMIO = 1 CIRCUITPY_RGBMATRIX = 1 @@ -47,7 +48,6 @@ CIRCUITPY_AUDIOPWMIO ?= 1 # These libraries require Cortex M4+ for fancy math instructions. CIRCUITPY_AUDIOMIXER ?= 0 -CIRCUITPY_AUDIOMP3 ?= 0 INTERNAL_LIBM = 1 From 16bfe3b41c46b1c8070f025bdbc932e21acf1753 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 10 Mar 2021 16:46:42 -0600 Subject: [PATCH 30/48] raspberrypi: RTC: Ensure a time is set Until a time is set, the RTC is not running, and rtc_get_datetime() returns false without assigning to the out-parameter. In CircuitPython, this would manifest as arbitrary values being returned, since uninitialized storage on the stack was being converted into a timestamp. --- ports/raspberrypi/common-hal/rtc/RTC.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ports/raspberrypi/common-hal/rtc/RTC.c b/ports/raspberrypi/common-hal/rtc/RTC.c index 89c23fc190..e6c5d88712 100644 --- a/ports/raspberrypi/common-hal/rtc/RTC.c +++ b/ports/raspberrypi/common-hal/rtc/RTC.c @@ -29,9 +29,23 @@ #include "py/runtime.h" #include "src/rp2_common/hardware_rtc/include/hardware/rtc.h" +#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" void common_hal_rtc_init(void) { + datetime_t t = { + .year = 2020, + .month = 1, + .day = 1, + .dotw = 3, // 0 is Sunday, so 3 is Wednesday + .hour = 0, + .min = 0, + .sec = 0 + }; + + // Start the RTC rtc_init(); + rtc_set_datetime(&t); + } void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { From 1ebbd14d0faab0da6673b595f4d25c17a67c24aa Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Thu, 11 Mar 2021 11:02:13 -0500 Subject: [PATCH 31/48] Fix UART deinit --- ports/stm/common-hal/busio/UART.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/stm/common-hal/busio/UART.c b/ports/stm/common-hal/busio/UART.c index 0cd9061819..b4794a31b3 100644 --- a/ports/stm/common-hal/busio/UART.c +++ b/ports/stm/common-hal/busio/UART.c @@ -268,6 +268,7 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_uart_banks); i++) { if (mcu_uart_banks[i] == self->handle.Instance) { + reserved_uart[i] = false; never_reset_uart[i] = false; break; } From 5ace7af933f7ebc3c43c0a27385ada4de068d149 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 11:06:00 -0500 Subject: [PATCH 32/48] disable default usb_cdc --- py/circuitpy_mpconfig.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 496ce918ba..fea1f937ec 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -322,8 +322,10 @@ CFLAGS += -DCIRCUITPY_TOUCHIO=$(CIRCUITPY_TOUCHIO) CIRCUITPY_UHEAP ?= 0 CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP) +# Disable by default for now, until we have dynamic enabling. +CIRCUITPY_USB_CDC ?= 0 # Secondary CDC is usually available if there are at least 8 endpoints. -CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8) +#CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8) CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) CIRCUITPY_USB_HID ?= 1 From 0b73c7a2125901f24ae0cb5669f420ebcd2f9d56 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Thu, 11 Mar 2021 11:27:17 -0500 Subject: [PATCH 33/48] Update F407 to match F405 --- .../mpconfigboard.mk | 2 + ports/stm/boards/pyboard_v11/mpconfigboard.mk | 2 + ports/stm/mpconfigport.mk | 3 +- .../peripherals/stm32f4/stm32f407xx/periph.c | 227 ++++++++++------- .../peripherals/stm32f4/stm32f407xx/periph.h | 52 ++-- .../peripherals/stm32f4/stm32f407xx/pins.c | 233 +++++++++--------- .../peripherals/stm32f4/stm32f407xx/pins.h | 209 ++++++++-------- 7 files changed, 412 insertions(+), 316 deletions(-) diff --git a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk index 39bf7dc542..e525ebe1ef 100644 --- a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk +++ b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk @@ -15,3 +15,5 @@ LD_DEFAULT = boards/STM32F405_default.ld # UF2 boot option LD_BOOT = boards/STM32F405_boot.ld UF2_OFFSET = 0x8010000 + +CIRCUITPY_RGBMATRIX ?= 1 diff --git a/ports/stm/boards/pyboard_v11/mpconfigboard.mk b/ports/stm/boards/pyboard_v11/mpconfigboard.mk index 78b96e55fc..4aff25bb0a 100644 --- a/ports/stm/boards/pyboard_v11/mpconfigboard.mk +++ b/ports/stm/boards/pyboard_v11/mpconfigboard.mk @@ -11,3 +11,5 @@ MCU_PACKAGE = LQFP64 LD_COMMON = boards/common_default.ld LD_FILE = boards/STM32F405_fs.ld + +CIRCUITPY_RGBMATRIX ?= 1 diff --git a/ports/stm/mpconfigport.mk b/ports/stm/mpconfigport.mk index fe257fc505..4d76d03c92 100644 --- a/ports/stm/mpconfigport.mk +++ b/ports/stm/mpconfigport.mk @@ -3,10 +3,9 @@ LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 USB_SERIAL_NUMBER_LENGTH ?= 24 -ifeq ($(MCU_VARIANT),STM32F405xx) +ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F405xx STM32F407xx)) CIRCUITPY_CANIO = 1 CIRCUITPY_FRAMEBUFFERIO ?= 1 - CIRCUITPY_RGBMATRIX ?= 1 CIRCUITPY_SDIOIO ?= 1 # Number of USB endpoint pairs. USB_NUM_EP = 4 diff --git a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.c b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.c index e75f0b2062..2f9accbf11 100644 --- a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.c +++ b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.c @@ -29,55 +29,57 @@ #include "peripherals/pins.h" #include "peripherals/periph.h" -// I2C +I2C_TypeDef * mcu_i2c_banks[I2C_BANK_ARRAY_LEN] = {I2C1, I2C2, I2C3}; -I2C_TypeDef * mcu_i2c_banks[3] = {I2C1, I2C2, I2C3}; - -const mcu_periph_obj_t mcu_i2c_sda_list[4] = { +const mcu_periph_obj_t mcu_i2c_sda_list[I2C_SDA_ARRAY_LEN] = { PERIPH(1, 4, &pin_PB07), PERIPH(1, 4, &pin_PB09), PERIPH(2, 4, &pin_PB11), PERIPH(3, 4, &pin_PC09), + PERIPH(2, 4, &pin_PF00), + PERIPH(2, 4, &pin_PH05), + PERIPH(3, 4, &pin_PH08), }; - -const mcu_periph_obj_t mcu_i2c_scl_list[4] = { +const mcu_periph_obj_t mcu_i2c_scl_list[I2C_SCL_ARRAY_LEN] = { + PERIPH(3, 4, &pin_PA08), PERIPH(1, 4, &pin_PB06), PERIPH(1, 4, &pin_PB08), PERIPH(2, 4, &pin_PB10), - PERIPH(3, 4, &pin_PA08) + PERIPH(2, 4, &pin_PF01), + PERIPH(2, 4, &pin_PH04), + PERIPH(3, 4, &pin_PH07), }; -SPI_TypeDef * mcu_spi_banks[3] = {SPI1, SPI2, SPI3}; +SPI_TypeDef * mcu_spi_banks[SPI_BANK_ARRAY_LEN] = {SPI1, SPI2, SPI3}; -const mcu_periph_obj_t mcu_spi_sck_list[7] = { +const mcu_periph_obj_t mcu_spi_sck_list[SPI_SCK_ARRAY_LEN] = { PERIPH(1, 5, &pin_PA05), PERIPH(1, 5, &pin_PB03), + PERIPH(3, 6, &pin_PB03), PERIPH(2, 5, &pin_PB10), PERIPH(2, 5, &pin_PB13), - PERIPH(2, 5, &pin_PC07), - PERIPH(3, 6, &pin_PB03), PERIPH(3, 6, &pin_PC10), + PERIPH(2, 5, &pin_PI01), }; - -const mcu_periph_obj_t mcu_spi_mosi_list[6] = { +const mcu_periph_obj_t mcu_spi_mosi_list[SPI_MOSI_ARRAY_LEN] = { PERIPH(1, 5, &pin_PA07), PERIPH(1, 5, &pin_PB05), + PERIPH(3, 6, &pin_PB05), PERIPH(2, 5, &pin_PB15), PERIPH(2, 5, &pin_PC03), - PERIPH(3, 6, &pin_PB05), PERIPH(3, 6, &pin_PC12), + PERIPH(2, 5, &pin_PI03), }; - -const mcu_periph_obj_t mcu_spi_miso_list[6] = { +const mcu_periph_obj_t mcu_spi_miso_list[SPI_MISO_ARRAY_LEN] = { PERIPH(1, 5, &pin_PA06), PERIPH(1, 5, &pin_PB04), + PERIPH(3, 6, &pin_PB04), PERIPH(2, 5, &pin_PB14), PERIPH(2, 5, &pin_PC02), - PERIPH(3, 6, &pin_PB04), PERIPH(3, 6, &pin_PC11), + PERIPH(2, 5, &pin_PI02), }; - -const mcu_periph_obj_t mcu_spi_nss_list[6] = { +const mcu_periph_obj_t mcu_spi_nss_list[SPI_NSS_ARRAY_LEN] = { PERIPH(1, 5, &pin_PA04), PERIPH(1, 5, &pin_PA15), PERIPH(2, 5, &pin_PB09), @@ -89,7 +91,7 @@ const mcu_periph_obj_t mcu_spi_nss_list[6] = { USART_TypeDef * mcu_uart_banks[MAX_UART] = {USART1, USART2, USART3, UART4, UART5, USART6}; bool mcu_uart_has_usart[MAX_UART] = {true, true, true, false, false, true}; -const mcu_periph_obj_t mcu_uart_tx_list[12] = { +const mcu_periph_obj_t mcu_uart_tx_list[UART_TX_ARRAY_LEN] = { PERIPH(4, 8, &pin_PA00), PERIPH(2, 7, &pin_PA02), PERIPH(1, 7, &pin_PA09), @@ -103,8 +105,7 @@ const mcu_periph_obj_t mcu_uart_tx_list[12] = { PERIPH(3, 7, &pin_PD08), PERIPH(6, 8, &pin_PG14), }; - -const mcu_periph_obj_t mcu_uart_rx_list[12] = { +const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN] = { PERIPH(4, 8, &pin_PA01), PERIPH(2, 7, &pin_PA03), PERIPH(1, 7, &pin_PA10), @@ -121,74 +122,120 @@ const mcu_periph_obj_t mcu_uart_rx_list[12] = { //Timers //TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins -TIM_TypeDef * mcu_tim_banks[14] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, TIM9, TIM10, +TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, TIM9, TIM10, TIM11, TIM12, TIM13, TIM14}; -const mcu_tim_pin_obj_t mcu_tim_pin_list[56] = { - TIM(2,1,1,&pin_PA00), - TIM(5,2,1,&pin_PA00), - TIM(2,1,2,&pin_PA01), - TIM(5,2,2,&pin_PA01), - TIM(2,1,3,&pin_PA02), - TIM(5,2,3,&pin_PA02), - TIM(2,1,4,&pin_PA03), - TIM(5,2,4,&pin_PA03), - TIM(9,3,1,&pin_PA02), - TIM(9,3,2,&pin_PA03), - TIM(3,2,1,&pin_PA06), - TIM(13,9,1,&pin_PA06), - TIM(3,2,2,&pin_PA07), - TIM(14,9,1,&pin_PA07), - TIM(1,1,1,&pin_PA08), - TIM(1,1,2,&pin_PA09), - TIM(1,1,3,&pin_PA10), - TIM(1,1,4,&pin_PA11), - TIM(2,1,1,&pin_PA15), - TIM(3,2,3,&pin_PB00), - TIM(3,2,4,&pin_PB01), - TIM(2,1,2,&pin_PB03), - TIM(3,2,1,&pin_PB04), - TIM(3,2,2,&pin_PB05), - TIM(4,2,1,&pin_PB06), - TIM(4,2,2,&pin_PB07), - TIM(4,2,3,&pin_PB08), - TIM(10,2,1,&pin_PB08), - TIM(4,2,4,&pin_PB09), - TIM(11,2,1,&pin_PB09), - TIM(2,1,3,&pin_PB10), - TIM(2,1,4,&pin_PB11), - TIM(12,9,1,&pin_PB14), - TIM(12,9,2,&pin_PB15), - TIM(3,2,1,&pin_PC06), - TIM(3,2,2,&pin_PC07), - TIM(3,2,3,&pin_PC08), - TIM(3,2,4,&pin_PC09), - TIM(8,3,1,&pin_PC06), - TIM(8,3,2,&pin_PC07), - TIM(8,3,3,&pin_PC08), - TIM(8,3,4,&pin_PC09), - TIM(4,2,1,&pin_PD12), - TIM(4,2,2,&pin_PD13), - TIM(4,2,3,&pin_PD14), - TIM(4,2,4,&pin_PD15), - TIM(9,3,1,&pin_PE05), - TIM(9,3,2,&pin_PE06), - TIM(1,1,1,&pin_PE09), - TIM(1,1,2,&pin_PE11), - TIM(1,1,3,&pin_PE13), - TIM(1,1,4,&pin_PE14), - TIM(10,3,1,&pin_PF06), - TIM(11,3,1,&pin_PF07), - TIM(13,9,1,&pin_PF08), - TIM(14,9,1,&pin_PF09), - // TIM(12,9,1,&pin_PH06), //TODO: include these when pin map is expanded - // TIM(12,9,2,&pin_PH09), - // TIM(5,2,1,&pin_PH10), - // TIM(5,2,2,&pin_PH11), - // TIM(5,2,3,&pin_PH12), - // TIM(5,2,4,&pin_PI00), - // TIM(8,3,4,&pin_PI02), - // TIM(8,3,1,&pin_PI05), - // TIM(8,3,2,&pin_PI06), - // TIM(8,3,3,&pin_PI07), +const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN] = { + TIM(2, 1, 1, &pin_PA00), + TIM(5, 2, 1, &pin_PA00), + TIM(2, 1, 2, &pin_PA01), + TIM(5, 2, 2, &pin_PA01), + TIM(2, 1, 3, &pin_PA02), + TIM(5, 2, 3, &pin_PA02), + TIM(9, 3, 1, &pin_PA02), + TIM(2, 1, 4, &pin_PA03), + TIM(5, 2, 4, &pin_PA03), + TIM(9, 3, 2, &pin_PA03), + TIM(2, 1, 1, &pin_PA05), + TIM(3, 2, 1, &pin_PA06), + TIM(13, 9, 1, &pin_PA06), + TIM(3, 2, 2, &pin_PA07), + TIM(14, 9, 1, &pin_PA07), + TIM(1, 1, 1, &pin_PA08), + TIM(1, 1, 2, &pin_PA09), + TIM(1, 1, 3, &pin_PA10), + TIM(1, 1, 4, &pin_PA11), + TIM(2, 1, 1, &pin_PA15), + TIM(3, 2, 3, &pin_PB00), + TIM(3, 2, 4, &pin_PB01), + TIM(2, 1, 2, &pin_PB03), + TIM(3, 2, 1, &pin_PB04), + TIM(3, 2, 2, &pin_PB05), + TIM(4, 2, 1, &pin_PB06), + TIM(4, 2, 2, &pin_PB07), + TIM(4, 2, 3, &pin_PB08), + TIM(10, 3, 1, &pin_PB08), + TIM(4, 2, 4, &pin_PB09), + TIM(11, 3, 1, &pin_PB09), + TIM(2, 1, 3, &pin_PB10), + TIM(2, 1, 4, &pin_PB11), + TIM(12, 9, 1, &pin_PB14), + TIM(12, 9, 2, &pin_PB15), + TIM(3, 2, 1, &pin_PC06), + TIM(8, 3, 1, &pin_PC06), + TIM(3, 2, 2, &pin_PC07), + TIM(8, 3, 2, &pin_PC07), + TIM(3, 2, 3, &pin_PC08), + TIM(8, 3, 3, &pin_PC08), + TIM(3, 2, 4, &pin_PC09), + TIM(8, 3, 4, &pin_PC09), + TIM(4, 2, 1, &pin_PD12), + TIM(4, 2, 2, &pin_PD13), + TIM(4, 2, 3, &pin_PD14), + TIM(4, 2, 4, &pin_PD15), + TIM(9, 3, 1, &pin_PE05), + TIM(9, 3, 2, &pin_PE06), + TIM(1, 1, 1, &pin_PE09), + TIM(1, 1, 2, &pin_PE11), + TIM(1, 1, 3, &pin_PE13), + TIM(1, 1, 4, &pin_PE14), + TIM(10, 3, 1, &pin_PF06), + TIM(11, 3, 1, &pin_PF07), + TIM(13, 9, 1, &pin_PF08), + TIM(14, 9, 1, &pin_PF09), + TIM(12, 9, 1, &pin_PH06), + TIM(12, 9, 2, &pin_PH09), + TIM(5, 2, 1, &pin_PH10), + TIM(5, 2, 2, &pin_PH11), + TIM(5, 2, 3, &pin_PH12), + TIM(5, 2, 4, &pin_PI00), + TIM(8, 3, 4, &pin_PI02), + TIM(8, 3, 1, &pin_PI05), + TIM(8, 3, 2, &pin_PI06), + TIM(8, 3, 3, &pin_PI07), +}; + +//SDIO +SDIO_TypeDef * mcu_sdio_banks[1] = {SDIO}; + +const mcu_periph_obj_t mcu_sdio_clock_list[1] = { + PERIPH(1, 12, &pin_PC12), +}; +const mcu_periph_obj_t mcu_sdio_command_list[1] = { + PERIPH(1, 12, &pin_PD02), +}; +const mcu_periph_obj_t mcu_sdio_data0_list[1] = { + PERIPH(1, 12, &pin_PC08), +}; +const mcu_periph_obj_t mcu_sdio_data1_list[1] = { + PERIPH(1, 12, &pin_PC09), +}; +const mcu_periph_obj_t mcu_sdio_data2_list[1] = { + PERIPH(1, 12, &pin_PC10), +}; +const mcu_periph_obj_t mcu_sdio_data3_list[1] = { + PERIPH(1, 12, &pin_PC11), +}; + +//CAN +CAN_TypeDef * mcu_can_banks[2] = {CAN1, CAN2}; + +const mcu_periph_obj_t mcu_can_tx_list[6] = { + PERIPH(1, 9, &pin_PA11), + PERIPH(1, 9, &pin_PB08), + PERIPH(1, 9, &pin_PD00), + PERIPH(1, 9, &pin_PI09), + + PERIPH(2, 9, &pin_PB12), + PERIPH(2, 9, &pin_PB05), +}; + +const mcu_periph_obj_t mcu_can_rx_list[6] = { + PERIPH(1, 9, &pin_PA12), + PERIPH(1, 9, &pin_PB09), + PERIPH(1, 9, &pin_PD01), + PERIPH(1, 9, &pin_PH13), + + PERIPH(2, 9, &pin_PB13), + PERIPH(2, 9, &pin_PB06), }; diff --git a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h index fb6348abaa..e6d4526b66 100644 --- a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h +++ b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h @@ -28,30 +28,54 @@ #define MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PERIPH_H //I2C -extern I2C_TypeDef * mcu_i2c_banks[3]; - -extern const mcu_periph_obj_t mcu_i2c_sda_list[4]; -extern const mcu_periph_obj_t mcu_i2c_scl_list[4]; +#define I2C_BANK_ARRAY_LEN 3 +#define I2C_SDA_ARRAY_LEN 7 +#define I2C_SCL_ARRAY_LEN 7 +extern I2C_TypeDef * mcu_i2c_banks[I2C_BANK_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_i2c_sda_list[I2C_SDA_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_i2c_scl_list[I2C_SCL_ARRAY_LEN]; //SPI -extern SPI_TypeDef * mcu_spi_banks[3]; - -extern const mcu_periph_obj_t mcu_spi_sck_list[7]; -extern const mcu_periph_obj_t mcu_spi_mosi_list[6]; -extern const mcu_periph_obj_t mcu_spi_miso_list[6]; -extern const mcu_periph_obj_t mcu_spi_nss_list[6]; +#define SPI_BANK_ARRAY_LEN 3 +#define SPI_SCK_ARRAY_LEN 7 +#define SPI_MOSI_ARRAY_LEN 7 +#define SPI_MISO_ARRAY_LEN 7 +#define SPI_NSS_ARRAY_LEN 6 +extern SPI_TypeDef * mcu_spi_banks[SPI_BANK_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_spi_sck_list[SPI_SCK_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_spi_mosi_list[SPI_MOSI_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_spi_miso_list[SPI_MISO_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_spi_nss_list[SPI_NSS_ARRAY_LEN]; //UART +#define UART_TX_ARRAY_LEN 12 +#define UART_RX_ARRAY_LEN 12 extern USART_TypeDef * mcu_uart_banks[MAX_UART]; extern bool mcu_uart_has_usart[MAX_UART]; - -extern const mcu_periph_obj_t mcu_uart_tx_list[12]; -extern const mcu_periph_obj_t mcu_uart_rx_list[12]; +extern const mcu_periph_obj_t mcu_uart_tx_list[UART_TX_ARRAY_LEN]; +extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN]; //Timers #define TIM_BANK_ARRAY_LEN 14 -#define TIM_PIN_ARRAY_LEN 56 +#define TIM_PIN_ARRAY_LEN 67 extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +//SDIO +extern SDIO_TypeDef * mcu_sdio_banks[1]; + +extern const mcu_periph_obj_t mcu_sdio_clock_list[1]; +extern const mcu_periph_obj_t mcu_sdio_command_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data0_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data1_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data2_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data3_list[1]; + +// CAN +extern CAN_TypeDef * mcu_can_banks[2]; + +extern const mcu_periph_obj_t mcu_can_tx_list[6]; +extern const mcu_periph_obj_t mcu_can_rx_list[6]; + + #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PERIPH_H diff --git a/ports/stm/peripherals/stm32f4/stm32f407xx/pins.c b/ports/stm/peripherals/stm32f4/stm32f407xx/pins.c index 4282741a84..62acb19550 100644 --- a/ports/stm/peripherals/stm32f4/stm32f407xx/pins.c +++ b/ports/stm/peripherals/stm32f4/stm32f407xx/pins.c @@ -28,33 +28,6 @@ #include "py/mphal.h" #include "peripherals/pins.h" -const mcu_pin_obj_t pin_PE02 = PIN(4, 2, NO_ADC); -const mcu_pin_obj_t pin_PE03 = PIN(4, 3, NO_ADC); -const mcu_pin_obj_t pin_PE04 = PIN(4, 4, NO_ADC); -const mcu_pin_obj_t pin_PE05 = PIN(4, 5, NO_ADC); -const mcu_pin_obj_t pin_PE06 = PIN(4, 6, NO_ADC); - -const mcu_pin_obj_t pin_PC13 = PIN(2, 13, NO_ADC); //anti-tamp -const mcu_pin_obj_t pin_PC14 = PIN(2, 14, NO_ADC); //OSC32_IN -const mcu_pin_obj_t pin_PC15 = PIN(2, 15, NO_ADC); //OSC32_OUT - -const mcu_pin_obj_t pin_PF00 = PIN(5, 0, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF01 = PIN(5, 1, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF02 = PIN(5, 2, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF03 = PIN(5, 3, ADC_INPUT(ADC_3,9)); // 144 only -const mcu_pin_obj_t pin_PF04 = PIN(5, 4, ADC_INPUT(ADC_3,14)); // 144 only -const mcu_pin_obj_t pin_PF05 = PIN(5, 5, ADC_INPUT(ADC_3,15)); // 144 only -const mcu_pin_obj_t pin_PF06 = PIN(5, 6, ADC_INPUT(ADC_3,4)); // 144 only -const mcu_pin_obj_t pin_PF07 = PIN(5, 7, ADC_INPUT(ADC_3,5)); // 144 only -const mcu_pin_obj_t pin_PF08 = PIN(5, 8, ADC_INPUT(ADC_3,6)); // 144 only -const mcu_pin_obj_t pin_PF09 = PIN(5, 9, ADC_INPUT(ADC_3,7)); // 144 only -const mcu_pin_obj_t pin_PF10 = PIN(5, 10, ADC_INPUT(ADC_3,8)); // 144 only - -const mcu_pin_obj_t pin_PC00 = PIN(2, 0, ADC_INPUT(ADC_123,10)); -const mcu_pin_obj_t pin_PC01 = PIN(2, 1, ADC_INPUT(ADC_123,11)); -const mcu_pin_obj_t pin_PC02 = PIN(2, 2, ADC_INPUT(ADC_123,12)); -const mcu_pin_obj_t pin_PC03 = PIN(2, 3, ADC_INPUT(ADC_123,13)); - const mcu_pin_obj_t pin_PA00 = PIN(0, 0, ADC_INPUT(ADC_123,0)); const mcu_pin_obj_t pin_PA01 = PIN(0, 1, ADC_INPUT(ADC_123,1)); const mcu_pin_obj_t pin_PA02 = PIN(0, 2, ADC_INPUT(ADC_123,2)); @@ -63,23 +36,69 @@ const mcu_pin_obj_t pin_PA04 = PIN(0, 4, ADC_INPUT(ADC_12,4)); const mcu_pin_obj_t pin_PA05 = PIN(0, 5, ADC_INPUT(ADC_12,5)); const mcu_pin_obj_t pin_PA06 = PIN(0, 6, ADC_INPUT(ADC_12,6)); const mcu_pin_obj_t pin_PA07 = PIN(0, 7, ADC_INPUT(ADC_12,7)); - -const mcu_pin_obj_t pin_PC04 = PIN(2, 4, ADC_INPUT(ADC_12,14)); -const mcu_pin_obj_t pin_PC05 = PIN(2, 5, ADC_INPUT(ADC_12,15)); - +const mcu_pin_obj_t pin_PA08 = PIN(0, 8, NO_ADC); +const mcu_pin_obj_t pin_PA09 = PIN(0, 9, NO_ADC); +const mcu_pin_obj_t pin_PA10 = PIN(0, 10, NO_ADC); +const mcu_pin_obj_t pin_PA11 = PIN(0, 11, NO_ADC); +const mcu_pin_obj_t pin_PA12 = PIN(0, 12, NO_ADC); +const mcu_pin_obj_t pin_PA13 = PIN(0, 13, NO_ADC); +const mcu_pin_obj_t pin_PA14 = PIN(0, 14, NO_ADC); +const mcu_pin_obj_t pin_PA15 = PIN(0, 15, NO_ADC); const mcu_pin_obj_t pin_PB00 = PIN(1, 0, ADC_INPUT(ADC_12,8)); const mcu_pin_obj_t pin_PB01 = PIN(1, 1, ADC_INPUT(ADC_12,9)); -const mcu_pin_obj_t pin_PB02 = PIN(1, 2, NO_ADC); //BOOT1 - -const mcu_pin_obj_t pin_PF11 = PIN(5, 11, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF12 = PIN(5, 12, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF13 = PIN(5, 13, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF14 = PIN(5, 14, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PF15 = PIN(5, 15, NO_ADC); // 144 only - -const mcu_pin_obj_t pin_PG00 = PIN(6, 0, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG01 = PIN(6, 1, NO_ADC); // 144 only - +const mcu_pin_obj_t pin_PB02 = PIN(1, 2, NO_ADC); +const mcu_pin_obj_t pin_PB03 = PIN(1, 3, NO_ADC); +const mcu_pin_obj_t pin_PB04 = PIN(1, 4, NO_ADC); +const mcu_pin_obj_t pin_PB05 = PIN(1, 5, NO_ADC); +const mcu_pin_obj_t pin_PB06 = PIN(1, 6, NO_ADC); +const mcu_pin_obj_t pin_PB07 = PIN(1, 7, NO_ADC); +const mcu_pin_obj_t pin_PB08 = PIN(1, 8, NO_ADC); +const mcu_pin_obj_t pin_PB09 = PIN(1, 9, NO_ADC); +const mcu_pin_obj_t pin_PB10 = PIN(1, 10, NO_ADC); +const mcu_pin_obj_t pin_PB11 = PIN(1, 11, NO_ADC); +const mcu_pin_obj_t pin_PB12 = PIN(1, 12, NO_ADC); +const mcu_pin_obj_t pin_PB13 = PIN(1, 13, NO_ADC); +const mcu_pin_obj_t pin_PB14 = PIN(1, 14, NO_ADC); +const mcu_pin_obj_t pin_PB15 = PIN(1, 15, NO_ADC); +const mcu_pin_obj_t pin_PC00 = PIN(2, 0, ADC_INPUT(ADC_123,10)); +const mcu_pin_obj_t pin_PC01 = PIN(2, 1, ADC_INPUT(ADC_123,11)); +const mcu_pin_obj_t pin_PC02 = PIN(2, 2, ADC_INPUT(ADC_123,12)); +const mcu_pin_obj_t pin_PC03 = PIN(2, 3, ADC_INPUT(ADC_123,13)); +const mcu_pin_obj_t pin_PC04 = PIN(2, 4, ADC_INPUT(ADC_12,14)); +const mcu_pin_obj_t pin_PC05 = PIN(2, 5, ADC_INPUT(ADC_12,15)); +const mcu_pin_obj_t pin_PC06 = PIN(2, 6, NO_ADC); +const mcu_pin_obj_t pin_PC07 = PIN(2, 7, NO_ADC); +const mcu_pin_obj_t pin_PC08 = PIN(2, 8, NO_ADC); +const mcu_pin_obj_t pin_PC09 = PIN(2, 9, NO_ADC); +const mcu_pin_obj_t pin_PC10 = PIN(2, 10, NO_ADC); +const mcu_pin_obj_t pin_PC11 = PIN(2, 11, NO_ADC); +const mcu_pin_obj_t pin_PC12 = PIN(2, 12, NO_ADC); +const mcu_pin_obj_t pin_PC13 = PIN(2, 13, NO_ADC); +const mcu_pin_obj_t pin_PC14 = PIN(2, 14, NO_ADC); +const mcu_pin_obj_t pin_PC15 = PIN(2, 15, NO_ADC); +const mcu_pin_obj_t pin_PD00 = PIN(3, 0, NO_ADC); +const mcu_pin_obj_t pin_PD01 = PIN(3, 1, NO_ADC); +const mcu_pin_obj_t pin_PD02 = PIN(3, 2, NO_ADC); +const mcu_pin_obj_t pin_PD03 = PIN(3, 3, NO_ADC); +const mcu_pin_obj_t pin_PD04 = PIN(3, 4, NO_ADC); +const mcu_pin_obj_t pin_PD05 = PIN(3, 5, NO_ADC); +const mcu_pin_obj_t pin_PD06 = PIN(3, 6, NO_ADC); +const mcu_pin_obj_t pin_PD07 = PIN(3, 7, NO_ADC); +const mcu_pin_obj_t pin_PD08 = PIN(3, 8, NO_ADC); +const mcu_pin_obj_t pin_PD09 = PIN(3, 9, NO_ADC); +const mcu_pin_obj_t pin_PD10 = PIN(3, 10, NO_ADC); +const mcu_pin_obj_t pin_PD11 = PIN(3, 11, NO_ADC); +const mcu_pin_obj_t pin_PD12 = PIN(3, 12, NO_ADC); +const mcu_pin_obj_t pin_PD13 = PIN(3, 13, NO_ADC); +const mcu_pin_obj_t pin_PD14 = PIN(3, 14, NO_ADC); +const mcu_pin_obj_t pin_PD15 = PIN(3, 15, NO_ADC); +const mcu_pin_obj_t pin_PE00 = PIN(4, 0, NO_ADC); +const mcu_pin_obj_t pin_PE01 = PIN(4, 1, NO_ADC); +const mcu_pin_obj_t pin_PE02 = PIN(4, 2, NO_ADC); +const mcu_pin_obj_t pin_PE03 = PIN(4, 3, NO_ADC); +const mcu_pin_obj_t pin_PE04 = PIN(4, 4, NO_ADC); +const mcu_pin_obj_t pin_PE05 = PIN(4, 5, NO_ADC); +const mcu_pin_obj_t pin_PE06 = PIN(4, 6, NO_ADC); const mcu_pin_obj_t pin_PE07 = PIN(4, 7, NO_ADC); const mcu_pin_obj_t pin_PE08 = PIN(4, 8, NO_ADC); const mcu_pin_obj_t pin_PE09 = PIN(4, 9, NO_ADC); @@ -89,73 +108,63 @@ const mcu_pin_obj_t pin_PE12 = PIN(4, 12, NO_ADC); const mcu_pin_obj_t pin_PE13 = PIN(4, 13, NO_ADC); const mcu_pin_obj_t pin_PE14 = PIN(4, 14, NO_ADC); const mcu_pin_obj_t pin_PE15 = PIN(4, 15, NO_ADC); - -const mcu_pin_obj_t pin_PB10 = PIN(1, 10, NO_ADC); -const mcu_pin_obj_t pin_PB11 = PIN(1, 11, NO_ADC); -const mcu_pin_obj_t pin_PB12 = PIN(1, 12, NO_ADC); -const mcu_pin_obj_t pin_PB13 = PIN(1, 13, NO_ADC); -const mcu_pin_obj_t pin_PB14 = PIN(1, 14, NO_ADC); -const mcu_pin_obj_t pin_PB15 = PIN(1, 15, NO_ADC); - -const mcu_pin_obj_t pin_PD08 = PIN(3, 8, NO_ADC); -const mcu_pin_obj_t pin_PD09 = PIN(3, 9, NO_ADC); -const mcu_pin_obj_t pin_PD10 = PIN(3, 10, NO_ADC); -const mcu_pin_obj_t pin_PD11 = PIN(3, 11, NO_ADC); -const mcu_pin_obj_t pin_PD12 = PIN(3, 12, NO_ADC); -const mcu_pin_obj_t pin_PD13 = PIN(3, 13, NO_ADC); -const mcu_pin_obj_t pin_PD14 = PIN(3, 14, NO_ADC); -const mcu_pin_obj_t pin_PD15 = PIN(3, 15, NO_ADC); - -const mcu_pin_obj_t pin_PG02 = PIN(6, 2, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG03 = PIN(6, 3, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG04 = PIN(6, 4, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG05 = PIN(6, 5, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG06 = PIN(6, 6, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG07 = PIN(6, 7, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG08 = PIN(6, 8, NO_ADC); // 144 only - -const mcu_pin_obj_t pin_PC06 = PIN(2, 6, NO_ADC); -const mcu_pin_obj_t pin_PC07 = PIN(2, 7, NO_ADC); -const mcu_pin_obj_t pin_PC08 = PIN(2, 8, NO_ADC); -const mcu_pin_obj_t pin_PC09 = PIN(2, 9, NO_ADC); - -const mcu_pin_obj_t pin_PA08 = PIN(0, 8, NO_ADC); -const mcu_pin_obj_t pin_PA09 = PIN(0, 9, NO_ADC); -const mcu_pin_obj_t pin_PA10 = PIN(0, 10, NO_ADC); -const mcu_pin_obj_t pin_PA11 = PIN(0, 11, NO_ADC); -const mcu_pin_obj_t pin_PA12 = PIN(0, 12, NO_ADC); -const mcu_pin_obj_t pin_PA13 = PIN(0, 13, NO_ADC); -const mcu_pin_obj_t pin_PA14 = PIN(0, 14, NO_ADC); -const mcu_pin_obj_t pin_PA15 = PIN(0, 15, NO_ADC); - -const mcu_pin_obj_t pin_PC10 = PIN(2, 10, NO_ADC); -const mcu_pin_obj_t pin_PC11 = PIN(2, 11, NO_ADC); -const mcu_pin_obj_t pin_PC12 = PIN(2, 12, NO_ADC); - -const mcu_pin_obj_t pin_PD00 = PIN(3, 0, NO_ADC); -const mcu_pin_obj_t pin_PD01 = PIN(3, 1, NO_ADC); -const mcu_pin_obj_t pin_PD02 = PIN(3, 2, NO_ADC); -const mcu_pin_obj_t pin_PD03 = PIN(3, 3, NO_ADC); -const mcu_pin_obj_t pin_PD04 = PIN(3, 4, NO_ADC); -const mcu_pin_obj_t pin_PD05 = PIN(3, 5, NO_ADC); -const mcu_pin_obj_t pin_PD06 = PIN(3, 6, NO_ADC); -const mcu_pin_obj_t pin_PD07 = PIN(3, 7, NO_ADC); - -const mcu_pin_obj_t pin_PG09 = PIN(6, 9, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG10 = PIN(6, 10, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG11 = PIN(6, 11, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG12 = PIN(6, 12, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG13 = PIN(6, 13, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG14 = PIN(6, 14, NO_ADC); // 144 only -const mcu_pin_obj_t pin_PG15 = PIN(6, 15, NO_ADC); // 144 only - -const mcu_pin_obj_t pin_PB03 = PIN(1, 3, NO_ADC); -const mcu_pin_obj_t pin_PB04 = PIN(1, 4, NO_ADC); -const mcu_pin_obj_t pin_PB05 = PIN(1, 5, NO_ADC); -const mcu_pin_obj_t pin_PB06 = PIN(1, 6, NO_ADC); -const mcu_pin_obj_t pin_PB07 = PIN(1, 7, NO_ADC); -const mcu_pin_obj_t pin_PB08 = PIN(1, 8, NO_ADC); -const mcu_pin_obj_t pin_PB09 = PIN(1, 9, NO_ADC); - -const mcu_pin_obj_t pin_PE00 = PIN(4, 0, NO_ADC); -const mcu_pin_obj_t pin_PE01 = PIN(4, 1, NO_ADC); +const mcu_pin_obj_t pin_PF00 = PIN(5, 0, NO_ADC); +const mcu_pin_obj_t pin_PF01 = PIN(5, 1, NO_ADC); +const mcu_pin_obj_t pin_PF02 = PIN(5, 2, NO_ADC); +const mcu_pin_obj_t pin_PF03 = PIN(5, 3, ADC_INPUT(ADC_3,9)); +const mcu_pin_obj_t pin_PF04 = PIN(5, 4, ADC_INPUT(ADC_3,14)); +const mcu_pin_obj_t pin_PF05 = PIN(5, 5, ADC_INPUT(ADC_3,15)); +const mcu_pin_obj_t pin_PF06 = PIN(5, 6, ADC_INPUT(ADC_3,4)); +const mcu_pin_obj_t pin_PF07 = PIN(5, 7, ADC_INPUT(ADC_3,5)); +const mcu_pin_obj_t pin_PF08 = PIN(5, 8, ADC_INPUT(ADC_3,6)); +const mcu_pin_obj_t pin_PF09 = PIN(5, 9, ADC_INPUT(ADC_3,7)); +const mcu_pin_obj_t pin_PF10 = PIN(5, 10, ADC_INPUT(ADC_3,8)); +const mcu_pin_obj_t pin_PF11 = PIN(5, 11, NO_ADC); +const mcu_pin_obj_t pin_PF12 = PIN(5, 12, NO_ADC); +const mcu_pin_obj_t pin_PF13 = PIN(5, 13, NO_ADC); +const mcu_pin_obj_t pin_PF14 = PIN(5, 14, NO_ADC); +const mcu_pin_obj_t pin_PF15 = PIN(5, 15, NO_ADC); +const mcu_pin_obj_t pin_PG00 = PIN(6, 0, NO_ADC); +const mcu_pin_obj_t pin_PG01 = PIN(6, 1, NO_ADC); +const mcu_pin_obj_t pin_PG02 = PIN(6, 2, NO_ADC); +const mcu_pin_obj_t pin_PG03 = PIN(6, 3, NO_ADC); +const mcu_pin_obj_t pin_PG04 = PIN(6, 4, NO_ADC); +const mcu_pin_obj_t pin_PG05 = PIN(6, 5, NO_ADC); +const mcu_pin_obj_t pin_PG06 = PIN(6, 6, NO_ADC); +const mcu_pin_obj_t pin_PG07 = PIN(6, 7, NO_ADC); +const mcu_pin_obj_t pin_PG08 = PIN(6, 8, NO_ADC); +const mcu_pin_obj_t pin_PG09 = PIN(6, 9, NO_ADC); +const mcu_pin_obj_t pin_PG10 = PIN(6, 10, NO_ADC); +const mcu_pin_obj_t pin_PG11 = PIN(6, 11, NO_ADC); +const mcu_pin_obj_t pin_PG12 = PIN(6, 12, NO_ADC); +const mcu_pin_obj_t pin_PG13 = PIN(6, 13, NO_ADC); +const mcu_pin_obj_t pin_PG14 = PIN(6, 14, NO_ADC); +const mcu_pin_obj_t pin_PG15 = PIN(6, 15, NO_ADC); +const mcu_pin_obj_t pin_PH00 = PIN(7, 0, NO_ADC); +const mcu_pin_obj_t pin_PH01 = PIN(7, 1, NO_ADC); +const mcu_pin_obj_t pin_PH02 = PIN(7, 2, NO_ADC); +const mcu_pin_obj_t pin_PH03 = PIN(7, 3, NO_ADC); +const mcu_pin_obj_t pin_PH04 = PIN(7, 4, NO_ADC); +const mcu_pin_obj_t pin_PH05 = PIN(7, 5, NO_ADC); +const mcu_pin_obj_t pin_PH06 = PIN(7, 6, NO_ADC); +const mcu_pin_obj_t pin_PH07 = PIN(7, 7, NO_ADC); +const mcu_pin_obj_t pin_PH08 = PIN(7, 8, NO_ADC); +const mcu_pin_obj_t pin_PH09 = PIN(7, 9, NO_ADC); +const mcu_pin_obj_t pin_PH10 = PIN(7, 10, NO_ADC); +const mcu_pin_obj_t pin_PH11 = PIN(7, 11, NO_ADC); +const mcu_pin_obj_t pin_PH12 = PIN(7, 12, NO_ADC); +const mcu_pin_obj_t pin_PH13 = PIN(7, 13, NO_ADC); +const mcu_pin_obj_t pin_PH14 = PIN(7, 14, NO_ADC); +const mcu_pin_obj_t pin_PH15 = PIN(7, 15, NO_ADC); +const mcu_pin_obj_t pin_PI00 = PIN(8, 0, NO_ADC); +const mcu_pin_obj_t pin_PI01 = PIN(8, 1, NO_ADC); +const mcu_pin_obj_t pin_PI02 = PIN(8, 2, NO_ADC); +const mcu_pin_obj_t pin_PI03 = PIN(8, 3, NO_ADC); +const mcu_pin_obj_t pin_PI04 = PIN(8, 4, NO_ADC); +const mcu_pin_obj_t pin_PI05 = PIN(8, 5, NO_ADC); +const mcu_pin_obj_t pin_PI06 = PIN(8, 6, NO_ADC); +const mcu_pin_obj_t pin_PI07 = PIN(8, 7, NO_ADC); +const mcu_pin_obj_t pin_PI08 = PIN(8, 8, NO_ADC); +const mcu_pin_obj_t pin_PI09 = PIN(8, 9, NO_ADC); +const mcu_pin_obj_t pin_PI10 = PIN(8, 10, NO_ADC); +const mcu_pin_obj_t pin_PI11 = PIN(8, 11, NO_ADC); diff --git a/ports/stm/peripherals/stm32f4/stm32f407xx/pins.h b/ports/stm/peripherals/stm32f4/stm32f407xx/pins.h index a247fe6312..74ba8da2ac 100644 --- a/ports/stm/peripherals/stm32f4/stm32f407xx/pins.h +++ b/ports/stm/peripherals/stm32f4/stm32f407xx/pins.h @@ -27,107 +27,54 @@ #ifndef MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PINS_H #define MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PINS_H -//Pins in datasheet order: DocID028087 Rev 7 page 50. LQFP100 only -//pg 50 -extern const mcu_pin_obj_t pin_PE02; -extern const mcu_pin_obj_t pin_PE03; -extern const mcu_pin_obj_t pin_PE04; -extern const mcu_pin_obj_t pin_PE05; -extern const mcu_pin_obj_t pin_PE06; -extern const mcu_pin_obj_t pin_PC13; -extern const mcu_pin_obj_t pin_PC14; -//pg 51 -extern const mcu_pin_obj_t pin_PC15; -extern const mcu_pin_obj_t pin_PF00; // 144 only -extern const mcu_pin_obj_t pin_PF01; // 144 only -extern const mcu_pin_obj_t pin_PF02; // 144 only -extern const mcu_pin_obj_t pin_PF03; // 144 only -extern const mcu_pin_obj_t pin_PF04; // 144 only -extern const mcu_pin_obj_t pin_PF05; // 144 only -extern const mcu_pin_obj_t pin_PF06; // 144 only -extern const mcu_pin_obj_t pin_PF07; // 144 only -extern const mcu_pin_obj_t pin_PF08; // 144 only -extern const mcu_pin_obj_t pin_PF09; // 144 only -extern const mcu_pin_obj_t pin_PF10; // 144 only -//pg 52 -extern const mcu_pin_obj_t pin_PC00; -extern const mcu_pin_obj_t pin_PC01; -extern const mcu_pin_obj_t pin_PC02; -extern const mcu_pin_obj_t pin_PC03; extern const mcu_pin_obj_t pin_PA00; extern const mcu_pin_obj_t pin_PA01; extern const mcu_pin_obj_t pin_PA02; -//pg 53 extern const mcu_pin_obj_t pin_PA03; extern const mcu_pin_obj_t pin_PA04; extern const mcu_pin_obj_t pin_PA05; extern const mcu_pin_obj_t pin_PA06; extern const mcu_pin_obj_t pin_PA07; -extern const mcu_pin_obj_t pin_PC04; -//pg 54 -extern const mcu_pin_obj_t pin_PC05; -extern const mcu_pin_obj_t pin_PB00; -extern const mcu_pin_obj_t pin_PB01; -extern const mcu_pin_obj_t pin_PB02; -extern const mcu_pin_obj_t pin_PF11; // 144 only -extern const mcu_pin_obj_t pin_PF12; // 144 only -extern const mcu_pin_obj_t pin_PF13; // 144 only -extern const mcu_pin_obj_t pin_PF14; // 144 only -extern const mcu_pin_obj_t pin_PF15; // 144 only -extern const mcu_pin_obj_t pin_PG00; // 144 only -extern const mcu_pin_obj_t pin_PG01; // 144 only -//pg 55 -extern const mcu_pin_obj_t pin_PE07; -extern const mcu_pin_obj_t pin_PE08; -extern const mcu_pin_obj_t pin_PE09; -extern const mcu_pin_obj_t pin_PE10; -extern const mcu_pin_obj_t pin_PE11; -extern const mcu_pin_obj_t pin_PE12; -extern const mcu_pin_obj_t pin_PE13; -extern const mcu_pin_obj_t pin_PE14; -//pg 56 -extern const mcu_pin_obj_t pin_PE15; -extern const mcu_pin_obj_t pin_PB10; -extern const mcu_pin_obj_t pin_PB11; // 144 only -extern const mcu_pin_obj_t pin_PB12; -extern const mcu_pin_obj_t pin_PB13; -//pg 57 -extern const mcu_pin_obj_t pin_PB14; -extern const mcu_pin_obj_t pin_PB15; -extern const mcu_pin_obj_t pin_PD08; -extern const mcu_pin_obj_t pin_PD09; -extern const mcu_pin_obj_t pin_PD10; -extern const mcu_pin_obj_t pin_PD11; -extern const mcu_pin_obj_t pin_PD12; -//pg 58 -extern const mcu_pin_obj_t pin_PD13; -extern const mcu_pin_obj_t pin_PD14; -extern const mcu_pin_obj_t pin_PD15; -extern const mcu_pin_obj_t pin_PG02; // 144 only -extern const mcu_pin_obj_t pin_PG03; // 144 only -extern const mcu_pin_obj_t pin_PG04; // 144 only -extern const mcu_pin_obj_t pin_PG05; // 144 only -extern const mcu_pin_obj_t pin_PG06; // 144 only -extern const mcu_pin_obj_t pin_PG07; // 144 only -extern const mcu_pin_obj_t pin_PG08; // 144 only -//pg 59 -extern const mcu_pin_obj_t pin_PC06; -extern const mcu_pin_obj_t pin_PC07; -extern const mcu_pin_obj_t pin_PC08; -extern const mcu_pin_obj_t pin_PC09; extern const mcu_pin_obj_t pin_PA08; extern const mcu_pin_obj_t pin_PA09; extern const mcu_pin_obj_t pin_PA10; -//pg 60 extern const mcu_pin_obj_t pin_PA11; extern const mcu_pin_obj_t pin_PA12; extern const mcu_pin_obj_t pin_PA13; extern const mcu_pin_obj_t pin_PA14; extern const mcu_pin_obj_t pin_PA15; +extern const mcu_pin_obj_t pin_PB00; +extern const mcu_pin_obj_t pin_PB01; +extern const mcu_pin_obj_t pin_PB02; +extern const mcu_pin_obj_t pin_PB03; +extern const mcu_pin_obj_t pin_PB04; +extern const mcu_pin_obj_t pin_PB05; +extern const mcu_pin_obj_t pin_PB06; +extern const mcu_pin_obj_t pin_PB07; +extern const mcu_pin_obj_t pin_PB08; +extern const mcu_pin_obj_t pin_PB09; +extern const mcu_pin_obj_t pin_PB10; +extern const mcu_pin_obj_t pin_PB11; +extern const mcu_pin_obj_t pin_PB12; +extern const mcu_pin_obj_t pin_PB13; +extern const mcu_pin_obj_t pin_PB14; +extern const mcu_pin_obj_t pin_PB15; +extern const mcu_pin_obj_t pin_PC00; +extern const mcu_pin_obj_t pin_PC01; +extern const mcu_pin_obj_t pin_PC02; +extern const mcu_pin_obj_t pin_PC03; +extern const mcu_pin_obj_t pin_PC04; +extern const mcu_pin_obj_t pin_PC05; +extern const mcu_pin_obj_t pin_PC06; +extern const mcu_pin_obj_t pin_PC07; +extern const mcu_pin_obj_t pin_PC08; +extern const mcu_pin_obj_t pin_PC09; extern const mcu_pin_obj_t pin_PC10; extern const mcu_pin_obj_t pin_PC11; -//pg 61 extern const mcu_pin_obj_t pin_PC12; +extern const mcu_pin_obj_t pin_PC13; +extern const mcu_pin_obj_t pin_PC14; +extern const mcu_pin_obj_t pin_PC15; extern const mcu_pin_obj_t pin_PD00; extern const mcu_pin_obj_t pin_PD01; extern const mcu_pin_obj_t pin_PD02; @@ -136,23 +83,89 @@ extern const mcu_pin_obj_t pin_PD04; extern const mcu_pin_obj_t pin_PD05; extern const mcu_pin_obj_t pin_PD06; extern const mcu_pin_obj_t pin_PD07; -//pg 62 -extern const mcu_pin_obj_t pin_PG09; // 144 only -extern const mcu_pin_obj_t pin_PG10; // 144 only -extern const mcu_pin_obj_t pin_PG11; // 144 only -extern const mcu_pin_obj_t pin_PG12; // 144 only -extern const mcu_pin_obj_t pin_PG13; // 144 only -extern const mcu_pin_obj_t pin_PG14; // 144 only -extern const mcu_pin_obj_t pin_PG15; // 144 only -extern const mcu_pin_obj_t pin_PB03; -extern const mcu_pin_obj_t pin_PB04; -//pg 63 -extern const mcu_pin_obj_t pin_PB05; -extern const mcu_pin_obj_t pin_PB06; -extern const mcu_pin_obj_t pin_PB07; -extern const mcu_pin_obj_t pin_PB08; -extern const mcu_pin_obj_t pin_PB09; +extern const mcu_pin_obj_t pin_PD08; +extern const mcu_pin_obj_t pin_PD09; +extern const mcu_pin_obj_t pin_PD10; +extern const mcu_pin_obj_t pin_PD11; +extern const mcu_pin_obj_t pin_PD12; +extern const mcu_pin_obj_t pin_PD13; +extern const mcu_pin_obj_t pin_PD14; +extern const mcu_pin_obj_t pin_PD15; extern const mcu_pin_obj_t pin_PE00; extern const mcu_pin_obj_t pin_PE01; +extern const mcu_pin_obj_t pin_PE02; +extern const mcu_pin_obj_t pin_PE03; +extern const mcu_pin_obj_t pin_PE04; +extern const mcu_pin_obj_t pin_PE05; +extern const mcu_pin_obj_t pin_PE06; +extern const mcu_pin_obj_t pin_PE07; +extern const mcu_pin_obj_t pin_PE08; +extern const mcu_pin_obj_t pin_PE09; +extern const mcu_pin_obj_t pin_PE10; +extern const mcu_pin_obj_t pin_PE11; +extern const mcu_pin_obj_t pin_PE12; +extern const mcu_pin_obj_t pin_PE13; +extern const mcu_pin_obj_t pin_PE14; +extern const mcu_pin_obj_t pin_PE15; +extern const mcu_pin_obj_t pin_PF00; +extern const mcu_pin_obj_t pin_PF01; +extern const mcu_pin_obj_t pin_PF02; +extern const mcu_pin_obj_t pin_PF03; +extern const mcu_pin_obj_t pin_PF04; +extern const mcu_pin_obj_t pin_PF05; +extern const mcu_pin_obj_t pin_PF06; +extern const mcu_pin_obj_t pin_PF07; +extern const mcu_pin_obj_t pin_PF08; +extern const mcu_pin_obj_t pin_PF09; +extern const mcu_pin_obj_t pin_PF10; +extern const mcu_pin_obj_t pin_PF11; +extern const mcu_pin_obj_t pin_PF12; +extern const mcu_pin_obj_t pin_PF13; +extern const mcu_pin_obj_t pin_PF14; +extern const mcu_pin_obj_t pin_PF15; +extern const mcu_pin_obj_t pin_PG00; +extern const mcu_pin_obj_t pin_PG01; +extern const mcu_pin_obj_t pin_PG02; +extern const mcu_pin_obj_t pin_PG03; +extern const mcu_pin_obj_t pin_PG04; +extern const mcu_pin_obj_t pin_PG05; +extern const mcu_pin_obj_t pin_PG06; +extern const mcu_pin_obj_t pin_PG07; +extern const mcu_pin_obj_t pin_PG08; +extern const mcu_pin_obj_t pin_PG09; +extern const mcu_pin_obj_t pin_PG10; +extern const mcu_pin_obj_t pin_PG11; +extern const mcu_pin_obj_t pin_PG12; +extern const mcu_pin_obj_t pin_PG13; +extern const mcu_pin_obj_t pin_PG14; +extern const mcu_pin_obj_t pin_PG15; +extern const mcu_pin_obj_t pin_PH00; +extern const mcu_pin_obj_t pin_PH01; +extern const mcu_pin_obj_t pin_PH02; +extern const mcu_pin_obj_t pin_PH03; +extern const mcu_pin_obj_t pin_PH04; +extern const mcu_pin_obj_t pin_PH05; +extern const mcu_pin_obj_t pin_PH06; +extern const mcu_pin_obj_t pin_PH07; +extern const mcu_pin_obj_t pin_PH08; +extern const mcu_pin_obj_t pin_PH09; +extern const mcu_pin_obj_t pin_PH10; +extern const mcu_pin_obj_t pin_PH11; +extern const mcu_pin_obj_t pin_PH12; +extern const mcu_pin_obj_t pin_PH13; +extern const mcu_pin_obj_t pin_PH14; +extern const mcu_pin_obj_t pin_PH15; +extern const mcu_pin_obj_t pin_PI00; +extern const mcu_pin_obj_t pin_PI01; +extern const mcu_pin_obj_t pin_PI02; +extern const mcu_pin_obj_t pin_PI03; +extern const mcu_pin_obj_t pin_PI04; +extern const mcu_pin_obj_t pin_PI05; +extern const mcu_pin_obj_t pin_PI06; +extern const mcu_pin_obj_t pin_PI07; +extern const mcu_pin_obj_t pin_PI08; +extern const mcu_pin_obj_t pin_PI09; +extern const mcu_pin_obj_t pin_PI10; +extern const mcu_pin_obj_t pin_PI11; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PINS_H From 76d0870fba5a86813242c37ee653c1fc7e008c65 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Thu, 11 Mar 2021 18:04:01 +0100 Subject: [PATCH 34/48] spresense: return error as positive value for i2c --- ports/cxd56/common-hal/busio/I2C.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/cxd56/common-hal/busio/I2C.c b/ports/cxd56/common-hal/busio/I2C.c index 127b6e75cd..5579bedeb1 100644 --- a/ports/cxd56/common-hal/busio/I2C.c +++ b/ports/cxd56/common-hal/busio/I2C.c @@ -103,7 +103,7 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t address, cons msg.flags = (stop ? 0 : I2C_M_NOSTOP); msg.buffer = (uint8_t *) data; msg.length = len; - return I2C_TRANSFER(self->i2c_dev, &msg, 1); + return -I2C_TRANSFER(self->i2c_dev, &msg, 1); } uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t address, uint8_t *data, size_t len) { @@ -114,7 +114,7 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t address, uint8 msg.flags = I2C_M_READ; msg.buffer = data; msg.length = len; - return I2C_TRANSFER(self->i2c_dev, &msg, 1); + return -I2C_TRANSFER(self->i2c_dev, &msg, 1); } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { From 18668f6e2848a5a36d37df42354ecd1ee53786ba Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Thu, 11 Mar 2021 18:06:49 +0100 Subject: [PATCH 35/48] spresense: fix spi to work with only one data pin --- ports/cxd56/common-hal/busio/SPI.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/cxd56/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c index 2d365d4826..56ab0758d4 100644 --- a/ports/cxd56/common-hal/busio/SPI.c +++ b/ports/cxd56/common-hal/busio/SPI.c @@ -35,9 +35,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso) { int port = -1; - if (clock->number == PIN_SPI4_SCK && mosi->number == PIN_SPI4_MOSI && miso->number == PIN_SPI4_MISO) { + if (clock->number == PIN_SPI4_SCK && + (mosi == NULL || mosi->number == PIN_SPI4_MOSI) && + (miso == NULL || miso->number == PIN_SPI4_MISO)) { port = 4; - } else if (clock->number == PIN_EMMC_CLK && mosi->number == PIN_EMMC_DATA0 && miso->number == PIN_EMMC_DATA1) { + } else if (clock->number == PIN_EMMC_CLK && + (mosi == NULL || mosi->number == PIN_EMMC_DATA0) && + (miso == NULL || miso->number == PIN_EMMC_DATA1)) { port = 5; } From 061d5910cb6e6eecda70a7a7a5320a414e8b3b9e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 12:09:01 -0500 Subject: [PATCH 36/48] use fixed esp-idf --- lib/tinyusb | 2 +- ports/esp32s2/esp-idf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 280297bdb7..2adb7e7193 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 280297bdb7aec67adf347ec046943a48a71647df +Subproject commit 2adb7e719316b12c53a907153cfa0056db1abd70 diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index ebe7784258..8dd3ea82f1 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit ebe7784258d8c10e9cc334ccc00c3fd270746c8b +Subproject commit 8dd3ea82f16a23bc31b194670627cea898e49935 From f75a009ed432221c2afd7546f77bce38bc7855fb Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 15:16:32 -0500 Subject: [PATCH 37/48] fix unnecessary statement order change --- ports/esp32s2/common-hal/busio/I2C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index c1a0f75ac4..e3586ab186 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -144,8 +144,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { i2c_driver_delete(self->i2c_num); - common_hal_reset_pin(self->scl_pin); common_hal_reset_pin(self->sda_pin); + common_hal_reset_pin(self->scl_pin); self->sda_pin = NULL; self->scl_pin = NULL; From a9afa0d9d4c66cda8fe7e6c1a72765e704e94985 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 11 Mar 2021 16:18:17 -0600 Subject: [PATCH 38/48] Move input checks to shared-module, update docstrings --- shared-bindings/bitmaptools/__init__.c | 38 ++---------------------- shared-module/bitmaptools/__init__.c | 40 +++++++++++++++++++------- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/shared-bindings/bitmaptools/__init__.c b/shared-bindings/bitmaptools/__init__.c index 6804889081..118564ff85 100644 --- a/shared-bindings/bitmaptools/__init__.c +++ b/shared-bindings/bitmaptools/__init__.c @@ -255,8 +255,8 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_rotozoom_obj, 0, bitmaptools_obj_rotozoom //| :param bitmap dest_bitmap: Destination bitmap that will be written into //| :param int x1: x-pixel position of the first corner of the rectangular fill region //| :param int y1: y-pixel position of the first corner of the rectangular fill region -//| :param int x2: x-pixel position of the second corner of the rectangular fill region -//| :param int y2: y-pixel position of the second corner of the rectangular fill region +//| :param int x2: x-pixel position of the second corner of the rectangular fill region (exclusive) +//| :param int y2: y-pixel position of the second corner of the rectangular fill region (exclusive) //| :param int value: Bitmap palette index that will be written into the rectangular //| fill region in the destination bitmap""" //| ... @@ -289,40 +289,6 @@ STATIC mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_a int16_t x2 = args[ARG_x2].u_int; int16_t y2 = args[ARG_y2].u_int; - // Ensure x1 < x2 and y1 < y2 - if (x1 > x2) { - int16_t temp=x2; - x2=x1; - x1=temp; - } - if (y1 > y2) { - int16_t temp=y2; - y2=y1; - y1=temp; - } - - // constrain to bitmap dimensions - if (x1 < 0) { - x1 = 0; - } else if (x1 > destination->width) { - x1 = destination->width; - } - if (x2 < 0) { - x2 = 0; - } else if (x2 > destination->width) { - x2 = destination->width; - } - if (y1 < 0) { - y1 = 0; - } else if (y1 > destination->height) { - y1 = destination->height; - } - if (y2 < 0) { - y2 = 0; - } else if (y2 > destination->height) { - y2 = destination->height; - } - common_hal_bitmaptools_fill_region(destination, x1, y1, x2, y2, value); return mp_const_none; diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c index 72db55c242..6f168b5552 100644 --- a/shared-module/bitmaptools/__init__.c +++ b/shared-module/bitmaptools/__init__.c @@ -175,6 +175,17 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16 } } +int16_t constrain(int16_t input, int16_t min, int16_t max) { + // constrain the input between the min and max values + if (input < min) { + return min; + } + if (input > max) { + return max; + } + return input; +} + void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination, int16_t x1, int16_t y1, int16_t x2, int16_t y2, @@ -187,6 +198,24 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination, mp_raise_RuntimeError(translate("Read-only object")); } + // Ensure x1 < x2 and y1 < y2 + if (x1 > x2) { + int16_t temp=x2; + x2=x1; + x1=temp; + } + if (y1 > y2) { + int16_t temp=y2; + y2=y1; + y1=temp; + } + + // constrain to bitmap dimensions + x1 = constrain(x1, 0, destination->width); + x2 = constrain(x2, 0, destination->width); + y1 = constrain(y1, 0, destination->height); + y2 = constrain(y2, 0, destination->height); + // update the dirty rectangle displayio_bitmap_set_dirty_area(destination, x1, y1, x2, y2); @@ -198,17 +227,6 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination, } } -int16_t constrain(int16_t input, int16_t min, int16_t max) { - // constrain the input between the min and max values - if (input < min) { - return min; - } - if (input > max) { - return max; - } - return input; -} - void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination, int16_t x0, int16_t y0, int16_t x1, int16_t y1, From c71b6cb699299fb12394ad07afeb54b81be9f581 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 20:05:31 -0500 Subject: [PATCH 39/48] move to esp-idf PR merge --- ports/esp32s2/esp-idf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index 8dd3ea82f1..f30a865fd1 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit 8dd3ea82f16a23bc31b194670627cea898e49935 +Subproject commit f30a865fd1a44d880b909b84112f74741412c2ce From fa34b8a40475724a7072ba85b05415c607915b19 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Mar 2021 21:02:07 -0500 Subject: [PATCH 40/48] correct clock stretch timeout for board.I2C() --- shared-module/board/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 2f1c34e565..5d45d58b43 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -60,7 +60,7 @@ mp_obj_t common_hal_board_create_i2c(void) { busio_i2c_obj_t *self = &i2c_obj; self->base.type = &busio_i2c_type; - common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 100000, 0); + common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 100000, 255); i2c_singleton = (mp_obj_t)self; return i2c_singleton; } From 06cabd69952bfd847d7ff65b7f8683cab3a3a0c8 Mon Sep 17 00:00:00 2001 From: Alvaro Figueroa Date: Thu, 11 Mar 2021 01:38:02 +0000 Subject: [PATCH 41/48] Translated using Weblate (Spanish) Currently translated at 100.0% (975 of 975 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/es/ --- locale/es.po | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/locale/es.po b/locale/es.po index ecd6b0042a..a9c5063f06 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,15 +8,15 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-03-07 15:50+0000\n" -"Last-Translator: Jose David M \n" +"PO-Revision-Date: 2021-03-12 02:03+0000\n" +"Last-Translator: Alvaro Figueroa \n" "Language-Team: \n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.5.1\n" +"X-Generator: Weblate 4.5.2-dev\n" #: main.c msgid "" @@ -1836,7 +1836,7 @@ msgstr "" #: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c msgid "Pins must be sequential" -msgstr "" +msgstr "Los pines deben estar en orden secuencial" #: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c msgid "Pins must share PWM slice" @@ -2142,11 +2142,10 @@ msgid "" "enough power for the whole circuit and press reset (after ejecting " "CIRCUITPY).\n" msgstr "" -"La alimentación del microntrolador cayó. Asegúrate que tu fuente de " +"La alimentación del microntrolador bajó. Asegúrate que tu fuente de " "alimentación\n" -"pueda aportar suficiente energía para todo el circuito y presiona reset " -"(luego de\n" -"expulsar CIRCUITPY)\n" +"pueda aportar suficiente energía para todo el circuito y presiona reset (" +"luego de expulsar CIRCUITPY)\n" #: shared-module/audiomixer/MixerVoice.c msgid "The sample's bits_per_sample does not match the mixer's" @@ -2818,7 +2817,7 @@ msgstr "circulo solo puede ser registrado con un pariente" #: shared-bindings/bitmaptools/__init__.c msgid "clip point must be (x,y) tuple" -msgstr "El punto clip debe ser una tupla (x, y)" +msgstr "El punto de recorte debe ser una tupla (x, y)" #: shared-bindings/msgpack/ExtType.c msgid "code outside range 0~127" @@ -3842,7 +3841,7 @@ msgstr "presionando ambos botones al inicio.\n" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" -msgstr "" +msgstr "máscara de pull en conflicto con máscara de dirección" #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "pull_threshold must be between 1 and 32" From 0ce5b2f5941f0dc11c3c0e9ca0ad054432ce652c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 12 Mar 2021 08:20:09 -0500 Subject: [PATCH 42/48] put back pullup setting --- ports/esp32s2/common-hal/busio/I2C.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/esp32s2/common-hal/busio/I2C.c b/ports/esp32s2/common-hal/busio/I2C.c index e3586ab186..a1d0b8f9c4 100644 --- a/ports/esp32s2/common-hal/busio/I2C.c +++ b/ports/esp32s2/common-hal/busio/I2C.c @@ -112,6 +112,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, .mode = I2C_MODE_MASTER, .sda_io_num = self->sda_pin->number, .scl_io_num = self->scl_pin->number, + .sda_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C sda signal*/ + .scl_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C scl signal*/ .master = { .clk_speed = frequency, From 8265c321f6d94c8322db604d73e49b4746f40a95 Mon Sep 17 00:00:00 2001 From: Artyom Skrobov Date: Fri, 12 Mar 2021 10:01:14 -0500 Subject: [PATCH 43/48] [vfs_fat_diskio] pdrv is not a drive number since f5f4cdae89 --- extmod/vfs_fat_diskio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 432c03b7c9..127b77d7dd 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -34,7 +34,7 @@ STATIC fs_user_mount_t *disk_get_device(void *bdev) { /*-----------------------------------------------------------------------*/ DRESULT disk_read ( - bdev_t pdrv, /* Physical drive nmuber (0..) */ + bdev_t pdrv, /* Physical drive */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ UINT count /* Number of sectors to read (1..128) */ @@ -75,7 +75,7 @@ DRESULT disk_read ( /*-----------------------------------------------------------------------*/ DRESULT disk_write ( - bdev_t pdrv, /* Physical drive nmuber (0..) */ + bdev_t pdrv, /* Physical drive */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ UINT count /* Number of sectors to write (1..128) */ @@ -122,7 +122,7 @@ DRESULT disk_write ( /*-----------------------------------------------------------------------*/ DRESULT disk_ioctl ( - bdev_t pdrv, /* Physical drive nmuber (0..) */ + bdev_t pdrv, /* Physical drive */ BYTE cmd, /* Control code */ void *buff /* Buffer to send/receive control data */ ) From aec03a409f66cdb90e1b51c7ffb827750eadd830 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 12 Mar 2021 11:06:39 -0800 Subject: [PATCH 44/48] Lower default flash speed. / 6 leads to ~40mhz. 2M and 4M have a max 0x03 read speed of 60mhz. If the divisor is / 4 then the speed is just over 60mhz. Fixes #4377 --- ports/raspberrypi/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index db4bd79581..413480d108 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -234,7 +234,7 @@ SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_ SRC_S = supervisor/$(CHIP_FAMILY)_cpu.s BOOT2_S_UPPER ?= sdk/src/rp2_common/boot_stage2/boot2_generic_03h.S -BOOT2_S_CFLAGS ?= -DPICO_FLASH_SPI_CLKDIV=2 +BOOT2_S_CFLAGS ?= -DPICO_FLASH_SPI_CLKDIV=6 SRC_S_UPPER = sdk/src/rp2_common/hardware_divider/divider.S \ sdk/src/rp2_common/hardware_irq/irq_handler_chain.S \ sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S \ From 6628f49852a4963cb2aeaa08fa281eb0e994415e Mon Sep 17 00:00:00 2001 From: DavePutz Date: Fri, 12 Mar 2021 16:06:57 -0600 Subject: [PATCH 45/48] Use StateMachine.c interrupt setup and simplify SM program --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 37 +++++++++++++++++++ .../raspberrypi/common-hal/pulseio/PulseIn.h | 3 ++ 2 files changed, 40 insertions(+) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 8ddeab9308..1a30373fcc 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -25,7 +25,10 @@ */ #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +<<<<<<< HEAD +======= #include "src/rp2_common/hardware_irq/include/hardware/irq.h" +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d #include @@ -46,12 +49,16 @@ volatile uint16_t result = 0; volatile uint16_t buf_index = 0; uint16_t pulsein_program[] = { +<<<<<<< HEAD + 0x4001, // 1: in pins, 1 +======= 0xe03f, // 0: set x, 31 0x4001, // 1: in pins, 1 0x0041, // 2: jmp x--, 2 0x8060, // 3: push iffull block 0xc020, // 4: irq wait 0 0x0000, // 5: jmp 1 +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d }; void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, @@ -73,7 +80,11 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, bool ok = rp2pio_statemachine_construct(&state_machine, pulsein_program, sizeof(pulsein_program) / sizeof(pulsein_program[0]), +<<<<<<< HEAD + 1000000, +======= 1000000 * 3, +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d NULL, 0, NULL, 0, pin, 1, @@ -91,11 +102,14 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, self->state_machine.state_machine = state_machine.state_machine; self->state_machine.sm_config = state_machine.sm_config; self->state_machine.offset = state_machine.offset; +<<<<<<< HEAD +======= if ( self->state_machine.pio == pio0 ) { self->pio_interrupt = PIO0_IRQ_0; } else { self->pio_interrupt = PIO1_IRQ_0; } +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d pio_sm_clear_fifos(self->state_machine.pio,self->state_machine.state_machine); last_level = self->idle_state; level_count = 0; @@ -103,9 +117,13 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, buf_index = 0; pio_sm_set_in_pins(state_machine.pio,state_machine.state_machine,pin->number); +<<<<<<< HEAD + common_hal_rp2pio_statemachine_set_interrupt_handler(&state_machine,&common_hal_pulseio_pulsein_interrupt,NULL,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS); +======= irq_set_exclusive_handler(self->pio_interrupt, common_hal_pulseio_pulsein_interrupt); hw_clear_bits(&state_machine.pio->inte0, 1u << state_machine.state_machine); hw_set_bits(&state_machine.pio->inte0, 1u << (state_machine.state_machine+8)); +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d // exec a set pindirs to 0 for input pio_sm_exec(state_machine.pio,state_machine.state_machine,0xe080); @@ -116,7 +134,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); } pio_sm_set_enabled(state_machine.pio, state_machine.state_machine, true); +<<<<<<< HEAD +======= irq_set_enabled(self->pio_interrupt, true); +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { @@ -127,7 +148,10 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { if (common_hal_pulseio_pulsein_deinited(self)) { return; } +<<<<<<< HEAD +======= irq_set_enabled(self->pio_interrupt, false); +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_unclaim (self->state_machine.pio, self->state_machine.state_machine); m_free(self->buffer); @@ -161,17 +185,23 @@ void common_hal_pulseio_pulsein_interrupt() { } } } +<<<<<<< HEAD +======= // clear interrupt irq_clear(self->pio_interrupt); hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); self->state_machine.pio->irq = 1u << self->state_machine.state_machine; +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d // check for a pulse thats too long (4000 us) or maxlen reached, and reset if (( level_count > 4000 ) || (buf_index >= self->maxlen)) { pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); +<<<<<<< HEAD +======= irq_set_enabled(self->pio_interrupt, true); +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d } } void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, @@ -189,10 +219,17 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, gpio_put(self->pin, !self->idle_state); common_hal_mcu_delay_us((uint32_t)trigger_duration); gpio_set_function(self->pin ,GPIO_FUNC_PIO0); +<<<<<<< HEAD + common_hal_mcu_delay_us(225); + } + + // Reconfigure the pin for PIO +======= } // Reconfigure the pin for PIO common_hal_mcu_delay_us(200); +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d gpio_set_function(self->pin, GPIO_FUNC_PIO0); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); } diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h index e99e1ff822..39199e5249 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -42,7 +42,10 @@ typedef struct { volatile uint16_t start; volatile uint16_t len; rp2pio_statemachine_obj_t state_machine; +<<<<<<< HEAD +======= uint16_t pio_interrupt; +>>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d } pulseio_pulsein_obj_t; void pulsein_reset(void); From 96ce43e6d6eaad1ef4d7ab455f594ed64169bc9d Mon Sep 17 00:00:00 2001 From: DavePutz Date: Fri, 12 Mar 2021 16:18:33 -0600 Subject: [PATCH 46/48] Added the correct files --- .../raspberrypi/common-hal/pulseio/PulseIn.c | 57 ------------------- .../raspberrypi/common-hal/pulseio/PulseIn.h | 4 -- 2 files changed, 61 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 1a30373fcc..e05b35536c 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -25,10 +25,6 @@ */ #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" -<<<<<<< HEAD -======= -#include "src/rp2_common/hardware_irq/include/hardware/irq.h" ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d #include @@ -49,16 +45,7 @@ volatile uint16_t result = 0; volatile uint16_t buf_index = 0; uint16_t pulsein_program[] = { -<<<<<<< HEAD 0x4001, // 1: in pins, 1 -======= - 0xe03f, // 0: set x, 31 - 0x4001, // 1: in pins, 1 - 0x0041, // 2: jmp x--, 2 - 0x8060, // 3: push iffull block - 0xc020, // 4: irq wait 0 - 0x0000, // 5: jmp 1 ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d }; void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, @@ -80,11 +67,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, bool ok = rp2pio_statemachine_construct(&state_machine, pulsein_program, sizeof(pulsein_program) / sizeof(pulsein_program[0]), -<<<<<<< HEAD 1000000, -======= - 1000000 * 3, ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d NULL, 0, NULL, 0, pin, 1, @@ -102,14 +85,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, self->state_machine.state_machine = state_machine.state_machine; self->state_machine.sm_config = state_machine.sm_config; self->state_machine.offset = state_machine.offset; -<<<<<<< HEAD -======= - if ( self->state_machine.pio == pio0 ) { - self->pio_interrupt = PIO0_IRQ_0; - } else { - self->pio_interrupt = PIO1_IRQ_0; - } ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d pio_sm_clear_fifos(self->state_machine.pio,self->state_machine.state_machine); last_level = self->idle_state; level_count = 0; @@ -117,13 +92,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, buf_index = 0; pio_sm_set_in_pins(state_machine.pio,state_machine.state_machine,pin->number); -<<<<<<< HEAD common_hal_rp2pio_statemachine_set_interrupt_handler(&state_machine,&common_hal_pulseio_pulsein_interrupt,NULL,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS); -======= - irq_set_exclusive_handler(self->pio_interrupt, common_hal_pulseio_pulsein_interrupt); - hw_clear_bits(&state_machine.pio->inte0, 1u << state_machine.state_machine); - hw_set_bits(&state_machine.pio->inte0, 1u << (state_machine.state_machine+8)); ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d // exec a set pindirs to 0 for input pio_sm_exec(state_machine.pio,state_machine.state_machine,0xe080); @@ -134,10 +103,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); } pio_sm_set_enabled(state_machine.pio, state_machine.state_machine, true); -<<<<<<< HEAD -======= - irq_set_enabled(self->pio_interrupt, true); ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { @@ -148,10 +113,6 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { if (common_hal_pulseio_pulsein_deinited(self)) { return; } -<<<<<<< HEAD -======= - irq_set_enabled(self->pio_interrupt, false); ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_unclaim (self->state_machine.pio, self->state_machine.state_machine); m_free(self->buffer); @@ -185,23 +146,12 @@ void common_hal_pulseio_pulsein_interrupt() { } } } -<<<<<<< HEAD -======= -// clear interrupt - irq_clear(self->pio_interrupt); - hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine); - self->state_machine.pio->irq = 1u << self->state_machine.state_machine; ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d // check for a pulse thats too long (4000 us) or maxlen reached, and reset if (( level_count > 4000 ) || (buf_index >= self->maxlen)) { pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); -<<<<<<< HEAD -======= - irq_set_enabled(self->pio_interrupt, true); ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d } } void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, @@ -219,17 +169,10 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, gpio_put(self->pin, !self->idle_state); common_hal_mcu_delay_us((uint32_t)trigger_duration); gpio_set_function(self->pin ,GPIO_FUNC_PIO0); -<<<<<<< HEAD common_hal_mcu_delay_us(225); } // Reconfigure the pin for PIO -======= - } - - // Reconfigure the pin for PIO - common_hal_mcu_delay_us(200); ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d gpio_set_function(self->pin, GPIO_FUNC_PIO0); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); } diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.h b/ports/raspberrypi/common-hal/pulseio/PulseIn.h index 39199e5249..c83a86fca0 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.h +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.h @@ -42,10 +42,6 @@ typedef struct { volatile uint16_t start; volatile uint16_t len; rp2pio_statemachine_obj_t state_machine; -<<<<<<< HEAD -======= - uint16_t pio_interrupt; ->>>>>>> a3c3e8a0fa5e06910747f1a95a12b899562a618d } pulseio_pulsein_obj_t; void pulsein_reset(void); From 45487f14a0c0623af8fad817ca8ab43c9490ca2c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 12 Mar 2021 15:58:38 -0800 Subject: [PATCH 47/48] Speed up a bit more --- ports/raspberrypi/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 413480d108..2c1a13a8b2 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -234,7 +234,7 @@ SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_ SRC_S = supervisor/$(CHIP_FAMILY)_cpu.s BOOT2_S_UPPER ?= sdk/src/rp2_common/boot_stage2/boot2_generic_03h.S -BOOT2_S_CFLAGS ?= -DPICO_FLASH_SPI_CLKDIV=6 +BOOT2_S_CFLAGS ?= -DPICO_FLASH_SPI_CLKDIV=4 SRC_S_UPPER = sdk/src/rp2_common/hardware_divider/divider.S \ sdk/src/rp2_common/hardware_irq/irq_handler_chain.S \ sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S \ From a8ea24849f1a98b86f2ad8e6108ad15d3c4a59eb Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Sat, 13 Mar 2021 01:50:44 +0100 Subject: [PATCH 48/48] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 2 +- locale/cs.po | 2 +- locale/de_DE.po | 2 +- locale/el.po | 2 +- locale/en_GB.po | 2 +- locale/es.po | 6 +++--- locale/fil.po | 2 +- locale/fr.po | 2 +- locale/hi.po | 2 +- locale/it_IT.po | 2 +- locale/ja.po | 2 +- locale/ko.po | 2 +- locale/nl.po | 2 +- locale/pl.po | 2 +- locale/pt_BR.po | 2 +- locale/sv.po | 2 +- locale/zh_Latn_pinyin.po | 2 +- 17 files changed, 19 insertions(+), 19 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index fbcd82940c..77a7b32072 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -3695,7 +3695,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index 57dd3cd760..d7658965f7 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -3646,7 +3646,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index b000590f7c..ff37ab3e4b 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -3732,7 +3732,7 @@ msgstr "" msgid "out of range of source" msgstr "Außerhalb des Bereichs der Quelle" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "Außerhalb des Bereichs des Ziels" diff --git a/locale/el.po b/locale/el.po index 309d3b86a9..3e2e896a09 100644 --- a/locale/el.po +++ b/locale/el.po @@ -3643,7 +3643,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index 6db894d453..e192b0eaf2 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -3642,7 +3642,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/es.po b/locale/es.po index a9c5063f06..529c987dab 100644 --- a/locale/es.po +++ b/locale/es.po @@ -2144,8 +2144,8 @@ msgid "" msgstr "" "La alimentación del microntrolador bajó. Asegúrate que tu fuente de " "alimentación\n" -"pueda aportar suficiente energía para todo el circuito y presiona reset (" -"luego de expulsar CIRCUITPY)\n" +"pueda aportar suficiente energía para todo el circuito y presiona reset " +"(luego de expulsar CIRCUITPY)\n" #: shared-module/audiomixer/MixerVoice.c msgid "The sample's bits_per_sample does not match the mixer's" @@ -3739,7 +3739,7 @@ msgstr "ord() espera un carácter, pero encontró un string de longitud %d" msgid "out of range of source" msgstr "fuera de rango de fuente" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "fuera de rango del objetivo" diff --git a/locale/fil.po b/locale/fil.po index 046ed0e8fb..b49fd072f9 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -3691,7 +3691,7 @@ msgstr "ord() umaasa ng character pero string ng %d haba ang nakita" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index a32590b685..e0b84990f9 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -3760,7 +3760,7 @@ msgstr "" msgid "out of range of source" msgstr "dépassement des bornes de source" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "dépassement des bornes de target" diff --git a/locale/hi.po b/locale/hi.po index 0ad1435b7d..e20c4a5e26 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -3643,7 +3643,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index 235855efd0..7e13fa0eff 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -3707,7 +3707,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/ja.po b/locale/ja.po index 8d1fa39e3f..7555843857 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -3671,7 +3671,7 @@ msgstr "ord()は1文字を要求しますが、長さ %d の文字列が与え msgid "out of range of source" msgstr "ソースが範囲外" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/ko.po b/locale/ko.po index b3137c1b94..77a145dba4 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -3647,7 +3647,7 @@ msgstr "" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index d47469236d..e839699efd 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -3704,7 +3704,7 @@ msgstr "ord() verwacht een teken (char) maar vond een string van lengte %d" msgid "out of range of source" msgstr "buiten bereik van bron" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "buiten bereik van doel" diff --git a/locale/pl.po b/locale/pl.po index b51df842fb..c4ce7ea7a7 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -3664,7 +3664,7 @@ msgstr "ord() oczekuje znaku, a jest łańcuch od długości %d" msgid "out of range of source" msgstr "" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 3adaa228a8..fcc9dc602a 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -3749,7 +3749,7 @@ msgstr "" msgid "out of range of source" msgstr "fora do alcance da fonte" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "fora do alcance do alvo" diff --git a/locale/sv.po b/locale/sv.po index de7e817691..00d4ce6de1 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -3707,7 +3707,7 @@ msgstr "ord() förväntade sig ett tecken, men en sträng med längden %d hittad msgid "out of range of source" msgstr "utanför räckvidd för source" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "utanför räckvidd för target" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index bb3e9cd585..4e1d1a12b6 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -3704,7 +3704,7 @@ msgstr "ord() yùqí zìfú, dàn chángdù zìfú chuàn %d" msgid "out of range of source" msgstr "yuán fàn wéi wài" -#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c msgid "out of range of target" msgstr "mù biāo fàn wéi wài"