Skip to content

Commit a8dfc2e

Browse files
Solved pro mini upload problem
Arduino pro mini have a diferent subname on boards.txt pro.menu.cpu.16MHzatmega32. subname = freqInMHz + normalSubname Fix #7 Signed-off-by: Patrick J.P <[email protected]>
1 parent 95b1686 commit a8dfc2e

File tree

8 files changed

+302
-198
lines changed

8 files changed

+302
-198
lines changed

env/Board.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,25 @@ QString Board::attribute(const QString &attr) const
133133
else
134134
return *it;
135135
}
136+
137+
void Board::setSelectedBoard(QString _name, QString _mcu, QString _freq)
138+
{
139+
name_ = _name;
140+
mcu_ = _mcu;
141+
freq_ = _freq;
142+
}
143+
144+
QString Board::selectedName() const
145+
{
146+
return name_;
147+
}
148+
149+
QString Board::selectedMcu() const
150+
{
151+
return mcu_;
152+
}
153+
154+
QString Board::selectedFreq() const
155+
{
156+
return freq_;
157+
}

env/Board.h

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
This file is part of arduide, The Qt-based IDE for the open-source Arduino electronics prototyping platform.
55
6-
Copyright (C) 2010-2016
6+
Copyright (C) 2010-2016
77
Authors : Denis Martinez
88
Martin Peres
99
@@ -36,78 +36,115 @@ This program is free software; you can redistribute it and/or modify
3636

3737
/**
3838
* @brief A class to help deal with boards.txt
39-
*
39+
*
4040
*/
4141

4242
class Board
4343
{
4444
public:
45-
45+
4646
/**
4747
* @brief Return the name of the board
4848
* e.g: uno.name="Arduino Uno"
49-
*
49+
*
5050
* @return const QString&
5151
*/
5252
const QString& name() const;
5353

54-
54+
5555
/**
5656
* @brief Return all Ids of the boards in boards.txt
57-
*
57+
*
5858
* @return QStringList
5959
*/
6060
static QStringList boardIds();
61-
62-
61+
62+
6363
/**
6464
* @brief Return a pointer to Board class with the board information.
65-
*
65+
*
6666
* @param name The board name. e.g: "uno" (uno.name=Arduino Uno)
6767
* @return const Board*
6868
*/
6969
static const Board *boardInfo(const QString &name);
7070

7171
/**
7272
* @brief Return the path of hardware directory
73-
*
73+
*
7474
* @return QString
7575
*/
7676
QString hardwarePath() const { return mHardwarePath; };
7777

7878
/**
7979
* @brief Return the value of an attribute
80-
*
80+
*
8181
* @param attr attribute name. e.g: "name" (uno.name=Arduino Uno)
8282
* @return QString
8383
*/
8484
QString attribute(const QString &attr) const;
85-
85+
8686
/**
8787
* @brief Stores all board's attribute
88-
*
88+
*
8989
*/
9090
QHash<QString, QString> mAttributes;
91-
91+
9292
/**
9393
* @brief save all boards in mBoards
94-
*
94+
*
9595
*/
9696
static QMap<QString, Board> mBoards;
97-
97+
98+
/**
99+
* @brief Set info about selected board
100+
*
101+
* @param name name of selected board
102+
* @param mcu mcu of selected board
103+
* @param freq freq of selected mcu
104+
* @return void
105+
*/
106+
void setSelectedBoard(QString _name, QString _mcu, QString _freq);
107+
108+
/**
109+
* @brief Return selected board name
110+
*
111+
* @return QString
112+
*/
113+
QString selectedName() const;
114+
115+
/**
116+
* @brief Return selected mcu of the board
117+
*
118+
* @return QString
119+
*/
120+
121+
QString selectedMcu() const;
122+
123+
/**
124+
* @brief Return selected freq of mcu
125+
*
126+
* @return QString
127+
*/
128+
QString selectedFreq() const;
129+
98130
private:
99-
100131
/**
101-
* @brief Function that read boards.txt to identify all compatible boards
102-
*
132+
* @brief Useful info to identify the selected board
133+
*
134+
*/
135+
QString name_,mcu_,freq_;
136+
137+
/**
138+
* @brief Function that read boards.txt to identify all compatible boards
139+
*
103140
* @return void
104141
*/
105142
static void listBoards();
106-
107-
143+
144+
108145
/**
109146
* @brief Check if boards.txt has already been read
110-
*
147+
*
111148
*/
112149
static bool mListed;
113150

env/Builder.cpp

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,41 +50,67 @@ Builder::Builder(QObject *parent)
5050

5151
const Board *Builder::board() const
5252
{
53-
QString name;
54-
QString mcu;
55-
QString freq;
53+
Board::mBoards[name()].setSelectedBoard(name(), mcu(), freq());
5654

57-
name = ideApp->settings()->board().split(",")[0];
55+
if(name()=="" or mcu() =="")
56+
return NULL;
57+
58+
return Board::boardInfo(name());
59+
}
60+
61+
const QString Builder::name() const
62+
{
63+
return ideApp->settings()->board().split(",")[0];
64+
}
5865

66+
const QString Builder::mcu() const
67+
{
5968
if(ideApp->settings()->board().split(",").size()>1)
6069
{
61-
mcu = ideApp->settings()->board().split(",")[1];
62-
Board::mBoards[name].mAttributes["builder.mcu"]= mcu;
63-
64-
if(ideApp->settings()->board().split(",").size()>2)
65-
{
66-
freq = ideApp->settings()->board().split(",")[2];
67-
Board::mBoards[name].mAttributes["builder.f_cpu"]= freq;
68-
}
69-
else
70-
{
71-
freq = Board::mBoards[name].mAttributes["build.f_cpu"];
72-
Board::mBoards[name].mAttributes["builder.f_cpu"]= freq;
73-
}
70+
return ideApp->settings()->board().split(",")[1];
7471
}
7572
else
7673
{
77-
mcu = Board::mBoards[name].mAttributes["build.mcu"];
78-
Board::mBoards[name].mAttributes["builder.mcu"]= mcu;
79-
80-
freq = Board::mBoards[name].mAttributes["build.f_cpu"];
81-
Board::mBoards[name].mAttributes["builder.f_cpu"]= freq;
74+
return Board::mBoards[name()].mAttributes["build.mcu"];
8275
}
76+
}
8377

84-
if(name=="" or mcu =="")
85-
return NULL;
78+
const QString Builder::freq() const
79+
{
80+
if(ideApp->settings()->board().split(",").size()>2)
81+
return ideApp->settings()->board().split(",")[2];
8682

87-
return Board::boardInfo(name);
83+
return Board::mBoards[name()].mAttributes["build.f_cpu"];
84+
}
85+
86+
const QString Builder::uploadSpeed() const
87+
{
88+
// if we have more than one mcu
89+
if(board()->attribute("upload.speed")=="")
90+
{
91+
QString subName = board()->selectedMcu();
92+
if(subName.right(1)=="p")
93+
subName = subName.left(subName.length() -1);
94+
95+
// arduino pro mini use other nomenclature for subName
96+
if(name() == "pro")
97+
{
98+
QString subFreq = freq().left(freq().length()-7)+"MHz";
99+
subName = subFreq + subName;
100+
}
101+
102+
return board()->attribute("menu.cpu."+subName+".upload.speed");
103+
}
104+
else
105+
return board()->attribute("upload.speed");
106+
}
107+
108+
const QString Builder::uploadProtocol() const
109+
{
110+
QString protocol = board()->attribute("upload.protocol");
111+
if (protocol == "stk500")
112+
protocol = "stk500v1";
113+
return protocol;
88114
}
89115

90116
const QString Builder::device() const
@@ -192,7 +218,7 @@ bool Builder::build(const QString &code, bool upload)
192218
return false;
193219
}
194220

