Files
drivers/examples/ssd1306/main_i2c.go
2025-07-02 10:44:06 -03:00

30 lines
567 B
Go

//go:build !thumby
package main
import (
"machine"
"tinygo.org/x/drivers/ssd1306"
)
func makeSSD1306(width, height int16) (*ssd1306.Device, error) {
err := machine.I2C0.Configure(machine.I2CConfig{
Frequency: 400 * machine.KHz,
})
if err != nil {
return nil, err
}
address := uint16(ssd1306.Address)
if width == 128 && (height == 32 || height == 64) {
address = ssd1306.Address_128_32
}
display := ssd1306.NewI2C(machine.I2C0)
display.Configure(ssd1306.Config{
Address: address,
Width: width,
Height: height,
})
return &display, nil
}