From 526925f1c61f7be74c7c4a808d98e802204ba589 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Wed, 9 Oct 2019 08:27:08 +0200 Subject: [PATCH 01/19] Add Spresense board --- ports/spresense/Makefile | 186 +++++++++++++++++ ports/spresense/README.md | 86 ++++++++ ports/spresense/alloca.h | 6 + ports/spresense/background.c | 53 +++++ ports/spresense/background.h | 33 +++ .../spresense/common-hal/analogio/AnalogIn.c | 131 ++++++++++++ .../spresense/common-hal/analogio/AnalogIn.h | 42 ++++ .../spresense/common-hal/analogio/AnalogOut.c | 43 ++++ .../spresense/common-hal/analogio/AnalogOut.h | 36 ++++ .../spresense/common-hal/analogio/__init__.c | 1 + ports/spresense/common-hal/board/__init__.c | 80 +++++++ ports/spresense/common-hal/busio/I2C.c | 123 +++++++++++ ports/spresense/common-hal/busio/I2C.h | 43 ++++ ports/spresense/common-hal/busio/OneWire.h | 33 +++ ports/spresense/common-hal/busio/SPI.c | 155 ++++++++++++++ ports/spresense/common-hal/busio/SPI.h | 49 +++++ ports/spresense/common-hal/busio/UART.c | 168 +++++++++++++++ ports/spresense/common-hal/busio/UART.h | 43 ++++ ports/spresense/common-hal/busio/__init__.c | 1 + .../common-hal/digitalio/DigitalInOut.c | 136 ++++++++++++ .../common-hal/digitalio/DigitalInOut.h | 42 ++++ .../spresense/common-hal/digitalio/__init__.c | 1 + .../common-hal/microcontroller/Pin.c | 162 +++++++++++++++ .../common-hal/microcontroller/Pin.h | 92 ++++++++ .../common-hal/microcontroller/Processor.c | 41 ++++ .../common-hal/microcontroller/Processor.h | 40 ++++ .../common-hal/microcontroller/__init__.c | 111 ++++++++++ ports/spresense/common-hal/os/__init__.c | 72 +++++++ ports/spresense/common-hal/pulseio/PWMOut.c | 157 ++++++++++++++ ports/spresense/common-hal/pulseio/PWMOut.h | 48 +++++ ports/spresense/common-hal/pulseio/PulseIn.c | 196 ++++++++++++++++++ ports/spresense/common-hal/pulseio/PulseIn.h | 47 +++++ ports/spresense/common-hal/pulseio/PulseOut.c | 126 +++++++++++ ports/spresense/common-hal/pulseio/PulseOut.h | 39 ++++ ports/spresense/common-hal/pulseio/__init__.c | 1 + ports/spresense/common-hal/rtc/RTC.c | 54 +++++ ports/spresense/common-hal/rtc/RTC.h | 30 +++ ports/spresense/common-hal/rtc/__init__.c | 1 + .../spresense/common-hal/supervisor/Runtime.c | 36 ++++ .../spresense/common-hal/supervisor/Runtime.h | 36 ++++ .../common-hal/supervisor/__init__.c | 36 ++++ ports/spresense/common-hal/time/__init__.c | 37 ++++ ports/spresense/fatfs_port.c | 46 ++++ ports/spresense/mpconfigboard.h | 39 ++++ ports/spresense/mpconfigport.h | 38 ++++ ports/spresense/mpconfigport.mk | 24 +++ ports/spresense/mphalport.c | 88 ++++++++ ports/spresense/mphalport.h | 36 ++++ ports/spresense/qstrdefsport.h | 1 + ports/spresense/supervisor/cpu.s | 27 +++ ports/spresense/supervisor/internal_flash.c | 114 ++++++++++ ports/spresense/supervisor/internal_flash.h | 30 +++ .../supervisor/internal_flash_root_pointers.h | 31 +++ ports/spresense/supervisor/port.c | 73 +++++++ ports/spresense/supervisor/usb.c | 30 +++ ports/spresense/tick.c | 45 ++++ ports/spresense/tick.h | 34 +++ 57 files changed, 3509 insertions(+) create mode 100644 ports/spresense/Makefile create mode 100644 ports/spresense/README.md create mode 100644 ports/spresense/alloca.h create mode 100644 ports/spresense/background.c create mode 100644 ports/spresense/background.h create mode 100644 ports/spresense/common-hal/analogio/AnalogIn.c create mode 100644 ports/spresense/common-hal/analogio/AnalogIn.h create mode 100644 ports/spresense/common-hal/analogio/AnalogOut.c create mode 100644 ports/spresense/common-hal/analogio/AnalogOut.h create mode 100644 ports/spresense/common-hal/analogio/__init__.c create mode 100644 ports/spresense/common-hal/board/__init__.c create mode 100644 ports/spresense/common-hal/busio/I2C.c create mode 100644 ports/spresense/common-hal/busio/I2C.h create mode 100644 ports/spresense/common-hal/busio/OneWire.h create mode 100644 ports/spresense/common-hal/busio/SPI.c create mode 100644 ports/spresense/common-hal/busio/SPI.h create mode 100644 ports/spresense/common-hal/busio/UART.c create mode 100644 ports/spresense/common-hal/busio/UART.h create mode 100644 ports/spresense/common-hal/busio/__init__.c create mode 100644 ports/spresense/common-hal/digitalio/DigitalInOut.c create mode 100644 ports/spresense/common-hal/digitalio/DigitalInOut.h create mode 100644 ports/spresense/common-hal/digitalio/__init__.c create mode 100644 ports/spresense/common-hal/microcontroller/Pin.c create mode 100644 ports/spresense/common-hal/microcontroller/Pin.h create mode 100644 ports/spresense/common-hal/microcontroller/Processor.c create mode 100644 ports/spresense/common-hal/microcontroller/Processor.h create mode 100644 ports/spresense/common-hal/microcontroller/__init__.c create mode 100644 ports/spresense/common-hal/os/__init__.c create mode 100644 ports/spresense/common-hal/pulseio/PWMOut.c create mode 100644 ports/spresense/common-hal/pulseio/PWMOut.h create mode 100644 ports/spresense/common-hal/pulseio/PulseIn.c create mode 100644 ports/spresense/common-hal/pulseio/PulseIn.h create mode 100644 ports/spresense/common-hal/pulseio/PulseOut.c create mode 100644 ports/spresense/common-hal/pulseio/PulseOut.h create mode 100644 ports/spresense/common-hal/pulseio/__init__.c create mode 100644 ports/spresense/common-hal/rtc/RTC.c create mode 100644 ports/spresense/common-hal/rtc/RTC.h create mode 100644 ports/spresense/common-hal/rtc/__init__.c create mode 100755 ports/spresense/common-hal/supervisor/Runtime.c create mode 100755 ports/spresense/common-hal/supervisor/Runtime.h create mode 100755 ports/spresense/common-hal/supervisor/__init__.c create mode 100644 ports/spresense/common-hal/time/__init__.c create mode 100644 ports/spresense/fatfs_port.c create mode 100644 ports/spresense/mpconfigboard.h create mode 100644 ports/spresense/mpconfigport.h create mode 100644 ports/spresense/mpconfigport.mk create mode 100644 ports/spresense/mphalport.c create mode 100644 ports/spresense/mphalport.h create mode 100644 ports/spresense/qstrdefsport.h create mode 100755 ports/spresense/supervisor/cpu.s create mode 100644 ports/spresense/supervisor/internal_flash.c create mode 100644 ports/spresense/supervisor/internal_flash.h create mode 100644 ports/spresense/supervisor/internal_flash_root_pointers.h create mode 100644 ports/spresense/supervisor/port.c create mode 100644 ports/spresense/supervisor/usb.c create mode 100644 ports/spresense/tick.c create mode 100644 ports/spresense/tick.h diff --git a/ports/spresense/Makefile b/ports/spresense/Makefile new file mode 100644 index 0000000000..d8f809635f --- /dev/null +++ b/ports/spresense/Makefile @@ -0,0 +1,186 @@ +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# Copyright 2019 Sony Semiconductor Solutions Corporation +# +# 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 ../../py/mkenv.mk + +# Port-specific +include mpconfigport.mk + +# CircuitPython-specific +include $(TOP)/py/circuitpy_mpconfig.mk + +# qstr definitions (must come before including py.mk) +QSTR_DEFS = qstrdefsport.h + +# include py core make definitions +include $(TOP)/py/py.mk + +include $(TOP)/supervisor/supervisor.mk + +# Include make rules and variables common across CircuitPython builds. +include $(TOP)/py/circuitpy_defns.mk + +CROSS_COMPILE = arm-none-eabi- + +SPRESENSE_SDK = spresense-exported-sdk + +FIRMWARE = $(SPRESENSE_SDK)/firmware + +INC += \ + -I. \ + -I../.. \ + -I../lib/mp-readline \ + -I../lib/timeutils \ + -I../../lib/tinyusb/src \ + -I../../supervisor/shared/usb \ + -I$(BUILD) \ + -I$(SPRESENSE_SDK)/nuttx/include \ + -I$(SPRESENSE_SDK)/nuttx/arch \ + -I$(SPRESENSE_SDK)/nuttx/arch/chip \ + -I$(SPRESENSE_SDK)/sdk/bsp/include \ + -I$(SPRESENSE_SDK)/sdk/bsp/include/sdk \ + +CFLAGS += \ + $(INC) \ + -DCONFIG_WCHAR_BUILTIN \ + -DCONFIG_HAVE_DOUBLE \ + -Dmain=spresense_main \ + -D_estack=__stack \ + -c \ + -Os \ + -pipe \ + -std=gnu11 \ + -mcpu=cortex-m4 \ + -mthumb \ + -mfpu=fpv4-sp-d16 \ + -mfloat-abi=hard \ + -mabi=aapcs \ + -fno-builtin \ + -fno-strict-aliasing \ + -fno-strength-reduce \ + -fomit-frame-pointer \ + -ffunction-sections \ + -fdata-sections \ + -Wall \ + +LIBM = "${shell "$(CC)" $(CFLAGS) -print-file-name=libm.a}" + +LIBGCC = "${shell "$(CC)" $(CFLAGS) -print-libgcc-file-name}" + +LDFLAGS = \ + --entry=__start \ + -nostartfiles \ + -nodefaultlibs \ + --defsym __stack=_vectors+786432 \ + -T$(SPRESENSE_SDK)/nuttx/build/ramconfig.ld \ + --gc-sections \ + -Map=$(BUILD)/output.map \ + -o $(BUILD)/circuitpython.elf \ + --start-group \ + -u spresense_main \ + $(BUILD)/libmpy.a \ + $(SPRESENSE_SDK)/sdk/libs/libapps.a \ + $(SPRESENSE_SDK)/sdk/libs/libsdk.a \ + $(LIBM) \ + $(LIBGCC) \ + --end-group \ + -L$(BUILD) \ + +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_CXD56 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=512 $(CFLAGS_MOD) + +SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ + $(addprefix common-hal/, $(SRC_COMMON_HAL)) + +SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) + +SRC_S = supervisor/cpu.s + +SRC_C = \ + tick.c \ + background.c \ + fatfs_port.c \ + mphalport.c \ + lib/utils/stdout_helpers.c \ + lib/utils/pyexec.c \ + lib/libc/string0.c \ + lib/mp-readline/readline.c \ + lib/timeutils/timeutils.c \ + lib/oofatfs/ff.c \ + lib/oofatfs/option/ccsbcs.c \ + lib/utils/interrupt_char.c \ + lib/utils/sys_stdio_mphal.c \ + lib/utils/context_manager_helpers.c \ + lib/utils/buffer_helper.c \ + supervisor/shared/memory.c \ + lib/tinyusb/src/portable/sony/cxd56/dcd_cxd56.c \ + +OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o)) + +# List of sources for qstr extraction +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) +# Sources that only hold QSTRs after pre-processing. +SRC_QSTR_PREPROCESSOR += + +all: $(BUILD)/circuitpython.spk + +$(FIRMWARE): + $(ECHO) "" + $(ECHO) "Download the spresense binaries zip archive from:" + $(ECHO) "https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000" + $(ECHO) "Extract spresense binaries to $(FIRMWARE)" + $(ECHO) "" + $(ECHO) "run make flash-bootloader again to flash bootloader." + exit 1 + +$(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ) + $(ECHO) "AR $@" + $(Q)$(AR) rcs $(BUILD)/libmpy.a $(OBJ) + +$(BUILD)/circuitpython.elf: $(BUILD)/libmpy.a + $(ECHO) "LD $@" + $(Q)$(LD) $(LDFLAGS) + +$(BUILD)/circuitpython.spk: $(BUILD)/circuitpython.elf + $(ECHO) "Creating $@" + $(SPRESENSE_SDK)/sdk/tools/linux/mkspk -c 2 $(BUILD)/circuitpython.elf nuttx $(BUILD)/circuitpython.spk + +flash: $(BUILD)/circuitpython.spk + $(ECHO) "Writing $< to the board" + $(SPRESENSE_SDK)/sdk/tools/flash.sh -c /dev/ttyUSB0 $(BUILD)/circuitpython.spk + +flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE) + $(ECHO) "Writing loader to the board" + $(SPRESENSE_SDK)/sdk/tools/flash.sh -l $(FIRMWARE) -c /dev/ttyUSB0 + +include $(TOP)/py/mkrules.mk + +# Print out the value of a make variable. +# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile +print-%: + @echo $* = $($*) diff --git a/ports/spresense/README.md b/ports/spresense/README.md new file mode 100644 index 0000000000..af4a6dea19 --- /dev/null +++ b/ports/spresense/README.md @@ -0,0 +1,86 @@ +CircuitPython port to Spresense +============================== + +This directory contains the port of CircuitPython to Spresense. It is a compact +development board based on Sony’s power-efficient multicore microcontroller +CXD5602. + +Board features: + +* Integrated GPS + * The embedded GNSS with support for GPS, QZSS and GLONASS enables applications + where tracking is required. +* Hi-res audio output and multi mic inputs + * Advanced 192kHz/24 bit audio codec and amplifier for audio output, and + support for up to 8 mic input channels. +* Multicore microcontroller + * Spresense is powered by Sony's CXD5602 microcontroller (ARM® Cortex®-M4F × 6 + cores), with a clock speed of 156 MHz. + +Currently, Spresense port does not support GNSS, Audio and Multicore. + +Refer to [developer.sony.com/develop/spresense/](https://developer.sony.com/develop/spresense/) +for further information about this board. + +Build instructions +------------------ + +Pull all submodules into your clone: + + $ git submodule update --init --recursive + +Build the MicroPython cross-compiler: + + $ make -C mpy-cross + +Change directory to spresense: + + $ cd ports/spresense + +To build circuitpython image run: + + $ make + +USB connection +-------------- + +Add user to `dialout` group: + + $ sudo usermod -a -G dialout + +Connect the Spresense main board to the PC via the USB cable. + +Flash the bootloader +-------------------- + +The correct bootloader is required for the Spresense board to function. + +Bootloader information: + +* The bootloader has to be flashed the very first time the board is used. + +* You have to accept the End User License Agreement to be able to download and use the Spresense bootloader binary. + +Download the spresense binaries zip archive from: + +Extract spresense binaries in your PC to ports/spresense/spresense-exported-sdk/firmware/ + +To flash the bootloader run the command: + + $ make flash-bootloader + +Flash the circuitpython.spk image +--------------------------------- + +To flash the firmware run the command: + + $ make flash + +Accessing the board +------------------- + +Connect the Spresense extension board to the PC via the USB cable. + +Once built and deployed, access the CircuitPython REPL (the Python prompt) via USB. You can run: + + $ screen /dev/ttyACM0 115200 diff --git a/ports/spresense/alloca.h b/ports/spresense/alloca.h new file mode 100644 index 0000000000..aad2f8b5b3 --- /dev/null +++ b/ports/spresense/alloca.h @@ -0,0 +1,6 @@ +#ifndef _ALLOCA_H +#define _ALLOCA_H + +#define alloca __builtin_alloca + +#endif /* _ALLOCA_H */ diff --git a/ports/spresense/background.c b/ports/spresense/background.c new file mode 100644 index 0000000000..ade257dd24 --- /dev/null +++ b/ports/spresense/background.c @@ -0,0 +1,53 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "background.h" + +#include "supervisor/usb.h" +#include "supervisor/filesystem.h" +#include "supervisor/shared/stack.h" + +static bool running_background_tasks = false; + +void background_tasks_reset(void) { + running_background_tasks = false; +} + +void run_background_tasks(void) { + // Don't call ourselves recursively. + if (running_background_tasks) { + return; + } + + assert_heap_ok(); + running_background_tasks = true; + + usb_background(); + filesystem_background(); + + running_background_tasks = false; + assert_heap_ok(); +} diff --git a/ports/spresense/background.h b/ports/spresense/background.h new file mode 100644 index 0000000000..39e7c4fc87 --- /dev/null +++ b/ports/spresense/background.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_BACKGROUND_H +#define MICROPY_INCLUDED_SPRESENSE_BACKGROUND_H + +void background_tasks_reset(void); +void run_background_tasks(void); + +#endif // MICROPY_INCLUDED_SPRESENSE_BACKGROUND_H diff --git a/ports/spresense/common-hal/analogio/AnalogIn.c b/ports/spresense/common-hal/analogio/AnalogIn.c new file mode 100644 index 0000000000..438fbbcaed --- /dev/null +++ b/ports/spresense/common-hal/analogio/AnalogIn.c @@ -0,0 +1,131 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include +#include + +#include +#include + +#include "py/runtime.h" + +#include "shared-bindings/analogio/AnalogIn.h" + +typedef struct { + const char* devpath; + const mcu_pin_obj_t *pin; + int fd; +} analogin_dev_t; + +STATIC analogin_dev_t analogin_dev[] = { + {"/dev/lpadc0", &pin_A0, -1}, + {"/dev/lpadc1", &pin_A1, -1}, + {"/dev/lpadc2", &pin_A2, -1}, + {"/dev/lpadc3", &pin_A3, -1}, + {"/dev/hpadc0", &pin_A4, -1}, + {"/dev/hpadc1", &pin_A5, -1}, +}; + +void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) { + if (!pin->analog) { + mp_raise_ValueError(translate("AnalogIn not supported on given pin")); + } + + self->number = -1; + + for (int i = 0; i < MP_ARRAY_SIZE(analogin_dev); i++) { + if (pin->number == analogin_dev[i].pin->number) { + self->number = i; + break; + } + } + + if (self->number < 0) { + mp_raise_ValueError(translate("Pin does not have ADC capabilities")); + } + + analogin_dev[self->number].fd = open(analogin_dev[pin->number].devpath, O_RDONLY); + if (analogin_dev[self->number].fd < 0) { + mp_raise_ValueError(translate("Pin does not have ADC capabilities")); + } + + // SCU FIFO overwrite + ioctl(analogin_dev[self->number].fd, SCUIOC_SETFIFOMODE, 1); + + // ADC FIFO size + ioctl(analogin_dev[self->number].fd, ANIOC_CXD56_FIFOSIZE, 2); + + // start ADC + ioctl(analogin_dev[self->number].fd, ANIOC_CXD56_START, 0); + + self->pin = pin; +} + +void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { + if (common_hal_analogio_analogin_deinited(self)) { + return; + } + + // stop ADC + ioctl(analogin_dev[self->number].fd, ANIOC_CXD56_STOP, 0); + close(analogin_dev[self->number].fd); + analogin_dev[self->number].fd = -1; + + self->pin = mp_const_none; +} + +bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { + return self->pin == mp_const_none; +} + +uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { + uint16_t value = 0; + + read(analogin_dev[self->number].fd, &value, sizeof(value)); + + return value; +} + +// Reference voltage is a fixed value which is depending on the board. +// e.g.) +// - Reference Voltage of A4 and A5 pins on Main Board is 0.7V. +// - Reference Voltage of A0 ~ A5 pins on External Interface board +// is selected 3.3V or 5.0V by a IO Volt jumper pin. +float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { + return 3.3f; +} + +void analogin_reset(void) { + for (int i = 0; i < MP_ARRAY_SIZE(analogin_dev); i++) { + if (analogin_dev[i].fd >= 0) { + // stop ADC + ioctl(analogin_dev[i].fd, ANIOC_CXD56_STOP, 0); + close(analogin_dev[i].fd); + analogin_dev[i].fd = -1; + } + } +} diff --git a/ports/spresense/common-hal/analogio/AnalogIn.h b/ports/spresense/common-hal/analogio/AnalogIn.h new file mode 100644 index 0000000000..7fc197f98b --- /dev/null +++ b/ports/spresense/common-hal/analogio/AnalogIn.h @@ -0,0 +1,42 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGIN_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGIN_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; + uint8_t number; +} analogio_analogin_obj_t; + +void analogin_reset(void); + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGIN_H diff --git a/ports/spresense/common-hal/analogio/AnalogOut.c b/ports/spresense/common-hal/analogio/AnalogOut.c new file mode 100644 index 0000000000..3f1abe80d1 --- /dev/null +++ b/ports/spresense/common-hal/analogio/AnalogOut.c @@ -0,0 +1,43 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "py/runtime.h" + +#include "shared-bindings/analogio/AnalogOut.h" + +void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { + mp_raise_RuntimeError(translate("AnalogOut functionality not supported")); +} + +void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { +} + +bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { + return true; +} + +void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, uint16_t value) { +} diff --git a/ports/spresense/common-hal/analogio/AnalogOut.h b/ports/spresense/common-hal/analogio/AnalogOut.h new file mode 100644 index 0000000000..60d3cf0a1a --- /dev/null +++ b/ports/spresense/common-hal/analogio/AnalogOut.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGOUT_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGOUT_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; +} analogio_analogout_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGOUT_H diff --git a/ports/spresense/common-hal/analogio/__init__.c b/ports/spresense/common-hal/analogio/__init__.c new file mode 100644 index 0000000000..eea58c77d6 --- /dev/null +++ b/ports/spresense/common-hal/analogio/__init__.c @@ -0,0 +1 @@ +// No analogio module functions. diff --git a/ports/spresense/common-hal/board/__init__.c b/ports/spresense/common-hal/board/__init__.c new file mode 100644 index 0000000000..d123969fea --- /dev/null +++ b/ports/spresense/common-hal/board/__init__.c @@ -0,0 +1,80 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_D0) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_D1) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_D2) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_D3) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_D4) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_D5) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_D6) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_D7) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_D8) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_D9) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_D10) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_D11) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_D12) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_D13) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_D14) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_D15) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_D16) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_D17) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_D18) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_D19) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_D20) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_D21) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_D22) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_D23) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_D24) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_D25) }, + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_D26) }, + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_D27) }, + { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_D28) }, + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_LED0) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_LED1) }, + { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_LED2) }, + { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_LED3) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_A0) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_A1) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_A2) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_A3) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_A4) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_A5) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_D14) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_D15) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_D13) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_D12) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_D11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_D0) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_D1) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/spresense/common-hal/busio/I2C.c b/ports/spresense/common-hal/busio/I2C.c new file mode 100644 index 0000000000..c163c183a9 --- /dev/null +++ b/ports/spresense/common-hal/busio/I2C.c @@ -0,0 +1,123 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include +#include + +#include "py/runtime.h" + +#include "shared-bindings/busio/I2C.h" + +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) { + if (frequency != I2C_SPEED_STANDARD && frequency != I2C_SPEED_FAST) { + mp_raise_ValueError(translate("Unsupported baudrate")); + } + + if (scl->number != PIN_I2C0_BCK || sda->number != PIN_I2C0_BDT) { + mp_raise_ValueError(translate("Invalid pins")); + } + + claim_pin(scl); + claim_pin(sda); + + self->scl_pin = scl; + self->sda_pin = sda; + self->frequency = frequency; + self->i2c_dev = cxd56_i2cbus_initialize(0); +} + +void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { + if (common_hal_busio_i2c_deinited(self)) { + return; + } + + cxd56_i2cbus_uninitialize(self->i2c_dev); + self->i2c_dev = NULL; + + reset_pin_number(self->scl_pin->number); + reset_pin_number(self->sda_pin->number); +} + +bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { + return self->i2c_dev == NULL; +} + +bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { + bool grabbed_lock = false; + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } + return grabbed_lock; +} + +bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) { + return self->has_lock; +} + +void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { + self->has_lock = false; +} + +bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { + struct i2c_msg_s msg; + + msg.frequency = self->frequency; + msg.addr = addr; + msg.flags = 0; + msg.buffer = NULL; + msg.length = 0; + return I2C_TRANSFER(self->i2c_dev, &msg, 1) < 0 ? false : true; +} + +uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t address, const uint8_t *data, size_t len, bool stop) { + struct i2c_msg_s msg; + + msg.frequency = self->frequency; + msg.addr = address; + msg.flags = (stop ? 0 : I2C_M_NOSTOP); + msg.buffer = (uint8_t *) data; + msg.length = len; + 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) { + struct i2c_msg_s msg; + + msg.frequency = self->frequency; + msg.addr = address; + msg.flags = I2C_M_READ; + msg.buffer = data; + msg.length = len; + return I2C_TRANSFER(self->i2c_dev, &msg, 1); +} + +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + never_reset_pin_number(self->scl_pin->number); + never_reset_pin_number(self->sda_pin->number); +} diff --git a/ports/spresense/common-hal/busio/I2C.h b/ports/spresense/common-hal/busio/I2C.h new file mode 100644 index 0000000000..ec2acfb53b --- /dev/null +++ b/ports/spresense/common-hal/busio/I2C.h @@ -0,0 +1,43 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_BUSIO_I2C_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_I2C_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + struct i2c_master_s* i2c_dev; + uint32_t frequency; + bool has_lock; + const mcu_pin_obj_t *scl_pin; + const mcu_pin_obj_t *sda_pin; +} busio_i2c_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/spresense/common-hal/busio/OneWire.h b/ports/spresense/common-hal/busio/OneWire.h new file mode 100644 index 0000000000..a76ee8c777 --- /dev/null +++ b/ports/spresense/common-hal/busio/OneWire.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_BUSIO_ONEWIRE_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_ONEWIRE_H + +// Use bitbangio. +#include "shared-module/busio/OneWire.h" + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/spresense/common-hal/busio/SPI.c b/ports/spresense/common-hal/busio/SPI.c new file mode 100644 index 0000000000..9a41011f2a --- /dev/null +++ b/ports/spresense/common-hal/busio/SPI.c @@ -0,0 +1,155 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include + +#include "py/runtime.h" + +#include "shared-bindings/busio/SPI.h" + +void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, + 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) { + port = 4; + } else if (clock->number == PIN_EMMC_CLK && mosi->number == PIN_EMMC_DATA0 && miso->number == PIN_EMMC_DATA1) { + port = 5; + } + + if (port < 0) { + mp_raise_ValueError(translate("Invalid pins")); + } + + claim_pin(clock); + claim_pin(mosi); + claim_pin(miso); + + self->clock_pin = clock; + self->mosi_pin = mosi; + self->miso_pin = miso; + self->spi_dev = cxd56_spibus_initialize(port); +} + +void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { + if (common_hal_busio_spi_deinited(self)) { + return; + } + + self->spi_dev = NULL; + + reset_pin_number(self->clock_pin->number); + reset_pin_number(self->mosi_pin->number); + reset_pin_number(self->miso_pin->number); +} + +bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) { + return self->spi_dev == NULL; +} + +bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { + uint8_t mode; + + self->frequency = baudrate; + SPI_SETFREQUENCY(self->spi_dev, baudrate); + + if (polarity == 0) { + if (phase == 0) { + mode = SPIDEV_MODE0; + } else { + mode = SPIDEV_MODE1; + } + } else { + if (phase == 0) { + mode = SPIDEV_MODE2; + } else { + mode = SPIDEV_MODE3; + } + } + + self->polarity = polarity; + self->phase = phase; + SPI_SETMODE(self->spi_dev, mode); + + self->bits = bits; + SPI_SETBITS(self->spi_dev, bits); + + return true; +} + +bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { + bool grabbed_lock = false; + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } + return grabbed_lock; +} + +bool common_hal_busio_spi_has_lock(busio_spi_obj_t *self) { + return self->has_lock; +} + +void common_hal_busio_spi_unlock(busio_spi_obj_t *self) { + self->has_lock = false; +} + +bool common_hal_busio_spi_write(busio_spi_obj_t *self, const uint8_t *data, size_t len) { + SPI_EXCHANGE(self->spi_dev, data, NULL, len); + + return true; +} + +bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size_t len, uint8_t write_value) { + SPI_EXCHANGE(self->spi_dev, NULL, data, len); + + return true; +} + +bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) { + SPI_EXCHANGE(self->spi_dev, data_out, data_in, len); + + return true; +} + +uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self) { + return self->frequency; +} + +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { + return self->phase; +} + +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t *self) { + return self->polarity; +} + +void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { + never_reset_pin_number(self->clock_pin->number); + never_reset_pin_number(self->mosi_pin->number); + never_reset_pin_number(self->miso_pin->number); +} diff --git a/ports/spresense/common-hal/busio/SPI.h b/ports/spresense/common-hal/busio/SPI.h new file mode 100644 index 0000000000..90c2f6b81a --- /dev/null +++ b/ports/spresense/common-hal/busio/SPI.h @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_BUSIO_SPI_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_SPI_H + +#include + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + struct spi_dev_s* spi_dev; + uint32_t frequency; + uint8_t phase; + uint8_t polarity; + uint8_t bits; + bool has_lock; + const mcu_pin_obj_t *clock_pin; + const mcu_pin_obj_t *mosi_pin; + const mcu_pin_obj_t *miso_pin; +} busio_spi_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/spresense/common-hal/busio/UART.c b/ports/spresense/common-hal/busio/UART.c new file mode 100644 index 0000000000..2389cbf960 --- /dev/null +++ b/ports/spresense/common-hal/busio/UART.c @@ -0,0 +1,168 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "py/mperrno.h" +#include "py/stream.h" +#include "py/runtime.h" + +#include "shared-bindings/busio/UART.h" + +void common_hal_busio_uart_construct(busio_uart_obj_t *self, + const mcu_pin_obj_t *tx, const mcu_pin_obj_t *rx, uint32_t baudrate, + uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, + uint16_t receiver_buffer_size) { + struct termios tio; + + self->uart_fd = open("/dev/ttyS2", O_RDWR); + if (self->uart_fd < 0) { + mp_raise_ValueError(translate("Could not initialize UART")); + } + + ioctl(self->uart_fd, TCGETS, (long unsigned int)&tio); + tio.c_speed = baudrate; + ioctl(self->uart_fd, TCSETS, (long unsigned int)&tio); + ioctl(self->uart_fd, TCFLSH, (long unsigned int)NULL); + + if (bits != 8) { + mp_raise_ValueError(translate("Could not initialize UART")); + } + + if (parity != PARITY_NONE) { + mp_raise_ValueError(translate("Could not initialize UART")); + } + + if (stop != 1) { + mp_raise_ValueError(translate("Could not initialize UART")); + } + + if (tx->number != PIN_UART2_TXD || rx->number != PIN_UART2_RXD) { + mp_raise_ValueError(translate("Invalid pins")); + } + + claim_pin(tx); + claim_pin(rx); + + self->tx_pin = tx; + self->rx_pin = rx; + self->baudrate = baudrate; + self->timeout = timeout; +} + +void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { + if (common_hal_busio_uart_deinited(self)) { + return; + } + + close(self->uart_fd); + self->uart_fd = -1; + + reset_pin_number(self->tx_pin->number); + reset_pin_number(self->rx_pin->number); +} + +bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { + return self->uart_fd < 0; +} + +size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) { + fd_set rfds; + struct timeval tv; + int retval, bytes_read; + + // make sure we want at least 1 char + if (len == 0) { + return 0; + } + + FD_ZERO(&rfds); + FD_SET(self->uart_fd, &rfds); + + tv.tv_sec = 0; + tv.tv_usec = self->timeout * 1000; + + retval = select(self->uart_fd + 1, &rfds, NULL, NULL, &tv); + + if (retval) { + bytes_read = read(self->uart_fd, data, len); + } else { + *errcode = EAGAIN; + return MP_STREAM_ERROR; + } + + return bytes_read; +} + +size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) { + int bytes_written = write(self->uart_fd, data, len); + + if (bytes_written < 0) { + *errcode = MP_EAGAIN; + return MP_STREAM_ERROR; + } + + return bytes_written; +} + +uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { + return self->baudrate; +} + +void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) { + struct termios tio; + + ioctl(self->uart_fd, TCGETS, (long unsigned int)&tio); + tio.c_speed = baudrate; + ioctl(self->uart_fd, TCSETS, (long unsigned int)&tio); + ioctl(self->uart_fd, TCFLSH, (long unsigned int)NULL); +} + +uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { + int count = 0; + + ioctl(self->uart_fd, FIONREAD, (long unsigned int)&count); + + return count; +} + +void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) { +} + +bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { + ioctl(self->uart_fd, TCFLSH, (long unsigned int)NULL); + return true; +} diff --git a/ports/spresense/common-hal/busio/UART.h b/ports/spresense/common-hal/busio/UART.h new file mode 100644 index 0000000000..7cdbe4ff3b --- /dev/null +++ b/ports/spresense/common-hal/busio/UART.h @@ -0,0 +1,43 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_BUSIO_UART_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_UART_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + int uart_fd; + const mcu_pin_obj_t *tx_pin; + const mcu_pin_obj_t *rx_pin; + uint32_t baudrate; + uint32_t timeout; +} busio_uart_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_UART_H diff --git a/ports/spresense/common-hal/busio/__init__.c b/ports/spresense/common-hal/busio/__init__.c new file mode 100644 index 0000000000..41761b6743 --- /dev/null +++ b/ports/spresense/common-hal/busio/__init__.c @@ -0,0 +1 @@ +// No busio module functions. diff --git a/ports/spresense/common-hal/digitalio/DigitalInOut.c b/ports/spresense/common-hal/digitalio/DigitalInOut.c new file mode 100644 index 0000000000..7b1f6cc031 --- /dev/null +++ b/ports/spresense/common-hal/digitalio/DigitalInOut.c @@ -0,0 +1,136 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "py/runtime.h" + +#include "shared-bindings/digitalio/DigitalInOut.h" + +digitalinout_result_t common_hal_digitalio_digitalinout_construct(digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { + if (pin->analog) { + mp_raise_ValueError(translate("DigitalInOut not supported on given pin")); + } + + claim_pin(pin); + + self->pin = pin; + self->input = true; + self->open_drain = false; + + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, true, true, PIN_FLOAT); + + return DIGITALINOUT_OK; +} + +void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_deinited(self)) { + return; + } + + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); + + reset_pin_number(self->pin->number); + self->pin = mp_const_none; +} + +bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { + return self->pin == mp_const_none; +} + +void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + self->input = true; + self->pull = pull; + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, true, true, pull); +} + +void common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode) { + self->input = false; + self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN; + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); + + if (self->open_drain) { + board_gpio_write(self->pin->number, 0); + } + common_hal_digitalio_digitalinout_set_value(self, value); +} + +digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(digitalio_digitalinout_obj_t *self) { + return self->input ? DIRECTION_INPUT : DIRECTION_OUTPUT; +} + +void common_hal_digitalio_digitalinout_set_value(digitalio_digitalinout_obj_t *self, bool value) { + if (self->open_drain) { + if (value) { + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, true, true, PIN_PULLUP); + } else { + board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); + board_gpio_write(self->pin->number, 0); + } + } else { + board_gpio_write(self->pin->number, value); + } +} + +bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) { + return board_gpio_read(self->pin->number); +} + +void common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { + if (drive_mode == DRIVE_MODE_PUSH_PULL) { + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); + self->open_drain = false; + } else { + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); + board_gpio_write(self->pin->number, 0); + self->open_drain = true; + } +} + +digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitalio_digitalinout_obj_t *self) { + return self->open_drain ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL; +} + +void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + self->pull = pull; + board_gpio_write(self->pin->number, -1); + board_gpio_config(self->pin->number, 0, true, true, pull); +} + +digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self) { + return self->pull; +} + +void common_hal_digitalio_digitalinout_never_reset(digitalio_digitalinout_obj_t *self) { + never_reset_pin_number(self->pin->number); +} diff --git a/ports/spresense/common-hal/digitalio/DigitalInOut.h b/ports/spresense/common-hal/digitalio/DigitalInOut.h new file mode 100644 index 0000000000..a5bfd22bdd --- /dev/null +++ b/ports/spresense/common-hal/digitalio/DigitalInOut.h @@ -0,0 +1,42 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_DIGITALIO_DIGITALINOUT_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_DIGITALIO_DIGITALINOUT_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; + bool input; + bool open_drain; + uint8_t pull; +} digitalio_digitalinout_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_DIGITALIO_DIGITALINOUT_H diff --git a/ports/spresense/common-hal/digitalio/__init__.c b/ports/spresense/common-hal/digitalio/__init__.c new file mode 100644 index 0000000000..20fad45959 --- /dev/null +++ b/ports/spresense/common-hal/digitalio/__init__.c @@ -0,0 +1 @@ +// No digitalio module functions. diff --git a/ports/spresense/common-hal/microcontroller/Pin.c b/ports/spresense/common-hal/microcontroller/Pin.c new file mode 100644 index 0000000000..005defa848 --- /dev/null +++ b/ports/spresense/common-hal/microcontroller/Pin.c @@ -0,0 +1,162 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include +#include +#include +#include + +#include "shared-bindings/microcontroller/Pin.h" + +typedef struct { + const mcu_pin_obj_t *pin; + bool reset; + bool free; +} pin_status_t; + +const mcu_pin_obj_t pin_D0 = PIN(PIN_UART2_RXD, false); +const mcu_pin_obj_t pin_D1 = PIN(PIN_UART2_TXD, false); +const mcu_pin_obj_t pin_D2 = PIN(PIN_HIF_IRQ_OUT, false); +const mcu_pin_obj_t pin_D3 = PIN(PIN_PWM3, false); +const mcu_pin_obj_t pin_D4 = PIN(PIN_SPI2_MOSI, false); +const mcu_pin_obj_t pin_D5 = PIN(PIN_PWM1, false); +const mcu_pin_obj_t pin_D6 = PIN(PIN_PWM0, false); +const mcu_pin_obj_t pin_D7 = PIN(PIN_SPI3_CS1_X, false); +const mcu_pin_obj_t pin_D8 = PIN(PIN_SPI2_MISO, false); +const mcu_pin_obj_t pin_D9 = PIN(PIN_PWM2, false); +const mcu_pin_obj_t pin_D10 = PIN(PIN_SPI4_CS_X, false); +const mcu_pin_obj_t pin_D11 = PIN(PIN_SPI4_MOSI, false); +const mcu_pin_obj_t pin_D12 = PIN(PIN_SPI4_MISO, false); +const mcu_pin_obj_t pin_D13 = PIN(PIN_SPI4_SCK, false); +const mcu_pin_obj_t pin_D14 = PIN(PIN_I2C0_BDT, false); +const mcu_pin_obj_t pin_D15 = PIN(PIN_I2C0_BCK, false); +const mcu_pin_obj_t pin_D16 = PIN(PIN_EMMC_DATA0, false); +const mcu_pin_obj_t pin_D17 = PIN(PIN_EMMC_DATA1, false); +const mcu_pin_obj_t pin_D18 = PIN(PIN_I2S0_DATA_OUT, false); +const mcu_pin_obj_t pin_D19 = PIN(PIN_I2S0_DATA_IN, false); +const mcu_pin_obj_t pin_D20 = PIN(PIN_EMMC_DATA2, false); +const mcu_pin_obj_t pin_D21 = PIN(PIN_EMMC_DATA3, false); +const mcu_pin_obj_t pin_D22 = PIN(PIN_SEN_IRQ_IN, false); +const mcu_pin_obj_t pin_D23 = PIN(PIN_EMMC_CLK, false); +const mcu_pin_obj_t pin_D24 = PIN(PIN_EMMC_CMD, false); +const mcu_pin_obj_t pin_D25 = PIN(PIN_I2S0_LRCK, false); +const mcu_pin_obj_t pin_D26 = PIN(PIN_I2S0_BCK, false); +const mcu_pin_obj_t pin_D27 = PIN(PIN_UART2_CTS, false); +const mcu_pin_obj_t pin_D28 = PIN(PIN_UART2_RTS, false); +const mcu_pin_obj_t pin_LED0 = PIN(PIN_I2S1_BCK, false); +const mcu_pin_obj_t pin_LED1 = PIN(PIN_I2S1_LRCK, false); +const mcu_pin_obj_t pin_LED2 = PIN(PIN_I2S1_DATA_IN, false); +const mcu_pin_obj_t pin_LED3 = PIN(PIN_I2S1_DATA_OUT, false); +const mcu_pin_obj_t pin_A0 = PIN(0, true); +const mcu_pin_obj_t pin_A1 = PIN(1, true); +const mcu_pin_obj_t pin_A2 = PIN(2, true); +const mcu_pin_obj_t pin_A3 = PIN(3, true); +const mcu_pin_obj_t pin_A4 = PIN(4, true); +const mcu_pin_obj_t pin_A5 = PIN(5, true); + +STATIC pin_status_t pins[] = { + { &pin_D0, true, true }, + { &pin_D1, true, true }, + { &pin_D2, true, true }, + { &pin_D3, true, true }, + { &pin_D4, true, true }, + { &pin_D5, true, true }, + { &pin_D6, true, true }, + { &pin_D7, true, true }, + { &pin_D8, true, true }, + { &pin_D9, true, true }, + { &pin_D10, true, true }, + { &pin_D11, true, true }, + { &pin_D12, true, true }, + { &pin_D13, true, true }, + { &pin_D14, true, true }, + { &pin_D15, true, true }, + { &pin_D16, true, true }, + { &pin_D17, true, true }, + { &pin_D18, true, true }, + { &pin_D19, true, true }, + { &pin_D20, true, true }, + { &pin_D21, true, true }, + { &pin_D22, true, true }, + { &pin_D23, true, true }, + { &pin_D24, true, true }, + { &pin_D25, true, true }, + { &pin_D26, true, true }, + { &pin_D27, true, true }, + { &pin_D28, true, true }, + { &pin_LED0, true, true }, + { &pin_LED1, true, true }, + { &pin_LED2, true, true }, + { &pin_LED3, true, true }, +}; + +bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { + for (int i = 0; i < MP_ARRAY_SIZE(pins); i++) { + if (pins[i].pin->number == pin->number) { + return pins[i].free; + } + } + + return true; +} + +void never_reset_pin_number(uint8_t pin_number) { + for (int i = 0; i < MP_ARRAY_SIZE(pins); i++) { + if (pins[i].pin->number == pin_number) { + pins[i].reset = false; + } + } +} + +void reset_pin_number(uint8_t pin_number) { + for (int i = 0; i < MP_ARRAY_SIZE(pins); i++) { + if (pins[i].pin->number == pin_number) { + pins[i].free = true; + } + } +} + +void reset_all_pins(void) { + for (int i = 0; i < MP_ARRAY_SIZE(pins); i++) { + if (!pins[i].free && pins[i].reset) { + board_gpio_write(pins[i].pin->number, -1); + board_gpio_config(pins[i].pin->number, 0, false, true, PIN_FLOAT); + board_gpio_int(pins[i].pin->number, false); + board_gpio_intconfig(pins[i].pin->number, 0, false, NULL); + pins[i].free = true; + } + } +} + +void claim_pin(const mcu_pin_obj_t *pin) { + for (int i = 0; i < MP_ARRAY_SIZE(pins); i++) { + if (pins[i].pin->number == pin->number) { + pins[i].free = false; + } + } +} diff --git a/ports/spresense/common-hal/microcontroller/Pin.h b/ports/spresense/common-hal/microcontroller/Pin.h new file mode 100644 index 0000000000..2d995d0dd3 --- /dev/null +++ b/ports/spresense/common-hal/microcontroller/Pin.h @@ -0,0 +1,92 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PIN_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PIN_H + +#include "py/obj.h" + +extern const mp_obj_type_t mcu_pin_type; + +#define PIN(pin, a) \ +{ \ + { &mcu_pin_type }, \ + .number = (pin), \ + .analog = (a) \ +} + +typedef struct { + mp_obj_base_t base; + uint8_t number; + bool analog; +} mcu_pin_obj_t; + +extern const mcu_pin_obj_t pin_D0; +extern const mcu_pin_obj_t pin_D1; +extern const mcu_pin_obj_t pin_D2; +extern const mcu_pin_obj_t pin_D3; +extern const mcu_pin_obj_t pin_D4; +extern const mcu_pin_obj_t pin_D5; +extern const mcu_pin_obj_t pin_D6; +extern const mcu_pin_obj_t pin_D7; +extern const mcu_pin_obj_t pin_D8; +extern const mcu_pin_obj_t pin_D9; +extern const mcu_pin_obj_t pin_D10; +extern const mcu_pin_obj_t pin_D11; +extern const mcu_pin_obj_t pin_D12; +extern const mcu_pin_obj_t pin_D13; +extern const mcu_pin_obj_t pin_D14; +extern const mcu_pin_obj_t pin_D15; +extern const mcu_pin_obj_t pin_D16; +extern const mcu_pin_obj_t pin_D17; +extern const mcu_pin_obj_t pin_D18; +extern const mcu_pin_obj_t pin_D19; +extern const mcu_pin_obj_t pin_D20; +extern const mcu_pin_obj_t pin_D21; +extern const mcu_pin_obj_t pin_D22; +extern const mcu_pin_obj_t pin_D23; +extern const mcu_pin_obj_t pin_D24; +extern const mcu_pin_obj_t pin_D25; +extern const mcu_pin_obj_t pin_D26; +extern const mcu_pin_obj_t pin_D27; +extern const mcu_pin_obj_t pin_D28; +extern const mcu_pin_obj_t pin_LED0; +extern const mcu_pin_obj_t pin_LED1; +extern const mcu_pin_obj_t pin_LED2; +extern const mcu_pin_obj_t pin_LED3; +extern const mcu_pin_obj_t pin_A0; +extern const mcu_pin_obj_t pin_A1; +extern const mcu_pin_obj_t pin_A2; +extern const mcu_pin_obj_t pin_A3; +extern const mcu_pin_obj_t pin_A4; +extern const mcu_pin_obj_t pin_A5; + +void never_reset_pin_number(uint8_t pin_number); +void reset_pin_number(uint8_t pin_number); +void reset_all_pins(void); +void claim_pin(const mcu_pin_obj_t* pin); + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PIN_H diff --git a/ports/spresense/common-hal/microcontroller/Processor.c b/ports/spresense/common-hal/microcontroller/Processor.c new file mode 100644 index 0000000000..355ee01df5 --- /dev/null +++ b/ports/spresense/common-hal/microcontroller/Processor.c @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "py/mphal.h" + +uint32_t common_hal_mcu_processor_get_frequency(void) { + return mp_hal_ticks_cpu(); +} + +float common_hal_mcu_processor_get_temperature(void) { + return 0; +} + +void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + boardctl(BOARDIOC_UNIQUEID, (uintptr_t) raw_id); +} diff --git a/ports/spresense/common-hal/microcontroller/Processor.h b/ports/spresense/common-hal/microcontroller/Processor.h new file mode 100644 index 0000000000..6c4c17b035 --- /dev/null +++ b/ports/spresense/common-hal/microcontroller/Processor.h @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H + +#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH CONFIG_BOARDCTL_UNIQUEID_SIZE + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; +} mcu_processor_obj_t; + +const mp_obj_type_t mcu_processor_type; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H diff --git a/ports/spresense/common-hal/microcontroller/__init__.c b/ports/spresense/common-hal/microcontroller/__init__.c new file mode 100644 index 0000000000..576896eb23 --- /dev/null +++ b/ports/spresense/common-hal/microcontroller/__init__.c @@ -0,0 +1,111 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "py/mphal.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/__init__.h" +#include "common-hal/microcontroller/Pin.h" +#include "supervisor/filesystem.h" +#include "supervisor/shared/safe_mode.h" + +// The singleton microcontroller.Processor object, bound to microcontroller.cpu +// It currently only has properties, and no state. +const mcu_processor_obj_t common_hal_mcu_processor_obj = { + .base = { + .type = &mcu_processor_type, + }, +}; + +void common_hal_mcu_delay_us(uint32_t delay) { + mp_hal_delay_us(delay); +} + +void common_hal_mcu_disable_interrupts(void) { + __asm volatile ("cpsid i" : : : "memory"); +} + +void common_hal_mcu_enable_interrupts(void) { + __asm volatile ("cpsie i" : : : "memory"); +} + +void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { + if(runmode == RUNMODE_BOOTLOADER) { + mp_raise_ValueError(translate("Cannot reset into bootloader because no bootloader is present.")); + } else if(runmode == RUNMODE_SAFE_MODE) { + safe_mode_on_next_reset(PROGRAMMATIC_SAFE_MODE); + } +} + +void common_hal_mcu_reset(void) { + filesystem_flush(); + boardctl(BOARDIOC_RESET, 0); +} + +STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_D0) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_D1) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_D2) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_D3) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_D4) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_D5) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_D6) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_D7) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_D8) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_D9) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_D10) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_D11) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_D12) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_D13) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_D14) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_D15) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_D16) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_D17) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_D18) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_D19) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_D20) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_D21) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_D22) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_D23) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_D24) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_D25) }, + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_D26) }, + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_D27) }, + { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_D28) }, + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_LED0) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_LED1) }, + { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_LED2) }, + { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_LED3) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_A0) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_A1) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_A2) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_A3) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_A4) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_A5) }, +}; +MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_globals_table); diff --git a/ports/spresense/common-hal/os/__init__.c b/ports/spresense/common-hal/os/__init__.c new file mode 100644 index 0000000000..d4b0e23bec --- /dev/null +++ b/ports/spresense/common-hal/os/__init__.c @@ -0,0 +1,72 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "genhdr/mpversion.h" +#include "py/objstr.h" +#include "py/objtuple.h" + +STATIC const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; + +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "spresense"); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "spresense"); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +STATIC MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj +); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + +bool common_hal_os_urandom(uint8_t* buffer, mp_uint_t length) { + uint32_t i = 0; + + while (i < length) { + uint32_t new_random = rand(); + for (int j = 0; j < 4 && i < length; j++) { + buffer[i] = new_random & 0xff; + i++; + new_random >>= 8; + } + } + + return true; +} diff --git a/ports/spresense/common-hal/pulseio/PWMOut.c b/ports/spresense/common-hal/pulseio/PWMOut.c new file mode 100644 index 0000000000..fae49aed3e --- /dev/null +++ b/ports/spresense/common-hal/pulseio/PWMOut.c @@ -0,0 +1,157 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include +#include + +#include "py/runtime.h" + +#include "shared-bindings/pulseio/PWMOut.h" + +typedef struct { + const char* devpath; + const mcu_pin_obj_t *pin; + int fd; + bool reset; +} pwmout_dev_t; + +STATIC pwmout_dev_t pwmout_dev[] = { + {"/dev/pwm0", &pin_D6, -1, true}, + {"/dev/pwm1", &pin_D5, -1, true}, + {"/dev/pwm2", &pin_D9, -1, true}, + {"/dev/pwm3", &pin_D3, -1, true} +}; + +pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, + const mcu_pin_obj_t *pin, uint16_t duty, uint32_t frequency, + bool variable_frequency) { + self->number = -1; + + for (int i = 0; i < MP_ARRAY_SIZE(pwmout_dev); i++) { + if (pin->number == pwmout_dev[i].pin->number) { + self->number = i; + break; + } + } + + if (self->number < 0) { + return PWMOUT_INVALID_PIN; + } + + pwmout_dev[self->number].fd = open(pwmout_dev[self->number].devpath, O_RDONLY); + if (pwmout_dev[self->number].fd < 0) { + return PWMOUT_INVALID_PIN; + } + + self->info.frequency = frequency; + self->info.duty = duty; + self->variable_frequency = variable_frequency; + + if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) { + mp_raise_ValueError(translate("Invalid PWM frequency")); + } + ioctl(pwmout_dev[self->number].fd, PWMIOC_START, 0); + + claim_pin(pin); + + self->pin = pin; + + return PWMOUT_OK; +} + +void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) { + if (common_hal_pulseio_pwmout_deinited(self)) { + return; + } + + ioctl(pwmout_dev[self->number].fd, PWMIOC_STOP, 0); + close(pwmout_dev[self->number].fd); + pwmout_dev[self->number].fd = -1; + + reset_pin_number(self->pin->number); + self->pin = mp_const_none; +} + +bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) { + return self->pin == mp_const_none; +} + +void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16_t duty) { + self->info.duty = duty; + + ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)); +} + +uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t *self) { + return self->info.duty; +} + +void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t *self, uint32_t frequency) { + self->info.frequency = frequency; + + if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) { + mp_raise_ValueError(translate("Invalid PWM frequency")); + } +} + +uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t *self) { + return self->info.frequency; +} + +bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self) { + return self->variable_frequency; +} + +void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { + never_reset_pin_number(self->pin->number); + + pwmout_dev[self->number].reset = false; +} + +void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { + pwmout_dev[self->number].reset = true; +} + +void pwmout_reset(void) { + for (int i = 0; i < MP_ARRAY_SIZE(pwmout_dev); i++) { + if (pwmout_dev[i].fd >= 0 && pwmout_dev[i].reset) { + ioctl(pwmout_dev[i].fd, PWMIOC_STOP, 0); + close(pwmout_dev[i].fd); + pwmout_dev[i].fd = -1; + + reset_pin_number(pwmout_dev[i].pin->number); + } + } +} + +void pwmout_start(uint8_t pwm_num) { + ioctl(pwmout_dev[pwm_num].fd, PWMIOC_START, 0); +} + +void pwmout_stop(uint8_t pwm_num) { + ioctl(pwmout_dev[pwm_num].fd, PWMIOC_STOP, 0); +} diff --git a/ports/spresense/common-hal/pulseio/PWMOut.h b/ports/spresense/common-hal/pulseio/PWMOut.h new file mode 100644 index 0000000000..486d5add96 --- /dev/null +++ b/ports/spresense/common-hal/pulseio/PWMOut.h @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_PULSEIO_PWMOUT_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PWMOUT_H + +#include + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; + struct pwm_info_s info; + bool variable_frequency; + uint8_t number; +} pulseio_pwmout_obj_t; + +void pwmout_reset(void); +void pwmout_start(uint8_t pwm_num); +void pwmout_stop(uint8_t pwm_num); + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PWMOUT_H diff --git a/ports/spresense/common-hal/pulseio/PulseIn.c b/ports/spresense/common-hal/pulseio/PulseIn.c new file mode 100644 index 0000000000..dd2773d1d0 --- /dev/null +++ b/ports/spresense/common-hal/pulseio/PulseIn.c @@ -0,0 +1,196 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "py/runtime.h" +#include "py/mphal.h" + +#include "shared-bindings/pulseio/PulseIn.h" +#include "shared-bindings/microcontroller/__init__.h" + +static pulseio_pulsein_obj_t *pulsein_objects[12]; + +static int pulsein_interrupt_handler(int irq, FAR void *context, FAR void *arg); + +static int pulsein_set_config(pulseio_pulsein_obj_t *self, bool first_edge) { + int mode; + + if (!first_edge) { + mode = INT_BOTH_EDGE; + } else if (self->idle_state) { + mode = INT_FALLING_EDGE; + } else { + mode = INT_RISING_EDGE; + } + return board_gpio_intconfig(self->pin->number, mode, false, pulsein_interrupt_handler); +} + +static int pulsein_interrupt_handler(int irq, FAR void *context, FAR void *arg) { + // Grab the current time first. + uint32_t current_us = mp_hal_ticks_us(); + + pulseio_pulsein_obj_t *self = pulsein_objects[irq - CXD56_IRQ_EXDEVICE_0]; + + if (self->first_edge) { + self->first_edge = false; + pulsein_set_config(self, false); + board_gpio_int(self->pin->number, true); + } else { + uint32_t us_diff = current_us - self->last_us; + + uint16_t duration = 0xffff; + if (us_diff < duration) { + duration = us_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_us = current_us; + + return 0; +} + +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; + self->maxlen = maxlen; + self->idle_state = idle_state; + self->start = 0; + self->len = 0; + self->first_edge = true; + self->paused = false; + + int irq = pulsein_set_config(self, true); + if (irq < 0) { + mp_raise_RuntimeError(translate("EXTINT channel already in use")); + } else { + pulsein_objects[irq - CXD56_IRQ_EXDEVICE_0] = self; + } + + claim_pin(pin); + + board_gpio_int(self->pin->number, true); +} + +void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { + if (common_hal_pulseio_pulsein_deinited(self)) { + return; + } + + board_gpio_int(self->pin->number, false); + board_gpio_intconfig(self->pin->number, 0, false, NULL); + + reset_pin_number(self->pin->number); + self->pin = mp_const_none; +} + +bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) { + return self->pin == mp_const_none; +} + +void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) { + board_gpio_int(self->pin->number, false); + self->paused = true; +} + +void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t trigger_duration) { + // Make sure we're paused. + common_hal_pulseio_pulsein_pause(self); + + // Send the trigger pulse. + if (trigger_duration > 0) { + board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT); + board_gpio_write(self->pin->number, !self->idle_state); + common_hal_mcu_delay_us((uint32_t)trigger_duration); + board_gpio_write(self->pin->number, self->idle_state); + } + + // Reconfigure the pin and make sure its set to detect the first edge. + self->first_edge = true; + self->paused = false; + + pulsein_set_config(self, true); + board_gpio_int(self->pin->number, true); +} + +void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) { + common_hal_mcu_disable_interrupts(); + self->start = 0; + self->len = 0; + common_hal_mcu_enable_interrupts(); +} + +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")); + } + common_hal_mcu_disable_interrupts(); + uint16_t value = self->buffer[self->start]; + self->start = (self->start + 1) % self->maxlen; + self->len--; + common_hal_mcu_enable_interrupts(); + + 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; +} + +uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_t index) { + common_hal_mcu_disable_interrupts(); + if (index < 0) { + index += self->len; + } + if (index < 0 || index >= self->len) { + common_hal_mcu_enable_interrupts(); + mp_raise_IndexError(translate("index out of range")); + } + uint16_t value = self->buffer[(self->start + index) % self->maxlen]; + common_hal_mcu_enable_interrupts(); + return value; +} + \ No newline at end of file diff --git a/ports/spresense/common-hal/pulseio/PulseIn.h b/ports/spresense/common-hal/pulseio/PulseIn.h new file mode 100644 index 0000000000..5f2f318110 --- /dev/null +++ b/ports/spresense/common-hal/pulseio/PulseIn.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_PULSEIO_PULSEIN_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEIN_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; + uint16_t *buffer; + uint16_t maxlen; + uint16_t start; + uint16_t len; + uint32_t last_us; + bool idle_state; + bool first_edge; + bool paused; +} pulseio_pulsein_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEIN_H diff --git a/ports/spresense/common-hal/pulseio/PulseOut.c b/ports/spresense/common-hal/pulseio/PulseOut.c new file mode 100644 index 0000000000..5e1d5a2ed4 --- /dev/null +++ b/ports/spresense/common-hal/pulseio/PulseOut.c @@ -0,0 +1,126 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include +#include +#include + +#include "py/runtime.h" + +#include "shared-bindings/pulseio/PulseOut.h" + +static uint16_t *pulse_buffer = NULL; +static uint16_t pulse_index = 0; +static uint16_t pulse_length; +static int pulse_fd = -1; + +static bool pulseout_timer_handler(unsigned int *next_interval_us, void *arg) +{ + uint8_t pwm_num = (uint8_t)(int)arg; + pulse_index++; + + if (pulse_index >= pulse_length) { + return false; + } + + *next_interval_us = pulse_buffer[pulse_index] * 1000; + + if (pulse_index % 2 == 0) { + pwmout_start(pwm_num); + } else { + pwmout_stop(pwm_num); + } + + return true; +} + +void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self, + const pulseio_pwmout_obj_t *carrier) { + if (pulse_fd < 0) { + pulse_fd = open("/dev/timer0", O_RDONLY); + } + + if (pulse_fd < 0) { + mp_raise_RuntimeError(translate("All timers in use")); + } + + self->pwm_num = carrier->number; +} + +void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) { + if (common_hal_pulseio_pulseout_deinited(self)) { + return; + } + + ioctl(pulse_fd, TCIOC_STOP, 0); + close(pulse_fd); + pulse_fd = -1; + + pulse_buffer = NULL; +} + +bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) { + return pulse_fd < 0; +} + +void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pulses, uint16_t len) { + if (pulse_buffer != NULL) { + mp_raise_RuntimeError(translate("Another send is already active")); + } + + struct timer_sethandler_s sethandler; + + pulse_buffer = pulses; + pulse_index = 0; + pulse_length = len; + + unsigned long timeout = pulse_buffer[0] * 1000; + + ioctl(pulse_fd, TCIOC_SETTIMEOUT, timeout); + + sethandler.handler = pulseout_timer_handler; + sethandler.arg = (void *)(int)self->pwm_num; + + ioctl(pulse_fd, TCIOC_SETHANDLER, (unsigned long)&sethandler); + ioctl(pulse_fd, TCIOC_START, 0); + + while(pulse_index < len) { + // Do other things while we wait. The interrupts will handle sending the + // signal. + RUN_BACKGROUND_TASKS; + } + + pulse_buffer = NULL; +} + +void pulseout_reset(void) { + ioctl(pulse_fd, TCIOC_STOP, 0); + close(pulse_fd); + pulse_fd = -1; + + pulse_buffer = NULL; +} diff --git a/ports/spresense/common-hal/pulseio/PulseOut.h b/ports/spresense/common-hal/pulseio/PulseOut.h new file mode 100644 index 0000000000..652a1197ed --- /dev/null +++ b/ports/spresense/common-hal/pulseio/PulseOut.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_PULSEIO_PULSEOUT_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEOUT_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint8_t pwm_num; +} pulseio_pulseout_obj_t; + +void pulseout_reset(void); + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEOUT_H diff --git a/ports/spresense/common-hal/pulseio/__init__.c b/ports/spresense/common-hal/pulseio/__init__.c new file mode 100644 index 0000000000..2bee925bc7 --- /dev/null +++ b/ports/spresense/common-hal/pulseio/__init__.c @@ -0,0 +1 @@ +// No pulseio module functions. diff --git a/ports/spresense/common-hal/rtc/RTC.c b/ports/spresense/common-hal/rtc/RTC.c new file mode 100644 index 0000000000..ce65e6acde --- /dev/null +++ b/ports/spresense/common-hal/rtc/RTC.c @@ -0,0 +1,54 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/rtc/RTC.h" + +void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { + struct timeval tv; + + gettimeofday(&tv, NULL); + timeutils_seconds_since_2000_to_struct_time(tv.tv_sec, tm); +} + +void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { + struct timeval tv = {0}; + + tv.tv_sec = timeutils_seconds_since_2000(tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + settimeofday(&tv, NULL); +} + +int common_hal_rtc_get_calibration(void) { + return 0; +} + +void common_hal_rtc_set_calibration(int calibration) { + mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board")); +} diff --git a/ports/spresense/common-hal/rtc/RTC.h b/ports/spresense/common-hal/rtc/RTC.h new file mode 100644 index 0000000000..7a3ef18bd5 --- /dev/null +++ b/ports/spresense/common-hal/rtc/RTC.h @@ -0,0 +1,30 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_RTC_RTC_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_RTC_RTC_H + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_RTC_RTC_H diff --git a/ports/spresense/common-hal/rtc/__init__.c b/ports/spresense/common-hal/rtc/__init__.c new file mode 100644 index 0000000000..92d25d563e --- /dev/null +++ b/ports/spresense/common-hal/rtc/__init__.c @@ -0,0 +1 @@ +// No rtc module functions. diff --git a/ports/spresense/common-hal/supervisor/Runtime.c b/ports/spresense/common-hal/supervisor/Runtime.c new file mode 100755 index 0000000000..a0d9e70ab1 --- /dev/null +++ b/ports/spresense/common-hal/supervisor/Runtime.c @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "shared-bindings/supervisor/Runtime.h" +#include "supervisor/serial.h" + +bool common_hal_get_serial_connected(void) { + return (bool) serial_connected(); +} + +bool common_hal_get_serial_bytes_available(void) { + return (bool) serial_bytes_available(); +} diff --git a/ports/spresense/common-hal/supervisor/Runtime.h b/ports/spresense/common-hal/supervisor/Runtime.h new file mode 100755 index 0000000000..c3ed62a25d --- /dev/null +++ b/ports/spresense/common-hal/supervisor/Runtime.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_COMMON_HAL_SUPERVISOR_RUNTIME_H +#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_SUPERVISOR_RUNTIME_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; +} super_runtime_obj_t; + +#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_SUPERVISOR_RUNTIME_H diff --git a/ports/spresense/common-hal/supervisor/__init__.c b/ports/spresense/common-hal/supervisor/__init__.c new file mode 100755 index 0000000000..e240525f22 --- /dev/null +++ b/ports/spresense/common-hal/supervisor/__init__.c @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "shared-bindings/supervisor/__init__.h" +#include "shared-bindings/supervisor/Runtime.h" + +// The singleton supervisor.Runtime object, bound to supervisor.runtime +// It currently only has properties, and no state. +const super_runtime_obj_t common_hal_supervisor_runtime_obj = { + .base = { + .type = &supervisor_runtime_type, + }, +}; diff --git a/ports/spresense/common-hal/time/__init__.c b/ports/spresense/common-hal/time/__init__.c new file mode 100644 index 0000000000..8f7326b629 --- /dev/null +++ b/ports/spresense/common-hal/time/__init__.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "py/mphal.h" + +#include "tick.h" + +uint64_t common_hal_time_monotonic(void) { + return ticks_ms; +} + +void common_hal_time_delay_ms(uint32_t delay) { + mp_hal_delay_ms(delay); +} diff --git a/ports/spresense/fatfs_port.c b/ports/spresense/fatfs_port.c new file mode 100644 index 0000000000..e986b4c6eb --- /dev/null +++ b/ports/spresense/fatfs_port.c @@ -0,0 +1,46 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "py/mphal.h" +#include "py/runtime.h" +#include "lib/oofatfs/ff.h" /* FatFs lower layer API */ +#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ +#include "lib/timeutils/timeutils.h" + +#if CIRCUITPY_RTC +#include "shared-bindings/rtc/RTC.h" +#endif + +DWORD get_fattime(void) { +#if CIRCUITPY_RTC + timeutils_struct_time_t tm; + common_hal_rtc_get_time(&tm); + return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | + (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); +#else + return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); +#endif +} diff --git a/ports/spresense/mpconfigboard.h b/ports/spresense/mpconfigboard.h new file mode 100644 index 0000000000..e0fef60f03 --- /dev/null +++ b/ports/spresense/mpconfigboard.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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. + */ + +#define MICROPY_HW_BOARD_NAME "SPRESENSE" +#define MICROPY_HW_MCU_NAME "CXD5602" +#define MICROPY_PY_SYS_PLATFORM "SPRESENSE" + +#define DEFAULT_I2C_BUS_SCL (&pin_D15) +#define DEFAULT_I2C_BUS_SDA (&pin_D14) + +#define DEFAULT_SPI_BUS_SCK (&pin_D13) +#define DEFAULT_SPI_BUS_MISO (&pin_D12) +#define DEFAULT_SPI_BUS_MOSI (&pin_D11) + +#define DEFAULT_UART_BUS_RX (&pin_D0) +#define DEFAULT_UART_BUS_TX (&pin_D1) diff --git a/ports/spresense/mpconfigport.h b/ports/spresense/mpconfigport.h new file mode 100644 index 0000000000..233b7b9a7b --- /dev/null +++ b/ports/spresense/mpconfigport.h @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 __INCLUDED_MPCONFIGPORT_H +#define __INCLUDED_MPCONFIGPORT_H + +// 24kiB stack +#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 + +#include "py/circuitpy_mpconfig.h" + +#define MICROPY_PORT_ROOT_POINTERS \ + CIRCUITPY_COMMON_ROOT_POINTERS \ + +#endif // __INCLUDED_MPCONFIGPORT_H diff --git a/ports/spresense/mpconfigport.mk b/ports/spresense/mpconfigport.mk new file mode 100644 index 0000000000..53dba28403 --- /dev/null +++ b/ports/spresense/mpconfigport.mk @@ -0,0 +1,24 @@ +USB_VID = 0x054c +USB_PID = 0x0bc2 +USB_PRODUCT = "Spresense" +USB_MANUFACTURER = "Sony" +USB_SERIAL_NUMBER_LENGTH = 10 +USB_DEVICES = "CDC,MSC" +USB_MSC_MAX_PACKET_SIZE = 512 +USB_RENUMBER_ENDPOINTS = 0 +USB_CDC_EP_NUM_NOTIFICATION = 3 +USB_CDC_EP_NUM_DATA_OUT = 2 +USB_CDC_EP_NUM_DATA_IN = 1 +USB_MSC_EP_NUM_OUT = 5 +USB_MSC_EP_NUM_IN = 4 + +CIRCUITPY_AUDIOIO = 0 +CIRCUITPY_AUDIOBUSIO = 0 +CIRCUITPY_I2CSLAVE = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_TOUCHIO = 0 +CIRCUITPY_GAMEPAD = 0 +CIRCUITPY_NEOPIXEL_WRITE = 0 +CIRCUITPY_NVM = 0 +CIRCUITPY_DISPLAYIO = 0 +CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/spresense/mphalport.c b/ports/spresense/mphalport.c new file mode 100644 index 0000000000..79d93f9759 --- /dev/null +++ b/ports/spresense/mphalport.c @@ -0,0 +1,88 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include +#include +#include + +#include "py/mpstate.h" + +#include "tick.h" + +#define DELAY_CORRECTION (700) +#define DELAY_INTERVAL (50) + +void mp_hal_init(void) { + boardctl(BOARDIOC_INIT, 0); +} + +mp_uint_t mp_hal_ticks_ms(void) { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000 + tv.tv_usec / 1000; +} + +mp_uint_t mp_hal_ticks_us(void) { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000000 + tv.tv_usec; +} + +mp_uint_t mp_hal_ticks_cpu(void) { + return cxd56_get_cpu_baseclk(); +} + +void mp_hal_delay_ms(mp_uint_t delay) { + uint64_t start_tick = ticks_ms; + uint64_t duration = 0; + while (duration < delay) { + #ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP + #endif + // Check to see if we've been CTRL-Ced by autoreload or the user. + if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) || + MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) { + break; + } + duration = (ticks_ms - start_tick); + // TODO(tannewt): Go to sleep for a little while while we wait. + } +} + +void mp_hal_delay_us(uint32_t us) { + if (us) { + unsigned long long ticks = mp_hal_ticks_cpu() / 1000000L * us; + if (ticks < DELAY_CORRECTION) return; // delay time already used in calculation + + ticks -= DELAY_CORRECTION; + ticks /= 6; + // following loop takes 6 cycles + do { + __asm__ __volatile__("nop"); + } while(--ticks); + } +} diff --git a/ports/spresense/mphalport.h b/ports/spresense/mphalport.h new file mode 100644 index 0000000000..8b397d41e4 --- /dev/null +++ b/ports/spresense/mphalport.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_MPHALPORT_H +#define MICROPY_INCLUDED_SPRESENSE_MPHALPORT_H + +#include + +#include "lib/utils/interrupt_char.h" + +extern volatile uint64_t ticks_ms; + +#endif // MICROPY_INCLUDED_SPRESENSE_MPHALPORT_H diff --git a/ports/spresense/qstrdefsport.h b/ports/spresense/qstrdefsport.h new file mode 100644 index 0000000000..3ba897069b --- /dev/null +++ b/ports/spresense/qstrdefsport.h @@ -0,0 +1 @@ +// qstrs specific to this port diff --git a/ports/spresense/supervisor/cpu.s b/ports/spresense/supervisor/cpu.s new file mode 100755 index 0000000000..9e6807a5e2 --- /dev/null +++ b/ports/spresense/supervisor/cpu.s @@ -0,0 +1,27 @@ +.syntax unified +.cpu cortex-m4 +.thumb +.text +.align 2 + +@ uint cpu_get_regs_and_sp(r0=uint regs[10]) +.global cpu_get_regs_and_sp +.thumb +.thumb_func +.type cpu_get_regs_and_sp, %function +cpu_get_regs_and_sp: +@ store registers into given array +str r4, [r0], #4 +str r5, [r0], #4 +str r6, [r0], #4 +str r7, [r0], #4 +str r8, [r0], #4 +str r9, [r0], #4 +str r10, [r0], #4 +str r11, [r0], #4 +str r12, [r0], #4 +str r13, [r0], #4 + +@ return the sp +mov r0, sp +bx lr diff --git a/ports/spresense/supervisor/internal_flash.c b/ports/spresense/supervisor/internal_flash.c new file mode 100644 index 0000000000..0c9a61e063 --- /dev/null +++ b/ports/spresense/supervisor/internal_flash.c @@ -0,0 +1,114 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 + +#include "supervisor/flash.h" + +/* Prototypes for Remote API */ + +int FM_RawWrite(uint32_t offset, const void *buf, uint32_t size); +int FM_RawVerifyWrite(uint32_t offset, const void *buf, uint32_t size); +int FM_RawRead(uint32_t offset, void *buf, uint32_t size); +int FM_RawEraseSector(uint32_t sector); + +#define CXD56_SPIFLASHSIZE (16 * 1024 * 1024) + +#define SECTOR_SHIFT 12 +#define SECTOR_SIZE (1 << SECTOR_SHIFT) + +#define PAGE_SHIFT 9 +#define PAGE_SIZE (1 << PAGE_SHIFT) + +#define NO_SECTOR 0xffffffff + +uint8_t flash_cache[SECTOR_SIZE]; +uint32_t flash_sector = NO_SECTOR; + +void supervisor_flash_init(void) { +} + +uint32_t supervisor_flash_get_block_size(void) { + return FILESYSTEM_BLOCK_SIZE; +} + +uint32_t supervisor_flash_get_block_count(void) { + return CXD56_SPIFLASHSIZE >> PAGE_SHIFT; +} + +void supervisor_flash_flush(void) { + if (flash_sector == NO_SECTOR) { + return; + } + + FM_RawEraseSector(flash_sector); + FM_RawWrite(flash_sector << SECTOR_SHIFT, flash_cache, SECTOR_SIZE); + + flash_sector = NO_SECTOR; +} + +mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { + supervisor_flash_flush(); + + if (FM_RawRead(block << PAGE_SHIFT, dest, num_blocks << PAGE_SHIFT) < 0) { + return 1; + } + + return 0; // success +} + +mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32_t num_blocks) { + uint32_t sector; + uint32_t block_position; + uint32_t current_block = 0; + + while (num_blocks--) { + sector = (lba << PAGE_SHIFT) >> SECTOR_SHIFT; + block_position = lba - 8 * sector; + + if (sector != flash_sector) { + supervisor_flash_flush(); + + if (FM_RawRead(sector << SECTOR_SHIFT, flash_cache, SECTOR_SIZE) < 0) { + return 1; + } + + if (memcmp(&flash_cache[block_position << PAGE_SHIFT], &src[current_block << PAGE_SHIFT], PAGE_SIZE) != 0) { + flash_sector = sector; + } + } + + memcpy(&flash_cache[block_position << PAGE_SHIFT], &src[current_block << PAGE_SHIFT], PAGE_SIZE); + + lba++; + current_block++; + } + + return 0; // success +} + +void supervisor_flash_release_cache(void) { +} diff --git a/ports/spresense/supervisor/internal_flash.h b/ports/spresense/supervisor/internal_flash.h new file mode 100644 index 0000000000..bc4e98baf3 --- /dev/null +++ b/ports/spresense/supervisor/internal_flash.h @@ -0,0 +1,30 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_INTERNAL_FLASH_H +#define MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_H + +#endif // MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_H diff --git a/ports/spresense/supervisor/internal_flash_root_pointers.h b/ports/spresense/supervisor/internal_flash_root_pointers.h new file mode 100644 index 0000000000..87f478d130 --- /dev/null +++ b/ports/spresense/supervisor/internal_flash_root_pointers.h @@ -0,0 +1,31 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_INTERNAL_FLASH_ROOT_POINTERS_H +#define MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_ROOT_POINTERS_H + +#define FLASH_ROOT_POINTERS + +#endif // MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_ROOT_POINTERS_H diff --git a/ports/spresense/supervisor/port.c b/ports/spresense/supervisor/port.c new file mode 100644 index 0000000000..ab1ea52731 --- /dev/null +++ b/ports/spresense/supervisor/port.c @@ -0,0 +1,73 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 +#include + +#include "supervisor/port.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/analogio/AnalogIn.h" +#include "common-hal/pulseio/PulseOut.h" +#include "common-hal/pulseio/PWMOut.h" + +safe_mode_t port_init(void) { + boardctl(BOARDIOC_INIT, 0); + return NO_SAFE_MODE; +} + +void reset_cpu(void) { + boardctl(BOARDIOC_RESET, 0); +} + +void reset_port(void) { +#if CIRCUITPY_ANALOGIO + analogin_reset(); +#endif +#if CIRCUITPY_PULSEIO + pulseout_reset(); + pwmout_reset(); +#endif + + reset_all_pins(); +} + +void reset_board(void) { +} + +void reset_to_bootloader(void) { +} + +extern uint32_t _ebss; + +// Place the word to save just after our BSS section that gets blanked. +void port_set_saved_word(uint32_t value) { + _ebss = value; +} + +uint32_t port_get_saved_word(void) { + return _ebss; +} diff --git a/ports/spresense/supervisor/usb.c b/ports/spresense/supervisor/usb.c new file mode 100644 index 0000000000..6ad253c6d4 --- /dev/null +++ b/ports/spresense/supervisor/usb.c @@ -0,0 +1,30 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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/usb.h" + +void init_usb_hardware(void) { +} diff --git a/ports/spresense/tick.c b/ports/spresense/tick.c new file mode 100644 index 0000000000..6529db7901 --- /dev/null +++ b/ports/spresense/tick.c @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "tick.h" + +#include "supervisor/shared/autoreload.h" +#include "supervisor/filesystem.h" + +// Global millisecond tick count +volatile uint64_t ticks_ms = 0; + +void board_timerhook(void) +{ + ticks_ms += 1; + +#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0 + filesystem_tick(); +#endif +#ifdef CIRCUITPY_AUTORELOAD_DELAY_MS + autoreload_tick(); +#endif +} diff --git a/ports/spresense/tick.h b/ports/spresense/tick.h new file mode 100644 index 0000000000..7c4d5725fb --- /dev/null +++ b/ports/spresense/tick.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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_SPRESENSE_TICK_H +#define MICROPY_INCLUDED_SPRESENSE_TICK_H + +#include "py/mpconfig.h" + +extern volatile uint64_t ticks_ms; + +#endif // MICROPY_INCLUDED_SPRESENSE_TICK_H From 49db102bdd6ae29a312b34d806a39fd639bc06da Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Wed, 9 Oct 2019 08:32:58 +0200 Subject: [PATCH 02/19] Update tinyUSB --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index d3e48da5a1..c42edc080c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit d3e48da5a1266a88f5f0fdfe28818c8599b09844 +Subproject commit c42edc080cb61d4af8015df6c1d404273b3a5bfa From 6d1748fd59d9e224d6d928fc796a797483e5fe49 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Wed, 9 Oct 2019 08:38:50 +0200 Subject: [PATCH 03/19] Add spresense-exported-sdk submodule --- .gitmodules | 3 +++ ports/spresense/spresense-exported-sdk | 1 + 2 files changed, 4 insertions(+) create mode 160000 ports/spresense/spresense-exported-sdk diff --git a/.gitmodules b/.gitmodules index 7b57cab547..d21ed511ee 100644 --- a/.gitmodules +++ b/.gitmodules @@ -98,3 +98,6 @@ [submodule "ports/stm32f4/stm32f4"] path = ports/stm32f4/stm32f4 url = https://github.com/adafruit/stm32f4.git +[submodule "ports/spresense/spresense-exported-sdk"] + path = ports/spresense/spresense-exported-sdk + url = https://github.com/sonydevworld/spresense-exported-sdk.git diff --git a/ports/spresense/spresense-exported-sdk b/ports/spresense/spresense-exported-sdk new file mode 160000 index 0000000000..b473b28a14 --- /dev/null +++ b/ports/spresense/spresense-exported-sdk @@ -0,0 +1 @@ +Subproject commit b473b28a14a03f3d416b6e2c071bcfd4fb92cb63 From 24c0fe26d86833465bab2dd365effa7bee67c2df Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Wed, 9 Oct 2019 12:31:17 +0200 Subject: [PATCH 04/19] Exclude spresense-exported-sdk from docs --- conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conf.py b/conf.py index 3df958fe1f..df6e6ab60d 100644 --- a/conf.py +++ b/conf.py @@ -142,6 +142,7 @@ exclude_patterns = ["**/build*", "ports/stm32f4/README.md", "ports/pic16bit", "ports/qemu-arm", + "ports/spresense/spresense-exported-sdk", "ports/stm32", "ports/stm32/hal", "ports/stm32/cmsis", From 0a48282e517413ce402b0ed8fd0be49927236516 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Wed, 9 Oct 2019 13:11:22 +0200 Subject: [PATCH 05/19] Add Spresense to supported_ports --- docs/supported_ports.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/supported_ports.rst b/docs/supported_ports.rst index 039ddea68b..c256315f79 100644 --- a/docs/supported_ports.rst +++ b/docs/supported_ports.rst @@ -10,3 +10,4 @@ and ESP8266. ../ports/atmel-samd/README ../ports/esp8266/README ../ports/nrf/README + ../ports/spresense/README From 1fa8841d20ef973e71dce52978de59c6dd6f918b Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 08:09:15 +0200 Subject: [PATCH 06/19] Change port name to cxd56 --- .gitmodules | 4 ++-- conf.py | 2 +- docs/supported_ports.rst | 2 +- ports/{spresense => cxd56}/Makefile | 0 ports/{spresense => cxd56}/README.md | 4 ++-- ports/{spresense => cxd56}/alloca.h | 0 ports/{spresense => cxd56}/background.c | 0 ports/{spresense => cxd56}/background.h | 6 +++--- ports/{spresense => cxd56}/common-hal/analogio/AnalogIn.c | 0 ports/{spresense => cxd56}/common-hal/analogio/AnalogIn.h | 6 +++--- ports/{spresense => cxd56}/common-hal/analogio/AnalogOut.c | 0 ports/{spresense => cxd56}/common-hal/analogio/AnalogOut.h | 6 +++--- ports/{spresense => cxd56}/common-hal/analogio/__init__.c | 0 ports/{spresense => cxd56}/common-hal/board/__init__.c | 0 ports/{spresense => cxd56}/common-hal/busio/I2C.c | 0 ports/{spresense => cxd56}/common-hal/busio/I2C.h | 6 +++--- ports/{spresense => cxd56}/common-hal/busio/OneWire.h | 6 +++--- ports/{spresense => cxd56}/common-hal/busio/SPI.c | 0 ports/{spresense => cxd56}/common-hal/busio/SPI.h | 6 +++--- ports/{spresense => cxd56}/common-hal/busio/UART.c | 0 ports/{spresense => cxd56}/common-hal/busio/UART.h | 6 +++--- ports/{spresense => cxd56}/common-hal/busio/__init__.c | 0 .../common-hal/digitalio/DigitalInOut.c | 0 .../common-hal/digitalio/DigitalInOut.h | 6 +++--- ports/{spresense => cxd56}/common-hal/digitalio/__init__.c | 0 ports/{spresense => cxd56}/common-hal/microcontroller/Pin.c | 0 ports/{spresense => cxd56}/common-hal/microcontroller/Pin.h | 6 +++--- .../common-hal/microcontroller/Processor.c | 0 .../common-hal/microcontroller/Processor.h | 6 +++--- .../common-hal/microcontroller/__init__.c | 0 ports/{spresense => cxd56}/common-hal/os/__init__.c | 0 ports/{spresense => cxd56}/common-hal/pulseio/PWMOut.c | 0 ports/{spresense => cxd56}/common-hal/pulseio/PWMOut.h | 6 +++--- ports/{spresense => cxd56}/common-hal/pulseio/PulseIn.c | 0 ports/{spresense => cxd56}/common-hal/pulseio/PulseIn.h | 6 +++--- ports/{spresense => cxd56}/common-hal/pulseio/PulseOut.c | 0 ports/{spresense => cxd56}/common-hal/pulseio/PulseOut.h | 6 +++--- ports/{spresense => cxd56}/common-hal/pulseio/__init__.c | 0 ports/{spresense => cxd56}/common-hal/rtc/RTC.c | 0 ports/{spresense => cxd56}/common-hal/rtc/RTC.h | 6 +++--- ports/{spresense => cxd56}/common-hal/rtc/__init__.c | 0 ports/{spresense => cxd56}/common-hal/supervisor/Runtime.c | 0 ports/{spresense => cxd56}/common-hal/supervisor/Runtime.h | 6 +++--- ports/{spresense => cxd56}/common-hal/supervisor/__init__.c | 0 ports/{spresense => cxd56}/common-hal/time/__init__.c | 0 ports/{spresense => cxd56}/fatfs_port.c | 0 ports/{spresense => cxd56}/mpconfigboard.h | 0 ports/{spresense => cxd56}/mpconfigport.h | 0 ports/{spresense => cxd56}/mpconfigport.mk | 0 ports/{spresense => cxd56}/mphalport.c | 0 ports/{spresense => cxd56}/mphalport.h | 6 +++--- ports/{spresense => cxd56}/qstrdefsport.h | 0 ports/{spresense => cxd56}/spresense-exported-sdk | 0 ports/{spresense => cxd56}/supervisor/cpu.s | 0 ports/{spresense => cxd56}/supervisor/internal_flash.c | 0 ports/{spresense => cxd56}/supervisor/internal_flash.h | 6 +++--- .../supervisor/internal_flash_root_pointers.h | 6 +++--- ports/{spresense => cxd56}/supervisor/port.c | 0 ports/{spresense => cxd56}/supervisor/usb.c | 0 ports/{spresense => cxd56}/tick.c | 0 ports/{spresense => cxd56}/tick.h | 6 +++--- 61 files changed, 63 insertions(+), 63 deletions(-) rename ports/{spresense => cxd56}/Makefile (100%) rename ports/{spresense => cxd56}/README.md (97%) rename ports/{spresense => cxd56}/alloca.h (100%) rename ports/{spresense => cxd56}/background.c (100%) rename ports/{spresense => cxd56}/background.h (89%) rename ports/{spresense => cxd56}/common-hal/analogio/AnalogIn.c (100%) rename ports/{spresense => cxd56}/common-hal/analogio/AnalogIn.h (87%) rename ports/{spresense => cxd56}/common-hal/analogio/AnalogOut.c (100%) rename ports/{spresense => cxd56}/common-hal/analogio/AnalogOut.h (86%) rename ports/{spresense => cxd56}/common-hal/analogio/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/board/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/busio/I2C.c (100%) rename ports/{spresense => cxd56}/common-hal/busio/I2C.h (89%) rename ports/{spresense => cxd56}/common-hal/busio/OneWire.h (87%) rename ports/{spresense => cxd56}/common-hal/busio/SPI.c (100%) rename ports/{spresense => cxd56}/common-hal/busio/SPI.h (90%) rename ports/{spresense => cxd56}/common-hal/busio/UART.c (100%) rename ports/{spresense => cxd56}/common-hal/busio/UART.h (89%) rename ports/{spresense => cxd56}/common-hal/busio/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/digitalio/DigitalInOut.c (100%) rename ports/{spresense => cxd56}/common-hal/digitalio/DigitalInOut.h (87%) rename ports/{spresense => cxd56}/common-hal/digitalio/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/microcontroller/Pin.c (100%) rename ports/{spresense => cxd56}/common-hal/microcontroller/Pin.h (93%) rename ports/{spresense => cxd56}/common-hal/microcontroller/Processor.c (100%) rename ports/{spresense => cxd56}/common-hal/microcontroller/Processor.h (86%) rename ports/{spresense => cxd56}/common-hal/microcontroller/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/os/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/pulseio/PWMOut.c (100%) rename ports/{spresense => cxd56}/common-hal/pulseio/PWMOut.h (89%) rename ports/{spresense => cxd56}/common-hal/pulseio/PulseIn.c (100%) rename ports/{spresense => cxd56}/common-hal/pulseio/PulseIn.h (89%) rename ports/{spresense => cxd56}/common-hal/pulseio/PulseOut.c (100%) rename ports/{spresense => cxd56}/common-hal/pulseio/PulseOut.h (87%) rename ports/{spresense => cxd56}/common-hal/pulseio/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/rtc/RTC.c (100%) rename ports/{spresense => cxd56}/common-hal/rtc/RTC.h (87%) rename ports/{spresense => cxd56}/common-hal/rtc/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/supervisor/Runtime.c (100%) rename ports/{spresense => cxd56}/common-hal/supervisor/Runtime.h (86%) rename ports/{spresense => cxd56}/common-hal/supervisor/__init__.c (100%) rename ports/{spresense => cxd56}/common-hal/time/__init__.c (100%) rename ports/{spresense => cxd56}/fatfs_port.c (100%) rename ports/{spresense => cxd56}/mpconfigboard.h (100%) rename ports/{spresense => cxd56}/mpconfigport.h (100%) rename ports/{spresense => cxd56}/mpconfigport.mk (100%) rename ports/{spresense => cxd56}/mphalport.c (100%) rename ports/{spresense => cxd56}/mphalport.h (90%) rename ports/{spresense => cxd56}/qstrdefsport.h (100%) rename ports/{spresense => cxd56}/spresense-exported-sdk (100%) rename ports/{spresense => cxd56}/supervisor/cpu.s (100%) rename ports/{spresense => cxd56}/supervisor/internal_flash.c (100%) rename ports/{spresense => cxd56}/supervisor/internal_flash.h (88%) rename ports/{spresense => cxd56}/supervisor/internal_flash_root_pointers.h (86%) rename ports/{spresense => cxd56}/supervisor/port.c (100%) rename ports/{spresense => cxd56}/supervisor/usb.c (100%) rename ports/{spresense => cxd56}/tick.c (100%) rename ports/{spresense => cxd56}/tick.h (91%) diff --git a/.gitmodules b/.gitmodules index d21ed511ee..bb62a5c39d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -98,6 +98,6 @@ [submodule "ports/stm32f4/stm32f4"] path = ports/stm32f4/stm32f4 url = https://github.com/adafruit/stm32f4.git -[submodule "ports/spresense/spresense-exported-sdk"] - path = ports/spresense/spresense-exported-sdk +[submodule "ports/cxd56/spresense-exported-sdk"] + path = ports/cxd56/spresense-exported-sdk url = https://github.com/sonydevworld/spresense-exported-sdk.git diff --git a/conf.py b/conf.py index df6e6ab60d..a477016dc0 100644 --- a/conf.py +++ b/conf.py @@ -125,6 +125,7 @@ exclude_patterns = ["**/build*", "ports/cc3200", "ports/cc3200/FreeRTOS", "ports/cc3200/hal", + "ports/cxd56/spresense-exported-sdk", "ports/esp32", "ports/esp8266/boards", "ports/esp8266/common-hal", @@ -142,7 +143,6 @@ exclude_patterns = ["**/build*", "ports/stm32f4/README.md", "ports/pic16bit", "ports/qemu-arm", - "ports/spresense/spresense-exported-sdk", "ports/stm32", "ports/stm32/hal", "ports/stm32/cmsis", diff --git a/docs/supported_ports.rst b/docs/supported_ports.rst index c256315f79..e221d86657 100644 --- a/docs/supported_ports.rst +++ b/docs/supported_ports.rst @@ -10,4 +10,4 @@ and ESP8266. ../ports/atmel-samd/README ../ports/esp8266/README ../ports/nrf/README - ../ports/spresense/README + ../ports/cxd56/README diff --git a/ports/spresense/Makefile b/ports/cxd56/Makefile similarity index 100% rename from ports/spresense/Makefile rename to ports/cxd56/Makefile diff --git a/ports/spresense/README.md b/ports/cxd56/README.md similarity index 97% rename from ports/spresense/README.md rename to ports/cxd56/README.md index af4a6dea19..d66ea40b4d 100644 --- a/ports/spresense/README.md +++ b/ports/cxd56/README.md @@ -33,9 +33,9 @@ Build the MicroPython cross-compiler: $ make -C mpy-cross -Change directory to spresense: +Change directory to cxd56: - $ cd ports/spresense + $ cd ports/cxd56 To build circuitpython image run: diff --git a/ports/spresense/alloca.h b/ports/cxd56/alloca.h similarity index 100% rename from ports/spresense/alloca.h rename to ports/cxd56/alloca.h diff --git a/ports/spresense/background.c b/ports/cxd56/background.c similarity index 100% rename from ports/spresense/background.c rename to ports/cxd56/background.c diff --git a/ports/spresense/background.h b/ports/cxd56/background.h similarity index 89% rename from ports/spresense/background.h rename to ports/cxd56/background.h index 39e7c4fc87..a38e3faed4 100644 --- a/ports/spresense/background.h +++ b/ports/cxd56/background.h @@ -24,10 +24,10 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_BACKGROUND_H -#define MICROPY_INCLUDED_SPRESENSE_BACKGROUND_H +#ifndef MICROPY_INCLUDED_CXD56_BACKGROUND_H +#define MICROPY_INCLUDED_CXD56_BACKGROUND_H void background_tasks_reset(void); void run_background_tasks(void); -#endif // MICROPY_INCLUDED_SPRESENSE_BACKGROUND_H +#endif // MICROPY_INCLUDED_CXD56_BACKGROUND_H diff --git a/ports/spresense/common-hal/analogio/AnalogIn.c b/ports/cxd56/common-hal/analogio/AnalogIn.c similarity index 100% rename from ports/spresense/common-hal/analogio/AnalogIn.c rename to ports/cxd56/common-hal/analogio/AnalogIn.c diff --git a/ports/spresense/common-hal/analogio/AnalogIn.h b/ports/cxd56/common-hal/analogio/AnalogIn.h similarity index 87% rename from ports/spresense/common-hal/analogio/AnalogIn.h rename to ports/cxd56/common-hal/analogio/AnalogIn.h index 7fc197f98b..4e8b41e52b 100644 --- a/ports/spresense/common-hal/analogio/AnalogIn.h +++ b/ports/cxd56/common-hal/analogio/AnalogIn.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGIN_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGIN_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGIN_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGIN_H #include "py/obj.h" @@ -39,4 +39,4 @@ typedef struct { void analogin_reset(void); -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGIN_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGIN_H diff --git a/ports/spresense/common-hal/analogio/AnalogOut.c b/ports/cxd56/common-hal/analogio/AnalogOut.c similarity index 100% rename from ports/spresense/common-hal/analogio/AnalogOut.c rename to ports/cxd56/common-hal/analogio/AnalogOut.c diff --git a/ports/spresense/common-hal/analogio/AnalogOut.h b/ports/cxd56/common-hal/analogio/AnalogOut.h similarity index 86% rename from ports/spresense/common-hal/analogio/AnalogOut.h rename to ports/cxd56/common-hal/analogio/AnalogOut.h index 60d3cf0a1a..b0fd65265a 100644 --- a/ports/spresense/common-hal/analogio/AnalogOut.h +++ b/ports/cxd56/common-hal/analogio/AnalogOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGOUT_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGOUT_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGOUT_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGOUT_H #include "py/obj.h" @@ -33,4 +33,4 @@ typedef struct { mp_obj_base_t base; } analogio_analogout_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_ANALOGIO_ANALOGOUT_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGOUT_H diff --git a/ports/spresense/common-hal/analogio/__init__.c b/ports/cxd56/common-hal/analogio/__init__.c similarity index 100% rename from ports/spresense/common-hal/analogio/__init__.c rename to ports/cxd56/common-hal/analogio/__init__.c diff --git a/ports/spresense/common-hal/board/__init__.c b/ports/cxd56/common-hal/board/__init__.c similarity index 100% rename from ports/spresense/common-hal/board/__init__.c rename to ports/cxd56/common-hal/board/__init__.c diff --git a/ports/spresense/common-hal/busio/I2C.c b/ports/cxd56/common-hal/busio/I2C.c similarity index 100% rename from ports/spresense/common-hal/busio/I2C.c rename to ports/cxd56/common-hal/busio/I2C.c diff --git a/ports/spresense/common-hal/busio/I2C.h b/ports/cxd56/common-hal/busio/I2C.h similarity index 89% rename from ports/spresense/common-hal/busio/I2C.h rename to ports/cxd56/common-hal/busio/I2C.h index ec2acfb53b..cdef270bfa 100644 --- a/ports/spresense/common-hal/busio/I2C.h +++ b/ports/cxd56/common-hal/busio/I2C.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_I2C_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_I2C_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_I2C_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_I2C_H #include "py/obj.h" @@ -40,4 +40,4 @@ typedef struct { const mcu_pin_obj_t *sda_pin; } busio_i2c_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_I2C_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/spresense/common-hal/busio/OneWire.h b/ports/cxd56/common-hal/busio/OneWire.h similarity index 87% rename from ports/spresense/common-hal/busio/OneWire.h rename to ports/cxd56/common-hal/busio/OneWire.h index a76ee8c777..17c1b22375 100644 --- a/ports/spresense/common-hal/busio/OneWire.h +++ b/ports/cxd56/common-hal/busio/OneWire.h @@ -24,10 +24,10 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_ONEWIRE_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_ONEWIRE_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H // Use bitbangio. #include "shared-module/busio/OneWire.h" -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_ONEWIRE_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/spresense/common-hal/busio/SPI.c b/ports/cxd56/common-hal/busio/SPI.c similarity index 100% rename from ports/spresense/common-hal/busio/SPI.c rename to ports/cxd56/common-hal/busio/SPI.c diff --git a/ports/spresense/common-hal/busio/SPI.h b/ports/cxd56/common-hal/busio/SPI.h similarity index 90% rename from ports/spresense/common-hal/busio/SPI.h rename to ports/cxd56/common-hal/busio/SPI.h index 90c2f6b81a..8985a60d9f 100644 --- a/ports/spresense/common-hal/busio/SPI.h +++ b/ports/cxd56/common-hal/busio/SPI.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_SPI_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_SPI_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_SPI_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_SPI_H #include @@ -46,4 +46,4 @@ typedef struct { const mcu_pin_obj_t *miso_pin; } busio_spi_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_SPI_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/spresense/common-hal/busio/UART.c b/ports/cxd56/common-hal/busio/UART.c similarity index 100% rename from ports/spresense/common-hal/busio/UART.c rename to ports/cxd56/common-hal/busio/UART.c diff --git a/ports/spresense/common-hal/busio/UART.h b/ports/cxd56/common-hal/busio/UART.h similarity index 89% rename from ports/spresense/common-hal/busio/UART.h rename to ports/cxd56/common-hal/busio/UART.h index 7cdbe4ff3b..1c01cfbb9a 100644 --- a/ports/spresense/common-hal/busio/UART.h +++ b/ports/cxd56/common-hal/busio/UART.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_UART_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_UART_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_UART_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_UART_H #include "py/obj.h" @@ -40,4 +40,4 @@ typedef struct { uint32_t timeout; } busio_uart_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_BUSIO_UART_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_BUSIO_UART_H diff --git a/ports/spresense/common-hal/busio/__init__.c b/ports/cxd56/common-hal/busio/__init__.c similarity index 100% rename from ports/spresense/common-hal/busio/__init__.c rename to ports/cxd56/common-hal/busio/__init__.c diff --git a/ports/spresense/common-hal/digitalio/DigitalInOut.c b/ports/cxd56/common-hal/digitalio/DigitalInOut.c similarity index 100% rename from ports/spresense/common-hal/digitalio/DigitalInOut.c rename to ports/cxd56/common-hal/digitalio/DigitalInOut.c diff --git a/ports/spresense/common-hal/digitalio/DigitalInOut.h b/ports/cxd56/common-hal/digitalio/DigitalInOut.h similarity index 87% rename from ports/spresense/common-hal/digitalio/DigitalInOut.h rename to ports/cxd56/common-hal/digitalio/DigitalInOut.h index a5bfd22bdd..58a11817c8 100644 --- a/ports/spresense/common-hal/digitalio/DigitalInOut.h +++ b/ports/cxd56/common-hal/digitalio/DigitalInOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_DIGITALIO_DIGITALINOUT_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_DIGITALIO_DIGITALINOUT_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_DIGITALIO_DIGITALINOUT_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_DIGITALIO_DIGITALINOUT_H #include "py/obj.h" @@ -39,4 +39,4 @@ typedef struct { uint8_t pull; } digitalio_digitalinout_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_DIGITALIO_DIGITALINOUT_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_DIGITALIO_DIGITALINOUT_H diff --git a/ports/spresense/common-hal/digitalio/__init__.c b/ports/cxd56/common-hal/digitalio/__init__.c similarity index 100% rename from ports/spresense/common-hal/digitalio/__init__.c rename to ports/cxd56/common-hal/digitalio/__init__.c diff --git a/ports/spresense/common-hal/microcontroller/Pin.c b/ports/cxd56/common-hal/microcontroller/Pin.c similarity index 100% rename from ports/spresense/common-hal/microcontroller/Pin.c rename to ports/cxd56/common-hal/microcontroller/Pin.c diff --git a/ports/spresense/common-hal/microcontroller/Pin.h b/ports/cxd56/common-hal/microcontroller/Pin.h similarity index 93% rename from ports/spresense/common-hal/microcontroller/Pin.h rename to ports/cxd56/common-hal/microcontroller/Pin.h index 2d995d0dd3..113387cef3 100644 --- a/ports/spresense/common-hal/microcontroller/Pin.h +++ b/ports/cxd56/common-hal/microcontroller/Pin.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PIN_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PIN_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PIN_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PIN_H #include "py/obj.h" @@ -89,4 +89,4 @@ void reset_pin_number(uint8_t pin_number); void reset_all_pins(void); void claim_pin(const mcu_pin_obj_t* pin); -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PIN_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PIN_H diff --git a/ports/spresense/common-hal/microcontroller/Processor.c b/ports/cxd56/common-hal/microcontroller/Processor.c similarity index 100% rename from ports/spresense/common-hal/microcontroller/Processor.c rename to ports/cxd56/common-hal/microcontroller/Processor.c diff --git a/ports/spresense/common-hal/microcontroller/Processor.h b/ports/cxd56/common-hal/microcontroller/Processor.h similarity index 86% rename from ports/spresense/common-hal/microcontroller/Processor.h rename to ports/cxd56/common-hal/microcontroller/Processor.h index 6c4c17b035..12555e82c1 100644 --- a/ports/spresense/common-hal/microcontroller/Processor.h +++ b/ports/cxd56/common-hal/microcontroller/Processor.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H #define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH CONFIG_BOARDCTL_UNIQUEID_SIZE @@ -37,4 +37,4 @@ typedef struct { const mp_obj_type_t mcu_processor_type; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H diff --git a/ports/spresense/common-hal/microcontroller/__init__.c b/ports/cxd56/common-hal/microcontroller/__init__.c similarity index 100% rename from ports/spresense/common-hal/microcontroller/__init__.c rename to ports/cxd56/common-hal/microcontroller/__init__.c diff --git a/ports/spresense/common-hal/os/__init__.c b/ports/cxd56/common-hal/os/__init__.c similarity index 100% rename from ports/spresense/common-hal/os/__init__.c rename to ports/cxd56/common-hal/os/__init__.c diff --git a/ports/spresense/common-hal/pulseio/PWMOut.c b/ports/cxd56/common-hal/pulseio/PWMOut.c similarity index 100% rename from ports/spresense/common-hal/pulseio/PWMOut.c rename to ports/cxd56/common-hal/pulseio/PWMOut.c diff --git a/ports/spresense/common-hal/pulseio/PWMOut.h b/ports/cxd56/common-hal/pulseio/PWMOut.h similarity index 89% rename from ports/spresense/common-hal/pulseio/PWMOut.h rename to ports/cxd56/common-hal/pulseio/PWMOut.h index 486d5add96..c16084fe62 100644 --- a/ports/spresense/common-hal/pulseio/PWMOut.h +++ b/ports/cxd56/common-hal/pulseio/PWMOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H #include @@ -45,4 +45,4 @@ void pwmout_reset(void); void pwmout_start(uint8_t pwm_num); void pwmout_stop(uint8_t pwm_num); -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H diff --git a/ports/spresense/common-hal/pulseio/PulseIn.c b/ports/cxd56/common-hal/pulseio/PulseIn.c similarity index 100% rename from ports/spresense/common-hal/pulseio/PulseIn.c rename to ports/cxd56/common-hal/pulseio/PulseIn.c diff --git a/ports/spresense/common-hal/pulseio/PulseIn.h b/ports/cxd56/common-hal/pulseio/PulseIn.h similarity index 89% rename from ports/spresense/common-hal/pulseio/PulseIn.h rename to ports/cxd56/common-hal/pulseio/PulseIn.h index 5f2f318110..ff31712abc 100644 --- a/ports/spresense/common-hal/pulseio/PulseIn.h +++ b/ports/cxd56/common-hal/pulseio/PulseIn.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEIN_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEIN_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PULSEIN_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PULSEIN_H #include "common-hal/microcontroller/Pin.h" @@ -44,4 +44,4 @@ typedef struct { bool paused; } pulseio_pulsein_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEIN_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PULSEIN_H diff --git a/ports/spresense/common-hal/pulseio/PulseOut.c b/ports/cxd56/common-hal/pulseio/PulseOut.c similarity index 100% rename from ports/spresense/common-hal/pulseio/PulseOut.c rename to ports/cxd56/common-hal/pulseio/PulseOut.c diff --git a/ports/spresense/common-hal/pulseio/PulseOut.h b/ports/cxd56/common-hal/pulseio/PulseOut.h similarity index 87% rename from ports/spresense/common-hal/pulseio/PulseOut.h rename to ports/cxd56/common-hal/pulseio/PulseOut.h index 652a1197ed..61bc175276 100644 --- a/ports/spresense/common-hal/pulseio/PulseOut.h +++ b/ports/cxd56/common-hal/pulseio/PulseOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEOUT_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEOUT_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PULSEOUT_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PULSEOUT_H #include "py/obj.h" @@ -36,4 +36,4 @@ typedef struct { void pulseout_reset(void); -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_PULSEIO_PULSEOUT_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PULSEOUT_H diff --git a/ports/spresense/common-hal/pulseio/__init__.c b/ports/cxd56/common-hal/pulseio/__init__.c similarity index 100% rename from ports/spresense/common-hal/pulseio/__init__.c rename to ports/cxd56/common-hal/pulseio/__init__.c diff --git a/ports/spresense/common-hal/rtc/RTC.c b/ports/cxd56/common-hal/rtc/RTC.c similarity index 100% rename from ports/spresense/common-hal/rtc/RTC.c rename to ports/cxd56/common-hal/rtc/RTC.c diff --git a/ports/spresense/common-hal/rtc/RTC.h b/ports/cxd56/common-hal/rtc/RTC.h similarity index 87% rename from ports/spresense/common-hal/rtc/RTC.h rename to ports/cxd56/common-hal/rtc/RTC.h index 7a3ef18bd5..5647fdcf14 100644 --- a/ports/spresense/common-hal/rtc/RTC.h +++ b/ports/cxd56/common-hal/rtc/RTC.h @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_RTC_RTC_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_RTC_RTC_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_RTC_RTC_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_RTC_RTC_H -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_RTC_RTC_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_RTC_RTC_H diff --git a/ports/spresense/common-hal/rtc/__init__.c b/ports/cxd56/common-hal/rtc/__init__.c similarity index 100% rename from ports/spresense/common-hal/rtc/__init__.c rename to ports/cxd56/common-hal/rtc/__init__.c diff --git a/ports/spresense/common-hal/supervisor/Runtime.c b/ports/cxd56/common-hal/supervisor/Runtime.c similarity index 100% rename from ports/spresense/common-hal/supervisor/Runtime.c rename to ports/cxd56/common-hal/supervisor/Runtime.c diff --git a/ports/spresense/common-hal/supervisor/Runtime.h b/ports/cxd56/common-hal/supervisor/Runtime.h similarity index 86% rename from ports/spresense/common-hal/supervisor/Runtime.h rename to ports/cxd56/common-hal/supervisor/Runtime.h index c3ed62a25d..f4669c6ab3 100755 --- a/ports/spresense/common-hal/supervisor/Runtime.h +++ b/ports/cxd56/common-hal/supervisor/Runtime.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_SUPERVISOR_RUNTIME_H -#define MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_SUPERVISOR_RUNTIME_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_SUPERVISOR_RUNTIME_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_SUPERVISOR_RUNTIME_H #include "py/obj.h" @@ -33,4 +33,4 @@ typedef struct { mp_obj_base_t base; } super_runtime_obj_t; -#endif // MICROPY_INCLUDED_SPRESENSE_COMMON_HAL_SUPERVISOR_RUNTIME_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_SUPERVISOR_RUNTIME_H diff --git a/ports/spresense/common-hal/supervisor/__init__.c b/ports/cxd56/common-hal/supervisor/__init__.c similarity index 100% rename from ports/spresense/common-hal/supervisor/__init__.c rename to ports/cxd56/common-hal/supervisor/__init__.c diff --git a/ports/spresense/common-hal/time/__init__.c b/ports/cxd56/common-hal/time/__init__.c similarity index 100% rename from ports/spresense/common-hal/time/__init__.c rename to ports/cxd56/common-hal/time/__init__.c diff --git a/ports/spresense/fatfs_port.c b/ports/cxd56/fatfs_port.c similarity index 100% rename from ports/spresense/fatfs_port.c rename to ports/cxd56/fatfs_port.c diff --git a/ports/spresense/mpconfigboard.h b/ports/cxd56/mpconfigboard.h similarity index 100% rename from ports/spresense/mpconfigboard.h rename to ports/cxd56/mpconfigboard.h diff --git a/ports/spresense/mpconfigport.h b/ports/cxd56/mpconfigport.h similarity index 100% rename from ports/spresense/mpconfigport.h rename to ports/cxd56/mpconfigport.h diff --git a/ports/spresense/mpconfigport.mk b/ports/cxd56/mpconfigport.mk similarity index 100% rename from ports/spresense/mpconfigport.mk rename to ports/cxd56/mpconfigport.mk diff --git a/ports/spresense/mphalport.c b/ports/cxd56/mphalport.c similarity index 100% rename from ports/spresense/mphalport.c rename to ports/cxd56/mphalport.c diff --git a/ports/spresense/mphalport.h b/ports/cxd56/mphalport.h similarity index 90% rename from ports/spresense/mphalport.h rename to ports/cxd56/mphalport.h index 8b397d41e4..25bca97ad7 100644 --- a/ports/spresense/mphalport.h +++ b/ports/cxd56/mphalport.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_MPHALPORT_H -#define MICROPY_INCLUDED_SPRESENSE_MPHALPORT_H +#ifndef MICROPY_INCLUDED_CXD56_MPHALPORT_H +#define MICROPY_INCLUDED_CXD56_MPHALPORT_H #include @@ -33,4 +33,4 @@ extern volatile uint64_t ticks_ms; -#endif // MICROPY_INCLUDED_SPRESENSE_MPHALPORT_H +#endif // MICROPY_INCLUDED_CXD56_MPHALPORT_H diff --git a/ports/spresense/qstrdefsport.h b/ports/cxd56/qstrdefsport.h similarity index 100% rename from ports/spresense/qstrdefsport.h rename to ports/cxd56/qstrdefsport.h diff --git a/ports/spresense/spresense-exported-sdk b/ports/cxd56/spresense-exported-sdk similarity index 100% rename from ports/spresense/spresense-exported-sdk rename to ports/cxd56/spresense-exported-sdk diff --git a/ports/spresense/supervisor/cpu.s b/ports/cxd56/supervisor/cpu.s similarity index 100% rename from ports/spresense/supervisor/cpu.s rename to ports/cxd56/supervisor/cpu.s diff --git a/ports/spresense/supervisor/internal_flash.c b/ports/cxd56/supervisor/internal_flash.c similarity index 100% rename from ports/spresense/supervisor/internal_flash.c rename to ports/cxd56/supervisor/internal_flash.c diff --git a/ports/spresense/supervisor/internal_flash.h b/ports/cxd56/supervisor/internal_flash.h similarity index 88% rename from ports/spresense/supervisor/internal_flash.h rename to ports/cxd56/supervisor/internal_flash.h index bc4e98baf3..1580ad3e1e 100644 --- a/ports/spresense/supervisor/internal_flash.h +++ b/ports/cxd56/supervisor/internal_flash.h @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_H -#define MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_H +#ifndef MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_H +#define MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_H -#endif // MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_H +#endif // MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_H diff --git a/ports/spresense/supervisor/internal_flash_root_pointers.h b/ports/cxd56/supervisor/internal_flash_root_pointers.h similarity index 86% rename from ports/spresense/supervisor/internal_flash_root_pointers.h rename to ports/cxd56/supervisor/internal_flash_root_pointers.h index 87f478d130..126c6af097 100644 --- a/ports/spresense/supervisor/internal_flash_root_pointers.h +++ b/ports/cxd56/supervisor/internal_flash_root_pointers.h @@ -23,9 +23,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_ROOT_POINTERS_H -#define MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_ROOT_POINTERS_H +#ifndef MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_ROOT_POINTERS_H +#define MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_ROOT_POINTERS_H #define FLASH_ROOT_POINTERS -#endif // MICROPY_INCLUDED_SPRESENSE_INTERNAL_FLASH_ROOT_POINTERS_H +#endif // MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_ROOT_POINTERS_H diff --git a/ports/spresense/supervisor/port.c b/ports/cxd56/supervisor/port.c similarity index 100% rename from ports/spresense/supervisor/port.c rename to ports/cxd56/supervisor/port.c diff --git a/ports/spresense/supervisor/usb.c b/ports/cxd56/supervisor/usb.c similarity index 100% rename from ports/spresense/supervisor/usb.c rename to ports/cxd56/supervisor/usb.c diff --git a/ports/spresense/tick.c b/ports/cxd56/tick.c similarity index 100% rename from ports/spresense/tick.c rename to ports/cxd56/tick.c diff --git a/ports/spresense/tick.h b/ports/cxd56/tick.h similarity index 91% rename from ports/spresense/tick.h rename to ports/cxd56/tick.h index 7c4d5725fb..a0d9ee5263 100644 --- a/ports/spresense/tick.h +++ b/ports/cxd56/tick.h @@ -24,11 +24,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SPRESENSE_TICK_H -#define MICROPY_INCLUDED_SPRESENSE_TICK_H +#ifndef MICROPY_INCLUDED_CXD56_TICK_H +#define MICROPY_INCLUDED_CXD56_TICK_H #include "py/mpconfig.h" extern volatile uint64_t ticks_ms; -#endif // MICROPY_INCLUDED_SPRESENSE_TICK_H +#endif // MICROPY_INCLUDED_CXD56_TICK_H From 5f09609d41349741b57b8a52415bad3a8662bf20 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 08:54:36 +0200 Subject: [PATCH 07/19] Add Spresense board folder --- ports/cxd56/Makefile | 18 +++++ ports/cxd56/README.md | 6 +- ports/cxd56/boards/board.h | 45 +++++++++++ ports/cxd56/boards/spresense/board.c | 38 +++++++++ .../{ => boards/spresense}/mpconfigboard.h | 0 ports/cxd56/boards/spresense/mpconfigboard.mk | 4 + ports/cxd56/boards/spresense/pins.c | 80 ++++++++++++++++++ ports/cxd56/common-hal/board/__init__.c | 81 +------------------ ports/cxd56/mpconfigport.mk | 4 - ports/cxd56/supervisor/port.c | 12 ++- 10 files changed, 198 insertions(+), 90 deletions(-) create mode 100644 ports/cxd56/boards/board.h create mode 100644 ports/cxd56/boards/spresense/board.c rename ports/cxd56/{ => boards/spresense}/mpconfigboard.h (100%) create mode 100644 ports/cxd56/boards/spresense/mpconfigboard.mk create mode 100644 ports/cxd56/boards/spresense/pins.c diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index d8f809635f..69c8e1bef6 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -22,8 +22,23 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +# Select the board to build for. +ifeq ($(BOARD),) + $(error You must provide a BOARD parameter) +else + ifeq ($(wildcard boards/$(BOARD)/.),) + $(error Invalid BOARD specified) + endif +endif + +# If the build directory is not given, make it reflect the board name. +BUILD ?= build-$(BOARD) + include ../../py/mkenv.mk +# Board-specific +include boards/$(BOARD)/mpconfigboard.mk + # Port-specific include mpconfigport.mk @@ -54,6 +69,7 @@ INC += \ -I../lib/timeutils \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ + -Iboards/$(BOARD) \ -I$(BUILD) \ -I$(SPRESENSE_SDK)/nuttx/include \ -I$(SPRESENSE_SDK)/nuttx/arch \ @@ -123,6 +139,8 @@ SRC_C = \ background.c \ fatfs_port.c \ mphalport.c \ + boards/$(BOARD)/board.c \ + boards/$(BOARD)/pins.c \ lib/utils/stdout_helpers.c \ lib/utils/pyexec.c \ lib/libc/string0.c \ diff --git a/ports/cxd56/README.md b/ports/cxd56/README.md index d66ea40b4d..99a9032fe6 100644 --- a/ports/cxd56/README.md +++ b/ports/cxd56/README.md @@ -39,7 +39,7 @@ Change directory to cxd56: To build circuitpython image run: - $ make + $ make BOARD=spresense USB connection -------------- @@ -67,14 +67,14 @@ Extract spresense binaries in your PC to ports/spresense/spresense-exported-sdk/ To flash the bootloader run the command: - $ make flash-bootloader + $ make BOARD=spresense flash-bootloader Flash the circuitpython.spk image --------------------------------- To flash the firmware run the command: - $ make flash + $ make BOARD=spresense flash Accessing the board ------------------- diff --git a/ports/cxd56/boards/board.h b/ports/cxd56/boards/board.h new file mode 100644 index 0000000000..597ae72e6a --- /dev/null +++ b/ports/cxd56/boards/board.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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. + */ + +// This file defines board specific functions. + +#ifndef MICROPY_INCLUDED_CXD56_BOARDS_BOARD_H +#define MICROPY_INCLUDED_CXD56_BOARDS_BOARD_H + +#include + +// Initializes board related state once on start up. +void board_init(void); + +// Returns true if the user initiates safe mode in a board specific way. +// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific +// way. +bool board_requests_safe_mode(void); + +// Reset the state of off MCU components such as neopixels. +void reset_board(void); + +#endif // MICROPY_INCLUDED_CXD56_BOARDS_BOARD_H diff --git a/ports/cxd56/boards/spresense/board.c b/ports/cxd56/boards/spresense/board.c new file mode 100644 index 0000000000..2af7cfdcf2 --- /dev/null +++ b/ports/cxd56/boards/spresense/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/cxd56/mpconfigboard.h b/ports/cxd56/boards/spresense/mpconfigboard.h similarity index 100% rename from ports/cxd56/mpconfigboard.h rename to ports/cxd56/boards/spresense/mpconfigboard.h diff --git a/ports/cxd56/boards/spresense/mpconfigboard.mk b/ports/cxd56/boards/spresense/mpconfigboard.mk new file mode 100644 index 0000000000..a2d4e5d88c --- /dev/null +++ b/ports/cxd56/boards/spresense/mpconfigboard.mk @@ -0,0 +1,4 @@ +USB_VID = 0x054c +USB_PID = 0x0bc2 +USB_PRODUCT = "Spresense" +USB_MANUFACTURER = "Sony" diff --git a/ports/cxd56/boards/spresense/pins.c b/ports/cxd56/boards/spresense/pins.c new file mode 100644 index 0000000000..d123969fea --- /dev/null +++ b/ports/cxd56/boards/spresense/pins.c @@ -0,0 +1,80 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * 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 "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_D0) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_D1) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_D2) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_D3) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_D4) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_D5) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_D6) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_D7) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_D8) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_D9) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_D10) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_D11) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_D12) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_D13) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_D14) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_D15) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_D16) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_D17) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_D18) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_D19) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_D20) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_D21) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_D22) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_D23) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_D24) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_D25) }, + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_D26) }, + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_D27) }, + { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_D28) }, + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_LED0) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_LED1) }, + { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_LED2) }, + { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_LED3) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_A0) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_A1) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_A2) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_A3) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_A4) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_A5) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_D14) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_D15) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_D13) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_D12) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_D11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_D0) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_D1) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/cxd56/common-hal/board/__init__.c b/ports/cxd56/common-hal/board/__init__.c index d123969fea..7a409d503e 100644 --- a/ports/cxd56/common-hal/board/__init__.c +++ b/ports/cxd56/common-hal/board/__init__.c @@ -1,80 +1 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright 2019 Sony Semiconductor Solutions Corporation - * - * 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 "shared-bindings/board/__init__.h" - -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_D0) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_D1) }, - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_D2) }, - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_D3) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_D4) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_D5) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_D6) }, - { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_D7) }, - { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_D8) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_D9) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_D10) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_D11) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_D12) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_D13) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_D14) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_D15) }, - { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_D16) }, - { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_D17) }, - { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_D18) }, - { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_D19) }, - { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_D20) }, - { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_D21) }, - { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_D22) }, - { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_D23) }, - { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_D24) }, - { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_D25) }, - { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_D26) }, - { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_D27) }, - { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_D28) }, - { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_LED0) }, - { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_LED1) }, - { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_LED2) }, - { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_LED3) }, - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_A0) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_A1) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_A2) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_A3) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_A4) }, - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_A5) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_D14) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_D15) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_D13) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_D12) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_D11) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_D0) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_D1) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, -}; -MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); +// No board module functions. diff --git a/ports/cxd56/mpconfigport.mk b/ports/cxd56/mpconfigport.mk index 53dba28403..a418ae8e9d 100644 --- a/ports/cxd56/mpconfigport.mk +++ b/ports/cxd56/mpconfigport.mk @@ -1,7 +1,3 @@ -USB_VID = 0x054c -USB_PID = 0x0bc2 -USB_PRODUCT = "Spresense" -USB_MANUFACTURER = "Sony" USB_SERIAL_NUMBER_LENGTH = 10 USB_DEVICES = "CDC,MSC" USB_MSC_MAX_PACKET_SIZE = 512 diff --git a/ports/cxd56/supervisor/port.c b/ports/cxd56/supervisor/port.c index ab1ea52731..3fddfe52c6 100644 --- a/ports/cxd56/supervisor/port.c +++ b/ports/cxd56/supervisor/port.c @@ -27,6 +27,8 @@ #include #include +#include "boards/board.h" + #include "supervisor/port.h" #include "common-hal/microcontroller/Pin.h" @@ -36,6 +38,13 @@ safe_mode_t port_init(void) { boardctl(BOARDIOC_INIT, 0); + + board_init(); + + if (board_requests_safe_mode()) { + return USER_SAFE_MODE; + } + return NO_SAFE_MODE; } @@ -55,9 +64,6 @@ void reset_port(void) { reset_all_pins(); } -void reset_board(void) { -} - void reset_to_bootloader(void) { } From 8f653d62384fd9463d1c4df5c9ded4fe8546c6d4 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 09:34:00 +0200 Subject: [PATCH 08/19] Use CXD56 pin names --- ports/cxd56/boards/spresense/mpconfigboard.h | 14 +- ports/cxd56/boards/spresense/pins.c | 92 +++++------ ports/cxd56/common-hal/analogio/AnalogIn.c | 12 +- ports/cxd56/common-hal/microcontroller/Pin.c | 144 +++++++++--------- ports/cxd56/common-hal/microcontroller/Pin.h | 78 +++++----- .../common-hal/microcontroller/__init__.c | 78 +++++----- ports/cxd56/common-hal/pulseio/PWMOut.c | 8 +- 7 files changed, 213 insertions(+), 213 deletions(-) diff --git a/ports/cxd56/boards/spresense/mpconfigboard.h b/ports/cxd56/boards/spresense/mpconfigboard.h index e0fef60f03..b20d006586 100644 --- a/ports/cxd56/boards/spresense/mpconfigboard.h +++ b/ports/cxd56/boards/spresense/mpconfigboard.h @@ -28,12 +28,12 @@ #define MICROPY_HW_MCU_NAME "CXD5602" #define MICROPY_PY_SYS_PLATFORM "SPRESENSE" -#define DEFAULT_I2C_BUS_SCL (&pin_D15) -#define DEFAULT_I2C_BUS_SDA (&pin_D14) +#define DEFAULT_I2C_BUS_SCL (&pin_I2C0_BCK) +#define DEFAULT_I2C_BUS_SDA (&pin_I2C0_BDT) -#define DEFAULT_SPI_BUS_SCK (&pin_D13) -#define DEFAULT_SPI_BUS_MISO (&pin_D12) -#define DEFAULT_SPI_BUS_MOSI (&pin_D11) +#define DEFAULT_SPI_BUS_SCK (&pin_SPI4_SCK) +#define DEFAULT_SPI_BUS_MISO (&pin_SPI4_MISO) +#define DEFAULT_SPI_BUS_MOSI (&pin_SPI4_MOSI) -#define DEFAULT_UART_BUS_RX (&pin_D0) -#define DEFAULT_UART_BUS_TX (&pin_D1) +#define DEFAULT_UART_BUS_RX (&pin_UART2_RXD) +#define DEFAULT_UART_BUS_TX (&pin_UART2_TXD) diff --git a/ports/cxd56/boards/spresense/pins.c b/ports/cxd56/boards/spresense/pins.c index d123969fea..fcc854590a 100644 --- a/ports/cxd56/boards/spresense/pins.c +++ b/ports/cxd56/boards/spresense/pins.c @@ -27,52 +27,52 @@ #include "shared-bindings/board/__init__.h" STATIC const mp_rom_map_elem_t board_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_D0) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_D1) }, - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_D2) }, - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_D3) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_D4) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_D5) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_D6) }, - { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_D7) }, - { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_D8) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_D9) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_D10) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_D11) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_D12) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_D13) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_D14) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_D15) }, - { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_D16) }, - { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_D17) }, - { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_D18) }, - { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_D19) }, - { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_D20) }, - { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_D21) }, - { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_D22) }, - { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_D23) }, - { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_D24) }, - { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_D25) }, - { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_D26) }, - { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_D27) }, - { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_D28) }, - { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_LED0) }, - { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_LED1) }, - { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_LED2) }, - { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_LED3) }, - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_A0) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_A1) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_A2) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_A3) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_A4) }, - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_A5) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_D14) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_D15) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_D13) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_D12) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_D11) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_D0) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_D1) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_UART2_RXD) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_UART2_TXD) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_HIF_IRQ_OUT) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PWM3) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_SPI2_MOSI) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PWM1) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PWM0) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_SPI3_CS1_X) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_SPI2_MISO) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PWM2) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_SPI4_CS_X) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_SPI4_MOSI) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_SPI4_MISO) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_SPI4_SCK) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_I2C0_BDT) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_I2C0_BCK) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_EMMC_DATA0) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_EMMC_DATA1) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_I2S0_DATA_OUT) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_I2S0_DATA_IN) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_EMMC_DATA2) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_EMMC_DATA3) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_SEN_IRQ_IN) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_EMMC_CLK) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_EMMC_CMD) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_I2S0_LRCK) }, + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_I2S0_BCK) }, + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_UART2_CTS) }, + { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_UART2_RTS) }, + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_I2S1_BCK) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_I2S1_LRCK) }, + { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_I2S1_DATA_IN) }, + { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_I2S1_DATA_OUT) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_LPADC0) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_LPADC1) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_LPADC2) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_LPADC3) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_HPADC0) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_HPADC1) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_I2C0_BDT) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_I2C0_BCK) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_SPI4_SCK) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_SPI4_MISO) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_SPI4_MOSI) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_UART2_RXD) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_UART2_TXD) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, diff --git a/ports/cxd56/common-hal/analogio/AnalogIn.c b/ports/cxd56/common-hal/analogio/AnalogIn.c index 438fbbcaed..6f3b7a1ba6 100644 --- a/ports/cxd56/common-hal/analogio/AnalogIn.c +++ b/ports/cxd56/common-hal/analogio/AnalogIn.c @@ -42,12 +42,12 @@ typedef struct { } analogin_dev_t; STATIC analogin_dev_t analogin_dev[] = { - {"/dev/lpadc0", &pin_A0, -1}, - {"/dev/lpadc1", &pin_A1, -1}, - {"/dev/lpadc2", &pin_A2, -1}, - {"/dev/lpadc3", &pin_A3, -1}, - {"/dev/hpadc0", &pin_A4, -1}, - {"/dev/hpadc1", &pin_A5, -1}, + {"/dev/lpadc0", &pin_LPADC0, -1}, + {"/dev/lpadc1", &pin_LPADC1, -1}, + {"/dev/lpadc2", &pin_LPADC2, -1}, + {"/dev/lpadc3", &pin_LPADC3, -1}, + {"/dev/hpadc0", &pin_HPADC0, -1}, + {"/dev/hpadc1", &pin_HPADC1, -1}, }; void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const mcu_pin_obj_t *pin) { diff --git a/ports/cxd56/common-hal/microcontroller/Pin.c b/ports/cxd56/common-hal/microcontroller/Pin.c index 005defa848..23377197c2 100644 --- a/ports/cxd56/common-hal/microcontroller/Pin.c +++ b/ports/cxd56/common-hal/microcontroller/Pin.c @@ -39,80 +39,80 @@ typedef struct { bool free; } pin_status_t; -const mcu_pin_obj_t pin_D0 = PIN(PIN_UART2_RXD, false); -const mcu_pin_obj_t pin_D1 = PIN(PIN_UART2_TXD, false); -const mcu_pin_obj_t pin_D2 = PIN(PIN_HIF_IRQ_OUT, false); -const mcu_pin_obj_t pin_D3 = PIN(PIN_PWM3, false); -const mcu_pin_obj_t pin_D4 = PIN(PIN_SPI2_MOSI, false); -const mcu_pin_obj_t pin_D5 = PIN(PIN_PWM1, false); -const mcu_pin_obj_t pin_D6 = PIN(PIN_PWM0, false); -const mcu_pin_obj_t pin_D7 = PIN(PIN_SPI3_CS1_X, false); -const mcu_pin_obj_t pin_D8 = PIN(PIN_SPI2_MISO, false); -const mcu_pin_obj_t pin_D9 = PIN(PIN_PWM2, false); -const mcu_pin_obj_t pin_D10 = PIN(PIN_SPI4_CS_X, false); -const mcu_pin_obj_t pin_D11 = PIN(PIN_SPI4_MOSI, false); -const mcu_pin_obj_t pin_D12 = PIN(PIN_SPI4_MISO, false); -const mcu_pin_obj_t pin_D13 = PIN(PIN_SPI4_SCK, false); -const mcu_pin_obj_t pin_D14 = PIN(PIN_I2C0_BDT, false); -const mcu_pin_obj_t pin_D15 = PIN(PIN_I2C0_BCK, false); -const mcu_pin_obj_t pin_D16 = PIN(PIN_EMMC_DATA0, false); -const mcu_pin_obj_t pin_D17 = PIN(PIN_EMMC_DATA1, false); -const mcu_pin_obj_t pin_D18 = PIN(PIN_I2S0_DATA_OUT, false); -const mcu_pin_obj_t pin_D19 = PIN(PIN_I2S0_DATA_IN, false); -const mcu_pin_obj_t pin_D20 = PIN(PIN_EMMC_DATA2, false); -const mcu_pin_obj_t pin_D21 = PIN(PIN_EMMC_DATA3, false); -const mcu_pin_obj_t pin_D22 = PIN(PIN_SEN_IRQ_IN, false); -const mcu_pin_obj_t pin_D23 = PIN(PIN_EMMC_CLK, false); -const mcu_pin_obj_t pin_D24 = PIN(PIN_EMMC_CMD, false); -const mcu_pin_obj_t pin_D25 = PIN(PIN_I2S0_LRCK, false); -const mcu_pin_obj_t pin_D26 = PIN(PIN_I2S0_BCK, false); -const mcu_pin_obj_t pin_D27 = PIN(PIN_UART2_CTS, false); -const mcu_pin_obj_t pin_D28 = PIN(PIN_UART2_RTS, false); -const mcu_pin_obj_t pin_LED0 = PIN(PIN_I2S1_BCK, false); -const mcu_pin_obj_t pin_LED1 = PIN(PIN_I2S1_LRCK, false); -const mcu_pin_obj_t pin_LED2 = PIN(PIN_I2S1_DATA_IN, false); -const mcu_pin_obj_t pin_LED3 = PIN(PIN_I2S1_DATA_OUT, false); -const mcu_pin_obj_t pin_A0 = PIN(0, true); -const mcu_pin_obj_t pin_A1 = PIN(1, true); -const mcu_pin_obj_t pin_A2 = PIN(2, true); -const mcu_pin_obj_t pin_A3 = PIN(3, true); -const mcu_pin_obj_t pin_A4 = PIN(4, true); -const mcu_pin_obj_t pin_A5 = PIN(5, true); +const mcu_pin_obj_t pin_UART2_RXD = PIN(PIN_UART2_RXD, false); +const mcu_pin_obj_t pin_UART2_TXD = PIN(PIN_UART2_TXD, false); +const mcu_pin_obj_t pin_HIF_IRQ_OUT = PIN(PIN_HIF_IRQ_OUT, false); +const mcu_pin_obj_t pin_PWM3 = PIN(PIN_PWM3, false); +const mcu_pin_obj_t pin_SPI2_MOSI = PIN(PIN_SPI2_MOSI, false); +const mcu_pin_obj_t pin_PWM1 = PIN(PIN_PWM1, false); +const mcu_pin_obj_t pin_PWM0 = PIN(PIN_PWM0, false); +const mcu_pin_obj_t pin_SPI3_CS1_X = PIN(PIN_SPI3_CS1_X, false); +const mcu_pin_obj_t pin_SPI2_MISO = PIN(PIN_SPI2_MISO, false); +const mcu_pin_obj_t pin_PWM2 = PIN(PIN_PWM2, false); +const mcu_pin_obj_t pin_SPI4_CS_X = PIN(PIN_SPI4_CS_X, false); +const mcu_pin_obj_t pin_SPI4_MOSI = PIN(PIN_SPI4_MOSI, false); +const mcu_pin_obj_t pin_SPI4_MISO = PIN(PIN_SPI4_MISO, false); +const mcu_pin_obj_t pin_SPI4_SCK = PIN(PIN_SPI4_SCK, false); +const mcu_pin_obj_t pin_I2C0_BDT = PIN(PIN_I2C0_BDT, false); +const mcu_pin_obj_t pin_I2C0_BCK = PIN(PIN_I2C0_BCK, false); +const mcu_pin_obj_t pin_EMMC_DATA0 = PIN(PIN_EMMC_DATA0, false); +const mcu_pin_obj_t pin_EMMC_DATA1 = PIN(PIN_EMMC_DATA1, false); +const mcu_pin_obj_t pin_I2S0_DATA_OUT = PIN(PIN_I2S0_DATA_OUT, false); +const mcu_pin_obj_t pin_I2S0_DATA_IN = PIN(PIN_I2S0_DATA_IN, false); +const mcu_pin_obj_t pin_EMMC_DATA2 = PIN(PIN_EMMC_DATA2, false); +const mcu_pin_obj_t pin_EMMC_DATA3 = PIN(PIN_EMMC_DATA3, false); +const mcu_pin_obj_t pin_SEN_IRQ_IN = PIN(PIN_SEN_IRQ_IN, false); +const mcu_pin_obj_t pin_EMMC_CLK = PIN(PIN_EMMC_CLK, false); +const mcu_pin_obj_t pin_EMMC_CMD = PIN(PIN_EMMC_CMD, false); +const mcu_pin_obj_t pin_I2S0_LRCK = PIN(PIN_I2S0_LRCK, false); +const mcu_pin_obj_t pin_I2S0_BCK = PIN(PIN_I2S0_BCK, false); +const mcu_pin_obj_t pin_UART2_CTS = PIN(PIN_UART2_CTS, false); +const mcu_pin_obj_t pin_UART2_RTS = PIN(PIN_UART2_RTS, false); +const mcu_pin_obj_t pin_I2S1_BCK = PIN(PIN_I2S1_BCK, false); +const mcu_pin_obj_t pin_I2S1_LRCK = PIN(PIN_I2S1_LRCK, false); +const mcu_pin_obj_t pin_I2S1_DATA_IN = PIN(PIN_I2S1_DATA_IN, false); +const mcu_pin_obj_t pin_I2S1_DATA_OUT = PIN(PIN_I2S1_DATA_OUT, false); +const mcu_pin_obj_t pin_LPADC0 = PIN(0, true); +const mcu_pin_obj_t pin_LPADC1 = PIN(1, true); +const mcu_pin_obj_t pin_LPADC2 = PIN(2, true); +const mcu_pin_obj_t pin_LPADC3 = PIN(3, true); +const mcu_pin_obj_t pin_HPADC0 = PIN(4, true); +const mcu_pin_obj_t pin_HPADC1 = PIN(5, true); STATIC pin_status_t pins[] = { - { &pin_D0, true, true }, - { &pin_D1, true, true }, - { &pin_D2, true, true }, - { &pin_D3, true, true }, - { &pin_D4, true, true }, - { &pin_D5, true, true }, - { &pin_D6, true, true }, - { &pin_D7, true, true }, - { &pin_D8, true, true }, - { &pin_D9, true, true }, - { &pin_D10, true, true }, - { &pin_D11, true, true }, - { &pin_D12, true, true }, - { &pin_D13, true, true }, - { &pin_D14, true, true }, - { &pin_D15, true, true }, - { &pin_D16, true, true }, - { &pin_D17, true, true }, - { &pin_D18, true, true }, - { &pin_D19, true, true }, - { &pin_D20, true, true }, - { &pin_D21, true, true }, - { &pin_D22, true, true }, - { &pin_D23, true, true }, - { &pin_D24, true, true }, - { &pin_D25, true, true }, - { &pin_D26, true, true }, - { &pin_D27, true, true }, - { &pin_D28, true, true }, - { &pin_LED0, true, true }, - { &pin_LED1, true, true }, - { &pin_LED2, true, true }, - { &pin_LED3, true, true }, + { &pin_UART2_RXD, true, true }, + { &pin_UART2_TXD, true, true }, + { &pin_HIF_IRQ_OUT, true, true }, + { &pin_PWM3, true, true }, + { &pin_SPI2_MOSI, true, true }, + { &pin_PWM1, true, true }, + { &pin_PWM0, true, true }, + { &pin_SPI3_CS1_X, true, true }, + { &pin_SPI2_MISO, true, true }, + { &pin_PWM2, true, true }, + { &pin_SPI4_CS_X, true, true }, + { &pin_SPI4_MOSI, true, true }, + { &pin_SPI4_MISO, true, true }, + { &pin_SPI4_SCK, true, true }, + { &pin_I2C0_BDT, true, true }, + { &pin_I2C0_BCK, true, true }, + { &pin_EMMC_DATA0, true, true }, + { &pin_EMMC_DATA1, true, true }, + { &pin_I2S0_DATA_OUT, true, true }, + { &pin_I2S0_DATA_IN, true, true }, + { &pin_EMMC_DATA2, true, true }, + { &pin_EMMC_DATA3, true, true }, + { &pin_SEN_IRQ_IN, true, true }, + { &pin_EMMC_CLK, true, true }, + { &pin_EMMC_CMD, true, true }, + { &pin_I2S0_LRCK, true, true }, + { &pin_I2S0_BCK, true, true }, + { &pin_UART2_CTS, true, true }, + { &pin_UART2_RTS, true, true }, + { &pin_I2S1_BCK, true, true }, + { &pin_I2S1_LRCK, true, true }, + { &pin_I2S1_DATA_IN, true, true }, + { &pin_I2S1_DATA_OUT, true, true }, }; bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { diff --git a/ports/cxd56/common-hal/microcontroller/Pin.h b/ports/cxd56/common-hal/microcontroller/Pin.h index 113387cef3..fe6524edb5 100644 --- a/ports/cxd56/common-hal/microcontroller/Pin.h +++ b/ports/cxd56/common-hal/microcontroller/Pin.h @@ -44,45 +44,45 @@ typedef struct { bool analog; } mcu_pin_obj_t; -extern const mcu_pin_obj_t pin_D0; -extern const mcu_pin_obj_t pin_D1; -extern const mcu_pin_obj_t pin_D2; -extern const mcu_pin_obj_t pin_D3; -extern const mcu_pin_obj_t pin_D4; -extern const mcu_pin_obj_t pin_D5; -extern const mcu_pin_obj_t pin_D6; -extern const mcu_pin_obj_t pin_D7; -extern const mcu_pin_obj_t pin_D8; -extern const mcu_pin_obj_t pin_D9; -extern const mcu_pin_obj_t pin_D10; -extern const mcu_pin_obj_t pin_D11; -extern const mcu_pin_obj_t pin_D12; -extern const mcu_pin_obj_t pin_D13; -extern const mcu_pin_obj_t pin_D14; -extern const mcu_pin_obj_t pin_D15; -extern const mcu_pin_obj_t pin_D16; -extern const mcu_pin_obj_t pin_D17; -extern const mcu_pin_obj_t pin_D18; -extern const mcu_pin_obj_t pin_D19; -extern const mcu_pin_obj_t pin_D20; -extern const mcu_pin_obj_t pin_D21; -extern const mcu_pin_obj_t pin_D22; -extern const mcu_pin_obj_t pin_D23; -extern const mcu_pin_obj_t pin_D24; -extern const mcu_pin_obj_t pin_D25; -extern const mcu_pin_obj_t pin_D26; -extern const mcu_pin_obj_t pin_D27; -extern const mcu_pin_obj_t pin_D28; -extern const mcu_pin_obj_t pin_LED0; -extern const mcu_pin_obj_t pin_LED1; -extern const mcu_pin_obj_t pin_LED2; -extern const mcu_pin_obj_t pin_LED3; -extern const mcu_pin_obj_t pin_A0; -extern const mcu_pin_obj_t pin_A1; -extern const mcu_pin_obj_t pin_A2; -extern const mcu_pin_obj_t pin_A3; -extern const mcu_pin_obj_t pin_A4; -extern const mcu_pin_obj_t pin_A5; +extern const mcu_pin_obj_t pin_UART2_RXD; +extern const mcu_pin_obj_t pin_UART2_TXD; +extern const mcu_pin_obj_t pin_HIF_IRQ_OUT; +extern const mcu_pin_obj_t pin_PWM3; +extern const mcu_pin_obj_t pin_SPI2_MOSI; +extern const mcu_pin_obj_t pin_PWM1; +extern const mcu_pin_obj_t pin_PWM0; +extern const mcu_pin_obj_t pin_SPI3_CS1_X; +extern const mcu_pin_obj_t pin_SPI2_MISO; +extern const mcu_pin_obj_t pin_PWM2; +extern const mcu_pin_obj_t pin_SPI4_CS_X; +extern const mcu_pin_obj_t pin_SPI4_MOSI; +extern const mcu_pin_obj_t pin_SPI4_MISO; +extern const mcu_pin_obj_t pin_SPI4_SCK; +extern const mcu_pin_obj_t pin_I2C0_BDT; +extern const mcu_pin_obj_t pin_I2C0_BCK; +extern const mcu_pin_obj_t pin_EMMC_DATA0; +extern const mcu_pin_obj_t pin_EMMC_DATA1; +extern const mcu_pin_obj_t pin_I2S0_DATA_OUT; +extern const mcu_pin_obj_t pin_I2S0_DATA_IN; +extern const mcu_pin_obj_t pin_EMMC_DATA2; +extern const mcu_pin_obj_t pin_EMMC_DATA3; +extern const mcu_pin_obj_t pin_SEN_IRQ_IN; +extern const mcu_pin_obj_t pin_EMMC_CLK; +extern const mcu_pin_obj_t pin_EMMC_CMD; +extern const mcu_pin_obj_t pin_I2S0_LRCK; +extern const mcu_pin_obj_t pin_I2S0_BCK; +extern const mcu_pin_obj_t pin_UART2_CTS; +extern const mcu_pin_obj_t pin_UART2_RTS; +extern const mcu_pin_obj_t pin_I2S1_BCK; +extern const mcu_pin_obj_t pin_I2S1_LRCK; +extern const mcu_pin_obj_t pin_I2S1_DATA_IN; +extern const mcu_pin_obj_t pin_I2S1_DATA_OUT; +extern const mcu_pin_obj_t pin_LPADC0; +extern const mcu_pin_obj_t pin_LPADC1; +extern const mcu_pin_obj_t pin_LPADC2; +extern const mcu_pin_obj_t pin_LPADC3; +extern const mcu_pin_obj_t pin_HPADC0; +extern const mcu_pin_obj_t pin_HPADC1; void never_reset_pin_number(uint8_t pin_number); void reset_pin_number(uint8_t pin_number); diff --git a/ports/cxd56/common-hal/microcontroller/__init__.c b/ports/cxd56/common-hal/microcontroller/__init__.c index 576896eb23..2be74b0069 100644 --- a/ports/cxd56/common-hal/microcontroller/__init__.c +++ b/ports/cxd56/common-hal/microcontroller/__init__.c @@ -68,44 +68,44 @@ void common_hal_mcu_reset(void) { } STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_D0) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_D1) }, - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_D2) }, - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_D3) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_D4) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_D5) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_D6) }, - { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_D7) }, - { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_D8) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_D9) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_D10) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_D11) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_D12) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_D13) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_D14) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_D15) }, - { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_D16) }, - { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_D17) }, - { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_D18) }, - { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_D19) }, - { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_D20) }, - { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_D21) }, - { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_D22) }, - { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_D23) }, - { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_D24) }, - { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_D25) }, - { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_D26) }, - { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_D27) }, - { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_D28) }, - { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_LED0) }, - { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_LED1) }, - { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_LED2) }, - { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_LED3) }, - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_A0) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_A1) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_A2) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_A3) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_A4) }, - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_A5) }, + { MP_ROM_QSTR(MP_QSTR_UART2_RXD), MP_ROM_PTR(&pin_UART2_RXD) }, + { MP_ROM_QSTR(MP_QSTR_UART2_TXD), MP_ROM_PTR(&pin_UART2_TXD) }, + { MP_ROM_QSTR(MP_QSTR_HIF_IRQ_OUT), MP_ROM_PTR(&pin_HIF_IRQ_OUT) }, + { MP_ROM_QSTR(MP_QSTR_PWM3), MP_ROM_PTR(&pin_PWM3) }, + { MP_ROM_QSTR(MP_QSTR_SPI2_MOSI), MP_ROM_PTR(&pin_SPI2_MOSI) }, + { MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_PWM1) }, + { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_PWM0) }, + { MP_ROM_QSTR(MP_QSTR_SPI3_CS1_X), MP_ROM_PTR(&pin_SPI3_CS1_X) }, + { MP_ROM_QSTR(MP_QSTR_SPI2_MISO), MP_ROM_PTR(&pin_SPI2_MISO) }, + { MP_ROM_QSTR(MP_QSTR_PWM2), MP_ROM_PTR(&pin_PWM2) }, + { MP_ROM_QSTR(MP_QSTR_SPI4_CS_X), MP_ROM_PTR(&pin_SPI4_CS_X) }, + { MP_ROM_QSTR(MP_QSTR_SPI4_MOSI), MP_ROM_PTR(&pin_SPI4_MOSI) }, + { MP_ROM_QSTR(MP_QSTR_SPI4_MISO), MP_ROM_PTR(&pin_SPI4_MISO) }, + { MP_ROM_QSTR(MP_QSTR_SPI4_SCK), MP_ROM_PTR(&pin_SPI4_SCK) }, + { MP_ROM_QSTR(MP_QSTR_I2C0_BDT), MP_ROM_PTR(&pin_I2C0_BDT) }, + { MP_ROM_QSTR(MP_QSTR_I2C0_BCK), MP_ROM_PTR(&pin_I2C0_BCK) }, + { MP_ROM_QSTR(MP_QSTR_EMMC_DATA0), MP_ROM_PTR(&pin_EMMC_DATA0) }, + { MP_ROM_QSTR(MP_QSTR_EMMC_DATA1), MP_ROM_PTR(&pin_EMMC_DATA1) }, + { MP_ROM_QSTR(MP_QSTR_I2S0_DATA_OUT), MP_ROM_PTR(&pin_I2S0_DATA_OUT) }, + { MP_ROM_QSTR(MP_QSTR_I2S0_DATA_IN), MP_ROM_PTR(&pin_I2S0_DATA_IN) }, + { MP_ROM_QSTR(MP_QSTR_EMMC_DATA2), MP_ROM_PTR(&pin_EMMC_DATA2) }, + { MP_ROM_QSTR(MP_QSTR_EMMC_DATA3), MP_ROM_PTR(&pin_EMMC_DATA3) }, + { MP_ROM_QSTR(MP_QSTR_SEN_IRQ_IN), MP_ROM_PTR(&pin_SEN_IRQ_IN) }, + { MP_ROM_QSTR(MP_QSTR_EMMC_CLK), MP_ROM_PTR(&pin_EMMC_CLK) }, + { MP_ROM_QSTR(MP_QSTR_EMMC_CMD), MP_ROM_PTR(&pin_EMMC_CMD) }, + { MP_ROM_QSTR(MP_QSTR_I2S0_LRCK), MP_ROM_PTR(&pin_I2S0_LRCK) }, + { MP_ROM_QSTR(MP_QSTR_I2S0_BCK), MP_ROM_PTR(&pin_I2S0_BCK) }, + { MP_ROM_QSTR(MP_QSTR_UART2_CTS), MP_ROM_PTR(&pin_UART2_CTS) }, + { MP_ROM_QSTR(MP_QSTR_UART2_RTS), MP_ROM_PTR(&pin_UART2_RTS) }, + { MP_ROM_QSTR(MP_QSTR_I2S1_BCK), MP_ROM_PTR(&pin_I2S1_BCK) }, + { MP_ROM_QSTR(MP_QSTR_I2S1_LRCK), MP_ROM_PTR(&pin_I2S1_LRCK) }, + { MP_ROM_QSTR(MP_QSTR_I2S1_DATA_IN), MP_ROM_PTR(&pin_I2S1_DATA_IN) }, + { MP_ROM_QSTR(MP_QSTR_I2S1_DATA_OUT), MP_ROM_PTR(&pin_I2S1_DATA_OUT) }, + { MP_ROM_QSTR(MP_QSTR_LPADC0), MP_ROM_PTR(&pin_LPADC0) }, + { MP_ROM_QSTR(MP_QSTR_LPADC1), MP_ROM_PTR(&pin_LPADC1) }, + { MP_ROM_QSTR(MP_QSTR_LPADC2), MP_ROM_PTR(&pin_LPADC2) }, + { MP_ROM_QSTR(MP_QSTR_LPADC3), MP_ROM_PTR(&pin_LPADC3) }, + { MP_ROM_QSTR(MP_QSTR_HPADC0), MP_ROM_PTR(&pin_HPADC0) }, + { MP_ROM_QSTR(MP_QSTR_HPADC1), MP_ROM_PTR(&pin_HPADC1) }, }; MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_globals_table); diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.c b/ports/cxd56/common-hal/pulseio/PWMOut.c index fae49aed3e..38692146c2 100644 --- a/ports/cxd56/common-hal/pulseio/PWMOut.c +++ b/ports/cxd56/common-hal/pulseio/PWMOut.c @@ -40,10 +40,10 @@ typedef struct { } pwmout_dev_t; STATIC pwmout_dev_t pwmout_dev[] = { - {"/dev/pwm0", &pin_D6, -1, true}, - {"/dev/pwm1", &pin_D5, -1, true}, - {"/dev/pwm2", &pin_D9, -1, true}, - {"/dev/pwm3", &pin_D3, -1, true} + {"/dev/pwm0", &pin_PWM0, -1, true}, + {"/dev/pwm1", &pin_PWM1, -1, true}, + {"/dev/pwm2", &pin_PWM2, -1, true}, + {"/dev/pwm3", &pin_PWM3, -1, true} }; pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, From c062990830891cd4193563a4a11eabbec25b1b57 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 11:17:28 +0200 Subject: [PATCH 09/19] Make Makefile work across OS --- ports/cxd56/Makefile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 69c8e1bef6..c7350a652f 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -62,6 +62,20 @@ SPRESENSE_SDK = spresense-exported-sdk FIRMWARE = $(SPRESENSE_SDK)/firmware +# Platforms are: Linux, Darwin, MSYS, CYGWIN +PLATFORM := $(firstword $(subst _, ,$(shell uname -s 2>/dev/null))) + +ifeq ($(PLATFORM),Darwin) + # macOS + MKSPK = $(SPRESENSE_SDK)/sdk/tools/macos/mkspk +else ifeq ($(PLATFORM),Linux) + # Linux + MKSPK = $(SPRESENSE_SDK)/sdk/tools/linux/mkspk +else + # Cygwin/MSYS2 + MKSPK = $(SPRESENSE_SDK)/sdk/tools/windows/mkspk.exe +endif + INC += \ -I. \ -I../.. \ @@ -186,7 +200,7 @@ $(BUILD)/circuitpython.elf: $(BUILD)/libmpy.a $(BUILD)/circuitpython.spk: $(BUILD)/circuitpython.elf $(ECHO) "Creating $@" - $(SPRESENSE_SDK)/sdk/tools/linux/mkspk -c 2 $(BUILD)/circuitpython.elf nuttx $(BUILD)/circuitpython.spk + $(MKSPK) -c 2 $(BUILD)/circuitpython.elf nuttx $(BUILD)/circuitpython.spk flash: $(BUILD)/circuitpython.spk $(ECHO) "Writing $< to the board" From 0d139e4eca0a992137a4ec93c86aa56518ed1095 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 11:31:32 +0200 Subject: [PATCH 10/19] Add a way to change serial device name --- ports/cxd56/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index c7350a652f..19d8ad1e98 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -76,6 +76,8 @@ else MKSPK = $(SPRESENSE_SDK)/sdk/tools/windows/mkspk.exe endif +SERIAL ?= /dev/ttyUSB0 + INC += \ -I. \ -I../.. \ @@ -204,11 +206,11 @@ $(BUILD)/circuitpython.spk: $(BUILD)/circuitpython.elf flash: $(BUILD)/circuitpython.spk $(ECHO) "Writing $< to the board" - $(SPRESENSE_SDK)/sdk/tools/flash.sh -c /dev/ttyUSB0 $(BUILD)/circuitpython.spk + $(SPRESENSE_SDK)/sdk/tools/flash.sh -c $(SERIAL) $(BUILD)/circuitpython.spk flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE) $(ECHO) "Writing loader to the board" - $(SPRESENSE_SDK)/sdk/tools/flash.sh -l $(FIRMWARE) -c /dev/ttyUSB0 + $(SPRESENSE_SDK)/sdk/tools/flash.sh -l $(FIRMWARE) -c $(SERIAL) include $(TOP)/py/mkrules.mk From 5cf66dfec278ba6e34bfb3041ef98e2d23c0eb1b Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 12:00:58 +0200 Subject: [PATCH 11/19] Add cxd56 to build_board_info --- tools/build_board_info.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/build_board_info.py b/tools/build_board_info.py index 7d0d2996cc..efa481a637 100644 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -12,18 +12,20 @@ from sh.contrib import git sys.path.append("adabot") import adabot.github_requests as github -SUPPORTED_PORTS = ["nrf", "atmel-samd", "stm32f4"] +SUPPORTED_PORTS = ["nrf", "atmel-samd", "stm32f4", "cxd56"] BIN = ('bin',) UF2 = ('uf2',) BIN_UF2 = ('bin', 'uf2') HEX = ('hex',) +SPK = ('spk',) # Default extensions extension_by_port = { "nrf": UF2, "atmel-samd": UF2, "stm32f4": BIN, + "cxd56": SPK, } # Per board overrides From 954c1942f671aefb60cbef29e356c2763af39d53 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 12:05:47 +0200 Subject: [PATCH 12/19] Add Spresense 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 8c1f46f6ff..1bf7bf9adf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -145,6 +145,7 @@ jobs: - "sparkfun_redboard_turbo" - "sparkfun_samd21_dev" - "sparkfun_samd21_mini" + - "spresense" - "stm32f411ve_discovery" - "stm32f412zg_discovery" - "trellis_m4_express" From eb1dfd2312ea643404c8f1c9a5232a9b8353c5f4 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 12:11:48 +0200 Subject: [PATCH 13/19] Add .gitignore --- ports/cxd56/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 ports/cxd56/.gitignore diff --git a/ports/cxd56/.gitignore b/ports/cxd56/.gitignore new file mode 100644 index 0000000000..414487d53e --- /dev/null +++ b/ports/cxd56/.gitignore @@ -0,0 +1 @@ +build-*/ From 771f43591a41dc45e3f034f3ec4ee313a5dc2922 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 12:57:43 +0200 Subject: [PATCH 14/19] Add links to serial drivers --- ports/cxd56/README.md | 48 +++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/ports/cxd56/README.md b/ports/cxd56/README.md index 99a9032fe6..5b3c61726b 100644 --- a/ports/cxd56/README.md +++ b/ports/cxd56/README.md @@ -1,5 +1,4 @@ -CircuitPython port to Spresense -============================== +# CircuitPython port to Spresense # This directory contains the port of CircuitPython to Spresense. It is a compact development board based on Sony’s power-efficient multicore microcontroller @@ -22,8 +21,29 @@ Currently, Spresense port does not support GNSS, Audio and Multicore. Refer to [developer.sony.com/develop/spresense/](https://developer.sony.com/develop/spresense/) for further information about this board. -Build instructions ------------------- +## Prerequisites ## + +### Linux ### + +Add user to `dialout` group: + + $ sudo usermod -a -G dialout + +### Windows ### + +Download and install USB serial driver + +* [CP210x USB to serial driver for Windows 7/8/8.1](https://www.silabs.com/documents/public/software/CP210x_Windows_Drivers.zip) + +* [CP210x USB to serial driver for Windows 10](https://www.silabs.com/documents/public/software/CP210x_Universal_Windows_Driver.zip) + +### macOS ### + +Download and install USB serial driver + +* [CP210x USB to serial driver for Mac OS X](https://www.silabs.com/documents/public/software/Mac_OSX_VCP_Driver.zip) + +## Build instructions ## Pull all submodules into your clone: @@ -41,17 +61,11 @@ To build circuitpython image run: $ make BOARD=spresense -USB connection --------------- +## USB connection ## -Add user to `dialout` group: +Connect the `Spresense main board` to the PC via the USB cable. - $ sudo usermod -a -G dialout - -Connect the Spresense main board to the PC via the USB cable. - -Flash the bootloader --------------------- +## Flash the bootloader ## The correct bootloader is required for the Spresense board to function. @@ -69,17 +83,15 @@ To flash the bootloader run the command: $ make BOARD=spresense flash-bootloader -Flash the circuitpython.spk image ---------------------------------- +## Flash the circuitpython.spk image ## To flash the firmware run the command: $ make BOARD=spresense flash -Accessing the board -------------------- +## Accessing the board ## -Connect the Spresense extension board to the PC via the USB cable. +Connect the `Spresense extension board` to the PC via the USB cable. Once built and deployed, access the CircuitPython REPL (the Python prompt) via USB. You can run: From 6b9375804c6ef0c56fe3bfa83c5780317dc5f4aa Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Fri, 11 Oct 2019 17:15:25 +0200 Subject: [PATCH 15/19] Rename circuitpython.spk to firmware.spk --- ports/cxd56/Makefile | 14 +++++++------- ports/cxd56/README.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 19d8ad1e98..38ebd83050 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -128,7 +128,7 @@ LDFLAGS = \ -T$(SPRESENSE_SDK)/nuttx/build/ramconfig.ld \ --gc-sections \ -Map=$(BUILD)/output.map \ - -o $(BUILD)/circuitpython.elf \ + -o $(BUILD)/firmware.elf \ --start-group \ -u spresense_main \ $(BUILD)/libmpy.a \ @@ -181,7 +181,7 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_M # Sources that only hold QSTRs after pre-processing. SRC_QSTR_PREPROCESSOR += -all: $(BUILD)/circuitpython.spk +all: $(BUILD)/firmware.spk $(FIRMWARE): $(ECHO) "" @@ -196,17 +196,17 @@ $(BUILD)/libmpy.a: $(SPRESENSE_SDK) $(OBJ) $(ECHO) "AR $@" $(Q)$(AR) rcs $(BUILD)/libmpy.a $(OBJ) -$(BUILD)/circuitpython.elf: $(BUILD)/libmpy.a +$(BUILD)/firmware.elf: $(BUILD)/libmpy.a $(ECHO) "LD $@" $(Q)$(LD) $(LDFLAGS) -$(BUILD)/circuitpython.spk: $(BUILD)/circuitpython.elf +$(BUILD)/firmware.spk: $(BUILD)/firmware.elf $(ECHO) "Creating $@" - $(MKSPK) -c 2 $(BUILD)/circuitpython.elf nuttx $(BUILD)/circuitpython.spk + $(MKSPK) -c 2 $(BUILD)/firmware.elf nuttx $(BUILD)/firmware.spk -flash: $(BUILD)/circuitpython.spk +flash: $(BUILD)/firmware.spk $(ECHO) "Writing $< to the board" - $(SPRESENSE_SDK)/sdk/tools/flash.sh -c $(SERIAL) $(BUILD)/circuitpython.spk + $(SPRESENSE_SDK)/sdk/tools/flash.sh -c $(SERIAL) $(BUILD)/firmware.spk flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE) $(ECHO) "Writing loader to the board" diff --git a/ports/cxd56/README.md b/ports/cxd56/README.md index 5b3c61726b..b98cf35f24 100644 --- a/ports/cxd56/README.md +++ b/ports/cxd56/README.md @@ -83,7 +83,7 @@ To flash the bootloader run the command: $ make BOARD=spresense flash-bootloader -## Flash the circuitpython.spk image ## +## Flash the circuitpython image ## To flash the firmware run the command: From c67b2c16619c456935dd93675b478668aeac0352 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 14 Oct 2019 08:18:17 +0200 Subject: [PATCH 16/19] Return None if reference_voltage is 0.0 --- shared-bindings/analogio/AnalogIn.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index a8bbbf59af..de48ba082d 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -138,7 +138,13 @@ const mp_obj_property_t analogio_analogin_value_obj = { STATIC mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) { analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return mp_obj_new_float(common_hal_analogio_analogin_get_reference_voltage(self)); + + float reference_voltage = common_hal_analogio_analogin_get_reference_voltage(self); + if (reference_voltage == 0.0f) { + return mp_const_none; + } else { + return mp_obj_new_float(reference_voltage); + } } MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogin_get_reference_voltage_obj, analogio_analogin_obj_get_reference_voltage); From 8dfc8b584fa962231719a489994d28897890ab37 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 14 Oct 2019 08:19:52 +0200 Subject: [PATCH 17/19] Change Spresense reference_voltage to 0.0 (None) --- ports/cxd56/common-hal/analogio/AnalogIn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/cxd56/common-hal/analogio/AnalogIn.c b/ports/cxd56/common-hal/analogio/AnalogIn.c index 6f3b7a1ba6..ebe291582a 100644 --- a/ports/cxd56/common-hal/analogio/AnalogIn.c +++ b/ports/cxd56/common-hal/analogio/AnalogIn.c @@ -116,7 +116,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { // - Reference Voltage of A0 ~ A5 pins on External Interface board // is selected 3.3V or 5.0V by a IO Volt jumper pin. float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { - return 3.3f; + return 0.0f; } void analogin_reset(void) { From b750ed3a0fbd010b1256ab26f945a3bbf851773b Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 14 Oct 2019 08:42:10 +0200 Subject: [PATCH 18/19] Change Spresense firmware download link --- ports/cxd56/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/cxd56/README.md b/ports/cxd56/README.md index b98cf35f24..ec284e7421 100644 --- a/ports/cxd56/README.md +++ b/ports/cxd56/README.md @@ -75,7 +75,7 @@ Bootloader information: * You have to accept the End User License Agreement to be able to download and use the Spresense bootloader binary. -Download the spresense binaries zip archive from: +Download the spresense binaries zip archive from: [Spresense firmware v1-4-000](https://developer.sony.com/file/download/download-spresense-firmware-v1-4-000) Extract spresense binaries in your PC to ports/spresense/spresense-exported-sdk/firmware/ From 150f9041e32f8d0887378d6568db1f50bf2b9317 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 14 Oct 2019 09:05:55 +0200 Subject: [PATCH 19/19] Fix unsafe floating point comparison --- shared-bindings/analogio/AnalogIn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index de48ba082d..9a9b525d8b 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -140,7 +140,7 @@ STATIC mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) { check_for_deinit(self); float reference_voltage = common_hal_analogio_analogin_get_reference_voltage(self); - if (reference_voltage == 0.0f) { + if (reference_voltage <= 0.0f) { return mp_const_none; } else { return mp_obj_new_float(reference_voltage);