merge from upstream

crypto-aes
Dan Halbert 3 years ago
commit 615ec7f74d
  1. 1
      .github/workflows/build.yml
  2. 3
      .gitmodules
  3. 1
      conf.py
  4. 1
      docs/supported_ports.rst
  5. 1
      ports/cxd56/.gitignore
  6. 220
      ports/cxd56/Makefile
  7. 98
      ports/cxd56/README.md
  8. 6
      ports/cxd56/alloca.h
  9. 53
      ports/cxd56/background.c
  10. 33
      ports/cxd56/background.h
  11. 45
      ports/cxd56/boards/board.h
  12. 38
      ports/cxd56/boards/spresense/board.c
  13. 39
      ports/cxd56/boards/spresense/mpconfigboard.h
  14. 4
      ports/cxd56/boards/spresense/mpconfigboard.mk
  15. 80
      ports/cxd56/boards/spresense/pins.c
  16. 131
      ports/cxd56/common-hal/analogio/AnalogIn.c
  17. 42
      ports/cxd56/common-hal/analogio/AnalogIn.h
  18. 43
      ports/cxd56/common-hal/analogio/AnalogOut.c
  19. 36
      ports/cxd56/common-hal/analogio/AnalogOut.h
  20. 1
      ports/cxd56/common-hal/analogio/__init__.c
  21. 1
      ports/cxd56/common-hal/board/__init__.c
  22. 123
      ports/cxd56/common-hal/busio/I2C.c
  23. 43
      ports/cxd56/common-hal/busio/I2C.h
  24. 33
      ports/cxd56/common-hal/busio/OneWire.h
  25. 155
      ports/cxd56/common-hal/busio/SPI.c
  26. 49
      ports/cxd56/common-hal/busio/SPI.h
  27. 168
      ports/cxd56/common-hal/busio/UART.c
  28. 43
      ports/cxd56/common-hal/busio/UART.h
  29. 1
      ports/cxd56/common-hal/busio/__init__.c
  30. 136
      ports/cxd56/common-hal/digitalio/DigitalInOut.c
  31. 42
      ports/cxd56/common-hal/digitalio/DigitalInOut.h
  32. 1
      ports/cxd56/common-hal/digitalio/__init__.c
  33. 162
      ports/cxd56/common-hal/microcontroller/Pin.c
  34. 92
      ports/cxd56/common-hal/microcontroller/Pin.h
  35. 41
      ports/cxd56/common-hal/microcontroller/Processor.c
  36. 40
      ports/cxd56/common-hal/microcontroller/Processor.h
  37. 111
      ports/cxd56/common-hal/microcontroller/__init__.c
  38. 72
      ports/cxd56/common-hal/os/__init__.c
  39. 157
      ports/cxd56/common-hal/pulseio/PWMOut.c
  40. 48
      ports/cxd56/common-hal/pulseio/PWMOut.h
  41. 196
      ports/cxd56/common-hal/pulseio/PulseIn.c
  42. 47
      ports/cxd56/common-hal/pulseio/PulseIn.h
  43. 126
      ports/cxd56/common-hal/pulseio/PulseOut.c
  44. 39
      ports/cxd56/common-hal/pulseio/PulseOut.h
  45. 1
      ports/cxd56/common-hal/pulseio/__init__.c
  46. 54
      ports/cxd56/common-hal/rtc/RTC.c
  47. 30
      ports/cxd56/common-hal/rtc/RTC.h
  48. 1
      ports/cxd56/common-hal/rtc/__init__.c
  49. 36
      ports/cxd56/common-hal/supervisor/Runtime.c
  50. 36
      ports/cxd56/common-hal/supervisor/Runtime.h
  51. 36
      ports/cxd56/common-hal/supervisor/__init__.c
  52. 37
      ports/cxd56/common-hal/time/__init__.c
  53. 46
      ports/cxd56/fatfs_port.c
  54. 38
      ports/cxd56/mpconfigport.h
  55. 20
      ports/cxd56/mpconfigport.mk
  56. 88
      ports/cxd56/mphalport.c
  57. 36
      ports/cxd56/mphalport.h
  58. 1
      ports/cxd56/qstrdefsport.h
  59. 1
      ports/cxd56/spresense-exported-sdk
  60. 27
      ports/cxd56/supervisor/cpu.s
  61. 114
      ports/cxd56/supervisor/internal_flash.c
  62. 30
      ports/cxd56/supervisor/internal_flash.h
  63. 31
      ports/cxd56/supervisor/internal_flash_root_pointers.h
  64. 79
      ports/cxd56/supervisor/port.c
  65. 30
      ports/cxd56/supervisor/usb.c
  66. 45
      ports/cxd56/tick.c
  67. 34
      ports/cxd56/tick.h
  68. 49
      py/nlr.h
  69. 8
      shared-bindings/analogio/AnalogIn.c
  70. 4
      tools/build_board_info.py

