@@ -77,16 +77,18 @@ endfunction
77
77
" Boards and programmer definitions {{{1
78
78
function ! arduino#ReloadBoards () abort
79
79
" First let's search the arduino system install for boards
80
+ " The path looks like /hardware/<package>/<arch>/boards.txt
80
81
let arduino_dir = arduino#GetArduinoDir ()
81
82
let filenames = split (globpath (arduino_dir . ' /hardware' , ' **/boards.txt' ), ' \n' )
82
83
for filename in filenames
83
84
let pieces = split (filename, ' /' )
84
85
let package = pieces[-3 ]
85
86
let arch = pieces[-2 ]
86
- call arduino#AddBoard (package, arch, filename)
87
+ call arduino#AddHardwareDir (package, arch, filename)
87
88
endfor
88
89
89
90
" Now search any packages installed in the home dir
91
+ " The path looks like /packages/<package>/hardware/<arch>/<version>/boards.txt
90
92
let arduino_home_dir = arduino#GetArduinoHomeDir ()
91
93
let packagedirs = split (globpath (arduino_home_dir . ' /packages' , ' *' ), ' \n' )
92
94
for packagedir in packagedirs
@@ -96,25 +98,29 @@ function! arduino#ReloadBoards() abort
96
98
let arch = fnamemodify (archdir, ' :t' )
97
99
let filenames = split (globpath (archdir, ' **/boards.txt' ), ' \n' )
98
100
for filename in filenames
99
- call arduino#AddBoard (package, arch, filename)
101
+ call arduino#AddHardwareDir (package, arch, filename)
100
102
endfor
101
103
endfor
102
104
endfor
103
105
104
106
" Some platforms put the default arduino boards/programmers in /etc/arduino
105
107
if filereadable (' /etc/arduino/boards.txt' )
106
- call arduino#AddBoard (' arduino' , ' avr' , ' /etc/arduino' )
108
+ call arduino#AddHardwareDir (' arduino' , ' avr' , ' /etc/arduino' )
109
+ endif
110
+ if empty (s: hardware_dirs )
111
+ echoerr " Could not find any boards.txt or programmers.txt files. Please set g:arduino_dir and/or g:arduino_home_dir (see help for details)"
107
112
endif
108
113
endfunction
109
114
110
- function ! arduino#AddBoard (package, arch, file ) abort
111
- if a: file = ~? ' \.txt$'
115
+ function ! arduino#AddHardwareDir (package, arch, file ) abort
116
+ " If a boards.txt file was passed in, get the parent dir
117
+ if ! isdirectory (a: file )
112
118
let filepath = fnamemodify (a: file , ' :h' )
113
119
else
114
120
let filepath = a: file
115
121
endif
116
122
if ! isdirectory (filepath)
117
- echoerr ' Could not find hardware directory ' . filepath
123
+ echoerr ' Could not find hardware directory or file ' . a: file
118
124
return
119
125
endif
120
126
let s: hardware_dirs [filepath] = {
@@ -218,8 +224,6 @@ function! arduino#GetBoards() abort
218
224
endfunction
219
225
220
226
function ! arduino#GetBoardOptions (board) abort
221
- let arduino_dir = arduino#GetArduinoDir ()
222
- let arduino_home_dir = arduino#GetArduinoHomeDir ()
223
227
" Board will be in the format package:arch:board
224
228
let [package, arch, boardname] = split (a: board , ' :' )
225
229
@@ -566,9 +570,6 @@ function! arduino#GetArduinoDir() abort
566
570
if s: OS == ' Darwin'
567
571
let arduino_dir = fnamemodify (arduino_dir, ' :h' ) . ' /Java'
568
572
endif
569
- if ! isdirectory (arduino_dir . ' /hardware/arduino/' )
570
- throw " Could not find arduino directory. Please set g:arduino_dir"
571
- endif
572
573
return arduino_dir
573
574
endfunction
574
575
@@ -589,10 +590,15 @@ function! arduino#GetInfo() abort
589
590
if empty (port)
590
591
let port = " none"
591
592
endif
592
- echo " Board: " . g: arduino_board
593
- echo " Programmer: " . g: arduino_programmer
594
- echo " Port: " . port
595
- echo " Baud rate: " . g: arduino_serial_baud
593
+ let dirs = join (keys (s: hardware_dirs ), ' , ' )
594
+ if empty (dirs)
595
+ let dirs = ' None'
596
+ endif
597
+ echo " Board : " . g: arduino_board
598
+ echo " Programmer : " . g: arduino_programmer
599
+ echo " Port : " . port
600
+ echo " Baud rate : " . g: arduino_serial_baud
601
+ echo " Hardware dirs : " . dirs
596
602
echo " Verify command: " . arduino#GetArduinoCommand (" --verify" )
597
603
endfunction
598
604
0 commit comments