tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
584 stars 180 forks source link

microbitmatrix not rendering correctly on microbit v2 device #641

Closed nightmarlin closed 5 months ago

nightmarlin commented 5 months ago

When using the microbitmatrix driver on a Micro:Bit V2, only 2 LEDs correctly illuminate (see "got" section).

This is unlikely to be an issue with the device itself as when the equivalent JS code is loaded from the MakeCode IDE, the display works as expected. I also have a Micro:Bit V1 and the below snippet runs as expected on that.

TinyGo Example

// tinygo version 0.30.0 darwin/amd64 (using go version go1.21.6 and LLVM version 16.0.1)
//
// built and flashed with
// tinygo flash -target=microbit ./main.go

// Command showall enables every LED in the display matrix
package main

import (
    mbitm "tinygo.org/x/drivers/microbitmatrix"
)

func main() {
    display := mbitm.New()
    display.Configure(mbitm.Config{})
    display.EnableAll()
}

JS Equivalent

see it in MakeCode

// MakeCode https://makecode.microbit.org/S21855-36575-72332-71233
basic.forever(function () {
    basic.showLeds(`
        # # # # #
        # # # # #
        # # # # #
        # # # # #
        # # # # #
        `)
})

This display pattern is correctly rendered on both Micro:Bit V1 and V2

Micro:Bit V2 DETAILS.TXT

# DAPLink Firmware - see https://daplink.io
Build ID: v0258-gcbc2daa8 (gcc)
Unique ID: 9904360275044e450038900a00000033000000009796990b
HIC ID: 9796990b
Auto Reset: 1
Automation allowed: 0
Overflow detection: 0
Incompatible image detection: 1
Page erasing: 0
Daplink Mode: Interface
Interface Version: 0258
Bootloader Version: 0255
Git SHA: cbc2daa8815f02c580fbfc5daa441bfc31db2051
Local Mods: 0
USB Interfaces: MSD, CDC, HID, WebUSB
Bootloader CRC: 0x828c6069
Interface CRC: 0x70bfa202
Remount count: 0
URL: https://microbit.org/device/?id=9904&v=0258

the presence of Incompatible image detection: 1 may suggest that there's a difference in how the LED display is set-up and used in microbit V2s over microbit V1s?

nightmarlin commented 5 months ago

after further investigation, I needed to use -target=microbit-v2 instead of -target=microbit. I'll open a separate issue (and probably a PR) on the docs repo to make this clearer as it was not obvious from https://tinygo.org/docs/reference/microcontrollers/microbit/ or https://tinygo.org/docs/reference/machine/