Skip to content

Commit 8e3c54a

Browse files
authored
Merge pull request #2 from roleroz/isp
Isp
2 parents 0a76510 + da69aa4 commit 8e3c54a

File tree

7 files changed

+133
-0
lines changed

7 files changed

+133
-0
lines changed

platformio/platformio.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ def _emit_ini_file_action(ctx, output_files):
178178
framework=ctx.attr.framework,
179179
environment_kwargs=environment_kwargs,
180180
build_flags=build_flags,
181+
programmer=ctx.attr.programmer,
182+
port=ctx.attr.port,
181183
).to_json()
182184
ctx.actions.run(
183185
outputs=[output_files.platformio_ini],
@@ -429,6 +431,12 @@ A string, name of the Arduino board to build this project for. You can
429431
find the supported boards in the
430432
[PlatformIO Embedded Boards Explorer](http://platformio.org/boards). This is
431433
mandatory.
434+
""",
435+
),
436+
"port": attr.string(
437+
doc = """
438+
Port where your microcontroller is connected. This field is mandatory if you
439+
are using arduino_as_isp as your programmer.
432440
""",
433441
),
434442
"platform": attr.string(
@@ -467,6 +475,21 @@ generated platformio.ini file in the build_flags option for the selected
467475
env:board section. Refer to the [Project Configuration File manual](
468476
http://docs.platformio.org/en/latest/projectconf.html) for the available
469477
options.
478+
""",
479+
),
480+
"programmer": attr.string(
481+
default = "direct",
482+
values = [
483+
"arduino_as_isp",
484+
"direct",
485+
],
486+
doc = """
487+
Type of programmer to use:
488+
- direct: Use the USB connection in the microcontroller deveopment board to
489+
program it
490+
- arduino_as_isp: Use an arduino programmed with the Arduino as ISP code to
491+
in-circuit program another microcontroller (see
492+
https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP for details).
470493
""",
471494
),
472495
"deps": attr.label_list(

platformio/platformio.ini.tmpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ framework =
2222
{%- for kwarg in environment_kwargs %}
2323
{{environment_kwargs}}
2424
{%- endfor %}
25+
{%- if programmer == "arduino_as_isp" %}
26+
upload_protocol = custom
27+
upload_port = {{ port }}
28+
upload_speed = 19200
29+
upload_flags =
30+
-C
31+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
32+
-p
33+
$BOARD_MCU
34+
-P
35+
$UPLOAD_PORT
36+
-b
37+
$UPLOAD_SPEED
38+
-c
39+
stk500v1
40+
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
41+
{% endif %}

tests/blink/BUILD

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load("//platformio:platformio.bzl", "platformio_project")
2+
3+
configs = [
4+
{
5+
"name": "attiny85",
6+
"board": "attiny85",
7+
"build_flags": ["-DTARGET_PIN=4"],
8+
"programmer": "arduino_as_isp",
9+
"port": "/dev/ttyUSB0",
10+
},
11+
{
12+
"name": "nano",
13+
"board": "nanoatmega328",
14+
"build_flags": [],
15+
"programmer": "direct",
16+
"port": "unused",
17+
},
18+
]
19+
20+
[platformio_project(
21+
name = "blink_%s" % config["name"],
22+
src = "blink.cc",
23+
board = config["board"],
24+
framework = "arduino",
25+
platform = "atmelavr",
26+
build_flags = config["build_flags"],
27+
programmer = config["programmer"],
28+
port = config["port"],
29+
deps = [
30+
"//tests/arduino:Arduino_impl",
31+
"//tests/arduino:Arduino_interface",
32+
],
33+
) for config in configs]
34+

tests/blink/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# A blinking LED
2+
3+
The most classic electronics example, blinking an LED, is an example of an
4+
Arduino project.
5+
6+
This project has no inputs, and only uses one output to blink the LED.
7+
8+
## The circuit
9+
10+
### On Arduino Nano
11+
You don't need to connect anything, the Arduino Nano has an internal LED
12+
connected to the right pin
13+
14+
### On Arduino Mega
15+
![The clinking LED breadboard](doc/blink_attiny_bb.png)
16+
17+
The [Fritzing](http://fritzing.org) circuit is stored in file
18+
[binary_counter.fzz](doc/blink_attiny.fzz).

tests/blink/blink.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Blink an LED. The "hello world" of electronics.
2+
//
3+
// By default this will blink an LED connected to pin 13 (standard Arduino)
4+
// with a 1/2 Hz frequency and a 50% duty cycle (1 second on, 1 second off).
5+
//
6+
// You can change the behaviour with the following macros at compile time:
7+
// - TARGET_PIN: The number of the pin where the LED is connected to
8+
// - TIME_HIGH_MS: The number of milliseconds the LED will be on per cycle
9+
// - TIME_LOW_MS: The number of milliseconds the LED will be off per cycle
10+
11+
#include <Arduino.h>
12+
#include <Arduino_impl.h>
13+
#include <Arduino_interface.h>
14+
15+
using arduino::ArduinoImpl;
16+
using arduino::ArduinoInterface;
17+
18+
#ifndef TARGET_PIN
19+
// If target pin is not defined, use the Arduino standard 13
20+
#define TARGET_PIN 13
21+
#endif
22+
#ifndef TIME_HIGH_MS
23+
#define TIME_HIGH_MS 1000
24+
#endif
25+
#ifndef TIME_LOW_MS
26+
#define TIME_LOW_MS 1000
27+
#endif
28+
29+
// Arduino hardware layer.
30+
const ArduinoImpl ino = ArduinoImpl();
31+
32+
void setup() {
33+
pinMode(TARGET_PIN, OUTPUT);
34+
}
35+
36+
void loop () {
37+
ino.DigitalWrite(TARGET_PIN, HIGH);
38+
ino.Delay(TIME_HIGH_MS);
39+
ino.DigitalWrite(TARGET_PIN, LOW);
40+
ino.Delay(TIME_LOW_MS);
41+
}

tests/blink/doc/blink_attiny.fzz

3.27 KB
Binary file not shown.

tests/blink/doc/blink_attiny_bb.png

278 KB
Loading

0 commit comments

Comments
 (0)