package adafruit4650 import ( "bytes" _ "embed" "encoding/hex" "fmt" "image" "image/color" "image/draw" "image/png" "os" "testing" "time" "tinygo.org/x/drivers" "tinygo.org/x/tinyfont" "tinygo.org/x/tinyfont/freemono" ) //go:embed expected_hello_world.png var expectedHelloWorld []byte // mockBus mocks a fake i2c device adafruit4650 display. // The memory layout assumes that clients set up the device in a particular way and always send complete // pages to the device buffer. type mockBus struct { img draw.Image line int addr uint8 currentPage int currentColumn int } func (m *mockBus) Tx(addr uint16, w, r []byte) error { if addr != uint16(m.addr) { panic("unexpected address") } if r != nil { panic("mock does not support reads") } if w[0] == 0x00 { if w[1]&0xf0 == 0xb0 { m.currentPage = int(w[1] & 0x0f) lo := w[2] & 0x0f hi := w[2] & 0x07 m.currentColumn = int(hi<<4 | lo) } return nil } if w[0] != 0x40 { panic("unexpected first byte: " + hex.EncodeToString(w[0:1])) } return m.writeRAM(w[1:]) } func newMock() *mockBus { m := image.NewRGBA(image.Rect(0, 0, width, height)) return &mockBus{img: m, addr: DefaultAddress, currentPage: -1, currentColumn: -1} } func (m *mockBus) writeRAM(data []byte) error { // RAM layout // *-----> y // | // x| col0 col1 ... col63 // v p0 a0 b0 .. // a1 b1 .. // .. .. .. // a7 b7 .. // p1 a0 b0 // a1 b1 // fmt.Printf("writing page %d\n", m.currentPage) // assuming entire pages will be written for x := 0; x < 8; x++ { for y := 0; y < height; y++ { col := data[y] c := color.Black if col&(1<