@ -145,6 +145,7 @@ jobs:
- "sparkfun_redboard_turbo"
- "sparkfun_samd21_dev"
- "sparkfun_samd21_mini"
- "spresense"
- "stm32f411ve_discovery"
- "stm32f412zg_discovery"
- "trellis_m4_express"

3
.gitmodules vendored

@ -98,3 +98,6 @@
[submodule "ports/stm32f4/stm32f4"]
path = ports/stm32f4/stm32f4
url = https://github.com/adafruit/stm32f4.git
[submodule "ports/cxd56/spresense-exported-sdk"]
path = ports/cxd56/spresense-exported-sdk
url = https://github.com/sonydevworld/spresense-exported-sdk.git

@ -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",

@ -10,3 +10,4 @@ and ESP8266.
../ports/atmel-samd/README
../ports/nrf/README
../ports/stm32f4/README
../ports/cxd56/README

@ -0,0 +1 @@
build-*/

@ -0,0 +1,220 @@
# 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.
# 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
# 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
# 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
SERIAL ?= /dev/ttyUSB0
INC += \
-I. \
-I../.. \
-I../lib/mp-readline \
-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 \
-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)/firmware.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 \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.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)/firmware.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)/firmware.elf: $(BUILD)/libmpy.a
$(ECHO) "LD $@"
$(Q)$(LD) $(LDFLAGS)
$(BUILD)/firmware.spk: $(BUILD)/firmware.elf
$(ECHO) "Creating $@"
$(MKSPK) -c 2 $(BUILD)/firmware.elf nuttx $(BUILD)/firmware.spk
flash: $(BUILD)/firmware.spk
$(ECHO) "Writing $< to the board"
$(SPRESENSE_SDK)/sdk/tools/flash.sh -c $(SERIAL) $(BUILD)/firmware.spk
flash-bootloader: $(SPRESENSE_SDK) $(FIRMWARE)
$(ECHO) "Writing loader to the board"
$(SPRESENSE_SDK)/sdk/tools/flash.sh -l $(FIRMWARE) -c $(SERIAL)
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 $* = $($*)

@ -0,0 +1,98 @@
# 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.
## Prerequisites ##
### Linux ###
Add user to `dialout` group:
$ sudo usermod -a -G dialout <user-name>
### 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:
$ git submodule update --init --recursive
Build the MicroPython cross-compiler:
$ make -C mpy-cross
Change directory to cxd56:
$ cd ports/cxd56
To build circuitpython image run:
$ make BOARD=spresense
## USB connection ##
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: [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/
To flash the bootloader run the command:
$ make BOARD=spresense flash-bootloader
## Flash the circuitpython image ##
To flash the firmware run the command:
$ make BOARD=spresense 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

@ -0,0 +1,6 @@
#ifndef _ALLOCA_H
#define _ALLOCA_H
#define alloca __builtin_alloca
#endif /* _ALLOCA_H */

@ -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();
}

@ -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_CXD56_BACKGROUND_H
#define MICROPY_INCLUDED_CXD56_BACKGROUND_H
void background_tasks_reset(void);
void run_background_tasks(void);
#endif // MICROPY_INCLUDED_CXD56_BACKGROUND_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 <stdbool.h>
// 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

@ -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) {
}

@ -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_I2C0_BCK)
#define DEFAULT_I2C_BUS_SDA (&pin_I2C0_BDT)
#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_UART2_RXD)
#define DEFAULT_UART_BUS_TX (&pin_UART2_TXD)

@ -0,0 +1,4 @@
USB_VID = 0x054c
USB_PID = 0x0bc2
USB_PRODUCT = "Spresense"
USB_MANUFACTURER = "Sony"

@ -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_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) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

@ -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 <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <arch/chip/scu.h>
#include <arch/chip/adc.h>
#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_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) {
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 0.0f;
}
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;
}
}
}

@ -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_CXD56_COMMON_HAL_ANALOGIO_ANALOGIN_H
#define MICROPY_INCLUDED_CXD56_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_CXD56_COMMON_HAL_ANALOGIO_ANALOGIN_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.
*/
#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) {
}

@ -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_CXD56_COMMON_HAL_ANALOGIO_ANALOGOUT_H
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGOUT_H
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
} analogio_analogout_obj_t;
#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_ANALOGIO_ANALOGOUT_H

@ -0,0 +1 @@
// No analogio module functions.

@ -0,0 +1 @@
// No board module functions.

@ -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 <arch/chip/pin.h>
#include <nuttx/i2c/i2c_master.h>
#include <cxd56_i2c.h>
#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);
}

@ -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_CXD56_COMMON_HAL_BUSIO_I2C_H
#define MICROPY_INCLUDED_CXD56_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_CXD56_COMMON_HAL_BUSIO_I2C_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_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_CXD56_COMMON_HAL_BUSIO_ONEWIRE_H

@ -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 <arch/chip/pin.h>
#include <cxd56_spi.h>
#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);
}

@ -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.
*</