Skip to content

Commit

Permalink
[arduino] Add PDP-11 example sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Oct 21, 2024
1 parent 4ff5d3c commit 1f90a6d
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ EXS = \
mn1610 \
mos6502 \
ns32000 \
pdp11 \
pdp8 \
scn2650 \
tlcs90 \
Expand Down
109 changes: 109 additions & 0 deletions examples/pdp11/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2021 Tadashi G. Takaoka
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

help:
@echo '"make clean" remove unnecessary files'
@echo '"make pio-ci" run PlatformIO CI for a board'
@echo " (default BOARD=$(BOARD))"
@echo '"make pio-ci-all" run PlatformIO CI for all boards'
@echo " ($(BOARDS))"
@echo '"make pio-run" build sketch for an environment'
@echo " (default ENV=$(ENV))"
@echo '"make pio-run-all" build sketch for all environments'
@echo " ($(ENVS))"

ifdef INSIDE_EMACS
ifeq ($(filter $(PIO_FLAGS),"--no-ansi"),)
PIO_FLAGS += --no-ansi
endif
ifeq ($(filter $(ARDUINO_FLAGS),"--no-color"),)
ARDUINO_FLAGS += --no-color
endif
endif

PIO_CI_FLAGS =
ARDUINO_CI_FLAGS = --warnings all --library $(CURDIR)/../../

ENVS = $(shell grep -Po '^\[env:\K[^]]+' platformio.ini)
ENV ?= $(firstword $(ENVS))

BOARDS = $(shell grep -Po '^board *= *\K[\w]+' platformio.ini)
BOARD ?= $(firstword $(BOARDS))

EXAMPLE = $(shell basename $(CURDIR))

define pio-libdep-path # env libdep
-l .pio/libdeps/$(1)/$(2)
endef

define pio-ci # board
ENV=$(shell awk 'BEGIN{RS="\n\n"} /$(1)/' platformio.ini | grep -Po '(?<=env:)[^]]+')
pio $(PIO_FLAGS) pkg install -l libcli
pio $(PIO_FLAGS) ci -l $(CURDIR)/../.. $(call pio-libdep-path,$(ENV),libcli) -b $(1) $(EXAMPLE).ino

endef

pio-ci:
$(call pio-ci,$(BOARD))

pio-ci-all:
$(foreach board,$(BOARDS),$(call pio-ci,$(board)))

boards: platformio.ini
@echo $(BOARDS)

define pio-run # env
pio $(PIO_FLAGS) run $(PIO_RUN_FLAGS) -e $(1)

endef

pio-run:
$(call pio-run,$(ENV))

pio-run-all:
$(foreach env,$(ENVS),$(call pio-run,$(env)))

envs: platformio.ini
@echo $(ENVS)

define arduino-ci # fqbn
arduino-cli $(ARDUINO_FLAGS) compile -b $(1) $(ARDUINO_CI_FLAGS)

endef

FQBNS = \
MightyCore:avr:1284 \
DxCore:megaavr:avrda \
teensy:avr:teensy41
FQBN ?= $(firstword $(FQBNS))

fqbns:
@echo $(FQBNS)

arduino-ci:
$(call arduino-ci,$(FQBN))

arduino-ci-all:
$(foreach fqbn,$(FQBNS),$(call arduino-ci,$(fqbn)))

clean:
rm -rf $$(find . -type d -a -name .pio)

.PHONY: help clean pio-run pio-run-all pio-ci pio-ci-all pio-boards pio-envs \
arduino-ci arduino-ci-all

# Local Variables:
# mode: makefile-gmake
# End:
# vim: set ft=make:
40 changes: 40 additions & 0 deletions examples/pdp11/pdp11.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 Tadashi G. Takaoka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <arduino_example.h>
#include <asm_pdp11.h>
#include <dis_pdp11.h>

libasm::pdp11::AsmPdp11 asmpdp11;
libasm::pdp11::DisPdp11 dispdp11;

libasm::arduino::Example example(asmpdp11, dispdp11);

void setup() {
Serial.begin(9600);
example.begin(Serial);
}

void loop() {
example.loop();
}

// Local Variables:
// mode: c++
// c-basic-offset: 2
// tab-width: 2
// End:
// vim: set ft=cpp et ts=2 sw=2:
33 changes: 33 additions & 0 deletions examples/pdp11/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
src_dir = .
default_envs = atmega1284p, avr128da, teensy41

[env]
lib_deps =
tgtakaoka/[email protected]
tgtakaoka/[email protected]

[env:atmega1284p]
platform = atmelavr
board = ATmega1284P
framework = arduino

[env:avr128da]
platform = atmelmegaavr
board = AVR128DA48
framework = arduino

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino

0 comments on commit 1f90a6d

Please sign in to comment.