UNPKG

@microbit/microbit-universal-hex

Version:
108 lines 4.39 kB
/** * The Board ID is used to identify the different targets from a Universal Hex. * In this case the target represents a micro:bit version. * For micro:bit V1 (v1.3, v1.3B and v1.5) the `boardId` is `0x9900`, and for * V2 `0x9903`. */ declare enum microbitBoardId { V1 = 39168, V2 = 39171 } /** * Very simple interface to group an Intel Hex string with a Board ID. * * The Board ID is used in an Universal Hex file to identify the target, in this * case the micro:bit version. */ interface IndividualHex { /** The Intel Hex in string format. */ hex: string; /** * The Board ID identifies the target for the Intel Hex string. * Any number can be used in this field, but to target a micro:bit the * micro:bit firmware will process the data */ boardId: number | microbitBoardId; } /** * Converts an Intel Hex string into a Hex string using the 512 byte blocks * format and the Universal Hex specific record types. * * The output of this function is not a fully formed Universal Hex, but one part * of a Universal Hex, ready to be merged by the calling code. * * More information on this "block" format: * https://github.com/microbit-foundation/spec-universal-hex * * @throws {Error} When the Board ID is not between 0 and 2^16. * @throws {Error} When there is an EoF record not at the end of the file. * * @param iHexStr - Intel Hex string to convert into the custom format with 512 * byte blocks and the customer records. * @returns New Intel Hex string with the custom format. */ declare function iHexToCustomFormatBlocks(iHexStr: string, boardId: number | microbitBoardId): string; /** * Converts an Intel Hex string into a Hex string using custom records and * aligning the content size to a 512-byte boundary. * * The output of this function is not a fully formed Universal Hex, but one part * of a Universal Hex, ready to be merged by the calling code. * * More information on this "section" format: * https://github.com/microbit-foundation/spec-universal-hex * * @throws {Error} When the Board ID is not between 0 and 2^16. * @throws {Error} When there is an EoF record not at the end of the file. * * @param iHexStr - Intel Hex string to convert into the custom format with 512 * byte blocks and the customer records. * @returns New Intel Hex string with the custom format. */ declare function iHexToCustomFormatSection(iHexStr: string, boardId: number | microbitBoardId): string; /** * Creates a Universal Hex from a collection of Intel Hex strings and their * board IDs. * * For the current micro:bit board versions use the values from the * `microbitBoardId` enum. * * @param hexes An array of objects containing an Intel Hex string and the board * ID associated with it. * @param blocks Indicate if the Universal Hex format should be "blocks" * instead of "sections". The current specification recommends using the * default "sections" format as is much quicker in micro:bits with DAPLink * version 0234. * @returns A Universal Hex string. */ declare function createUniversalHex(hexes: IndividualHex[], blocks?: boolean): string; /** * Checks if the provided hex string is a Universal Hex. * * Very simple test only checking for the opening Extended Linear Address and * Block Start records. * * The string is manually iterated as this method can be x20 faster than * breaking the string into records and checking their types with the ihex * functions. * * @param hexStr Hex string to check * @return True if the hex is an Universal Hex. */ declare function isUniversalHex(hexStr: string): boolean; /** * Checks if the Hex string is an Intel Hex file from MakeCode for micro:bit V1. * * @param hexStr Hex string to check * @return True if the hex is an Universal Hex. */ declare function isMakeCodeForV1Hex(hexStr: string): boolean; /** * Separates a Universal Hex into its individual Intel Hexes. * * @param universalHexStr Universal Hex string with the Universal Hex. * @returns An array of object with boardId and hex keys. */ declare function separateUniversalHex(universalHexStr: string): IndividualHex[]; export { microbitBoardId, IndividualHex, iHexToCustomFormatBlocks, iHexToCustomFormatSection, createUniversalHex, separateUniversalHex, isUniversalHex, isMakeCodeForV1Hex, }; //# sourceMappingURL=universal-hex.d.ts.map