195-
emit logImportant(tr("Compiling for %0...").arg(board()->name()));
221+
emit logImportant(tr("Compiling for %0...").arg(name()));
196222
mBuildDir.reset(new QxtTemporaryDir(QDir(QDir::tempPath()).filePath("arduino-build")));
197223
QString buildPath = mBuildDir->path();
198224

@@ -490,28 +516,13 @@ bool Builder::extractHEX(const QString &input, const QString &output)
490516

491517
bool Builder::uploadViaBootloader(const QString &hexFileName)
492518
{
493-
QString protocol = board()->attribute("upload.protocol");
494-
if (protocol == "stk500")
495-
protocol = "stk500v1";
496-
497-
if(board()->attribute("upload.speed")=="")
498-
{
499-
QString name = ideApp->settings()->board().split(",")[0];
500-
501-
QString subName = board()->attribute("builder.mcu");
502-
if(subName.right(1)=="p")
503-
subName = subName.left(subName.length() -1);
504-
QString uploadSpeed = board()->attribute("menu.cpu."+subName+".upload.speed");
505-
Board::mBoards[name].mAttributes["upload.speed"]= uploadSpeed;
506-
}
507-
508519
QStringList command;
509520
command
510521
<< Toolkit::avrdudePath()
511522
<< Toolkit::avrdudeFlags(board())
512-
<< "-c" << protocol
523+
<< "-c" << uploadProtocol()
513524
<< "-P" << device()
514-
<< "-b" << board()->attribute("upload.speed")
525+
<< "-b" << uploadSpeed()
515526
<< "-D"
516527
<< QString("-Uflash:w:%0:i").arg(hexFileName);
517528

0 commit comments

Comments
 (0)