forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArduino_Wifi_AVRISP.ino
73 lines (64 loc) · 1.81 KB
/
Arduino_Wifi_AVRISP.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266AVRISP.h>
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif
const char* host = "esp8266-avrisp";
const char* ssid = STASSID;
const char* pass = STAPSK;
const uint16_t port = 328;
const uint8_t reset_pin = 5;
ESP8266AVRISP avrprog(port, reset_pin);
void setup() {
Serial.begin(115200);
Serial.println("");
Serial.println("Arduino AVR-ISP over TCP");
avrprog.setReset(false); // let the AVR run
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.waitForConnectResult() != WL_CONNECTED);
MDNS.begin(host);
MDNS.addService("avrisp", "tcp", port);
IPAddress local_ip = WiFi.localIP();
Serial.print("IP address: ");
Serial.println(local_ip);
Serial.println("Use your avrdude:");
Serial.print("avrdude -c arduino -p <device> -P net:");
Serial.print(local_ip);
Serial.print(":");
Serial.print(port);
Serial.println(" -t # or -U ...");
// listen for avrdudes
avrprog.begin();
}
void loop() {
static AVRISPState_t last_state = AVRISP_STATE_IDLE;
AVRISPState_t new_state = avrprog.update();
if (last_state != new_state) {
switch (new_state) {
case AVRISP_STATE_IDLE: {
Serial.printf("[AVRISP] now idle\r\n");
// Use the SPI bus for other purposes
break;
}
case AVRISP_STATE_PENDING: {
Serial.printf("[AVRISP] connection pending\r\n");
// Clean up your other purposes and prepare for programming mode
break;
}
case AVRISP_STATE_ACTIVE: {
Serial.printf("[AVRISP] programming mode\r\n");
// Stand by for completion
break;
}
}
last_state = new_state;
}
// Serve the client
if (last_state != AVRISP_STATE_IDLE) {
avrprog.serve();
}
}