Skip to content

Commit 0869890

Browse files
fisherdog1hlorenzi
authored andcommitted
add intelhex format argument addr_unit
1 parent 5cc272a commit 0869890

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/driver.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ pub enum OutputFormat
3434
BinDump,
3535
HexDump,
3636
Mif,
37-
IntelHex,
37+
IntelHex {
38+
address_unit: usize,
39+
},
3840
DecComma,
3941
HexComma,
4042
DecSpace,
@@ -567,6 +569,11 @@ pub fn parse_output_format(
567569
[2, 16].contains(&base)
568570
};
569571

572+
let check_8_16_or_32 = &mut |base: usize| -> bool
573+
{
574+
[8, 16, 32].contains(&base)
575+
};
576+
570577
let format = {
571578
match format_id
572579
{
@@ -594,7 +601,9 @@ pub fn parse_output_format(
594601
"hexdump" => OutputFormat::HexDump,
595602

596603
"mif" => OutputFormat::Mif,
597-
"intelhex" => OutputFormat::IntelHex,
604+
"intelhex" => OutputFormat::IntelHex {
605+
address_unit: get_arg_usize("addr_unit", 8, check_8_16_or_32)?,
606+
},
598607

599608
"deccomma" => OutputFormat::DecComma,
600609
"hexcomma" => OutputFormat::HexComma,
@@ -759,7 +768,8 @@ pub fn format_output(
759768
OutputFormat::HexDump => output.format_hexdump(),
760769

761770
OutputFormat::Mif => output.format_mif(),
762-
OutputFormat::IntelHex => output.format_intelhex(),
771+
OutputFormat::IntelHex { address_unit } =>
772+
output.format_intelhex(address_unit),
763773

764774
OutputFormat::DecComma => output.format_separator(10, ", "),
765775
OutputFormat::HexComma => output.format_separator(16, ", "),

src/usage_help.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Examples:
7171
* `hexdump`
7272

7373
* `mif`
74-
* `intelhex`
74+
* `intelhex,addr_unit:8`
7575

7676
* `deccomma`
7777
* `hexcomma`

src/util/bitvec_format.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ impl util::BitVec
205205
result.push_str("END;");
206206
result
207207
}
208-
209-
210-
pub fn format_intelhex(&self) -> String
211-
{
208+
209+
210+
pub fn format_intelhex(&self, address_unit: usize) -> String
211+
{
212212
let mut result = String::new();
213213

214214
let mut bytes_left = self.len() / 8 + if self.len() % 8 != 0 { 1 } else { 0 };
@@ -220,13 +220,13 @@ impl util::BitVec
220220

221221
result.push(':');
222222
result.push_str(&format!("{:02X}", bytes_in_row));
223-
result.push_str(&format!("{:04X}", index / 8));
223+
result.push_str(&format!("{:04X}", index / address_unit));
224224
result.push_str("00");
225225

226226
let mut checksum = 0_u8;
227227
checksum = checksum.wrapping_add(bytes_in_row as u8);
228-
checksum = checksum.wrapping_add(((index / 8) >> 8) as u8);
229-
checksum = checksum.wrapping_add((index / 8) as u8);
228+
checksum = checksum.wrapping_add(((index / address_unit) >> 8) as u8);
229+
checksum = checksum.wrapping_add((index / address_unit) as u8);
230230

231231
for _ in 0..bytes_in_row
232232
{

0 commit comments

Comments
 (0)