Skip to content

Commit

Permalink
Merge pull request #34 from roleroz/master
Browse files Browse the repository at this point in the history
Allow Arduino as ISP as programmer
  • Loading branch information
mum4k authored Dec 28, 2022
2 parents 0a76510 + 8e3c54a commit e2b6c86
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 0 deletions.
23 changes: 23 additions & 0 deletions platformio/platformio.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def _emit_ini_file_action(ctx, output_files):
framework=ctx.attr.framework,
environment_kwargs=environment_kwargs,
build_flags=build_flags,
programmer=ctx.attr.programmer,
port=ctx.attr.port,
).to_json()
ctx.actions.run(
outputs=[output_files.platformio_ini],
Expand Down Expand Up @@ -429,6 +431,12 @@ A string, name of the Arduino board to build this project for. You can
find the supported boards in the
[PlatformIO Embedded Boards Explorer](http://platformio.org/boards). This is
mandatory.
""",
),
"port": attr.string(
doc = """
Port where your microcontroller is connected. This field is mandatory if you
are using arduino_as_isp as your programmer.
""",
),
"platform": attr.string(
Expand Down Expand Up @@ -467,6 +475,21 @@ generated platformio.ini file in the build_flags option for the selected
env:board section. Refer to the [Project Configuration File manual](
http://docs.platformio.org/en/latest/projectconf.html) for the available
options.
""",
),
"programmer": attr.string(
default = "direct",
values = [
"arduino_as_isp",
"direct",
],
doc = """
Type of programmer to use:
- direct: Use the USB connection in the microcontroller deveopment board to
program it
- arduino_as_isp: Use an arduino programmed with the Arduino as ISP code to
in-circuit program another microcontroller (see
https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP for details).
""",
),
"deps": attr.label_list(
Expand Down
17 changes: 17 additions & 0 deletions platformio/platformio.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ framework =
{%- for kwarg in environment_kwargs %}
{{environment_kwargs}}
{%- endfor %}
{%- if programmer == "arduino_as_isp" %}
upload_protocol = custom
upload_port = {{ port }}
upload_speed = 19200
upload_flags =
-C
${platformio.packages_dir}/tool-avrdude/avrdude.conf
-p
$BOARD_MCU
-P
$UPLOAD_PORT
-b
$UPLOAD_SPEED
-c
stk500v1
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
{% endif %}
34 changes: 34 additions & 0 deletions tests/blink/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//platformio:platformio.bzl", "platformio_project")

configs = [
{
"name": "attiny85",
"board": "attiny85",
"build_flags": ["-DTARGET_PIN=4"],
"programmer": "arduino_as_isp",
"port": "/dev/ttyUSB0",
},
{
"name": "nano",
"board": "nanoatmega328",
"build_flags": [],
"programmer": "direct",
"port": "unused",
},
]

[platformio_project(
name = "blink_%s" % config["name"],
src = "blink.cc",
board = config["board"],
framework = "arduino",
platform = "atmelavr",
build_flags = config["build_flags"],
programmer = config["programmer"],
port = config["port"],
deps = [
"//tests/arduino:Arduino_impl",
"//tests/arduino:Arduino_interface",
],
) for config in configs]

18 changes: 18 additions & 0 deletions tests/blink/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# A blinking LED

The most classic electronics example, blinking an LED, is an example of an
Arduino project.

This project has no inputs, and only uses one output to blink the LED.

## The circuit

### On Arduino Nano
You don't need to connect anything, the Arduino Nano has an internal LED
connected to the right pin

### On Arduino Mega
![The clinking LED breadboard](doc/blink_attiny_bb.png)

The [Fritzing](http://fritzing.org) circuit is stored in file
[binary_counter.fzz](doc/blink_attiny.fzz).
41 changes: 41 additions & 0 deletions tests/blink/blink.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Blink an LED. The "hello world" of electronics.
//
// By default this will blink an LED connected to pin 13 (standard Arduino)
// with a 1/2 Hz frequency and a 50% duty cycle (1 second on, 1 second off).
//
// You can change the behaviour with the following macros at compile time:
// - TARGET_PIN: The number of the pin where the LED is connected to
// - TIME_HIGH_MS: The number of milliseconds the LED will be on per cycle
// - TIME_LOW_MS: The number of milliseconds the LED will be off per cycle

#include <Arduino.h>
#include <Arduino_impl.h>
#include <Arduino_interface.h>

using arduino::ArduinoImpl;
using arduino::ArduinoInterface;

#ifndef TARGET_PIN
// If target pin is not defined, use the Arduino standard 13
#define TARGET_PIN 13
#endif
#ifndef TIME_HIGH_MS
#define TIME_HIGH_MS 1000
#endif
#ifndef TIME_LOW_MS
#define TIME_LOW_MS 1000
#endif

// Arduino hardware layer.
const ArduinoImpl ino = ArduinoImpl();

void setup() {
pinMode(TARGET_PIN, OUTPUT);
}

void loop () {
ino.DigitalWrite(TARGET_PIN, HIGH);
ino.Delay(TIME_HIGH_MS);
ino.DigitalWrite(TARGET_PIN, LOW);
ino.Delay(TIME_LOW_MS);
}
Binary file added tests/blink/doc/blink_attiny.fzz
Binary file not shown.
Binary file added tests/blink/doc/blink_attiny_bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e2b6c86

Please sign in to comment.