summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/SDdatalogger/README.md4
-rw-r--r--examples/SDdatalogger/boot.py25
-rw-r--r--examples/SDdatalogger/cardreader.py2
-rw-r--r--examples/SDdatalogger/datalogger.py33
-rw-r--r--examples/accel_i2c.py34
-rw-r--r--examples/accellog.py17
-rw-r--r--examples/asmled.py85
-rw-r--r--examples/asmsum.py57
-rw-r--r--examples/conwaylife.py46
-rw-r--r--examples/embedding/Makefile8
-rw-r--r--examples/embedding/Makefile.upylib199
-rw-r--r--examples/embedding/README.md67
-rw-r--r--examples/embedding/hello-embed.c74
l---------examples/embedding/mpconfigport.h1
-rw-r--r--examples/embedding/mpconfigport_minimal.h134
-rw-r--r--examples/hwapi/README.md126
-rw-r--r--examples/hwapi/button_led.py9
-rw-r--r--examples/hwapi/button_reaction.py19
-rw-r--r--examples/hwapi/hwconfig_console.py19
-rw-r--r--examples/hwapi/hwconfig_dragonboard410c.py22
-rw-r--r--examples/hwapi/hwconfig_esp8266_esp12.py5
-rw-r--r--examples/hwapi/hwconfig_pyboard.py13
-rw-r--r--examples/hwapi/hwconfig_z_96b_carbon.py9
-rw-r--r--examples/hwapi/hwconfig_z_frdm_k64f.py5
-rw-r--r--examples/hwapi/soft_pwm.py38
-rw-r--r--examples/hwapi/soft_pwm2_uasyncio.py31
-rw-r--r--examples/hwapi/soft_pwm_uasyncio.py28
-rw-r--r--examples/ledangle.py25
-rw-r--r--examples/mandel.py27
-rw-r--r--examples/micropython.py8
-rw-r--r--examples/network/http_client.py30
-rw-r--r--examples/network/http_client_ssl.py38
-rw-r--r--examples/network/http_server.py64
-rw-r--r--examples/network/http_server_simplistic.py40
-rw-r--r--examples/network/http_server_simplistic_commented.py76
-rw-r--r--examples/network/http_server_ssl.py64
-rw-r--r--examples/pins.py58
-rw-r--r--examples/pyb.py49
-rw-r--r--examples/switch.py45
-rw-r--r--examples/unix/ffi_example.py38
-rw-r--r--examples/unix/machine_bios.py9
41 files changed, 0 insertions, 1681 deletions
diff --git a/examples/SDdatalogger/README.md b/examples/SDdatalogger/README.md
deleted file mode 100644
index 24e69c87e..000000000
--- a/examples/SDdatalogger/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-This is a SDdatalogger, to log data from the accelerometer to the SD-card. It also functions as card reader, so you can easily get the data on your PC.
-
-To run, put the boot.py, cardreader.py and datalogger.py files on either the flash or the SD-card of your pyboard.
-Upon reset, the datalogger script is run and logs the data. If you press the user button after reset and hold it until the orange LED goes out, you enter the cardreader mode and the filesystem is mounted to your PC.
diff --git a/examples/SDdatalogger/boot.py b/examples/SDdatalogger/boot.py
deleted file mode 100644
index 4ac94bbaa..000000000
--- a/examples/SDdatalogger/boot.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# boot.py -- runs on boot-up
-# Let's you choose which script to run.
-# > To run 'datalogger.py':
-# * press reset and do nothing else
-# > To run 'cardreader.py':
-# * press reset
-# * press user switch and hold until orange LED goes out
-
-import pyb
-
-pyb.LED(3).on() # indicate we are waiting for switch press
-pyb.delay(2000) # wait for user to maybe press the switch
-switch_value = pyb.Switch()() # sample the switch at end of delay
-pyb.LED(3).off() # indicate that we finished waiting for the switch
-
-pyb.LED(4).on() # indicate that we are selecting the mode
-
-if switch_value:
- pyb.usb_mode('VCP+MSC')
- pyb.main('cardreader.py') # if switch was pressed, run this
-else:
- pyb.usb_mode('VCP+HID')
- pyb.main('datalogger.py') # if switch wasn't pressed, run this
-
-pyb.LED(4).off() # indicate that we finished selecting the mode
diff --git a/examples/SDdatalogger/cardreader.py b/examples/SDdatalogger/cardreader.py
deleted file mode 100644
index 98d7a3792..000000000
--- a/examples/SDdatalogger/cardreader.py
+++ /dev/null
@@ -1,2 +0,0 @@
-# cardread.py
-# This is called when the user enters cardreader mode. It does nothing.
diff --git a/examples/SDdatalogger/datalogger.py b/examples/SDdatalogger/datalogger.py
deleted file mode 100644
index 0690c20bb..000000000
--- a/examples/SDdatalogger/datalogger.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# datalogger.py
-# Logs the data from the acceleromter to a file on the SD-card
-
-import pyb
-
-# creating objects
-accel = pyb.Accel()
-blue = pyb.LED(4)
-switch = pyb.Switch()
-
-# loop
-while True:
-
- # wait for interrupt
- # this reduces power consumption while waiting for switch press
- pyb.wfi()
-
- # start if switch is pressed
- if switch():
- pyb.delay(200) # delay avoids detection of multiple presses
- blue.on() # blue LED indicates file open
- log = open('/sd/log.csv', 'w') # open file on SD (SD: '/sd/', flash: '/flash/)
-
- # until switch is pressed again
- while not switch():
- t = pyb.millis() # get time
- x, y, z = accel.filtered_xyz() # get acceleration data
- log.write('{},{},{},{}\n'.format(t,x,y,z)) # write data to file
-
- # end after switch is pressed again
- log.close() # close file
- blue.off() # blue LED indicates file closed
- pyb.delay(200) # delay avoids detection of multiple presses
diff --git a/examples/accel_i2c.py b/examples/accel_i2c.py
deleted file mode 100644
index d635e3ccc..000000000
--- a/examples/accel_i2c.py
+++ /dev/null
@@ -1,34 +0,0 @@
-# This is an example on how to access accelerometer on
-# PyBoard directly using I2C bus. As such, it's more
-# intended to be an I2C example, rather than accelerometer
-# example. For the latter, using pyb.Accel class is
-# much easier.
-
-from machine import Pin
-from machine import I2C
-import time
-
-# Accelerometer needs to be powered on first. Even
-# though signal is called "AVDD", and there's separate
-# "DVDD", without AVDD, it won't event talk on I2C bus.
-accel_pwr = Pin("MMA_AVDD")
-accel_pwr.value(1)
-
-i2c = I2C(1, baudrate=100000)
-addrs = i2c.scan()
-print("Scanning devices:", [hex(x) for x in addrs])
-if 0x4c not in addrs:
- print("Accelerometer is not detected")
-
-ACCEL_ADDR = 0x4c
-ACCEL_AXIS_X_REG = 0
-ACCEL_MODE_REG = 7
-
-# Now activate measurements
-i2c.mem_write(b"\x01", ACCEL_ADDR, ACCEL_MODE_REG)
-
-print("Try to move accelerometer and watch the values")
-while True:
- val = i2c.mem_read(1, ACCEL_ADDR, ACCEL_AXIS_X_REG)
- print(val[0])
- time.sleep(1)
diff --git a/examples/accellog.py b/examples/accellog.py
deleted file mode 100644
index b1f289f8a..000000000
--- a/examples/accellog.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# log the accelerometer values to a .csv-file on the SD-card
-
-import pyb
-
-accel = pyb.Accel() # create object of accelerometer
-blue = pyb.LED(4) # create object of blue LED
-
-log = open('/sd/log.csv', 'w') # open file to write data - /sd/ is the SD-card, /flash/ the internal memory
-blue.on() # turn on blue LED
-
-for i in range(100): # do 100 times (if the board is connected via USB, you can't write longer because the PC tries to open the filesystem which messes up your file.)
- t = pyb.millis() # get time since reset
- x, y, z = accel.filtered_xyz() # get acceleration data
- log.write('{},{},{},{}\n'.format(t,x,y,z)) # write data to file
-
-log.close() # close file
-blue.off() # turn off LED
diff --git a/examples/asmled.py b/examples/asmled.py
deleted file mode 100644
index 917d9ba03..000000000
--- a/examples/asmled.py
+++ /dev/null
@@ -1,85 +0,0 @@
-# flash LED #1 using inline assembler
-# this version is overly verbose and uses word stores
-@micropython.asm_thumb
-def flash_led(r0):
- movw(r1, (stm.GPIOA + stm.GPIO_BSRRL) & 0xffff)
- movt(r1, ((stm.GPIOA + stm.GPIO_BSRRL) >> 16) & 0x7fff)
- movw(r2, 1 << 13)
- movt(r2, 0)
- movw(r3, 0)
- movt(r3, 1 << 13)
-
- b(loop_entry)
-
- label(loop1)
-
- # turn LED on
- str(r2, [r1, 0])
-
- # delay for a bit
- movw(r4, 5599900 & 0xffff)
- movt(r4, (5599900 >> 16) & 0xffff)
- label(delay_on)
- sub(r4, r4, 1)
- cmp(r4, 0)
- bgt(delay_on)
-
- # turn LED off
- str(r3, [r1, 0])
-
- # delay for a bit
- movw(r4, 5599900 & 0xffff)
- movt(r4, (5599900 >> 16) & 0xffff)
- label(delay_off)
- sub(r4, r4, 1)
- cmp(r4, 0)
- bgt(delay_off)
-
- # loop r0 times
- sub(r0, r0, 1)
- label(loop_entry)
- cmp(r0, 0)
- bgt(loop1)
-
-# flash LED #2 using inline assembler
-# this version uses half-word sortes, and the convenience assembler operation 'movwt'
-@micropython.asm_thumb
-def flash_led_v2(r0):
- # get the GPIOA address in r1
- movwt(r1, stm.GPIOA)
-
- # get the bit mask for PA14 (the pin LED #2 is on)
- movw(r2, 1 << 14)
-
- b(loop_entry)
-
- label(loop1)
-
- # turn LED on
- strh(r2, [r1, stm.GPIO_BSRRL])
-
- # delay for a bit
- movwt(r4, 5599900)
- label(delay_on)
- sub(r4, r4, 1)
- cmp(r4, 0)
- bgt(delay_on)
-
- # turn LED off
- strh(r2, [r1, stm.GPIO_BSRRH])
-
- # delay for a bit
- movwt(r4, 5599900)
- label(delay_off)
- sub(r4, r4, 1)
- cmp(r4, 0)
- bgt(delay_off)
-
- # loop r0 times
- sub(r0, r0, 1)
- label(loop_entry)
- cmp(r0, 0)
- bgt(loop1)
-
-flash_led(5)
-flash_led_v2(5)
diff --git a/examples/asmsum.py b/examples/asmsum.py
deleted file mode 100644
index 07e71c738..000000000
--- a/examples/asmsum.py
+++ /dev/null
@@ -1,57 +0,0 @@
-@micropython.asm_thumb
-def asm_sum_words(r0, r1):
-
- # r0 = len
- # r1 = ptr
- # r2 = sum
- # r3 = dummy
- mov(r2, 0)
-
- b(loop_entry)
-
- label(loop1)
- ldr(r3, [r1, 0])
- add(r2, r2, r3)
-
- add(r1, r1, 4)
- sub(r0, r0, 1)
-
- label(loop_entry)
- cmp(r0, 0)
- bgt(loop1)
-
- mov(r0, r2)
-
-@micropython.asm_thumb
-def asm_sum_bytes(r0, r1):
-
- # r0 = len
- # r1 = ptr
- # r2 = sum
- # r3 = dummy
- mov(r2, 0)
-
- b(loop_entry)
-
- label(loop1)
- ldrb(r3, [r1, 0])
- add(r2, r2, r3)
-
- add(r1, r1, 1)
- sub(r0, r0, 1)
-
- label(loop_entry)
- cmp(r0, 0)
- bgt(loop1)
-
- mov(r0, r2)
-
-import array
-
-b = array.array('l', (100, 200, 300, 400))
-n = asm_sum_words(len(b), b)
-print(b, n)
-
-b = array.array('b', (10, 20, 30, 40, 50, 60, 70, 80))
-n = asm_sum_bytes(len(b), b)
-print(b, n)
diff --git a/examples/conwaylife.py b/examples/conwaylife.py
deleted file mode 100644
index 323f42e85..000000000
--- a/examples/conwaylife.py
+++ /dev/null
@@ -1,46 +0,0 @@
-#import essential libraries
-import pyb
-
-lcd = pyb.LCD('x')
-lcd.light(1)
-
-# do 1 iteration of Conway's Game of Life
-def conway_step():
- for x in range(128): # loop over x coordinates
- for y in range(32): # loop over y coordinates
- # count number of neighbours
- num_neighbours = (lcd.get(x - 1, y - 1) +
- lcd.get(x, y - 1) +
- lcd.get(x + 1, y - 1) +
- lcd.get(x - 1, y) +
- lcd.get(x + 1, y) +
- lcd.get(x + 1, y + 1) +
- lcd.get(x, y + 1) +
- lcd.get(x - 1, y + 1))
-
- # check if the centre cell is alive or not
- self = lcd.get(x, y)
-
- # apply the rules of life
- if self and not (2 <= num_neighbours <= 3):
- lcd.pixel(x, y, 0) # not enough, or too many neighbours: cell dies
- elif not self and num_neighbours == 3:
- lcd.pixel(x, y, 1) # exactly 3 neighbours around an empty cell: cell is born
-
-# randomise the start
-def conway_rand():
- lcd.fill(0) # clear the LCD
- for x in range(128): # loop over x coordinates
- for y in range(32): # loop over y coordinates
- lcd.pixel(x, y, pyb.rng() & 1) # set the pixel randomly
-
-# loop for a certain number of frames, doing iterations of Conway's Game of Life
-def conway_go(num_frames):
- for i in range(num_frames):
- conway_step() # do 1 iteration
- lcd.show() # update the LCD
- pyb.delay(50)
-
-# testing
-conway_rand()
-conway_go(100)
diff --git a/examples/embedding/Makefile b/examples/embedding/Makefile
deleted file mode 100644
index 99f239a7c..000000000
--- a/examples/embedding/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
-MPTOP = ../..
-CFLAGS = -std=c99 -I. -I$(MPTOP) -DNO_QSTR
-LDFLAGS = -L.
-
-hello-embed: hello-embed.o -lmicropython
-
--lmicropython:
- $(MAKE) -f $(MPTOP)/examples/embedding/Makefile.upylib MPTOP=$(MPTOP)
diff --git a/examples/embedding/Makefile.upylib b/examples/embedding/Makefile.upylib
deleted file mode 100644
index a9b653517..000000000
--- a/examples/embedding/Makefile.upylib
+++ /dev/null
@@ -1,199 +0,0 @@
-MPTOP = ../..
--include mpconfigport.mk
-include $(MPTOP)/py/mkenv.mk
-
-all: lib
-
-# OS name, for simple autoconfig
-UNAME_S := $(shell uname -s)
-
-# include py core make definitions
-include $(MPTOP)/py/py.mk
-
-INC += -I.
-INC += -I..
-INC += -I$(MPTOP)
-INC += -I$(MPTOP)/unix
-INC += -I$(BUILD)
-
-# compiler settings
-CWARN = -Wall -Werror
-CWARN += -Wpointer-arith -Wuninitialized
-CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
-
-# Debugging/Optimization
-ifdef DEBUG
-CFLAGS += -g
-COPT = -O0
-else
-COPT = -Os #-DNDEBUG
-# _FORTIFY_SOURCE is a feature in gcc/glibc which is intended to provide extra
-# security for detecting buffer overflows. Some distros (Ubuntu at the very least)
-# have it enabled by default.
-#
-# gcc already optimizes some printf calls to call puts and/or putchar. When
-# _FORTIFY_SOURCE is enabled and compiling with -O1 or greater, then some
-# printf calls will also be optimized to call __printf_chk (in glibc). Any
-# printfs which get redirected to __printf_chk are then no longer synchronized
-# with printfs that go through mp_printf.
-#
-# In MicroPython, we don't want to use the runtime library's printf but rather
-# go through mp_printf, so that stdout is properly tied into streams, etc.
-# This means that we either need to turn off _FORTIFY_SOURCE or provide our
-# own implementation of __printf_chk. We've chosen to turn off _FORTIFY_SOURCE.
-# It should also be noted that the use of printf in MicroPython is typically
-# quite limited anyways (primarily for debug and some error reporting, etc
-# in the unix version).
-#
-# Information about _FORTIFY_SOURCE seems to be rather scarce. The best I could
-# find was this: https://securityblog.redhat.com/2014/03/26/fortify-and-you/
-# Original patchset was introduced by
-# https://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html .
-#
-# Turning off _FORTIFY_SOURCE is only required when compiling with -O1 or greater
-CFLAGS += -U _FORTIFY_SOURCE
-endif
-
-# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
-# The unix port of MicroPython on OSX must be compiled with clang,
-# while cross-compile ports require gcc, so we test here for OSX and
-# if necessary override the value of 'CC' set in py/mkenv.mk
-ifeq ($(UNAME_S),Darwin)
-CC = clang
-# Use clang syntax for map file
-LDFLAGS_ARCH = -Wl,-map,$@.map
-else
-# Use gcc syntax for map file
-LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref
-endif
-LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
-
-ifeq ($(MICROPY_FORCE_32BIT),1)
-# Note: you may need to install i386 versions of dependency packages,
-# starting with linux-libc-dev:i386
-ifeq ($(MICROPY_PY_FFI),1)
-ifeq ($(UNAME_S),Linux)
-CFLAGS_MOD += -I/usr/include/i686-linux-gnu
-endif
-endif
-endif
-
-ifeq ($(MICROPY_USE_READLINE),1)
-INC += -I../lib/mp-readline
-CFLAGS_MOD += -DMICROPY_USE_READLINE=1
-LIB_SRC_C_EXTRA += mp-readline/readline.c
-endif
-ifeq ($(MICROPY_USE_READLINE),2)
-CFLAGS_MOD += -DMICROPY_USE_READLINE=2
-LDFLAGS_MOD += -lreadline
-# the following is needed for BSD
-#LDFLAGS_MOD += -ltermcap
-endif
-ifeq ($(MICROPY_PY_TIME),1)
-CFLAGS_MOD += -DMICROPY_PY_TIME=1
-SRC_MOD += modtime.c
-endif
-ifeq ($(MICROPY_PY_TERMIOS),1)
-CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1
-SRC_MOD += modtermios.c
-endif
-ifeq ($(MICROPY_PY_SOCKET),1)
-CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
-SRC_MOD += modsocket.c
-endif
-
-ifeq ($(MICROPY_PY_FFI),1)
-
-ifeq ($(MICROPY_STANDALONE),1)
-LIBFFI_CFLAGS_MOD := -I$(shell ls -1d ../lib/libffi/build_dir/out/lib/libffi-*/include)
- ifeq ($(MICROPY_FORCE_32BIT),1)
- LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib32/libffi.a
- else
- LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib/libffi.a
- endif
-else
-LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
-LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
-endif
-
-ifeq ($(UNAME_S),Linux)
-LIBFFI_LDFLAGS_MOD += -ldl
-endif
-
-CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
-LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
-SRC_MOD += modffi.c
-endif
-
-MAIN_C = main.c
-
-# source files
-SRC_C = $(addprefix $(MPTOP)/unix/,\
- $(MAIN_C) \
- gccollect.c \
- unix_mphal.c \
- input.c \
- file.c \
- modmachine.c \
- modos.c \
- moduselect.c \
- alloc.c \
- coverage.c \
- fatfs_port.c \
- $(SRC_MOD) \
- )
-
-LIB_SRC_C = $(addprefix lib/,\
- $(LIB_SRC_C_EXTRA) \
- utils/printf.c \
- timeutils/timeutils.c \
- )
-
-ifeq ($(MICROPY_FATFS),1)
-LIB_SRC_C += $(addprefix lib/,\
- fatfs/ff.c \
- fatfs/option/ccsbcs.c \
- )
-endif
-
-OBJ = $(PY_O)
-OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
-OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
-OBJ += $(addprefix $(BUILD)/, $(STMHAL_SRC_C:.c=.o))
-
-# List of sources for qstr extraction
-SRC_QSTR += $(SRC_C) $(LIB_SRC_C)
-# Append any auto-generated sources that are needed by sources listed in
-# SRC_QSTR
-SRC_QSTR_AUTO_DEPS +=
-
-include $(MPTOP)/py/mkrules.mk
-
-# Value of configure's --host= option (required for cross-compilation).
-# Deduce it from CROSS_COMPILE by default, but can be overridden.
-ifneq ($(CROSS_COMPILE),)
-CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE))
-else
-CROSS_COMPILE_HOST =
-endif
-
-deplibs: libffi axtls
-
-# install-exec-recursive & install-data-am targets are used to avoid building
-# docs and depending on makeinfo
-libffi:
- cd ../lib/libffi; git clean -d -x -f
- cd ../lib/libffi; ./autogen.sh
- mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
- ../configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out CC="$(CC)" CXX="$(CXX)" LD="$(LD)"; \
- make install-exec-recursive; make -C include install-data-am
-
-axtls: ../lib/axtls/README
- cd ../lib/axtls; cp config/upyconfig config/.config
- cd ../lib/axtls; make oldconfig -B
- cd ../lib/axtls; make clean
- cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)"
-
-../lib/axtls/README:
- @echo "You cloned without --recursive, fetching submodules for you."
- (cd ..; git submodule update --init --recursive)
diff --git a/examples/embedding/README.md b/examples/embedding/README.md
deleted file mode 100644
index 804dfede6..000000000
--- a/examples/embedding/README.md
+++ /dev/null
@@ -1,67 +0,0 @@
-Example of embedding MicroPython in a standlone C application
-=============================================================
-
-This directory contains a (very simple!) example of how to embed a MicroPython
-in an existing C application.
-
-A C application is represented by the file hello-embed.c. It executes a simple
-Python statement which prints to the standard output.
-
-
-Building the example
---------------------
-
-Building the example is as simple as running:
-
- make
-
-It's worth to trace what's happening behind the scenes though:
-
-1. As a first step, a MicroPython library is built. This is handled by a
-separate makefile, Makefile.upylib. It is more or less complex, but the
-good news is that you won't need to change anything in it, just use it
-as is, the main Makefile shows how. What may require editing though is
-a MicroPython configuration file. MicroPython is highly configurable, so
-you would need to build a library suiting your application well, while
-not bloating its size. Check the options in the file "mpconfigport.h".
-Included is a copy of the "minimal" Unix port, which should be a good start
-for minimal embedding. For the list of all available options, see
-py/mpconfig.h.
-
-2. Once the MicroPython library is built, your application is compiled
-and linked it. The main Makefile is very simple and shows that the changes
-you would need to do to your application's Makefile (or other build
-configuration) are also simple:
-
-a) You would need to use C99 standard (you're using this 15+ years old
-standard already, not a 25+ years old one, right?).
-
-b) You need to provide a path to MicroPython's top-level dir, for includes.
-
-c) You need to include -DNO_QSTR compile-time flag.
-
-d) Otherwise, just link with the MicroPython library produced in step 1.
-
-
-Out of tree build
------------------
-
-This example is set up to work out of the box, being part of the MicroPython
-tree. Your application of course will be outside of its tree, but the
-only thing you need to do is to pass MPTOP variable pointing to
-MicroPython directory to both Makefiles (in this example, the main Makefile
-automatically passes it to Makefile.upylib; in your own Makefile, don't forget
-to use a suitable value).
-
-A practical way to embed MicroPython in your application is to include it
-as a git submodule. Suppose you included it as libs/micropython. Then in
-your main Makefile you would have something like:
-
-~~~
-MPTOP = libs/micropython
-
-my_app: $(MY_OBJS) -lmicropython
-
--lmicropython:
- $(MAKE) -f $(MPTOP)/examples/embedding/Makefile.upylib MPTOP=$(MPTOP)
-~~~
diff --git a/examples/embedding/hello-embed.c b/examples/embedding/hello-embed.c
deleted file mode 100644
index 3473e5bcd..000000000
--- a/examples/embedding/hello-embed.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2016 Paul Sokolovsky
- *
- * 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 <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "py/compile.h"
-#include "py/runtime.h"
-#include "py/gc.h"
-#include "py/stackctrl.h"
-
-static char heap[16384];
-
-mp_obj_t execute_from_str(const char *str) {
- nlr_buf_t nlr;
- if (nlr_push(&nlr) == 0) {
- mp_lexer_t *lex = mp_lexer_new_from_str_len(0/*MP_QSTR_*/, str, strlen(str), false);
- mp_parse_tree_t pt = mp_parse(lex, MP_PARSE_FILE_INPUT);
- mp_obj_t module_fun = mp_compile(&pt, lex->source_name, MP_EMIT_OPT_NONE, false);
- mp_call_function_0(module_fun);
- nlr_pop();
- return 0;
- } else {
- // uncaught exception
- return (mp_obj_t)nlr.ret_val;
- }
-}
-
-int main() {
- // Initialized stack limit
- mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4));
- // Initialize heap
- gc_init(heap, heap + sizeof(heap));
- // Initialize interpreter
- mp_init();
-
- const char str[] = "print('Hello world of easy embedding!')";
- if (execute_from_str(str)) {
- printf("Error\n");
- }
-}
-
-uint mp_import_stat(const char *path) {
- return MP_IMPORT_STAT_NO_EXIST;
-}
-
-void nlr_jump_fail(void *val) {
- printf("FATAL: uncaught NLR %p\n", val);
- exit(1);
-}
diff --git a/examples/embedding/mpconfigport.h b/examples/embedding/mpconfigport.h
deleted file mode 120000
index 142e5d6f4..000000000
--- a/examples/embedding/mpconfigport.h
+++ /dev/null
@@ -1 +0,0 @@
-mpconfigport_minimal.h \ No newline at end of file
diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h
deleted file mode 100644
index fa52be4ad..000000000
--- a/examples/embedding/mpconfigport_minimal.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2015 Damien P. George
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-// options to control how MicroPython is built
-
-#define MICROPY_ALLOC_PATH_MAX (PATH_MAX)
-#define MICROPY_ENABLE_GC (1)
-#define MICROPY_ENABLE_FINALISER (0)
-#define MICROPY_STACK_CHECK (0)
-#define MICROPY_COMP_CONST (0)
-#define MICROPY_MEM_STATS (0)
-#define MICROPY_DEBUG_PRINTERS (0)
-#define MICROPY_READER_POSIX (1)
-#define MICROPY_KBD_EXCEPTION (1)
-#define MICROPY_HELPER_REPL (1)
-#define MICROPY_HELPER_LEXER_UNIX (1)
-#define MICROPY_ENABLE_SOURCE_LINE (0)
-#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
-#define MICROPY_WARNINGS (0)
-#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (0)
-#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_NONE)
-#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_NONE)
-#define MICROPY_STREAMS_NON_BLOCK (0)
-#define MICROPY_OPT_COMPUTED_GOTO (0)
-#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
-#define MICROPY_CAN_OVERRIDE_BUILTINS (0)
-#define MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG (0)
-#define MICROPY_CPYTHON_COMPAT (0)
-#define MICROPY_PY_BUILTINS_BYTEARRAY (0)
-#define MICROPY_PY_BUILTINS_MEMORYVIEW (0)
-#define MICROPY_PY_BUILTINS_COMPILE (0)
-#define MICROPY_PY_BUILTINS_ENUMERATE (0)
-#define MICROPY_PY_BUILTINS_FILTER (0)
-#define MICROPY_PY_BUILTINS_FROZENSET (0)
-#define MICROPY_PY_BUILTINS_REVERSED (0)
-#define MICROPY_PY_BUILTINS_SET (0)
-#define MICROPY_PY_BUILTINS_SLICE (0)
-#define MICROPY_PY_BUILTINS_STR_UNICODE (0)
-#define MICROPY_PY_BUILTINS_PROPERTY (0)
-#define MICROPY_PY_BUILTINS_MIN_MAX (0)
-#define MICROPY_PY___FILE__ (0)
-#define MICROPY_PY_MICROPYTHON_MEM_INFO (0)
-#define MICROPY_PY_GC (0)
-#define MICROPY_PY_GC_COLLECT_RETVAL (0)
-#define MICROPY_PY_ARRAY (0)
-#define MICROPY_PY_COLLECTIONS (0)
-#define MICROPY_PY_MATH (0)
-#define MICROPY_PY_CMATH (0)
-#define MICROPY_PY_IO (0)
-#define MICROPY_PY_IO_FILEIO (0)
-#define MICROPY_PY_STRUCT (0)
-#define MICROPY_PY_SYS (1)
-#define MICROPY_PY_SYS_EXIT (0)
-#define MICROPY_PY_SYS_PLATFORM "linux"
-#define MICROPY_PY_SYS_MAXSIZE (0)
-#define MICROPY_PY_SYS_STDFILES (0)
-#define MICROPY_PY_CMATH (0)
-#define MICROPY_PY_UCTYPES (0)
-#define MICROPY_PY_UZLIB (0)
-#define MICROPY_PY_UJSON (0)
-#define MICROPY_PY_URE (0)
-#define MICROPY_PY_UHEAPQ (0)
-#define MICROPY_PY_UHASHLIB (0)
-#define MICROPY_PY_UBINASCII (0)
-
-extern const struct _mp_obj_module_t mp_module_os;
-
-#define MICROPY_PORT_BUILTIN_MODULES \
- { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_os) }, \
-
-#define MICROPY_PORT_ROOT_POINTERS \
-
-//////////////////////////////////////////
-// Do not change anything beyond this line
-//////////////////////////////////////////
-
-// Define to 1 to use undertested inefficient GC helper implementation
-// (if more efficient arch-specific one is not available).
-#ifndef MICROPY_GCREGS_SETJMP
- #ifdef __mips__
- #define MICROPY_GCREGS_SETJMP (1)
- #else
- #define MICROPY_GCREGS_SETJMP (0)
- #endif
-#endif
-
-// type definitions for the specific machine
-
-#ifdef __LP64__
-typedef long mp_int_t; // must be pointer size
-typedef unsigned long mp_uint_t; // must be pointer size
-#else
-// These are definitions for machines where sizeof(int) == sizeof(void*),
-// regardless for actual size.
-typedef int mp_int_t; // must be pointer size
-typedef unsigned int mp_uint_t; // must be pointer size
-#endif
-
-// Cannot include <sys/types.h>, as it may lead to symbol name clashes
-#if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
-typedef long long mp_off_t;
-#else
-typedef long mp_off_t;
-#endif
-
-// We need to provide a declaration/definition of alloca()
-#ifdef __FreeBSD__
-#include <stdlib.h>
-#else
-#include <alloca.h>
-#endif
diff --git a/examples/hwapi/README.md b/examples/hwapi/README.md
deleted file mode 100644
index 1992eb660..000000000
--- a/examples/hwapi/README.md
+++ /dev/null
@@ -1,126 +0,0 @@
-This directory shows the best practices for using MicroPython hardware API
-(`machine` module). `machine` module strives to provide consistent API
-across various boards, with the aim to enable writing portable applications,
-which would work from a board to board, from a system to another systems.
-This is inherently a hard problem, because hardware is different from one
-board type to another, and even from examplar of board to another. For
-example, if your app requires an external LED, one user may connect it
-to one GPIO pin, while another user may find it much more convinient to
-use another pin. This of course applies to relays, buzzers, sensors, etc.
-
-With complications above in mind, it's still possible to write portable
-applications by using "low[est] denominator" subset of hardware API and
-following simple rules outlined below. The applications won't be able
-to rely on advanced hardware capabilities of a particular board and
-will be limited to generic capabilities, but it's still possible to
-write many useful applications in such a way, with the obvious benefit of
-"write once - run everywhere" approach (only configuration for a particular
-board is required).
-
-The key to this approach is splitting your application into (at least)
-2 parts:
-
-* main application logic
-* hardware configuration
-
-The key point is that hardware configuration should be a separate file
-(module in Python terms). A good name would be `hwconfig.py`, and that's
-how we'll call it from now on. Another key point is that main application
-should never instantiate (construct) hardware objects directly. Instead,
-they should be defined in `hwconfig.py`, and main application should
-import and reference hardware objects via this module. The simplest
-application of this idea would look like:
-
-`hwconfig.py`:
-
- from machine import Pin
-
- LED = Pin("A3", Pin.OUT)
-
-`app.py`:
-
- from hwconfig import *
- import utime
-
- while True:
- LED.value(1)
- utime.sleep_ms(500)
- LED.value(0)
- utime.sleep_ms(500)
-
-
-To deploy this application to a particular board, a user will need:
-
-1. Edit `hwconfig.py` to adjust Pin and other hardware peripheral
- parameters and locations.
-2. Actually deploy `hwconfig.py` and `app.py` to a board (e.g. copy to
- board's filesystem, or build new firmware with these modules frozen
- into it).
-
-Note that there's no need to edit the main application code! (Which may
-be complex, while `hwconfig.py` should usually remain short enough, and
-focused solely on hardware configuration).
-
-An obvious improvement to this approach is the following. There're few
-well-known boards which run MicroPython, and most of them include an
-onboard LED. So, to help users of these boards to do configuration
-quickly (that's especially important for novice users, for who may
-be stumped by the need to reach out to a board reference to find LED
-pin assignments), `hwconfig.py` your application ships may include
-commented out sections with working configurations for different
-boards. The step 1 above then will be:
-
-1. Look thru `hwconfig.py` to find a section which either exactly
- matches your board, or the closest to it. Uncomment, and if any
- adjustments required, apply them.
-
-It's important to keep in mind that adjustments may be always required,
-and that there may be users whose configuration doesn't match any of
-the available. So, always include a section or instructions for them.
-Consider for example that even on a supported board, user may want to
-blink not an on-board LED, but the one they connected externally.
-MicroPython's Hardware API offers portability not just among "supported"
-boards, but to any board at all, so make sure users can enjoy it.
-
-There's next step of improvement to make. While having one `hwconfig.py`
-with many sections would work for smaller projects with few hardware
-objects, it may become more cumbersome to maintain both on programmer's
-and user's sides for larger projects. Then instead of single
-`hwconfig.py` file, you can provide few "template" ones for well-known
-boards:
-
-* `hwconfig_pyboard.py`
-* `hwconfig_wipy.py`
-* `hwconfig_esp8266.py`
-* etc.
-
-Then step 1 above will be:
-
-1. Look thru available `hwconfig_*.py` files and find one which matches
- your board the best, then rename to `hwconfig.py` and make adjustments,
- if any.
-
-Again, please keep in mind that there may be users whose hardware will be
-completely unlike you heard of. Give them some helpful hints too, perhaps
-provide `hwconfig_custom.py` with some instructions.
-
-That's where we stop with improvements to the "separate file for hardware
-configuration" idea, as it is already pretty flexible and viable. An
-application in this directory shows it in practice, using slightly less
-trivial example than just a blinking LED: `soft_pwm.py` implements a
-software PWM (pulse width modulation) to produce an LED fade-in/fade-out
-effect - without any dependence on hardware PWM availability.
-
-Note that improvements to board configuration handling may continue further.
-For example, one may invent a "configuration manager" helper module which will
-try to detect current board (among well-known ones), and load appropriate
-`hwconfig_*.py` - this assumes that a user would lazily deploy them all
-(or that application will be automatically installed, e.g. using MicroPython's
-`upip` package manager). The key point in this case remains the same as
-elaborated above - always assume there can, and will be a custom configuration,
-and it should be well supported. So, any automatic detection should be
-overridable by a user, and instructions how to do so are among the most
-important you may provide for your application.
-
-By following these best practices, you will use MicroPython at its full
-potential, and let users enjoy it too. Good luck!
diff --git a/examples/hwapi/button_led.py b/examples/hwapi/button_led.py
deleted file mode 100644
index bd6fe0172..000000000
--- a/examples/hwapi/button_led.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import utime
-from hwconfig import LED, BUTTON
-
-# Light LED when (and while) a BUTTON is pressed
-
-while 1:
- LED.value(BUTTON.value())
- # Don't burn CPU
- utime.sleep_ms(10)
diff --git a/examples/hwapi/button_reaction.py b/examples/hwapi/button_reaction.py
deleted file mode 100644
index b72e813e4..000000000
--- a/examples/hwapi/button_reaction.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import utime
-import machine
-from hwconfig import LED, BUTTON
-
-# machine.time_pulse_us() function demo
-
-print("""\
-Let's play an interesting game:
-You click button as fast as you can, and I tell you how slow you are.
-Ready? Cliiiiick!
-""")
-
-while 1:
- delay = machine.time_pulse_us(BUTTON, 1, 10*1000*1000)
- if delay < 0:
- print("Well, you're *really* slow")
- else:
- print("You are as slow as %d microseconds!" % delay)
- utime.sleep_ms(10)
diff --git a/examples/hwapi/hwconfig_console.py b/examples/hwapi/hwconfig_console.py
deleted file mode 100644
index bbcc0e816..000000000
--- a/examples/hwapi/hwconfig_console.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# This is hwconfig for "emulation" for cases when there's no real hardware.
-# It just prints information to console.
-class LEDClass:
-
- def __init__(self, id):
- self.id = "LED(%d):" % id
-
- def value(self, v):
- print(self.id, v)
-
- def on(self):
- self.value(1)
-
- def off(self):
- self.value(0)
-
-
-LED = LEDClass(1)
-LED2 = LEDClass(12)
diff --git a/examples/hwapi/hwconfig_dragonboard410c.py b/examples/hwapi/hwconfig_dragonboard410c.py
deleted file mode 100644
index eec358203..000000000
--- a/examples/hwapi/hwconfig_dragonboard410c.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from machine import Pin, Signal
-
-# 96Boards/Qualcomm DragonBoard 410c
-#
-# By default, on-board LEDs are controlled by kernel LED driver.
-# To make corresponding pins be available as normal GPIO,
-# corresponding driver needs to be unbound first (as root):
-# echo -n "soc:leds" >/sys/class/leds/apq8016-sbc:green:user1/device/driver/unbind
-# Note that application also either should be run as root, or
-# /sys/class/gpio ownership needs to be changed.
-# Likewise, onboard buttons are controlled by gpio_keys driver.
-# To release corresponding GPIOs:
-# echo -n "gpio_keys" >/sys/class/input/input1/device/driver/unbind
-
-# User LED 1 on gpio21
-LED = Signal(Pin(21, Pin.OUT))
-
-# User LED 2 on gpio120
-LED2 = Signal(Pin(120, Pin.OUT))
-
-# Button S3 on gpio107
-BUTTON = Pin(107, Pin.IN)
diff --git a/examples/hwapi/hwconfig_esp8266_esp12.py b/examples/hwapi/hwconfig_esp8266_esp12.py
deleted file mode 100644
index 2e855ee3d..000000000
--- a/examples/hwapi/hwconfig_esp8266_esp12.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from machine import Pin, Signal
-
-# ESP12 module as used by many boards
-# Blue LED on pin 2, active low (inverted)
-LED = Signal(2, Pin.OUT, invert=True)
diff --git a/examples/hwapi/hwconfig_pyboard.py b/examples/hwapi/hwconfig_pyboard.py
deleted file mode 100644
index fb260033e..000000000
--- a/examples/hwapi/hwconfig_pyboard.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from machine import Pin, Signal
-
-# Red LED on pin LED_RED also kown as A13
-LED = Signal('LED_RED', Pin.OUT)
-
-# Green LED on pin LED_GREEN also known as A14
-LED2 = Signal('LED_GREEN', Pin.OUT)
-
-# Yellow LED on pin LED_YELLOW also known as A15
-LED3 = Signal('LED_YELLOW', Pin.OUT)
-
-# Blue LED on pin LED_BLUE also known as B4
-LED4 = Signal('LED_BLUE', Pin.OUT)
diff --git a/examples/hwapi/hwconfig_z_96b_carbon.py b/examples/hwapi/hwconfig_z_96b_carbon.py
deleted file mode 100644
index 97fd57a07..000000000
--- a/examples/hwapi/hwconfig_z_96b_carbon.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from machine import Signal
-
-# 96Boards Carbon board
-# USR1 - User controlled led, connected to PD2
-# USR2 - User controlled led, connected to PA15
-# BT - Bluetooth indicator, connected to PB5.
-# Note - 96b_carbon uses (at the time of writing) non-standard
-# for Zephyr port device naming convention.
-LED = Signal(("GPIOA", 15), Pin.OUT)
diff --git a/examples/hwapi/hwconfig_z_frdm_k64f.py b/examples/hwapi/hwconfig_z_frdm_k64f.py
deleted file mode 100644
index 377c63878..000000000
--- a/examples/hwapi/hwconfig_z_frdm_k64f.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from machine import Pin, Signal
-
-# Freescale/NXP FRDM-K64F board
-# Blue LED on port B, pin 21
-LED = Signal(("GPIO_1", 21), Pin.OUT)
diff --git a/examples/hwapi/soft_pwm.py b/examples/hwapi/soft_pwm.py
deleted file mode 100644
index 72291b0ec..000000000
--- a/examples/hwapi/soft_pwm.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import utime
-from hwconfig import LED
-
-
-# Using sleep_ms() gives pretty poor PWM resolution and
-# brightness control, but we use it in the attempt to
-# make this demo portable to even more boards (e.g. to
-# those which don't provide sleep_us(), or provide, but
-# it's not precise, like would be on non realtime OSes).
-# We otherwise use 20ms period, to make frequency not less
-# than 50Hz to avoid visible flickering (you may still see
-# if you're unlucky).
-def pwm_cycle(led, duty, cycles):
- duty_off = 20 - duty
- for i in range(cycles):
- if duty:
- led.on()
- utime.sleep_ms(duty)
- if duty_off:
- led.off()
- utime.sleep_ms(duty_off)
-
-
-# At the duty setting of 1, an LED is still pretty bright, then
-# at duty 0, it's off. This makes rather unsmooth transition, and
-# breaks fade effect. So, we avoid value of 0 and oscillate between
-# 1 and 20. Actually, highest values like 19 and 20 are also
-# barely distinguishible (like, both of them too bright and burn
-# your eye). So, improvement to the visible effect would be to use
-# more steps (at least 10x), and then higher frequency, and use
-# range which includes 1 but excludes values at the top.
-while True:
- # Fade in
- for i in range(1, 21):
- pwm_cycle(LED, i, 2)
- # Fade out
- for i in range(20, 0, -1):
- pwm_cycle(LED, i, 2)
diff --git a/examples/hwapi/soft_pwm2_uasyncio.py b/examples/hwapi/soft_pwm2_uasyncio.py
deleted file mode 100644
index 908ef2d8a..000000000
--- a/examples/hwapi/soft_pwm2_uasyncio.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# Like soft_pwm_uasyncio.py, but fading 2 LEDs with different phase.
-# Also see original soft_pwm.py.
-import uasyncio
-from hwconfig import LED, LED2
-
-
-async def pwm_cycle(led, duty, cycles):
- duty_off = 20 - duty
- for i in range(cycles):
- if duty:
- led.value(1)
- await uasyncio.sleep_ms(duty)
- if duty_off:
- led.value(0)
- await uasyncio.sleep_ms(duty_off)
-
-
-async def fade_in_out(LED):
- while True:
- # Fade in
- for i in range(1, 21):
- await pwm_cycle(LED, i, 2)
- # Fade out
- for i in range(20, 0, -1):
- await pwm_cycle(LED, i, 2)
-
-
-loop = uasyncio.get_event_loop()
-loop.create_task(fade_in_out(LED))
-loop.call_later_ms(800, fade_in_out(LED2))
-loop.run_forever()
diff --git a/examples/hwapi/soft_pwm_uasyncio.py b/examples/hwapi/soft_pwm_uasyncio.py
deleted file mode 100644
index 8d7ad8c9e..000000000
--- a/examples/hwapi/soft_pwm_uasyncio.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# See original soft_pwm.py for detailed comments.
-import uasyncio
-from hwconfig import LED
-
-
-async def pwm_cycle(led, duty, cycles):
- duty_off = 20 - duty
- for i in range(cycles):
- if duty:
- led.value(1)
- await uasyncio.sleep_ms(duty)
- if duty_off:
- led.value(0)
- await uasyncio.sleep_ms(duty_off)
-
-
-async def fade_in_out(LED):
- while True:
- # Fade in
- for i in range(1, 21):
- await pwm_cycle(LED, i, 2)
- # Fade out
- for i in range(20, 0, -1):
- await pwm_cycle(LED, i, 2)
-
-
-loop = uasyncio.get_event_loop()
-loop.run_until_complete(fade_in_out(LED))
diff --git a/examples/ledangle.py b/examples/ledangle.py
deleted file mode 100644
index 8c8d9e99d..000000000
--- a/examples/ledangle.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import pyb
-
-def led_angle(seconds_to_run_for):
- # make LED objects
- l1 = pyb.LED(1)
- l2 = pyb.LED(2)
- accel = pyb.Accel()
-
- for i in range(20 * seconds_to_run_for):
- # get x-axis
- x = accel.x()
-
- # turn on LEDs depending on angle
- if x < -10:
- l1.on()
- l2.off()
- elif x > 10:
- l1.off()
- l2.on()
- else:
- l1.off()
- l2.off()
-
- # delay so that loop runs at at 1/50ms = 20Hz
- pyb.delay(50)
diff --git a/examples/mandel.py b/examples/mandel.py
deleted file mode 100644
index bbb808647..000000000
--- a/examples/mandel.py
+++ /dev/null
@@ -1,27 +0,0 @@
-try:
- import micropython
-except:
- pass
-
-def mandelbrot():
- # returns True if c, complex, is in the Mandelbrot set
- #@micropython.native
- def in_set(c):
- z = 0
- for i in range(40):
- z = z*z + c
- if abs(z) > 60:
- return False
- return True
-
- lcd.clear()
- for u in range(91):
- for v in range(31):
- if in_set((u / 30 - 2) + (v / 15 - 1) * 1j):
- lcd.set(u, v)
- lcd.show()
-
-# PC testing
-import lcd
-lcd = lcd.LCD(128, 32)
-mandelbrot()
diff --git a/examples/micropython.py b/examples/micropython.py
deleted file mode 100644
index f91da94f4..000000000
--- a/examples/micropython.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# micropython module placeholder for CPython
-
-# Dummy function decorators
-
-def nodecor(x):
- return x
-
-bytecode = native = viper = nodecor
diff --git a/examples/network/http_client.py b/examples/network/http_client.py
deleted file mode 100644
index 0791c8066..000000000
--- a/examples/network/http_client.py
+++ /dev/null
@@ -1,30 +0,0 @@
-try:
- import usocket as socket
-except:
- import socket
-
-
-def main(use_stream=False):
- s = socket.socket()
-
- ai = socket.getaddrinfo("google.com", 80)
- print("Address infos:", ai)
- addr = ai[0][-1]
-
- print("Connect address:", addr)
- s.connect(addr)
-
- if use_stream:
- # MicroPython socket objects support stream (aka file) interface
- # directly, but the line below is needed for CPython.
- s = s.makefile("rwb", 0)
- s.write(b"GET / HTTP/1.0\r\n\r\n")
- print(s.read())
- else:
- s.send(b"GET / HTTP/1.0\r\n\r\n")
- print(s.recv(4096))
-
- s.close()
-
-
-main()
diff --git a/examples/network/http_client_ssl.py b/examples/network/http_client_ssl.py
deleted file mode 100644
index 83f685fdf..000000000
--- a/examples/network/http_client_ssl.py
+++ /dev/null
@@ -1,38 +0,0 @@
-try:
- import usocket as _socket
-except:
- import _socket
-try:
- import ussl as ssl
-except:
- import ssl
-
-
-def main(use_stream=True):
- s = _socket.socket()
-
- ai = _socket.getaddrinfo("google.com", 443)
- print("Address infos:", ai)
- addr = ai[0][-1]
-
- print("Connect address:", addr)
- s.connect(addr)
-
- s = ssl.wrap_socket(s)
- print(s)
-
- if use_stream:
- # Both CPython and MicroPython SSLSocket objects support read() and
- # write() methods.
- s.write(b"GET / HTTP/1.0\r\n\r\n")
- print(s.read(4096))
- else:
- # MicroPython SSLSocket objects implement only stream interface, not
- # socket interface
- s.send(b"GET / HTTP/1.0\r\n\r\n")
- print(s.recv(4096))
-
- s.close()
-
-
-main()
diff --git a/examples/network/http_server.py b/examples/network/http_server.py
deleted file mode 100644
index e3a66e828..000000000
--- a/examples/network/http_server.py
+++ /dev/null
@@ -1,64 +0,0 @@
-try:
- import usocket as socket
-except:
- import socket
-
-
-CONTENT = b"""\
-HTTP/1.0 200 OK
-
-Hello #%d from MicroPython!
-"""
-
-def main(micropython_optimize=False):
- s = socket.socket()
-
- # Binding to all interfaces - server will be accessible to other hosts!
- ai = socket.getaddrinfo("0.0.0.0", 8080)
- print("Bind address info:", ai)
- addr = ai[0][-1]
-
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- s.bind(addr)
- s.listen(5)
- print("Listening, connect your browser to http://<this_host>:8080/")
-
- counter = 0
- while True:
- res = s.accept()
- client_sock = res[0]
- client_addr = res[1]
- print("Client address:", client_addr)
- print("Client socket:", client_sock)
-
- if not micropython_optimize:
- # To read line-oriented protocol (like HTTP) from a socket (and
- # avoid short read problem), it must be wrapped in a stream (aka
- # file-like) object. That's how you do it in CPython:
- client_stream = client_sock.makefile("rwb")
- else:
- # .. but MicroPython socket objects support stream interface
- # directly, so calling .makefile() method is not required. If
- # you develop application which will run only on MicroPython,
- # especially on a resource-constrained embedded device, you
- # may take this shortcut to save resources.
- client_stream = client_sock
-
- print("Request:")
- req = client_stream.readline()
- print(req)
- while True:
- h = client_stream.readline()
- if h == b"" or h == b"\r\n":
- break
- print(h)
- client_stream.write(CONTENT % counter)
-
- client_stream.close()
- if not micropython_optimize:
- client_sock.close()
- counter += 1
- print()
-
-
-main()
diff --git a/examples/network/http_server_simplistic.py b/examples/network/http_server_simplistic.py
deleted file mode 100644
index 67ecb1ad7..000000000
--- a/examples/network/http_server_simplistic.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# Do not use this code in real projects! Read
-# http_server_simplistic_commented.py for details.
-try:
- import usocket as socket
-except:
- import socket
-
-
-CONTENT = b"""\
-HTTP/1.0 200 OK
-
-Hello #%d from MicroPython!
-"""
-
-def main():
- s = socket.socket()
- ai = socket.getaddrinfo("0.0.0.0", 8080)
- addr = ai[0][-1]
-
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-
- s.bind(addr)
- s.listen(5)
- print("Listening, connect your browser to http://<this_host>:8080/")
-
- counter = 0
- while True:
- res = s.accept()
- client_s = res[0]
- client_addr = res[1]
- req = client_s.recv(4096)
- print("Request:")
- print(req)
- client_s.send(CONTENT % counter)
- client_s.close()
- counter += 1
- print()
-
-
-main()
diff --git a/examples/network/http_server_simplistic_commented.py b/examples/network/http_server_simplistic_commented.py
deleted file mode 100644
index b58e9eeb6..000000000
--- a/examples/network/http_server_simplistic_commented.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# MicroPython http_server_simplistic.py example
-#
-# This example shows how to write the smallest possible HTTP
-# server in MicroPython. With comments and convenience code
-# removed, this example can be compressed literally to ten
-# lines. There's a catch though - read comments below for
-# details, and use this code only for quick hacks, preferring
-# http_server.py for "real thing".
-#
-try:
- import usocket as socket
-except:
- import socket
-
-
-CONTENT = b"""\
-HTTP/1.0 200 OK
-
-Hello #%d from MicroPython!
-"""
-
-def main():
- s = socket.socket()
-
- # Bind to (allow to be connected on ) all interfaces. This means
- # this server will be accessible to other hosts on your local
- # network, and if your server has direct (non-firewalled) connection
- # to the Internet, then to anyone on the Internet. We bind to all
- # interfaces to let this example work easily on embedded MicroPython
- # targets, which you will likely access from another machine on your
- # local network. Take care when running this on an Internet-connected
- # machine though! Replace "0.0.0.0" with "127.0.0.1" if in doubt, to
- # make the server accessible only on the machine it runs on.
- ai = socket.getaddrinfo("0.0.0.0", 8080)
- print("Bind address info:", ai)
- addr = ai[0][-1]
-
- # A port on which a socket listened remains inactive during some time.
- # This means that if you run this sample, terminate it, and run again
- # you will likely get an error. To avoid this timeout, set SO_REUSEADDR
- # socket option.
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-
- s.bind(addr)
- s.listen(5)
- print("Listening, connect your browser to http://<this_host>:8080/")
-
- counter = 0
- while True:
- res = s.accept()
- client_s = res[0]
- client_addr = res[1]
- print("Client address:", client_addr)
- print("Client socket:", client_s)
- # We assume here that .recv() call will read entire HTTP request
- # from client. This is usually true, at least on "big OS" systems
- # like Linux/MacOS/Windows. But that doesn't have to be true in
- # all cases, in particular on embedded systems, when there can
- # easily be "short recv", where it returns much less than requested
- # data size. That's why this example is called "simplistic" - it
- # shows that writing a web server in Python that *usually works* is
- # ten lines of code, and you can use this technique for quick hacks
- # and experimentation. But don't do it like that in production
- # applications - instead, parse HTTP request properly, as shown
- # by http_server.py example.
- req = client_s.recv(4096)
- print("Request:")
- print(req)
- client_s.send(CONTENT % counter)
- client_s.close()
- counter += 1
- print()
-
-
-main()
diff --git a/examples/network/http_server_ssl.py b/examples/network/http_server_ssl.py
deleted file mode 100644
index 9a69ca9d4..000000000
--- a/examples/network/http_server_ssl.py
+++ /dev/null
@@ -1,64 +0,0 @@
-try:
- import usocket as socket
-except:
- import socket
-import ussl as ssl
-
-
-CONTENT = b"""\
-HTTP/1.0 200 OK
-
-Hello #%d from MicroPython!
-"""
-
-def main(use_stream=True):
- s = socket.socket()
-
- # Binding to all interfaces - server will be accessible to other hosts!
- ai = socket.getaddrinfo("0.0.0.0", 8443)
- print("Bind address info:", ai)
- addr = ai[0][-1]
-
- s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- s.bind(addr)
- s.listen(5)
- print("Listening, connect your browser to https://<this_host>:8443/")
-
- counter = 0
- while True:
- res = s.accept()
- client_s = res[0]
- client_addr = res[1]
- print("Client address:", client_addr)
- print("Client socket:", client_s)
- client_s = ssl.wrap_socket(client_s, server_side=True)
- print(client_s)
- print("Request:")
- if use_stream:
- # Both CPython and MicroPython SSLSocket objects support read() and
- # write() methods.
- # Browsers are prone to terminate SSL connection abruptly if they
- # see unknown certificate, etc. We must continue in such case -
- # next request they issue will likely be more well-behaving and
- # will succeed.
- try:
- req = client_s.readline()
- print(req)
- while True:
- h = client_s.readline()
- if h == b"" or h == b"\r\n":
- break
- print(h)
- if req:
- client_s.write(CONTENT % counter)
- except Exception as e:
- print("Exception serving request:", e)
- else:
- print(client_s.recv(4096))
- client_s.send(CONTENT % counter)
- client_s.close()
- counter += 1
- print()
-
-
-main()
diff --git a/examples/pins.py b/examples/pins.py
deleted file mode 100644
index aafdb4813..000000000
--- a/examples/pins.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Print a nice list of pins, their current settings, and available afs.
-# Requires pins_af.py from ports/stm32/build-PYBV10/ directory.
-
-import pyb
-import pins_af
-
-def af():
- max_name_width = 0
- max_af_width = 0
- for pin_entry in pins_af.PINS_AF:
- max_name_width = max(max_name_width, len(pin_entry[0]))
- for af_entry in pin_entry[1:]:
- max_af_width = max(max_af_width, len(af_entry[1]))
- for pin_entry in pins_af.PINS_AF:
- pin_name = pin_entry[0]
- print('%-*s ' % (max_name_width, pin_name), end='')
- for af_entry in pin_entry[1:]:
- print('%2d: %-*s ' % (af_entry[0], max_af_width, af_entry[1]), end='')
- print('')
-
-def pins():
- mode_str = { pyb.Pin.IN : 'IN',
- pyb.Pin.OUT_PP : 'OUT_PP',
- pyb.Pin.OUT_OD : 'OUT_OD',
- pyb.Pin.AF_PP : 'AF_PP',
- pyb.Pin.AF_OD : 'AF_OD',
- pyb.Pin.ANALOG : 'ANALOG' }
- pull_str = { pyb.Pin.PULL_NONE : '',
- pyb.Pin.PULL_UP : 'PULL_UP',
- pyb.Pin.PULL_DOWN : 'PULL_DOWN' }
- width = [0, 0, 0, 0]
- rows = []
- for pin_entry in pins_af.PINS_AF:
- row = []
- pin_name = pin_entry[0]
- pin = pyb.Pin(pin_name)
- pin_mode = pin.mode()
- row.append(pin_name)
- row.append(mode_str[pin_mode])
- row.append(pull_str[pin.pull()])
- if pin_mode == pyb.Pin.AF_PP or pin_mode == pyb.Pin.AF_OD:
- pin_af = pin.af()
- for af_entry in pin_entry[1:]:
- if pin_af == af_entry[0]:
- af_str = '%d: %s' % (pin_af, af_entry[1])
- break
- else:
- af_str = '%d' % pin_af
- else:
- af_str = ''
- row.append(af_str)
- for col in range(len(width)):
- width[col] = max(width[col], len(row[col]))
- rows.append(row)
- for row in rows:
- for col in range(len(width)):
- print('%-*s ' % (width[col], row[col]), end='')
- print('')
diff --git a/examples/pyb.py b/examples/pyb.py
deleted file mode 100644
index b303777e5..000000000
--- a/examples/pyb.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# pyboard testing functions for CPython
-import time
-
-def delay(n):
- #time.sleep(float(n) / 1000)
- pass
-
-rand_seed = 1
-def rng():
- global rand_seed
- # for these choice of numbers, see P L'Ecuyer, "Tables of linear congruential generators of different sizes and good lattice structure"
- rand_seed = (rand_seed * 653276) % 8388593
- return rand_seed
-
-# LCD testing object for PC
-# uses double buffering
-class LCD:
- def __init__(self, port):
- self.width = 128
- self.height = 32
- self.buf1 = [[0 for x in range(self.width)] for y in range(self.height)]
- self.buf2 = [[0 for x in range(self.width)] for y in range(self.height)]
-
- def light(self, value):
- pass
-
- def fill(self, value):
- for y in range(self.height):
- for x in range(self.width):
- self.buf1[y][x] = self.buf2[y][x] = value
-
- def show(self):
- print('') # blank line to separate frames
- for y in range(self.height):
- for x in range(self.width):
- self.buf1[y][x] = self.buf2[y][x]
- for y in range(self.height):
- row = ''.join(['*' if self.buf1[y][x] else ' ' for x in range(self.width)])
- print(row)
-
- def get(self, x, y):
- if 0 <= x < self.width and 0 <= y < self.height:
- return self.buf1[y][x]
- else:
- return 0
-
- def pixel(self, x, y, value):
- if 0 <= x < self.width and 0 <= y < self.height:
- self.buf2[y][x] = value
diff --git a/examples/switch.py b/examples/switch.py
deleted file mode 100644
index 0efaf2267..000000000
--- a/examples/switch.py
+++ /dev/null
@@ -1,45 +0,0 @@
-"""
-switch.py
-=========
-
-Light up some leds when the USR switch on the pyboard is pressed.
-
-Example Usage::
-
- Micro Python v1.0.1 on 2014-05-12; PYBv1.0 with STM32F405RG
- Type "help()" for more information.
- >>> import switch
- >>> switch.run_loop()
- Loop started.
- Press Ctrl+C to break out of the loop.
-
-"""
-
-import pyb
-
-switch = pyb.Switch()
-red_led = pyb.LED(1)
-green_led = pyb.LED(2)
-orange_led = pyb.LED(3)
-blue_led = pyb.LED(4)
-all_leds = (red_led, green_led, orange_led, blue_led)
-
-def run_loop(leds=all_leds):
- """
- Start the loop.
-
- :param `leds`: Which LEDs to light up upon switch press.
- :type `leds`: sequence of LED objects
- """
- print('Loop started.\nPress Ctrl+C to break out of the loop.')
- while 1:
- try:
- if switch():
- [led.on() for led in leds]
- else:
- [led.off() for led in leds]
- except OSError: # VCPInterrupt # Ctrl+C in interpreter mode.
- break
-
-if __name__ == '__main__':
- run_loop()
diff --git a/examples/unix/ffi_example.py b/examples/unix/ffi_example.py
deleted file mode 100644
index f650e3370..000000000
--- a/examples/unix/ffi_example.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import ffi
-
-libc = ffi.open("libc.so.6")
-print("libc:", libc)
-print()
-
-# Declare few functions
-perror = libc.func("v", "perror", "s")
-time = libc.func("i", "time", "p")
-open = libc.func("i", "open", "si")
-qsort = libc.func("v", "qsort", "piip")
-# And one variable
-errno = libc.var("i", "errno")
-
-print("time:", time)
-print("UNIX time is:", time(None))
-print()
-
-perror("ffi before error")
-open("somethingnonexistent__", 0)
-print("errno object:", errno)
-print("errno value:", errno.get())
-perror("ffi after error")
-print()
-
-def cmp(pa, pb):
- a = ffi.as_bytearray(pa, 1)
- b = ffi.as_bytearray(pb, 1)
- print("cmp:", a, b)
- return a[0] - b[0]
-
-cmp_c = ffi.callback("i", cmp, "pp")
-print("callback:", cmp_c)
-
-s = bytearray(b"foobar")
-print("org string:", s)
-qsort(s, len(s), 1, cmp_c)
-print("qsort'ed string:", s)
diff --git a/examples/unix/machine_bios.py b/examples/unix/machine_bios.py
deleted file mode 100644
index f62e4dbdb..000000000
--- a/examples/unix/machine_bios.py
+++ /dev/null
@@ -1,9 +0,0 @@
-# This example shows how to access Video BIOS memory area via machine.mem
-# It requires root privilege and x86 legacy harfware (which has mentioned
-# Video BIOS at all).
-# It is expected to print 0xaa55, which is a signature at the start of
-# Video BIOS.
-
-import umachine as machine
-
-print(hex(machine.mem16[0xc0000]))