-
Notifications
You must be signed in to change notification settings - Fork 0
/
PicProgrammer.cs
124 lines (97 loc) · 2.34 KB
/
PicProgrammer.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.ComponentModel;
using System.Threading;
using BusPirateLibCS;
using BusPirateLibCS.Modes;
namespace BusPiratePICProgrammer
{
public abstract class PicProgrammer
{
protected BusPirate bp;
protected RawWire hw;
bool lvp = false;
public PicProgrammer(SerialPort sp, bool LVP)
{
bp = new BusPirate(sp);
bp.Open();
hw = new RawWire(bp);
hw.EnterMode();
var ActiveOut = true;
hw.ConfigProtocol(activeOutput: ActiveOut, threeWire: false, LSBfirst: true);
hw.ConfigPins(power: true, pullups: !ActiveOut, aux: false, cs: true);
hw.SpeedMode = RawWire.Speed.s400khz;
this.lvp = LVP;
}
bool program = false;
public bool Program
{
set
{
//hw.Power = false;
//hw.CS = false;
BusPirate.Wait(50);
hw.OutputPin = false;
hw.ClockPin = false;
if (lvp)
{
if (value)
{
hw.CS = value;
BusPirate.Wait(10);
hw.AUX = value;
}
else
{
hw.AUX = value;
BusPirate.Wait(10);
hw.CS = value;
}
}
else {
if (value)
{
hw.Power = true;
BusPirate.Wait(10);
}
hw.AUX = value;
if (!value)
{
BusPirate.Wait(10);
hw.Power = false;
BusPirate.Wait(10);
hw.Power = true;
}
}
BusPirate.Wait(50);
//hw.Power = true;
//hw.CS = true;
program = value;
}
get
{
return program;
}
}
public void DelayMs(int time)
{
Thread.Sleep(time);
}
public abstract void bulkErase(bool eraseEEPROM = true);
public abstract void eraseData();
public abstract void writeCode(int address, byte[] data, int offset, int length, ProgressReporter pr = null);
public abstract void writeData(int address, byte[] data, int offset, int length, ProgressReporter pr = null);
public delegate void ProgressReporter(int percentage);
public abstract void writeConfig(int address, byte[] data, int offset, int length, ProgressReporter pr = null);
public abstract void readData(int address, byte[] data, int offset, int length, ProgressReporter pr = null);
public abstract void readCode(int address, byte[] data, int offset, int length, ProgressReporter pr = null);
public void close()
{
hw.ExitMode();
bp.Close();
}
}
}