Skip to content

Commit 34b4ecc

Browse files
committed
Merge branch 'master' into f/serial
2 parents ba760ca + 667dfe8 commit 34b4ecc

File tree

7 files changed

+48
-43
lines changed

7 files changed

+48
-43
lines changed

LICENSE

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
The MIT License (MIT)
12

2-
DAP.JS
3-
3+
Copyright (c) Arm Limited 2018
44
Copyright (c) Microsoft Corporation
55

6-
All rights reserved.�
7-
8-
MIT License
9-
10-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
1112

12-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
1315

14-
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,3 @@ await this.target.reset();
8989
API documentation can be viewed at:
9090

9191
https://armmbed.github.io/dapjs/docs/
92-
93-
## Code of Conduct
94-
95-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

src/dap/utils.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/targets/FlashProgram.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as MemoryMap from "nrf-intel-hex";
2-
import {Utils} from "../dap/utils";
2+
import {isBufferBinary} from "../util";
33

44
export class FlashSection {
55
constructor(public address: number, public data: Uint32Array) {
@@ -40,7 +40,7 @@ export class FlashProgram {
4040
constructor(public sections: FlashSection[]) {}
4141

4242
public static fromArrayBuffer(buffer: ArrayBuffer): FlashProgram {
43-
if (Utils.isBufferBinary(buffer)) {
43+
if (isBufferBinary(buffer)) {
4444
return FlashProgram.fromBinary(0, new Uint32Array(buffer));
4545
}
4646
const bufferString = Buffer.from(buffer).toString("utf8");

src/transport/hid.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export class HID {
2525
private epIn: USBEndpoint;
2626
private epOut: USBEndpoint;
2727
private useControlTransfer: boolean;
28+
private packetSize = 64;
29+
private controlTransferGetReport = 0x01;
30+
private controlTransferSetReport = 0x09;
31+
private controlTransferOutReport = 0x200;
32+
private controlTransferInReport = 0x100;
2833

2934
constructor(device: USBDevice) {
3035
this.device = device;
@@ -72,15 +77,14 @@ export class HID {
7277
return this.device.transferOut(this.epOut.endpointNumber, buffer);
7378
} else {
7479
// Device does not have out endpoint. Send data using control transfer
75-
const buffer = bufferExtend(data, 64);
76-
const interfaceNumber = this.interface.interfaceNumber;
80+
const buffer = bufferExtend(data, this.packetSize);
7781
return this.device.controlTransferOut(
7882
{
7983
requestType: "class",
8084
recipient: "interface",
81-
request: 0x09,
82-
value: 0x200,
83-
index: interfaceNumber
85+
request: this.controlTransferSetReport,
86+
value: this.controlTransferOutReport,
87+
index: this.interface.interfaceNumber
8488
},
8589
buffer
8690
);
@@ -93,16 +97,15 @@ export class HID {
9397
return this.device.transferIn(this.epIn.endpointNumber, reportSize)
9498
.then(res => res.data);
9599
} else {
96-
const interfaceNumber = this.interface.interfaceNumber;
97100
return this.device.controlTransferIn(
98101
{
99102
requestType: "class",
100103
recipient: "interface",
101-
request: 0x01,
102-
value: 0x100,
103-
index: interfaceNumber
104+
request: this.controlTransferGetReport,
105+
value: this.controlTransferInReport,
106+
index: this.interface.interfaceNumber
104107
},
105-
64
108+
this.packetSize
106109
).then(res => res.data);
107110
}
108111
}

src/util.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,18 @@ export const hexBytes = (bytes: number[]) => {
113113

114114
return r.toUpperCase();
115115
};
116+
117+
export const isBufferBinary = (buffer: ArrayBuffer): boolean => {
118+
// detect if buffer contains text or binary data
119+
const lengthToCheck = buffer.byteLength > 50 ? 50 : buffer.byteLength;
120+
const bufferString = Buffer.from(buffer).toString("utf8");
121+
for (let i = 0; i < lengthToCheck; i++) {
122+
const charCode = bufferString.charCodeAt(i);
123+
// 65533 is a code for unknown character
124+
// 0-8 are codes for control characters
125+
if (charCode === 65533 || charCode <= 8) {
126+
return true;
127+
}
128+
}
129+
return false;
130+
};

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"max-line-length": [false],
1616
"member-ordering": [true, { "order": ["static-field", "instance-field", "constructor", "static-method", "instance-method"] }],
1717
"no-bitwise": false,
18-
"no-console": [false],
18+
"no-console": [true],
1919
"no-empty-interface": false,
2020
"no-floating-promises": true,
2121
"no-trailing-whitespace": [true],

0 commit comments

Comments
 (0)