Documentation ¶
Index ¶
- Constants
- Variables
- func AddressCommandFlashAddress(address uint16) []byte
- func AddressCommandFlashPage(page uint16) []byte
- func AddressCommandFlashcartBlock(block uint16) []byte
- func AddressCommandFlashcartPage(page uint16) []byte
- func AddressCommandRaw(address uint16) []byte
- func AlignData(data []byte, alignment int) []byte
- func AlignWidth(width uint, alignment uint) uint
- func BinToHex(data []byte, writer io.Writer) error
- func CreateReadFlashcartBuffer() []byte
- func DeleteEeprom(sercon io.ReadWriter) error
- func EchoSpaceControls(s string) string
- func ExitBootloader(sercon io.ReadWriteCloser) error
- func FillStringArray(strings []string, data []byte) (int, int)
- func FindStringDiff(a string, b string) error
- func FindSuitablePackageImage(archive *zip.ReadCloser) (string, error)
- func FxHeaderStartBytes() []byte
- func Get2ByteValue(data []byte, index int) uint16
- func HexToBin(reader io.Reader) ([]byte, error)
- func ImageToPaletted(img image.Image, whiteThreshold uint8, alphaThreshold uint8) ([]byte, int, int)
- func LoadPackageFile(archive *zip.ReadCloser, filename string) ([]byte, error)
- func MakeFxHeaderAddress(name string, addr int) string
- func MakeFxHeaderField(typ string, name string, value int, hex int) string
- func MakeFxHeaderMainPointer(name string, addr uint, length uint) string
- func MakePadding(length int) []byte
- func MapHeaderResult(result *[]HeaderCategory, header *FxHeader, addr int) (*string, error)
- func Md5String(data []byte) string
- func PalettedToCode(ptiles [][]byte, config *TileConfig, computed *TileConfigComputed) (string, error)
- func PalettedToImage(raw []byte, width int, height int, black color.Color, white color.Color, ...) error
- func PalettedToImageTitleBW(raw []byte, format string) ([]byte, error)
- func PalettedToRaw(paletted []byte, width int, height int) ([]byte, []byte, error)
- func PalettedToRawTitle(raw []byte) ([]byte, error)
- func ParseStringArray(data []byte) []string
- func PatchMenuButtons(program []byte) (bool, string)
- func PatchMicroLED(flashdata []byte)
- func PatchScreen(flashdata []byte, ssd1309 bool, contrast int) int
- func RawImageToPaletted(raw io.Reader, whiteThreshold uint8, alphaThreshold uint8) ([]byte, int, int, error)
- func RawImageToPalettedTitle(raw io.Reader, whiteThreshold uint8) ([]byte, error)
- func RawToPaletted(raw []byte, width int, height int) ([]byte, error)
- func RawToPalettedTitle(raw []byte) ([]byte, error)
- func ReadEeprom(sercon io.ReadWriter) ([]byte, error)
- func ReadEepromCommand(length uint16) []byte
- func ReadFlash(sercon io.ReadWriter) ([]byte, error)
- func ReadFlashCommand(length uint16) []byte
- func ReadFlashcart(sercon io.ReadWriter, address int, length int) ([]byte, error)
- func ReadFlashcartCommand(length uint16) []byte
- func ReadFlashcartInto(sercon io.ReadWriter, address int, length int, output io.Writer, ...) error
- func ReadFlashcartOptimized(sercon io.ReadWriter, page uint16, length uint16) ([]byte, error)
- func ReadFlashcartOptimizedInto(sercon io.ReadWriter, page uint16, data []byte) error
- func ReadSketch(sercon io.ReadWriter, trim bool) ([]byte, error)
- func ReadWholeFlashcart(sercon io.ReadWriter, output io.Writer, logProgress bool) (int, int, error)
- func ReadWriteCommandRaw(mode rune, length uint16, device rune) []byte
- func RenderFlashcartMeta(categories []HeaderCategory, deviceId string, destination io.Writer) error
- func ResetRgbButtonState(sercon io.ReadWriter) error
- func RgbButtonCommand(data uint8) []byte
- func RgbButtonCommandRaw(data uint8) []byte
- func RunLuaFlashcartGenerator(script string, arguments []string, dir string) (string, error)
- func ScanFlashcart(sercon io.ReadWriter, ...) (int, int, error)
- func ScanFlashcartFile(data io.ReadSeeker, headerFunc func(io.ReadSeeker, *FxHeader, int, int) error) (int, error)
- func ScanFlashcartSize(sercon io.ReadWriter) (int, int, error)
- func SeekRead(f io.ReadSeeker, addr int64, buffer []byte) error
- func SetRgbButtonState(sercon io.ReadWriter, state uint8) error
- func SetRgbEnabledGlobal(enabled bool)
- func SortedKeys[S comparable, T any](m map[S]T, order []S) []S
- func TrimUnused(data []byte, blocksize int) []byte
- func Uint32ToColor(c uint32) color.Color
- func VidPidString(vid string, pid string) string
- func Write2ByteValue(value uint16, data []byte, index int)
- func WriteEeprom(sercon io.ReadWriter, data []byte) error
- func WriteEepromCommand(length uint16) []byte
- func WriteFlashCommand(length uint16) []byte
- func WriteFlashcart(sercon io.ReadWriter, address int, data []byte, logProgress bool) (int, int, error)
- func WriteFlashcartCommand(length uint16) []byte
- func WriteHex(sercon io.ReadWriter, rawSketch io.Reader, fullClear bool) ([]byte, []bool, error)
- func WriteWholeFlashcart(sercon io.ReadWriter, input io.Reader, verify bool, logProgress bool) (int, error)
- type BasicBoardInfo
- type BasicDeviceInfo
- type BootloaderInfo
- type ExtendedDeviceInfo
- type FlashcartReader
- type FlashcartState
- type FlashcartWriter
- type FxDataState
- func (state *FxDataState) AddFunction(name string, f func(*lua.LState, *FxDataState) int, L *lua.LState)
- func (state *FxDataState) CurrentAddress() int
- func (state *FxDataState) FilePath(path string) string
- func (state *FxDataState) FinalizeBin() (*FxOffsets, error)
- func (state *FxDataState) WriteBin(raw []byte, L *lua.LState) int
- func (state *FxDataState) WriteHeader(raw string, L *lua.LState) int
- type FxHeader
- type FxOffsets
- type HeaderCategory
- type HeaderProgram
- type JedecInfo
- type NotEnoughDataError
- type NotHeaderError
- type PackageBinary
- type PackageInfo
- type ReadWriteErrorPass
- type ReadWritePasser
- type RemoveFirstLines
- type SketchAnalysis
- type TileConfig
- type TileConfigComputed
Constants ¶
const ( AnyPortKey = "any" ArduboyDeviceKey = "Arduboy" ArduboyFXDeviceKey = "ArduboyFX" ArduboyMiniDeviceKey = "ArduboyMini" ResetToBootloaderWait = 1 * time.Second JedecVerifyWait = 500 * time.Millisecond DefaultBaudRate = 57600 RebootBaudRate = 1200 FlashSize int = 32768 FlashPageSize int = 128 FlashPageCount int = FlashSize / FlashPageSize FXPageSize int = 256 FXBlockSize int = 65536 FxPagesPerBlock int = FXBlockSize / FXPageSize EepromSize int = 1024 CaterinaTotalSize int = 4096 CaterinaStartPage int = (FlashSize - CaterinaTotalSize) / FlashPageSize CathyTotalSize int = 3072 CathyStartPage int = (FlashSize - CathyTotalSize) / FlashPageSize ScreenWidth int = 128 ScreenHeight int = 64 ScreenBytes int = ScreenWidth * ScreenHeight / 8 MinBootloaderWithFlash = 13 )
const ( Board_ArduboyLeonardo = "Arduboy Leonardo" Board_ArduboyMicro = "Arduboy Micro" Board_GenuinoMicro = "Genuino Micro" Board_SparkfunMicro = "Sparkfun Pro Micro 5V" Board_AdafruitItsyBitsy = "Adafruit ItsyBitsy 5V" )
const ( FxHeaderStartString = "ARDUBOY" FxHeaderLength = 256 // The flashcart slot header length in bytes FxHeaderMetaSize = 199 // Length of the metadata section FxHeaderImageLength = 1024 // The flashcart slot title image length in bytes FxPreamblePages = (FxHeaderLength + FxHeaderImageLength) >> 8 // Page size of entire preamble (includes title) FxSaveAlignment = 4096 // Saves must be aligned to this size FxHeaderCategoryIndex = 7 // "Index into slot header for" category (1 byte) FxHeaderPreviousPageIndex = 8 // "" previous slot page (2 bytes) FxHeaderNextPageIndex = 10 // "" next slot page (2 bytes) FxHeaderSlotSizeIndex = 12 // "" slot size. (2 bytes) FxHeaderProgramSizeIndex = 14 // "" program size (1 byte, factor of 128) FxHeaderProgramPageIndex = 15 // "" starting page of program (2 bytes) FxHeaderDataPageIndex = 17 // "" starting page of data (2 bytes) FxHeaderSavePageIndex = 19 // "" starting page of save (2 bytes) FxHeaderDataSizeIndex = 21 // "" data segment size (2 bytes, factor of 256) FxHeaderHashIndex = 25 // "" hash (32 bytes) FxHeaderHashLength = 32 FxHeaderMetaIndex = 57 // "" metadata )
const ( LCDBOOTPROGRAM = "\xD5\xF0\x8D\x14\xA1\xC8\x81\xCF\xD9\xF1\xAF\x20\x00" MENUBUTTONPATCH = "\x0f\x92\x0f\xb6\x8f\x93\x9f\x93\xef\x93\xff\x93\x80\x91\xcc\x01" + "\x8d\x5f\x8d\x37\x08\xf0\x8d\x57\x80\x93\xcc\x01\xe2\xe4\xf3\xe0" + "\x80\x81\x8e\x4f\x80\x83\x91\x81\x9f\x4f\x91\x83\x82\x81\x8f\x4f" + "\x82\x83\x83\x81\x8f\x4f\x83\x83\xed\xec\xf1\xe0\x80\x81\x8f\x5f" + "\x80\x83\x81\x81\x8f\x4f\x81\x83\x82\x81\x8f\x4f\x82\x83\x83\x81" + "\x8f\x4f\x83\x83\x8f\xb1\x8f\x60\x66\x99\x1c\x9b\x88\x27\x8f\x36" + "\x81\xf4\x80\x91\xFF\x0A\x98\x1b\x96\x30\x68\xf0\xe0\xe0\xf8\xe0" + "\x87\xe7\x80\x83\x81\x83\x88\xe1\x80\x93\x60\x00\xf0\x93\x60\x00" + "\xff\xcf\x90\x93\xFF\x0A\xff\x91\xef\x91\x9f\x91\x8f\x91\x0f\xbe" + "\x0f\x90\x18\x95" RET_INSTRUCTION = "\x08\x95" RETI_INSTRUCTION = "\x18\x95" CONTRAST_NOCHANGE = -1 CONTRAST_NORMAL = 0xCF CONTRAST_DIM = 0x7F CONTRAST_DIMMER = 0x2F CONTRAST_DIMMEST = 0x00 CONTRAST_HIGHEST = 0xFF MBP_fract_lds = 14 MBP_fract_sts = 26 MBP_millis_r30 = 28 MBP_millis_r31 = 30 MBP_overflow_r30 = 56 MBP_overflow_r31 = 58 )
const ( LEDCtrlBtnOff = 0x80 LEDCtrlRGB = 0x40 LEDCtrlRxTx = 0x20 LEDCtrlRxOn = 0x10 LEDCtrlTxOn = 0x08 LEDCtrlGrOn = 0x04 LEDCtrlRdOn = 0x02 LEDCtrlBlOn = 0x01 )
const (
CartBuilderFolder = "cart_build"
)
const FlashcartMetaTemplate = `` /* 1058-byte string literal not displayed */
const (
FxDevExpectedFlashCapacity = 1 << 24
)
const (
HexLineLength = 16
)
const (
PackageInfoFile = "info.json"
)
Variables ¶
var ( ARDUBOYFXEnableBytes = []byte{0x59, 0x98} ARDUBOYFXDisableBytes = []byte{0x59, 0x9a} ARDUBOYMINIEnableBytes = []byte{0x72, 0x98} //, 0x0e, 0x94} ARDUBOYMINIDisableBytes = []byte{0x72, 0x9a} //, 0x08, 0x95} ARDUBOYCallFollowBytes = [][]byte{ {0x08, 0x95}, {0x0e, 0x94}, {0x83, 0xe0, 0x0e, 0x94}, } )
var JedecManufacturerKeys = map[int]string{
0x01: "Spansion",
0x14: "Cypress",
0x1C: "EON",
0x1F: "Adesto(Atmel)",
0x20: "Micron",
0x37: "AMIC",
0x9D: "ISSI",
0xC2: "General Plus",
0xC8: "Giga Device",
0xBF: "Microchip",
0xEF: "Winbond",
}
A mapping from identifiers returned from the bootloader to manufacturer strings. Pulled from Mr.Blinky's Python Utilities: https://github.com/MrBlinky/Arduboy-Python-Utilities/blob/main/fxdata-upload.py
var VidPidTable = map[string]BasicBoardInfo{ "VID:PID=2341:0036": {Name: Board_ArduboyLeonardo, IsBootloader: true}, "VID:PID=2341:8036": {Name: Board_ArduboyLeonardo, IsBootloader: false}, "VID:PID=2A03:0036": {Name: Board_ArduboyLeonardo, IsBootloader: true}, "VID:PID=2A03:8036": {Name: Board_ArduboyLeonardo, IsBootloader: false}, "VID:PID=2341:0037": {Name: Board_ArduboyMicro, IsBootloader: true}, "VID:PID=2341:8037": {Name: Board_ArduboyMicro, IsBootloader: false}, "VID:PID=2A03:0037": {Name: Board_ArduboyMicro, IsBootloader: true}, "VID:PID=2A03:8037": {Name: Board_ArduboyMicro, IsBootloader: false}, "VID:PID=2341:0237": {Name: Board_GenuinoMicro, IsBootloader: true}, "VID:PID=2341:8237": {Name: Board_GenuinoMicro, IsBootloader: false}, "VID:PID=1B4F:9205": {Name: Board_SparkfunMicro, IsBootloader: true}, "VID:PID=1B4F:9206": {Name: Board_SparkfunMicro, IsBootloader: false}, "VID:PID=239A:000E": {Name: Board_AdafruitItsyBitsy, IsBootloader: true}, "VID:PID=239A:800E": {Name: Board_AdafruitItsyBitsy, IsBootloader: false}, }
A mapping from VID/PID values to basic information about the board. Pulled from Mr.Blinky's Python Utilities: https://github.com/MrBlinky/Arduboy-Python-Utilities/blob/main/fxdata-upload.py
Functions ¶
func AddressCommandFlashAddress ¶
Produce the command for setting the flash address based on true byte offset
func AddressCommandFlashPage ¶
Produce the command for setting the address before reading (page aligned)
func AddressCommandFlashcartPage ¶
Produce the command for setting the address before reading flashcart data (flashcart page aligned)
func AddressCommandRaw ¶
Produce the command for setting the address before reading (raw address)
func AlignWidth ¶ added in v0.4.0
Align given address (or length) so it is the smallest multiple of alignment which can contain it. The number is always >= given
func CreateReadFlashcartBuffer ¶ added in v0.3.0
func CreateReadFlashcartBuffer() []byte
Create the optimal buffer needed for ReadFlashcartInto
func EchoSpaceControls ¶ added in v0.3.0
func ExitBootloader ¶
func ExitBootloader(sercon io.ReadWriteCloser) error
Exit the given bootloader
func FillStringArray ¶
Fill the given data byte buffer with as much of the strings contained within the strings parameter. Returns the total amount of strings written and the amount truncated from the last written string
func FindStringDiff ¶ added in v0.3.0
func FindSuitablePackageImage ¶ added in v0.6.0
func FindSuitablePackageImage(archive *zip.ReadCloser) (string, error)
Scan package for the first image alphabetically which matches the aspect ratio.
func FxHeaderStartBytes ¶
func FxHeaderStartBytes() []byte
func Get2ByteValue ¶
Read a 2 byte value in the middle of data
func HexToBin ¶
Convert hex within given reader to full byte blob. Does NOT modify the data in any way (no padding/etc)
func ImageToPaletted ¶
func ImageToPaletted(img image.Image, whiteThreshold uint8, alphaThreshold uint8) ([]byte, int, int)
Convert real image to paletted image, no resizing. Returns paletted blob and width/height of image
func LoadPackageFile ¶ added in v0.6.0
func LoadPackageFile(archive *zip.ReadCloser, filename string) ([]byte, error)
Read the entirety of the given package file into memory and return it
func MakeFxHeaderAddress ¶ added in v0.4.0
Return the line representing the full field at the given address. Only works for actual fxdata (don't use for FX_DATA_PAGE etc)
func MakeFxHeaderField ¶ added in v0.4.0
func MakeFxHeaderMainPointer ¶ added in v0.4.0
Return the block representing a main fx pointer, such as FX_DATA_PAGE or FX_SAVE_PAGE
func MakePadding ¶ added in v0.4.0
Generate padding for arduboy data, which is always 0xFF
func MapHeaderResult ¶
func MapHeaderResult(result *[]HeaderCategory, header *FxHeader, addr int) (*string, error)
Given a header, store it in the appropriate place within the 'result' category list. This is a common operation for flashcart metadata scanning. Gives you the location where you can store the image (since both have the generic item)
func PalettedToCode ¶ added in v0.3.0
func PalettedToCode(ptiles [][]byte, config *TileConfig, computed *TileConfigComputed) (string, error)
Convert the given paletted image to the header data. Taken almost directly from https://github.com/MrBlinky/Arduboy-Python-Utilities/blob/main/image-converter.py THIS FUNCTION CAN BE MEMORY INTENSIVE! The entire code file is buffered in memory!
func PalettedToImage ¶
func PalettedToImage(raw []byte, width int, height int, black color.Color, white color.Color, format string, writer io.Writer) error
Convert a paletted raw to an image of the given format. Possible values are gif, png, bmp, jpg. Transparency is possible if the right colors are chosen, but only two colors are allowed
func PalettedToImageTitleBW ¶ added in v0.2.0
Convert a paletted image to a real image in the given format. Don't bother with a writer, since titles are so small
func PalettedToRaw ¶
Convert a paletted image to a raw arduboy format
func PalettedToRawTitle ¶ added in v0.2.0
func ParseStringArray ¶
Parse as many null-terminated strings as possible out of the data. Useful for the header "metadata"
func PatchMenuButtons ¶ added in v0.6.0
Directly modify the given program so that it allows resetting to the bootloader with up and down
func PatchMicroLED ¶ added in v0.6.0
func PatchMicroLED(flashdata []byte)
Given binary data, patch EVERY instance of wrong LED polarity for Micro Taken directly from https://github.com/MrBlinky/Arduboy-Python-Utilities/blob/main/uploader.py
func PatchScreen ¶ added in v0.6.0
Apply a combination of screen patches to the given program
func RawImageToPaletted ¶ added in v0.3.0
func RawImageToPaletted(raw io.Reader, whiteThreshold uint8, alphaThreshold uint8) ([]byte, int, int, error)
If you haven't already decoded the image, we can do that for you
func RawImageToPalettedTitle ¶ added in v0.3.0
Resize and downscale the given image into a paletted image with arduboy dimensions. The whiteThreshold is the start of what is considered "white". Everything else is black
func RawToPaletted ¶
Convert a raw arduboy image (in arduboy format) to "regular" grayscale using the given black + white points
func RawToPalettedTitle ¶ added in v0.2.0
func ReadEeprom ¶
func ReadEeprom(sercon io.ReadWriter) ([]byte, error)
Read the entire flash memory, including bootloader. This is ironically faster than just reading the sketch
func ReadEepromCommand ¶
Produce command for reading an amount from eeprom (probably the whole thing though)
func ReadFlash ¶
func ReadFlash(sercon io.ReadWriter) ([]byte, error)
Read the entire flash memory, including bootloader. This is ironically faster than just reading the sketch
func ReadFlashCommand ¶
Produce the command for reading some amount from the current address
func ReadFlashcart ¶
Read portion of flashcart at given address, allocating a new slice every time. Very much not performant; prefer ReadFlashcartOptimized if possible
func ReadFlashcartCommand ¶
Produce command for reading an amount from the flashcart
func ReadFlashcartInto ¶
func ReadFlashcartInto(sercon io.ReadWriter, address int, length int, output io.Writer, readbuf []byte) error
Read any portion of flashcart at given address. Not performant at all
func ReadFlashcartOptimized ¶ added in v0.3.0
Read flashcart at simple page boundaries, creating a new slice every time
func ReadFlashcartOptimizedInto ¶ added in v0.3.0
func ReadFlashcartOptimizedInto(sercon io.ReadWriter, page uint16, data []byte) error
Read flashcart at simple page boundaries and in less-than-16bit lengths. Function will NOT throw an error if data is too long, it will simply only read up to 65k
func ReadSketch ¶
func ReadSketch(sercon io.ReadWriter, trim bool) ([]byte, error)
Read the entire sketch, without the bootloader. Also trims the sketch
func ReadWholeFlashcart ¶
Read the entire flashcart slot-by-slot and write it out to the 'output' writer. This is a "smart" reader that scans through slots reading them one by one. This is slightly slower than mindless block reading, but can be overall faster because it's not reading the entire flash memory (plus you can get more interesting logging + data). NOTE: DOES NOT CHECK FOR FLASHCART EXISTENCE!
func RenderFlashcartMeta ¶
func RenderFlashcartMeta(categories []HeaderCategory, deviceId string, destination io.Writer) error
func ResetRgbButtonState ¶
func ResetRgbButtonState(sercon io.ReadWriter) error
func RgbButtonCommand ¶
func RgbButtonCommandRaw ¶
func RunLuaFlashcartGenerator ¶ added in v0.6.0
func ScanFlashcart ¶
func ScanFlashcart(sercon io.ReadWriter, headerFunc func(io.ReadWriter, *FxHeader, int, int) error, flashRate int, flashColor uint8) (int, int, error)
Scan through the flashcart, calling the given function for each header parsed. returns the total size of the flashcart and the number of headers read. The function also receives the current header address and number of headers previously read (starts with 0). NOTE: DOES NOT CHECK FOR FLASHCART EXISTENCE!!!
func ScanFlashcartFile ¶
func ScanFlashcartFile(data io.ReadSeeker, headerFunc func(io.ReadSeeker, *FxHeader, int, int) error) (int, error)
Same as ScanFlashcart but for a file / other file-like readerseeker.
func ScanFlashcartSize ¶ added in v0.3.0
func ScanFlashcartSize(sercon io.ReadWriter) (int, int, error)
A wrapper for ScanFlashcart which only returns the basic flashcart size in bytes and slots
func SeekRead ¶ added in v0.6.0
func SeekRead(f io.ReadSeeker, addr int64, buffer []byte) error
Seek to given addr (absolute) and read FULL amount into given buffer
func SetRgbButtonState ¶
func SetRgbButtonState(sercon io.ReadWriter, state uint8) error
func SetRgbEnabledGlobal ¶
func SetRgbEnabledGlobal(enabled bool)
func SortedKeys ¶ added in v0.4.0
func SortedKeys[S comparable, T any](m map[S]T, order []S) []S
func TrimUnused ¶
Remove unused sections from the end of the byte array. In these files, sections of 0xFF represent unused data.
func Uint32ToColor ¶
func VidPidString ¶
Construct 'standardized' VID:PID string (the same format python uses, just in case)
func Write2ByteValue ¶
Write a 2 byte value directly into the middle of data
func WriteEeprom ¶
func WriteEeprom(sercon io.ReadWriter, data []byte) error
Write the given eeprom to the device. This may take a while
func WriteEepromCommand ¶
func WriteFlashCommand ¶
func WriteFlashcart ¶ added in v0.3.0
func WriteFlashcart(sercon io.ReadWriter, address int, data []byte, logProgress bool) (int, int, error)
Write any arbitrary amount of data to the flash, perserving any data surrounding it (since writing flashes the entire 65k block). Return the actual address it started writing to, and the total write size
func WriteFlashcartCommand ¶
func WriteHex ¶
Writing a sketch the "right way" is WEIRD because of the intel hex format. The hex file indicates various addresses to write data to, not a giant data blob. In theory, you could supply this function with hex that writes only every other page, or only some pages in the middle. As such, you must provide the raw sketch, not actual binary data, since there might be holes (there most likely aren't). This function reads the entire existing sketch area (everything minus the bootloader) into memory, applies the hex modifications on top, then writes only the modified pages (smallest writable unit) back to the flash memory. We could technically ignore the hex standard and assume no sketch will ever have holes and simplify this dramatically, but I wanted this to be as correct as possible. Alternatively, to write an "arduboy" sketch program, set fullClear to true and you don't have to worry about any weirdness
func WriteWholeFlashcart ¶
func WriteWholeFlashcart(sercon io.ReadWriter, input io.Reader, verify bool, logProgress bool) (int, error)
Write an entire flashcart starting at the normal address and going to the end. Does not care about any existing data on the flashcart. NOTE: DOES NOT CHECK FOR FLASHCART EXISTENCE OR SIZE
Types ¶
type BasicBoardInfo ¶
type BasicDeviceInfo ¶
type BasicDeviceInfo struct { VidPid string Port string Product string BoardType string IsBootloader bool }
func ConnectWithBootloader ¶
func ConnectWithBootloader(port string) (io.ReadWriteCloser, *BasicDeviceInfo, error)
Connect to given port and force bootloader. Accepts "any" as a special port identifier, will connect to "first" connection found. If exact port is given and no bootloader specified, will reboot device and NOT connect, since it is not always possible to reconnect on the same port. If "any" given, will attempt a reconnect after 2 seconds
func GetBasicDevices ¶
func GetBasicDevices() ([]BasicDeviceInfo, error)
Retrieve a list of all connected arduboys and any information that can be parsed without actually connected to the ports
func (*BasicDeviceInfo) SmallString ¶
func (device *BasicDeviceInfo) SmallString() string
type BootloaderInfo ¶
type BootloaderInfo struct { Device string SoftwareId string Startpage int Length int IsCaterina bool Version int MD5 string }
func GetBootloaderInfo ¶
func GetBootloaderInfo(sercon io.ReadWriter) (*BootloaderInfo, error)
Pull as much bootloader information as possible without overstepping into JEDEC or whatever
func (*BootloaderInfo) GetJedecInfo ¶
func (info *BootloaderInfo) GetJedecInfo(sercon io.ReadWriter, verify bool) (*JedecInfo, error)
Ask device for JEDEC info. NOTE: this function will block for some time (500ms?) while it verifies the jedec ID! (if you ask for it).
type ExtendedDeviceInfo ¶
type ExtendedDeviceInfo struct { Basic *BasicDeviceInfo Bootloader *BootloaderInfo Jedec *JedecInfo HasFlashcart bool }
func QueryDevice ¶
func QueryDevice(device *BasicDeviceInfo, sercon io.ReadWriteCloser, verify bool) (*ExtendedDeviceInfo, error)
Get extended device info from the given information
type FlashcartReader ¶ added in v0.6.0
type FlashcartState ¶ added in v0.6.0
type FlashcartState struct { FileDirectory string Readers []*FlashcartReader Writers []*FlashcartWriter Arguments []string }
General tracking for entire lua script (user can open arbitrary flashcarts)
func (*FlashcartState) AddFunction ¶ added in v0.6.0
func (state *FlashcartState) AddFunction(name string, f func(*lua.LState, *FlashcartState) int, L *lua.LState)
Add a function to the given lua state that actually tracks with our own state. Usually lua functions don't accept extra go parameters
func (*FlashcartState) CloseAll ¶ added in v0.6.0
func (state *FlashcartState) CloseAll() []error
Attempt to close all open files
func (*FlashcartState) FilePath ¶ added in v0.6.0
func (state *FlashcartState) FilePath(path string) string
Get full path to given file requested by user. The system has a way to set the "working directory" for the whole script, that's all
type FlashcartWriter ¶ added in v0.6.0
type FlashcartWriter struct { File *os.File CategoryId int Slots int LastSlotPage uint16 //Address int // Current address within the flashcart // TODO: add settings for menu, contrast, screen patching, etc ValidateCategoryStructure bool ValidateImageLength bool PatchMenu bool PatchMicroLED bool PatchSsd1309 bool Contrast int }
func NewFlashcartWriter ¶ added in v0.6.0
func NewFlashcartWriter(file *os.File) *FlashcartWriter
type FxDataState ¶ added in v0.5.0
type FxDataState struct { Header io.Writer Bin io.Writer BinLength int // Total bin length as of now DataEnd int // Exclusive end SaveStart int // Inclusive start HasSave bool // Whether a save is active for this thing CurrentNamespace string FileDirectory string }
Tracking data for fx script system
func (*FxDataState) AddFunction ¶ added in v0.5.0
func (state *FxDataState) AddFunction(name string, f func(*lua.LState, *FxDataState) int, L *lua.LState)
Shorthand to add global function that also accepts this state
func (*FxDataState) CurrentAddress ¶ added in v0.5.0
func (state *FxDataState) CurrentAddress() int
func (*FxDataState) FilePath ¶ added in v0.5.0
func (state *FxDataState) FilePath(path string) string
func (*FxDataState) FinalizeBin ¶ added in v0.5.0
func (state *FxDataState) FinalizeBin() (*FxOffsets, error)
func (*FxDataState) WriteBin ¶ added in v0.5.0
func (state *FxDataState) WriteBin(raw []byte, L *lua.LState) int
Write the raw data directly to the bin. Pretty simple! But raises a script error if there's an error in the underlying write
func (*FxDataState) WriteHeader ¶ added in v0.5.0
func (state *FxDataState) WriteHeader(raw string, L *lua.LState) int
Write the raw string to the header with the given number of extra newlines. Raises a lua "error" if writing the header doesn't work
type FxHeader ¶
type FxHeader struct { Category uint8 PreviousPage uint16 NextPage uint16 SlotPages uint16 ProgramPages uint8 ProgramStart uint16 DataStart uint16 SaveStart uint16 DataPages uint16 Sha256 string // Metadata Title string Version string Developer string Info string }
All data in the header of an fx slot (JUST the header, not the image)
func ParseHeader ¶
Parse the header out of a byte slice. Will throw an error on slice too small or on header "not a header". Byte array returned is the slice without the header anymore
func (*FxHeader) IsCategory ¶
func (*FxHeader) IsOldFormat ¶ added in v0.6.0
We didn't always utilize that data pages field. If there's actual FX data but the data pages field is "unset", this is the old format.
func (*FxHeader) MakeHeader ¶
Generate the bytes you can write to the flashcart
type FxOffsets ¶ added in v0.4.0
type FxOffsets struct { DataLength int // real length of data as user defined it SaveLength int // real length of save as user defined it DataLengthFlash int // length of data on flash (may be larger than DataLength) SaveLengthFlash int // length of save on flash (may be larger than SaveLength) DataStart int // Beginning address (byte) of data SaveStart int // Beginning address (byte) of save (will be past end of flash if no save) }
func RunLuaFxGenerator ¶ added in v0.5.0
func RunLuaFxGenerator(script string, header io.Writer, bin io.Writer, dir string) (*FxOffsets, error)
Run an entire lua script which may write fxdata to the given header and bin files. For files loaded from the script, load them from dir (or send empty string for nothing)
type HeaderCategory ¶
type HeaderCategory struct { Title string Info string Image string Address int SlotSize int Slots []*HeaderProgram }
func ScanFlashcartFileMeta ¶
func ScanFlashcartFileMeta(data io.ReadSeeker, getImages bool) ([]HeaderCategory, error)
Scrape metadata out of a file flashcart, same as ScanFlashcartMeta
func ScanFlashcartMeta ¶
func ScanFlashcartMeta(sercon io.ReadWriter, getImages bool) ([]HeaderCategory, error)
Scrape just the metadata out of the flashcart. Optionally pull images (much slower)
type HeaderProgram ¶
type JedecInfo ¶
func (*JedecInfo) FitsFlashcart ¶
Whether this jedec info will fit a flashcart of given size. there are caveats to fitting a flashcart (it must end with an empty page and whatever)
func (*JedecInfo) ValidateFitsFxData ¶ added in v0.3.0
Whether the flashcart of fsize could fit fxdata of dsize at the end. Can also specify whether it would fit without block overlap, simplifying the writing process (no reads required)
type NotEnoughDataError ¶
func (*NotEnoughDataError) Error ¶
func (m *NotEnoughDataError) Error() string
type NotHeaderError ¶
type NotHeaderError struct{}
func (*NotHeaderError) Error ¶
func (m *NotHeaderError) Error() string
type PackageBinary ¶ added in v0.6.0
type PackageBinary struct { Title string `json:"title"` Filename string `json:"filename"` Device string `json:"device"` CartImage string `json:"cartimage"` FlashData string `json:"flashdata"` FlashSave string `json:"flashsave"` }
func FindAnyBinary ¶ added in v0.6.0
func FindAnyBinary(info *PackageInfo, device []string) (*PackageBinary, error)
A rather dangerous function to find binaries: just get the first binary that matches ANY of the given devices. The order of the devices doesn't matter, just the order of the binaries in the package
func FindSuitableBinary ¶ added in v0.6.0
func FindSuitableBinary(info *PackageInfo, device string, title string) (*PackageBinary, error)
Search for a suitable binary within the archive. We try to find a matching binary using either device or title. If neither are set, the only way this function works is if there's only one option.
type PackageInfo ¶ added in v0.6.0
type PackageInfo struct { SchemaVersion int `json:"schemaVersion"` Title string `json:"title"` Description string `json:"description"` Author string `json:"author"` Version string `json:"version"` Binaries []*PackageBinary `json:"binaries"` }
All data parsed from info.json. We don't parse all fields, only the ones we actually care about here.
func ReadPackageInfo ¶ added in v0.6.0
func ReadPackageInfo(archive *zip.ReadCloser) (PackageInfo, error)
type ReadWriteErrorPass ¶
type ReadWriteErrorPass struct {
// contains filtered or unexported fields
}
func (*ReadWriteErrorPass) IsPass ¶
func (rwep *ReadWriteErrorPass) IsPass() error
func (*ReadWriteErrorPass) Read ¶
func (rwep *ReadWriteErrorPass) Read(b []byte) (int, error)
A special read function which will skip if an error is present in the struct, and which will read until it fills the entire given byte slice (blocking)
func (*ReadWriteErrorPass) ReadPass ¶
func (rwep *ReadWriteErrorPass) ReadPass(b []byte) int
func (*ReadWriteErrorPass) Write ¶
func (rwep *ReadWriteErrorPass) Write(b []byte) (int, error)
A special write function which will skip if an error is present in the struct, and which will write until it has written the entire buffer contents (blocking)
func (*ReadWriteErrorPass) WritePass ¶
func (rwep *ReadWriteErrorPass) WritePass(b []byte) int
type ReadWritePasser ¶
type RemoveFirstLines ¶
A writer wrapper which removes the first few lines of output
type SketchAnalysis ¶
type SketchAnalysis struct { OverwritesCaterina bool OverwritesCathy bool // If this happens, sketch is too large. Probably not used... TotalPages int TrimmedData []byte DetectedDevice string }
func AnalyzeSketch ¶
func AnalyzeSketch(bindata []byte, bootloader bool) SketchAnalysis
Compute various important attributes of the given flash data. It could be a sketch or a bootloader
type TileConfig ¶ added in v0.2.0
type TileConfig struct { Width int // Width of tile (0 means use all available width) Height int // Height of tile (0 means use all available height) Spacing int // Spacing between tiles (including on edges) UseMask bool // Whether to use transparency as a data mask SeparateMask bool // Separate the mask from the data NoDimensions bool // Don't output dimension variables in data NoPreamble bool // Don't generate the preamble (includes, etc) WindowsFormat bool // Windows newlines (\r\n) Name string // Name of the sprite variables to generate }
Configuration for tile / code generation
func (*TileConfig) Expand ¶ added in v0.2.0
func (t *TileConfig) Expand(width int, height int) *TileConfigComputed
Calculate individaul sprite width, height, horizontal count, and vertical count
type TileConfigComputed ¶ added in v0.2.0
type TileConfigComputed struct { SpriteWidth int // Calculated width of each sprite SpriteHeight int // Calculated height of each sprite HFrames int // How many tiles across VFrames int // How many tiles vertical StartX int // Where to start reading tiles within the image StartY int // Where to start reading tiles within the image StrideX int // How far to move through the image to find the next tile StrideY int // How far to move through the image to find the next tile }
Extra computed fields when we know more about the image we're applying the tile config to
func SplitImageToTiles ¶ added in v0.2.0
func SplitImageToTiles(rawimage io.Reader, config *TileConfig) ([]*image.NRGBA, *TileConfigComputed, error)
Split the given image into linear tiles based on the given tile config. returns the array of tile images, each in NRGBA format
func (*TileConfigComputed) ValidateForCode ¶ added in v0.2.0
func (c *TileConfigComputed) ValidateForCode() error
Ensure computed tile config is valid. Check returned error for nil
func (*TileConfigComputed) ValidateForFx ¶ added in v0.2.0
func (c *TileConfigComputed) ValidateForFx() error
Ensure computed tile config is valid for writing to fx.
func (*TileConfigComputed) ValidateGeneral ¶ added in v0.2.0
func (c *TileConfigComputed) ValidateGeneral() error