Merge branch 'master' into master
This commit is contained in:
commit
bbf77a7efb
52
.travis.yml
52
.travis.yml
@ -25,7 +25,7 @@ env:
|
||||
- TRAVIS_BOARDS="metro_m0_express metro_m4_express pirkey_m0 trellis_m4_express trinket_m0" TRAVIS_SDK=arm
|
||||
- TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow" TRAVIS_SDK=arm
|
||||
- TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero arduino_mkr1300 arduino_mkrzero" TRAVIS_SDK=arm
|
||||
- TRAVIS_BOARDS="circuitplayground_express_crickit feather_m0_adalogger feather_m0_basic feather_m0_express catwan_usbstick sparkfun_samd21_mini" TRAVIS_SDK=arm
|
||||
- TRAVIS_BOARDS="circuitplayground_express_crickit feather_m0_adalogger feather_m0_basic feather_m0_express catwan_usbstick pyportal sparkfun_samd21_mini" TRAVIS_SDK=arm
|
||||
|
||||
addons:
|
||||
artifacts:
|
||||
@ -77,7 +77,7 @@ before_script:
|
||||
- sudo apt-get install -y python3-pip
|
||||
- pip3 install --user sh click
|
||||
- ([[ -z "$TRAVIS_TESTS" ]] || sudo pip install --upgrade cpp-coveralls)
|
||||
- (! var_search "${TRAVIS_TESTS-}" docs || pip install --user 'Sphinx<1.8.0' sphinx-rtd-theme recommonmark)
|
||||
- (! var_search "${TRAVIS_TESTS-}" docs || pip install --user Sphinx sphinx-rtd-theme recommonmark)
|
||||
- (! var_search "${TRAVIS_TESTS-}" translations || pip3 install --user polib)
|
||||
|
||||
# report some good version numbers to the build
|
||||
@ -88,47 +88,47 @@ before_script:
|
||||
|
||||
script:
|
||||
# Build mpy-cross first because other builds depend on it.
|
||||
- echo 'Building mpy-cross' && echo -en 'travis_fold:start:mpy-cross\\r'
|
||||
- make -C mpy-cross -j2
|
||||
- echo -en 'travis_fold:end:mpy-cross\\r'
|
||||
- echo 'Building mpy-cross' && echo 'travis_fold:start:mpy-cross'
|
||||
- make -C mpy-cross -j2 ; echo $? > status
|
||||
- echo 'travis_fold:end:mpy-cross' && tools/print_status.py status
|
||||
|
||||
# Use unbuffered output because building all the releases can take a long time.
|
||||
# Travis will cancel the job if it sees no output for >10 minutes.
|
||||
- cd tools && python3 -u build_release_files.py
|
||||
- cd ..
|
||||
|
||||
- echo 'Building unix' && echo -en 'travis_fold:start:unix\\r'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (make -C ports/unix deplibs -j2 && make -C ports/unix -j2 && make -C ports/unix coverage -j2))
|
||||
- echo -en 'travis_fold:end:unix\\r'
|
||||
- echo 'Building unix' && echo 'travis_fold:start:unix'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (make -C ports/unix deplibs -j2 && make -C ports/unix -j2 && make -C ports/unix coverage -j2)) ; echo $? > status
|
||||
- echo 'travis_fold:end:unix' && tools/print_status.py status
|
||||
|
||||
# run tests without coverage info
|
||||
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests -j1)
|
||||
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests -j1 --emit native)
|
||||
|
||||
# run tests with coverage info
|
||||
- echo 'Test all' && echo -en 'travis_fold:start:test_all\\r'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1))
|
||||
- echo -en 'travis_fold:end:test_all\\r'
|
||||
- echo 'Test all' && echo 'travis_fold:start:test_all'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1)) ; echo $? > status
|
||||
- echo 'travis_fold:end:test_all' && tools/print_status.py status
|
||||
|
||||
- echo 'Test threads' && echo -en 'travis_fold:start:test_threads\\r'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 -d thread))
|
||||
- echo -en 'travis_fold:end:test_threads\\r'
|
||||
- echo 'Test threads' && echo 'travis_fold:start:test_threads'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 -d thread)) ; echo $? >status
|
||||
- echo 'travis_fold:end:test_threads' && tools/print_status.py status
|
||||
|
||||
- echo 'Testing with native' && echo -en 'travis_fold:start:test_native\\r'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --emit native))
|
||||
- echo -en 'travis_fold:end:test_native\\r'
|
||||
- echo 'Testing with native' && echo 'travis_fold:start:test_native'
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --emit native)) ; echo $? >status
|
||||
- echo 'travis_fold:end:test_native' && tools/print_status.py status
|
||||
|
||||
- (echo 'Testing with mpy' && echo -en 'travis_fold:start:test_mpy\\r')
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --via-mpy -d basics float))
|
||||
- echo -en 'travis_fold:end:test_mpy\\r'
|
||||
- (echo 'Testing with mpy' && echo 'travis_fold:start:test_mpy')
|
||||
- (! var_search "${TRAVIS_TESTS-}" unix || (cd tests && MICROPY_CPYTHON3=python3.5 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --via-mpy -d basics float)) ; echo $? >status
|
||||
- echo 'travis_fold:end:test_mpy' && tools/print_status.py status
|
||||
|
||||
- (echo 'Building docs' && echo -en 'travis_fold:start:build_docs\\r')
|
||||
- (! var_search "${TRAVIS_TESTS-}" docs || sphinx-build -E -W -b html . _build/html)
|
||||
- echo -en 'travis_fold:end:build_docs\\r'
|
||||
- (echo 'Building docs' && echo 'travis_fold:start:build_docs')
|
||||
- (! var_search "${TRAVIS_TESTS-}" docs || sphinx-build -E -W -b html . _build/html) ; echo $? >status
|
||||
- echo 'travis_fold:end:build_docs' && tools/print_status.py status
|
||||
|
||||
- (echo 'Building translations' && echo -en 'travis_fold:start:build_translations\\r')
|
||||
- (! var_search "${TRAVIS_TESTS-}" translations || make check-translate)
|
||||
- echo -en 'travis_fold:end:build_translations\\r'
|
||||
- (echo 'Building translations' && echo 'travis_fold:start:build_translations')
|
||||
- (! var_search "${TRAVIS_TESTS-}" translations || make check-translate) ; echo $? >status
|
||||
- echo 'travis_fold:end:build_translations' && tools/print_status.py status
|
||||
|
||||
# run coveralls coverage analysis (try to, even if some builds/tests failed)
|
||||
#- (cd ports/unix && coveralls --root ../.. --build-root . --gcov $(which gcov) --gcov-options '\-o build-coverage/' --include py --include extmod)
|
||||
|
6
conf.py
6
conf.py
@ -284,7 +284,7 @@ latex_elements = {
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'CircuitPython.tex', 'CircuitPython Documentation',
|
||||
'Damien P. George, Paul Sokolovsky, and contributors', 'manual'),
|
||||
'CircuitPython Contributors', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
@ -314,7 +314,7 @@ latex_documents = [
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'CircuitPython', 'CircuitPython Documentation',
|
||||
['Damien P. George, Paul Sokolovsky, and contributors'], 1),
|
||||
['CircuitPython contributors'], 1),
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
@ -328,7 +328,7 @@ man_pages = [
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'CircuitPython', 'CircuitPython Documentation',
|
||||
'Damien P. George, Paul Sokolovsky, and contributors', 'CircuitPython', 'One line description of project.',
|
||||
'CircuitPython contributors', 'CircuitPython', 'Python for Microcontrollers.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
|
39
ports/atmel-samd/boards/pyportal/board.c
Normal file
39
ports/atmel-samd/boards/pyportal/board.c
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "mpconfigboard.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
||||
void board_init(void) {
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void reset_board(void) {
|
||||
}
|
40
ports/atmel-samd/boards/pyportal/mpconfigboard.h
Normal file
40
ports/atmel-samd/boards/pyportal/mpconfigboard.h
Normal file
@ -0,0 +1,40 @@
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit PyPortal"
|
||||
#define MICROPY_HW_MCU_NAME "samd51j20"
|
||||
|
||||
#define CIRCUITPY_MCU_FAMILY samd51
|
||||
|
||||
// This is for Rev B
|
||||
|
||||
#define MICROPY_HW_LED_STATUS (&pin_PA27)
|
||||
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_PB22)
|
||||
|
||||
// These are pins not to reset.
|
||||
// QSPI Data pins
|
||||
#define MICROPY_PORT_A ( PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11 )
|
||||
// QSPI CS, and QSPI SCK
|
||||
#define MICROPY_PORT_B ( PORT_PB10 | PORT_PB11 )
|
||||
#define MICROPY_PORT_C ( 0 )
|
||||
#define MICROPY_PORT_D (0)
|
||||
|
||||
#define AUTORESET_DELAY_MS 500
|
||||
|
||||
// If you change this, then make sure to update the linker scripts as well to
|
||||
// make sure you don't overwrite code
|
||||
#define CIRCUITPY_INTERNAL_NVM_SIZE 8192
|
||||
|
||||
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_PB03)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_PB02)
|
||||
|
||||
#define DEFAULT_SPI_BUS_SCK (&pin_PA13)
|
||||
#define DEFAULT_SPI_BUS_MOSI (&pin_PA12)
|
||||
#define DEFAULT_SPI_BUS_MISO (&pin_PA14)
|
||||
|
||||
#define DEFAULT_UART_BUS_RX (&pin_PB13)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_PB12)
|
||||
|
||||
// USB is always used internally so skip the pin objects for it.
|
||||
#define IGNORE_PIN_PA24 1
|
||||
#define IGNORE_PIN_PA25 1
|
14
ports/atmel-samd/boards/pyportal/mpconfigboard.mk
Normal file
14
ports/atmel-samd/boards/pyportal/mpconfigboard.mk
Normal file
@ -0,0 +1,14 @@
|
||||
LD_FILE = boards/samd51x20-bootloader-external-flash.ld
|
||||
USB_VID = 0x239A
|
||||
USB_PID = 0x8032
|
||||
USB_PRODUCT = "PyPortal"
|
||||
USB_MANUFACTURER = "Adafruit Industries LLC"
|
||||
|
||||
QSPI_FLASH_FILESYSTEM = 1
|
||||
|
||||
EXTERNAL_FLASH_DEVICE_COUNT = 1
|
||||
EXTERNAL_FLASH_DEVICES = "GD25Q64C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CHIP_VARIANT = SAMD51J20A
|
||||
CHIP_FAMILY = samd51
|
55
ports/atmel-samd/boards/pyportal/pins.c
Normal file
55
ports/atmel-samd/boards/pyportal/pins.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "board_busses.h"
|
||||
|
||||
// This mapping only includes functional names because pins broken
|
||||
// out on connectors are labeled with their MCU name available from
|
||||
// microcontroller.pin.
|
||||
STATIC const mp_map_elem_t board_global_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_AUDIO_OUT), (mp_obj_t)&pin_PA02 },
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_D13), (mp_obj_t)&pin_PA27 },
|
||||
|
||||
// LCD pins
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_RESET), (mp_obj_t)&pin_PA00 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_RD), (mp_obj_t)&pin_PB04 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_RS), (mp_obj_t)&pin_PB05 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_CS), (mp_obj_t)&pin_PB06 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_TE), (mp_obj_t)&pin_PB07 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_WR), (mp_obj_t)&pin_PB09 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TFT_BACKLIGHT), (mp_obj_t)&pin_PB31 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA0), (mp_obj_t)&pin_PA16 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA1), (mp_obj_t)&pin_PA17 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA2), (mp_obj_t)&pin_PA18 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA3), (mp_obj_t)&pin_PA19 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA4), (mp_obj_t)&pin_PA20 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA5), (mp_obj_t)&pin_PA21 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA6), (mp_obj_t)&pin_PA22 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD_DATA7), (mp_obj_t)&pin_PA23 },
|
||||
|
||||
// Touch pins
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TOUCH_YD), (mp_obj_t)&pin_PA04 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TOUCH_XL), (mp_obj_t)&pin_PA05 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TOUCH_YU), (mp_obj_t)&pin_PA06 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_TOUCH_XR), (mp_obj_t)&pin_PB08 },
|
||||
|
||||
// ESP control
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_CS), (mp_obj_t)&pin_PA15 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_BUSY), (mp_obj_t)&pin_PB14 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_GPIO0), (mp_obj_t)&pin_PB15 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RESET), (mp_obj_t)&pin_PB16 },
|
||||
|
||||
|
||||
// SD Card
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD_MOSI), (mp_obj_t)&pin_PA12 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD_SCK), (mp_obj_t)&pin_PA13 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD_CS), (mp_obj_t)&pin_PB30 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD_MISO), (mp_obj_t)&pin_PA14 },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD_CARD_DETECT), (mp_obj_t)&pin_PA01 },
|
||||
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), (mp_obj_t)&pin_PB22 },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);
|
@ -101,6 +101,7 @@ SRC_NRFX = $(addprefix nrfx/,\
|
||||
drivers/src/nrfx_timer.c \
|
||||
drivers/src/nrfx_twim.c \
|
||||
drivers/src/nrfx_uarte.c \
|
||||
drivers/src/nrfx_gpiote.c \
|
||||
)
|
||||
|
||||
ifdef EXTERNAL_FLASH_DEVICES
|
||||
|
@ -36,10 +36,10 @@ the following links:
|
||||
> **NOTE**: These board specific readmes may be more up to date than the
|
||||
generic board-neutral documentation further down.
|
||||
|
||||
* Adafruit [Feather nRF52](boards/feather_nrf52832/README.md): 512KB Flash, 64KB SRAM
|
||||
* Adafruit [Feather nRF52840](boards/feather_nrf52840_express/README.md): 1MB Flash, 256KB SRAM
|
||||
* Nordic PCA10056 see [Feather nRF52840](boards/pca10056/README.md)
|
||||
* MakerDiary NRF52840 MDK see [its README](boards/makerdiary_nrf52840_mdk/README.md)
|
||||
* Adafruit Feather nRF52: boards/feather_nrf52832/README.md: 512KB Flash, 64KB SRAM
|
||||
* Adafruit Feather nRF52840: boards/feather_nrf52840_express/README.md: 1MB Flash, 256KB SRAM
|
||||
* Nordic PCA10056 (uses nRF52840): boards/pca10056/README.md
|
||||
* MakerDiary NRF52840 MDK: boards/makerdiary_nrf52840_mdk/README.md
|
||||
|
||||
For all other board targets, see the generic notes below.
|
||||
|
||||
|
@ -141,7 +141,7 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
|
||||
for ( uint16_t n = 0; n < numBytes; n++ ) {
|
||||
uint8_t pix = pixels[n];
|
||||
|
||||
for ( uint8_t mask = 0x80, i = 0; mask > 0; mask >>= 1, i++ ) {
|
||||
for ( uint8_t mask = 0x80; mask > 0; mask >>= 1 ) {
|
||||
pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H;
|
||||
pos++;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "common-hal/pulseio/PulseIn.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/mpconfig.h"
|
||||
#include "py/gc.h"
|
||||
@ -35,50 +36,247 @@
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/pulseio/PulseIn.h"
|
||||
|
||||
void pulsein_reset(void) {
|
||||
#include "tick.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
|
||||
// obj array to map pin -> self since nrfx hide the mapping
|
||||
static pulseio_pulsein_obj_t* _objs[GPIOTE_CH_NUM];
|
||||
|
||||
// return index of the object in array
|
||||
static int _find_pulsein_obj(pulseio_pulsein_obj_t* obj) {
|
||||
for(int i = 0; i < NRFX_ARRAY_SIZE(_objs); i++ ) {
|
||||
if ( _objs[i] == obj) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void _pulsein_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
|
||||
// Grab the current time first.
|
||||
uint32_t current_us;
|
||||
uint64_t current_ms;
|
||||
current_tick(¤t_ms, ¤t_us);
|
||||
|
||||
// current_tick gives us the remaining us until the next tick but we want the number since the last ms.
|
||||
current_us = 1000 - current_us;
|
||||
|
||||
pulseio_pulsein_obj_t* self = NULL;
|
||||
for(int i = 0; i < NRFX_ARRAY_SIZE(_objs); i++ ) {
|
||||
if ( _objs[i] && _objs[i]->pin == pin ) {
|
||||
self = _objs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !self ) return;
|
||||
|
||||
if (self->first_edge) {
|
||||
// first pulse is opposite state from idle
|
||||
bool state = nrf_gpio_pin_read(self->pin);
|
||||
if ( self->idle_state != state ) {
|
||||
self->first_edge = false;
|
||||
}
|
||||
}else {
|
||||
uint32_t ms_diff = current_ms - self->last_ms;
|
||||
uint16_t us_diff = current_us - self->last_us;
|
||||
uint32_t total_diff = us_diff;
|
||||
|
||||
if (self->last_us > current_us) {
|
||||
total_diff = 1000 + current_us - self->last_us;
|
||||
if (ms_diff > 1) {
|
||||
total_diff += (ms_diff - 1) * 1000;
|
||||
}
|
||||
} else {
|
||||
total_diff += ms_diff * 1000;
|
||||
}
|
||||
uint16_t duration = 0xffff;
|
||||
if (total_diff < duration) {
|
||||
duration = total_diff;
|
||||
}
|
||||
|
||||
uint16_t i = (self->start + self->len) % self->maxlen;
|
||||
self->buffer[i] = duration;
|
||||
if (self->len < self->maxlen) {
|
||||
self->len++;
|
||||
} else {
|
||||
self->start++;
|
||||
}
|
||||
}
|
||||
|
||||
self->last_ms = current_ms;
|
||||
self->last_us = current_us;
|
||||
}
|
||||
|
||||
void pulsein_reset(void) {
|
||||
if ( nrfx_gpiote_is_init() ) {
|
||||
nrfx_gpiote_uninit();
|
||||
}
|
||||
nrfx_gpiote_init();
|
||||
|
||||
memset(_objs, 0, sizeof(_objs));
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
int idx = _find_pulsein_obj(NULL);
|
||||
if ( idx < 0 ) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
_objs[idx] = self;
|
||||
|
||||
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;
|
||||
self->first_edge = true;
|
||||
self->paused = false;
|
||||
self->last_us = 0;
|
||||
self->last_ms = 0;
|
||||
|
||||
claim_pin(pin);
|
||||
|
||||
nrfx_gpiote_in_config_t cfg = {
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE,
|
||||
.pull = NRF_GPIO_PIN_NOPULL, // idle_state ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_PULLUP,
|
||||
.is_watcher = false, // nrf_gpio_cfg_watcher vs nrf_gpio_cfg_input
|
||||
.hi_accuracy = true,
|
||||
.skip_gpio_setup = false
|
||||
};
|
||||
nrfx_gpiote_in_init(self->pin, &cfg, _pulsein_handler);
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
|
||||
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
|
||||
return 1;
|
||||
return self->pin == NO_PIN;
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
|
||||
if (common_hal_pulseio_pulsein_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_event_disable(self->pin);
|
||||
nrfx_gpiote_in_uninit(self->pin);
|
||||
|
||||
// mark local array as invalid
|
||||
int idx = _find_pulsein_obj(self);
|
||||
if ( idx < 0 ) {
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
_objs[idx] = NULL;
|
||||
|
||||
reset_pin_number(self->pin);
|
||||
self->pin = NO_PIN;
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) {
|
||||
|
||||
nrfx_gpiote_in_event_disable(self->pin);
|
||||
self->paused = true;
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, uint16_t trigger_duration) {
|
||||
// Make sure we're paused.
|
||||
if ( !self->paused ) {
|
||||
common_hal_pulseio_pulsein_pause(self);
|
||||
}
|
||||
|
||||
// Send the trigger pulse.
|
||||
if (trigger_duration > 0) {
|
||||
nrfx_gpiote_in_uninit(self->pin);
|
||||
|
||||
nrf_gpio_cfg_output(self->pin);
|
||||
nrf_gpio_pin_write(self->pin, !self->idle_state);
|
||||
common_hal_mcu_delay_us((uint32_t)trigger_duration);
|
||||
nrf_gpio_pin_write(self->pin, self->idle_state);
|
||||
|
||||
nrfx_gpiote_in_config_t cfg = {
|
||||
.sense = NRF_GPIOTE_POLARITY_TOGGLE,
|
||||
.pull = NRF_GPIO_PIN_NOPULL, // idle_state ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_PULLUP,
|
||||
.is_watcher = false, // nrf_gpio_cfg_watcher vs nrf_gpio_cfg_input
|
||||
.hi_accuracy = true,
|
||||
.skip_gpio_setup = false
|
||||
};
|
||||
nrfx_gpiote_in_init(self->pin, &cfg, _pulsein_handler);
|
||||
}
|
||||
|
||||
self->first_edge = true;
|
||||
self->paused = false;
|
||||
self->last_ms = 0;
|
||||
self->last_us = 0;
|
||||
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) {
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_disable(self->pin);
|
||||
}
|
||||
|
||||
}
|
||||
self->start = 0;
|
||||
self->len = 0;
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) {
|
||||
return 0xadaf;
|
||||
}
|
||||
|
||||
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
|
||||
return 0xadaf;
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self, int16_t index) {
|
||||
return 0xadaf;
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_disable(self->pin);
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
index += self->len;
|
||||
}
|
||||
if (index < 0 || index >= self->len) {
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
mp_raise_IndexError(translate("index out of range"));
|
||||
}
|
||||
uint16_t value = self->buffer[(self->start + index) % self->maxlen];
|
||||
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
|
||||
if (self->len == 0) {
|
||||
mp_raise_IndexError(translate("pop from an empty PulseIn"));
|
||||
}
|
||||
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_disable(self->pin);
|
||||
}
|
||||
|
||||
uint16_t value = self->buffer[self->start];
|
||||
self->start = (self->start + 1) % self->maxlen;
|
||||
self->len--;
|
||||
|
||||
if ( !self->paused ) {
|
||||
nrfx_gpiote_in_event_enable(self->pin, true);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) {
|
||||
return self->maxlen;
|
||||
}
|
||||
|
||||
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) {
|
||||
return self->paused;
|
||||
}
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
|
||||
return self->len;
|
||||
}
|
||||
|
@ -33,15 +33,19 @@
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
uint8_t channel;
|
||||
|
||||
uint8_t pin;
|
||||
bool idle_state;
|
||||
bool paused;
|
||||
volatile bool first_edge;
|
||||
|
||||
uint16_t* buffer;
|
||||
uint16_t maxlen;
|
||||
bool idle_state;
|
||||
|
||||
volatile uint16_t start;
|
||||
volatile uint16_t len;
|
||||
volatile bool first_edge;
|
||||
uint16_t ticks_per_ms;
|
||||
volatile uint16_t last_us;
|
||||
volatile uint64_t last_ms;
|
||||
} pulseio_pulsein_obj_t;
|
||||
|
||||
void pulsein_reset(void);
|
||||
|
@ -84,4 +84,9 @@
|
||||
|
||||
#define NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY 7
|
||||
|
||||
// GPIO interrupt
|
||||
#define NRFX_GPIOTE_ENABLED 1
|
||||
#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
|
||||
#define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 7
|
||||
|
||||
#endif // NRFX_CONFIG_H__
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "common-hal/busio/SPI.h"
|
||||
#include "common-hal/pulseio/PWMOut.h"
|
||||
#include "common-hal/pulseio/PulseOut.h"
|
||||
#include "common-hal/pulseio/PulseIn.h"
|
||||
#include "tick.h"
|
||||
|
||||
static void power_warning_handler(void) {
|
||||
@ -84,6 +85,7 @@ void reset_port(void) {
|
||||
spi_reset();
|
||||
pwmout_reset();
|
||||
pulseout_reset();
|
||||
pulsein_reset();
|
||||
timers_reset();
|
||||
|
||||
reset_all_pins();
|
||||
|
15
tools/print_status.py
Executable file
15
tools/print_status.py
Executable file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
if len(sys.argv) != 2:
|
||||
print("""\
|
||||
Usage: print_status.py STATUS_FILENAME
|
||||
STATUS_FILENAME contains one line with an integer status."""
|
||||
)
|
||||
sys.exit(1)
|
||||
with open(sys.argv[1], 'r') as status_in:
|
||||
status = int(status_in.readline())
|
||||
|
||||
print('{} with status {}'.format(
|
||||
"\033[32msucceeded\033[0m" if status == 0 else "\033[31mfailed\033[0m",
|
||||
status))
|
Loading…
Reference in New Issue
Block a user